Skip to content

Button

Default button

Use the variant prop to change the visual aspect of the button.

Show code
default.tsx
import { Button } from "@hrc/button";
export function ButtonDefault() {
return (
<>
<Button />
<Button variant="outline">Outline</Button>
<Button variant="text">Text</Button>
</>
);
}

Colors

Use the color prop to change the color of the button.

Show code
colors.tsx
import { Button } from "@hrc/button";
const colors = [
"primary",
"secondary",
"error",
"info",
"warning",
"success",
] as const;
const toTitleCase = (str: string) => `${str[0].toUpperCase()}${str.slice(1)}`;
export function ButtonColors() {
return (
<>
{colors.map((color) => (
<div key={`button-${color}`}>
<Button color={color}>{toTitleCase(color)}</Button>
<Button color={color} variant="outline">
Outline
</Button>
<Button color={color} variant="text">
Text
</Button>
</div>
))}
</>
);
}

Disabled

Add the disabled prop to disable the button. The disabled variant has a higher priority than the color variant.

Show code
import { useState } from "react";
import { Button } from "@hrc/button";
import { ToggleDisabled } from "./ToggleDisabled";
export function ButtonDisabled() {
const [disabled, setDisabled] = useState(false);
return (
<>
<ToggleDisabled disabled={disabled} setter={setDisabled} />
<Button disabled={disabled} />
<Button variant="outline" disabled={disabled}>
Outline
</Button>
<Button variant="text" disabled={disabled}>
Text
</Button>
<Button color="warning" disabled={disabled} />
<Button color="info" variant="outline" disabled={disabled}>
Outline
</Button>
<Button color="success" variant="text" disabled={disabled}>
Text
</Button>
</>
);
}

Sizes

Set the size prop to change the size of the button.

Show code
sizes.tsx
import { Button } from "@hrc/button";
export function ButtonSizes() {
return (
<>
<Button color="primary" size="small">
Small
</Button>
<Button color="primary" />
<Button color="primary" size="large">
Large
</Button>
</>
);
}

Rounded

Add the roundedSide prop or set the fullRounded prop to change the button’s border radius.

Show code
rounded.tsx
import { Button } from "@hrc/button";
export function ButtonRounded() {
return (
<>
<Button color="secondary" roundedSide="top">
Top rounded
</Button>
<Button color="secondary" roundedSide="bottom">
Bottom rounded
</Button>
<Button color="secondary" roundedSide="left">
Left rounded
</Button>
<Button color="secondary" roundedSide="right">
Right rounded
</Button>
<Button color="secondary" fullRounded>
Full rounded
</Button>
</>
);
}

With Icons

You can add icons to the button using the iconStart and iconEnd props.

Show code
with-icons.tsx
import { Button } from "@hrc/button";
import { Icon } from "@hrc/material-icons";
export function ButtonWithIcons() {
return (
<>
<Button color="error" iconStart={<Icon name="delete" />}>
Delete
</Button>
<Button color="error" iconEnd={<Icon name="delete" />}>
Delete
</Button>
<Button color="error" variant="outline" iconStart={<Icon name="close" />}>
Close
</Button>
<Button color="error" variant="outline" iconEnd={<Icon name="close" />}>
Close
</Button>
<Button color="error" variant="text" iconStart={<Icon name="favorite" />}>
Favorite
</Button>
<Button color="error" variant="text" iconEnd={<Icon name="favorite" />}>
Favorite
</Button>
</>
);
}

API

See documentation below for reference to all of the props, classes and CSS variables (custom properties) available for <Button />: