@atomic-ui/ui 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/custom-elements.json +460 -28
- package/dist/base/FieldElement.d.ts +4 -0
- package/dist/{chunk-TRZO5CHU.js → chunk-26BO3W56.js} +8 -4
- package/dist/chunk-26BO3W56.js.map +1 -0
- package/dist/{chunk-4ZQTXTPA.js → chunk-2EP3IV3G.js} +8 -4
- package/dist/chunk-2EP3IV3G.js.map +1 -0
- package/dist/{chunk-NU34ZQFR.js → chunk-2ZF3J7OO.js} +8 -5
- package/dist/chunk-2ZF3J7OO.js.map +1 -0
- package/dist/{chunk-WP5WJ4V5.js → chunk-3NEWOO2P.js} +3 -3
- package/dist/chunk-3NEWOO2P.js.map +1 -0
- package/dist/{chunk-AMDTBUUL.js → chunk-3T7J66Z2.js} +16 -4
- package/dist/chunk-3T7J66Z2.js.map +1 -0
- package/dist/{chunk-XU2XODVH.js → chunk-5OJAJA3U.js} +3 -3
- package/dist/chunk-5OJAJA3U.js.map +1 -0
- package/dist/{chunk-3EF4T242.js → chunk-6PMA6NHE.js} +8 -4
- package/dist/chunk-6PMA6NHE.js.map +1 -0
- package/dist/{chunk-HNBG2POR.js → chunk-7C56LPNJ.js} +2 -2
- package/dist/{chunk-HNBG2POR.js.map → chunk-7C56LPNJ.js.map} +1 -1
- package/dist/{chunk-EJSX4WCD.js → chunk-7UWJXPR3.js} +12 -8
- package/dist/chunk-7UWJXPR3.js.map +1 -0
- package/dist/{chunk-WH43U4IY.js → chunk-A4M3A4SZ.js} +4 -4
- package/dist/{chunk-WH43U4IY.js.map → chunk-A4M3A4SZ.js.map} +1 -1
- package/dist/{chunk-I54DOEZB.js → chunk-AG4EP3OY.js} +3 -3
- package/dist/{chunk-I54DOEZB.js.map → chunk-AG4EP3OY.js.map} +1 -1
- package/dist/{chunk-WS4AYRSL.js → chunk-AL4IUSML.js} +7 -4
- package/dist/{chunk-WS4AYRSL.js.map → chunk-AL4IUSML.js.map} +1 -1
- package/dist/{chunk-ZQBEFP2O.js → chunk-APQEXM4I.js} +8 -4
- package/dist/chunk-APQEXM4I.js.map +1 -0
- package/dist/{chunk-YYYQPKQ7.js → chunk-AURT72IC.js} +2 -2
- package/dist/{chunk-KFAGXPIK.js → chunk-AVDSYLOY.js} +3 -3
- package/dist/{chunk-KFAGXPIK.js.map → chunk-AVDSYLOY.js.map} +1 -1
- package/dist/{chunk-GJPHQLLN.js → chunk-AYKYHZGQ.js} +2 -2
- package/dist/{chunk-GJPHQLLN.js.map → chunk-AYKYHZGQ.js.map} +1 -1
- package/dist/{chunk-QBORJTS4.js → chunk-D3JWVMJE.js} +55 -19
- package/dist/chunk-D3JWVMJE.js.map +1 -0
- package/dist/{chunk-RXX4CN5J.js → chunk-EGJZDKMW.js} +2 -2
- package/dist/{chunk-RXX4CN5J.js.map → chunk-EGJZDKMW.js.map} +1 -1
- package/dist/{chunk-UPOTBKKK.js → chunk-FU3CEHBS.js} +2 -2
- package/dist/{chunk-UPOTBKKK.js.map → chunk-FU3CEHBS.js.map} +1 -1
- package/dist/{chunk-FWR6SEIA.js → chunk-HA6OJRVI.js} +17 -6
- package/dist/chunk-HA6OJRVI.js.map +1 -0
- package/dist/{chunk-XZQH2M5I.js → chunk-HURHKQTJ.js} +18 -8
- package/dist/chunk-HURHKQTJ.js.map +1 -0
- package/dist/{chunk-UF6KCRNT.js → chunk-JNLKM3JT.js} +29 -13
- package/dist/chunk-JNLKM3JT.js.map +1 -0
- package/dist/{chunk-2HWO5TFV.js → chunk-KAQJVGYW.js} +14 -9
- package/dist/{chunk-2HWO5TFV.js.map → chunk-KAQJVGYW.js.map} +1 -1
- package/dist/{chunk-BNYILASW.js → chunk-MLKNZL5J.js} +28 -12
- package/dist/chunk-MLKNZL5J.js.map +1 -0
- package/dist/{chunk-PYVUQNFQ.js → chunk-MOO63SHZ.js} +2 -2
- package/dist/{chunk-PYVUQNFQ.js.map → chunk-MOO63SHZ.js.map} +1 -1
- package/dist/{chunk-A7YBFS4H.js → chunk-NKMJMVZP.js} +2 -2
- package/dist/{chunk-5ZQVL3V2.js → chunk-ONED3PUB.js} +8 -7
- package/dist/{chunk-5ZQVL3V2.js.map → chunk-ONED3PUB.js.map} +1 -1
- package/dist/{chunk-MLRTPQQO.js → chunk-OZGKK3N5.js} +11 -6
- package/dist/chunk-OZGKK3N5.js.map +1 -0
- package/dist/{chunk-RZWRAJCD.js → chunk-P6HG5RB2.js} +71 -29
- package/dist/chunk-P6HG5RB2.js.map +1 -0
- package/dist/{chunk-NUUX2SSN.js → chunk-TE3CBEJQ.js} +34 -12
- package/dist/chunk-TE3CBEJQ.js.map +1 -0
- package/dist/{chunk-YR6T73GY.js → chunk-V7EB7Q2M.js} +1 -1
- package/dist/chunk-V7EB7Q2M.js.map +1 -0
- package/dist/{chunk-OE6O3XQB.js → chunk-VYYY5DDZ.js} +3 -3
- package/dist/chunk-VYYY5DDZ.js.map +1 -0
- package/dist/{chunk-DE3INTHZ.js → chunk-YWP2Z3JN.js} +3 -3
- package/dist/{chunk-DE3INTHZ.js.map → chunk-YWP2Z3JN.js.map} +1 -1
- package/dist/{chunk-WS5AUJ35.js → chunk-Z2EWQMTR.js} +7 -4
- package/dist/chunk-Z2EWQMTR.js.map +1 -0
- package/dist/{chunk-INA53XXW.js → chunk-ZL3JFUIE.js} +3 -3
- package/dist/chunk-ZL3JFUIE.js.map +1 -0
- package/dist/components/accordion.js +2 -2
- package/dist/components/alert.js +2 -2
- package/dist/components/app-ui.d.ts +13 -0
- package/dist/components/app-ui.js +4 -4
- package/dist/components/badge.js +3 -3
- package/dist/components/blocks.js +4 -4
- package/dist/components/button.js +3 -3
- package/dist/components/checkbox-group.js +3 -3
- package/dist/components/checkbox.js +3 -3
- package/dist/components/chip.js +2 -2
- package/dist/components/date-input.js +3 -3
- package/dist/components/dialog.js +2 -2
- package/dist/components/fieldset.js +2 -2
- package/dist/components/grid.js +2 -2
- package/dist/components/help.js +2 -2
- package/dist/components/icon.js +2 -2
- package/dist/components/journey.js +3 -3
- package/dist/components/layout.js +2 -2
- package/dist/components/link.js +3 -3
- package/dist/components/list.js +2 -2
- package/dist/components/media.js +2 -2
- package/dist/components/navigation.js +3 -3
- package/dist/components/page.js +2 -2
- package/dist/components/price.js +2 -2
- package/dist/components/progress.d.ts +12 -0
- package/dist/components/progress.js +2 -2
- package/dist/components/radio-group.js +3 -3
- package/dist/components/rows.js +3 -3
- package/dist/components/select.d.ts +11 -0
- package/dist/components/select.js +3 -3
- package/dist/components/shell.js +3 -3
- package/dist/components/summary-list.js +2 -2
- package/dist/components/switch.d.ts +17 -0
- package/dist/components/switch.js +3 -3
- package/dist/components/table.js +3 -3
- package/dist/components/text-input.js +4 -4
- package/dist/components/textarea.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -35
- package/dist/standalone/atomic-ui.js +95 -73
- package/dist/standalone/atomic-ui.js.map +3 -3
- package/dist/standalone/index.html +189 -150
- package/package.json +2 -2
- package/scripts/copy-to-product.mjs +8 -7
- package/specimen/index.html +189 -150
- package/dist/chunk-3EF4T242.js.map +0 -1
- package/dist/chunk-4ZQTXTPA.js.map +0 -1
- package/dist/chunk-AMDTBUUL.js.map +0 -1
- package/dist/chunk-BNYILASW.js.map +0 -1
- package/dist/chunk-EJSX4WCD.js.map +0 -1
- package/dist/chunk-FWR6SEIA.js.map +0 -1
- package/dist/chunk-INA53XXW.js.map +0 -1
- package/dist/chunk-MLRTPQQO.js.map +0 -1
- package/dist/chunk-NU34ZQFR.js.map +0 -1
- package/dist/chunk-NUUX2SSN.js.map +0 -1
- package/dist/chunk-OE6O3XQB.js.map +0 -1
- package/dist/chunk-QBORJTS4.js.map +0 -1
- package/dist/chunk-RZWRAJCD.js.map +0 -1
- package/dist/chunk-TRZO5CHU.js.map +0 -1
- package/dist/chunk-UF6KCRNT.js.map +0 -1
- package/dist/chunk-WP5WJ4V5.js.map +0 -1
- package/dist/chunk-WS5AUJ35.js.map +0 -1
- package/dist/chunk-XU2XODVH.js.map +0 -1
- package/dist/chunk-XZQH2M5I.js.map +0 -1
- package/dist/chunk-YR6T73GY.js.map +0 -1
- package/dist/chunk-ZQBEFP2O.js.map +0 -1
- /package/dist/{chunk-YYYQPKQ7.js.map → chunk-AURT72IC.js.map} +0 -0
- /package/dist/{chunk-A7YBFS4H.js.map → chunk-NKMJMVZP.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-3IGNZTJU.js";
|
|
4
4
|
import {
|
|
5
5
|
iconSvg
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AL4IUSML.js";
|
|
7
7
|
import {
|
|
8
8
|
ImpaktElement,
|
|
9
9
|
focusRing,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
t,
|
|
14
14
|
touchTarget,
|
|
15
15
|
visuallyHidden
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
17
17
|
|
|
18
18
|
// packages/ui/src/components/table.ts
|
|
19
19
|
import { html, css, nothing } from "lit";
|
|
@@ -299,21 +299,26 @@ var ImpaktTable = class extends ImpaktElement {
|
|
|
299
299
|
<thead role="rowgroup">
|
|
300
300
|
<tr role="row">
|
|
301
301
|
${this.selectable ? html`<th scope="col" role="columnheader" class="pick"><label><input type="checkbox" aria-label=${this.selectAllText} .checked=${every} .indeterminate=${some} ?disabled=${!rows.length}
|
|
302
|
-
@change=${(e) => this.choose(
|
|
302
|
+
@change=${(e) => this.choose(
|
|
303
|
+
rows.map((r) => r.key),
|
|
304
|
+
e.target.checked
|
|
305
|
+
)} /></label></th>` : nothing}
|
|
303
306
|
${columns.map((c) => this.heading(c))}
|
|
304
307
|
</tr>
|
|
305
308
|
</thead>
|
|
306
309
|
<tbody role="rowgroup">
|
|
307
|
-
${rows.length ? rows.map(
|
|
310
|
+
${rows.length ? rows.map(
|
|
311
|
+
({ row, key }, i) => html`
|
|
308
312
|
<tr role="row" class=${chosen.has(key) ? "chosen" : ""} part="row">
|
|
309
313
|
${this.selectable ? html`<td role="cell" class="pick"><label><input type="checkbox" aria-label=${this.selectRowText.replace("{row}", String(row[columns[0]?.key ?? ""] ?? key))} .checked=${chosen.has(key)}
|
|
310
314
|
@change=${(e) => this.choose([key], e.target.checked)} /></label></td>` : nothing}
|
|
311
315
|
${columns.map((c, j) => {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
316
|
+
const value = html`<span class="label" aria-hidden="true">${c.label}</span><span class="value"><slot name=${`cell:${key}:${c.key}`}>${row[c.key] ?? ""}</slot></span>`;
|
|
317
|
+
return j === 0 ? html`<th scope="row" role="rowheader" id=${`${this.uid}-r${i}`}>${value}</th>` : html`<td role="cell" class=${c.numeric ? "numeric" : ""}>${value}</td>`;
|
|
318
|
+
})}
|
|
315
319
|
</tr>
|
|
316
|
-
`
|
|
320
|
+
`
|
|
321
|
+
) : html`<tr role="row"><td role="cell" class="empty" colspan=${columns.length + (this.selectable ? 1 : 0) || 1}><slot name="empty">${this.emptyText}</slot></td></tr>`}
|
|
317
322
|
</tbody>
|
|
318
323
|
</table>
|
|
319
324
|
</div>
|
|
@@ -325,4 +330,4 @@ customElements.define("impakt-table", ImpaktTable);
|
|
|
325
330
|
export {
|
|
326
331
|
ImpaktTable
|
|
327
332
|
};
|
|
328
|
-
//# sourceMappingURL=chunk-
|
|
333
|
+
//# sourceMappingURL=chunk-KAQJVGYW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/table.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { pageLocale } from '../base/locale';\nimport { focusRing, touchTarget, visuallyHidden } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\nimport { iconSvg } from './icon';\n\nexport interface TableColumn {\n key: string;\n label: string;\n numeric?: boolean;\n /** Let the rows be sorted by this column. Its heading becomes a button. */\n sortable?: boolean;\n}\n\n/** Which way a sorted column runs, in the words `aria-sort` uses. */\nexport type SortDirection = 'ascending' | 'descending';\n\n/**\n * A data table — a plan comparison, a payment schedule, a list of cases.\n *\n * **The caption is required.** It is the table's name, and a page with three\n * unnamed tables is a page a screen-reader user has to read in full to tell\n * apart. Visually it can be the heading they would have written anyway.\n *\n * **It scrolls, and the scroller is focusable.** A wide table cannot reflow to\n * 320px without becoming unreadable, so it scrolls horizontally — and a region\n * that scrolls must be reachable by keyboard, or a keyboard user simply cannot\n * see the right-hand columns. `tabindex=\"0\"` with a role and a name is the\n * established fix, and the name is why the role is there: a bare focusable div\n * announces nothing.\n *\n * **Or it stacks.** With `stack`, a narrow table turns each row into a card,\n * with each value under the name of its column, so a phone reads a list of\n * cases rather than scrolling a grid. The table keeps its roles written out,\n * because some browsers drop a table's meaning once it is no longer drawn as one.\n *\n * **Sorting is announced.** A sortable column's heading is a button, and the\n * column the rows are sorted by carries `aria-sort`, so a screen reader says\n * \"Opened, sorted descending\" rather than leaving the order to be guessed. The\n * table sorts its own rows unless `manual-sort` says the app does it, as an app\n * that pages its rows on the server must.\n *\n * **Rows can be chosen.** With `selectable`, each row has a checkbox named by\n * the row's first cell, and the heading has one for every row. A row is known by\n * its `id`, or by the key `row-key` names.\n *\n * A cell can hold more than words: give the table a child with\n * `slot=\"cell:{row id}:{column key}\"`, such as a badge, and it is drawn in that\n * cell. With no rows the table says `empty-text`, or shows a child with\n * `slot=\"empty\"`.\n *\n * @category content\n * @icon table\n * @slot empty - What to show when there are no rows, in place of the empty text.\n * @fires {CustomEvent<{ key: string; direction: SortDirection }>} impakt-sort - When a column heading is pressed to sort the rows.\n * @fires {CustomEvent<{ selected: string[] }>} impakt-selection - When rows are chosen or let go. The ids are in detail.selected.\n */\nexport class ImpaktTable extends ImpaktElement {\n static properties = {\n caption: { type: String },\n columns: { type: Array },\n rows: { type: Array },\n sortKey: { type: String, attribute: 'sort-key', reflect: true },\n sortDirection: { type: String, attribute: 'sort-direction', reflect: true },\n manualSort: { type: Boolean, attribute: 'manual-sort' },\n selectable: { type: Boolean, reflect: true },\n selected: { type: Array },\n rowKey: { type: String, attribute: 'row-key' },\n stack: { type: Boolean, reflect: true },\n emptyText: { type: String, attribute: 'empty-text' },\n selectAllText: { type: String, attribute: 'select-all-text' },\n selectRowText: { type: String, attribute: 'select-row-text' },\n };\n\n declare caption: string;\n declare columns: TableColumn[];\n declare rows: Array<Record<string, string>>;\n /** The key of the column the rows are sorted by. Empty leaves them in the order given. */\n declare sortKey: string;\n declare sortDirection: SortDirection;\n /** The app sorts the rows itself, on `impakt-sort`. The table only shows which column and which way. */\n declare manualSort: boolean;\n /** Each row has a checkbox, and the heading one for every row. */\n declare selectable: boolean;\n /** The ids of the chosen rows. */\n declare selected: string[];\n /** The key in each row that tells rows apart. */\n declare rowKey: string;\n /** On a narrow screen, draw each row as a card rather than scroll the table sideways. */\n declare stack: boolean;\n /** What the table says when it has no rows. */\n declare emptyText: string;\n /** The name of the checkbox that chooses every row. */\n declare selectAllText: string;\n /** The name of each row's checkbox, with `{row}` for the row's first cell. */\n declare selectRowText: string;\n\n constructor() {\n super();\n this.caption = '';\n this.columns = [];\n this.rows = [];\n this.sortKey = '';\n this.sortDirection = 'ascending';\n this.manualSort = false;\n this.selectable = false;\n this.selected = [];\n this.rowKey = 'id';\n this.stack = false;\n this.emptyText = 'Nothing to show';\n this.selectAllText = 'Select all rows';\n this.selectRowText = 'Select {row}';\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n touchTarget('.sort, .pick label'),\n css`\n :host {\n display: block;\n }\n :host([stack]) {\n container-type: inline-size;\n }\n .scroller {\n overflow-x: auto;\n }\n table {\n inline-size: 100%;\n border-collapse: collapse;\n font-size: ${fontSize('md')};\n }\n caption {\n text-align: start;\n font-weight: ${fontWeight('semibold')};\n padding-block-end: ${space(2)};\n }\n th,\n td {\n text-align: start;\n padding: ${space(3)};\n border-block-end: ${t.borderThin} solid ${t.rule};\n }\n thead th {\n font-weight: ${fontWeight('semibold')};\n background: ${t.surfaceInset};\n }\n tbody th {\n font-weight: ${fontWeight('semibold')};\n }\n .numeric {\n /* A figure read across a line break is a different figure. */\n white-space: nowrap;\n text-align: end;\n font-variant-numeric: tabular-nums;\n }\n th.sortable {\n padding: ${space(1)};\n }\n .sort {\n display: inline-flex;\n align-items: center;\n gap: ${space(1)};\n min-block-size: ${t.targetMin};\n padding: ${space(2)};\n font: inherit;\n color: inherit;\n background: none;\n border: 0;\n border-radius: ${t.radius};\n cursor: pointer;\n }\n .sort:hover {\n background: ${t.wash};\n }\n .numeric .sort {\n flex-direction: row-reverse;\n }\n .arrow {\n display: inline-flex;\n color: ${t.textMuted};\n transition: transform 140ms ease-in-out;\n }\n [aria-sort] .arrow {\n color: inherit;\n }\n [aria-sort='ascending'] .arrow {\n transform: rotate(180deg);\n }\n :not([aria-sort]) > .sort .arrow {\n opacity: 0.45;\n }\n .pick {\n inline-size: 1%;\n padding-block: 0;\n padding-inline-end: 0;\n }\n .pick label {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-block-size: ${t.targetMin};\n min-inline-size: ${t.targetMin};\n cursor: pointer;\n }\n .pick input {\n inline-size: 20px;\n block-size: 20px;\n margin: 0;\n accent-color: ${t.brand};\n cursor: pointer;\n }\n tr.chosen > * {\n background: ${t.brandSubtle};\n }\n .empty {\n padding-block: ${space(6)};\n text-align: center;\n color: ${t.textMuted};\n }\n .label {\n display: none;\n }\n .visually-hidden {\n ${visuallyHidden}\n }\n /* Stacked: each row a card, each value under its column's name. */\n @container (max-width: 36rem) {\n table, tbody, tr, tbody th, tbody td {\n display: block;\n }\n thead tr {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: ${space(1)};\n margin-block-end: ${space(3)};\n }\n thead th {\n display: none;\n padding: 0;\n border: 0;\n background: none;\n }\n thead th.sortable, thead th.pick {\n display: block;\n inline-size: auto;\n }\n thead .sort {\n border: ${t.borderThin} solid ${t.rule};\n border-radius: 999px;\n padding-inline: ${space(3)};\n background: ${t.surfaceCard};\n }\n tbody tr {\n position: relative;\n margin-block-end: ${space(3)};\n padding: ${space(3)} ${space(4)};\n border: ${t.borderThin} solid ${t.rule};\n border-radius: ${t.radiusXl};\n background: ${t.surfaceCard};\n }\n tbody tr.chosen {\n background: ${t.brandSubtle};\n }\n tr.chosen > * {\n background: none;\n }\n tbody th, tbody td {\n display: grid;\n grid-template-columns: minmax(6rem, 38%) minmax(0, 1fr);\n gap: ${space(3)};\n padding: ${space(1.5)} 0;\n border: 0;\n text-align: start;\n white-space: normal;\n }\n tbody td.numeric {\n text-align: start;\n }\n tbody .pick {\n display: block;\n position: absolute;\n inset-block-start: ${space(1)};\n inset-inline-end: ${space(1)};\n inline-size: auto;\n padding: 0;\n }\n tbody tr:has(.pick) > th {\n padding-inline-end: ${space(10)};\n }\n .label {\n display: block;\n font-size: ${fontSize('sm')};\n font-weight: ${fontWeight('semibold')};\n color: ${t.textMuted};\n }\n .empty {\n display: block;\n border: 0;\n }\n }\n `,\n ];\n\n private keyOf(row: Record<string, string>, index: number): string {\n const key = row?.[this.rowKey];\n return key === undefined || key === null || key === '' ? String(index) : String(key);\n }\n\n /** The rows in the order they are drawn: as given, or sorted by the chosen column. */\n private ordered(): Array<{ row: Record<string, string>; key: string }> {\n const rows = (this.rows ?? []).map((row, i) => ({ row, key: this.keyOf(row, i) }));\n const column = (this.columns ?? []).find((c) => c.key === this.sortKey && c.sortable);\n if (!column || this.manualSort) return rows;\n const way = this.sortDirection === 'descending' ? -1 : 1;\n const locale = pageLocale(this);\n const figure = (v: unknown) => Number(String(v ?? '').replace(/[^\\d.-]/g, '')) || 0;\n return rows.sort((a, b) => {\n const x = a.row[column.key] ?? '';\n const y = b.row[column.key] ?? '';\n const order = column.numeric ? figure(x) - figure(y) : String(x).localeCompare(String(y), locale, { numeric: true, sensitivity: 'base' });\n return order * way;\n });\n }\n\n private sortBy(key: string): void {\n const direction: SortDirection = this.sortKey === key && this.sortDirection === 'ascending' ? 'descending' : 'ascending';\n this.sortKey = key;\n this.sortDirection = direction;\n this.dispatchEvent(new CustomEvent('impakt-sort', { detail: { key, direction }, bubbles: true, composed: true }));\n }\n\n private choose(keys: string[], on: boolean): void {\n const now = new Set(this.selected ?? []);\n for (const key of keys) {\n if (on) now.add(key);\n else now.delete(key);\n }\n this.selected = [...now];\n this.dispatchEvent(new CustomEvent('impakt-selection', { detail: { selected: this.selected }, bubbles: true, composed: true }));\n }\n\n private heading(c: TableColumn): TemplateResult {\n const sorted = c.sortable && c.key === this.sortKey;\n const classes = [c.numeric ? 'numeric' : '', c.sortable ? 'sortable' : ''].filter(Boolean).join(' ');\n if (!c.sortable) return html`<th scope=\"col\" role=\"columnheader\" class=${classes}>${c.label}</th>`;\n return html`<th scope=\"col\" role=\"columnheader\" class=${classes} aria-sort=${sorted ? this.sortDirection : nothing}>\n <button class=\"sort\" type=\"button\" part=\"sort\" @click=${() => this.sortBy(c.key)}>${c.label}<span class=\"arrow\" aria-hidden=\"true\">${iconSvg('chevron-down', '16px')}</span></button>\n </th>`;\n }\n\n render(): TemplateResult {\n const columns = this.columns ?? [];\n const rows = this.ordered();\n const chosen = new Set(this.selected ?? []);\n const every = rows.length > 0 && rows.every((r) => chosen.has(r.key));\n const some = !every && rows.some((r) => chosen.has(r.key));\n return html`\n <div class=\"scroller\" part=\"scroller\" tabindex=\"0\" role=\"region\" aria-label=${this.caption || nothing}>\n <table part=\"table\" role=\"table\">\n ${this.caption ? html`<caption part=\"caption\">${this.caption}</caption>` : nothing}\n <thead role=\"rowgroup\">\n <tr role=\"row\">\n ${this.selectable\n ? html`<th scope=\"col\" role=\"columnheader\" class=\"pick\"><label><input type=\"checkbox\" aria-label=${this.selectAllText} .checked=${every} .indeterminate=${some} ?disabled=${!rows.length}\n @change=${(e: Event) => this.choose(rows.map((r) => r.key), (e.target as HTMLInputElement).checked)} /></label></th>`\n : nothing}\n ${columns.map((c) => this.heading(c))}\n </tr>\n </thead>\n <tbody role=\"rowgroup\">\n ${rows.length\n ? rows.map(({ row, key }, i) => html`\n <tr role=\"row\" class=${chosen.has(key) ? 'chosen' : ''} part=\"row\">\n ${this.selectable\n ? html`<td role=\"cell\" class=\"pick\"><label><input type=\"checkbox\" aria-label=${this.selectRowText.replace('{row}', String(row[columns[0]?.key ?? ''] ?? key))} .checked=${chosen.has(key)}\n @change=${(e: Event) => this.choose([key], (e.target as HTMLInputElement).checked)} /></label></td>`\n : nothing}\n ${columns.map((c, j) => {\n const value = html`<span class=\"label\" aria-hidden=\"true\">${c.label}</span><span class=\"value\"><slot name=${`cell:${key}:${c.key}`}>${row[c.key] ?? ''}</slot></span>`;\n // The first cell of each row is a row header, so a screen\n // reader announces \"Delivery charge, £250\" rather than\n // reading a bare number with no idea what it belongs to.\n return j === 0\n ? html`<th scope=\"row\" role=\"rowheader\" id=${`${this.uid}-r${i}`}>${value}</th>`\n : html`<td role=\"cell\" class=${c.numeric ? 'numeric' : ''}>${value}</td>`;\n })}\n </tr>\n `)\n : html`<tr role=\"row\"><td role=\"cell\" class=\"empty\" colspan=${columns.length + (this.selectable ? 1 : 0) || 1}><slot name=\"empty\">${this.emptyText}</slot></td></tr>`}\n </tbody>\n </table>\n </div>\n `;\n }\n}\n\ncustomElements.define('impakt-table', ImpaktTable);\n\ndeclare global {\n interface HTMLElementTagNameMap { 'impakt-table': ImpaktTable }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,MAAM,KAAK,eAAoC;AA0DjD,IAAM,cAAN,cAA0B,cAAc;AAAA,EAC7C;AAAA,SAAO,aAAa;AAAA,MAClB,SAAS,EAAE,MAAM,OAAO;AAAA,MACxB,SAAS,EAAE,MAAM,MAAM;AAAA,MACvB,MAAM,EAAE,MAAM,MAAM;AAAA,MACpB,SAAS,EAAE,MAAM,QAAQ,WAAW,YAAY,SAAS,KAAK;AAAA,MAC9D,eAAe,EAAE,MAAM,QAAQ,WAAW,kBAAkB,SAAS,KA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,GAAG,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,GAAG,KAAK,EAAE;AAItJ,aAAO,MAAM,IACT,2CAA2C,GAAG,KAAK,GAAG,KAAK,CAAC,EAAE,IAAI,KAAK,UACvE,6BAA6B,EAAE,UAAU,YAAY,EAAE,IAAI,KAAK;AAAA,IACtE,CAAC,CAAC;AAAA;AAAA,eAEL,IACC,4DAA4D,QAAQ,UAAU,KAAK,aAAa,IAAI,MAAM,CAAC,uBAAuB,KAAK,SAAS,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjL;AACF;AAEA,eAAe,OAAO,gBAAgB,WAAW;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/components/table.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { pageLocale } from '../base/locale';\nimport { focusRing, touchTarget, visuallyHidden } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\nimport { iconSvg } from './icon';\n\nexport interface TableColumn {\n key: string;\n label: string;\n numeric?: boolean;\n /** Let the rows be sorted by this column. Its heading becomes a button. */\n sortable?: boolean;\n}\n\n/** Which way a sorted column runs, in the words `aria-sort` uses. */\nexport type SortDirection = 'ascending' | 'descending';\n\n/**\n * A data table — a plan comparison, a payment schedule, a list of cases.\n *\n * **The caption is required.** It is the table's name, and a page with three\n * unnamed tables is a page a screen-reader user has to read in full to tell\n * apart. Visually it can be the heading they would have written anyway.\n *\n * **It scrolls, and the scroller is focusable.** A wide table cannot reflow to\n * 320px without becoming unreadable, so it scrolls horizontally — and a region\n * that scrolls must be reachable by keyboard, or a keyboard user simply cannot\n * see the right-hand columns. `tabindex=\"0\"` with a role and a name is the\n * established fix, and the name is why the role is there: a bare focusable div\n * announces nothing.\n *\n * **Or it stacks.** With `stack`, a narrow table turns each row into a card,\n * with each value under the name of its column, so a phone reads a list of\n * cases rather than scrolling a grid. The table keeps its roles written out,\n * because some browsers drop a table's meaning once it is no longer drawn as one.\n *\n * **Sorting is announced.** A sortable column's heading is a button, and the\n * column the rows are sorted by carries `aria-sort`, so a screen reader says\n * \"Opened, sorted descending\" rather than leaving the order to be guessed. The\n * table sorts its own rows unless `manual-sort` says the app does it, as an app\n * that pages its rows on the server must.\n *\n * **Rows can be chosen.** With `selectable`, each row has a checkbox named by\n * the row's first cell, and the heading has one for every row. A row is known by\n * its `id`, or by the key `row-key` names.\n *\n * A cell can hold more than words: give the table a child with\n * `slot=\"cell:{row id}:{column key}\"`, such as a badge, and it is drawn in that\n * cell. With no rows the table says `empty-text`, or shows a child with\n * `slot=\"empty\"`.\n *\n * @category content\n * @icon table\n * @slot empty - What to show when there are no rows, in place of the empty text.\n * @fires {CustomEvent<{ key: string; direction: SortDirection }>} impakt-sort - When a column heading is pressed to sort the rows.\n * @fires {CustomEvent<{ selected: string[] }>} impakt-selection - When rows are chosen or let go. The ids are in detail.selected.\n */\nexport class ImpaktTable extends ImpaktElement {\n static properties = {\n caption: { type: String },\n columns: { type: Array },\n rows: { type: Array },\n sortKey: { type: String, attribute: 'sort-key', reflect: true },\n sortDirection: { type: String, attribute: 'sort-direction', reflect: true },\n manualSort: { type: Boolean, attribute: 'manual-sort' },\n selectable: { type: Boolean, reflect: true },\n selected: { type: Array },\n rowKey: { type: String, attribute: 'row-key' },\n stack: { type: Boolean, reflect: true },\n emptyText: { type: String, attribute: 'empty-text' },\n selectAllText: { type: String, attribute: 'select-all-text' },\n selectRowText: { type: String, attribute: 'select-row-text' },\n };\n\n declare caption: string;\n declare columns: TableColumn[];\n declare rows: Array<Record<string, string>>;\n /** The key of the column the rows are sorted by. Empty leaves them in the order given. */\n declare sortKey: string;\n declare sortDirection: SortDirection;\n /** The app sorts the rows itself, on `impakt-sort`. The table only shows which column and which way. */\n declare manualSort: boolean;\n /** Each row has a checkbox, and the heading one for every row. */\n declare selectable: boolean;\n /** The ids of the chosen rows. */\n declare selected: string[];\n /** The key in each row that tells rows apart. */\n declare rowKey: string;\n /** On a narrow screen, draw each row as a card rather than scroll the table sideways. */\n declare stack: boolean;\n /** What the table says when it has no rows. */\n declare emptyText: string;\n /** The name of the checkbox that chooses every row. */\n declare selectAllText: string;\n /** The name of each row's checkbox, with `{row}` for the row's first cell. */\n declare selectRowText: string;\n\n constructor() {\n super();\n this.caption = '';\n this.columns = [];\n this.rows = [];\n this.sortKey = '';\n this.sortDirection = 'ascending';\n this.manualSort = false;\n this.selectable = false;\n this.selected = [];\n this.rowKey = 'id';\n this.stack = false;\n this.emptyText = 'Nothing to show';\n this.selectAllText = 'Select all rows';\n this.selectRowText = 'Select {row}';\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n touchTarget('.sort, .pick label'),\n css`\n :host {\n display: block;\n }\n :host([stack]) {\n container-type: inline-size;\n }\n .scroller {\n overflow-x: auto;\n }\n table {\n inline-size: 100%;\n border-collapse: collapse;\n font-size: ${fontSize('md')};\n }\n caption {\n text-align: start;\n font-weight: ${fontWeight('semibold')};\n padding-block-end: ${space(2)};\n }\n th,\n td {\n text-align: start;\n padding: ${space(3)};\n border-block-end: ${t.borderThin} solid ${t.rule};\n }\n thead th {\n font-weight: ${fontWeight('semibold')};\n background: ${t.surfaceInset};\n }\n tbody th {\n font-weight: ${fontWeight('semibold')};\n }\n .numeric {\n /* A figure read across a line break is a different figure. */\n white-space: nowrap;\n text-align: end;\n font-variant-numeric: tabular-nums;\n }\n th.sortable {\n padding: ${space(1)};\n }\n .sort {\n display: inline-flex;\n align-items: center;\n gap: ${space(1)};\n min-block-size: ${t.targetMin};\n padding: ${space(2)};\n font: inherit;\n color: inherit;\n background: none;\n border: 0;\n border-radius: ${t.radius};\n cursor: pointer;\n }\n .sort:hover {\n background: ${t.wash};\n }\n .numeric .sort {\n flex-direction: row-reverse;\n }\n .arrow {\n display: inline-flex;\n color: ${t.textMuted};\n transition: transform 140ms ease-in-out;\n }\n [aria-sort] .arrow {\n color: inherit;\n }\n [aria-sort='ascending'] .arrow {\n transform: rotate(180deg);\n }\n :not([aria-sort]) > .sort .arrow {\n opacity: 0.45;\n }\n .pick {\n inline-size: 1%;\n padding-block: 0;\n padding-inline-end: 0;\n }\n .pick label {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-block-size: ${t.targetMin};\n min-inline-size: ${t.targetMin};\n cursor: pointer;\n }\n .pick input {\n inline-size: 20px;\n block-size: 20px;\n margin: 0;\n accent-color: ${t.brand};\n cursor: pointer;\n }\n tr.chosen > * {\n background: ${t.brandSubtle};\n }\n .empty {\n padding-block: ${space(6)};\n text-align: center;\n color: ${t.textMuted};\n }\n .label {\n display: none;\n }\n .visually-hidden {\n ${visuallyHidden}\n }\n /* Stacked: each row a card, each value under its column's name. */\n @container (max-width: 36rem) {\n table, tbody, tr, tbody th, tbody td {\n display: block;\n }\n thead tr {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: ${space(1)};\n margin-block-end: ${space(3)};\n }\n thead th {\n display: none;\n padding: 0;\n border: 0;\n background: none;\n }\n thead th.sortable, thead th.pick {\n display: block;\n inline-size: auto;\n }\n thead .sort {\n border: ${t.borderThin} solid ${t.rule};\n border-radius: 999px;\n padding-inline: ${space(3)};\n background: ${t.surfaceCard};\n }\n tbody tr {\n position: relative;\n margin-block-end: ${space(3)};\n padding: ${space(3)} ${space(4)};\n border: ${t.borderThin} solid ${t.rule};\n border-radius: ${t.radiusXl};\n background: ${t.surfaceCard};\n }\n tbody tr.chosen {\n background: ${t.brandSubtle};\n }\n tr.chosen > * {\n background: none;\n }\n tbody th, tbody td {\n display: grid;\n grid-template-columns: minmax(6rem, 38%) minmax(0, 1fr);\n gap: ${space(3)};\n padding: ${space(1.5)} 0;\n border: 0;\n text-align: start;\n white-space: normal;\n }\n tbody td.numeric {\n text-align: start;\n }\n tbody .pick {\n display: block;\n position: absolute;\n inset-block-start: ${space(1)};\n inset-inline-end: ${space(1)};\n inline-size: auto;\n padding: 0;\n }\n tbody tr:has(.pick) > th {\n padding-inline-end: ${space(10)};\n }\n .label {\n display: block;\n font-size: ${fontSize('sm')};\n font-weight: ${fontWeight('semibold')};\n color: ${t.textMuted};\n }\n .empty {\n display: block;\n border: 0;\n }\n }\n `,\n ];\n\n private keyOf(row: Record<string, string>, index: number): string {\n const key = row?.[this.rowKey];\n return key === undefined || key === null || key === '' ? String(index) : String(key);\n }\n\n /** The rows in the order they are drawn: as given, or sorted by the chosen column. */\n private ordered(): Array<{ row: Record<string, string>; key: string }> {\n const rows = (this.rows ?? []).map((row, i) => ({ row, key: this.keyOf(row, i) }));\n const column = (this.columns ?? []).find((c) => c.key === this.sortKey && c.sortable);\n if (!column || this.manualSort) return rows;\n const way = this.sortDirection === 'descending' ? -1 : 1;\n const locale = pageLocale(this);\n const figure = (v: unknown) => Number(String(v ?? '').replace(/[^\\d.-]/g, '')) || 0;\n return rows.sort((a, b) => {\n const x = a.row[column.key] ?? '';\n const y = b.row[column.key] ?? '';\n const order = column.numeric ? figure(x) - figure(y) : String(x).localeCompare(String(y), locale, { numeric: true, sensitivity: 'base' });\n return order * way;\n });\n }\n\n private sortBy(key: string): void {\n const direction: SortDirection = this.sortKey === key && this.sortDirection === 'ascending' ? 'descending' : 'ascending';\n this.sortKey = key;\n this.sortDirection = direction;\n this.dispatchEvent(new CustomEvent('impakt-sort', { detail: { key, direction }, bubbles: true, composed: true }));\n }\n\n private choose(keys: string[], on: boolean): void {\n const now = new Set(this.selected ?? []);\n for (const key of keys) {\n if (on) now.add(key);\n else now.delete(key);\n }\n this.selected = [...now];\n this.dispatchEvent(new CustomEvent('impakt-selection', { detail: { selected: this.selected }, bubbles: true, composed: true }));\n }\n\n private heading(c: TableColumn): TemplateResult {\n const sorted = c.sortable && c.key === this.sortKey;\n const classes = [c.numeric ? 'numeric' : '', c.sortable ? 'sortable' : ''].filter(Boolean).join(' ');\n if (!c.sortable) return html`<th scope=\"col\" role=\"columnheader\" class=${classes}>${c.label}</th>`;\n return html`<th scope=\"col\" role=\"columnheader\" class=${classes} aria-sort=${sorted ? this.sortDirection : nothing}>\n <button class=\"sort\" type=\"button\" part=\"sort\" @click=${() => this.sortBy(c.key)}>${c.label}<span class=\"arrow\" aria-hidden=\"true\">${iconSvg('chevron-down', '16px')}</span></button>\n </th>`;\n }\n\n render(): TemplateResult {\n const columns = this.columns ?? [];\n const rows = this.ordered();\n const chosen = new Set(this.selected ?? []);\n const every = rows.length > 0 && rows.every((r) => chosen.has(r.key));\n const some = !every && rows.some((r) => chosen.has(r.key));\n return html`\n <div class=\"scroller\" part=\"scroller\" tabindex=\"0\" role=\"region\" aria-label=${this.caption || nothing}>\n <table part=\"table\" role=\"table\">\n ${this.caption ? html`<caption part=\"caption\">${this.caption}</caption>` : nothing}\n <thead role=\"rowgroup\">\n <tr role=\"row\">\n ${\n this.selectable\n ? html`<th scope=\"col\" role=\"columnheader\" class=\"pick\"><label><input type=\"checkbox\" aria-label=${this.selectAllText} .checked=${every} .indeterminate=${some} ?disabled=${!rows.length}\n @change=${(e: Event) =>\n this.choose(\n rows.map((r) => r.key),\n (e.target as HTMLInputElement).checked,\n )} /></label></th>`\n : nothing\n }\n ${columns.map((c) => this.heading(c))}\n </tr>\n </thead>\n <tbody role=\"rowgroup\">\n ${\n rows.length\n ? rows.map(\n ({ row, key }, i) => html`\n <tr role=\"row\" class=${chosen.has(key) ? 'chosen' : ''} part=\"row\">\n ${\n this.selectable\n ? html`<td role=\"cell\" class=\"pick\"><label><input type=\"checkbox\" aria-label=${this.selectRowText.replace('{row}', String(row[columns[0]?.key ?? ''] ?? key))} .checked=${chosen.has(key)}\n @change=${(e: Event) => this.choose([key], (e.target as HTMLInputElement).checked)} /></label></td>`\n : nothing\n }\n ${columns.map((c, j) => {\n const value = html`<span class=\"label\" aria-hidden=\"true\">${c.label}</span><span class=\"value\"><slot name=${`cell:${key}:${c.key}`}>${row[c.key] ?? ''}</slot></span>`;\n // The first cell of each row is a row header, so a screen\n // reader announces \"Delivery charge, £250\" rather than\n // reading a bare number with no idea what it belongs to.\n return j === 0\n ? html`<th scope=\"row\" role=\"rowheader\" id=${`${this.uid}-r${i}`}>${value}</th>`\n : html`<td role=\"cell\" class=${c.numeric ? 'numeric' : ''}>${value}</td>`;\n })}\n </tr>\n `,\n )\n : html`<tr role=\"row\"><td role=\"cell\" class=\"empty\" colspan=${columns.length + (this.selectable ? 1 : 0) || 1}><slot name=\"empty\">${this.emptyText}</slot></td></tr>`\n }\n </tbody>\n </table>\n </div>\n `;\n }\n}\n\ncustomElements.define('impakt-table', ImpaktTable);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impakt-table': ImpaktTable;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,MAAM,KAAK,eAAoC;AA0DjD,IAAM,cAAN,cAA0B,cAAc;AAAA,EAC7C;AAAA,SAAO,aAAa;AAAA,MAClB,SAAS,EAAE,MAAM,OAAO;AAAA,MACxB,SAAS,EAAE,MAAM,MAAM;AAAA,MACvB,MAAM,EAAE,MAAM,MAAM;AAAA,MACpB,SAAS,EAAE,MAAM,QAAQ,WAAW,YAAY,SAAS,KAAK;AAAA,MAC9D,eAAe,EAAE,MAAM,QAAQ,WAAW,kBAAkB,SAAS,KAAK;AAAA,MAC1E,YAAY,EAAE,MAAM,SAAS,WAAW,cAAc;AAAA,MACtD,YAAY,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,MAC3C,UAAU,EAAE,MAAM,MAAM;AAAA,MACxB,QAAQ,EAAE,MAAM,QAAQ,WAAW,UAAU;AAAA,MAC7C,OAAO,EAAE,MAAM,SAAS,SAAS,KAAK;AAAA,MACtC,WAAW,EAAE,MAAM,QAAQ,WAAW,aAAa;AAAA,MACnD,eAAe,EAAE,MAAM,QAAQ,WAAW,kBAAkB;AAAA,MAC5D,eAAe,EAAE,MAAM,QAAQ,WAAW,kBAAkB;AAAA,IAC9D;AAAA;AAAA,EAyBA,cAAc;AACZ,UAAM;AACN,SAAK,UAAU;AACf,SAAK,UAAU,CAAC;AAChB,SAAK,OAAO,CAA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
} from "./chunk-
|
|
3
|
+
} from "./chunk-JNLKM3JT.js";
|
|
4
4
|
import {
|
|
5
5
|
ImpaktElement,
|
|
6
6
|
focusRing,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
targetSize,
|
|
12
12
|
touchTarget,
|
|
13
13
|
visuallyHidden
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
15
15
|
|
|
16
16
|
// packages/ui/src/components/blocks.ts
|
|
17
17
|
import { css, html, nothing } from "lit";
|
|
@@ -28,14 +28,17 @@ var ImpaktDivider = class extends ImpaktElement {
|
|
|
28
28
|
this.tone = "subtle";
|
|
29
29
|
}
|
|
30
30
|
static {
|
|
31
|
-
this.styles = [
|
|
31
|
+
this.styles = [
|
|
32
|
+
...ImpaktElement.styles,
|
|
33
|
+
css`
|
|
32
34
|
:host { display: block; }
|
|
33
35
|
hr { margin: ${space(4)} 0; border: 0; border-block-start: ${t.borderThin} solid ${t.border}; opacity: 0.5; }
|
|
34
36
|
:host([tone='strong']) hr { opacity: 1; border-block-start-width: ${t.borderThick}; }
|
|
35
37
|
:host([spacing='sm']) hr { margin-block: ${space(2)}; }
|
|
36
38
|
:host([spacing='lg']) hr { margin-block: ${space(8)}; }
|
|
37
39
|
:host([spacing='xl']) hr { margin-block: ${space(12)}; }
|
|
38
|
-
`
|
|
40
|
+
`
|
|
41
|
+
];
|
|
39
42
|
}
|
|
40
43
|
render() {
|
|
41
44
|
return html`<hr aria-hidden="true" part="line" />`;
|
|
@@ -50,13 +53,16 @@ var ImpaktSpacer = class extends ImpaktElement {
|
|
|
50
53
|
this.size = "md";
|
|
51
54
|
}
|
|
52
55
|
static {
|
|
53
|
-
this.styles = [
|
|
56
|
+
this.styles = [
|
|
57
|
+
...ImpaktElement.styles,
|
|
58
|
+
css`
|
|
54
59
|
:host { display: block; block-size: ${space(4)}; }
|
|
55
60
|
:host([size='sm']) { block-size: ${space(2)}; }
|
|
56
61
|
:host([size='lg']) { block-size: ${space(8)}; }
|
|
57
62
|
:host([size='xl']) { block-size: ${space(12)}; }
|
|
58
63
|
:host([size='2xl']) { block-size: ${space(16)}; }
|
|
59
|
-
`
|
|
64
|
+
`
|
|
65
|
+
];
|
|
60
66
|
}
|
|
61
67
|
render() {
|
|
62
68
|
return html``;
|
|
@@ -89,10 +95,19 @@ var ImpaktTabs = class extends ImpaktElement {
|
|
|
89
95
|
this.look = "line";
|
|
90
96
|
}
|
|
91
97
|
static {
|
|
92
|
-
this.styles = [
|
|
93
|
-
|
|
98
|
+
this.styles = [
|
|
99
|
+
...ImpaktElement.styles,
|
|
100
|
+
focusRing,
|
|
101
|
+
touchTarget("[role='tab']"),
|
|
102
|
+
css`
|
|
103
|
+
/* Only the two-row layout needs a size container. Making every tab set one
|
|
104
|
+
would take its width from its parent alone, so in a flex row, with no
|
|
105
|
+
width given, it would shrink to nothing. In a row it may still shrink
|
|
106
|
+
below its tabs, which then scroll, rather than widen the page. */
|
|
107
|
+
:host { display: block; min-inline-size: 0; }
|
|
108
|
+
:host([two-rows]) { container-type: inline-size; }
|
|
94
109
|
[role='tablist'] { display: flex; gap: ${space(1)}; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; border-block-end: ${t.borderThin} solid ${t.border}; }
|
|
95
|
-
[role='tab'] { ${targetSize} flex: none; padding: ${space(3)} ${space(4)}; font: inherit; font-weight: ${fontWeight("semibold")}; white-space: nowrap; color: ${t.textMuted}; background: transparent; border: 0; border-block-end: 3px solid transparent; margin-block-end: -1px; cursor: pointer; border-radius: ${t.radius} ${t.radius} 0 0; }
|
|
110
|
+
[role='tab'] { ${targetSize} position: relative; flex: none; padding: ${space(3)} ${space(4)}; font: inherit; font-weight: ${fontWeight("semibold")}; white-space: nowrap; color: ${t.textMuted}; background: transparent; border: 0; border-block-end: 3px solid transparent; margin-block-end: -1px; cursor: pointer; border-radius: ${t.radius} ${t.radius} 0 0; }
|
|
96
111
|
/* Inside a box that scrolls the ring would be clipped, so it is drawn inside the tab. */
|
|
97
112
|
[role='tab']:focus-visible { box-shadow: inset 0 0 0 2px ${t.text}, inset 0 0 0 4px ${t.surfaceCard}; }
|
|
98
113
|
[role='tab']:hover { color: ${t.text}; background: ${t.surfaceInset}; }
|
|
@@ -109,7 +124,7 @@ var ImpaktTabs = class extends ImpaktElement {
|
|
|
109
124
|
.sr-only { ${visuallyHidden} }
|
|
110
125
|
/* Links drawn as tabs. */
|
|
111
126
|
nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: ${space(1)}; overflow-x: auto; scrollbar-width: thin; border-block-end: ${t.borderThin} solid ${t.border}; }
|
|
112
|
-
nav a { ${targetSize} display: inline-flex; align-items: center; flex: none; padding: ${space(3)} ${space(4)}; font-weight: ${fontWeight("semibold")}; white-space: nowrap; color: ${t.textMuted}; text-decoration: none; border-block-end: 3px solid transparent; margin-block-end: -1px; border-radius: ${t.radius} ${t.radius} 0 0; }
|
|
127
|
+
nav a { ${targetSize} position: relative; display: inline-flex; align-items: center; flex: none; padding: ${space(3)} ${space(4)}; font-weight: ${fontWeight("semibold")}; white-space: nowrap; color: ${t.textMuted}; text-decoration: none; border-block-end: 3px solid transparent; margin-block-end: -1px; border-radius: ${t.radius} ${t.radius} 0 0; }
|
|
113
128
|
nav a:hover { color: ${t.text}; background: ${t.surfaceInset}; }
|
|
114
129
|
nav a[aria-current='page'] { color: ${t.link}; border-block-end-color: currentColor; }
|
|
115
130
|
nav a:focus-visible { box-shadow: inset 0 0 0 2px ${t.text}, inset 0 0 0 4px ${t.surfaceCard}; outline: none; }
|
|
@@ -119,7 +134,8 @@ var ImpaktTabs = class extends ImpaktElement {
|
|
|
119
134
|
:host([look='pill']) :is([role='tab'], nav a):hover { background: ${t.surfaceInset}; }
|
|
120
135
|
:host([look='pill']) :is([role='tab'][aria-selected='true'], nav a[aria-current='page']) { background: ${t.text}; color: ${t.surfaceCard}; }
|
|
121
136
|
@media (forced-colors: active) { :host([look='pill']) :is([role='tab'][aria-selected='true'], nav a[aria-current='page']) { border: 2px solid Highlight; } }
|
|
122
|
-
`
|
|
137
|
+
`
|
|
138
|
+
];
|
|
123
139
|
}
|
|
124
140
|
countOf(item) {
|
|
125
141
|
if (typeof item.count !== "number") return nothing;
|
|
@@ -190,4 +206,4 @@ export {
|
|
|
190
206
|
ImpaktVisuallyHidden,
|
|
191
207
|
ImpaktTabs
|
|
192
208
|
};
|
|
193
|
-
//# sourceMappingURL=chunk-
|
|
209
|
+
//# sourceMappingURL=chunk-MLKNZL5J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/blocks.ts"],"sourcesContent":["import { css, html, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { focusRing, targetSize, touchTarget, visuallyHidden } from '../base/styles';\nimport { fontWeight, lineHeight, space, t } from '../base/tokens';\nimport { announceNavigate } from './shell';\n\n/**\n * A line between two parts of a page.\n *\n * It is decoration, so a screen reader passes over it. Where the change of\n * subject matters, a heading says so better.\n *\n * @category layout\n * @icon divider\n */\nexport class ImpaktDivider extends ImpaktElement {\n static properties = {\n spacing: { type: String, reflect: true },\n tone: { type: String, reflect: true },\n };\n /** Space above and below the line. */\n declare spacing: 'sm' | 'md' | 'lg' | 'xl';\n declare tone: 'subtle' | 'strong';\n\n constructor() {\n super();\n this.spacing = 'md';\n this.tone = 'subtle';\n }\n\n static styles = [\n ...ImpaktElement.styles,\n css`\n :host { display: block; }\n hr { margin: ${space(4)} 0; border: 0; border-block-start: ${t.borderThin} solid ${t.border}; opacity: 0.5; }\n :host([tone='strong']) hr { opacity: 1; border-block-start-width: ${t.borderThick}; }\n :host([spacing='sm']) hr { margin-block: ${space(2)}; }\n :host([spacing='lg']) hr { margin-block: ${space(8)}; }\n :host([spacing='xl']) hr { margin-block: ${space(12)}; }\n `,\n ];\n\n render(): TemplateResult {\n return html`<hr aria-hidden=\"true\" part=\"line\" />`;\n }\n}\n\n/**\n * Empty space, from the spacing scale, for the rare place where the gaps of the\n * containers around it are not enough.\n *\n * @category layout\n * @icon spacer\n */\nexport class ImpaktSpacer extends ImpaktElement {\n static properties = { size: { type: String, reflect: true } };\n declare size: 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\n constructor() {\n super();\n this.size = 'md';\n }\n\n static styles = [\n ...ImpaktElement.styles,\n css`\n :host { display: block; block-size: ${space(4)}; }\n :host([size='sm']) { block-size: ${space(2)}; }\n :host([size='lg']) { block-size: ${space(8)}; }\n :host([size='xl']) { block-size: ${space(12)}; }\n :host([size='2xl']) { block-size: ${space(16)}; }\n `,\n ];\n\n render(): TemplateResult {\n return html``;\n }\n}\n\n/**\n * Words a screen reader says that are not shown: \"(opens a map)\" after a link\n * whose purpose is clear on screen from where it sits.\n *\n * @category typography\n * @icon hidden\n * @slot - The words to say.\n */\nexport class ImpaktVisuallyHidden extends ImpaktElement {\n static styles = [...ImpaktElement.styles, css`:host { ${visuallyHidden} }`];\n render(): TemplateResult {\n return html`<slot></slot>`;\n }\n}\n\n/** One tab and what it shows. */\nexport interface TabItem {\n id: string;\n label: string;\n /** The panel's words. A child with `slot` set to the tab's id is shown instead, for anything richer. */\n body?: string;\n /** A number shown on the tab, such as the open tasks behind it. */\n count?: number;\n /** The count in words for a screen reader, such as \"2 overdue tasks\". The number alone when empty. */\n countLabel?: string;\n /** Where the tab goes. When every tab has one, the tabs are links to pages, not panels. */\n href?: string;\n}\n\n/**\n * Panels of content behind a row of tabs, one shown at a time: the floor plans\n * of three house types, or a case's summary, tasks and files.\n *\n * It follows the ARIA tabs pattern. The tabs are one stop in the tab order,\n * the arrow keys, Home and End move between them, and each panel is labelled\n * by its tab. Use an accordion instead when someone may want to compare panels.\n *\n * **The tabs stay on one row** and scroll sideways when they do not fit, as the\n * design guide sets, and the chosen tab is scrolled into view, so on a phone it\n * is never hidden off the edge. With `two-rows`, a set of more than four tabs is\n * laid out in two rows on a narrow screen instead, so every tab can be seen.\n *\n * **The chosen tab is kept** when the tabs are given again, as a React or Vue app\n * does on every render, so long as a tab with that id is still there.\n *\n * A panel shows its item's `body`, or a child whose `slot` is the item's id.\n *\n * **Tabs that go to pages are links.** When every item has an `href`, such as\n * a job's Overview, Money and Notes, each of which has its own address, the\n * tabs are drawn the same but are a `nav` of links, the current one marked\n * `aria-current=\"page\"`, with no panels. A row of links is not the ARIA tabs\n * pattern, and announcing it as one would promise arrow keys and panels that\n * are not there. They send `impakt-navigate` like the side navigation, so an\n * app can route without a reload.\n *\n * `look=\"pill\"` draws the tabs as pills in a rounded bar, with the chosen one\n * filled, as a product's workspace tabs are.\n *\n * @category content\n * @icon tabs\n * @slot - A child with `slot` set to a tab's id is that tab's panel.\n * @fires {CustomEvent<{ value: string }>} impakt-change - When another tab is chosen.\n * @fires {CustomEvent<{ href: string; id: string }>} impakt-navigate - When a tab that is a link is followed. Cancel it to route in the app.\n */\nexport class ImpaktTabs extends ImpaktElement {\n static properties = {\n items: { type: Array },\n selected: { type: String, reflect: true },\n label: { type: String },\n twoRows: { type: Boolean, reflect: true, attribute: 'two-rows' },\n look: { type: String, reflect: true },\n };\n declare items: TabItem[];\n /** The id of the tab shown first. The first tab when it is empty. */\n declare selected: string;\n /** What the set of tabs is about, for a screen reader. */\n declare label: string;\n /** On a narrow screen, lay more than four tabs out in two rows rather than scroll them. */\n declare twoRows: boolean;\n /** `line` underlines the chosen tab; `pill` fills it, in a rounded bar. */\n declare look: 'line' | 'pill';\n\n constructor() {\n super();\n this.items = [];\n this.selected = '';\n this.label = '';\n this.twoRows = false;\n this.look = 'line';\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n touchTarget(\"[role='tab']\"),\n css`\n /* Only the two-row layout needs a size container. Making every tab set one\n would take its width from its parent alone, so in a flex row, with no\n width given, it would shrink to nothing. In a row it may still shrink\n below its tabs, which then scroll, rather than widen the page. */\n :host { display: block; min-inline-size: 0; }\n :host([two-rows]) { container-type: inline-size; }\n [role='tablist'] { display: flex; gap: ${space(1)}; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; border-block-end: ${t.borderThin} solid ${t.border}; }\n [role='tab'] { ${targetSize} position: relative; flex: none; padding: ${space(3)} ${space(4)}; font: inherit; font-weight: ${fontWeight('semibold')}; white-space: nowrap; color: ${t.textMuted}; background: transparent; border: 0; border-block-end: 3px solid transparent; margin-block-end: -1px; cursor: pointer; border-radius: ${t.radius} ${t.radius} 0 0; }\n /* Inside a box that scrolls the ring would be clipped, so it is drawn inside the tab. */\n [role='tab']:focus-visible { box-shadow: inset 0 0 0 2px ${t.text}, inset 0 0 0 4px ${t.surfaceCard}; }\n [role='tab']:hover { color: ${t.text}; background: ${t.surfaceInset}; }\n [role='tab'][aria-selected='true'] { color: ${t.link}; border-block-end-color: currentColor; }\n [role='tabpanel'] { padding-block: ${space(5)}; line-height: ${lineHeight('normal')}; }\n .body { white-space: pre-line; }\n @container (max-width: 40rem) {\n :host([two-rows]) [role='tablist'].many { display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); overflow: visible; border-block-end: 0; gap: ${space(1)}; }\n :host([two-rows]) .many [role='tab'] { white-space: normal; padding-inline: ${space(2)}; margin: 0; border-block-end-width: 3px; border-block-end-color: ${t.rule}; border-radius: ${t.radius}; }\n :host([two-rows]) .many [role='tab'][aria-selected='true'] { border-block-end-color: currentColor; background: ${t.brandSubtle}; }\n }\n @media (forced-colors: active) { [role='tab'][aria-selected='true'] { border-block-end-color: Highlight; } }\n .count { display: inline-flex; align-items: center; justify-content: center; min-inline-size: 20px; block-size: 20px; margin-inline-start: ${space(2)}; padding: 0 ${space(1.5)}; border-radius: 999px; font-size: 12px; font-weight: ${fontWeight('semibold')}; background: ${t.brand}; color: ${t.onBrand}; font-variant-numeric: tabular-nums; }\n .sr-only { ${visuallyHidden} }\n /* Links drawn as tabs. */\n nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: ${space(1)}; overflow-x: auto; scrollbar-width: thin; border-block-end: ${t.borderThin} solid ${t.border}; }\n nav a { ${targetSize} position: relative; display: inline-flex; align-items: center; flex: none; padding: ${space(3)} ${space(4)}; font-weight: ${fontWeight('semibold')}; white-space: nowrap; color: ${t.textMuted}; text-decoration: none; border-block-end: 3px solid transparent; margin-block-end: -1px; border-radius: ${t.radius} ${t.radius} 0 0; }\n nav a:hover { color: ${t.text}; background: ${t.surfaceInset}; }\n nav a[aria-current='page'] { color: ${t.link}; border-block-end-color: currentColor; }\n nav a:focus-visible { box-shadow: inset 0 0 0 2px ${t.text}, inset 0 0 0 4px ${t.surfaceCard}; outline: none; }\n /* The pill look, for either kind. */\n :host([look='pill']) :is([role='tablist'], nav ul) { padding: ${space(1)}; border: 0; border-radius: 999px; background: ${t.surfaceCard}; gap: ${space(0.5)}; }\n :host([look='pill']) :is([role='tab'], nav a) { padding: ${space(2)} ${space(4)}; margin: 0; border: 0; border-radius: 999px; font-weight: ${fontWeight('medium')}; color: ${t.text}; }\n :host([look='pill']) :is([role='tab'], nav a):hover { background: ${t.surfaceInset}; }\n :host([look='pill']) :is([role='tab'][aria-selected='true'], nav a[aria-current='page']) { background: ${t.text}; color: ${t.surfaceCard}; }\n @media (forced-colors: active) { :host([look='pill']) :is([role='tab'][aria-selected='true'], nav a[aria-current='page']) { border: 2px solid Highlight; } }\n `,\n ];\n\n private countOf(item: TabItem): TemplateResult | typeof nothing {\n if (typeof item.count !== 'number') return nothing;\n return item.countLabel\n ? html`<span class=\"count\" aria-hidden=\"true\">${item.count}</span><span class=\"sr-only\">, ${item.countLabel}</span>`\n : html`<span class=\"count\">${item.count}</span>`;\n }\n\n private get linked(): boolean {\n const items = this.items ?? [];\n return items.length > 0 && items.every((i) => Boolean(i.href));\n }\n\n private current(): string {\n const items = this.items ?? [];\n return items.some((i) => i.id === this.selected) ? this.selected : (items[0]?.id ?? '');\n }\n\n private choose(id: string, focus: boolean): void {\n if (id === this.current()) return;\n this.selected = id;\n this.dispatchEvent(new CustomEvent('impakt-change', { detail: { value: id }, bubbles: true, composed: true }));\n if (focus) void this.updateComplete.then(() => this.renderRoot.querySelector<HTMLElement>(`#${this.id_(`tab-${id}`)}`)?.focus({ preventScroll: true }));\n }\n\n private onKey(event: KeyboardEvent): void {\n const items = this.items ?? [];\n const at = items.findIndex((i) => i.id === this.current());\n const to = { ArrowRight: at + 1, ArrowLeft: at - 1, Home: 0, End: items.length - 1 }[event.key];\n if (to === undefined || !items.length) return;\n event.preventDefault();\n this.choose(items[(to + items.length) % items.length]!.id, true);\n }\n\n /**\n * Bring the chosen tab into view inside the row of tabs. Only the row scrolls:\n * `scrollIntoView` would scroll the page too, and move someone who is reading\n * further down.\n */\n private reveal(): void {\n const list = this.renderRoot.querySelector<HTMLElement>(\"[role='tablist']\");\n const tab = this.renderRoot.querySelector<HTMLElement>(\"[role='tab'][aria-selected='true']\");\n if (!list || !tab || list.scrollWidth <= list.clientWidth) return;\n const start = tab.offsetLeft - list.offsetLeft;\n const end = start + tab.offsetWidth;\n if (start < list.scrollLeft) list.scrollLeft = start - 16;\n else if (end > list.scrollLeft + list.clientWidth) list.scrollLeft = end - list.clientWidth + 16;\n }\n\n updated(changed: Map<string, unknown>): void {\n if (changed.has('selected') || changed.has('items')) this.reveal();\n }\n\n render(): TemplateResult {\n const items = this.items ?? [];\n const current = this.current();\n if (this.linked) {\n return html`<nav aria-label=${this.label || nothing} part=\"tabs\"><ul>\n ${items.map((item) => html`<li><a href=${item.href!} part=\"tab\" aria-current=${item.id === current ? 'page' : nothing} @click=${(e: MouseEvent) => announceNavigate(this, e, { href: item.href!, id: item.id })}>${item.label}${this.countOf(item)}</a></li>`)}\n </ul></nav>`;\n }\n const many = items.length > 4;\n return html`<div role=\"tablist\" aria-label=${this.label || nothing} part=\"tabs\" class=${many ? 'many' : ''} style=${many ? `--columns:${Math.ceil(items.length / 2)}` : nothing} @keydown=${this.onKey}>\n ${items.map((item) => html`<button role=\"tab\" type=\"button\" id=${this.id_(`tab-${item.id}`)} aria-selected=${item.id === current ? 'true' : 'false'} aria-controls=${this.id_(`panel-${item.id}`)} tabindex=${item.id === current ? '0' : '-1'} @click=${() => this.choose(item.id, false)}>${item.label}${this.countOf(item)}</button>`)}\n </div>\n ${items.map((item) => html`<div role=\"tabpanel\" id=${this.id_(`panel-${item.id}`)} aria-labelledby=${this.id_(`tab-${item.id}`)} tabindex=\"0\" ?hidden=${item.id !== current} part=\"panel\"><slot name=${item.id}><span class=\"body\">${item.body ?? ''}</span></slot></div>`)}`;\n }\n}\n\ncustomElements.define('impakt-divider', ImpaktDivider);\ncustomElements.define('impakt-spacer', ImpaktSpacer);\ncustomElements.define('impakt-visually-hidden', ImpaktVisuallyHidden);\ncustomElements.define('impakt-tabs', ImpaktTabs);\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impakt-divider': ImpaktDivider;\n 'impakt-spacer': ImpaktSpacer;\n 'impakt-visually-hidden': ImpaktVisuallyHidden;\n 'impakt-tabs': ImpaktTabs;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,KAAK,MAAM,eAAoC;AAejD,IAAM,gBAAN,cAA4B,cAAc;AAAA,EAC/C;AAAA,SAAO,aAAa;AAAA,MAClB,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACvC,MAAM,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC;AAAA;AAAA,EAKA,cAAc;AACZ,UAAM;AACN,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA;AAAA,SAAO,SAAS;AAAA,MACd,GAAG,cAAc;AAAA,MACjB;AAAA;AAAA,mBAEe,MAAM,CAAC,CAAC,sCAAsC,EAAE,UAAU,UAAU,EAAE,MAAM;AAAA,wEACvB,EAAE,WAAW;AAAA,+CACtC,MAAM,CAAC,CAAC;AAAA,+CACR,MAAM,CAAC,CAAC;AAAA,+CACR,MAAM,EAAE,CAAC;AAAA;AAAA,IAEtD;AAAA;AAAA,EAEA,SAAyB;AACvB,WAAO;AAAA,EACT;AACF;AASO,IAAM,eAAN,cAA2B,cAAc;A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AAAA,QAClM,MAAM,IAAI,CAAC,SAAS,2CAA2C,KAAK,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC,kBAAkB,KAAK,OAAO,UAAU,SAAS,OAAO,kBAAkB,KAAK,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC,aAAa,KAAK,OAAO,UAAU,MAAM,IAAI,WAAW,MAAM,KAAK,OAAO,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,GAAG,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC;AAAA;AAAA,MAEzU,MAAM,IAAI,CAAC,SAAS,+BAA+B,KAAK,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC,oBAAoB,KAAK,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC,yBAAyB,KAAK,OAAO,OAAO,4BAA4B,KAAK,EAAE,uBAAuB,KAAK,QAAQ,EAAE,sBAAsB,CAAC;AAAA,EAC7Q;AACF;AAEA,eAAe,OAAO,kBAAkB,aAAa;AACrD,eAAe,OAAO,iBAAiB,YAAY;AACnD,eAAe,OAAO,0BAA0B,oBAAoB;AACpE,eAAe,OAAO,eAAe,UAAU;","names":[]}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
t,
|
|
12
12
|
targetSize,
|
|
13
13
|
touchTarget
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
15
15
|
|
|
16
16
|
// packages/ui/src/components/dialog.ts
|
|
17
17
|
import { html, css, nothing } from "lit";
|
|
@@ -155,4 +155,4 @@ customElements.define("impakt-dialog", ImpaktDialog);
|
|
|
155
155
|
export {
|
|
156
156
|
ImpaktDialog
|
|
157
157
|
};
|
|
158
|
-
//# sourceMappingURL=chunk-
|
|
158
|
+
//# sourceMappingURL=chunk-MOO63SHZ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/dialog.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { focusRing, targetSize, touchTarget } from '../base/styles';\nimport { lockScroll, unlockScroll } from '../base/scroll-lock';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\n/**\n * A modal dialog — \"are you sure you want to leave this order?\".\n *\n * **It is a native `<dialog>` opened with `showModal()`, and that is the whole\n * design.** The platform then provides, correctly and in every browser: a\n * focus trap, Escape to close, the rest of the page made inert so a screen\n * reader cannot wander out of the dialog, rendering in the top layer so no\n * `z-index` can cover it, and focus returned to whatever opened it when it\n * closes.\n *\n * Every one of those is a thing hand-rolled modals get wrong. The focus trap\n * is the famous one, but inertness is the worse failure: a dialog that traps\n * the Tab key but leaves the background in the accessibility tree lets a\n * screen-reader user read straight past it into a page they cannot interact\n * with, and nothing on screen tells them that is what happened.\n *\n * What is left to get right is the labelling. `aria-labelledby` points at the\n * dialog's own heading, so it is announced by name on open rather than as\n * \"dialog\".\n *\n * Two things the platform leaves out are added. The page behind does not scroll\n * while the dialog is open, so a finger on the backdrop does not move the page\n * out from under it. And with `phone-full-screen` the dialog fills a phone's\n * screen, which suits a dialog holding a form; a short question is better left\n * as a box in the middle, which is the default.\n\n *\n * @category feedback\n * @icon dialog\n * @fires {CustomEvent<null>} impakt-close - When the dialog is closed.\n * @slot - The body of the dialog.\n */\nexport class ImpaktDialog extends ImpaktElement {\n static properties = {\n open: { type: Boolean, reflect: true },\n heading: { type: String },\n closeLabel: { type: String, attribute: 'close-label' },\n dismissible: { type: Boolean },\n phoneFullScreen: { type: Boolean, reflect: true, attribute: 'phone-full-screen' },\n };\n\n declare open: boolean;\n declare heading: string;\n declare closeLabel: string;\n /** When false, Escape and the backdrop do not close it — a decision must be made. */\n declare dismissible: boolean;\n /** Fill the screen on a phone, for a dialog that holds a form or a long text. */\n declare phoneFullScreen: boolean;\n\n constructor() {\n super();\n this.open = false;\n this.heading = '';\n this.closeLabel = 'Close';\n this.dismissible = true;\n this.phoneFullScreen = false;\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n touchTarget('.close'),\n css`\n dialog {\n padding: 0;\n border: 0;\n border-radius: ${t.radius2xl};\n background: ${t.surfaceCard};\n color: ${t.text};\n box-shadow: ${t.shadowXl}, 0 0 0 1px ${t.hairline};\n max-inline-size: min(32rem, calc(100vw - 2rem));\n /* 1.4.10 Reflow: a dialog taller than the viewport must scroll inside\n itself rather than clipping, at 320px and at 400% zoom alike. */\n max-block-size: calc(100vh - 2rem);\n overflow: auto;\n }\n dialog::backdrop {\n background: color-mix(in srgb, ${t.text} 30%, transparent);\n backdrop-filter: blur(2px);\n }\n .head {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: ${space(3)};\n padding: ${space(5)} ${space(5)} 0;\n }\n .heading {\n margin: 0;\n font-family: ${t.fontHeading};\n font-size: ${fontSize('xl')};\n font-weight: ${fontWeight('bold')};\n color: ${t.textHeading};\n }\n .body {\n padding: ${space(4)} ${space(5)} ${space(5)};\n }\n @media (max-width: 40rem) {\n :host([phone-full-screen]) dialog {\n inline-size: 100vw;\n max-inline-size: 100vw;\n block-size: 100dvh;\n max-block-size: 100dvh;\n margin: 0;\n border-radius: 0;\n }\n }\n .close {\n ${targetSize}\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n background: none;\n border: 0;\n border-radius: ${t.radius};\n font: inherit;\n font-size: ${fontSize('lg')};\n color: ${t.text};\n cursor: pointer;\n }\n `,\n ];\n\n private get dialog(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n updated(changed: Map<string, unknown>): void {\n if (!changed.has('open')) return;\n const dialog = this.dialog;\n if (!dialog) return;\n // happy-dom and older engines do not implement showModal. Falling back to\n // the `open` attribute renders a NON-modal dialog — no focus trap, no\n // inert background — so it is used only to keep tests and ancient browsers\n // from throwing, never as an equivalent.\n if (this.open) {\n if (typeof dialog.showModal === 'function') dialog.showModal();\n else dialog.setAttribute('open', '');\n lockScroll(this);\n } else {\n if (typeof dialog.close === 'function' && dialog.open) dialog.close();\n else dialog.removeAttribute('open');\n unlockScroll(this);\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n unlockScroll(this);\n }\n\n private close(): void {\n this.open = false;\n this.dispatchEvent(new CustomEvent('impakt-close', { bubbles: true, composed: true }));\n }\n\n render(): TemplateResult {\n return html`\n <dialog\n part=\"dialog\"\n aria-labelledby=${this.heading ? this.id_('heading') : nothing}\n @cancel=${(e: Event) => {\n // `cancel` fires on Escape. Blocking it is what makes a dialog\n // non-dismissible, and it is why `dismissible` exists rather than\n // leaving a caller to re-open on close.\n if (!this.dismissible) e.preventDefault();\n else this.close();\n }}\n @close=${() => {
|
|
1
|
+
{"version":3,"sources":["../src/components/dialog.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { focusRing, targetSize, touchTarget } from '../base/styles';\nimport { lockScroll, unlockScroll } from '../base/scroll-lock';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\n/**\n * A modal dialog — \"are you sure you want to leave this order?\".\n *\n * **It is a native `<dialog>` opened with `showModal()`, and that is the whole\n * design.** The platform then provides, correctly and in every browser: a\n * focus trap, Escape to close, the rest of the page made inert so a screen\n * reader cannot wander out of the dialog, rendering in the top layer so no\n * `z-index` can cover it, and focus returned to whatever opened it when it\n * closes.\n *\n * Every one of those is a thing hand-rolled modals get wrong. The focus trap\n * is the famous one, but inertness is the worse failure: a dialog that traps\n * the Tab key but leaves the background in the accessibility tree lets a\n * screen-reader user read straight past it into a page they cannot interact\n * with, and nothing on screen tells them that is what happened.\n *\n * What is left to get right is the labelling. `aria-labelledby` points at the\n * dialog's own heading, so it is announced by name on open rather than as\n * \"dialog\".\n *\n * Two things the platform leaves out are added. The page behind does not scroll\n * while the dialog is open, so a finger on the backdrop does not move the page\n * out from under it. And with `phone-full-screen` the dialog fills a phone's\n * screen, which suits a dialog holding a form; a short question is better left\n * as a box in the middle, which is the default.\n\n *\n * @category feedback\n * @icon dialog\n * @fires {CustomEvent<null>} impakt-close - When the dialog is closed.\n * @slot - The body of the dialog.\n */\nexport class ImpaktDialog extends ImpaktElement {\n static properties = {\n open: { type: Boolean, reflect: true },\n heading: { type: String },\n closeLabel: { type: String, attribute: 'close-label' },\n dismissible: { type: Boolean },\n phoneFullScreen: { type: Boolean, reflect: true, attribute: 'phone-full-screen' },\n };\n\n declare open: boolean;\n declare heading: string;\n declare closeLabel: string;\n /** When false, Escape and the backdrop do not close it — a decision must be made. */\n declare dismissible: boolean;\n /** Fill the screen on a phone, for a dialog that holds a form or a long text. */\n declare phoneFullScreen: boolean;\n\n constructor() {\n super();\n this.open = false;\n this.heading = '';\n this.closeLabel = 'Close';\n this.dismissible = true;\n this.phoneFullScreen = false;\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n touchTarget('.close'),\n css`\n dialog {\n padding: 0;\n border: 0;\n border-radius: ${t.radius2xl};\n background: ${t.surfaceCard};\n color: ${t.text};\n box-shadow: ${t.shadowXl}, 0 0 0 1px ${t.hairline};\n max-inline-size: min(32rem, calc(100vw - 2rem));\n /* 1.4.10 Reflow: a dialog taller than the viewport must scroll inside\n itself rather than clipping, at 320px and at 400% zoom alike. */\n max-block-size: calc(100vh - 2rem);\n overflow: auto;\n }\n dialog::backdrop {\n background: color-mix(in srgb, ${t.text} 30%, transparent);\n backdrop-filter: blur(2px);\n }\n .head {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: ${space(3)};\n padding: ${space(5)} ${space(5)} 0;\n }\n .heading {\n margin: 0;\n font-family: ${t.fontHeading};\n font-size: ${fontSize('xl')};\n font-weight: ${fontWeight('bold')};\n color: ${t.textHeading};\n }\n .body {\n padding: ${space(4)} ${space(5)} ${space(5)};\n }\n @media (max-width: 40rem) {\n :host([phone-full-screen]) dialog {\n inline-size: 100vw;\n max-inline-size: 100vw;\n block-size: 100dvh;\n max-block-size: 100dvh;\n margin: 0;\n border-radius: 0;\n }\n }\n .close {\n ${targetSize}\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n background: none;\n border: 0;\n border-radius: ${t.radius};\n font: inherit;\n font-size: ${fontSize('lg')};\n color: ${t.text};\n cursor: pointer;\n }\n `,\n ];\n\n private get dialog(): HTMLDialogElement | null {\n return this.renderRoot.querySelector('dialog');\n }\n\n updated(changed: Map<string, unknown>): void {\n if (!changed.has('open')) return;\n const dialog = this.dialog;\n if (!dialog) return;\n // happy-dom and older engines do not implement showModal. Falling back to\n // the `open` attribute renders a NON-modal dialog — no focus trap, no\n // inert background — so it is used only to keep tests and ancient browsers\n // from throwing, never as an equivalent.\n if (this.open) {\n if (typeof dialog.showModal === 'function') dialog.showModal();\n else dialog.setAttribute('open', '');\n lockScroll(this);\n } else {\n if (typeof dialog.close === 'function' && dialog.open) dialog.close();\n else dialog.removeAttribute('open');\n unlockScroll(this);\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n unlockScroll(this);\n }\n\n private close(): void {\n this.open = false;\n this.dispatchEvent(new CustomEvent('impakt-close', { bubbles: true, composed: true }));\n }\n\n render(): TemplateResult {\n return html`\n <dialog\n part=\"dialog\"\n aria-labelledby=${this.heading ? this.id_('heading') : nothing}\n @cancel=${(e: Event) => {\n // `cancel` fires on Escape. Blocking it is what makes a dialog\n // non-dismissible, and it is why `dismissible` exists rather than\n // leaving a caller to re-open on close.\n if (!this.dismissible) e.preventDefault();\n else this.close();\n }}\n @close=${() => {\n if (this.open) this.close();\n }}\n >\n <div class=\"head\">\n ${this.heading ? html`<h2 class=\"heading\" id=${this.id_('heading')} part=\"heading\">${this.heading}</h2>` : nothing}\n ${\n this.dismissible\n ? html`<button class=\"close\" part=\"close\" type=\"button\" @click=${this.close}>\n <span aria-hidden=\"true\">×</span>\n <span class=\"sr-only\" style=\"position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)\">${this.closeLabel}</span>\n </button>`\n : nothing\n }\n </div>\n <div class=\"body\" part=\"body\"><slot></slot></div>\n </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KAAM,MAAK,MAAM;AAAA,IAC5B,CAAC;AAAA;AAAA;AAAA,YAGG,KAAK,UAAU,8BAA8B,KAAK,IAAI,SAAS,CAAC,mBAAmB,KAAK,OAAO,UAAU,OAAO;AAAA,YAEhH,KAAK,cACD,+DAA+D,KAAK,KAAK;AAAA;AAAA,4HAEmC,KAAK,UAAU;AAAA,2BAE3H,OACN;AAAA;AAAA;AAAA;AAAA;AAAA,EAKR;AACF;AAEA,eAAe,OAAO,iBAAiB,YAAY;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ImpaktElement,
|
|
3
3
|
t
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
5
5
|
|
|
6
6
|
// packages/ui/src/components/media.ts
|
|
7
7
|
import { html, css, nothing } from "lit";
|
|
@@ -175,4 +175,4 @@ export {
|
|
|
175
175
|
ImpaktLogo,
|
|
176
176
|
ImpaktDocumentLink
|
|
177
177
|
};
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
178
|
+
//# sourceMappingURL=chunk-NKMJMVZP.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
space,
|
|
8
8
|
t,
|
|
9
9
|
visuallyHidden
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
11
11
|
|
|
12
12
|
// packages/ui/src/base/FieldElement.ts
|
|
13
13
|
import { html, css, nothing } from "lit";
|
|
@@ -120,10 +120,7 @@ var FieldElement = class extends ImpaktElement {
|
|
|
120
120
|
* already learned to ignore it.
|
|
121
121
|
*/
|
|
122
122
|
get describedBy() {
|
|
123
|
-
const ids = [
|
|
124
|
-
this.description ? this.id_("description") : "",
|
|
125
|
-
this.error ? this.id_("error") : ""
|
|
126
|
-
].filter(Boolean);
|
|
123
|
+
const ids = [this.description ? this.id_("description") : "", this.error ? this.id_("error") : ""].filter(Boolean);
|
|
127
124
|
return ids.length ? ids.join(" ") : nothing;
|
|
128
125
|
}
|
|
129
126
|
/**
|
|
@@ -176,7 +173,11 @@ var FieldElement = class extends ImpaktElement {
|
|
|
176
173
|
setFormValue(value) {
|
|
177
174
|
this.value = value;
|
|
178
175
|
this.internals?.setFormValue(value);
|
|
179
|
-
this.dispatchEvent(new CustomEvent("impakt-change", { detail:
|
|
176
|
+
this.dispatchEvent(new CustomEvent("impakt-change", { detail: this.changeDetail(value), bubbles: true, composed: true }));
|
|
177
|
+
}
|
|
178
|
+
/** What `impakt-change` carries. A control with more to say than its value adds it here. */
|
|
179
|
+
changeDetail(value) {
|
|
180
|
+
return { value };
|
|
180
181
|
}
|
|
181
182
|
};
|
|
182
183
|
|
|
@@ -184,4 +185,4 @@ export {
|
|
|
184
185
|
fieldWidths,
|
|
185
186
|
FieldElement
|
|
186
187
|
};
|
|
187
|
-
//# sourceMappingURL=chunk-
|
|
188
|
+
//# sourceMappingURL=chunk-ONED3PUB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base/FieldElement.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from './ImpaktElement';\nimport { focusRing, visuallyHidden } from './styles';\nimport { fontSize, fontWeight, lineHeight, space, t } from './tokens';\n\n/**\n * The shared anatomy of a form control: a label, an optional description, a\n * control, and an error.\n *\n * This exists because the ARIA wiring between those four is where accessible\n * forms actually fail, and it fails the same way every time — a description\n * that is never announced, an error that appears silently, a label that points\n * at nothing. Written once, it is right once.\n *\n * Everything is rendered inside this component's own shadow root, including\n * the native control. That is not an implementation detail: `aria-describedby`\n * cannot cross a shadow boundary, so a component that slotted the input from\n * outside could not describe it. Keeping the whole relationship in one tree is\n * what makes the wiring work at all.\n */\n/**\n * How wide a single-line control is, from what it holds: a postcode is short,\n * an email address is long. A width that matches the answer is a hint about\n * what to type (1.3.5 is about the purpose, this is about the size). Applied by\n * the controls that take a `width`, through `--impakt-field-width`.\n */\nexport const fieldWidths = css`\n :host { --impakt-field-width: 100%; }\n :host([width='xs']) { --impakt-field-width: 8ch; }\n :host([width='sm']) { --impakt-field-width: 14ch; }\n :host([width='md']) { --impakt-field-width: 24ch; }\n :host([width='lg']) { --impakt-field-width: 40ch; }\n`;\n\n/**\n * The base of every form control.\n *\n * @fires {CustomEvent<{ value: string }>} impakt-change - When the answer changes. The answer is in detail.value.\n */\nexport abstract class FieldElement extends ImpaktElement {\n /** Form controls participate in a `<form>` like native ones. */\n static formAssociated = true;\n\n static properties = {\n label: { type: String },\n name: { type: String },\n value: { type: String },\n description: { type: String },\n error: { type: String },\n required: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n readonly: { type: Boolean, reflect: true },\n requiredText: { type: String, attribute: 'required-text' },\n };\n\n declare label: string;\n declare name: string;\n declare value: string;\n declare description: string;\n declare error: string;\n declare required: boolean;\n declare disabled: boolean;\n declare readonly: boolean;\n /**\n * How \"you must answer this\" is said.\n *\n * Words, not an asterisk. 3.3.2 asks for labels or instructions, and an\n * asterisk is neither until a legend explains it — which puts the\n * explanation somewhere other than the field it explains. It is a property\n * so a partner can reword it, not so they can empty it.\n */\n declare requiredText: string;\n\n protected internals: ElementInternals | null = null;\n\n constructor() {\n super();\n this.label = '';\n this.name = '';\n this.value = '';\n this.description = '';\n this.error = '';\n this.required = false;\n this.disabled = false;\n this.readonly = false;\n this.requiredText = 'required';\n // happy-dom and older engines do not implement attachInternals. A control\n // that cannot associate with a form is still a usable control, so this\n // degrades rather than throwing on construction.\n try {\n this.internals = this.attachInternals();\n } catch {\n this.internals = null;\n }\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n css`\n :host {\n display: block;\n margin-block-end: ${space(4)};\n }\n .label {\n display: block;\n font-size: ${fontSize('sm')};\n font-weight: ${fontWeight('semibold')};\n line-height: ${lineHeight('normal')};\n margin-block-end: ${space(1)};\n color: ${t.text};\n }\n .required {\n font-weight: ${fontWeight('regular')};\n color: ${t.textMuted};\n }\n .description {\n font-size: ${fontSize('sm')};\n line-height: ${lineHeight('normal')};\n color: ${t.textMuted};\n margin-block-end: ${space(2)};\n }\n .error {\n font-size: ${fontSize('sm')};\n line-height: ${lineHeight('normal')};\n color: ${t.dangerText};\n margin-block-start: ${space(1)};\n display: flex;\n gap: ${space(1)};\n }\n .error:empty {\n display: none;\n }\n .visually-hidden {\n ${visuallyHidden}\n }\n /*\n * Only the control is dimmed. Dimming the whole host took the question,\n * the hint and the error below 4.5:1, and a disabled field still has to\n * say what it is and why it cannot be changed. The native disabled\n * control itself is exempt from the contrast criterion.\n */\n :host([disabled]) :is(input, select, textarea, button) {\n opacity: 0.6;\n cursor: not-allowed;\n }\n `,\n ];\n\n protected get controlId(): string {\n return this.id_('control');\n }\n\n /**\n * What the control points `aria-describedby` at.\n *\n * The error id is included only while there is an error. A describedby that\n * always names an empty element trains a screen-reader user to expect\n * nothing after the description, and then the one time it matters they have\n * already learned to ignore it.\n */\n protected get describedBy(): string | typeof nothing {\n const ids = [\n this.description ? this.id_('description') : '',\n this.error ? this.id_('error') : '',\n ].filter(Boolean);\n return ids.length ? ids.join(' ') : nothing;\n }\n\n /**\n * Focusing the element focuses its control, so `el.focus()` from an app, a\n * React ref or the error summary's link lands where someone can type, rather\n * than on a host that cannot take focus and so silently does nothing.\n */\n focus(options?: FocusOptions): void {\n const control = this.renderRoot?.querySelector<HTMLElement>(`#${this.controlId}`)\n ?? this.renderRoot?.querySelector<HTMLElement>('input, select, textarea, button');\n if (control) control.focus(options);\n else super.focus(options);\n }\n\n /** Subclasses render the control itself; everything round it is here. */\n protected abstract renderControl(): TemplateResult;\n\n /**\n * `<label for>` by default. A group of controls — radios, checkboxes —\n * cannot use one, because `for` names a single control, so those override\n * this and render a `<fieldset>` and `<legend>` instead.\n */\n protected renderLabel(): TemplateResult {\n return html`\n <label class=\"label\" for=${this.controlId} part=\"label\">\n ${this.label}${this.required\n ? html`<span class=\"required\"> (${this.requiredText})</span>`\n : nothing}\n </label>\n `;\n }\n\n render(): TemplateResult {\n return html`\n ${this.renderLabel()}\n ${this.description\n ? html`<div class=\"description\" id=${this.id_('description')} part=\"description\">\n ${this.description}\n </div>`\n : nothing}\n ${this.renderControl()}\n <!--\n The error region is always present, even when empty. A live region\n inserted at the same moment as its content is announced unreliably\n across screen readers; one that already exists and is then filled is\n announced consistently. \"polite\" rather than \"assertive\" because a\n validation message should not interrupt what is being read.\n -->\n <div\n class=\"error\"\n id=${this.id_('error')}\n part=\"error\"\n aria-live=\"polite\"\n >\n ${this.error || nothing}\n </div>\n `;\n }\n\n /** Keep the form value in step with the control. */\n protected setFormValue(value: string): void {\n this.value = value;\n this.internals?.setFormValue(value);\n this.dispatchEvent(new CustomEvent('impakt-change', { detail: { value }, bubbles: true, composed: true }));\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,MAAM,KAAK,eAAoC;AA0BjD,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAapB,IAAe,eAAf,cAAoC,cAAc;AAAA,EAoCvD,cAAc;AACZ,UAAM;AAHR,SAAU,YAAqC;AAI7C,SAAK,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,cAAc;AACnB,SAAK,QAAQ;AACb,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,eAAe;AAIpB,QAAI;AACF,WAAK,YAAY,KAAK,gBAAgB;AAAA,IACxC,QAAQ;AACN,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA,EArDA;AAAA;AAAA,SAAO,iBAAiB;AAAA;AAAA,EAExB;AAAA,SAAO,aAAa;AAAA,MAClB,OAAO,EAAE,MAAM,OAAO;AAAA,MACtB,MAAM,EAAE,MAAM,OAAO;AAAA,MACrB,OAAO,EAAE,MAAM,OAAO;AAAA,MACtB,aAAa,EAAE,MAAM,OAAO;AAAA,MAC5B,OAAO,EAAE,MAAM,OAAO;AAAA,MACtB,UAAU,EAAE,MAAM,SAA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,IAAI;AAAA,IACnC,EAAE,OAAO,OAAO;AAChB,WAAO,IAAI,SAAS,IAAI,KAAK,GAAG,IAAI;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAA8B;AAClC,UAAM,UAAU,KAAK,YAAY,cAA2B,IAAI,KAAK,SAAS,EAAE,KAC3E,KAAK,YAAY,cAA2B,iCAAiC;AAClF,QAAI,QAAS,SAAQ,MAAM,OAAO;AAAA,QAC7B,OAAM,MAAM,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,cAA8B;AACtC,WAAO;AAAA,iCACsB,KAAK,SAAS;AAAA,UACrC,KAAK,KAAK,GAAG,KAAK,WAChB,gCAAgC,KAAK,YAAY,aACjD,OAAO;AAAA;AAAA;AAAA,EAGjB;AAAA,EAEA,SAAyB;AACvB,WAAO;AAAA,QACH,KAAK,YAAY,CAAC;AAAA,QAClB,KAAK,cACH,mCAAmC,KAAK,IAAI,aAAa,CAAC;AAAA,cACtD,KAAK,WAAW;AAAA,oBAEpB,OAAO;AAAA,QACT,KAAK,cAAc,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAUf,KAAK,IAAI,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA,UAIpB,KAAK,SAAS,OAAO;AAAA;AAAA;AAAA,EAG7B;AAAA;AAAA,EAGU,aAAa,OAAqB;AAC1C,SAAK,QAAQ;AACb,SAAK,WAAW,aAAa,KAAK;AAClC,SAAK,cAAc,IAAI,YAAY,iBAAiB,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,UAAU,KAAK,CAAC,CAAC;AAAA,EAC3G;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/base/FieldElement.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { ImpaktElement } from './ImpaktElement';\nimport { focusRing, visuallyHidden } from './styles';\nimport { fontSize, fontWeight, lineHeight, space, t } from './tokens';\n\n/**\n * The shared anatomy of a form control: a label, an optional description, a\n * control, and an error.\n *\n * This exists because the ARIA wiring between those four is where accessible\n * forms actually fail, and it fails the same way every time — a description\n * that is never announced, an error that appears silently, a label that points\n * at nothing. Written once, it is right once.\n *\n * Everything is rendered inside this component's own shadow root, including\n * the native control. That is not an implementation detail: `aria-describedby`\n * cannot cross a shadow boundary, so a component that slotted the input from\n * outside could not describe it. Keeping the whole relationship in one tree is\n * what makes the wiring work at all.\n */\n/**\n * How wide a single-line control is, from what it holds: a postcode is short,\n * an email address is long. A width that matches the answer is a hint about\n * what to type (1.3.5 is about the purpose, this is about the size). Applied by\n * the controls that take a `width`, through `--impakt-field-width`.\n */\nexport const fieldWidths = css`\n :host { --impakt-field-width: 100%; }\n :host([width='xs']) { --impakt-field-width: 8ch; }\n :host([width='sm']) { --impakt-field-width: 14ch; }\n :host([width='md']) { --impakt-field-width: 24ch; }\n :host([width='lg']) { --impakt-field-width: 40ch; }\n`;\n\n/**\n * The base of every form control.\n *\n * @fires {CustomEvent<{ value: string }>} impakt-change - When the answer changes. The answer is in detail.value.\n */\nexport abstract class FieldElement extends ImpaktElement {\n /** Form controls participate in a `<form>` like native ones. */\n static formAssociated = true;\n\n static properties = {\n label: { type: String },\n name: { type: String },\n value: { type: String },\n description: { type: String },\n error: { type: String },\n required: { type: Boolean, reflect: true },\n disabled: { type: Boolean, reflect: true },\n readonly: { type: Boolean, reflect: true },\n requiredText: { type: String, attribute: 'required-text' },\n };\n\n declare label: string;\n declare name: string;\n declare value: string;\n declare description: string;\n declare error: string;\n declare required: boolean;\n declare disabled: boolean;\n declare readonly: boolean;\n /**\n * How \"you must answer this\" is said.\n *\n * Words, not an asterisk. 3.3.2 asks for labels or instructions, and an\n * asterisk is neither until a legend explains it — which puts the\n * explanation somewhere other than the field it explains. It is a property\n * so a partner can reword it, not so they can empty it.\n */\n declare requiredText: string;\n\n protected internals: ElementInternals | null = null;\n\n constructor() {\n super();\n this.label = '';\n this.name = '';\n this.value = '';\n this.description = '';\n this.error = '';\n this.required = false;\n this.disabled = false;\n this.readonly = false;\n this.requiredText = 'required';\n // happy-dom and older engines do not implement attachInternals. A control\n // that cannot associate with a form is still a usable control, so this\n // degrades rather than throwing on construction.\n try {\n this.internals = this.attachInternals();\n } catch {\n this.internals = null;\n }\n }\n\n static styles = [\n ...ImpaktElement.styles,\n focusRing,\n css`\n :host {\n display: block;\n margin-block-end: ${space(4)};\n }\n .label {\n display: block;\n font-size: ${fontSize('sm')};\n font-weight: ${fontWeight('semibold')};\n line-height: ${lineHeight('normal')};\n margin-block-end: ${space(1)};\n color: ${t.text};\n }\n .required {\n font-weight: ${fontWeight('regular')};\n color: ${t.textMuted};\n }\n .description {\n font-size: ${fontSize('sm')};\n line-height: ${lineHeight('normal')};\n color: ${t.textMuted};\n margin-block-end: ${space(2)};\n }\n .error {\n font-size: ${fontSize('sm')};\n line-height: ${lineHeight('normal')};\n color: ${t.dangerText};\n margin-block-start: ${space(1)};\n display: flex;\n gap: ${space(1)};\n }\n .error:empty {\n display: none;\n }\n .visually-hidden {\n ${visuallyHidden}\n }\n /*\n * Only the control is dimmed. Dimming the whole host took the question,\n * the hint and the error below 4.5:1, and a disabled field still has to\n * say what it is and why it cannot be changed. The native disabled\n * control itself is exempt from the contrast criterion.\n */\n :host([disabled]) :is(input, select, textarea, button) {\n opacity: 0.6;\n cursor: not-allowed;\n }\n `,\n ];\n\n protected get controlId(): string {\n return this.id_('control');\n }\n\n /**\n * What the control points `aria-describedby` at.\n *\n * The error id is included only while there is an error. A describedby that\n * always names an empty element trains a screen-reader user to expect\n * nothing after the description, and then the one time it matters they have\n * already learned to ignore it.\n */\n protected get describedBy(): string | typeof nothing {\n const ids = [this.description ? this.id_('description') : '', this.error ? this.id_('error') : ''].filter(Boolean);\n return ids.length ? ids.join(' ') : nothing;\n }\n\n /**\n * Focusing the element focuses its control, so `el.focus()` from an app, a\n * React ref or the error summary's link lands where someone can type, rather\n * than on a host that cannot take focus and so silently does nothing.\n */\n focus(options?: FocusOptions): void {\n const control =\n this.renderRoot?.querySelector<HTMLElement>(`#${this.controlId}`) ?? this.renderRoot?.querySelector<HTMLElement>('input, select, textarea, button');\n if (control) control.focus(options);\n else super.focus(options);\n }\n\n /** Subclasses render the control itself; everything round it is here. */\n protected abstract renderControl(): TemplateResult;\n\n /**\n * `<label for>` by default. A group of controls — radios, checkboxes —\n * cannot use one, because `for` names a single control, so those override\n * this and render a `<fieldset>` and `<legend>` instead.\n */\n protected renderLabel(): TemplateResult {\n return html`\n <label class=\"label\" for=${this.controlId} part=\"label\">\n ${this.label}${this.required ? html`<span class=\"required\"> (${this.requiredText})</span>` : nothing}\n </label>\n `;\n }\n\n render(): TemplateResult {\n return html`\n ${this.renderLabel()}\n ${\n this.description\n ? html`<div class=\"description\" id=${this.id_('description')} part=\"description\">\n ${this.description}\n </div>`\n : nothing\n }\n ${this.renderControl()}\n <!--\n The error region is always present, even when empty. A live region\n inserted at the same moment as its content is announced unreliably\n across screen readers; one that already exists and is then filled is\n announced consistently. \"polite\" rather than \"assertive\" because a\n validation message should not interrupt what is being read.\n -->\n <div\n class=\"error\"\n id=${this.id_('error')}\n part=\"error\"\n aria-live=\"polite\"\n >\n ${this.error || nothing}\n </div>\n `;\n }\n\n /** Keep the form value in step with the control. */\n protected setFormValue(value: string): void {\n this.value = value;\n this.internals?.setFormValue(value);\n this.dispatchEvent(new CustomEvent('impakt-change', { detail: this.changeDetail(value), bubbles: true, composed: true }));\n }\n\n /** What `impakt-change` carries. A control with more to say than its value adds it here. */\n protected changeDetail(value: string): { value: string } {\n return { value };\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,MAAM,KAAK,eAAoC;AA0BjD,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAapB,IAAe,eAAf,cAAoC,cAAc;AAAA,EAoCvD,cAAc;AACZ,UAAM;AAHR,SAAU,YAAqC;AAI7C,SAAK,QAAQ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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAUf,KAAK,IAAI,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA,UAIpB,KAAK,SAAS,OAAO;AAAA;AAAA;AAAA,EAG7B;AAAA;AAAA,EAGU,aAAa,OAAqB;AAC1C,SAAK,QAAQ;AACb,SAAK,WAAW,aAAa,KAAK;AAClC,SAAK,cAAc,IAAI,YAAY,iBAAiB,EAAE,QAAQ,KAAK,aAAa,KAAK,GAAG,SAAS,MAAM,UAAU,KAAK,CAAC,CAAC;AAAA,EAC1H;AAAA;AAAA,EAGU,aAAa,OAAkC;AACvD,WAAO,EAAE,MAAM;AAAA,EACjB;AACF;","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
space,
|
|
7
7
|
t,
|
|
8
8
|
visuallyHidden
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-V7EB7Q2M.js";
|
|
10
10
|
|
|
11
11
|
// packages/ui/src/components/progress.ts
|
|
12
12
|
import { html, css, nothing } from "lit";
|
|
@@ -16,7 +16,8 @@ var ImpaktProgress = class extends ImpaktElement {
|
|
|
16
16
|
steps: { type: Array },
|
|
17
17
|
current: { type: String },
|
|
18
18
|
label: { type: String },
|
|
19
|
-
look: { type: String, reflect: true }
|
|
19
|
+
look: { type: String, reflect: true },
|
|
20
|
+
hideLabels: { type: Boolean, attribute: "hide-labels", reflect: true }
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
constructor() {
|
|
@@ -25,6 +26,7 @@ var ImpaktProgress = class extends ImpaktElement {
|
|
|
25
26
|
this.current = "";
|
|
26
27
|
this.label = "Progress";
|
|
27
28
|
this.look = "steps";
|
|
29
|
+
this.hideLabels = false;
|
|
28
30
|
}
|
|
29
31
|
static {
|
|
30
32
|
this.styles = [
|
|
@@ -95,11 +97,14 @@ var ImpaktProgress = class extends ImpaktElement {
|
|
|
95
97
|
:host([look='bars']) li::before { background: GrayText; }
|
|
96
98
|
:host([look='bars']) li[data-state='done']::before, :host([look='bars']) li[data-state='current']::before { background: CanvasText; }
|
|
97
99
|
}
|
|
100
|
+
:host([hide-labels]) .name {
|
|
101
|
+
${visuallyHidden}
|
|
102
|
+
}
|
|
98
103
|
/* Below 30rem the labels stop fitting; the position in words is the part
|
|
99
104
|
that has to survive, so the list collapses to bars and the current
|
|
100
105
|
step's name. */
|
|
101
106
|
@media (max-width: 30rem) {
|
|
102
|
-
li:not([data-state='current'])
|
|
107
|
+
li:not([data-state='current']) .name {
|
|
103
108
|
${visuallyHidden}
|
|
104
109
|
}
|
|
105
110
|
}
|
|
@@ -114,9 +119,9 @@ var ImpaktProgress = class extends ImpaktElement {
|
|
|
114
119
|
${this.steps.map((step, i) => {
|
|
115
120
|
const state = i < index ? "done" : i === index ? "current" : "todo";
|
|
116
121
|
return html`
|
|
117
|
-
<li data-state=${state} aria-current=${state === "current" ? "step" : nothing}>
|
|
122
|
+
<li part="step step-${state}" data-state=${state} aria-current=${state === "current" ? "step" : nothing}>
|
|
118
123
|
${state === "current" ? html`<span class="sr-only">${say("Step {step} of {steps}:", { step: i + 1, steps: this.steps.length })} </span>` : nothing}
|
|
119
|
-
<span>${step.label}</span>
|
|
124
|
+
<span class="name" part="step-label">${step.label}</span>
|
|
120
125
|
</li>
|
|
121
126
|
`;
|
|
122
127
|
})}
|
|
@@ -130,4 +135,4 @@ customElements.define("impakt-progress", ImpaktProgress);
|
|
|
130
135
|
export {
|
|
131
136
|
ImpaktProgress
|
|
132
137
|
};
|
|
133
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-OZGKK3N5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/progress.ts"],"sourcesContent":["import { html, css, nothing, type TemplateResult } from 'lit';\nimport { say } from '../base/say';\nimport { ImpaktElement } from '../base/ImpaktElement';\nimport { visuallyHidden } from '../base/styles';\nimport { fontSize, fontWeight, space, t } from '../base/tokens';\n\nexport interface ProgressStep {\n id: string;\n label: string;\n}\n\n/**\n * Where the customer is in a journey.\n *\n * **It is not a `progressbar`.** That role is for a task completing — a file\n * uploading, a price calculating — and it carries `aria-valuenow`. A journey\n * indicator is navigation: an ordered list of named steps with\n * `aria-current=\"step\"` on the one you are on. Using `progressbar` here\n * announces a percentage and loses the step names, which are the only useful\n * part.\n *\n * **The position is said in words.** \"Step 2 of 5\" is visually hidden and read\n * aloud, because the visual design communicates position through colour and a\n * filled bar, and neither is available to a screen-reader user — nor to anyone\n * who cannot distinguish the filled colour from the empty one, which is 1.4.1.\n\n *\n * @category content\n * @icon progress\n */\nexport class ImpaktProgress extends ImpaktElement {\n static properties = {\n steps: { type: Array },\n current: { type: String },\n label: { type: String },\n look: { type: String, reflect: true },\n hideLabels: { type: Boolean, attribute: 'hide-labels', reflect: true },\n };\n\n declare steps: ProgressStep[];\n /** The id of the step being shown. */\n declare current: string;\n declare label: string;\n /**\n * `steps` is the full indicator. `bars` is a compact one for a card: short\n * rounded bars, the done steps in the text colour and the current one in the\n * brand, with small names under them. The current step is also set in a\n * heavier weight, so it does not rest on colour alone.\n */\n declare look: 'steps' | 'bars';\n /**\n * Draw the bars or steps alone, for a card too small for the names. The\n * names and \"Step 2 of 5\" are still read aloud. Each step is also a `step`\n * part, with `step-done`, `step-current` or `step-todo`, and its name is the\n * `step-label` part, for finer styling.\n */\n declare hideLabels: boolean;\n\n constructor() {\n super();\n this.steps = [];\n this.current = '';\n this.label = 'Progress';\n this.look = 'steps';\n this.hideLabels = false;\n }\n\n static styles = [\n ...ImpaktElement.styles,\n css`\n :host {\n display: block;\n margin-block-end: ${space(5)};\n }\n ol {\n display: flex;\n gap: ${space(2)};\n list-style: none;\n margin: 0;\n padding: 0;\n }\n li {\n flex: 1;\n font-size: ${fontSize('sm')};\n color: ${t.textMuted};\n padding-block-start: ${space(2)};\n border-block-start: 4px solid ${t.border};\n }\n li[data-state='done'] {\n color: ${t.text};\n border-block-start-color: ${t.brand};\n }\n li[data-state='current'] {\n color: ${t.text};\n font-weight: ${fontWeight('semibold')};\n border-block-start-color: ${t.brand};\n }\n .sr-only {\n ${visuallyHidden}\n }\n :host([look='bars']) {\n margin-block-end: 0;\n }\n :host([look='bars']) ol {\n gap: ${space(1.5)};\n }\n :host([look='bars']) li {\n position: relative;\n padding-block-start: ${space(3)};\n border: 0;\n font-size: 12px;\n min-inline-size: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n :host([look='bars']) li::before {\n content: '';\n position: absolute;\n inset-inline: 0;\n inset-block-start: 0;\n block-size: 5px;\n border-radius: 999px;\n background: ${t.border};\n }\n :host([look='bars']) li[data-state='done']::before {\n background: ${t.text};\n }\n :host([look='bars']) li[data-state='current']::before {\n background: ${t.brand};\n }\n @media (forced-colors: active) {\n :host([look='bars']) li::before { background: GrayText; }\n :host([look='bars']) li[data-state='done']::before, :host([look='bars']) li[data-state='current']::before { background: CanvasText; }\n }\n :host([hide-labels]) .name {\n ${visuallyHidden}\n }\n /* Below 30rem the labels stop fitting; the position in words is the part\n that has to survive, so the list collapses to bars and the current\n step's name. */\n @media (max-width: 30rem) {\n li:not([data-state='current']) .name {\n ${visuallyHidden}\n }\n }\n `,\n ];\n\n render(): TemplateResult {\n const index = this.steps.findIndex((s) => s.id === this.current);\n return html`\n <nav part=\"nav\" aria-label=${this.label}>\n <ol part=\"list\">\n ${this.steps.map((step, i) => {\n const state = i < index ? 'done' : i === index ? 'current' : 'todo';\n return html`\n <li part=\"step step-${state}\" data-state=${state} aria-current=${state === 'current' ? 'step' : nothing}>\n ${\n state === 'current'\n ? html`<span class=\"sr-only\">${say('Step {step} of {steps}:', { step: i + 1, steps: this.steps.length })} </span>`\n : nothing\n }\n <span class=\"name\" part=\"step-label\">${step.label}</span>\n </li>\n `;\n })}\n </ol>\n </nav>\n `;\n }\n}\n\ncustomElements.define('impakt-progress', ImpaktProgress);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'impakt-progress': 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