Skip to main content

Button

Used to trigger an operation.

When to Use

A button represents an operation (or a series of operations). Clicking a button will trigger corresponding business logic.

In Kube Design we provide 4 types of buttons:

  • Primary button: Indicates the main action, one primary button at most in one section
  • Default button: Indicates a series of actions without priority
  • Text button: Used for the most secondary action
  • Link button: Used for external links

Examples

Variants

Kube Design provides filled button, outline button, text button and link button.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button variant="filled" color="secondary">
        Filled
      </Button>
      <Button variant="outline" color="default" radius="xl">
        Outline
      </Button>
      <Button variant="text" radius="xl">
        Text
      </Button>
      <Button variant="link" color="default">
        Link
      </Button>
    </Group>
  );
}
Result
Loading...

Colors

Button has six colors. The color property can be set to default, primary, secondary, success, warning and error.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button variant="filled" color="default">
        Default
      </Button>
      <Button variant="filled" color="primary">
        Primary
      </Button>
      <Button variant="filled" color="secondary">
        Secondary
      </Button>
      <Button variant="filled" color="success">
        Success
      </Button>
      <Button variant="filled" color="warning">
        Warning
      </Button>
      <Button variant="filled" color="error">
        Error
      </Button>
    </Group>
  );
}
Result
Loading...

Disabled State

To mark a button as disabled, add the disabled property to the Button.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button variant="filled" color="primary" disabled>
        Disabled Filled
      </Button>
      <Button variant="outline" color="secondary" disabled>
        Disabled Outline
      </Button>
      <Button variant="text" disabled>
        Disabled Text
      </Button>
    </Group>
  );
}
Result
Loading...

Block Button

The block property will make the button fit to its parent width.

Live Editor
function Demo() {
  return (
    <div style={{ width: '100%' }}>
      <Button variant="filled" color="primary" block>
        Primary Block
      </Button>
      <div style={{ marginTop: '12px' }}>
        <Button variant="outline" color="secondary" block>
          Outline Block
        </Button>
      </div>
    </div>
  );
}
Result
Loading...

Shadow Button

The shadow property will make the button have a shadow effect.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button variant="filled" color="primary" shadow>
        Primary
      </Button>
      <Button variant="filled" color="secondary" shadow>
        Secondary
      </Button>
      <Button variant="filled" color="success" shadow>
        Success
      </Button>
      <Button variant="filled" color="warning" shadow>
        Warning
      </Button>
      <Button variant="filled" color="error" shadow>
        Error
      </Button>
    </Group>
  );
}
Result
Loading...

Size and Radius

Use the size and radius props to change the size or radius of the button. You can set the value to xs, sm, md, lg or xl.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button variant="filled" color="primary" radius="sm" size="xs">
        XS Size
      </Button>
      <Button variant="filled" color="primary" radius="md" size="sm">
        Small
      </Button>
      <Button variant="filled" color="success" radius="md" size="md">
        Medium
      </Button>
      <Button variant="filled" color="warning" radius="lg" size="lg">
        Large
      </Button>
      <Button variant="filled" color="error" radius="xl" size="xl">
        XL Size
      </Button>
    </Group>
  );
}
Result
Loading...

Loading State

A loading indicator can be added to a button by setting the loading property.

Live Editor
function Demo() {
  const [loading, setLoading] = React.useState(false);

  const handleClick = () => {
    setLoading(true);
    setTimeout(() => setLoading(false), 2000);
  };

  return (
    <Group spacing="xl">
      <Button variant="filled" color="primary" size="md" loading={loading} onClick={handleClick}>
        {loading ? 'Loading...' : 'Click Me'}
      </Button>
      <Button variant="filled" color="primary" size="lg" loading>
        Always Loading
      </Button>
    </Group>
  );
}
Result
Loading...

With Icon

Button components can contain an Icon. This is done by setting the leftIcon or rightIcon property or placing an Icon component within the Button.

Live Editor
function Demo() {
  const { Add } = KubedIcons;
  return (
    <Group spacing="xl">
      <Button variant="filled" radius="xl" leftIcon={<Add size={16} />}>
        Left Icon
      </Button>
      <Button variant="filled" radius="xl">
        <Add />
      </Button>
      <Button variant="filled" radius="xl" color="success">
        <Add />
      </Button>
      <Button variant="filled" radius="xl" color="success" rightIcon={<Add size={16} />}>
        Right Icon
      </Button>
    </Group>
  );
}
Result
Loading...

As Different Element

The as attribute can change the underlying element used by the component.

Live Editor
function Demo() {
  return (
    <Group spacing="xl">
      <Button as="a" href="https://kubesphere.io" target="_blank" variant="filled" color="primary">
        Link Button
      </Button>
      <Button as="a" href="#button" variant="outline" color="secondary">
        Anchor Link
      </Button>
    </Group>
  );
}
Result
Loading...

API

Button Props

PropertyDescriptionTypeDefault
variantButton variant'filled' | 'outline' | 'text' | 'link''filled'
colorButton color'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error''default'
sizeButton size'xs' | 'sm' | 'md' | 'lg' | 'xl''sm'
radiusBorder radius'xs' | 'sm' | 'md' | 'lg' | 'xl' | number'xl'
disabledDisabled statebooleanfalse
loadingLoading statebooleanfalse
blockFull width buttonbooleanfalse
shadowAdd shadow effectbooleanfalse
leftIconLeft side iconReactNode-
rightIconRight side iconReactNode-
asChange underlying elementstring | Component'button'
classNameCustom class namestring-
childrenButton contentReactNode-
othersNative attributesButtonHTMLAttributes<HTMLButtonElement>-
info

Button component inherits all native HTML button element attributes (such as onClick, onMouseEnter, type, etc.). When using the as property, it will inherit the attributes of the corresponding element.