# Mark

Crate: `libero`
Import: `use libero::components::{Highlight, Mark};`
Feature: `mark` (on by default, turns on `box`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/typography/mark.rs>
Index: [index.md](index.md) lists every other page
Description: A `mark` element that highlights text with a light tint of a theme color.

Highlights a chunk of text in a real `<mark>`, tinted with a light shade of the
theme's `warning` color by default. The text color follows the tint, so it
stays readable. `Highlight` marks every match of its search terms in a text.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::{Mark, Text};

#[component]
fn Demo() -> Element {
    rsx! {
        Text {
            "Highlight "
            Mark { color: "warning", "this chunk" }
            " of the text."
        }
    }
}
```

## Props

### Mark

| Prop | Type | Default | Description |
|---|---|---|---|
| `color` | `ThemeAwareValue` | `warning`, tinted | A theme color name gets a light shade, and an explicit shade such as `error.4` stays as it is. Any CSS color works too: a hex turns the text black or white to read on it, any other sets only the background, so set the text color in `sx`. Under a gradient, its first stop; unset, the gradient starts at the theme gradient's first stop, not at `warning`. |
| `gradient` | `Gradient` | - | Fills the highlight with a gradient from `color` to a second stop, as `("info", 90)` or `Gradient::default().to("info").deg(90)`; `Gradient::default()` is the theme's. The text turns black or white, whichever reads on both stops and the span between; the contrast of a literal CSS stop is yours to check. Solid in its first stop where a renderer drops the image; in forced colors, the system highlight colors. |
| `children` | `Element` | required | The highlighted content. |

### Highlight

| Prop | Type | Default | Description |
|---|---|---|---|
| `text` | `String` | required | The plain text searched, in a `<span>`. |
| `terms` | `Vec<String>` | `[]` | Every match of any term is a `Mark`, compared lowercase character by character (no full case folding: `istanbul` does not match `İstanbul`). Where terms overlap, the longest wins; touching matches join into one. Blank terms match nothing. |
| `color` | `ThemeAwareValue` | `warning`, tinted | Each match's `color`, as on `Mark`. |
| `gradient` | `Gradient` | - | Each match's `gradient`, as on `Mark`. |

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

## Accessibility

### Libero handles

- Each highlight is a real `<mark>`.
- For a theme color, a shade or a hex, the text takes the tint's contrast
  color, so it stays readable.
- A link inside is underlined in the text's color, unless its `underline` is
  `never`, and its focus ring clears 3:1 against the tint.
- In forced colors the tint or gradient gives way to the system highlight
  colors, `Mark` and `MarkText`.
- Under a `gradient`, the text is black or white, picked to read at 4.5:1 on
  both stops and the span between in light and dark.

### You must

- With a CSS color name such as `gold`, the text keeps the page's color: check
  its contrast.
- Check the contrast of a literal CSS stop in `gradient`.
- Check a hand-picked pair of theme stops: in the default light theme,
  `success` into `secondary` reads only 4.24:1, and a debug build warns in the
  console. There, any theme color into `error`, the demo's default, reads.
- Say in the text why a highlight matters. Not every screen reader announces
  `<mark>`.

### Example

A search result with the query highlighted, `Mark { "libero" }`: the text
stays readable on the tint, and the result says "1 match" in words, since not
every screen reader announces the highlight.

## Theme defaults

`MarkDefaults` on the theme.

| Field | Type | Description |
|---|---|---|
| `color` | `Color` | Which theme color the tint is taken from; the shade is fixed at 1. |

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-mark-background` | The resolved tint, set per instance from `color` or the theme default. |
| `--lsx-mark-color` | The tint's contrast color for the text, set per instance. Unset for a literal other than a hex. |
| `--lsx-focus-contrast` | The same contrast color, published for focus rings inside the mark. |
| `--lsx-anchor-color` | The same contrast color again, for an `Anchor` inside the mark. |
| `--lsx-focus-ring-halo` | The tint, published beside it as the ring's halo, so a dark shade's white ring still reads. |

## Data attributes

The `states` prop renders as `data-state`. `Mark` adds `gradient` while
`gradient` is set.
