Button
Buttons provides a way to trigger an action. The caption of a Button should hint what action will occur. Buttons come in 3 sizes: small, medium and large. Along with the main component, Button provides 4 named exports:
Buttons can render an icon or qualifier before or after the caption.
Buttons except ToggleButtons:
💡
Don't use outline buttons as an alternative to secondary buttons. Only secondary buttons should be used with primary buttons.
All buttons accept most button attributes.
Accessibility considerations
- All buttons are focusable and support keyboard navigation; tab (or shift+tab when tabbing backwards)
- space and enter keyboard shortcuts trigger the buttons when in focus; toggles the state of ToggleButton.
- ToggleButton has a role of “switch”.
- The state of ToggleButton determines the value of
aria-checked attribute.
- Add
aria-label or aria-labelledby in IconButton & icon-only variant of ToggleButton to help assitive technologies.
- enter keyboard shortcut triggers the link buttons when in focus.
- All buttons accept the button aria-* attributes.
- Both link buttons accept the link aria-* attributes.
Props
children
React node for button's caption
size
Controls size of button. Possible values are "s", "m", "l" for small, medium & large respectively
stretch
Button matches width of it's container
nude
Renders a nude button
primary
Applies primary brand color
secondary
Renders a secondary button
outline
Renders an outline button
danger
Renders as danger button
qualifier
Qualifiers provide a hint about the action a button will perform. Appends (default) or prepends an icon to the button's caption.
Accepts SVG or SVG wrapped React component.
Checkout @asphalt-react/iconpack for SVG wrapped React components.
qualifierStart
Renders qualifier before the button's caption
qualifierEnd
Renders qualifier after the button's caption. Has priority over qualifierStart.
IconButton
IconButton provides a way to render an icon as a button.
Props
icon
Renders an icon for the caption. Accepts an inline SVG or SVG wrapped React component
primary
Applies primary brand color
danger
Renders as danger button
nude
Renders a nude icon button
size
Determines the size. Possible values are "s", "m", "l" for small, medium & large respectively/
ToggleButton
A ToggleButton is a digital switch to turn an option on or off. Switching between the states — as a result of direct user action or a programmatic event — should produce an immediate result. The caption should always reflect the current logical state of the button.
There are two variants:
ToggleButton vs Checkbox
Similar to ToggleSwitches, ToggleButtons are not an alternative to Checkboxes. They are not form controls and should not appear inside a form. ToggleButtons should only manipulate local UI states, i.e. they should not directly or indirectly initiate a remote API call to change database states.
ToggleButton vs ToggleSwitch
Both of them provide options to toggle between states. Consider the following points to choose between them:
- Prefer ToggleSwitches to toggle states on mobile; they support swipe gestures
- ToggleButtons fit better in designs with space constraints
- Use ToggleButtons to programmatically toggle the state. For example, you can bind a keyboard shortcut to a mute button in a video player.
Props
text
Label for text-only variant
icon
Icon for icon-only variant. Accepts SVG or SVG wrapped React component
Note: icon prop overrides text prop
children
React node for caption
Note: Both icon and text props override children
on
Sets the state of button
size
Sets the size of button. Possible values are "s", "m", "l" for small, medium & large respectively
ButtonLink
ButtonLink is a semantic link element styled as a Button component.
It supports two variants - Primary & Secondary. It can also render an icon (qualifier) along with the caption. There are three sizes available - small, medium & large.
ButtonLink detects target="_blank" in the props and adds an icon hinting users that the link will open in a new tab (or window). However, you can provide your custom icon via qualifier prop to override this default behavior.
Security and privacy risks
When a link opens in a new tab, users' security and privacy may be at risk. To prevent this both ButtonLink and IconButtonLink checks the value of target attribute and adds rel="noreferrer" (why not rel="noopener noreferrer") if the value is other than _self, _top or _parent. To override this default behavior, you can pass a rel attribute in tagProps prop.
Props
children
React node for the caption.
tagProps
Accepts props & attributes for the link element.
as
Link element to render. Accepts an HTML element or a React component.
size
Size of ButtonLink. Possible values are "s", "m", "l" for small, medium & large respectively.
primary
Applies primary brand styles.
secondary
Applies secondary styles.
qualifier
Qualifiers provide a hint about the action a ButtonLink will perform. Appends or prepends (default) an icon to the caption.
Accepts SVG or SVG wrapped React component.
Checkout @asphalt-react/iconpack for SVG wrapped React components.
qualifierEnd
Appends qualifier to the caption.
IconButtonLink
IconButtonLinks are semantic links styled as an IconButton component. Supports two variants - Primary & Nude. There are three sizes available - small, medium & large.
Props
icon
Renders an icon for the caption. Accepts an inline SVG or SVG wrapped React component
Checkout @asphalt-react/iconpack for SVG wrapped React components.
tagProps
Accepts props & attributes for the link element
as
Link element to render. Accepts an HTML element or a React component.
primary
Applies primary brand styles.
nude
Applies nude styles
size
Size of IconButtonLink. Possible values are "s", "m", "l" for small, medium & large respectively