Button

Triggers an action or event.

Usage

Code
import { Button, ButtonGroup } from '@leverui/components';
Code
<Button>Click me</Button>

Examples

Sizes

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

Variants

Use the variant prop to change the visual style of the Button.

Icon

Use icons within a button.

Color

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

gray

red

green

blue

teal

pink

purple

cyan

orange

yellow

Disabled

Use the disabled prop to disable the button.

For a disabled link, prevent navigation and add aria-disabled and data-disabled.

Loading

Use loading and loadingText while an action is in progress.

Toggle loading while keeping the Button width steady.

Spinner Placement

Use spinnerPlacement to move the spinner.

Custom Spinner

Use spinner to change the loading indicator.

Group

Share size and variant choices with ButtonGroup.

Use attached to join the buttons.

Split Menu

Combine a Button and Menu in an attached Group.

Responsive Size

Pass breakpoint choices to size for a responsive Button.

Radius

Use public radius variables to change Button corners.

Semantic radius

Core radius

Use as="a" to render a semantic link.

Ref

ref gives you the real button element.

Code
import { onSettled } from 'solid-js';
import { Button } from '@leverui/components';

export function Demo() {
  let button: HTMLButtonElement | undefined;

  onSettled(() => button?.focus());

  return (
    <Button
      ref={(element) => {
        button = element;
      }}
    >
      Click me
    </Button>
  );
}

Customization

Style with plain CSS and the --leverui-* variables. Load your CSS after @leverui/components/styles.css.

Adding a new variant

Give the button a class and style it. The variant prop accepts only the six built-in variants.

Code
.action-pill.leverui-button {
  border-radius: 9999px;
  padding-inline: 1.5rem;
  background: var(--leverui-colors-blue-solid);
  color: var(--leverui-colors-blue-contrast);
}
Code
import { Button } from '@leverui/components';

export function Demo() {
  return <Button class="action-pill">Pill Button</Button>;
}

Adding a new size

Give the button a class and set the size in CSS.

Code
.action-xxl.leverui-button {
  min-height: 4rem;
  min-width: 4rem;
  padding-inline: 2rem;
  font-size: 1.25rem;
}

Changing the default size

ButtonPropsProvider sets the default size for the buttons inside it. A size on a button wins.

Code
import { Button, ButtonPropsProvider } from '@leverui/components';

export function Demo() {
  return (
    <ButtonPropsProvider value={{ size: 'lg' }}>
      <Button>Large by default</Button>
    </ButtonPropsProvider>
  );
}

Changing the default variant

Code
import { Button, ButtonPropsProvider } from '@leverui/components';

export function Demo() {
  return (
    <ButtonPropsProvider value={{ variant: 'outline' }}>
      <Button>Outline by default</Button>
    </ButtonPropsProvider>
  );
}

Props

PropDefaultType
spinnerPlacement'start''start' | 'end'
colorPalette'gray'Palette name
size'md''2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' or responsive choices
variant'solid''solid' | 'subtle' | 'surface' | 'outline' | 'ghost' | 'plain' or responsive choices
loadingfalseboolean
loadingText—JSX.Element
spinner—JSX.Element
as'button'Native element tag
asChild—Solid render callback

Other HTML attributes go to the rendered tag. asChild takes a Solid function that returns your own element.