# Providers

Crate: `libero`
Import: `use libero::{IconProvider, IconSet, IconSlot, LiberoProvider};`
Source: <https://github.com/tdymel/libero/tree/main/libero/src/context/libero/mod.rs>
Index: [index.md](index.md) lists every other page
Description: LiberoProvider (themes, localization, formats, direction) and IconProvider (glyphs): what each provides, and how parts of a page sit below different providers.

`LiberoProvider` is the root every app renders once: themes, localization,
formats, stylesheets and portals. `IconProvider` swaps libero's glyphs. Both are
plain context providers, so different parts of one page can sit below different
ones, and the nearest wins.

## Different providers in one page

A `LiberoProvider` inside another gives its own subtree its own `localization`
and `formats`. Everything outside keeps the outer ones. Here the outer
provider has English words and German formats, as the docs site does, so only
the words differ.

```rust
use dioxus::prelude::*;
use libero::{
    LiberoProvider,
    chrono::NaiveDate,
    components::DatePicker,
    localization::{Formats, Localization},
};

#[component]
fn Calendars() -> Element {
    let day = NaiveDate::from_ymd_opt(2026, 3, 14);

    rsx! {
        // English words and German formats.
        LiberoProvider {
            formats: &Formats::GERMAN,
            DatePicker { value: day, onchange: |_| {} }
            // German words as well, only in here; `lang` lets a screen reader say them in German.
            div { lang: "de",
                LiberoProvider {
                    localization: &Localization::GERMAN,
                    formats: &Formats::GERMAN,
                    DatePicker { value: day, onchange: |_| {} }
                }
            }
        }
    }
}
```

Five limits:

- The theme is a sheet on the document root, so a nested provider's `themes`
  do not scope to its subtree.
- `direction` also sets the document root. For one subtree, put a `dir="rtl"`
  attribute on an element around it.
- Only the outermost provider sets the root's `lang`. Put `lang="de"` on an
  element around an inner provider in another language, as above, or a screen
  reader reads its words in the page's voice.
- `use_localization_handle` and `use_formats_handle` switch the nearest provider
  only.
- A nested provider portals into its own outlet, so its popovers stack inside
  the nearest stacking context around it, such as a `ScrollArea`, and a sticky
  header over that area covers them.

## Icon providers merge

Nested `IconProvider`s merge: the inner one wins per slot, the rest comes from
the outer one, then lucide.

```rust
use dioxus::prelude::*;
use libero::{IconProvider, IconSet, IconSlot, LiberoProvider, components::Checkbox};
use pictogram_icons_lucide as lucide;

#[component]
fn Checks() -> Element {
    rsx! {
        LiberoProvider {
            IconProvider {
                icons: IconSet::new().with(IconSlot::CheckboxCheck, lucide::check_check::outlined),
                Checkbox { label: "Outer", checked: true, onchange: |_| {} }
                IconProvider {
                    icons: IconSet::new().with(IconSlot::CheckboxCheck, lucide::square_check::outlined),
                    Checkbox { label: "Inner", checked: true, onchange: |_| {} }
                }
            }
        }
    }
}
```

## Props

### LiberoProvider

| Prop | Type | Default | Description |
|---|---|---|---|
| `themes` | `ThemeSet` | `ThemeSet::DEFAULT` | Every theme the app ships; the light and dark halves share one sheet. A lone `&'static Theme` is a set of one. |
| `localization` | `&'static Localization` | `Localization::ENGLISH` | Every string libero shows a reader. Read at mount; switch it later with `use_localization_handle`. |
| `formats` | `&'static Formats` | `Formats::AMERICAN` | How dates, times and numbers are written, whatever the language. Read at mount; switch it later with `use_formats_handle`. |
| `direction` | `Option<Direction>` | `None` | The start text direction, set as the document root's `dir`. A choice made through `use_direction` is kept on the web and wins. |

### IconProvider

| Prop | Type | Default | Description |
|---|---|---|---|
| `icons` | `IconSet` | required | The slots to swap. An empty slot keeps the outer provider's glyph, then libero's lucide default. |
