- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Tooltip
A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-preview',
imports: [HlmTooltipImports, HlmButtonImports],
template: `
<button hlmTooltip="Add to library" hlmBtn variant="outline">Default</button>
`,
})
export class TooltipPreview {}Installation
ng g @spartan-ng/cli:ui tooltipnx g @spartan-ng/cli:ui tooltipimport { OVERLAY_DEFAULT_CONFIG } from '@angular/cdk/overlay';
import { brnClasses, type BrnClassesOptions } from '@spartan-ng/brain/core';
import { cn, type ClassValue } from 'cn';
import { createCn } from 'cn/config';
import { makeEnvironmentProviders, type EnvironmentProviders } from '@angular/core';
import { provideSpartanHlm } from '@spartan-ng/helm/utils';
/**
* Merges class values and resolves Tailwind CSS conflicts.
*
* To customize the merge (e.g. register custom theme values), create your own instance:
*
* @example
* ```ts
*
*
* export const hlm = createCn({
* extend: { classGroups: { 'font-size': [{ text: ['hero'] }] } },
* });
* ```
*/
export const hlm = cn;
/**
* This function dynamically adds and removes classes for a given element without requiring
* the a class binding (e.g. `[class]="..."`) which may interfere with other class bindings.
* The classes are merged with `hlm`.
*/
export function classes(computed: () => ClassValue[] | string, options: Omit<BrnClassesOptions, 'merge'> = {}) {
brnClasses(computed, { ...options, merge: hlm });
}
/**
* Provides default configuration for Spartan Helm components.
*
* This utility configures the Angular CDK overlay to disable the `usePopover`
* behavior introduced in Angular 21, which causes CDK overlay-based components
* (sheets, dialogs, tooltips, etc.) to render above `position: fixed` elements
* like `<hlm-toaster>`.
*
* @returns {EnvironmentProviders} Environment providers to be added to the application config.
*
* @example
* ```ts
* // app.config.ts
*
*
* export const appConfig: ApplicationConfig = {
* providers: [
* provideSpartanHlm(),
* // ... other providers
* ],
* };
* ```
*/
export function provideSpartanHlm(): EnvironmentProviders {
return makeEnvironmentProviders([
{
provide: OVERLAY_DEFAULT_CONFIG,
useValue: { usePopover: false },
},
]);
}import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-md px-3 py-1.5 text-xs bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-md px-3 py-1.5 text-xs bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-none px-3 py-1.5 text-xs bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-2xl px-3 py-1.5 text-xs **:data-[slot=kbd]:rounded-4xl bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-md px-3 py-1.5 text-xs **:data-[slot=kbd]:rounded-md bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;import { BrnTooltip, BrnTooltipPosition, provideBrnTooltipDefaultOptions } from '@spartan-ng/brain/tooltip';
import { Directive } from '@angular/core';
import { cva } from 'class-variance-authority';
import { hlm } from '@spartan-ng/helm/utils';
export const DEFAULT_TOOLTIP_SVG_CLASS =
'bg-foreground fill-foreground z-50 block size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]';
export const DEFAULT_TOOLTIP_CONTENT_CLASSES = hlm(
'data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-end-2 data-[side=right]:slide-in-from-start-2 data-[side=top]:slide-in-from-bottom-2 inline-flex items-center gap-1.5 rounded-xl px-3 py-1.5 text-xs has-data-[slot=kbd]:pe-1.5 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-lg bg-foreground text-background data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) text-balance',
);
export const tooltipPositionVariants = cva('absolute', {
variants: {
position: {
top: 'bottom-0 left-[calc(50%-5px)] translate-y-full',
bottom: '-top-2.5 left-[calc(50%-5px)] translate-y-0 rotate-180',
left: '-end-2.5 top-[calc(50%-5px)] translate-y-0 rotate-270 rtl:-rotate-270',
right: '-start-2.5 top-[calc(50%-5px)] translate-y-0 rotate-90 rtl:-rotate-90',
},
},
});
@Directive({
selector: '[hlmTooltip]',
exportAs: 'hlmTooltip',
providers: [
provideBrnTooltipDefaultOptions({
svgClasses: DEFAULT_TOOLTIP_SVG_CLASS,
tooltipContentClasses: DEFAULT_TOOLTIP_CONTENT_CLASSES,
arrowClasses: (position: BrnTooltipPosition) => hlm(tooltipPositionVariants({ position })),
}),
],
hostDirectives: [
{
directive: BrnTooltip,
inputs: ['brnTooltip: hlmTooltip', 'position', 'hideDelay', 'showDelay', 'sideOffset', 'tooltipDisabled'],
},
],
})
export class HlmTooltip {}
export const HlmTooltipImports = [HlmTooltip] as const;Usage
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';<button hlmTooltip="Add to library" hlmBtn variant="outline">Default</button>Accessibility
Prefer using tooltips as visual labels only : Tooltips should act as supplementary visual labels for sighted mouse and keyboard users. Tooltips alone are not accessible to touch users. When touch users need to read the content, use a Popover instead.
Examples
Simple
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-simple',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<button [hlmTooltip]="'Simple tooltip'" hlmBtn variant="outline">Simple</button>
`,
})
export class TooltipSimple {}Group
Provide provideBrnTooltipGroup on a wrapping component so that once one tooltip opens, the others in the group open instantly until the skip-delay window elapses.
import { Component } from '@angular/core';
import { provideBrnTooltipGroup } from '@spartan-ng/brain/tooltip';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-group',
imports: [HlmButtonImports, HlmTooltipImports],
providers: [provideBrnTooltipGroup({ skipDelayDuration: 300 })],
template: `
<div class="flex gap-2">
<button [hlmTooltip]="'Save'" hlmBtn variant="outline">Save</button>
<button [hlmTooltip]="'Copy'" hlmBtn variant="outline">Copy</button>
<button [hlmTooltip]="'Paste'" hlmBtn variant="outline">Paste</button>
</div>
`,
})
export class TooltipGroup {}Positions
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-position',
imports: [HlmButtonImports, HlmTooltipImports],
host: {
class: 'flex flex-col space-y-2',
},
template: `
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="top">Top</button>
<div class="flex space-x-2">
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="left">Left</button>
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="right">Right</button>
</div>
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="bottom">Bottom</button>
`,
})
export class TooltipPosition {}Disabled
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-disabled',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<button [hlmTooltip]="'Simple tooltip'" [tooltipDisabled]="true" hlmBtn variant="outline">Simple</button>
`,
})
export class TooltipDisabled {}Disabled Button with Tooltip
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-disabled-button-with-tooltip',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<div hlmTooltip="Simple tooltip">
<button hlmBtn variant="outline" disabled>Disabled Button</button>
</div>
`,
})
export class TooltipDisabledButtonWithTooltip {}Template
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucidePlus } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-template',
imports: [HlmButtonImports, HlmTooltipImports, NgIcon],
providers: [provideIcons({ lucidePlus })],
template: `
<button [hlmTooltip]="tooltip" hlmBtn variant="outline">Simple</button>
<ng-template #tooltip>
<span class="flex items-center">
Add to library
<ng-icon class="ml-2 text-sm" name="lucidePlus" />
</span>
</ng-template>
`,
})
export class TooltipTemplate {}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-rtl-preview',
imports: [HlmButtonImports, HlmTooltipImports],
providers: [Directionality],
host: {
class: 'flex w-full flex-wrap items-center justify-center gap-3',
'[dir]': '_dir()',
},
template: `
<button [hlmTooltip]="_t()['save']" position="top" hlmBtn variant="outline">{{ _t()['top'] }}</button>
<button [hlmTooltip]="_t()['save']" position="bottom" hlmBtn variant="outline">{{ _t()['bottom'] }}</button>
<button [hlmTooltip]="_t()['save']" position="left" hlmBtn variant="outline">{{ _t()['left'] }}</button>
<button [hlmTooltip]="_t()['save']" position="right" hlmBtn variant="outline">{{ _t()['right'] }}</button>
`,
})
export class TooltipRtlPreview {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: { save: 'Save your changes', top: 'Top', bottom: 'Bottom', left: 'Left', right: 'Right' },
},
ar: {
dir: 'rtl',
values: { save: 'احفظ تغييراتك', top: 'أعلى', bottom: 'أسفل', left: 'يسار', right: 'يمين' },
},
he: {
dir: 'rtl',
values: { save: 'שמור את השינויים שלך', top: 'למעלה', bottom: 'למטה', left: 'שמאל', right: 'ימין' },
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnTooltipContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-tooltip-${++uniqueId}` | - |
BrnTooltipStringTemplateOutlet
Selector: [brnTooltipStringTemplateOutlet]
ExportAs: brnTooltipStringTemplateOutlet
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| brnTooltipStringTemplateOutletContext | BrnTemplateOutletContext | undefined | undefined | - |
| brnTooltipStringTemplateOutlet* (required) | T | TemplateRef<void> | - | - |
BrnTooltip
Selector: [brnTooltip]
ExportAs: brnTooltip
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| tooltipDisabled | boolean | false | - |
| position | BrnTooltipPosition | this._config.position ?? 'top' | - |
| brnTooltip | BrnTooltipType | null | - |
| showDelay | number | this._config.showDelay | - |
| hideDelay | number | this._config.hideDelay | - |
| sideOffset | number | this._config.sideOffset ?? 8 | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| show | void | - | - |
| hide | void | - | - |
Helm API
HlmTooltip
Selector: [hlmTooltip]
ExportAs: hlmTooltip
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| hlmTooltip | BrnTooltipType | null | - |
| position | BrnTooltipPosition | this._config.position ?? 'top' | - |
| hideDelay | number | this._config.hideDelay | - |
| showDelay | number | this._config.showDelay | - |
| sideOffset | number | this._config.sideOffset ?? 8 | - |
| tooltipDisabled | boolean | false | - |
On This Page