Command Palette

Search for a command to run...

Components · Core component

Button

Buttons consist of a clickable area usually containing a textual label or an icon that users can click to perform an action. In addition, keyboard users may activate buttons using the Space or Enter keys.

Usage

TSX
import { Button } from '@console/nimbus-ui/core';

Examples

Button Variations

Buttons allow for variantions in different styles. With the variation prop, you can control the colour, background color and style of the button without having to explicitly

Brand Color

Use the brandColor prop in conjunction with the variant="brand" prop to allow for a custom brand colour from one of the design tokens we have. This prop is usually used best with lighter colours such as accent-bright-2.

Size

A Button size can be changed using the size prop. This prop allows you to specify "sm" or "lg" which will change the size of the button.

Rounded

A Button border radius can be changed using the rounded prop. Setting this prop to true or false will allow you toggle. Implicity by including this prop it will toggle radius.

On Press

Button supports user interactions via mouse, keyboard, and touch. You can handle all of these via the onPress prop. This is similar to the standard onClick event, but normalized to support all interaction methods equally. In addition, the onPressStart, onPressEnd, and onPressChange events are fired as the user interacts with the button.

Auto Focus

A Button can be set to have autoFocus using the autoFocus prop. This prop allows you to automatically toggle focus on render. This is useful for modals and portals inside of your components and should mainly be used as a focus trap.

Disabled

A Button can be disabled using the disabled prop.

Loading

A Button can be toggled as loading using the loading prop. Use the loadingText prop as a method to create loading text inside the button

With Icon

Using a custom icon can be easy by including it as a child. The fill will be inherited from the parent. You can specify a custom colour using a className.

Full Width

A Button can be toggled to show fullWidth.

Polymorphic Button

The as prop can be used to transform the underlying HTML element to the correct button type. The HTML element can be any element but the most common are a, button and RouterLink by React Router.

Classes API

Use the classes API to make changes without destroying the button. You can use the following psudoselectors. `` data-pressed="true" data-hovered="true" data-focus-visible="true" data-size="sm | lg" data-rounded="true" data-loading="true" data-disabled="true" data-full-width="true"

Press Event Propagation

Press events propagate by default. You can use stopPropagation on the PressEvent to stop the event from bubbling.

API