Actions
Button
A pill that runs one action when pressed, used for the commands of a screen such as "Mark as done" or "Continue".
In kanso-ui as Button
Web and native
Button in kanso-ui 0.59.0, for React.
import { Button } from '@kanso-labs/kanso-ui'A labelled button at five emphasis levels and five heights, which can also act as a link or a toggle.
It follows the Material Design buttons page, including its newer colour pairs and the pressed shape morph. Under forced colours a button with a container is drawn as a 1px rule, so it keeps a visible edge. Its container, label and rule colours, its shadow and its corner ease between states over the short motion duration, and move at once for a reader who asks for reduced motion.
What you provide
children: the label, in sentence case, naming the outcome (Save changes).- An optional
iconbefore the label, drawn1emsquare incurrentColorso it takes the size's icon size and the label's colour. - Any
aria-*prop is forwarded to the element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | |
className | ClassNameOrFunction<ButtonState> | — | A function may compute the class from the button's render state. |
disableRipple | boolean | false | Disables the press ripple. A press then draws its layer flat instead, at Kanso's pressed opacity, 12%, which is the opacity the ripple reaches too, so the button reads the same either way. The hover and focus layers are unaffected. |
icon | ReactNode | — | An icon before the label: Kanso's 20px at `xs` and `md`, 24px at `lg`. Draw it `1em` square in `currentColor`, as every icon here is, and it follows. Hidden with the label while the button is pending. |
pendingLabel | string | — | The name of the ring shown while the button is pending, for a screen reader. The label it replaces is hidden while it shows. Left out, it is the word for it in the I18nProvider's locale — "Loading" in English. |
shape | 'round' | 'square' | 'round' | The corner the button rests at: `round` is the pill, `square` a rounded rectangle, 12px up to `md` and 16px at `lg`. Either tightens while pressed, and a toggle trades one for the other once selected. |
size | 'lg' | 'md' | 'xl' | 'xs' | 'xxl' | 'md' | Control height: `xs` 32px, `md` 40px, `lg` 56px, each with its own inline padding and type. `md` is the web's default. `xl` and `xxl` are deprecated and render at `lg`, Kanso's largest, with a warning in development; use `lg`. Deprecated sizes. Kanso stops at lg, 56px: xl (96px) and xxl (136px) are deprecated in Kanso, though kanso-ui still accepts them. |
style | StyleOrFunction<ButtonState> | — | A function may compute the style from the button's render state. |
variant | Exclude<ButtonVariant, 'accent' | 'critical' | 'text'> | — | A toggle takes `filled`, `tonal`, `outlined` or the deprecated `elevated`, the variants Kanso gives a selected state. |
Also takes the props of ButtonDOMProps, ButtonLinkForm, ButtonPressForm, ButtonToggleForm.
Example
import { Button } from '@kanso-labs/kanso-ui'
<Button variant="filled" onPress={save}>Save changes</Button>
<Button variant="outlined" size="lg" icon={<PlusIcon />}>Label</Button>
<Button variant="tonal" defaultSelected>Label</Button>The design’s classes
k-btn with k-btn--accent, k-btn--ink, k-btn--tonal, k-btn--outline, k-btn--text, k-btn--critical or a spotlight variant; k-btn--sm, k-btn--md, k-btn--xl; k-btn--block; a k-icon inside.
Maps to Button in kanso-ui and react-native-kanso-ui.