# DirectionToggle

Crate: `libero`
Import: `use libero::components::DirectionToggle;`
Feature: `direction-toggle` (off by default, turns on `action-icon`, `use-direction`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/buttons/direction_toggle.rs>
Index: [index.md](index.md) - every other component's markdown page
Description: An icon button that turns the app's text between left to right and right to left.

An icon button that turns the app's text between left to right and right to
left. It sets the document's `dir`, so every component and every overlay turns
with it, and the web keeps the choice for the next visit. The arrow shows where
the next press goes. It needs no state of its own; build your own control on
`use_direction()`, and set the start direction with `LiberoProvider { direction }`.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::DirectionToggle;

#[component]
fn Demo() -> Element {
    rsx! {
        DirectionToggle {}
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `variant` | `Responsive<Variant>` | `outlined` | Visual style, as on `ActionIcon`. Or one per breakpoint, `variant: responsive(Variant::Outlined).md(Variant::Filled)`. |
| `color` | `ThemeAwareValue` | `muted` | Accent color. A theme color name or any CSS color. |
| `size` | `Responsive<ThemeAwareValue>` | `md` | Button size. The icon takes 55% of it. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. |
| `radius` | `Responsive<ThemeAwareValue>` | `sm` | Corner radius, independent of `size`. Or one per breakpoint, `radius: responsive(Size::Sm).md(Size::Xl)`. |
| `label` | `Callback<Direction, String>` | - | Replaces the two built-in names. Gets the direction a press turns the text to and returns what the press does. |
| `disabled` | `bool` | `false` | Disables and dims the button. |

Like every component, `DirectionToggle` also takes the shared props `sx`,
`class`, `style`, `states`, `hidden_from`, `visible_from`, and any extra HTML attributes.

## Accessibility

### Libero handles

- The button's name says what a press does, from the localization's
  `DirectionToggleLabels`: `to_rtl` or `to_ltr`.
- It sets the document's `dir`, so a screen reader and every component follow
  the new direction.

### You must

- With `label`, return what the press does, not the current direction.

### Example

A `DirectionToggle {}` in the site header on an English page: its name says
what a press does, switch to right-to-left, and after the press the page and
its components follow the new direction.

## Theme defaults

`DirectionToggleDefaults` on the theme, as `direction_toggle`.

| Field | Type | Description |
|---|---|---|
| `variant` | `Variant` | Default `variant` when the prop is omitted (`outlined`). |
| `color` | `Color` | Default `color` when the prop is omitted (`muted`). |

The names are `DirectionToggleLabels` in the localization: `to_rtl` and
`to_ltr`.

## CSS variables

None of its own; it renders an `ActionIcon`, whose variables apply.

## Data attributes

`ActionIcon`'s, on the root's `data-state`.
