4.8.1 • Published 3 years ago

@workday/canvas-kit-react-button v4.8.1

Weekly downloads
1,413
License
Apache-2.0
Repository
github
Last release
3 years ago

Canvas Kit Button

Clickable button elements that extend the native <button> element with Canvas styling.

Disclaimer

The documentation below is for the current Canvas buttons. The next iteration of our buttons have been implemented in this module, but will not be documented until we're ready to roll them out across all our products. We want to discourage their use until everyone can uptake them simultaneously for consistencies sake.

The new buttons include new ButtonTypes, icon support, and the ButtonSizes equate to different button and font sizes.

If you would like to use the new buttons, please consult the design systems team and get approval first

Installation

yarn add @workday/canvas-kit-react

or

yarn add @workday/canvas-kit-react-button

Usage

import * as React from 'react';
import {Button} from '@workday/canvas-kit-react-button';

<Button>Button Label</Button>;

Static Properties

Sizes: ButtonSizes

<Button buttonSize={Button.Sizes.Small}>Small Button</Button>

Types: ButtonTypes

<Button buttonType={Button.Types.Primary}>Primary Button</Button>

Component Props

Required

children: ReactNode

Buttons cannot be empty

Optional

buttonType: ButtonTypes

The type of the button

Default: ButtonTypes.Secondary

ThemeDescription
PrimaryOrange background, white text
SecondaryGray background, dark gray text
DeleteRed background, dark text

buttonSize: ButtonSizes

The type of the button

Default: ButtonSizes.Large

ThemeDescription
Small18px tall, small padding, small text
Medium24px tall, medium padding, medium text
Large40px tall, large padding, larger text

grow: boolean

If true, the button will grow to its container's width.

Default: false


buttonRef: React.Ref<HTMLButtonElement>

Returns the ref to the rendered HTMLButtonElement.

Icon Button

Button containing an icon. Icon may be a component from canvas-kit-react-icon or an svg element.

Usage

import * as React from 'react';
import {IconButton} from '@workday/canvas-kit-react-button';
import {SystemIcon} from '@workday/canvas-kit-react-icon';
import {activityStreamIcon} from '@workday/canvas-system-icons-web';

<IconButton title="Activity Stream" aria-label="Activity Stream">
  <SystemIcon icon={activityStreamIcon} />
</IconButton>;

<IconButton icon={activityStreamIcon} title="Activity Stream" aria-label="Activity Stream" />;

Static Properties

Sizes: ButtonSizes

<IconButton buttonSize={IconButton.Sizes.Small} icon={xIcon} />

Types: IconButtonTypes

<IconButton buttonType={IconButton.Types.Plain} icon={xIcon} />

Component Props

Same as Button Undocumented props are spread to the button element.


Optional

buttonType: IconButtonTypes

The type of the icon button

Default: IconButtonTypes.Circle

ThemeDescription
SquareSquare, white background, dark gray icon
SquareFilledSquare, gray background, dark gray icon
PlainDark gray icon
CircleCircular, dark gray icon
CircleFilledCircular, gray background, dark gray icon
InverseCircular, transparent background, white icon
InverseFilledCircular, semitransparent background, white icon

buttonSize: IconButton.Sizes.Small | IconButton.Sizes.Medium

The size of the icon button

ThemeDescriptionIs Default
Small32px Diameter, 20px Icon SizeFalse
Medium40px Diameter, 24px Icon SizeTrue
Small (Square Icon Type)32px x 32px, 24px Icon SizeTrue
Medium (Square Icon Type)40px x 40px, 24px Icon SizeFalse

toggled: boolean | undefined

If defined as a boolean, then it manages the button state: on (true) or off (false). This is a controlled button component. If left undefined then the button is not considered toggle-able (aria-pressed is undefined) and will act as a normal button.

Default: undefined


onToggleChange: (toggled: boolean | undefined) => void

The callback that is fired when a button toggle prop changes This is true when the toggle changes from true to false but also if you disable the toggle-ability of a button (in other words, if toggle changes from a boolean to undefined). This is important because the aria-pressed attribute for accessibility is goverened by whether or not the toggle prop is defined.


value: string

Value of the button. Must be unique if used within an IconButtonToggleGroup.

Accessibility Notes

The content of an IconButton is not always clear to the user. In order to better convey what the icon represents, the IconButton should be initialized with title and aria-label attributes.

Icon Button Toggle Group

Group of buttons containing an icon. This is a controlled component.

Usage

import * as React from 'react';
import {IconButton, IconButtonToggleGroup} from '@workday/canvas-kit-react-button';
import {listViewIcon, worksheetsIcon} from '@workday/canvas-system-icons-web';

<IconButtonToggleGroup>
  <IconButton icon={listViewIcon} value="list-view" title="List View" aria-label="List View" />
  <IconButton icon={worksheetsIcon} value="table-view" title="Worksheets" aria-label="Worksheets" />
</IconButtonToggleGroup>;

Note: while managing state using a unique value for each IconButton child is encouraged, you can also use indexes and omit the value field. It is strongly recommended to not mix these two methods.

