import { Component } from '@angular/core';
import { WrButton } from 'ngwr/button';
@Component({ imports: [WrButton] })
export class MyComponent {}Button
A button for an action or a link.
Installation
Import the class, and @use the entry point in your global styles: without it the component renders unstyled.
Basic usage
Use it as <wr-btn>, <button wr-btn> or <a wr-btn>.
<wr-btn>Default</wr-btn>
<button wr-btn type="button">Native button</button>
<a wr-btn href="/reference/components/button-group">Anchor</a>Inside a form
<wr-btn> never submits a form: use <button wr-btn type="submit">, or bind the click.
<form (ngSubmit)="save()">
<!-- Submits -->
<button wr-btn type="submit" color="primary">Save</button>
<!-- Does not submit: bind the click -->
<wr-btn (click)="save()" color="primary">Save</wr-btn>
</form>Colors
Leave color unset for the default.
<wr-btn>Default</wr-btn>
<wr-btn color="primary">Primary</wr-btn>
<wr-btn color="success">Success</wr-btn>Outlined
outlined drops the fill and keeps a coloured border.
<wr-btn outlined>Default</wr-btn>
<wr-btn color="primary" outlined>Outlined</wr-btn>Sizes
<wr-btn size="sm">Small</wr-btn>
<wr-btn size="md">Medium</wr-btn>
<wr-btn size="lg">Large</wr-btn>Shape
shape is rounded (default), pill or squircle.
<wr-btn color="primary">Rounded (default)</wr-btn>
<wr-btn color="primary" shape="pill">Pill</wr-btn>
<wr-btn color="primary" shape="squircle">Squircle</wr-btn>With icon
icon takes a name registered with provideWrIcons(); iconPosition is start (default) or end.
<wr-btn icon="add" color="primary">Add</wr-btn>
<wr-btn icon="trash" color="danger" outlined>Delete</wr-btn>
<wr-btn icon="download" iconPosition="end">Download</wr-btn>Disabled
<wr-btn disabled>Disabled</wr-btn>Loading
The spinner covers the label and blocks clicks; [disabledWhenLoading]="false" keeps the button clickable.
<wr-btn [loading]="loading()" [disabledWhenLoading]="false" color="primary" (click)="loading.set(!loading())">
Click to toggle
</wr-btn>Block
block fills the parent's width.
<wr-btn color="primary" block>Full width</wr-btn>API
| Name | Description | Type | Default |
|---|---|---|---|
color | Color variant. Omit for the neutral default style. | WrColor | null | null |
size | Size variant. | WrButtonSize | 'md' |
shape | Corner treatment — rounded, pill or squircle. null (default) falls back to rounded. Inside a <wr-btn-group shape="…">, the group's shape ALWAYS wins over this input — the group enforces a consistent corner treatment across its members. | WrButtonShape | null | null |
icon | Icon name to render alongside the label. The icon is hidden while loading is true so the spinner can take its place. | WrIconName | null | null |
iconPosition | Position of the icon relative to the label. | WrButtonIconPosition | 'start' |
disabled | Disable the button. | boolean | false |
outlined | Outlined variant — colored text and border on a transparent background. | boolean | false |
block | Stretch the button to fill its parent's width. | boolean | false |
loading | Show a spinner overlaying the label. Layout is preserved. | boolean | false |
disabledWhenLoading | When loading is true and this is also true, pointer events are suppressed and the button reports as disabled to assistive tech. | boolean | true |
CSS variables
Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/button's own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-btn-bg | var(--wr-color-surface) | .wr-btn +11 variant overrides |
--wr-btn-border | var(--wr-border-base) | .wr-btn +6 variant overrides |
--wr-btn-color | var(--wr-color-on-surface) | .wr-btn +4 variant overrides |
--wr-btn-font-family | var(--wr-font-family-base) | .wr-btn |
--wr-btn-font-size | var(--wr-control-font-size-md) | .wr-btn +2 variant overrides |
--wr-btn-font-weight | var(--wr-font-weight-medium) | .wr-btn |
--wr-btn-gap | var(--wr-space-sm) | .wr-btn +2 variant overrides |
--wr-btn-icon-size | 1rem | .wr-btn +2 variant overrides |
--wr-btn-line-height | var(--wr-control-line-height-md) | .wr-btn +2 variant overrides |
--wr-btn-padding-x | var(--wr-space-lg) | .wr-btn +2 variant overrides |
--wr-btn-padding-y | var(--wr-control-padding-y-md) | .wr-btn +2 variant overrides |
--wr-btn-radius | var(--wr-control-radius-md) | .wr-btn +4 variant overrides |
Dependencies
| Built on | Icon, Spinner |
|---|---|
| Used by | Editor, Event calendar, Pagination, Popconfirm, WrTour, Transfer |
See also
Component Button GroupJoins buttons into one control with shared borders.Component DropdownA menu that opens from any trigger.Component PopconfirmAsk "Are you sure?" next to a button before its action runs.Component Speed DialA floating button that opens a set of related actions.Component ToolbarAn action bar with start, center and end zones.Component SegmentedPick one option from a row of buttons.Component IconRenders an SVG icon you register by name; ngwr ships none of its own.Component SpinnerAn inline loading indicator.