Buttons
Button
Buttons allow users to perform an action.
Import
tsximport { Button } from "@hope-ui/core";
tsximport { Button } from "@hope-ui/core";
Usage
tsx<Button>Button</Button>
tsx<Button>Button</Button>
Variants
Use the variant prop to change the visual style of the Button.
tsx<HStack spacing={4}><Button variant="default">Button</Button><Button variant="solid">Button</Button><Button variant="soft">Button</Button><Button variant="outlined">Button</Button><Button variant="plain">Button</Button></HStack>
tsx<HStack spacing={4}><Button variant="default">Button</Button><Button variant="solid">Button</Button><Button variant="soft">Button</Button><Button variant="outlined">Button</Button><Button variant="plain">Button</Button></HStack>
Colors
The colorScheme prop allows changing the color of the Button.
tsx<HStack spacing={4}><Button variant="solid" colorScheme="primary">Button</Button><Button variant="solid" colorScheme="neutral">Button</Button><Button variant="solid" colorScheme="success">Button</Button><Button variant="solid" colorScheme="info">Button</Button><Button variant="solid" colorScheme="warning">Button</Button><Button variant="solid" colorScheme="danger">Button</Button></HStack>
tsx<HStack spacing={4}><Button variant="solid" colorScheme="primary">Button</Button><Button variant="solid" colorScheme="neutral">Button</Button><Button variant="solid" colorScheme="success">Button</Button><Button variant="solid" colorScheme="info">Button</Button><Button variant="solid" colorScheme="warning">Button</Button><Button variant="solid" colorScheme="danger">Button</Button></HStack>
colorScheme prop is ignored when the variant is set to default.Sizes
Use the size prop to change the size of the Button.
tsx<HStack spacing={4}><Button size="xs">Button</Button><Button size="sm">Button</Button><Button size="md">Button</Button><Button size="lg">Button</Button></HStack>
tsx<HStack spacing={4}><Button size="xs">Button</Button><Button size="sm">Button</Button><Button size="md">Button</Button><Button size="lg">Button</Button></HStack>
Button with icon
The leftIcon and rightIcon props allows to add left and right icons to the Button.
tsx<HStack spacing={4}><Button leftIcon={<CopyIcon boxSize={18} />}>Copy to clipboard</Button><Button rightIcon={<ArrowRightIcon />}>Next</Button></HStack>
tsx<HStack spacing={4}><Button leftIcon={<CopyIcon boxSize={18} />}>Copy to clipboard</Button><Button rightIcon={<ArrowRightIcon />}>Next</Button></HStack>
If you want to create your own icon components check out Hope UI Icon documentation.
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.
tsx<HStack spacing={4}><Button isLoading>Loading</Button><Button isLoading loadingText="Processing">Save</Button></HStack>
tsx<HStack spacing={4}><Button isLoading>Loading</Button><Button isLoading loadingText="Processing">Save</Button></HStack>
You can also change the loader element with the loader prop.
tsx<Button isLoading loader={<BeatLoaderIcon boxSize={8} />}>Button</Button>
tsx<Button isLoading loader={<BeatLoaderIcon boxSize={8} />}>Button</Button>
When a loaderText is present, you can change the placement of the loader element to either startorend.
tsx<HStack spacing={4}><Button isLoading loadingText="Loading" loaderPlacement="start">Save</Button><Button isLoading loadingText="Loading" loaderPlacement="end">Continue</Button></HStack>
tsx<HStack spacing={4}><Button isLoading loadingText="Loading" loaderPlacement="start">Save</Button><Button isLoading loadingText="Loading" loaderPlacement="end">Continue</Button></HStack>
Grouping buttons
You can use the ButtonGroup component to group buttons which allows to:
- Set the
variant,colorScheme,sizeandisDisabledstate of all buttons within it. - Flush the buttons together by removing the border radius of its children as needed.
- Supports horizontal and vertical stacking.
tsx<ButtonGroup size="sm" variant="outlined"><Button>Save</Button><IconButton aria-label="Create new file"><PlusIcon /></IconButton></ButtonGroup>
tsx<ButtonGroup size="sm" variant="outlined"><Button>Save</Button><IconButton aria-label="Create new file"><PlusIcon /></IconButton></ButtonGroup>
Use the orientation prop to change the orientation of the group.
tsx<ButtonGroup orientation="vertical"><Button>First</Button><Button>Second</Button><Button>Third</Button></ButtonGroup>
tsx<ButtonGroup orientation="vertical"><Button>First</Button><Button>Second</Button><Button>Third</Button></ButtonGroup>
Theming
Use the ButtonTheme type to override Button styles and default props when extending Hope UI theme.
tsximport { extendTheme, ButtonTheme } from "@hope-ui/core";const theme = extendTheme({components: {Button: {// ...overrides} as ButtonTheme,},});
tsximport { extendTheme, ButtonTheme } from "@hope-ui/core";const theme = extendTheme({components: {Button: {// ...overrides} as ButtonTheme,},});
Component parts
| Name | Static selector | Description |
|---|---|---|
| root | hope-Button-root | Root element |
| icon | hope-Button-icon | Shared icon styles |
| leftIcon | hope-Button-leftIcon | Left icon |
| rightIcon | hope-Button-rightIcon | Right icon |
| loaderWrapper | hope-Button-loaderWrapper | Wrapper arround the loader icon |
| loaderIcon | hope-Button-loaderIcon | Default loader icon |
Props
Button
| Name | Type | Description | Default value |
|---|---|---|---|
| variant | "default" | "solid" | "soft" | "outlined" | "plain" | The visual style of the button. | default |
| colorScheme | "primary" | "neutral" | "success" | "info" | "warning" | "danger" | The color of the button. | primary |
| size | "xs" | "sm" | "md" | "lg" | The size of the button. | md |
| isDisabled | boolean | Whether the button should be disabled. | |
| isFullWidth | boolean | Whether the button should take the full width of its container. | |
| isLoading | boolean | Whether the button is in a loading state. | |
| loaderPlacement | "start" | "end" | The placement of the loader when isLoading is true. | |
| loadingText | string | The label to show in the button when loading is true. | |
| loader | JSX.Element | Replace the loader component when isLoading is true. | |
| leftIcon | JSX.Element | If added, the button will show an icon before the button's label. | |
| rightIcon | JSX.Element | If added, the button will show an icon after the button's label. |
ButtonGroup
| Name | Type | Description | Default value |
|---|---|---|---|
| variant | "default" | "solid" | "soft" | "outlined" | "plain" | The visual style of all wrapped buttons. | |
| colorScheme | "primary" | "neutral" | "success" | "info" | "warning" | "danger" | The color of all wrapped buttons. | |
| size | "xs" | "sm" | "md" | "lg" | The size of all wrapped buttons. | |
| isDisabled | boolean | Whether all wrapped buttons should be disabled. | |
| orientation | "horizontal" | "vertical" | Orientation of the buttons in the group. | horizontal |