Sources
Where an answer came from: numbered source cards under the answer, and the
superscript markers in its text that point at them. ds::sources is the list,
ds::source-card one card, and ds::citation the marker.

No script for the list or the cards. A citation is a link to its card's anchor with no script at all; with Alpine and the package's script, resting on it or tabbing to it also shows the source in a hover card.
Use it
The answer, citing by number, and its sources below:
<p>
Orders can be refunded for 30 days after delivery<x-ds::citation number="1" :title="$sources[0]['title']" :url="$sources[0]['url']" />,
or 14 for opened electronics<x-ds::citation number="2" :title="$sources[1]['title']" :url="$sources[1]['url']" />.
</p>
<x-ds::sources :sources="$sources" />
$sources is rows the host built, numbered by the host:
$sources = [
['number' => 1, 'title' => 'Refund policy', 'url' => 'https://help.example.com/refunds', 'favicon' => '/favicons/help.png', 'snippet' => 'Thirty days from delivery…'],
['number' => 2, 'title' => 'Opened electronics', 'url' => 'https://help.example.com/electronics'],
];
Several answers on one page each need their own anchors, or citation 1 of the third answer jumps to source 1 of the first:
<x-ds::citation number="1" :anchor="'m'.$message->id.'-source'" … />
<x-ds::sources :anchor="'m'.$message->id.'-source'" :sources="$message->sources" />
Folded to one line, "5 sources" with their icons, until opened:
<x-ds::sources :collapsed="true" :sources="$sources" />
A grid or a list, with the rest behind "+3 more":
<x-ds::sources layout="grid" :max="3" :sources="$sources" />
<x-ds::sources layout="list" :sources="$sources" />
Props: sources
| Prop | Type | Default | What it does |
|---|---|---|---|
sources | array | [] | Rows: title, url, favicon, snippet, number (the row's place, from 1, when left out). Arrays or objects. |
layout | row grid list | row | One line that scrolls sideways and snaps card by card; a grid by the container's width; or a column. |
max | int | — | Show this many; the rest open under "+N more", a native disclosure. |
collapsed | bool | false | One line, "5 sources" with up to four icons, that opens to the list. |
open | bool | false | With collapsed, open on first paint. |
label | string | Sources | Names the list, shown above it. Collapsed, the line's words name it. |
anchor | string | source | Each card's id is {anchor}-{number}. |
variant | compact detailed | detailed in a list, else compact | detailed shows each snippet. |
summaryLabel | string | :count source|:count sources | The collapsed line. |
moreLabel | string | +:count more | The fold's words. |
target | string | _blank | Where the links open. |
Props: source-card
| Prop | Type | Default | What it does |
|---|---|---|---|
number | int or string | — | The badge, and the anchor's number. |
title | string | the domain | |
url | string | — | Only http and https become a link; anything else is shown as text, as in link preview. |
favicon | string | a globe | An http(s) URL, a path on your host, or a data:image. |
snippet | string | — | Shown by detailed, three lines at most. |
variant | compact detailed | compact | |
anchor | string | source | The card's id is {anchor}-{number}. Empty for none. |
bare | bool | false | No border or padding, inside something that draws its own. |
target | string | _blank |
The card a citation links to is outlined while it is the page's target.
Props: citation
| Prop | Type | Default | What it does |
|---|---|---|---|
number | int or string | required | The marker's text. |
title | string | — | Names the marker "Source 1: title", and is the hover card's heading. Without it, no hover card. |
url, favicon, snippet | string | — | The hover card's site, icon and quote. |
href | string | #{anchor}-{number} | Where the marker links. |
anchor | string | source | As the list's. |
preview | bool | true | Show the hover card. Needs Alpine and the script. |
nameText | string | Source :number: :title | The marker's accessible name. |
Accessibility
- The list is an ordered list named by its label; each card is one link, named by its number, title and site, and described by its snippet.
- A citation's accessible name is "Source 1: Refund policy", not "1". Its visible number is part of that name.
- The hover card is the hover card's: it opens after a pause on hover or on keyboard focus, never on a tap, closes on Escape, and holds a link the reader can Tab into.
- A citation is a span and a link, so it sits inside the paragraph it cites from.
Don't
- Don't renumber in the view. Numbering is the host's; the components only show it, so a citation and its card always agree.
- Don't pass a URL you have not looked at as a favicon. Proxy images through your own host where you can: the reader's browser fetches them.
From the package repo: edit this page on GitHub.