- 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
Dialog
A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-dialog-preview',
imports: [HlmDialogImports, HlmFieldImports, HlmInputImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog>
<button hlmDialogTrigger hlmBtn variant="outline">Open Dialog</button>
<hlm-dialog-content *hlmDialogPortal="let ctx" class="sm:max-w-sm">
<hlm-dialog-header>
<h3 hlmDialogTitle>Edit profile</h3>
<p hlmDialogDescription>Make changes to your profile here. Click save when you're done.</p>
</hlm-dialog-header>
<hlm-field-group>
<hlm-field>
<label hlmFieldLabel for="name">Name</label>
<input hlmInput id="name" value="Pedro Duarte" />
</hlm-field>
<hlm-field>
<label hlmFieldLabel for="username">Username</label>
<input hlmInput id="username" value="@peduarte" />
</hlm-field>
</hlm-field-group>
<hlm-dialog-footer>
<button hlmBtn variant="outline" hlmDialogClose>Cancel</button>
<button hlmBtn type="submit">Save changes</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogPreview {}Installation
ng g @spartan-ng/cli:ui dialognx g @spartan-ng/cli:ui dialogimport { 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 { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="absolute end-2 top-2" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-sm ring-1 duration-100 sm:max-w-sm relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'bg-muted/50 -mx-4 -mb-4 rounded-b-xl border-t p-4 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-2 flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'text-base leading-none font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;import { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="absolute end-4 top-4" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-6 rounded-xl p-6 text-sm ring-1 duration-100 sm:max-w-md relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-2 flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'leading-none font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;import { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="absolute end-2 top-2" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-none p-4 text-xs/relaxed ring-1 duration-100 sm:max-w-sm relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-1 text-start flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'text-sm font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;import { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="absolute end-4 top-4" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/5 grid max-w-[calc(100%-2rem)] gap-6 rounded-4xl p-6 text-sm ring-1 duration-100 sm:max-w-md relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-2 flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'text-base leading-none font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;import { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="absolute end-2 top-2" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-4 rounded-xl p-4 text-xs/relaxed ring-1 duration-100 sm:max-w-sm relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-xs/relaxed *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-1 flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'text-sm font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;import { BrnDialog, BrnDialogClose, BrnDialogContent, BrnDialogDescription, BrnDialogOverlay, BrnDialogRef, BrnDialogService, BrnDialogTitle, BrnDialogTrigger, cssClassesToArray, injectBrnDialogContext, provideBrnDialogDefaultOptions, type BrnDialogOptions, type BrnDialogRef } from '@spartan-ng/brain/dialog';
import { ChangeDetectionStrategy, Component, Directive, Injectable, booleanAttribute, computed, effect, forwardRef, inject, input, untracked, type TemplateRef } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { NgComponentOutlet } from '@angular/common';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable } from '@spartan-ng/brain/core';
import { lucideX } from '@ng-icons/lucide';
import { type BooleanInput } from '@angular/cdk/coercion';
import { type ClassValue } from 'cn';
import { type ComponentType } from '@angular/cdk/portal';
@Directive({
selector: 'button[hlmDialogClose]',
exportAs: 'hlmDialogClose',
hostDirectives: [BrnDialogClose],
host: { 'data-slot': 'dialog-close' },
})
export class HlmDialogClose {}
type HlmDialogContentContext = {
$component?: ComponentType<unknown>;
$dynamicComponentClass?: string;
$showCloseButton?: boolean;
$closeLabel?: string;
};
@Component({
selector: 'hlm-dialog-content',
exportAs: 'hlmDialogContent',
imports: [NgComponentOutlet, HlmButton, HlmDialogClose, NgIcon],
providers: [provideIcons({ lucideX })],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'data-slot': 'dialog-content',
'[attr.data-state]': 'state()',
},
template: `
@if (component) {
<ng-container [ngComponentOutlet]="component" />
} @else {
<ng-content />
}
@if (showCloseButton()) {
<button hlmBtn variant="ghost" size="icon-sm" class="bg-secondary absolute end-4 top-4" hlmDialogClose>
<span class="sr-only">{{ closeLabel() }}</span>
<ng-icon name="lucideX" />
</button>
}
`,
})
export class HlmDialogContent {
private readonly _dialogRef = inject(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<HlmDialogContentContext | null>({ optional: true });
public readonly showCloseButton = input<boolean, BooleanInput>(this._dialogContext?.$showCloseButton ?? true, {
transform: booleanAttribute,
});
public readonly closeLabel = input<string>(this._dialogContext?.$closeLabel ?? 'Close');
public readonly state = computed(() => this._dialogRef?.state() ?? 'closed');
public readonly component = this._dialogContext?.$component;
private readonly _dynamicComponentClass = this._dialogContext?.$dynamicComponentClass;
constructor() {
classes(() => [
'bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/5 dark:ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-6 rounded-4xl p-6 text-sm shadow-xl ring-1 duration-100 sm:max-w-md relative mx-auto w-[calc(100vw-2rem)] outline-none sm:mx-0',
this._dynamicComponentClass,
]);
}
}
@Directive({
selector: '[hlmDialogDescription]',
exportAs: 'hlmDialogDescription',
hostDirectives: [BrnDialogDescription],
host: { 'data-slot': 'dialog-description' },
})
export class HlmDialogDescription {
constructor() {
classes(() => 'text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3');
}
}
@Directive({
selector: '[hlmDialogFooter],hlm-dialog-footer',
exportAs: 'hlmDialogFooter',
host: { 'data-slot': 'dialog-footer' },
})
export class HlmDialogFooter {
constructor() {
classes(() => 'flex flex-col-reverse gap-2 sm:flex-row sm:justify-end');
}
}
@Directive({
selector: '[hlmDialogHeader],hlm-dialog-header',
exportAs: 'hlmDialogHeader',
host: { 'data-slot': 'dialog-header' },
})
export class HlmDialogHeader {
constructor() {
classes(() => 'gap-1.5 flex flex-col');
}
}
export const hlmDialogOverlayClass = hlm('data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 isolate bg-black/30 duration-100 supports-backdrop-filter:backdrop-blur-sm');
@Directive({
selector: '[hlmDialogOverlay],hlm-dialog-overlay',
exportAs: 'hlmDialogOverlay',
hostDirectives: [BrnDialogOverlay],
})
export class HlmDialogOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() => hlm(hlmDialogOverlayClass, this.userClass()));
constructor() {
effect(() => {
const newClass = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(newClass));
});
}
}
@Directive({
selector: '[hlmDialogPortal]',
exportAs: 'hlmDialogPortal',
hostDirectives: [{ directive: BrnDialogContent, inputs: ['context', 'class'] }],
})
export class HlmDialogPortal {}
@Directive({
selector: '[hlmDialogTitle]',
exportAs: 'hlmDialogTitle',
hostDirectives: [BrnDialogTitle],
host: { 'data-slot': 'dialog-title' },
})
export class HlmDialogTitle {
constructor() {
classes(() => 'text-base leading-none font-medium');
}
}
@Directive({
selector: 'button[hlmDialogTrigger],button[hlmDialogTriggerFor]',
exportAs: 'hlmDialogTrigger',
hostDirectives: [{ directive: BrnDialogTrigger, inputs: ['id', 'brnDialogTriggerFor: hlmDialogTriggerFor', 'type'] }],
host: { 'data-slot': 'dialog-trigger' },
})
export class HlmDialogTrigger {}
export type HlmDialogOptions<DialogContext = unknown> = BrnDialogOptions & {
contentClass?: string;
showCloseButton?: boolean;
closeLabel?: string;
context?: DialogContext;
};
@Injectable({
providedIn: 'root',
})
export class HlmDialogService {
private readonly _brnDialogService = inject(BrnDialogService);
public open<TResult = unknown, TContext = unknown>(
component: ComponentType<unknown> | TemplateRef<unknown>,
options?: Partial<HlmDialogOptions<TContext>>,
): BrnDialogRef<TResult> {
const mergedOptions = {
...(options ?? {}),
backdropClass: cssClassesToArray(`${hlmDialogOverlayClass} ${options?.backdropClass ?? ''}`),
context: {
...(options?.context && typeof options.context === 'object' ? options.context : {}),
$component: component,
$dynamicComponentClass: options?.contentClass,
$showCloseButton: options?.showCloseButton,
$closeLabel: options?.closeLabel,
},
};
return this._brnDialogService.open<unknown, TResult>(
HlmDialogContent,
undefined,
mergedOptions.context,
mergedOptions,
);
}
}
@Component({
selector: 'hlm-dialog',
exportAs: 'hlmDialog',
imports: [HlmDialogOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDialog),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog-overlay />
<ng-content />
`,
})
export class HlmDialog extends BrnDialog {}
export const HlmDialogImports = [
HlmDialog,
HlmDialogContent,
HlmDialogDescription,
HlmDialogFooter,
HlmDialogHeader,
HlmDialogOverlay,
HlmDialogPortal,
HlmDialogTitle,
HlmDialogTrigger,
HlmDialogClose,
] as const;Usage
import { HlmDialogImports } from '@spartan-ng/helm/dialog';<hlm-dialog>
<button hlmDialogTrigger hlmBtn variant="outline">Open Dialog</button>
<hlm-dialog-content *hlmDialogPortal="let ctx">
<hlm-dialog-header>
<h3 hlmDialogTitle>Edit profile</h3>
<p hlmDialogDescription>Make changes to your profile here. Click save when you're done.</p>
</hlm-dialog-header>
<hlm-dialog-footer>
<button hlmBtn variant="outline" hlmDialogClose>Cancel</button>
<button hlmBtn type="submit">Save changes</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>Examples
No Close Button
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-dialog-no-close-button',
imports: [HlmDialogImports, HlmFieldImports, HlmInputImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog>
<button hlmDialogTrigger hlmBtn variant="outline">No Close Button</button>
<hlm-dialog-content [showCloseButton]="false" *hlmDialogPortal="let ctx" class="sm:max-w-sm">
<hlm-dialog-header>
<h3 hlmDialogTitle>No Close Button</h3>
<p hlmDialogDescription>This dialog does not have a close button in the header.</p>
</hlm-dialog-header>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogNoCloseButton {}Dismiss Options
Use disableClose to block every user-initiated dismissal (Escape, backdrop clicks, and outside pointer events), or closeOnOutsidePointerEvents to only control whether clicks outside the dialog close it. Hover the toggle labels in the example for a summary of each option, then open the dialog and try Escape or a backdrop click.
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmSwitchImports } from '@spartan-ng/helm/switch';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-dialog-dismiss-options',
imports: [HlmDialogImports, HlmButtonImports, HlmLabelImports, HlmSwitchImports, HlmTooltipImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="flex flex-col gap-4">
<label hlmLabel class="flex w-fit items-center" [hlmTooltip]="disableCloseTip">
<hlm-switch class="mr-2" [checked]="_disableClose()" (checkedChange)="_disableClose.set($event)" />
disableClose
</label>
<ng-template #disableCloseTip>
<div class="max-w-56 py-1 text-sm">
<p class="font-semibold">disableClose</p>
<p>Ignores Escape and outside clicks. Only a close button can close the dialog.</p>
</div>
</ng-template>
<label hlmLabel class="flex w-fit items-center" [hlmTooltip]="outsideClickTip">
<hlm-switch
class="mr-2"
[checked]="_closeOnOutsidePointerEvents()"
(checkedChange)="_closeOnOutsidePointerEvents.set($event)"
/>
closeOnOutsidePointerEvents
</label>
<ng-template #outsideClickTip>
<div class="max-w-56 py-1 text-sm">
<p class="font-semibold">closeOnOutsidePointerEvents</p>
<p>When off, outside clicks no longer close the dialog. Escape still works.</p>
</div>
</ng-template>
<hlm-dialog [disableClose]="_disableClose()" [closeOnOutsidePointerEvents]="_closeOnOutsidePointerEvents()">
<button hlmDialogTrigger hlmBtn variant="outline" class="w-fit">Open Dialog</button>
<hlm-dialog-content *hlmDialogPortal="let ctx" class="sm:max-w-md">
<hlm-dialog-header>
<h3 hlmDialogTitle>Dismiss options</h3>
<p hlmDialogDescription>
Press Escape or click the backdrop to see how the dialog reacts to the selected options.
</p>
</hlm-dialog-header>
<hlm-dialog-footer>
<button hlmBtn hlmDialogClose>Close</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>
</div>
`,
})
export class DialogDismissOptions {
protected readonly _disableClose = signal(false);
protected readonly _closeOnOutsidePointerEvents = signal(true);
}Sticky Footer
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-dialog-sticky-footer',
imports: [HlmDialogImports, HlmFieldImports, HlmInputImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog>
<button hlmDialogTrigger hlmBtn variant="outline">Sticky Footer</button>
<hlm-dialog-content *hlmDialogPortal="let ctx" class="sm:max-w-sm">
<hlm-dialog-header>
<h3 hlmDialogTitle>Sticky Footer</h3>
<p hlmDialogDescription>This dialog has a sticky footer that stays visible while the content scrolls.</p>
</hlm-dialog-header>
<div class="no-scrollbar -mx-4 max-h-[50vh] overflow-y-auto px-4">
@for (item of _items; track item) {
<p class="mb-4 leading-normal">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
</p>
}
</div>
<hlm-dialog-footer>
<button hlmBtn variant="outline" hlmDialogClose>Close</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogStickyFooter {
protected readonly _items = Array.from({ length: 5 }, (_, i) => i + 1);
}Scrollable Content
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-dialog-scrollable-content',
imports: [HlmDialogImports, HlmFieldImports, HlmInputImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog>
<button hlmDialogTrigger hlmBtn variant="outline">Scrollable Content</button>
<hlm-dialog-content *hlmDialogPortal="let ctx" class="sm:max-w-sm">
<hlm-dialog-header>
<h3 hlmDialogTitle>Scrollable Content</h3>
<p hlmDialogDescription>This is a dialog with scrollable content.</p>
</hlm-dialog-header>
<div class="no-scrollbar -mx-4 max-h-[50vh] overflow-y-auto px-4">
@for (item of _items; track item) {
<p class="mb-4 leading-normal">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
</p>
}
</div>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogScrollableContent {
protected readonly _items = Array.from({ length: 5 }, (_, i) => i + 1);
}Declarative Usage
Spartan's dialog supports declarative usage. Simply set it's state input to open or closed and let spartan handle the rest. This allows you to leverage the power of declarative code, like listening to changes in an input field, debouncing the value, and opening the dialog only if the user's enters the correct passphrase.
Enter passphrase to open dialog
Hint: It's sparta
import { Component, signal } from '@angular/core';
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmInputImports } from '@spartan-ng/helm/input';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmTypographyImports } from '@spartan-ng/helm/typography';
import { debounceTime, map } from 'rxjs/operators';
@Component({
selector: 'spartan-dialog-declarative-preview',
imports: [FormsModule, HlmDialogImports, HlmLabelImports, HlmInputImports, HlmTypographyImports],
template: `
<div class="mt-6 space-y-4">
<p hlmH4>Enter passphrase to open dialog</p>
<div class="flex flex-col gap-2">
<label hlmLabel for="passphrase" class="px-1">Passphrase</label>
<input
id="passphrase"
name="passphrase"
hlmInput
[ngModelOptions]="{ standalone: true }"
[ngModel]="_passphrase()"
(ngModelChange)="_passphrase.set($event)"
/>
<p hlmMuted class="px-1">Hint: It's sparta</p>
</div>
</div>
<hlm-dialog [state]="_state()" (closed)="_passphrase.set('')">
<hlm-dialog-content *hlmDialogPortal="let ctx">
<hlm-dialog-header class="w-[250px]">
<h3 hlmDialogTitle>Welcome to Sparta</h3>
<p hlmDialogDescription>Enjoy declarative dialogs.</p>
</hlm-dialog-header>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogDeclarativePreview {
protected readonly _passphrase = signal<string>('');
private readonly _debouncedState$ = toObservable(this._passphrase).pipe(
debounceTime(500),
map((passphrase) => (passphrase === 'sparta' ? 'open' : 'closed')),
);
protected readonly _state = toSignal(this._debouncedState$, { initialValue: 'closed' as 'open' | 'closed' });
}Inside Menu
Use the hlmDialogTriggerFor on the menu button, which takes in a reference to the hlm-dialog, to open the dialog from within a menu.
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-dialog-context-menu',
imports: [HlmDialogImports, HlmButtonImports, HlmDropdownMenuImports, HlmContextMenuImports],
template: `
<div
[hlmContextMenuTrigger]="menu"
class="border-border flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm"
>
Right click here
</div>
<ng-template #menu>
<hlm-dropdown-menu class="w-64">
<hlm-dropdown-menu-group>
<button inset hlmDropdownMenuItem>
Save
<hlm-dropdown-menu-shortcut>⌘S</hlm-dropdown-menu-shortcut>
</button>
<button disabled inset hlmDropdownMenuItem>
Archive
<hlm-dropdown-menu-shortcut>⌘A</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem inset="true" [hlmDialogTriggerFor]="dialog">
Print
<hlm-dropdown-menu-shortcut>⌘P</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
<hlm-dialog #dialog>
<hlm-dialog-content class="sm:max-w-[425px]" *hlmDialogPortal="let ctx">
<hlm-dialog-header>
<h3 hlmDialogTitle>Print this page</h3>
<p hlmDialogDescription>
Are you sure you want to print this page? Only print if absolutely necessary! The less we print, the less
paper we need, the better it is for our environment!
</p>
</hlm-dialog-header>
<hlm-dialog-footer>
<button hlmBtn variant="ghost" (click)="ctx.close()">Cancel</button>
<button hlmBtn>Print</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogContextMenuPreview {}Dynamic Component
You can dynamically open a dialog with a component rendered as the content. The dialog context can be injected into the dynamic component using the provided injectBrnDialogContext function.
Note
Avoid using the <hlm-dialog-content> tag when your dialog relies on dynamic content. Using it in this case can cause the dialog to repeatedly render itself in a loop. The tag is meant to wrap static content for the dialog, but with a dynamic component, the component automatically acts as the wrapper.
import { Component, inject } from '@angular/core';
import { BrnDialogRef, injectBrnDialogContext } from '@spartan-ng/brain/dialog';
import { HlmButton } from '@spartan-ng/helm/button';
import { HlmDialogDescription, HlmDialogHeader, HlmDialogService, HlmDialogTitle } from '@spartan-ng/helm/dialog';
import { HlmTableImports } from '@spartan-ng/helm/table';
type ExampleUser = {
name: string;
email: string;
phone: string;
};
@Component({
selector: 'spartan-dialog-dynamic-component-preview',
imports: [HlmButton],
template: `
<button hlmBtn (click)="openDynamicComponent()">Select User</button>
`,
})
export class DialogDynamicPreview {
private readonly _hlmDialogService = inject(HlmDialogService);
private readonly _users: ExampleUser[] = [
{
name: 'Helena Chambers',
email: 'helenachambers@chorizon.com',
phone: '+1 (812) 588-3759',
},
{
name: 'Josie Crane',
email: 'josiecrane@hinway.com',
phone: '+1 (884) 523-3324',
},
{
name: 'Lou Hartman',
email: 'louhartman@optyk.com',
phone: '+1 (912) 479-3998',
},
{
name: 'Lydia Zimmerman',
email: 'lydiazimmerman@ultrasure.com',
phone: '+1 (944) 511-2111',
},
];
public openDynamicComponent() {
const dialogRef = this._hlmDialogService.open(SelectUser, {
context: {
users: this._users,
},
contentClass: 'sm:!max-w-[750px]',
});
dialogRef.closed$.subscribe((user) => {
if (user) {
console.log('Selected user:', user);
}
});
}
}
@Component({
selector: 'spartan-dynamic-content',
imports: [HlmDialogHeader, HlmDialogTitle, HlmDialogDescription, ...HlmTableImports],
host: {
class: 'flex flex-col gap-4',
},
template: `
<hlm-dialog-header>
<h3 hlmDialogTitle>Select user</h3>
<p hlmDialogDescription>Click a row to select a user.</p>
</hlm-dialog-header>
<table hlmTable class="w-full">
<tr hlmTr>
<th hlmTh>Name</th>
<th hlmTh>Email</th>
<th hlmTh>Phone</th>
</tr>
@for (user of _users; track user.name) {
<tr hlmTr (click)="selectUser(user)" class="cursor-pointer">
<td hlmTd truncate class="font-medium">{{ user.name }}</td>
<td hlmTd>{{ user.email }}</td>
<td hlmTd>{{ user.phone }}</td>
</tr>
}
</table>
`,
})
class SelectUser {
private readonly _dialogRef = inject<BrnDialogRef<ExampleUser>>(BrnDialogRef);
private readonly _dialogContext = injectBrnDialogContext<{ users: ExampleUser[] }>();
protected readonly _users = this._dialogContext.users;
public selectUser(user: ExampleUser) {
this._dialogRef.close(user);
}
}Close Dialog
You can close the dialog by using a directive, a template reference, or a viewchild/contentchild reference to the dialog.
import { Component, viewChild } from '@angular/core';
import { BrnDialog } from '@spartan-ng/brain/dialog';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmLabelImports } from '@spartan-ng/helm/label';
@Component({
selector: 'spartan-dialog-close-preview',
imports: [HlmDialogImports, HlmLabelImports, HlmButtonImports],
template: `
<hlm-dialog #dialogRef>
<button id="edit-profile" hlmDialogTrigger hlmBtn>Open</button>
<hlm-dialog-content class="sm:max-w-[425px]" *hlmDialogPortal="let ctx">
<hlm-dialog-header>
<h3 hlmDialogTitle>Dialog</h3>
</hlm-dialog-header>
<div class="grid gap-4 py-4">
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by directive</label>
<button hlmBtn hlmDialogClose>Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by reference</label>
<button hlmBtn (click)="dialogRef.close({})">Close</button>
</div>
<div class="flex items-center justify-between gap-4">
<label hlmLabel>Close dialog by viewchild reference</label>
<button hlmBtn (click)="closeDialog()">Close</button>
</div>
</div>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogClosePreview {
public readonly viewchildDialogRef = viewChild(BrnDialog);
closeDialog() {
this.viewchildDialogRef()?.close({});
}
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDialogImports } from '@spartan-ng/helm/dialog';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-dialog-rtl',
imports: [HlmDialogImports, HlmFieldImports, HlmInputImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-dialog [dir]="_dir()">
<button hlmDialogTrigger hlmBtn variant="outline">{{ _t()['openDialog'] }}</button>
<hlm-dialog-content *hlmDialogPortal="let ctx" class="sm:max-w-sm" [dir]="_dir()">
<hlm-dialog-header>
<h3 hlmDialogTitle>{{ _t()['editProfile'] }}</h3>
<p hlmDialogDescription>{{ _t()['description'] }}</p>
</hlm-dialog-header>
<hlm-field-group>
<hlm-field>
<label hlmFieldLabel for="name">{{ _t()['name'] }}</label>
<input hlmInput id="name" value="Pedro Duarte" />
</hlm-field>
<hlm-field>
<label hlmFieldLabel for="username">{{ _t()['username'] }}</label>
<input hlmInput id="username" value="@peduarte" />
</hlm-field>
</hlm-field-group>
<hlm-dialog-footer>
<button hlmBtn variant="outline" hlmDialogClose>{{ _t()['cancel'] }}</button>
<button hlmBtn type="submit">{{ _t()['saveChanges'] }}</button>
</hlm-dialog-footer>
</hlm-dialog-content>
</hlm-dialog>
`,
})
export class DialogRtl {
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
openDialog: 'Open Dialog',
editProfile: 'Edit profile',
description: "Make changes to your profile here. Click save when you're done.",
name: 'Name',
username: 'Username',
cancel: 'Cancel',
saveChanges: 'Save changes',
},
},
ar: {
dir: 'rtl',
values: {
openDialog: 'فتح الحوار',
editProfile: 'تعديل الملف الشخصي',
description: 'قم بإجراء تغييرات على ملفك الشخصي هنا. انقر فوق حفظ عند الانتهاء.',
name: 'الاسم',
username: 'اسم المستخدم',
cancel: 'إلغاء',
saveChanges: 'حفظ التغييرات',
},
},
he: {
dir: 'rtl',
values: {
openDialog: 'פתח דיאלוג',
editProfile: 'ערוך פרופיל',
description: 'בצע שינויים בפרופיל שלך כאן. לחץ על שמור כשתסיים.',
name: 'שם',
username: 'שם משתמש',
cancel: 'בטל',
saveChanges: 'שמור שינויים',
},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
}Brain API
BrnDialogClose
Selector: button[brnDialogClose]
ExportAs: brnDialogClose
BrnDialogContent
Selector: [brnDialogContent]
ExportAs: brnDialogContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | null | undefined | undefined | - |
| context | T | undefined | undefined | - |
BrnDialogDescription
Selector: [brnDialogDescription]
ExportAs: brnDialogDescription
BrnDialogOverlay
Selector: [brnDialogOverlay],brn-dialog-overlay
ExportAs: brnDialogOverlay
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | null | undefined | undefined | - |
BrnDialogTitle
Selector: [brnDialogTitle]
ExportAs: brnDialogTitle
BrnDialogTrigger
Selector: button[brnDialogTrigger],button[brnDialogTriggerFor]
ExportAs: brnDialogTrigger
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-dialog-trigger-${++triggerIdSequence}` | - |
| type | 'button' | 'submit' | 'reset' | 'button' | - |
| brnDialogTriggerFor | BrnDialog | undefined | undefined | - |
BrnDialog
Selector: [brnDialog],brn-dialog
ExportAs: brnDialog
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | nextBrnDialogId() | - |
| state | BrnDialogState | null | null | - |
| role | BrnDialogOptions['role'] | this._defaultOptions.role | - |
| hasBackdrop | boolean | this._defaultOptions.hasBackdrop | - |
| positionStrategy | BrnDialogOptions['positionStrategy'] | this._defaultOptions.positionStrategy | - |
| scrollStrategy | BrnDialogOptions['scrollStrategy'] | 'close' | 'reposition' | null | this._defaultOptions.scrollStrategy | - |
| restoreFocus | BrnDialogOptions['restoreFocus'] | this._defaultOptions.restoreFocus | - |
| closeOnOutsidePointerEvents | boolean | this._defaultOptions.closeOnOutsidePointerEvents | - |
| attachTo | BrnDialogOptions['attachTo'] | this._defaultOptions.attachTo | - |
| attachPositions | BrnDialogOptions['attachPositions'] | this._defaultOptions.attachPositions | - |
| autoFocus | BrnDialogOptions['autoFocus'] | this._defaultOptions.autoFocus | - |
| disableClose | boolean | this._defaultOptions.disableClose | - |
| aria-describedby | BrnDialogOptions['ariaDescribedBy'] | this._defaultOptions.ariaDescribedBy | - |
| aria-labelledby | BrnDialogOptions['ariaLabelledBy'] | this._defaultOptions.ariaLabelledBy | - |
| aria-label | BrnDialogOptions['ariaLabel'] | this._defaultOptions.ariaLabel | - |
| aria-modal | boolean | this._defaultOptions.ariaModal | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| closed | TResult | - | - |
| stateChanged | BrnDialogState | - | - |
Helm API
HlmDialogClose
Selector: button[hlmDialogClose]
ExportAs: hlmDialogClose
HlmDialogContent
Selector: hlm-dialog-content
ExportAs: hlmDialogContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| showCloseButton | boolean | this._dialogContext?.$showCloseButton ?? true | - |
| closeLabel | string | this._dialogContext?.$closeLabel ?? 'Close' | - |
HlmDialogDescription
Selector: [hlmDialogDescription]
ExportAs: hlmDialogDescription
HlmDialogFooter
Selector: [hlmDialogFooter],hlm-dialog-footer
ExportAs: hlmDialogFooter
HlmDialogHeader
Selector: [hlmDialogHeader],hlm-dialog-header
ExportAs: hlmDialogHeader
HlmDialogOverlay
Selector: [hlmDialogOverlay],hlm-dialog-overlay
ExportAs: hlmDialogOverlay
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | ClassValue | '' | - |
HlmDialogPortal
Selector: [hlmDialogPortal]
ExportAs: hlmDialogPortal
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| context | T | undefined | undefined | - |
| class | string | null | undefined | undefined | - |
HlmDialogTitle
Selector: [hlmDialogTitle]
ExportAs: hlmDialogTitle
HlmDialogTrigger
Selector: button[hlmDialogTrigger],button[hlmDialogTriggerFor]
ExportAs: hlmDialogTrigger
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-dialog-trigger-${++triggerIdSequence}` | - |
| hlmDialogTriggerFor | BrnDialog | undefined | undefined | - |
| type | 'button' | 'submit' | 'reset' | 'button' | - |
HlmDialog
Selector: hlm-dialog
ExportAs: hlmDialog
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | nextBrnDialogId() | - |
| state | BrnDialogState | null | null | - |
| role | BrnDialogOptions['role'] | this._defaultOptions.role | - |
| hasBackdrop | boolean | this._defaultOptions.hasBackdrop | - |
| positionStrategy | BrnDialogOptions['positionStrategy'] | this._defaultOptions.positionStrategy | - |
| scrollStrategy | BrnDialogOptions['scrollStrategy'] | 'close' | 'reposition' | null | this._defaultOptions.scrollStrategy | - |
| restoreFocus | BrnDialogOptions['restoreFocus'] | this._defaultOptions.restoreFocus | - |
| closeOnOutsidePointerEvents | boolean | this._defaultOptions.closeOnOutsidePointerEvents | - |
| attachTo | BrnDialogOptions['attachTo'] | this._defaultOptions.attachTo | - |
| attachPositions | BrnDialogOptions['attachPositions'] | this._defaultOptions.attachPositions | - |
| autoFocus | BrnDialogOptions['autoFocus'] | this._defaultOptions.autoFocus | - |
| disableClose | boolean | this._defaultOptions.disableClose | - |
| aria-describedby | BrnDialogOptions['ariaDescribedBy'] | this._defaultOptions.ariaDescribedBy | - |
| aria-labelledby | BrnDialogOptions['ariaLabelledBy'] | this._defaultOptions.ariaLabelledBy | - |
| aria-label | BrnDialogOptions['ariaLabel'] | this._defaultOptions.ariaLabel | - |
| aria-modal | boolean | this._defaultOptions.ariaModal | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| closed | TResult | - | - |
| stateChanged | BrnDialogState | - | - |
On This Page