# SiteDomain

> A site's domain where the app says which site a page is on, cut at its start when it doesn't fit, so its end, whose site it is, always shows.

Source: https://raft-design.botiverse.build/components/site-domain. Generated from the current release; where it differs from what you remember, this page is right.

SiteDomain draws a site's domain where the app says which site a page is on: a built-in browser's address bar, the head over a page on another site, a web page's panel title. When the domain is longer than its room it loses its start, never its end. The end of a domain says whose site it is: `accounts.google.com.sign-in.evil-example.net` with its end cut off would read as Google.

```tsx
import { Badge } from "@botiverse/raft-ui";
import { SiteDomain } from "@botiverse/raft-ui/wip";

/**
 * Heads over pages on other sites: the site's domain, with Not secure before
 * it on http. A domain that fits starts at the left; one too long for the head
 * loses its start, so its end, whose site it is, still shows.
 */
export function SiteDomainHeadContent() {
  return (
    <div className="flex w-80 max-w-full min-w-24 resize-x flex-col gap-3 overflow-hidden p-1">
      <div
        className="flex h-11 min-w-0 items-center gap-2 rounded-container border border-line-hairline bg-layer-canvas px-3"
        title="https://calendar.example.com/sign-in"
      >
        <SiteDomain
          host="calendar.example.com"
          className="text-callout font-bold text-foreground"
        />
      </div>
      <div
        className="flex h-11 min-w-0 items-center gap-2 rounded-container border border-line-hairline bg-layer-canvas px-3"
        title="http://accounts.google.com.sign-in.account-recovery.evil-example.net/challenge"
      >
        <Badge appearance="soft" variant="warning" className="shrink-0">
          Not secure
        </Badge>
        <SiteDomain
          host="accounts.google.com.sign-in.account-recovery.evil-example.net"
          className="text-callout font-bold text-foreground"
        />
      </div>
    </div>
  );
}
```

## When to use

| Situation                                                                          | Use                                                                                                                                                                     |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The domain of the page someone is on, in a head, an address bar or a panel title   | SiteDomain                                                                                                                                                              |
| A web page's row that shows its path too (a web page opened beside a conversation) | SiteDomain for the domain, and the path beside it as text cut at its end ([Address rows](#address-rows))                                                                |
| A built-in browser's address bar                                                   | SiteDomain alone: the bar shows only the domain, the path is noise there ([Navigation](https://raft-design.botiverse.build/patterns/navigation.md#where-raft-isnt-signed-in), rule 4) |
| A link's domain after a card button's label, or in a link preview                  | Text: it names where a link goes, not the page someone is on, and is written without the `www.` ([MessageItem](https://raft-design.botiverse.build/components/message-item.md))                        |
| A file name, a title or another name too long for its row                          | [Ellipsis](https://raft-design.botiverse.build/components/ellipsis.md): it cuts at the end                                                                                                                 |

## Anatomy

- `SiteDomain`: a `span` that cuts its text at the start, holding the domain in a left-to-right `bdi`. Its `host` is the domain. Required.

It draws the domain and nothing else. The Not secure badge, the path, the tooltip with the full address and any icon are the caller's, beside it.

## Behavior

- A domain that fits starts at the inline start, as every head and address does.
- One that doesn't fit is cut at its start with an ellipsis: the box is laid right to left so the browser's `text-overflow: ellipsis` falls at the start, and the `bdi` keeps the domain itself, and text selected or copied from it, left to right. Find in page, copy and screen readers get the whole domain.
- It shrinks in a flex row (`min-w-0`). Put it after whatever should give up its room first, and give that `shrink`.

### Address rows

Only where the design shows a page's path as well, today the row of a web page opened beside a conversation, the domain comes first, in full and bold, and the path, query and fragment follow it, muted and cut at their end. The path gives up its room first (`shrink-9999`); the domain is cut, at its start, only once the path has gone. A built-in browser's address bar shows the domain alone, with no path ([Navigation](https://raft-design.botiverse.build/patterns/navigation.md#where-raft-isnt-signed-in), rule 4). Never pass a whole address to SiteDomain: cut at its start, an address loses its domain first.

```tsx
import { SiteDomain } from "@botiverse/raft-ui/wip";

const ADDRESS = "https://docs.example.com/guides/getting-started/install?platform=macos#homebrew";

/**
 * The row of a web page opened beside a conversation: the domain in full,
 * bold, and the path after it, muted. The path gives up its room first and is
 * cut at its end; the domain is cut, at its start, only once the path has gone.
 */
export function SiteDomainAddressContent() {
  const url = new URL(ADDRESS);
  const path = `${url.pathname === "/" ? "" : url.pathname}${url.search}${url.hash}`;
  return (
    <div
      className="flex h-8 w-full max-w-sm min-w-0 items-center rounded-control border border-line-hairline px-3 text-callout"
      title={ADDRESS}
    >
      <SiteDomain host={url.host} className="font-bold text-foreground" />
      <span className="min-w-0 shrink-9999 truncate text-foreground-muted">{path}</span>
    </div>
  );
}
```

## Content

- Pass the domain as `URL.host` gives it: ASCII (punycode, `xn--…`) for an internationalized domain, so a look-alike Unicode domain can't pass for another, and with its port when it has one. Don't drop `www.` or any other subdomain: a subdomain can belong to someone else.
- On an `http:` page, show Not secure before the domain: a [Badge](https://raft-design.botiverse.build/components/badge.md) with `appearance="soft"` and `variant="warning"`, which doesn't shrink.
- Put the full address in the row's `title` (or a [Tooltip](https://raft-design.botiverse.build/components/tooltip.md)), so a cut domain can still be read in full.

## Accessibility

- It is text, with no role of its own. A screen reader reads the whole domain, left to right, whatever is cut.
- A head or a panel that names its page by the domain uses it inside its heading element.

## Rules

- Cut a domain at its start, never its end: the end says whose site it is.
- Draw only a domain with it. The path goes beside it, cut at its end.
- Show the domain in ASCII form, as the browser's address does: a Unicode look-alike of another site's domain would read as that site.

## API

### SiteDomain

A site's domain where the app says which site a page is on. Too long for its room, it loses its start, never its end: the end says whose site it is. The right-to-left box puts the ellipsis at the start; the `<bdi>` keeps the domain itself, and text selected from it, left to right.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `host` (required) | `string` |  | The site's domain as `URL.host` gives it: ASCII (punycode) for an internationalized domain, with its port when it has one. Never a full address: the path goes beside it, cut at its end (site-domain.md). |

Also takes the attributes of its element.
