Web and native

Fab in kanso-ui 0.59.0, for React.

import { Fab } from '@kanso-labs/kanso-ui'

A floating action button: a screen's primary action, raised over its content.

It follows the Material Design FAB page and, given a label, the extended FAB page. It rests on the level 3 shadow and lifts to level 4 under a hovering pointer. The spec gives no disabled FAB; a disabled one takes the usual disabled opacities and drops its shadow.

What you provide

  • children: the icon, drawn 1em square in currentColor, so it takes the size's icon size.
  • aria-label when there is no label: an icon alone has no name. With a label, the label is its name.
  • Its place on the screen, typically the bottom trailing corner: the FAB does not position itself, and className, style and ref land on the button.

Props

PropTypeDefaultDescription
aria-labelstring—What the FAB does, in words. A FAB without a `label` is an icon alone, which has no name of its own, so give it this; with a `label` the label is its name.
childrenReactNode—The FAB's icon, drawn at Kanso's 24px.
classNameClassNameOrFunction<ButtonState>—A function may compute the class from the FAB's render state.
disableRipplebooleanfalseDisables the press ripple, and draws the flat pressed layer in its place. The hover and focus layers are unaffected.
hrefstring—Where the FAB leads. Given one, it is rendered as a link — an `<a>`, announced as the link it is — with the same styles and ripple.
labelReactNode—A label after the icon, which makes this the extended FAB: as tall as the size, as wide as what it holds. Kept to one line, it ends in an ellipsis when the FAB's container is narrower than it, and shows its full text in a tooltip on hover.
relstring—The link's `rel`, when `href` is set.
size'lg' | 'md' | 'xl''md'Kanso's one size, `md`, 56px. `lg` and `xl` are deprecated and draw it too. Deprecated sizes. Kanso's FAB is the 56px one, md: lg (80px) and xl (96px) are deprecated in Kanso, though kanso-ui still accepts them.
styleStyleOrFunction<ButtonState>—A function may compute the style from the FAB's render state.
targetstring—The link's `target`, when `href` is set.
tone'accent' | 'ink' | 'primary' | 'secondary' | 'tertiary''ink'The colour the FAB is drawn in: `ink`, Kanso's FAB, or `accent`, the product's colour, for a screen whose one highlighted action it is. `primary` is deprecated and draws `accent`; `secondary` and `tertiary` are deprecated and draw `ink`.
variant'filled' | 'tonal''filled'`filled` draws the tone itself, Kanso's FAB; `tonal` draws its quieter pair, `container` for ink and `accent-soft` for accent.

Also takes the props of Omit<ButtonDOMProps, 'aria-label' | 'isPending'>.

Example

import { Fab } from '@kanso-labs/kanso-ui'

<Fab aria-label="Label" onPress={create}>
  <PlusIcon />
</Fab>

<Fab label="Label" size="lg" tone="secondary">
  <PlusIcon />
</Fab>

The design’s classes

k-fab, k-fab--icon, k-fab--accent; on the web, k-btn k-btn--ink k-btn--md inside k-appbar.

Maps to Fab in kanso-ui and react-native-kanso-ui.