# Repository

Crate: `libero`
Import: `use libero::components::{Repository, RepoHost};`
Feature: `repository` (off by default, turns on `action-icon`, `use-local-storage`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/buttons/repository.rs>
Index: [index.md](index.md) - every other component's markdown page
Description: A link to a GitHub or GitLab repository with its star count beside the host's icon.

A link to a repository with its star count beside the host's icon. It opens in a
new tab. The count comes from the host's public API at mount and is kept for the
session. Until it arrives, when it is 0, or when the host does not answer, the
icon stands alone. Native builds fetch through dioxus-native's `net` feature, on
by default.

## Usage

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

#[component]
fn Demo() -> Element {
    rsx! {
        Repository {
            repo: "tdymel/libero",
            new_tab_icon: true,
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `repo` | `String` | required | `owner/repo`, as in the repository's URL. GitLab takes nested groups too. |
| `host` | `RepoHost` | `GitHub` | Where the repository lives: `RepoHost::GitHub` or `RepoHost::GitLab`. |
| `variant` | `Variant` | `outlined` | Visual style, as on `ActionIcon`. |
| `color` | `ThemeAwareValue` | `muted` | Accent color. A theme color name or any CSS color. Unset, a `gradient` takes the theme's gradient, as no label reads on a muted one. |
| `size` | `Responsive<ThemeAwareValue>` | `md` | Button size. The icon takes half 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)`. |
| `aria_label` | `String` | - | Replaces the name's subject, the host and repository; the star count and new-tab cue still follow. A raw `"aria-label"` attribute replaces the whole name. |
| `new_tab_icon` | `bool` | `false` | Draws the new-tab icon in the corner of the link. Unset, the theme's `anchor.new_tab_icon`, which is off. |
| `parts` | `Parts<RepositoryPart>` | - | Styles for the inner parts in the Style API tab, under `sx`. |

Like every component, `Repository` also takes the shared props `sx`, `class`,
`style`, `states`, `hidden_from`, `visible_from`, and any extra HTML attributes. They land on the link.

## Style API

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

| Part | `data-slot` | Description |
|---|---|---|
| `RepositoryPart::Icon` | `icon` | The host's logo. |
| `RepositoryPart::Count` | `count` | The star count, once it has loaded. |

## Accessibility

### Libero handles

- The link's name is the host and repository ("GitHub tdymel/libero"), the exact
  star count once it arrives ("1234 stars", where the button shows `1.2k`; bare digits, as `1.234` reads as
  a decimal in English), and
  the new-tab cue, so two buttons on one page read apart. The words come from `RepositoryLabels::stars`,
  `RepositoryLabels::compact` and `AnchorLabels::new_tab` in the localization.
- The drawn count is not read twice: the name replaces the link's content.
- A count drawn in the accent color, which could miss 4.5:1, takes the `ink`
  color instead.
- Set, `aria_label` replaces the host and repository; the star count and new-tab
  cue still follow it.

### You must

- With your own `aria_label`, name the repository. With a raw `"aria-label"`
  attribute, which replaces the whole name, also say the star count and that it
  opens in a new tab.

### Example

A header link, `Repository { repo: "tdymel/libero" }`: a screen reader reads
"GitHub tdymel/libero", then the star count once it arrives, then that it
opens in a new tab.

## Theme defaults

`RepositoryDefaults` on the theme, as `repository`.

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

The count's words are `RepositoryLabels::stars` in the localization, a function
of the count for plural forms; it takes the exact count as bare digits
(`1234`), as digit groups read as a decimal under another language's formats. The shortened count on the button (`1.2k`, German
`1,2 Tsd.`) is `RepositoryLabels::compact`. The new-tab cue is
`AnchorLabels::new_tab`.

## CSS variables

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

## Data attributes

`ActionIcon`'s, on the link's `data-state`. A `display: contents` wrapper around
the link carries `stars` while a count shows.
