# Button

> Cherry Button component - primary, secondary, and tertiary variants, sizes, and outline mode.

Source: https://cherry.al/code/button

# Button

<iframe className="light-only" src="https://demo.cherry.al/preview/button?theme=light" title="Button" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />
<iframe className="dark-only" src="https://demo.cherry.al/preview/button?theme=dark" title="Button" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />

Buttons are essential components in web development, frequently used for user interactions.

Keep in mind that the `<button>` element inherently includes native browser properties like `onClick`. Cherry UI components introduce custom properties that always begin with a `$` to distinguish them from native props.

For design guidelines and all interactive states, see the [Buttons](/buttons) design page.

The examples below assume the Cherry theme provider from [Installation](/code/installation) is already set up.

```jsx
import React from "react";
import { Button } from "cherry-styled-components";

export default function Page() {
  return <Button>Button</Button>;
}
```

You can change the look of your button by adding a `$variant` prop:

```html
<Button $variant="secondary">Button</Button>
```

You can try more variations and props like `$outline`:

```html
<Button $variant="tertiary" $outline>
  Button
</Button>
```

## Properties

<Field value="children" type="React.ReactNode">
  Button content.
</Field>

<Field value="$variant" type='"primary" | "secondary" | "tertiary"'>
  Color variant of the button. Defaults to `"primary"`.
</Field>

<Field value="$size" type='"default" | "big" | "small"'>
  Size of the button.
</Field>

<Field value="$outline" type="boolean">
  Renders the button with an outline style.
</Field>

<Field value="$error" type="boolean">
  Renders the button in the theme's error color.
</Field>

<Field value="$fullWidth" type="boolean">
  Makes the button span the full width of its container.
</Field>

<Field value="$icon" type="React.ReactNode">
  Icon element rendered inside the button.
</Field>

<Field value="$iconPosition" type='"left" | "right"'>
  Position of the icon relative to the label. Defaults to `"left"`.
</Field>

<Field value="disabled" type="boolean">
  Native attribute. While disabled the button turns gray (`grayLight` background and border, `gray` text), shows `cursor: not-allowed`, and all `$variant` and `$error` styles are suppressed.
</Field>

Button forwards its ref to the underlying `HTMLButtonElement`, and any remaining native `<button>` attributes pass through. The props above are typed by the exported `ButtonProps` interface.

## buttonStyles

Button's CSS is also exported as the `buttonStyles(theme, $variant, $size, $outline, $fullWidth, $error, disabled)` helper, so you can style other elements to look like a Button, like a styled link:

```tsx
import styled from "styled-components";
import { buttonStyles } from "cherry-styled-components";

const ButtonLink = styled.a`
  ${({ theme }) => buttonStyles(theme, "primary")}
`;
```

<Button href="https://github.com/cherry-design-system/styled-components/blob/main/src/lib/button.tsx" icon="code" iconPosition="left">
  View Source
</Button>
