# Pressable

A Box that is a button or a link as a whole, for custom tiles and rows.

- Family: action
- Import: `import { Pressable } from "@senvenli/react/action";`
- Page: https://design.senvenli.com/docs/components/pressable
- JSON: https://design.senvenli.com/docs/components/pressable.json

## Example: A pressable tile

A custom surface that is one button; `aria-pressed` says which one is chosen.

```tsx
import { Text } from "@senvenli/react/display";
import { Grid, Stack } from "@senvenli/react/layout";
import { Pressable } from "@senvenli/react/action";
import { useState } from "react";

const PLANS = [
  { id: "starter", name: "Starter", detail: "3 projects, 1 seat" },
  { id: "team", name: "Team", detail: "Unlimited projects, 10 seats" },
];

export default function Example() {
  const [plan, setPlan] = useState("starter");
  return (
    <Grid minColumnWidth={200} space="space-150">
      {PLANS.map((item) => (
        <Pressable
          key={item.id}
          padding="space-200"
          radius="large"
          border
          background={plan === item.id ? "selected" : "surface"}
          aria-pressed={plan === item.id}
          onPress={() => setPlan(item.id)}
        >
          <Stack as="span" space="space-050">
            <Text weight="medium">{item.name}</Text>
            <Text size="body-small" tone="subtle">{item.detail}</Text>
          </Stack>
        </Pressable>
      ))}
    </Grid>
  );
}
```

## Examples

### A row that is a link

With `href` the whole row navigates.

```tsx
import { Avatar, Icon, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Pressable } from "@senvenli/react/action";

export default function Example() {
  return (
    <Pressable href="#customer" padding="space-150" radius="large" background="surface-sunken">
      <Stack direction="horizontal" as="span" space="space-150" justify="between" wrap={false}>
        <Stack direction="horizontal" as="span" space="space-150" wrap={false}>
          <Avatar name="Sofia Marin" src="/avatars/05.webp" />
          <Stack as="span">
            <Text weight="medium">Sofia Marin</Text>
            <Text size="body-small" tone="subtle">14 orders</Text>
          </Stack>
        </Stack>
        <Icon name="chevron-right" color="subtle" />
      </Stack>
    </Pressable>
  );
}
```

### Disabled

Dimmed, and it takes no press or focus.

```tsx
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Pressable } from "@senvenli/react/action";

export default function Example() {
  return (
    <Pressable padding="space-200" radius="large" border isDisabled>
      <Stack as="span" space="space-050">
        <Text weight="medium">Enterprise</Text>
        <Text size="body-small" tone="subtle">Not available in your region yet.</Text>
      </Stack>
    </Pressable>
  );
}
```

## Guidelines

### When to use it

- A custom-designed tile or row must be pressable.

### Use something else when

- [card](https://design.senvenli.com/docs/components/card.md): A standard interactive card fits.

## Accessibility

Keyboard:

- Enter, Space: Presses it (Enter only for links).

Built in:

- Real button or link semantics with the inner focus border.

You provide:

- An accessible name from its text or `aria-label`.

## API reference

### Pressable

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| padding | `Space` |  | no |  |
| paddingInline | `Space` |  | no |  |
| paddingBlock | `Space` |  | no |  |
| background | `Background` |  | no |  |
| radius | `Radius` |  | no |  |
| shadow | `Shadow` |  | no |  |
| border | `Border` |  | no |  |
| fullWidth | `boolean` | `true` | no | As wide as its container (default `true`), as a button or a link; `false` hugs what it holds. |
| children | `React.ReactNode` |  | no |  |
| isDisabled | `boolean` |  | no |  |
| aria-label | `string` |  | no | Required when the content has no text that names the action. |
| id | `string` |  | no |  |
| onPress | `(event: PressEvent) => void` |  | no |  |
| href | `string` |  | no |  |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| type | `"button" \| "submit" \| "reset"` |  | no | The behavior of the button when used in an HTML form. |
| form | `string` |  | no | The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#form). |
| rel | `string` |  | no | The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). |
| target | `HTMLAttributeAnchorTarget` |  | no | The target window for the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target). |

Also takes 3 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-neutral-hovered`, `--ds-background-neutral-pressed`, `--ds-background-selected-hovered`, `--ds-background-selected-pressed`, `--ds-border-focused`, `--ds-easing-standard`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-surface-hovered`

## Related

- [box](https://design.senvenli.com/docs/components/box.md)
- [card](https://design.senvenli.com/docs/components/card.md)
