Button
Displays a callout for user attention.
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-preview',
imports: [HlmButton],
template: `
<button hlmBtn>Button</button>
`,
})
export class ButtonPreview {}
Installation
npx nx g @spartan-ng/cli:ui button
ng g @spartan-ng/cli:ui button
Usage
import { HlmButtonDirective } from '@spartan-ng/helm/button';
<button hlmBtn>Button</button>
Helm API
HlmButton
Selector: [hlmBtn]
ExportAs: hlmBtn
Inputs
Prop | Type | Default | Description |
---|---|---|---|
class | ClassValue | - | - |
variant | ButtonVariants['variant'] | this._config.variant | - |
size | ButtonVariants['size'] | this._config.size | - |
Examples
Secondary
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-secondary',
imports: [HlmButton],
template: `
<button hlmBtn variant="secondary">Secondary</button>
`,
})
export class ButtonSecondary {}
Destructive
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-destructive',
imports: [HlmButton],
template: `
<button hlmBtn variant="destructive">Destructive</button>
`,
})
export class ButtonDestructive {}
Outline
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-outline',
imports: [HlmButton],
template: `
<button hlmBtn variant="outline">Outline</button>
`,
})
export class ButtonOutline {}
Ghost
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-ghost',
imports: [HlmButton],
template: `
<button hlmBtn variant="ghost">Ghost</button>
`,
})
export class ButtonGhost {}
Link
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-link',
imports: [HlmButton],
template: `
<button hlmBtn variant="link">Link</button>
`,
})
export class ButtonLink {}
Icon
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideChevronRight } from '@ng-icons/lucide';
import { HlmButton } from '@spartan-ng/helm/button';
import { HlmIcon } from '@spartan-ng/helm/icon';
@Component({
selector: 'spartan-button-icon',
imports: [HlmButton, NgIcon, HlmIcon],
providers: [provideIcons({ lucideChevronRight })],
template: `
<button hlmBtn size="icon" variant="secondary" class="size-8">
<ng-icon hlm size="sm" name="lucideChevronRight" />
</button>
`,
})
export class ButtonIcon {}
With Icon
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideGitBranch } from '@ng-icons/lucide';
import { HlmButton } from '@spartan-ng/helm/button';
import { HlmIcon } from '@spartan-ng/helm/icon';
@Component({
selector: 'spartan-button-with-icon',
imports: [HlmButton, NgIcon, HlmIcon],
providers: [provideIcons({ lucideGitBranch })],
template: `
<button hlmBtn variant="outline" size="sm">
<ng-icon hlm size="sm" name="lucideGitBranch" />
New Branch
</button>
`,
})
export class ButtonWithIcon {}
Loading
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideLoaderCircle } from '@ng-icons/lucide';
import { HlmButton } from '@spartan-ng/helm/button';
import { HlmIcon } from '@spartan-ng/helm/icon';
@Component({
selector: 'spartan-button-loading',
imports: [HlmButton, NgIcon, HlmIcon],
providers: [provideIcons({ lucideLoaderCircle })],
template: `
<button disabled hlmBtn size="sm">
<ng-icon hlm name="lucideLoaderCircle" size="sm" class="animate-spin" />
Please wait
</button>
`,
})
export class ButtonLoading {}
As Anchor
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-button-anchor',
imports: [HlmButton],
template: `
<a hlmBtn target="_blank" variant="link" href="https://github.com/goetzrobin/spartan">Star on GitHub</a>
`,
})
export class ButtonAnchor {}