Static Properties

None

Component Props

Required

children: React.ReactElement<IconButton>[]

Icon buttons to toggle between.


Optional

value: string | number

Identify which item is selected (toggled=true).
If a string is passed, the IconButton with the corresponding value will be selected.
If a number is passed, the IconButton with the corresponding index will be selected.


isRTL: boolean

Identify whether to render from right to left


onChange: (value:string | number)=> void

Callback function when a toggle button is selected. The value (if defined) or the index of the button will be returned.

4.8.3

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.1-next.18

3 years ago

4.7.1-next.14

3 years ago

4.7.1-next.15

3 years ago

4.7.1-next.16

3 years ago

4.7.1-next.0

3 years ago

4.7.1-next.1

3 years ago

4.7.1-next.2

3 years ago

4.7.1-next.3

3 years ago

4.7.1-next.4

3 years ago

4.7.1-next.5

3 years ago

4.7.1-next.6

3 years ago

4.7.1-next.7

3 years ago

4.7.1-next.8

3 years ago

4.7.1-next.9

3 years ago

4.7.1-next.10

3 years ago

4.7.1-next.11

3 years ago

4.7.1-next.12

3 years ago

4.7.0

3 years ago

4.6.1-next.3

3 years ago

4.6.1-next.2

3 years ago

4.6.1-next.1

3 years ago

4.6.0

3 years ago

4.5.2-next.3

3 years ago

4.5.2-next.2

3 years ago

4.5.2-next.1

3 years ago

4.5.2-next.0

3 years ago

4.5.1

3 years ago

4.5.1-next.4

3 years ago

4.5.1-next.3

3 years ago

4.5.1-next.2

3 years ago

4.5.1-next.1

3 years ago

4.5.1-next.0

3 years ago

4.5.0

3 years ago

4.4.3-next.17

3 years ago

4.4.3-next.16

3 years ago

4.4.3-next.18

3 years ago

4.4.3-next.15

3 years ago

4.4.3-next.14

3 years ago

4.4.3-next.13

3 years ago

4.4.3-next.12

3 years ago

4.4.3-next.11

3 years ago

5.0.0-beta.0

3 years ago

4.4.3-next.10

3 years ago

4.4.3-next.9

3 years ago

4.4.3-next.8

3 years ago

4.4.3-next.7

3 years ago

4.4.3-next.6

3 years ago

4.4.3-next.5

3 years ago

4.4.3-next.4

3 years ago

4.4.3-next.3

3 years ago

4.4.3-next.0

3 years ago

4.4.3-next.1

3 years ago

4.4.2

3 years ago

4.4.2-next.4

3 years ago

4.4.2-next.3

3 years ago

4.4.2-next.2

3 years ago

4.4.1-next.4

3 years ago

4.4.1

3 years ago

4.4.1-next.3

3 years ago

4.4.1-next.2

3 years ago

4.4.1-next.0

3 years ago

4.4.1-next.1

3 years ago

4.4.0

3 years ago

4.3.2-next.6

3 years ago

4.3.2-next.4

3 years ago

4.3.2-next.3

3 years ago

4.3.2-next.5

3 years ago

4.3.2-next.2

3 years ago

4.3.2-next.1

4 years ago

4.3.2-next.0

4 years ago

4.3.1

4 years ago

4.3.1-next.4

4 years ago

4.3.1-next.2

4 years ago

4.3.1-next.3

4 years ago

4.3.1-next.1

4 years ago

4.3.1-next.0

4 years ago

4.3.0

4 years ago

4.1.3-next.28

4 years ago

4.1.3-next.27

4 years ago

4.1.3-next.26

4 years ago

4.1.3-next.25

4 years ago

4.1.3-next.24

4 years ago

4.1.3-next.23

4 years ago

4.1.3-next.22

4 years ago

4.1.3-next.21

4 years ago

4.1.3-next.20

4 years ago

4.1.3-next.17

4 years ago

4.1.3-next.18

4 years ago

4.1.3-next.16

4 years ago

4.2.0

4 years ago

4.1.3-next.13

4 years ago

4.1.3-next.11

4 years ago

4.1.3-next.12

4 years ago

4.1.3-next.10

4 years ago

4.1.3-next.9

4 years ago

4.1.3-next.8

4 years ago

4.1.3-next.6

4 years ago

4.1.3-next.7

4 years ago

4.1.3-next.4

4 years ago

4.1.3-next.3

4 years ago

4.1.3-next.0

4 years ago

4.1.3-next.1

4 years ago

4.1.2

4 years ago

4.0.3

4 years ago

4.1.2-next.0

4 years ago

4.1.1

4 years ago

4.0.2

4 years ago

4.1.1-next.5

4 years ago

4.1.1-next.4

4 years ago

4.1.1-next.0

4 years ago

4.1.1-next.3

4 years ago

4.1.1-next.2

4 years ago

3.9.2

4 years ago

4.0.1-next.19

4 years ago

4.0.1-next.18

