- 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
Accordion
A vertically stacked set of interactive headings that each reveal a section of content.
import { Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-preview',
imports: [HlmAccordionImports],
host: {
class: 'max-w-sm block h-[250px]',
},
template: `
<hlm-accordion>
<hlm-accordion-item>
<hlm-accordion-trigger>What are your shipping options?</hlm-accordion-trigger>
<hlm-accordion-content>
We offer standard (5-7 days), express (2-3 days), and overnight shipping. Free shipping on international
orders.
</hlm-accordion-content>
</hlm-accordion-item>
<hlm-accordion-item>
<hlm-accordion-trigger>What is your return policy?</hlm-accordion-trigger>
<hlm-accordion-content>
Returns accepted within 30 days. Items must be unused and in original packaging. Refunds processed within 5-7
business days.
</hlm-accordion-content>
</hlm-accordion-item>
<hlm-accordion-item>
<hlm-accordion-trigger>How can I contact customer support?</hlm-accordion-trigger>
<hlm-accordion-content>
Reach us via email, live chat, or phone. We respond within 24 hours during business days.
</hlm-accordion-content>
</hlm-accordion-item>
</hlm-accordion>
`,
})
export class AccordionPreview {}Installation
ng g @spartan-ng/cli:ui accordionnx g @spartan-ng/cli:ui accordionimport { 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 { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-2.5 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'text-sm transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'focus-visible:ring-ring/50 focus-visible:border-ring focus-visible:after:border-ring **:data-[slot=accordion-trigger-icon]:text-muted-foreground! rounded-lg py-2.5 text-start text-sm font-medium hover:underline focus-visible:ring-3 **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;import { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-4 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'text-sm transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'focus-visible:ring-ring/50 focus-visible:border-ring focus-visible:after:border-ring **:data-[slot=accordion-trigger-icon]:text-muted-foreground! rounded-md py-4 text-start text-sm font-medium hover:underline focus-visible:ring-3 **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;import { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-2.5 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'text-xs transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'focus-visible:ring-ring/50 focus-visible:border-ring focus-visible:after:border-ring **:data-[slot=accordion-trigger-icon]:text-muted-foreground! rounded-none py-2.5 text-start text-xs font-medium hover:underline focus-visible:ring-1 **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;import { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-4 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'px-4 text-sm transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'data-open:bg-muted/50 not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'**:data-[slot=accordion-trigger-icon]:text-muted-foreground! gap-6 p-4 text-start text-sm font-medium hover:underline **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'overflow-hidden rounded-2xl border flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;import { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-4 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'px-2 text-xs/relaxed transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'data-open:bg-muted/50 not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'**:data-[slot=accordion-trigger-icon]:text-muted-foreground! gap-6 p-2 text-start text-xs/relaxed font-medium hover:underline **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'overflow-hidden rounded-md border flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;import { BrnAccordion, BrnAccordionContent, BrnAccordionContentLazy, BrnAccordionImports, BrnAccordionItem } from '@spartan-ng/brain/accordion';
import { ChangeDetectionStrategy, Component, Directive, computed, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { classes, hlm } from '@spartan-ng/helm/utils';
import { lucideChevronDown, lucideChevronUp } from '@ng-icons/lucide';
import { type ClassValue } from 'cn';
@Directive({
selector: 'ng-template[hlmAccordionContentLazy]',
exportAs: 'hlmAccordionContentLazy',
hostDirectives: [BrnAccordionContentLazy],
})
export class HlmAccordionContentLazy {}
@Component({
selector: 'hlm-accordion-content',
exportAs: 'hlmAccordionContent',
changeDetection: ChangeDetectionStrategy.OnPush,
hostDirectives: [{ directive: BrnAccordionContent, inputs: ['style'] }],
host: {
'data-slot': 'accordion-content',
},
template: `
<div
class="pt-0 pb-4 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4"
>
<ng-content />
</div>
`,
})
export class HlmAccordionContent {
constructor() {
classes(
() =>
'px-4 text-sm transition-all data-[state=closed]:h-0 data-[state=open]:h-(--brn-accordion-content-height)',
);
}
}
@Directive({
selector: '[hlmAccordionItem],hlm-accordion-item',
exportAs: 'hlmAccordionItem',
hostDirectives: [
{
directive: BrnAccordionItem,
inputs: ['isOpened', 'disabled'],
outputs: ['openedChange'],
},
],
host: {
'data-slot': 'accordion-item',
},
})
export class HlmAccordionItem {
constructor() {
classes(() => 'data-open:bg-muted/50 not-last:border-b flex flex-col');
}
}
@Component({
selector: 'hlm-accordion-trigger',
exportAs: 'hlmAccordionTrigger',
imports: [BrnAccordionImports, NgIcon],
providers: [provideIcons({ lucideChevronDown, lucideChevronUp })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h3 brnAccordionHeader class="flex">
<button brnAccordionTrigger data-slot="accordion-trigger" [class]="_computedTriggerClass()">
<ng-content />
<ng-icon
name="lucideChevronDown"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
/>
<ng-icon
name="lucideChevronUp"
data-slot="accordion-trigger-icon"
class="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:inline group-aria-[expanded=false]/accordion-trigger:hidden"
/>
</button>
</h3>
`,
})
export class HlmAccordionTrigger {
public readonly triggerClass = input<ClassValue>('');
protected readonly _computedTriggerClass = computed(() =>
hlm(
'**:data-[slot=accordion-trigger-icon]:text-muted-foreground! gap-6 p-4 text-start text-sm font-medium hover:underline **:data-[slot=accordion-trigger-icon]:ms-auto **:data-[slot=accordion-trigger-icon]:text-[length:--spacing(4)] group/accordion-trigger relative flex flex-1 items-start justify-between border border-transparent transition-all outline-none aria-disabled:pointer-events-none aria-disabled:opacity-50',
this.triggerClass(),
),
);
}
@Directive({
selector: '[hlmAccordion], hlm-accordion',
exportAs: 'hlmAccordion',
hostDirectives: [{ directive: BrnAccordion, inputs: ['type', 'orientation'] }],
host: {
'data-slot': 'accordion',
},
})
export class HlmAccordion {
constructor() {
classes(() => 'overflow-hidden rounded-2xl border flex w-full flex-col');
}
}
export const HlmAccordionImports = [
HlmAccordion,
HlmAccordionItem,
HlmAccordionContent,
HlmAccordionContentLazy,
HlmAccordionTrigger,
] as const;Usage
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';<hlm-accordion>
<hlm-accordion-item>
<hlm-accordion-trigger>Is it accessible?</hlm-accordion-trigger>
<hlm-accordion-content> Yes. It adheres to the WAI-ARIA design pattern. </hlm-accordion-content>
</hlm-accordion-item>
</hlm-accordion>Examples
Multiple
The type input can be set to 'multiple' to allow multiple items to be opened at the same time.
The isOpened input can be used to set the initial state of an accordion item.
import { Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-multiple',
imports: [HlmAccordionImports],
host: {
class: 'max-w-sm h-[380px] flex flex-col justify-between',
},
template: `
<hlm-accordion type="multiple">
@for (item of items; track item.value; let i = $index) {
<hlm-accordion-item [isOpened]="i === 0">
<hlm-accordion-trigger>{{ item.trigger }}</hlm-accordion-trigger>
<hlm-accordion-content>{{ item.content }}</hlm-accordion-content>
</hlm-accordion-item>
}
</hlm-accordion>
`,
})
export class AccordionMultiple {
public items = [
{
value: 'notifications',
trigger: 'Notification Settings',
content:
'Manage how you receive notifications. You can enable email alerts for updates or push notifications for mobile devices.',
},
{
value: 'privacy',
trigger: 'Privacy & Security',
content:
'Control your privacy settings and security preferences. Enable two-factor authentication, manage connected devices, review active sessions, and configure data sharing preferences. You can also download your data or delete your account.',
},
{
value: 'billing',
trigger: 'Billing & Subscription',
content:
'View your current plan, payment history, and upcoming invoices. Update your payment method, change your subscription tier, or cancel your subscription.',
},
];
}Disabled
Use the disabled prop on the hlm-accordion-item to disable an item.
import { Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-disabled',
imports: [HlmAccordionImports],
host: {
class: 'max-w-sm h-[250px]',
},
template: `
<hlm-accordion>
<hlm-accordion-item>
<hlm-accordion-trigger>Can I access my account history?</hlm-accordion-trigger>
<hlm-accordion-content>
Yes, you can view your complete account history including all transactions, plan changes, and support tickets
in the Account History section of your dashboard.
</hlm-accordion-content>
</hlm-accordion-item>
<hlm-accordion-item disabled>
<hlm-accordion-trigger>Premium feature information</hlm-accordion-trigger>
<hlm-accordion-content>
This section contains information about premium features. Upgrade your plan to access this content.
</hlm-accordion-content>
</hlm-accordion-item>
<hlm-accordion-item>
<hlm-accordion-trigger>How do I update my email address?</hlm-accordion-trigger>
<hlm-accordion-content>
You can update your email address in your account settings. You'll receive a verification email at your new
address to confirm the change.
</hlm-accordion-content>
</hlm-accordion-item>
</hlm-accordion>
`,
})
export class AccordionDisabled {}Borders
Add border to the hlm-accordion and border-b last:border-b-0 to the hlm-accordion-item to add borders to the items.
import { Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-borders',
imports: [HlmAccordionImports],
host: {
class: 'max-w-lg h-[320px] flex flex-col justify-between',
},
template: `
<hlm-accordion class="rounded-lg border">
@for (item of items; track $index) {
<hlm-accordion-item class="border-b px-4 last:border-b-0">
<hlm-accordion-trigger>
{{ item.trigger }}
</hlm-accordion-trigger>
<hlm-accordion-content>{{ item.content }}</hlm-accordion-content>
</hlm-accordion-item>
}
</hlm-accordion>
`,
})
export class AccordionBorders {
public items = [
{
value: 'billing',
trigger: 'How does billing work?',
content:
'We offer monthly and annual subscription plans. Billing is charged at the beginning of each cycle, and you can cancel anytime. All plans include automatic backups, 24/7 support, and unlimited team members.',
},
{
value: 'security',
trigger: 'Is my data secure?',
content:
'Yes. We use end-to-end encryption, SOC 2 Type II compliance, and regular third-party security audits. All data is encrypted at rest and in transit using industry-standard protocols.',
},
{
value: 'integration',
trigger: 'What integrations do you support?',
content:
'We integrate with 500+ popular tools including Slack, Zapier, Salesforce, HubSpot, and more. You can also build custom integrations using our REST API and webhooks.',
},
];
}Dynamic content
Content added or removed with @if (or any async data) is measured as it changes, so the panel animates to fit its new height while it stays open.
Your plan includes analytics, alerts, and email support.
import { Component, signal } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
import { HlmButtonImports } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-accordion-dynamic',
imports: [HlmAccordionImports, HlmButtonImports],
host: {
class: 'block max-w-sm',
},
template: `
<hlm-accordion>
<hlm-accordion-item isOpened>
<hlm-accordion-trigger>What's included in my plan?</hlm-accordion-trigger>
<hlm-accordion-content>
<p>Your plan includes analytics, alerts, and email support.</p>
@if (showDetails()) {
<ul class="mt-2 list-disc pl-4">
<li>Priority support</li>
<li>Custom dashboards</li>
<li>Unlimited team seats</li>
</ul>
}
<button hlmBtn size="sm" variant="outline" class="mt-3" (click)="showDetails.set(!showDetails())">
{{ showDetails() ? 'Hide' : 'Show' }} details
</button>
</hlm-accordion-content>
</hlm-accordion-item>
</hlm-accordion>
`,
})
export class AccordionDynamic {
public readonly showDetails = signal(false);
}Card
Wrap the hlm-accordion inside a hlm-card component.
Subscription & Billing
Common questions about your account, plans, payments and cancellations.
import { Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
import { HlmCardImports } from '@spartan-ng/helm/card';
@Component({
selector: 'spartan-accordion-card',
imports: [HlmAccordionImports, HlmCardImports],
host: {
class: 'max-w-lg h-[32rem] md:h-[28rem] flex flex-col justify-between',
},
template: `
<hlm-card class="w-full max-w-sm">
<hlm-card-header>
<h3 hlmCardTitle>Subscription & Billing</h3>
<p hlmCardDescription>Common questions about your account, plans, payments and cancellations.</p>
</hlm-card-header>
<div hlmCardContent>
<hlm-accordion>
@for (item of items; track $index) {
<hlm-accordion-item>
<hlm-accordion-trigger>
{{ item.trigger }}
</hlm-accordion-trigger>
<hlm-accordion-content>
{{ item.content }}
</hlm-accordion-content>
</hlm-accordion-item>
}
</hlm-accordion>
</div>
</hlm-card>
`,
})
export class AccordionCard {
public items = [
{
value: 'plans',
trigger: 'What subscription plans do you offer?',
content:
'We offer three subscription tiers: Starter ($9/month), Professional ($29/month), and Enterprise ($99/month). Each plan includes increasing storage limits, API access, priority support, and team collaboration features.',
},
{
value: 'billing',
trigger: 'How does billing work?',
content:
"Billing occurs automatically at the start of each billing cycle. We accept all major credit cards, PayPal, and ACH transfers for enterprise customers. You'll receive an invoice via email after each payment.",
},
{
value: 'cancel',
trigger: 'How do I cancel my subscription?',
content:
'You can cancel your subscription anytime from your account settings. There are no cancellation fees or penalties. Your access will continue until the end of your current billing period.',
},
];
}Lazy Loading
Use hlmAccordionContentLazy on an ng-template inside hlm-accordion-content to keep an item's content out of the DOM until it is opened for the first time. This is particularly useful when panels trigger network requests or render expensive component trees. The content is created once on first open and remains alive for subsequent opens.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-lazy',
imports: [HlmAccordionImports],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: 'block w-full max-w-sm',
},
template: `
<hlm-accordion>
<hlm-accordion-item>
<hlm-accordion-trigger>Account</hlm-accordion-trigger>
<hlm-accordion-content>
<ng-template hlmAccordionContentLazy>
<p>This content was lazily loaded when the item was first opened.</p>
</ng-template>
</hlm-accordion-content>
</hlm-accordion-item>
<hlm-accordion-item>
<hlm-accordion-trigger>Password</hlm-accordion-trigger>
<hlm-accordion-content>
<ng-template hlmAccordionContentLazy>
<p>This content was lazily loaded when the item was first opened.</p>
</ng-template>
</hlm-accordion-content>
</hlm-accordion-item>
</hlm-accordion>
`,
})
export class AccordionLazy {}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmAccordionImports } from '@spartan-ng/helm/accordion';
@Component({
selector: 'spartan-accordion-rtl',
imports: [HlmAccordionImports],
providers: [Directionality],
host: {
class: 'max-w-sm h-[250px]',
'[dir]': '_dir()',
},
template: `
<hlm-accordion>
@for (item of _items; track item.value) {
<hlm-accordion-item>
<hlm-accordion-trigger>{{ _t()[item.questionKey] }}</hlm-accordion-trigger>
<hlm-accordion-content>
{{ _t()[item.answerKey] }}
</hlm-accordion-content>
</hlm-accordion-item>
}
</hlm-accordion>
`,
})
export class AccordionRtl {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
question1: 'How do I reset my password?',
answer1:
"Click on 'Forgot Password' on the login page, enter your email address, and we'll send you a link to reset your password. ",
question2: 'Can I change my subscription plan?',
answer2:
'Yes, you can upgrade or downgrade your plan at any time from your account settings. Changes will be reflected in your next billing cycle.',
question3: 'What payment methods do you accept?',
answer3:
'We accept all major credit cards, PayPal, and bank transfers. All payments are processed securely through our payment partners.',
},
},
ar: {
dir: 'rtl',
values: {
question1: 'كيف يمكنني إعادة تعيين كلمة المرور؟',
answer1:
"انقر على 'نسيت كلمة المرور' في صفحة تسجيل الدخول، أدخل عنوان بريدك الإلكتروني، وسنرسل لك رابطًا لإعادة تعيين كلمة المرور. سينتهي صلاحية الرابط خلال 24 ساعة.",
question2: 'هل يمكنني تغيير خطة الاشتراك الخاصة بي؟',
answer2: 'نعم، يمكنك ترقية أو تخفيض خطتك في أي وقت من إعدادات حسابك. ستظهر التغييرات في دورة الفوترة التالية.',
question3: 'ما هي طرق الدفع التي تقبلونها؟',
answer3:
'نقبل جميع بطاقات الائتمان الرئيسية و PayPal والتحويلات المصرفية. تتم معالجة جميع المدفوعات بأمان من خلال شركاء الدفع لدينا.',
},
},
he: {
dir: 'rtl',
values: {
question1: 'איך אני מאפס את הסיסמה שלי?',
answer1:
"לחץ על 'שכחתי סיסמה' בעמוד ההתחברות, הזן את כתובת האימייל שלך, ונשלח לך קישור לאיפוס הסיסמה. הקישור יפוג תוך 24 שעות.",
question2: 'האם אני יכול לשנות את תוכנית המנוי שלי?',
answer2:
'כן, אתה יכול לשדרג או להוריד את התוכנית שלך בכל עת מההגדרות של החשבון שלך. השינויים יבואו לידי ביטוי במחזור החיוב הבא.',
question3: 'אילו אמצעי תשלום אתם מקבלים?',
answer3: 'אנו מקבלים כרטיסי אשראי, PayPal והעברות בנקאיות.',
},
},
};
protected readonly _items = [
{
value: 'item-1',
questionKey: 'question1' as const,
answerKey: 'answer1' as const,
},
{
value: 'item-2',
questionKey: 'question2' as const,
answerKey: 'answer2' as const,
},
{
value: 'item-3',
questionKey: 'question3' as const,
answerKey: 'answer3' as const,
},
];
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnAccordionContentLazy
Selector: ng-template[brnAccordionContentLazy]
ExportAs: brnAccordionContentLazy
BrnAccordionContent
Selector: brn-accordion-content,[brnAccordionContent]
ExportAs: brnAccordionContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| style | string | 'overflow: hidden' | The style to be applied to the host element after the dimensions are calculated. |
BrnAccordionHeader
Selector: [brnAccordionHeader]
ExportAs: brnAccordionHeader
BrnAccordionItem
Selector: [brnAccordionItem]
ExportAs: brnAccordionItem
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| isOpened | boolean | false | Whether the item is opened or closed. |
| disabled | boolean | false | Whether the item is disabled. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| stateChange | 'open' | 'closed' | - | Emits boolean when the item is opened or closed. |
| openedChange | boolean | - | Emits state change when item is opened or closed |
BrnAccordionTrigger
Selector: button[brnAccordionTrigger]
ExportAs: brnAccordionTrigger
BrnAccordion
Selector: [brnAccordion]
ExportAs: brnAccordion
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'single' | 'multiple' | 'single' | Whether the accordion is in single or multiple mode. |
| orientation | 'horizontal' | 'vertical' | 'vertical' | The orientation of the accordion, either 'horizontal' or 'vertical'. |
Helm API
HlmAccordionContentLazy
Selector: ng-template[hlmAccordionContentLazy]
ExportAs: hlmAccordionContentLazy
HlmAccordionContent
Selector: hlm-accordion-content
ExportAs: hlmAccordionContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| style | string | 'overflow: hidden' | The style to be applied to the host element after the dimensions are calculated. |
HlmAccordionItem
Selector: [hlmAccordionItem],hlm-accordion-item
ExportAs: hlmAccordionItem
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| isOpened | boolean | false | Whether the item is opened or closed. |
| disabled | boolean | false | Whether the item is disabled. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| openedChange | boolean | - | Emits state change when item is opened or closed |
HlmAccordionTrigger
Selector: hlm-accordion-trigger
ExportAs: hlmAccordionTrigger
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| triggerClass | ClassValue | '' | - |
HlmAccordion
Selector: [hlmAccordion], hlm-accordion
ExportAs: hlmAccordion
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'single' | 'multiple' | 'single' | Whether the accordion is in single or multiple mode. |
| orientation | 'horizontal' | 'vertical' | 'vertical' | The orientation of the accordion, either 'horizontal' or 'vertical'. |
On This Page