# Toggle

Botão que fica apertado. Vive dentro de um `ToggleGroup`.

## No React Native

Traduz: o `@rivocode/ui-native` exporta `Toggle` - `pressed` e `onPressedChange`. A API não é a mesma do web (no nativo tudo é controlado), e a [tabela de paridade](/react-native) diz o que muda peça a peça.

## Importação

```tsx
import { Toggle } from '@rivocode/ui'
```

## Exemplos

### Modo de exibição

```tsx
import { Toggle, ToggleGroup } from '@rivocode/ui'

export function ViewMode() {
  return (
    <ToggleGroup defaultValue={['lista']}>
      <Toggle value="lista">Lista</Toggle>
      <Toggle value="grade">Grade</Toggle>
      <Toggle value="calendario">Calendário</Toggle>
    </ToggleGroup>
  )
}
```

## Props

| Prop | Tipo | Obrigatória | Desde | O que faz |
| --- | --- | --- | --- | --- |
| `defaultPressed` | `boolean` |  | 0.4.0 | Whether the toggle button is currently pressed. |
| `disabled` | `boolean` |  | 0.4.0 | Whether the component should ignore user interaction. |
| `nativeButton` | `boolean` |  | 0.4.0 | Whether the component renders a native `<button>` element when replacing it via the `render` prop. |
| `onPressedChange` | `((pressed: boolean, eventDetails: { reason: "none"; event: Event; cancel: () => void; allowPropagation: () => void; isCanceled: boolean; isPropagationAllowed: boolean; trigger: Element \| undefined; }) => void)` |  | 0.4.0 | Callback fired when the pressed state is changed. |
| `pressed` | `boolean` |  | 0.4.0 | Whether the toggle button is currently pressed. |
| `render` | `ComponentRenderFn<HTMLProps, ToggleState> \| ReactElement<unknown, string \| JSXElementConstructor<any>>` |  | 0.4.0 | Allows you to replace the component's HTML element with a different tag, or compose it with another component. |
| `value` | `string` |  | 0.4.0 | A unique string that identifies the toggle when used inside a toggle group. |

Além dessas: repassa `className`, `style`, `id` e os demais atributos do elemento raiz.

## Ver também

- [Button](/componentes/button.md)
- [ButtonGroup](/componentes/button-group.md)
- [Clipboard](/componentes/clipboard.md)
- [ToggleGroup](/componentes/toggle-group.md)
- [Toolbar](/componentes/toolbar.md)
- [Convenções da biblioteca](/convencoes.md): Provider, tokens e as regras que valem para toda peça
- [Índice completo](/llms.txt)
