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.

Sources

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

PropTypeDefaultWhat it does
sourcesarray[]Rows: title, url, favicon, snippet, number (the row's place, from 1, when left out). Arrays or objects.
layoutrow grid listrowOne line that scrolls sideways and snaps card by card; a grid by the container's width; or a column.
maxint—Show this many; the rest open under "+N more", a native disclosure.
collapsedboolfalseOne line, "5 sources" with up to four icons, that opens to the list.
openboolfalseWith collapsed, open on first paint.
labelstringSourcesNames the list, shown above it. Collapsed, the line's words name it.
anchorstringsourceEach card's id is {anchor}-{number}.
variantcompact detaileddetailed in a list, else compactdetailed shows each snippet.
summaryLabelstring:count source|:count sourcesThe collapsed line.
moreLabelstring+:count moreThe fold's words.
targetstring_blankWhere the links open.

Props: source-card

PropTypeDefaultWhat it does
numberint or string—The badge, and the anchor's number.
titlestringthe domain
urlstring—Only http and https become a link; anything else is shown as text, as in link preview.
faviconstringa globeAn http(s) URL, a path on your host, or a data:image.
snippetstring—Shown by detailed, three lines at most.
variantcompact detailedcompact
anchorstringsourceThe card's id is {anchor}-{number}. Empty for none.
bareboolfalseNo border or padding, inside something that draws its own.
targetstring_blank

The card a citation links to is outlined while it is the page's target.

Props: citation

PropTypeDefaultWhat it does
numberint or stringrequiredThe marker's text.
titlestring—Names the marker "Source 1: title", and is the hover card's heading. Without it, no hover card.
url, favicon, snippetstring—The hover card's site, icon and quote.
hrefstring#{anchor}-{number}Where the marker links.
anchorstringsourceAs the list's.
previewbooltrueShow the hover card. Needs Alpine and the script.
nameTextstringSource :number: :titleThe 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.

Was this page helpful?