The button label, can be used as alternative to children. Children always take precedence.
Button
Button component is used to trigger an action or event, such as submitting a form, opening a Dialog, canceling an action, or performing a delete operation.
The Button component is used to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.
Import#
Button
: The button component with support for custom icons, spinners, etc.ButtonGroup
: Used to group buttons whose actions are related, with an option to flush them together.
import { Button, ButtonGroup } from '@saas-ui/react'
Usage#
<Button>Button</Button>
Label#
<Button label="Button" />
Button colors#
<Stack spacing={4}><Stack spacing={4} direction="row" align="center"><Button colorScheme="primary">Primary</Button><Button colorScheme="secondary">Seconary</Button></Stack><Stack spacing={4} direction="row" align="center"><Button colorScheme="red">Red</Button><Button colorScheme="orange">Orange</Button><Button colorScheme="yellow">Yellow</Button><Button colorScheme="green">Green</Button><Button colorScheme="teal">Teal</Button><Button colorScheme="cyan">Cyan</Button><Button colorScheme="blue">Blue</Button><Button colorScheme="purple">Purple</Button><Button colorScheme="pink">Pink</Button></Stack></Stack>
Button sizes#
Use the size
prop to change the size of the button. You can set the value to
xs
, sm
, md
, or lg
.
<Stack spacing={4} direction="row" align="center"><Button colorScheme="teal" size="xs">Button</Button><Button colorScheme="teal" size="sm">Button</Button><Button colorScheme="teal" size="md">Button</Button><Button colorScheme="teal" size="lg">Button</Button></Stack>
Button variants#
Use the variant
prop to change the visual style of the Button. You can set the
value to solid
, subtle
, outline
, ghost
, elevated
or link
.
<Stack direction="row" spacing={4} align="center"><Button variant="solid">Button</Button><Button variant="subtle">Button</Button><Button variant="outline">Button</Button><Button variant="ghost">Button</Button><Button variant="elevated">Button</Button><Button variant="link">Button</Button></Stack>
White buttons#
White buttons only work with the
Saas UI
theme on darker colors or in darkmode.
<Stackdirection="row"spacing={4}p={8}align="center"bg="primary.500"borderRadius="md"><Button colorScheme="white" variant="solid">Button</Button><Button colorScheme="white" variant="subtle">Button</Button><Button colorScheme="white" variant="outline">Button</Button><Button colorScheme="white" variant="ghost">Button</Button><Button colorScheme="white" variant="elevated">Button</Button><Button colorScheme="white" variant="link">Button</Button></Stack>
Button with icon#
You can add left and right icons to the Button component using the leftIcon
and rightIcon
props respectively.
Note: The
leftIcon
andrightIcon
prop values should be react elements NOT strings.
<Stack direction="row" spacing={4}><Button leftIcon={<EmailIcon />} colorScheme="teal" variant="solid"></Button><Button rightIcon={<ArrowForwardIcon />} colorScheme="teal" variant="outline">Call us</Button></Stack>
You can also use icons from popular libraries like react-icons and pass it into the button.
// import { FiArrowRight } from "react-icons/fi"<Stack direction="row" spacing={4}><Button rightIcon={<FiArrowRight />} colorScheme="blue" variant="outline">Call us</Button></Stack>
Button loading state#
Pass the isLoading
prop to show its loading state. By default, the button will
show a spinner and leave the button's width unchanged.
You can also pass the loadingText
prop to show a spinner and the loading text.
<Stack direction="row" spacing={4}><Button isLoading colorScheme="teal" variant="solid"></Button><ButtonisLoadingloadingText="Submitting"colorScheme="teal"variant="outline">Submit</Button></Stack>
You can change the spinner element to use custom loaders as per your design
requirements. Pass the spinner
prop and set it to a custom react element.
<ButtonisLoadingcolorScheme="blue"spinner={<Spinner size="sm" color="white" />}>Click me</Button>
When a loadingText
is present, you can change the placement of the spinner
element to either start
or end
. It is start
by default.
<Stack direction="row" spacing={4} align="center"><ButtonisLoadingloadingText="Loading"colorScheme="teal"variant="outline"spinnerPlacement="start">Submit</Button><ButtonisLoadingloadingText="Loading"colorScheme="teal"variant="outline"spinnerPlacement="end">Continue</Button></Stack>
Social Buttons#
We've included the colors for common social media platforms, and you can simply
use their buttons via the colorScheme
prop.
<HStack><Button colorScheme="facebook" leftIcon={<FaFacebook />}></Button><Button colorScheme="twitter" leftIcon={<FaTwitter />}></Button></HStack>
The Facebook and Twitter icons in the above example are available from
react-icons
as FaFacebook
and
FaTwitter
, found in the react-icons/fa
import.
Grouping Buttons#
You can use the Stack
or ButtonGroup
component to group buttons. When you
use the ButtonGroup
component, it allows you to:
- Set the
size
andvariant
of all buttons within it. - Add
spacing
between the buttons. - Flush the buttons together by removing the border radius of the its children as needed.
<ButtonGroup variant="outline" spacing="6"><Button colorScheme="blue">Save</Button><Button>Cancel</Button></ButtonGroup>
To flush the buttons, pass the isAttached
prop.
<ButtonGroup size="sm" isAttached variant="outline"><Button mr="-px">Save</Button><IconButton aria-label="Add to friends" icon={<AddIcon />} /></ButtonGroup>
Accessibility#
- Button has
role
ofbutton
. - When Button has focus, Space or Enter activates it.
Composition#
All props you pass (variant
, colorScheme
, etc.) are converted to style
props. This means you can override any style of the Button via props.
// The size prop affects the height of the button// It can still be overridden by passing a custom height<Buttonsize="md"height="48px"width="200px"border="2px"borderColor="green.500">Button</Button>
Custom Button#
In the event that you need to make your own custom button, you can leverage the
Box
component. It provides the hover
, focus
, active
and disabled
style
props to style the button.
// Button from facebook.com<Boxas="button"height="24px"lineHeight="1.2"transition="all 0.2s cubic-bezier(.08,.52,.52,1)"border="1px"px="8px"borderRadius="2px"fontSize="14px"fontWeight="semibold"bg="#f5f6f7"borderColor="#ccd0d5"color="#4b4f56"_hover={{ bg: '#ebedf0' }}_active={{bg: '#dddfe2',transform: 'scale(0.98)',borderColor: '#bec3c9',}}_focus={{boxShadow:'0 0 1px 2px rgba(88, 144, 255, .75), 0 1px 1px rgba(0, 0, 0, .15)',}}>Join Group</Box>
Props#
Button Props#
Button
composes the Box
component, so you can pass all its props. These are
props specific to the Button
component:
label
label
ReactNode
Was this helpful?