4 years ago

4.1.0

4 years ago

4.0.1-next.17

4 years ago

4.0.1-next.16

4 years ago

4.0.1-next.15

4 years ago

4.0.1-next.14

4 years ago

4.0.1

4 years ago

3.9.1

4 years ago

4.0.1-next.12

4 years ago

4.0.1-next.11

4 years ago

4.0.1-next.10

4 years ago

4.0.1-next.9

4 years ago

4.0.1-next.7

4 years ago

4.0.1-next.8

4 years ago

4.0.1-next.6

4 years ago

4.0.1-next.5

4 years ago

4.0.1-next.4

4 years ago

4.0.1-next.1

4 years ago

4.0.1-next.2

4 years ago

4.0.1-next.0

4 years ago

3.8.1-next.17

4 years ago

4.0.0

4 years ago

3.9.0

4 years ago

3.8.1-next.16

4 years ago

4.0.0-beta.5

4 years ago

3.8.1-next.15

4 years ago

3.8.1-next.14

4 years ago

3.8.1-next.13

4 years ago

3.8.1-next.12

4 years ago

3.8.1-next.11

4 years ago

3.8.1-next.10

4 years ago

3.8.1-next.9

4 years ago

3.8.1-next.7

4 years ago

3.8.1-next.8

4 years ago

3.8.1-next.6

4 years ago

3.8.1-next.5

4 years ago

3.8.1-next.3

4 years ago

3.8.1-next.4

4 years ago

3.8.1-next.2

4 years ago

3.8.1-next.0

4 years ago

3.8.1-next.1

4 years ago

3.8.0

4 years ago

3.7.1-next.7

4 years ago

3.7.1-next.8

4 years ago

3.7.1-next.6

4 years ago

3.7.1-next.3

4 years ago

3.7.1-next.4

4 years ago

3.7.1-next.5

4 years ago

4.0.0-beta.4

4 years ago

3.7.1-next.2

4 years ago

3.7.1-next.0

4 years ago

4.0.0-beta.3

4 years ago

4.0.0-beta.2

4 years ago

3.6.1-next.14

4 years ago

3.7.0

4 years ago

3.6.1-next.13

4 years ago

3.6.1-next.12

4 years ago

3.6.1-next.11

4 years ago

3.6.1-next.10

4 years ago

3.6.1-next.9

4 years ago

3.6.1-next.8

4 years ago

3.6.1-next.7

4 years ago

3.6.1-next.6

4 years ago

3.6.1-next.5

4 years ago

3.6.1-next.4

4 years ago

3.6.1-next.3

4 years ago

3.6.1-next.2

4 years ago

3.6.1-next.1

4 years ago

3.6.1-next.0

4 years ago

4.0.0-beta.1

4 years ago

3.5.1-next.10

4 years ago

3.6.0

4 years ago

3.4.1

4 years ago

3.5.1-next.9

4 years ago

3.5.1-next.8

4 years ago

4.0.0-beta.0

4 years ago

3.5.1-next.7

4 years ago

3.5.1-next.6

4 years ago

3.5.1-next.5

4 years ago

3.5.1-next.4

4 years ago

3.5.1-next.3

4 years ago

3.5.1-next.2

4 years ago

3.5.1-next.1

4 years ago

3.5.1-next.0

4 years ago

3.5.0

4 years ago

3.4.1-next.17

4 years ago

3.4.1-next.16

4 years ago

3.4.1-next.15

4 years ago

3.4.1-next.14

4 years ago

3.4.1-next.13

4 years ago

3.4.1-next.12

4 years ago

3.4.1-next.11

4 years ago

3.4.1-next.10

4 years ago

3.4.1-next.8

4 years ago

3.4.1-next.9

4 years ago

3.4.1-next.6

4 years ago

3.4.1-next.7

4 years ago

3.4.1-next.5

4 years ago

3.4.1-next.4

4 years ago

3.4.1-next.3

4 years ago

3.4.1-next.2

4 years ago

3.4.1-next.0

4 years ago

3.4.1-next.1

4 years ago

3.3.3-next.31

4 years ago

3.4.0

4 years ago

3.3.3-next.30

4 years ago

3.3.3-next.29

4 years ago

3.3.3-next.28

4 years ago

3.3.3-next.26

4 years ago

3.3.3-next.27

4 years ago

3.3.3-next.25

4 years ago

3.3.3-next.21

4 years ago

3.3.3-next.19

4 years ago

3.3.3-next.18

4 years ago

3.3.3-next.17

4 years ago

3.3.3-next.15

4 years ago

3.3.3-next.14

4 years ago

3.3.3-next.16

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-beta.1

5 years ago

3.0.0-beta.0

5 years ago

3.0.0-alpha.7

5 years ago

3.0.0-alpha.6

5 years ago

3.0.0-alpha.5

5 years ago

3.0.0-alpha.4

5 years ago

3.0.0-alpha.3

5 years ago

3.0.0-alpha.2

5 years ago

3.0.0-alpha.1

5 years ago