# Button

Generic action primitive using semantic theme classes.

[All components](https://rickylabs.github.io/netscript/design-system/components/) · [Theme builder](https://rickylabs.github.io/netscript/create/) · [Implementation source](https://github.com/rickylabs/netscript/blob/main/packages/fresh-ui/registry/components/ui/button.tsx)

## Live preview

[Open live button preview](https://rickylabs.github.io/netscript/assets/fresh-ui/preview/?component=button&theme=studio-utility)

## Install

```bash
netscript ui:add button
```

## Usage and examples

The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.

```tsx
import { useState } from 'preact/hooks';
import { Button } from '@app/components/ui/button.tsx';

export function Example() {
  const [value, setValue] = useState('standard');
  const [open, setOpen] = useState(false);
  const [notice, report] = useState('');
  return (<><div><div class="demo-row"><Button onClick={() => report("Changes saved")}>Save changes</Button><Button variant="outline">Cancel</Button><Button disabled>Disabled</Button></div></div><p role="status">{notice}</p></>);
}
```

## Props

Generated from native `deno doc --json --private` over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.

| Owner | Prop | Type | Optional | Description |
| --- | --- | --- | --- | --- |
| `SharedButtonProps` | `data-part` | `string` | Yes |  |
| `SharedButtonProps` | `data-scope` | `string` | Yes |  |
| `SharedButtonProps` | `data-size` | `ButtonSize` | Yes |  |
| `SharedButtonProps` | `children` | `Renderable` | No |  |
| `SharedButtonProps` | `variant` | `ButtonVariant` | Yes |  |
| `SharedButtonProps` | `size` | `ButtonSize` | Yes |  |
| `SharedButtonProps` | `disabled` | `boolean` | Yes |  |
| `SharedButtonProps` | `loading` | `boolean` | Yes |  |
| `SharedButtonProps` | `class` | `string` | Yes |  |
| `SharedButtonProps` | `icon` | `Renderable` | Yes |  |
| `SharedButtonProps` | `iconPosition` | `"left" \| "right"` | Yes |  |
| `ButtonAsButtonProps` | `type` | `ButtonElementType` | Yes |  |
| `ButtonAsButtonProps` | `href` | `never` | Yes |  |
| `ButtonAsButtonProps` | `clientNav` | `never` | Yes |  |
| `ButtonAsLinkProps` | `type` | `"link"` | No |  |
| `ButtonAsLinkProps` | `href` | `string` | No |  |
| `ButtonAsLinkProps` | `clientNav` | `boolean` | Yes |  |

```typescript
type ButtonVariant = "primary" | "secondary" | "outline" | "ghost" | "destructive"
type ButtonSize = "sm" | "md" | "lg" | "icon"
type ButtonElementType = "button" | "submit" | "reset"
```

## Keyboard

| Key | Action |
| --- | --- |
| `Enter` | Activate |
| `Space` | Activate button; links use native Enter |

## Tokens

Semantic contract roles: `border/default`, `border/hover`, `border/width`, `destructive/default`, `destructive/fg`, `destructive/hover`, `primary/default`, `primary/fg`, `primary/hover`, `radius/control`, `secondary/border`, `secondary/default`, `secondary/fg`, `text/fg`, `text/muted`.

CSS custom properties referenced directly: `--ns-border`, `--ns-border-hover`, `--ns-border-strong`, `--ns-border-width`, `--ns-component-button-height`, `--ns-component-button-radius`, `--ns-control-gap`, `--ns-control-height`, `--ns-control-height-lg`, `--ns-control-height-sm`, `--ns-control-padding-x`, `--ns-control-padding-x-sm`, `--ns-destructive`, `--ns-destructive-fg`, `--ns-destructive-hover`, `--ns-fg`, `--ns-focus-ring-offset`, `--ns-focus-ring-width`, `--ns-font-label`, `--ns-font-sans`, `--ns-gray-12`, `--ns-leading-strong`, `--ns-motion-duration-normal`, `--ns-motion-easing-normal`, `--ns-muted-fg`, `--ns-primary`, `--ns-primary-fg`, `--ns-primary-hover`, `--ns-primary-stroke`, `--ns-radius-control`, `--ns-radius-lg`, `--ns-radius-sm`, `--ns-red-6`, `--ns-ring`, `--ns-secondary`, `--ns-secondary-border`, `--ns-secondary-fg`, `--ns-secondary-subtle`, `--ns-space-1-5`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-6`, `--ns-state-disabled-opacity`, `--ns-state-hover-opacity`, `--ns-state-pressed-opacity`, `--ns-text-base`, `--ns-text-label`, `--ns-text-small`, `--ns-text-strong`, `--ns-text-xs`, `--ns-tracking-strong`, `--ns-weight-label`, `--ns-weight-strong`.

## Contract and compatibility

Accessibility pattern: [WAI-ARIA guidance](https://www.w3.org/WAI/ARIA/apg/patterns/button/)

- Native DOM attributes pass through where the implementation accepts them.

Design contract values marked planned are not implementation props. The props above describe what ships today.
