# Blockquote

Crate: `libero`
Import: `use libero::components::Blockquote;`
Feature: `blockquote` (on by default, turns on `box`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/typography/blockquote.rs>
Index: [index.md](index.md) lists every other page
Description: A quotation in a tinted frame with an accent bar, with the attribution outside the quote.

A quotation in a tinted frame with an accent bar. The attribution sits in a
`<figcaption>` outside the `<blockquote>`, so a screen reader does not read the
speaker's name as part of the quote. `size` scales the text with the frame, on
[Text](text.md)'s scale. The accent bar sits at the start of the line, on
the right in a right-to-left writing direction.

## Usage

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

#[component]
fn Demo() -> Element {
    rsx! {
        Blockquote {
            attribution: rsx! { "Albert Einstein" },
            "Life is like riding a bicycle. To keep your balance, you must keep moving."
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `Responsive<Size>` | `md` | Text size, line height, padding and the accent bar's width. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `color` | `ThemeAwareValue` | `primary` | The accent bar and the tint behind the quote. A theme color name gets its lightest shade. Any CSS color works too, and a CSS color or a shade from 6 up fills the quote solid, with no separate bar or tint. |
| `radius` | `Responsive<ThemeAwareValue>` | `sm` | Rounds the two corners away from the accent bar, or any CSS, e.g. `radius: "0"`. Or one per breakpoint, `radius: responsive(Size::Xs).md(Size::Lg)`. |
| `attribution` | `Element` | - | Who said it, shown under the quote. For any join other than a comma, pass the whole line here. |
| `work` | `String` | - | The title of the quoted work, such as a book or a talk. Follows `attribution` after a comma. |
| `cite_url` | `String` | - | A URL naming the source. Only machines read it, browsers do not show it. |
| `parts` | `Parts<BlockquotePart>` | - | Styles for the inner parts in the Style API tab, under `sx`. |
| `children` | `Element` | required | The quote. |

Like every component, `Blockquote` also takes the shared props `sx`, `class`,
`style`, `states`, `hidden_from`, `visible_from`, and any extra HTML attributes. They land on the `<figure>`,
a `<div>` without `attribution` or `work`.

## Style API

Style a part with the `parts` prop, or address it as `[data-slot='…']` in your
own CSS. The names are stable. [Styling](styling.md#style-api) explains how
parts work.

| Part | `data-slot` | Description |
|---|---|---|
| `BlockquotePart::Quote` | `quote` | The tinted `<blockquote>`. |
| `BlockquotePart::Caption` | `caption` | The `<figcaption>`, with `attribution` or `work`. |
| `BlockquotePart::Work` | `work` | The `<cite>` holding `work`. |

## Accessibility

### Libero handles

- The quote is a `<blockquote>` in a `<figure>`, and the attribution sits in a
  `<figcaption>` outside it, so a screen reader does not read the speaker's name
  as part of the quote. Without `attribution` or `work` the root is a `<div>`,
  so no nameless figure is announced.
- `work` renders in a `<cite>`, the comma kept outside it.
- The caption dims its text color, not the whole caption, so a link in
  `attribution` keeps its own color and focus ring.
- The quote text, a link and a focus ring inside take the tint's contrast
  color, so they read on the tint. A link keeps its underline, as color alone
  does not mark it. Any other CSS color, such as `navy`, gets black or white
  from the browser's `contrast-color()`.
- A long word breaks inside the quote and its caption rather than overflowing a narrow column.

### Example

A quote with `attribution: rsx! { "Ada Lovelace" }` and `work: "Notes"`: a
screen reader reads the quote, then "Ada Lovelace, Notes" as its caption,
never the name as part of the quote.

### Limits

- `cite_url` is for machines only: browsers do not show it, so link the source
  yourself where readers need it.

## Theme defaults

`BlockquoteDefaults` on the theme, as `theme.blockquote`.

| Field | Type | Default | Description |
|---|---|---|---|
| `size` | `Size` | `Size::Md` | The size used when the prop is unset. |
| `radius` | `Size` | `Size::Sm` | The radius used when the prop is unset. |
| `color` | `Color` | `Color::Primary` | Which theme color the tint and the bar are taken from. |
| `cite_opacity` | `&'static str` | `"0.65"` | The share of the text color the `<figcaption>`'s text keeps. A link in it keeps its own color. |
| `sizes` | `Sizes<BlockquoteSizeLevel>` | below | Padding and bar width per size. |

`BlockquoteSizeLevel`, per size:

| Size | `padding_y` | `padding_x` | `border_width` |
|---|---|---|---|
| `xs` | `0.5rem` | `0.75rem` | `2px` |
| `sm` | `0.75rem` | `1rem` | `2px` |
| `md` | `1rem` | `1.5rem` | `3px` |
| `lg` | `1.25rem` | `2rem` | `3px` |
| `xl` | `1.5rem` | `2.5rem` | `4px` |
| `xxl` | `2rem` | `3rem` | `5px` |

The font size and line height come from `TextDefaults`' scale, so retuning
`theme.text` retunes quotes too. The `<figcaption>` is 0.85 of that font size.

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-blockquote-padding-y-{xs..xxl}` | Vertical padding per size. Declared on `:root` from the theme. |
| `--lsx-blockquote-padding-x-{xs..xxl}` | Horizontal padding per size. Declared on `:root` from the theme. |
| `--lsx-blockquote-border-width-{xs..xxl}` | The accent bar's width per size. Declared on `:root` from the theme. |
| `--lsx-blockquote-cite-opacity` | The share of the text color the `<figcaption>`'s text keeps. Declared on `:root` from the theme. |
| `--lsx-blockquote-background` | The resolved tint, set per instance on the `<blockquote>`. |
| `--lsx-blockquote-border-color` | The resolved accent bar color, set per instance on the `<blockquote>`. |
| `--lsx-blockquote-color` | The tint's contrast color for the body text, set per instance. |
| `--lsx-focus-contrast` | The same contrast color, published for focus rings inside the quote. |
| `--lsx-focus-ring-halo` | The tint, published beside it as the ring's halo. |
| `--lsx-anchor-color` | The same contrast color, for a link inside the quote. |

## Data attributes

State tokens on the `<blockquote>`'s `data-state`; the `<figcaption>` carries the
`size` token too. The `states` prop renders on the root instead.

| Token | Condition |
|---|---|
| `size-<size>` | The `size` in effect. |
| `radius-<size>` | The `radius` in effect. |
