form

Button

Displays a button or a component that looks like a button. Supports multiple variants, sizes, and states.

Preview

A preview of the Button component with interactive controls.

Preview Code
Interactive

Installation

Add the Button component to your project.

Bash
ng g @ng-cn/core:c button

Usage

Import and use the Button component in your Angular application.

Template TypeScript
template.html
<div class="flex flex-wrap items-center gap-4">
  <Button>Default</Button>
  <Button variant="secondary">Secondary</Button>
  <Button variant="destructive">Destructive</Button>
  <Button variant="outline">Outline</Button>
  <Button variant="ghost">Ghost</Button>
  <Button variant="link">Link</Button>
</div>

Examples

Explore different variations and use cases for the Button component.

All Variants

Buttons come in six distinct visual variants.

Preview Code
Interactive

All Sizes

Available in four sizes to fit different contexts.

Preview Code
Interactive

With Icon

Combine buttons with icons for enhanced visual communication.

Preview Code
Interactive

Loading State

Show loading state with a spinner and disabled interaction.

Preview Code
Interactive

Disabled State

Disabled buttons indicate unavailable actions.

Preview Code
Interactive

As Link (asChild Pattern)

Use button styling on links with the asChild pattern.

Preview Code
Interactive

Button Group

Group related buttons together.

Preview Code
Interactive

Custom Styling with buttonVariants

Use buttonVariants to apply button styles to custom elements.

Preview Code
Interactive

API Reference

Props
Prop Type Default Description
variant 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link' 'default' The visual style of the button.
size 'default' | 'sm' | 'lg' | 'icon' 'default' The size of the button.
disabled boolean false Whether the button is disabled.
asChild boolean false Render as child element, passing props to the child.
class string Additional CSS classes to apply.
type 'button' | 'submit' | 'reset' 'button' The button type attribute.