Button

Documentation of the <Button /> component. Learn how to use it and its available props.

Installation

To get started, install @exponentialeducation/betomic via yarn:

# Yarn
yarn add @exponentialeducation/betomic

Use of Button

Button is used by users to trigger action and operations when clicked.

import { Button } from "@exponentialeducation/betomic";
function IndexPage() {
return (
<main>
{/* ... */}
<Button>
Click me!
</Button>
{/* ... */}
</main>
)
}

The previous example describes the simplest way of using the Button component, it uses default props and renders a button like the following:

Sizes & variants

Betomic comes with three different sizes as well as variants for buttons.
Primary and secondary button variants indicate main and secondary actions respectivelly.
Tertiary variant also handles dark mode. Disabled buttons are non-interactive.

Small

PrimarySecondaryTertiaryDisabled

Medium

PrimarySecondaryTertiaryDisabled

Large

PrimarySecondaryTertiaryDisabled

Some examples of button sizes, variants and props:

import { Button } from "@exponentialeducation/betomic";
function IndexPage() {
return (
<main>
{/* ... */}
<Button size="sm" variant="primary">
Small primary button
</Button>
<Button variant="secondary">
Secondary button
</Button>
<Button variant="tertiary" disabled>
Tertiary button disabled
</Button>
{/* ... */}
</main>
)
}

Wrapping styles

Buttons handle two different wrapping styles, also known as constraints: Fill container and Hug contents.

Hug contents

Hug contents constraint keeps the size of the button bounded to its content. It means that the button will adapt its size according to the elements that it holds.

TextText + icon fixedText + icon extended

Fill container

Fill container constraint resizes the button to fill the width of its direct container.

TextText + icon fixed

Icon

Icon style adjusts button paddings to keep a 1:1 square aspect ratio.

SmallMediumLarge

Loading

Icon style adjusts button paddings to keep a 1:1 square aspect ratio.

SmallMediumLarge

Some examples of button wrapping styles and props:

import { Button } from "@exponentialeducation/betomic";
function IndexPage() {
return (
<main>
{/* ... */}
<Button>
Hug contents button
</Button>
<Button block className="justify-between">
Fill container button <ArrowRightIcon />
</Button>
<Button icon size="lg">
<ArrowRightIcon />
</Button>
<Button icon loading>
<ArrowRightIcon />
</Button>
{/* ... */}
</main>
)
}

Props

Extends ButtonHTMLAttributesprops

prop

description

block?

boolean = false
Wheter this button should fill container.
If not set to true, button hugs content.

className?

string
A list of CSS classes (e.g. TailwindCSS) to display and extend styles along with current button classes.

disabled?

boolean = false
Whether this button should be disabled, display disabled styles and be non-interactive.

icon?

boolean = false
Whether this button should display only an icon.
If set to true, button aspect ratio becomes a square to hold an icon.

size?

"sm" | "md" | "lg" = "md"
Whether this button should display button small, medium or large size styles.

type?

"button" | "reset" | "submit" = "button"
Sets the type attribute of button element.

variant?

"primary" | "secondary" | "tertiary" = "primary"
Whether this button should display button primary, secondary or tertiary styles.

style?

CSSProperties
A set of native CSS properties.

loading?

boolean? default=false
If set to true, the button will display a centered loading spinner instead of its contents, and the button will be disabled. The width of the button is not affected by the value of this prop.

onClick?

(event: MouseEvent<HTMLElement>) => void
Click event handler.