import { Button } from '@cerberus/react';To display an icon, use the ButtonParts API.
To display a loading state, use the ButtonParts.Icon and set the pending prop to true.
Use the shape prop to set the shape of the button. The Button component comes in three shapes: default, sharp and rounded.
Use the usage prop to set the usage style of the button. The Button component comes in three usage styles: filled, outlined, and ghost.
The Button component comes in two sizes: sm, md. You can set the size by using the size prop.
You can group buttons together using the ButtonGroup component.
You can create an attached button group by setting the layout prop to attached.
You can utilize the primitive components or the css prop to customize the button.
| Component | Description |
|---|---|
| Button.Root | The context provider for the Button parts |
| Button.Icon | The icon/spinner of the button |
To enable global customization, you can modify the theme configuration in your panda.config.ts file. For example, to customize the button component globally:
export default createCerberusConfig({ // ... theme: { extend: { recipes: { button: { defaultVariants: { shape: 'default', }, }, } } }})This change will set the default shape variant of all buttons to default.
The Button component is an abstraction of the primitives and accepts the following props:
| Name | Default | Description |
|---|---|---|
| palette | action | The color palette (any of the Cerberus palettes) of the button. |
| usage | filled | The style treatment of the button. |
| shape | sharp | The shape of the button. |
| pending | false | The loading state of the button. When a button has an Icon it will replace it with a spinner. When not, is shows a disabled state. |
| asChild | Render the Button as the child component. |
| Name | Default | Description |
|---|---|---|
| layout | default | The layout of the button group. Can be default or attached. |
| shape | sharp | The shape of the buttons in the group. Should match the shape prop of the Button components used. |
The ButtonParts API is an Object containing the full family of components.
| Name | Description |
|---|---|
| Root | The Button component which is the Provider for the family. |
| Icon | The ButtonIcon component which dynamically replaces an icon with a Spinner when the state is pending. |
On this page
import { Button } from '@cerberus/react'
export function BasicDemo() {
return <Button>Default</Button>
}
import { ButtonParts } from '@cerberus/react'
import { ArrowDownRight } from '@carbon/icons-react'
export function IconDemo() {
return (
<ButtonParts.Root>
With icon
<ButtonParts.Icon>
<ArrowDownRight />
</ButtonParts.Icon>
</ButtonParts.Root>
)
}
import { ButtonParts } from '@cerberus/react'
export function PendingDemo() {
return (
<ButtonParts.Root pending>
<ButtonParts.Icon />
Pending
</ButtonParts.Root>
)
}
import { Button } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function ShapesDemo() {
return (
<HStack>
<Button shape="default">Default</Button>
<Button shape="sharp">Sharp</Button>
<Button shape="rounded">Rounded</Button>
</HStack>
)
}
import { Button } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function UsageDemo() {
return (
<HStack>
<Button usage="filled">Filled</Button>
<Button usage="outlined">Outlined</Button>
<Button usage="outlined-subtle">Outlined Subtle</Button>
<Button usage="ghost">Ghost</Button>
</HStack>
)
}
import { Button } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function SizeDemo() {
return (
<HStack>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
</HStack>
)
}
import { Button, ButtonGroup } from '@cerberus/react'
export function GroupDemo() {
return (
<ButtonGroup>
<Button>Button 1</Button>
<Button>Button 2</Button>
<Button>Button 3</Button>
</ButtonGroup>
)
}
import { Button, ButtonGroup, IconButton } from '@cerberus/react'
import { ChevronDown } from '@carbon/icons-react'
import { HStack } from 'styled-system/jsx'
export function AttachedDemo() {
return (
<HStack justify="center" w="full">
<ButtonGroup layout="attached">
<Button>Main action</Button>
<IconButton ariaLabel="View options" shape="square" usage="filled">
<ChevronDown />
</IconButton>
</ButtonGroup>
<ButtonGroup layout="attached">
<Button usage="outlined">Main action</Button>
<IconButton ariaLabel="View options" shape="square" usage="outlined">
<ChevronDown />
</IconButton>
</ButtonGroup>
</HStack>
)
}
import { Button } from '@cerberus/react'
export function CustomDemo() {
return (
<Button
bgColor="danger.bg.initial"
color="danger.text.initial"
rounded="md"
transform="skew(-10deg)"
_hover={{
bgColor: 'black',
color: 'yellow',
}}
>
Cerberus Forever
</Button>
)
}