You are looking at the documentation of the work in progress Hope UI 1.0, examples and information may be broken or outdated.

Buttons

Button

Buttons allow users to perform an action.

Import

tsx
import { Button } from "@hope-ui/core";
tsx
import { 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>
The 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, size and isDisabled state 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.

tsx
import { extendTheme, ButtonTheme } from "@hope-ui/core";
const theme = extendTheme({
components: {
Button: {
// ...overrides
} as ButtonTheme,
},
});
tsx
import { extendTheme, ButtonTheme } from "@hope-ui/core";
const theme = extendTheme({
components: {
Button: {
// ...overrides
} as ButtonTheme,
},
});

Component parts

NameStatic selectorDescription
roothope-Button-rootRoot element
iconhope-Button-iconShared icon styles
leftIconhope-Button-leftIconLeft icon
rightIconhope-Button-rightIconRight icon
loaderWrapperhope-Button-loaderWrapperWrapper arround the loader icon
loaderIconhope-Button-loaderIconDefault loader icon

Props

Button

NameTypeDescriptionDefault 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
isDisabledbooleanWhether the button should be disabled.
isFullWidthbooleanWhether the button should take the full width of its container.
isLoadingbooleanWhether the button is in a loading state.
loaderPlacement"start" | "end"The placement of the loader when isLoading is true.
loadingTextstringThe label to show in the button when loading is true.
loaderJSX.ElementReplace the loader component when isLoading is true.
leftIconJSX.ElementIf added, the button will show an icon before the button's label.
rightIconJSX.ElementIf added, the button will show an icon after the button's label.

ButtonGroup

NameTypeDescriptionDefault 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.
isDisabledbooleanWhether all wrapped buttons should be disabled.
orientation"horizontal" | "vertical"Orientation of the buttons in the group.horizontal
Previous
Text