- 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
- 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
Item
A versatile component that you can use to display any content.
A simple item with title and description.
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideBadgeCheck, lucideChevronRight } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-preview',
imports: [HlmItemImports, HlmButtonImports, NgIcon, HlmIconImports],
providers: [
provideIcons({
lucideBadgeCheck,
lucideChevronRight,
}),
],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<div hlmItem variant="outline">
<div hlmItemContent>
<div hlmItemTitle>Basic Item</div>
<p hlmItemDescription>A simple item with title and description.</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="outline" size="sm">Action</button>
</div>
</div>
<a hlmItem variant="outline" size="sm">
<div hlmItemMedia>
<ng-icon hlm name="lucideBadgeCheck" size="20px" />
</div>
<div hlmItemContent>
<div hlmItemTitle>Your profile has been verified.</div>
</div>
<div hlmItemActions>
<ng-icon hlm name="lucideChevronRight" size="sm" />
</div>
</a>
`,
})
export class ItemPreview {}Installation
ng g @spartan-ng/cli:ui itemnx g @spartan-ng/cli:ui itemimport { 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 { BrnSeparator } from '@spartan-ng/brain/separator';
import { Directive, InjectionToken, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { cva, type VariantProps } from 'class-variance-authority';
import { hlmSeparatorClass } from '@spartan-ng/helm/separator';
@Directive({
selector: '[hlmItemActions],hlm-item-actions',
host: {
'data-slot': 'item-actions',
},
})
export class HlmItemActions {
constructor() {
classes(() => 'flex items-center gap-2');
}
}
@Directive({
selector: '[hlmItemContent],hlm-item-content',
host: {
'data-slot': 'item-content',
},
})
export class HlmItemContent {
constructor() {
classes(() => 'flex flex-1 flex-col gap-1 [&+[data-slot=item-content]]:flex-none');
}
}
@Directive({
selector: 'p[hlmItemDescription]',
host: {
'data-slot': 'item-description',
},
})
export class HlmItemDescription {
constructor() {
classes(() => [
'text-muted-foreground line-clamp-2 text-sm leading-normal font-normal text-balance',
'[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4',
]);
}
}
@Directive({
selector: '[hlmItemFooter],hlm-item-footer',
host: {
'data-slot': 'item-footer',
},
})
export class HlmItemFooter {
constructor() {
classes(() => 'flex basis-full items-center justify-between gap-2');
}
}
@Directive({
selector: '[hlmItemGroup],hlm-item-group',
host: { 'data-slot': 'item-group' },
})
export class HlmItemGroup {
constructor() {
classes(() => 'group/item-group flex flex-col');
}
}
@Directive({
selector: '[hlmItemHeader],hlm-item-header',
host: {
'data-slot': 'item-header',
},
})
export class HlmItemHeader {
constructor() {
classes(() => 'flex basis-full items-center justify-between gap-2');
}
}
const itemMediaVariants = cva(
'flex shrink-0 items-center justify-center gap-2 group-has-[[data-slot=item-description]]/item:translate-y-0.5 group-has-[[data-slot=item-description]]/item:self-start [&_ng-icon]:pointer-events-none',
{
variants: {
variant: {
default: 'bg-transparent',
icon: "bg-muted size-8 rounded-sm border [&_ng-icon:not([class*='text-'])]:text-base",
image: 'size-10 overflow-hidden rounded-sm [&_img]:size-full [&_img]:object-cover',
},
},
defaultVariants: {
variant: 'default',
},
},
);
export type ItemMediaVariants = VariantProps<typeof itemMediaVariants>;
@Directive({
selector: '[hlmItemMedia],hlm-item-media',
host: {
'data-slot': 'item-media',
'[attr.data-variant]': 'variant()',
},
})
export class HlmItemMedia {
private readonly _config = injectHlmItemMediaConfig();
public readonly variant = input<ItemMediaVariants['variant']>(this._config.variant);
constructor() {
classes(() => itemMediaVariants({ variant: this.variant() }));
}
}
@Directive({
selector: 'div[hlmItemSeparator]',
hostDirectives: [{ directive: BrnSeparator, inputs: ['orientation'] }],
host: { 'data-slot': 'item-separator' },
})
export class HlmItemSeparator {
constructor() {
classes(() => [hlmSeparatorClass, 'my-0']);
}
}
@Directive({
selector: '[hlmItemTitle],hlm-item-title',
host: {
'data-slot': 'item-title',
},
})
export class HlmItemTitle {
constructor() {
classes(() => 'flex w-fit items-center gap-2 text-sm leading-snug font-medium');
}
}
export interface HlmItemConfig {
variant: ItemVariants['variant'];
size: ItemVariants['size'];
}
const defaultConfig: HlmItemConfig = {
variant: 'default',
size: 'default',
};
const HlmItemConfigToken = new InjectionToken<HlmItemConfig>('HlmItemConfig');
export function provideHlmItemConfig(config: Partial<HlmItemConfig>): ValueProvider {
return { provide: HlmItemConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmItemConfig(): HlmItemConfig {
return inject(HlmItemConfigToken, { optional: true }) ?? defaultConfig;
}
export interface HlmItemMediaConfig {
variant: ItemMediaVariants['variant'];
}
const defaultMediaConfig: HlmItemMediaConfig = {
variant: 'default',
};
const HlmItemMediaConfigToken = new InjectionToken<HlmItemMediaConfig>('HlmItemMediaConfig');
export function provideHlmItemMediaConfig(config: Partial<HlmItemMediaConfig>): ValueProvider {
return { provide: HlmItemMediaConfigToken, useValue: { ...defaultMediaConfig, ...config } };
}
export function injectHlmItemMediaConfig(): HlmItemMediaConfig {
return inject(HlmItemMediaConfigToken, { optional: true }) ?? defaultMediaConfig;
}
const itemVariants = cva(
'group/item [a]:hover:bg-accent/50 focus-visible:border-ring focus-visible:ring-ring/50 flex flex-wrap items-center rounded-md border border-transparent text-sm transition-colors duration-100 outline-none focus-visible:ring-[3px] [a]:transition-colors',
{
variants: {
variant: {
default: 'bg-transparent',
outline: 'border-border',
muted: 'bg-muted/50',
},
size: {
default: 'gap-4 p-4',
sm: 'gap-2.5 px-4 py-3',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
},
);
export type ItemVariants = VariantProps<typeof itemVariants>;
@Directive({
selector: 'div[hlmItem], a[hlmItem]',
host: {
'data-slot': 'item',
'[attr.data-variant]': 'variant()',
'[attr.data-size]': 'size()',
},
})
export class HlmItem {
private readonly _config = injectHlmItemConfig();
public readonly variant = input<ItemVariants['variant']>(this._config.variant);
public readonly size = input<ItemVariants['size']>(this._config.size);
constructor() {
classes(() => itemVariants({ variant: this.variant(), size: this.size() }));
}
}
export const HlmItemImports = [
HlmItem,
HlmItemActions,
HlmItemContent,
HlmItemDescription,
HlmItemFooter,
HlmItemGroup,
HlmItemHeader,
HlmItemMedia,
HlmItemSeparator,
HlmItemTitle,
] as const;Usage
import { HlmItemImports } from '@spartan-ng/helm/item';<div hlmItem>
<div hlmItemHeader>Item Header</div>
<div hlmItemMedia />
<div hlmItemContent>
<div hlmItemTitle>Item</div>
<p hlmItemDescription>Item</div>
</p hlmItemContent>
<div hlmItemActions />
<div hlmItemFooter>Item Footer</div>
</div>Item vs Field
Use hlmField if you need to display a form input such as a checkbox, input, radio, or select. If you only need to display content such as a title, description, and actions, use hlmItem .
Variants
Standard styling with subtle background and borders.
Outlined style with clear borders and transparent background.
Subdued appearance with muted colors for secondary content.
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-variants-preview',
imports: [HlmItemImports, HlmButtonImports],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<div hlmItem>
<div hlmItemContent>
<div hlmItemTitle>Default Variant</div>
<p hlmItemDescription>Standard styling with subtle background and borders.</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="outline" size="sm">Open</button>
</div>
</div>
<div hlmItem variant="outline">
<div hlmItemContent>
<div hlmItemTitle>Outline Variant</div>
<p hlmItemDescription>Outlined style with clear borders and transparent background.</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="outline" size="sm">Open</button>
</div>
</div>
<div hlmItem variant="muted">
<div hlmItemContent>
<div hlmItemTitle>Muted Variant</div>
<p hlmItemDescription>Subdued appearance with muted colors for secondary content.</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="outline" size="sm">Open</button>
</div>
</div>
`,
})
export class ItemVariantsPreview {}Size
The hlmItem component has different sizes for different use cases. For example, you can use the sm size for a compact item or the default size for a standard item.
A simple item with title and description.
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideBadgeCheck, lucideChevronRight } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-size-preview',
imports: [HlmItemImports, HlmButtonImports, HlmIconImports],
providers: [
provideIcons({
lucideBadgeCheck,
lucideChevronRight,
}),
],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<div hlmItem variant="outline">
<div hlmItemContent>
<div hlmItemTitle>Basic Item</div>
<p hlmItemDescription>A simple item with title and description.</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="outline" size="sm">Action</button>
</div>
</div>
<a hlmItem variant="outline" size="sm" href="#">
<div hlmItemMedia>
<ng-icon hlm name="lucideBadgeCheck" size="20px" />
</div>
<div hlmItemContent>
<div hlmItemTitle>Your profile has been verified.</div>
</div>
<div hlmItemActions>
<ng-icon hlm name="lucideChevronRight" size="sm" />
</div>
</a>
`,
})
export class ItemSizePreview {}Icon
New login detected from unknown device.
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideShieldAlert } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-icon-preview',
imports: [HlmItemImports, HlmButtonImports, HlmIconImports],
providers: [
provideIcons({
lucideShieldAlert,
}),
],
host: {
class: 'flex w-full max-w-lg flex-col gap-6',
},
template: `
<div hlmItem variant="outline">
<div hlmItemMedia variant="icon">
<ng-icon hlm name="lucideShieldAlert" size="sm" />
</div>
<div hlmItemContent>
<div hlmItemTitle>Security Alert</div>
<p hlmItemDescription>New login detected from unknown device.</p>
</div>
<div hlmItemActions>
<button hlmBtn size="sm" variant="outline">Review</button>
</div>
</div>
`,
})
export class ItemIconPreview {}Avatar
Last seen 5 months ago
Invite your team to collaborate on this project.
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucidePlus } from '@ng-icons/lucide';
import { HlmAvatarImports } from '@spartan-ng/helm/avatar';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-avatar-preview',
imports: [HlmItemImports, HlmButtonImports, HlmAvatarImports, HlmIconImports],
providers: [
provideIcons({
lucidePlus,
}),
],
host: {
class: 'flex w-full max-w-lg flex-col gap-6',
},
template: `
<!-- Item 1: Evil Rabbit -->
<div hlmItem variant="outline">
<div hlmItemMedia>
<hlm-avatar class="size-10">
<img hlmAvatarImage src="https://github.com/evilrabbit.png" alt="Evil Rabbit" />
<span hlmAvatarFallback>ER</span>
</hlm-avatar>
</div>
<div hlmItemContent>
<div hlmItemTitle>Evil Rabbit</div>
<p hlmItemDescription>Last seen 5 months ago</p>
</div>
<div hlmItemActions>
<button hlmBtn size="icon-sm" variant="outline" class="rounded-full" aria-label="Invite">
<ng-icon hlm name="lucidePlus" />
</button>
</div>
</div>
<!-- Item 2: No Team Members -->
<div hlmItem variant="outline">
<div hlmItemMedia>
<div
class="*:data-[slot=avatar]:ring-background flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:grayscale"
>
<hlm-avatar class="hidden sm:flex">
<img hlmAvatarImage src="https://github.com/spartan-ng.png" alt="@spartan-ng" />
<span hlmAvatarFallback>CN</span>
</hlm-avatar>
<hlm-avatar class="hidden sm:flex">
<img hlmAvatarImage src="https://github.com/maxleiter.png" alt="@maxleiter" />
<span hlmAvatarFallback>LR</span>
</hlm-avatar>
<hlm-avatar>
<img hlmAvatarImage src="https://github.com/evilrabbit.png" alt="@evilrabbit" />
<span hlmAvatarFallback>ER</span>
</hlm-avatar>
</div>
</div>
<div hlmItemContent>
<div hlmItemTitle>No Team Members</div>
<p hlmItemDescription>Invite your team to collaborate on this project.</p>
</div>
<div hlmItemActions>
<button hlmBtn size="sm" variant="outline">Invite</button>
</div>
</div>
`,
})
export class ItemAvatarPreview {}Image
import { Component } from '@angular/core';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-image-preview',
imports: [HlmItemImports],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<div hlmItemGroup class="gap-4">
@for (song of _songs; track song.title) {
<a hlmItem variant="outline" role="listitem" href="#">
<div hlmItemMedia variant="image">
<img
[src]="'https://avatar.vercel.sh/' + song.title"
[alt]="song.title"
width="32"
height="32"
class="object-cover grayscale"
/>
</div>
<div hlmItemContent>
<div hlmItemTitle class="line-clamp-1">
{{ song.title }} -
<span class="text-muted-foreground">{{ song.album }}</span>
</div>
<p hlmItemDescription>{{ song.artist }}</p>
</div>
<div hlmItemContent class="flex-none text-center">
<p hlmItemDescription>{{ song.duration }}</p>
</div>
</a>
}
</div>
`,
})
export class ItemImagePreview {
protected readonly _songs = [
{
title: 'Midnight City Lights',
artist: 'Neon Dreams',
album: 'Electric Nights',
duration: '3:45',
},
{
title: 'Coffee Shop Conversations',
artist: 'The Morning Brew',
album: 'Urban Stories',
duration: '4:05',
},
{
title: 'Digital Rain',
artist: 'Cyber Symphony',
album: 'Binary Beats',
duration: '3:30',
},
];
}Group
spartan@ng.com
maxleiter@vercel.com
evilrabbit@vercel.com
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucidePlus } from '@ng-icons/lucide';
import { HlmAvatarImports } from '@spartan-ng/helm/avatar';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-group-preview',
imports: [HlmItemImports, HlmButtonImports, HlmIconImports, HlmAvatarImports],
providers: [
provideIcons({
lucidePlus,
}),
],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<div hlmItemGroup>
@for (person of _people; track person.username; let last = $last) {
<div hlmItem>
<div hlmItemMedia>
<hlm-avatar>
<img hlmAvatarImage [src]="person.avatar" [alt]="person.username" class="grayscale" />
<span hlmAvatarFallback>{{ person.username.charAt(0).toUpperCase() }}</span>
</hlm-avatar>
</div>
<div hlmItemContent class="gap-1">
<div hlmItemTitle>{{ person.username }}</div>
<p hlmItemDescription>{{ person.email }}</p>
</div>
<div hlmItemActions>
<button hlmBtn variant="ghost" size="icon" class="rounded-full">
<ng-icon hlm name="lucidePlus" />
</button>
</div>
</div>
@if (!last) {
<div hlmItemSeparator></div>
}
}
</div>
`,
})
export class ItemGroupPreview {
protected readonly _people = [
{
username: 'spartan-ng',
avatar: 'https://github.com/spartan-ng.png',
email: 'spartan@ng.com',
},
{
username: 'maxleiter',
avatar: 'https://github.com/maxleiter.png',
email: 'maxleiter@vercel.com',
},
{
username: 'evilrabbit',
avatar: 'https://github.com/evilrabbit.png',
email: 'evilrabbit@vercel.com',
},
];
}
``;Header
Everyday tasks and UI generation.
Advanced thinking or reasoning.
Open Source model for everyone.
import { Component } from '@angular/core';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-header-preview',
imports: [HlmItemImports],
host: {
class: 'flex w-full max-w-xl flex-col gap-6',
},
template: `
<div hlmItemGroup class="grid grid-cols-3 gap-4">
@for (model of _models; track model.name) {
<div hlmItem variant="outline">
<div hlmItemHeader>
<img
[src]="model.image"
[alt]="model.name"
width="128"
height="128"
class="aspect-square w-full rounded-sm object-cover"
/>
</div>
<div hlmItemContent>
<div hlmItemTitle>{{ model.name }}</div>
<p hlmItemDescription>{{ model.description }}</p>
</div>
</div>
}
</div>
`,
})
export class ItemHeaderPreview {
protected readonly _models = [
{
name: 'v0-1.5-sm',
description: 'Everyday tasks and UI generation.',
image: 'https://images.unsplash.com/photo-1650804068570-7fb2e3dbf888?q=80&w=640&auto=format&fit=crop',
},
{
name: 'v0-1.5-lg',
description: 'Advanced thinking or reasoning.',
image: 'https://images.unsplash.com/photo-1610280777472-54133d004c8c?q=80&w=640&auto=format&fit=crop',
},
{
name: 'v0-2.0-mini',
description: 'Open Source model for everyone.',
image: 'https://images.unsplash.com/photo-1602146057681-08560aee8cde?q=80&w=640&auto=format&fit=crop',
},
];
}Link
To render an item as a link, use a anchor element. The hover and focus states will be applied to the anchor element.
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideChevronRight, lucideExternalLink } from '@ng-icons/lucide';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-link-preview',
imports: [HlmItemImports, HlmIconImports],
providers: [
provideIcons({
lucideChevronRight,
lucideExternalLink,
}),
],
host: {
class: 'flex w-full max-w-md flex-col gap-6',
},
template: `
<a hlmItem href="#">
<div hlmItemContent>
<div hlmItemTitle>Visit our documentation</div>
<p hlmItemDescription>Learn how to get started with our components.</p>
</div>
<div hlmItemActions>
<ng-icon hlm name="lucideChevronRight" size="sm" />
</div>
</a>
<a hlmItem variant="outline" href="#" target="_blank" rel="noopener noreferrer">
<div hlmItemContent>
<div hlmItemTitle>External resource</div>
<p hlmItemDescription>Opens in a new tab with security attributes.</p>
</div>
<div hlmItemActions>
<ng-icon hlm name="lucideExternalLink" size="sm" />
</div>
</a>
`,
})
export class ItemLinkPreview {}Dropdown
import { Component } from '@angular/core';
import { provideIcons } from '@ng-icons/core';
import { lucideChevronDown } from '@ng-icons/lucide';
import { HlmAvatarImports } from '@spartan-ng/helm/avatar';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { HlmItemImports } from '@spartan-ng/helm/item';
@Component({
selector: 'spartan-item-dropdown-preview',
imports: [HlmItemImports, HlmButtonImports, HlmAvatarImports, HlmIconImports, HlmDropdownMenuImports],
providers: [
provideIcons({
lucideChevronDown,
}),
],
host: {
class: 'flex min-h-64 w-full max-w-md flex-col items-center gap-6',
},
template: `
<button hlmBtn variant="outline" size="sm" [hlmDropdownMenuTrigger]="people" class="w-fit" align="end">
Select
<ng-icon hlm name="lucideChevronDown" />
</button>
<ng-template #people>
<hlm-dropdown-menu class="w-72 [--radius:0.65rem]">
@for (person of _people; track person.email) {
<div hlmDropdownMenuItem class="p-0">
<div hlmItem size="sm" class="w-full p-2">
<div hlmItemMedia>
<hlm-avatar class="size-8">
<img hlmAvatarImage [src]="person.avatar" [alt]="person.username" class="grayscale" />
<span hlmAvatarFallback>
{{ person.username.charAt(0).toUpperCase() }}
</span>
</hlm-avatar>
</div>
<div hlmItemContent class="gap-0.5">
<div hlmItemTitle>{{ person.username }}</div>
<p hlmItemDescription>{{ person.email }}</p>
</div>
</div>
</div>
}
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ItemDropdownPreview {
protected readonly _people = [
{
username: 'spartan-ng',
avatar: 'https://github.com/spartan-ng.png',
email: 'spartan@ng.com',
},
{
username: 'maxleiter',
avatar: 'https://github.com/maxleiter.png',
email: 'maxleiter@vercel.com',
},
{
username: 'evilrabbit',
avatar: 'https://github.com/evilrabbit.png',
email: 'evilrabbit@vercel.com',
},
];
}Helm API
HlmItemActions
Selector: [hlmItemActions],hlm-item-actions
HlmItemContent
Selector: [hlmItemContent],hlm-item-content
HlmItemDescription
Selector: p[hlmItemDescription]
HlmItemFooter
Selector: [hlmItemFooter],hlm-item-footer
HlmItemGroup
Selector: [hlmItemGroup],hlm-item-group
HlmItemHeader
Selector: [hlmItemHeader],hlm-item-header
HlmItemMedia
Selector: [hlmItemMedia],hlm-item-media
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | ItemMediaVariants['variant'] | this._config.variant | - |
HlmItemSeparator
Selector: div[hlmItemSeparator]
HlmItemTitle
Selector: [hlmItemTitle],hlm-item-title
HlmItem
Selector: div[hlmItem], a[hlmItem]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | ItemVariants['variant'] | this._config.variant | - |
| size | ItemVariants['size'] | this._config.size | - |
On This Page