- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Icon
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
Drawer
A dialog that slides in from the bottom of the screen. Designed after the macOS/iOS bottom sheet pattern.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDrawerImports } from '@spartan-ng/helm/drawer';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-drawer-preview',
imports: [HlmDrawerImports, HlmButtonImports, HlmFieldImports, HlmInputImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer>
<button id="edit-profile" hlmDrawerTrigger hlmBtn variant="outline">Open Drawer</button>
<hlm-drawer-content *hlmDrawerPortal="let ctx">
<hlm-drawer-header>
<h3 hlmDrawerTitle>Edit Profile</h3>
<p hlmDrawerDescription>Make changes to your profile here. Click save when you're done.</p>
</hlm-drawer-header>
<hlm-field-group class="px-4">
<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-drawer-footer>
<button hlmBtn type="submit">Save Changes</button>
<button hlmDrawerClose hlmBtn variant="outline">Cancel</button>
</hlm-drawer-footer>
</hlm-drawer-content>
</hlm-drawer>
`,
})
export class DrawerPreview {}Installation
ng g @spartan-ng/cli:ui drawernx g @spartan-ng/cli:ui drawerimport { DestroyRef, ElementRef, HostAttributeToken, Injector, PLATFORM_ID, effect, inject, runInInjectionContext } from '@angular/core';
import { clsx, type ClassValue } from 'clsx';
import { isPlatformBrowser } from '@angular/common';
import { twMerge } from 'tailwind-merge';
export function hlm(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// Global map to track class managers per element
const elementClassManagers = new WeakMap<HTMLElement, ElementClassManager>();
// Global mutation observer for all elements
let globalObserver: MutationObserver | null = null;
const observedElements = new Set<HTMLElement>();
interface ElementClassManager {
element: HTMLElement;
sources: Map<number, { classes: Set<string>; order: number }>;
baseClasses: Set<string>;
isUpdating: boolean;
nextOrder: number;
hasInitialized: boolean;
restoreRafId: number | null;
/** Transitions are suppressed until the first effect writes correct classes */
transitionsSuppressed: boolean;
/** Original inline transition value to restore after suppression (empty string = none was set) */
previousTransition: string;
/** Original inline transition priority to preserve !important when restoring */
previousTransitionPriority: string;
}
let sourceCounter = 0;
/**
* 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.
*
* 1. This will merge the existing classes on the element with the new classes.
* 2. It will also remove any classes that were previously added by this function but are no longer present in the new classes.
* 3. Multiple calls to this function on the same element will be merged efficiently.
*/
export function classes(computed: () => ClassValue[] | string, options: ClassesOptions = {}) {
runInInjectionContext(options.injector ?? inject(Injector), () => {
const elementRef = options.elementRef ?? inject(ElementRef);
const platformId = inject(PLATFORM_ID);
const destroyRef = inject(DestroyRef);
const baseClasses = inject(new HostAttributeToken('class'), { optional: true });
const element = elementRef.nativeElement;
// Create unique identifier for this source
const sourceId = sourceCounter++;
// Get or create the class manager for this element
let manager = elementClassManagers.get(element);
if (!manager) {
// Initialize base classes from variation (host attribute 'class')
const initialBaseClasses = new Set<string>();
if (baseClasses) {
toClassList(baseClasses).forEach((cls) => initialBaseClasses.add(cls));
}
manager = {
element,
sources: new Map(),
baseClasses: initialBaseClasses,
isUpdating: false,
nextOrder: 0,
hasInitialized: false,
restoreRafId: null,
transitionsSuppressed: false,
previousTransition: '',
previousTransitionPriority: '',
};
elementClassManagers.set(element, manager);
// Setup global observer if needed and register this element
setupGlobalObserver(platformId);
observedElements.add(element);
// Suppress transitions until the first effect writes correct classes and
// the browser has painted them. This prevents CSS transition animations
// during hydration when classes change from SSR state to client state.
if (isPlatformBrowser(platformId)) {
manager.previousTransition = element.style.getPropertyValue('transition');
manager.previousTransitionPriority = element.style.getPropertyPriority('transition');
element.style.setProperty('transition', 'none', 'important');
manager.transitionsSuppressed = true;
}
}
// Assign order once at registration time
const sourceOrder = manager.nextOrder++;
function updateClasses(): void {
// Get the new classes from the computed function
const newClasses = toClassList(computed());
// Update this source's classes, keeping the original order
manager!.sources.set(sourceId, {
classes: new Set(newClasses),
order: sourceOrder,
});
// Update the element
updateElement(manager!);
// Re-enable transitions after the first effect writes correct classes.
// Deferred to next animation frame so the browser paints the class change
// with transitions disabled first, then re-enables them.
if (manager!.transitionsSuppressed) {
manager!.transitionsSuppressed = false;
manager!.restoreRafId = requestAnimationFrame(() => {
manager!.restoreRafId = null;
restoreTransitionSuppression(manager!);
});
}
}
// Register cleanup with DestroyRef
destroyRef.onDestroy(() => {
if (manager!.restoreRafId !== null) {
cancelAnimationFrame(manager!.restoreRafId);
manager!.restoreRafId = null;
}
if (manager!.transitionsSuppressed) {
manager!.transitionsSuppressed = false;
restoreTransitionSuppression(manager!);
}
// Remove this source from the manager
manager!.sources.delete(sourceId);
// If no more sources, clean up the manager
if (manager!.sources.size === 0) {
cleanupManager(element);
} else {
// Update element without this source's classes
updateElement(manager!);
}
});
/**
* We need this effect to track changes to the computed classes. Ideally, we would use
* afterRenderEffect here, but that doesn't run in SSR contexts, so we use a standard
* effect which works in both browser and SSR.
*/
effect(updateClasses);
});
}
function restoreTransitionSuppression(manager: ElementClassManager): void {
const prev = manager.previousTransition;
if (prev) {
manager.element.style.setProperty('transition', prev, manager.previousTransitionPriority || undefined);
} else {
manager.element.style.removeProperty('transition');
}
}
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
function setupGlobalObserver(platformId: Object): void {
if (isPlatformBrowser(platformId) && !globalObserver) {
// Create single global observer that watches the entire document
globalObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const element = mutation.target as HTMLElement;
const manager = elementClassManagers.get(element);
// Only process elements we're managing
if (manager && observedElements.has(element)) {
if (manager.isUpdating) continue; // Ignore changes we're making
// Update base classes to include any externally added classes
const currentClasses = toClassList(element.className);
const allSourceClasses = new Set<string>();
// Collect all classes from all sources
for (const source of manager.sources.values()) {
for (const className of source.classes) {
allSourceClasses.add(className);
}
}
// Any classes not from sources become new base classes
manager.baseClasses.clear();
for (const className of currentClasses) {
if (!allSourceClasses.has(className)) {
manager.baseClasses.add(className);
}
}
updateElement(manager);
}
}
}
});
// Start observing the entire document for class attribute changes
globalObserver.observe(document, {
attributes: true,
attributeFilter: ['class'],
subtree: true, // Watch all descendants
});
}
}
function updateElement(manager: ElementClassManager): void {
if (manager.isUpdating) return; // Prevent recursive updates
manager.isUpdating = true;
// Handle initialization: capture base classes after first source registration
if (!manager.hasInitialized && manager.sources.size > 0) {
// Get current classes on element (may include SSR classes)
const currentClasses = toClassList(manager.element.className);
// Get all classes that will be applied by sources
const allSourceClasses = new Set<string>();
for (const source of manager.sources.values()) {
source.classes.forEach((className) => allSourceClasses.add(className));
}
// Only consider classes as "base" if they're not produced by any source
// This prevents SSR-rendered classes from being preserved as base classes
currentClasses.forEach((className) => {
if (!allSourceClasses.has(className)) {
manager.baseClasses.add(className);
}
});
manager.hasInitialized = true;
}
// Get classes from all sources, sorted by registration order (later takes precedence)
const sortedSources = Array.from(manager.sources.entries()).sort(([, a], [, b]) => a.order - b.order);
const allSourceClasses: string[] = [];
for (const [, source] of sortedSources) {
allSourceClasses.push(...source.classes);
}
// Combine base classes with all source classes, ensuring base classes take precedence
const classesToApply =
allSourceClasses.length > 0 || manager.baseClasses.size > 0
? hlm([...allSourceClasses, ...manager.baseClasses])
: '';
// Apply the classes to the element
if (manager.element.className !== classesToApply) {
manager.element.className = classesToApply;
}
manager.isUpdating = false;
}
function cleanupManager(element: HTMLElement): void {
// Remove from global tracking
observedElements.delete(element);
elementClassManagers.delete(element);
// If no more elements being tracked, cleanup global observer
if (observedElements.size === 0 && globalObserver) {
globalObserver.disconnect();
globalObserver = null;
}
}
interface ClassesOptions {
elementRef?: ElementRef<HTMLElement>;
injector?: Injector;
}
// Cache for parsed class lists to avoid repeated string operations
const classListCache = new Map<string, string[]>();
function toClassList(className: string | ClassValue[]): string[] {
// For simple string inputs, use cache to avoid repeated parsing
if (typeof className === 'string' && classListCache.has(className)) {
return classListCache.get(className)!;
}
const result = clsx(className)
.split(' ')
.filter((c) => c.length > 0);
// Cache string results, but limit cache size to prevent memory growth
if (typeof className === 'string' && classListCache.size < 1000) {
classListCache.set(className, result);
}
return result;
}import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1.5 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'bg-background fixed z-50 flex h-auto flex-col text-sm data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-xl data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-r-xl data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-l-xl data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-xl data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-sm');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1 w-[100px] shrink-0 rounded-none group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'bg-background fixed z-50 flex h-auto flex-col text-xs/relaxed data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-none data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-none data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-none data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-none data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-xs/relaxed');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-0.5 md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground text-sm font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1.5 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'before:bg-background before:border-border fixed z-50 flex h-auto flex-col bg-transparent p-4 text-sm before:absolute before:inset-2 before:-z-10 before:rounded-4xl before:border data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-sm');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground text-base font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1.5 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'before:bg-background before:border-border fixed z-50 flex h-auto flex-col bg-transparent p-2 text-xs/relaxed before:absolute before:inset-2 before:-z-10 before:rounded-xl before:border data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-xs/relaxed');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-1 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground text-sm font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'bg-background fixed z-50 flex h-auto flex-col text-sm data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-xl data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-r-xl data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-l-xl data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-xl data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-sm');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-0.5 md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 supports-backdrop-filter:backdrop-blur-xs transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground text-base font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;import { BrnDialog, provideBrnDialogDefaultOptions } from '@spartan-ng/brain/dialog';
import { BrnDrawer, BrnDrawerClose, BrnDrawerContent, BrnDrawerDescription, BrnDrawerHandle, BrnDrawerOverlay, BrnDrawerTitle, BrnDrawerTrigger } from '@spartan-ng/brain/drawer';
import { ChangeDetectionStrategy, Component, Directive, computed, effect, forwardRef, input, signal, untracked } from '@angular/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { injectCustomClassSettable, injectExposedSideProvider, injectExposesStateProvider } from '@spartan-ng/brain/core';
import { type ClassValue } from 'clsx';
@Directive({
selector: 'button[hlmDrawerClose]',
hostDirectives: [{ directive: BrnDrawerClose, inputs: ['delay'] }],
host: { 'data-slot': 'drawer-close' },
})
export class HlmDrawerClose {}
@Component({
selector: 'hlm-drawer-content',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnDrawerHandle, inputs: ['closeThreshold'] }],
host: {
'data-slot': 'drawer-content',
'[attr.data-vaul-drawer-direction]': '_sideProvider.side()',
'[attr.data-state]': 'state()',
},
template: `
<div class="bg-muted mx-auto mt-4 hidden h-1.5 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block"></div>
<ng-content />
`,
})
export class HlmDrawerContent {
private readonly _stateProvider = injectExposesStateProvider({ host: true });
protected readonly _sideProvider = injectExposedSideProvider({ host: true });
public readonly state = this._stateProvider.state ?? signal('closed');
constructor() {
classes(() => [
'before:bg-popover before:border-border fixed z-50 flex h-auto flex-col bg-transparent p-4 text-sm before:absolute before:inset-2 before:-z-10 before:rounded-4xl before:border before:shadow-xl data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:start-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:end-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm',
'group/drawer-content',
'data-open:animate-in data-closed:animate-out',
'data-[vaul-drawer-direction=bottom]:data-closed:slide-out-to-bottom data-[vaul-drawer-direction=bottom]:data-open:slide-in-from-bottom',
'data-[vaul-drawer-direction=top]:data-closed:slide-out-to-top data-[vaul-drawer-direction=top]:data-open:slide-in-from-top',
'data-[vaul-drawer-direction=left]:data-closed:slide-out-to-left data-[vaul-drawer-direction=left]:data-open:slide-in-from-left',
'data-[vaul-drawer-direction=right]:data-closed:slide-out-to-right data-[vaul-drawer-direction=right]:data-open:slide-in-from-right',
]);
}
}
@Directive({
selector: '[hlmDrawerDescription]',
hostDirectives: [BrnDrawerDescription],
host: { 'data-slot': 'drawer-description' },
})
export class HlmDrawerDescription {
constructor() {
classes(() => 'text-muted-foreground text-sm');
}
}
@Directive({
selector: '[hlmDrawerFooter],hlm-drawer-footer',
host: { 'data-slot': 'drawer-footer' },
})
export class HlmDrawerFooter {
constructor() {
classes(() => 'gap-2 p-4 mt-auto flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerHeader],hlm-drawer-header',
host: { 'data-slot': 'drawer-header' },
})
export class HlmDrawerHeader {
constructor() {
classes(() => 'gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-start flex flex-col');
}
}
@Directive({
selector: '[hlmDrawerOverlay],hlm-drawer-overlay',
hostDirectives: [BrnDrawerOverlay],
})
export class HlmDrawerOverlay {
private readonly _classSettable = injectCustomClassSettable({ optional: true, host: true });
public readonly userClass = input<ClassValue>('', { alias: 'class' });
protected readonly _computedClass = computed(() =>
hlm(
'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/30 supports-backdrop-filter:backdrop-blur-sm transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0',
this.userClass(),
),
);
constructor() {
effect(() => {
const classValue = this._computedClass();
untracked(() => this._classSettable?.setClassToCustomElement(classValue));
});
}
}
@Directive({
selector: '[hlmDrawerPortal]',
hostDirectives: [{ directive: BrnDrawerContent, inputs: ['context', 'class'] }],
})
export class HlmDrawerPortal {}
@Directive({
selector: '[hlmDrawerTitle]',
hostDirectives: [BrnDrawerTitle],
host: { 'data-slot': 'drawer-title' },
})
export class HlmDrawerTitle {
constructor() {
classes(() => 'text-foreground text-base font-medium');
}
}
@Directive({
selector: 'button[hlmDrawerTrigger]',
hostDirectives: [{ directive: BrnDrawerTrigger, inputs: ['id', 'direction', 'type'] }],
host: { 'data-slot': 'drawer-trigger' },
})
export class HlmDrawerTrigger {}
@Component({
selector: 'hlm-drawer',
exportAs: 'hlmDrawer',
imports: [HlmDrawerOverlay],
providers: [
{
provide: BrnDialog,
useExisting: forwardRef(() => HlmDrawer),
},
{
provide: BrnDrawer,
useExisting: forwardRef(() => HlmDrawer),
},
provideBrnDialogDefaultOptions({
// add custom options here
}),
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer-overlay />
<ng-content />
`,
})
export class HlmDrawer extends BrnDrawer {}
export const HlmDrawerImports = [
HlmDrawer,
HlmDrawerClose,
HlmDrawerContent,
HlmDrawerDescription,
HlmDrawerFooter,
HlmDrawerHeader,
HlmDrawerOverlay,
HlmDrawerPortal,
HlmDrawerTitle,
HlmDrawerTrigger,
] as const;Usage
import { HlmDrawerImports } from '@spartan-ng/helm/drawer';<hlm-drawer>
<button hlmDrawerTrigger hlmBtn variant="outline">Open</button>
<hlm-drawer-content *hlmDrawerPortal="let ctx">
<hlm-drawer-header>
<h3 hlmDrawerTitle>Are you absolutely sure?</h3>
<p hlmDrawerDescription>This action cannot be undone.</p>
</hlm-drawer-header>
</hlm-drawer-content>
</hlm-drawer>Examples
Direction
You can change the direction the drawer slides in from using the direction input on the trigger.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDrawerImports } from '@spartan-ng/helm/drawer';
@Component({
selector: 'spartan-drawer-direction-preview',
imports: [HlmDrawerImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer>
<div class="flex flex-wrap gap-2">
<button id="bottom" hlmDrawerTrigger direction="bottom" hlmBtn variant="outline">Bottom</button>
<button id="top" hlmDrawerTrigger direction="top" hlmBtn variant="outline">Top</button>
<button id="left" hlmDrawerTrigger direction="left" hlmBtn variant="outline">Left</button>
<button id="right" hlmDrawerTrigger direction="right" hlmBtn variant="outline">Right</button>
</div>
<hlm-drawer-content *hlmDrawerPortal="let ctx">
<hlm-drawer-header>
<h3 hlmDrawerTitle>Edit profile</h3>
<p hlmDrawerDescription>Make changes to your profile here. Click save when you're done.</p>
</hlm-drawer-header>
<div class="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.
</p>
}
</div>
<hlm-drawer-footer>
<button hlmBtn>Save changes</button>
<button hlmBtn variant="outline" hlmDrawerClose>Cancel</button>
</hlm-drawer-footer>
</hlm-drawer-content>
</hlm-drawer>
`,
})
export class DrawerDirectionPreview {
protected readonly _items = Array.from({ length: 3 }, (_, i) => i + 1);
}Nested
Drawers can be nested within each other to create multi-step or drill-down experiences. Use a nested hlm-drawer inside the content of another drawer.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDrawerImports } from '@spartan-ng/helm/drawer';
@Component({
selector: 'spartan-drawer-nested-preview',
imports: [HlmDrawerImports, HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer>
<button hlmDrawerTrigger hlmBtn variant="outline">Open Drawer</button>
<hlm-drawer-content *hlmDrawerPortal="let ctx">
<hlm-drawer-header>
<h3 hlmDrawerTitle>Profile Settings</h3>
<p hlmDrawerDescription>Manage your account settings.</p>
</hlm-drawer-header>
<div class="px-4">
<p class="mb-4 leading-normal">This is the first drawer. You can open another drawer on top of this one.</p>
<hlm-drawer>
<button hlmDrawerTrigger hlmBtn variant="outline">Open Nested</button>
<hlm-drawer-content *hlmDrawerPortal="let nestedCtx">
<hlm-drawer-header>
<h3 hlmDrawerTitle>Nested Drawer</h3>
<p hlmDrawerDescription>This drawer is nested inside the first one.</p>
</hlm-drawer-header>
<div class="px-4">
<p class="mb-4 leading-normal">Nested drawers allow you to layer content without losing context.</p>
</div>
<hlm-drawer-footer>
<button hlmDrawerClose hlmBtn variant="outline">Close</button>
</hlm-drawer-footer>
</hlm-drawer-content>
</hlm-drawer>
</div>
<hlm-drawer-footer>
<button hlmDrawerClose hlmBtn variant="outline">Close</button>
</hlm-drawer-footer>
</hlm-drawer-content>
</hlm-drawer>
`,
})
export class DrawerNestedPreview {}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 { HlmDrawerImports } from '@spartan-ng/helm/drawer';
import { HlmFieldImports } from '@spartan-ng/helm/field';
import { HlmInputImports } from '@spartan-ng/helm/input';
@Component({
selector: 'spartan-drawer-rtl',
imports: [HlmDrawerImports, HlmFieldImports, HlmButtonImports, HlmInputImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<hlm-drawer [dir]="_dir()">
<button hlmDrawerTrigger hlmBtn variant="outline">{{ _t()['open'] }}</button>
<hlm-drawer-content *hlmDrawerPortal="let ctx" [dir]="_dir()">
<hlm-drawer-header>
<h3 hlmDrawerTitle>{{ _t()['editProfile'] }}</h3>
<p hlmDrawerDescription>{{ _t()['description'] }}</p>
</hlm-drawer-header>
<hlm-field-group class="px-4">
<hlm-field>
<label hlmFieldLabel for="name-rtl">{{ _t()['name'] }}</label>
<input hlmInput id="name-rtl" value="Pedro Duarte" />
</hlm-field>
<hlm-field>
<label hlmFieldLabel for="username-rtl">{{ _t()['username'] }}</label>
<input hlmInput id="username-rtl" value="peduarte" />
</hlm-field>
</hlm-field-group>
<hlm-drawer-footer>
<button hlmBtn type="submit">{{ _t()['save'] }}</button>
<button hlmDrawerClose hlmBtn variant="outline">{{ _t()['close'] }}</button>
</hlm-drawer-footer>
</hlm-drawer-content>
</hlm-drawer>
`,
})
export class DrawerRtl {
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
open: 'Open',
editProfile: 'Edit profile',
description: "Make changes to your profile here. Click save when you're done.",
name: 'Name',
username: 'Username',
save: 'Save changes',
close: 'Close',
},
},
ar: {
dir: 'rtl',
values: {
open: 'فتح',
editProfile: 'تعديل الملف الشخصي',
description: 'قم بإجراء تغييرات على ملفك الشخصي هنا. انقر حفظ عند الانتهاء.',
name: 'الاسم',
username: 'اسم المستخدم',
save: 'حفظ التغييرات',
close: 'إغلاق',
},
},
he: {
dir: 'rtl',
values: {
open: 'פתח',
editProfile: 'עריכת פרופיל',
description: 'בצע שינויים בפרופיל שלך כאן. לחץ שמור כשתסיים.',
name: 'שם',
username: 'שם משתמש',
save: 'שמור שינויים',
close: 'סגור',
},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
}Brain API
BrnDrawerClose
Selector: button[brnDrawerClose]
BrnDrawerContent
Selector: [brnDrawerContent]
BrnDrawerDescription
Selector: [brnDrawerDescription]
BrnDrawerHandle
Selector: [brnDrawerHandle]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| closeThreshold | number | DEFAULT_CLOSE_THRESHOLD | - |
BrnDrawerOverlay
Selector: [brnDrawerOverlay],brn-drawer-overlay
BrnDrawerTitle
Selector: [brnDrawerTitle]
BrnDrawerTrigger
Selector: button[brnDrawerTrigger]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| direction | 'bottom' | 'top' | 'left' | 'right' | undefined | undefined | - |
BrnDrawer
Selector: [brnDrawer],brn-drawer
ExportAs: brnDrawer
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| direction | 'bottom' | 'top' | 'left' | 'right' | bottom | - |
Helm API
HlmDrawerClose
Selector: button[hlmDrawerClose]
HlmDrawerContent
Selector: hlm-drawer-content
HlmDrawerDescription
Selector: [hlmDrawerDescription]
HlmDrawerFooter
Selector: [hlmDrawerFooter],hlm-drawer-footer
HlmDrawerHeader
Selector: [hlmDrawerHeader],hlm-drawer-header
HlmDrawerOverlay
Selector: [hlmDrawerOverlay],hlm-drawer-overlay
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | ClassValue | - | - |
HlmDrawerPortal
Selector: [hlmDrawerPortal]
HlmDrawerTitle
Selector: [hlmDrawerTitle]
HlmDrawerTrigger
Selector: button[hlmDrawerTrigger]
HlmDrawer
Selector: hlm-drawer
ExportAs: hlmDrawer
On This Page