@xerios/design-system 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +403 -2
- package/dist/components/AnchorHeading.svelte +79 -0
- package/dist/components/AnchorHeading.svelte.d.ts +28 -0
- package/dist/components/Breadcrumbs.svelte +216 -0
- package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
- package/dist/components/Button.svelte +178 -0
- package/dist/components/Button.svelte.d.ts +58 -0
- package/dist/components/Canvas.svelte +248 -0
- package/dist/components/Canvas.svelte.d.ts +91 -0
- package/dist/components/Collapsible.svelte +139 -0
- package/dist/components/Collapsible.svelte.d.ts +52 -0
- package/dist/components/CollapsibleAdvanced.svelte +174 -0
- package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
- package/dist/components/DashOutline.svelte +47 -0
- package/dist/components/DashOutline.svelte.d.ts +6 -0
- package/dist/components/Dialogs.svelte +123 -0
- package/dist/components/Dialogs.svelte.d.ts +6 -0
- package/dist/components/Drawer.svelte +231 -0
- package/dist/components/Drawer.svelte.d.ts +62 -0
- package/dist/components/ErrorMessage.svelte +140 -0
- package/dist/components/ErrorMessage.svelte.d.ts +41 -0
- package/dist/components/Icon.svelte +94 -0
- package/dist/components/Icon.svelte.d.ts +33 -0
- package/dist/components/InfoTip.svelte +183 -0
- package/dist/components/InfoTip.svelte.d.ts +28 -0
- package/dist/components/Md.svelte +28 -0
- package/dist/components/Md.svelte.d.ts +11 -0
- package/dist/components/Modal.svelte +91 -0
- package/dist/components/Modal.svelte.d.ts +41 -0
- package/dist/components/Notice.svelte +50 -0
- package/dist/components/Notice.svelte.d.ts +30 -0
- package/dist/components/Popover.svelte +212 -0
- package/dist/components/Popover.svelte.d.ts +70 -0
- package/dist/components/Shimmer.svelte +27 -0
- package/dist/components/Shimmer.svelte.d.ts +22 -0
- package/dist/components/Splitter.svelte +152 -0
- package/dist/components/Splitter.svelte.d.ts +41 -0
- package/dist/components/Table.svelte +448 -0
- package/dist/components/Table.svelte.d.ts +268 -0
- package/dist/components/Toast.svelte +273 -0
- package/dist/components/Toast.svelte.d.ts +31 -0
- package/dist/components/Tooltip.svelte +97 -0
- package/dist/components/Tooltip.svelte.d.ts +19 -0
- package/dist/components/WorkingBorder.svelte +105 -0
- package/dist/components/WorkingBorder.svelte.d.ts +26 -0
- package/dist/components/empty/Empty.svelte +55 -0
- package/dist/components/empty/Empty.svelte.d.ts +39 -0
- package/dist/components/empty/EmptyError.svelte +47 -0
- package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
- package/dist/components/empty/index.d.ts +18 -0
- package/dist/components/empty/index.js +10 -0
- package/dist/components/filters/DateFilter.svelte +59 -0
- package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
- package/dist/components/filters/FilterBar.svelte +342 -0
- package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
- package/dist/components/filters/FilterChip.svelte +235 -0
- package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
- package/dist/components/filters/OptionList.svelte +352 -0
- package/dist/components/filters/OptionList.svelte.d.ts +91 -0
- package/dist/components/filters/Panel.svelte +123 -0
- package/dist/components/filters/Panel.svelte.d.ts +25 -0
- package/dist/components/filters/index.d.ts +288 -0
- package/dist/components/filters/index.js +12 -0
- package/dist/components/icons.d.ts +54 -0
- package/dist/components/icons.js +58 -0
- package/dist/components/inputs/ButtonGroup.svelte +104 -0
- package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
- package/dist/components/inputs/Calendar.svelte +535 -0
- package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
- package/dist/components/inputs/DateField.svelte +247 -0
- package/dist/components/inputs/DateField.svelte.d.ts +74 -0
- package/dist/components/inputs/DateInput.svelte +118 -0
- package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
- package/dist/components/inputs/DatePicker.svelte +102 -0
- package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
- package/dist/components/inputs/DateRangePicker.svelte +208 -0
- package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
- package/dist/components/inputs/DateRangeSelect.svelte +548 -0
- package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
- package/dist/components/inputs/FieldLabel.svelte +43 -0
- package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
- package/dist/components/inputs/ListSearch.svelte +142 -0
- package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
- package/dist/components/inputs/RadioGroup.svelte +153 -0
- package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
- package/dist/components/inputs/RangeShortcuts.svelte +90 -0
- package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
- package/dist/components/inputs/RangeSlider.svelte +225 -0
- package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
- package/dist/components/inputs/SearchField.svelte +24 -0
- package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
- package/dist/components/inputs/Segmented.svelte +76 -0
- package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
- package/dist/components/inputs/Select.svelte +552 -0
- package/dist/components/inputs/Select.svelte.d.ts +100 -0
- package/dist/components/inputs/Slider.svelte +177 -0
- package/dist/components/inputs/Slider.svelte.d.ts +33 -0
- package/dist/components/inputs/SliderTicks.svelte +62 -0
- package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
- package/dist/components/inputs/Switch.svelte +120 -0
- package/dist/components/inputs/Switch.svelte.d.ts +31 -0
- package/dist/components/inputs/TagInput.svelte +296 -0
- package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
- package/dist/components/inputs/TextArea.svelte +86 -0
- package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
- package/dist/components/inputs/TextField.svelte +170 -0
- package/dist/components/inputs/TextField.svelte.d.ts +80 -0
- package/dist/components/menu/ContextMenu.svelte +25 -0
- package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
- package/dist/components/menu/MenuButton.svelte +46 -0
- package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
- package/dist/components/menu/MenuList.svelte +319 -0
- package/dist/components/menu/MenuList.svelte.d.ts +30 -0
- package/dist/components/metadata/Metadata.svelte +38 -0
- package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
- package/dist/components/metadata/MetadataRow.svelte +84 -0
- package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
- package/dist/components/metadata/index.d.ts +8 -0
- package/dist/components/metadata/index.js +13 -0
- package/dist/components/side-menu/SideMenu.svelte +138 -0
- package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
- package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
- package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
- package/dist/components/side-menu/SideMenuItem.svelte +221 -0
- package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
- package/dist/components/side-menu/context.d.ts +1 -0
- package/dist/components/side-menu/context.js +3 -0
- package/dist/components/side-menu/index.d.ts +62 -0
- package/dist/components/side-menu/index.js +15 -0
- package/dist/components/tiles/Tile.svelte +419 -0
- package/dist/components/tiles/Tile.svelte.d.ts +58 -0
- package/dist/components/tiles/TileGroup.svelte +135 -0
- package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
- package/dist/components/tiles/context.d.ts +35 -0
- package/dist/components/tiles/context.js +14 -0
- package/dist/components/tiles/index.d.ts +6 -0
- package/dist/components/tiles/index.js +13 -0
- package/dist/components/upload/FileCard.svelte +301 -0
- package/dist/components/upload/FileCard.svelte.d.ts +127 -0
- package/dist/components/upload/Thumb.svelte +274 -0
- package/dist/components/upload/Thumb.svelte.d.ts +101 -0
- package/dist/components/upload/UploadFile.svelte +123 -0
- package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
- package/dist/components/upload/UploadFiles.svelte +177 -0
- package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
- package/dist/components/upload/UploadFolder.svelte +153 -0
- package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
- package/dist/components/upload/UploadImage.svelte +137 -0
- package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
- package/dist/components/upload/UploadImages.svelte +172 -0
- package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
- package/dist/components/upload/UploadZone.svelte +130 -0
- package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
- package/dist/components/upload/common.d.ts +31 -0
- package/dist/components/upload/common.js +103 -0
- package/dist/components/upload/context.d.ts +18 -0
- package/dist/components/upload/context.js +10 -0
- package/dist/components/upload/index.d.ts +16 -0
- package/dist/components/upload/index.js +18 -0
- package/dist/css/atoms.css +892 -0
- package/dist/css/base.css +333 -0
- package/dist/css/effects.css +430 -0
- package/dist/css/index.css +10 -0
- package/dist/css/tokens.css +296 -0
- package/dist/fonts.d.ts +1 -0
- package/dist/fonts.js +7 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +77 -0
- package/dist/lib/announce.d.ts +8 -0
- package/dist/lib/announce.js +48 -0
- package/dist/lib/controls.d.ts +10 -0
- package/dist/lib/controls.js +42 -0
- package/dist/lib/dates.d.ts +104 -0
- package/dist/lib/dates.js +235 -0
- package/dist/lib/dialogs.svelte.d.ts +8 -0
- package/dist/lib/dialogs.svelte.js +45 -0
- package/dist/lib/dom.d.ts +34 -0
- package/dist/lib/dom.js +90 -0
- package/dist/lib/field-errors.svelte.d.ts +40 -0
- package/dist/lib/field-errors.svelte.js +89 -0
- package/dist/lib/files.d.ts +74 -0
- package/dist/lib/files.js +215 -0
- package/dist/lib/inline-md.d.ts +1 -0
- package/dist/lib/inline-md.js +36 -0
- package/dist/lib/invalid.d.ts +4 -0
- package/dist/lib/invalid.js +35 -0
- package/dist/lib/list-search.d.ts +9 -0
- package/dist/lib/list-search.js +27 -0
- package/dist/lib/menu.svelte.d.ts +39 -0
- package/dist/lib/menu.svelte.js +98 -0
- package/dist/lib/morph.svelte.d.ts +17 -0
- package/dist/lib/morph.svelte.js +46 -0
- package/dist/lib/motion.d.ts +115 -0
- package/dist/lib/motion.js +174 -0
- package/dist/lib/observe.d.ts +36 -0
- package/dist/lib/observe.js +142 -0
- package/dist/lib/reveal.d.ts +7 -0
- package/dist/lib/reveal.js +28 -0
- package/dist/lib/roving.d.ts +16 -0
- package/dist/lib/roving.js +35 -0
- package/dist/lib/runs.d.ts +18 -0
- package/dist/lib/runs.js +25 -0
- package/dist/lib/scroll-fade.d.ts +4 -0
- package/dist/lib/scroll-fade.js +71 -0
- package/dist/lib/spotlight.d.ts +4 -0
- package/dist/lib/spotlight.js +109 -0
- package/dist/lib/ticks.d.ts +12 -0
- package/dist/lib/ticks.js +24 -0
- package/dist/lib/tooltip.d.ts +4 -0
- package/dist/lib/tooltip.js +110 -0
- package/dist/lib/validity.d.ts +16 -0
- package/dist/lib/validity.js +36 -0
- package/package.json +69 -3
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Data table in a lit card: sortable columns, optional groups shown as collapsible row sections, a sticky header, and
|
|
4
|
+
* an optional row menu (right-click plus a visible ⋯ button in a trailing column). It scrolls inside its own box both
|
|
5
|
+
* ways, so in a parent of limited height (a flex column) the header stays in view and the horizontal scrollbar too.
|
|
6
|
+
*
|
|
7
|
+
* <Table columns={cols} rows={people} key={(p) => p.id} label="People" />
|
|
8
|
+
*
|
|
9
|
+
* <Table columns={cols} groups={teams} key={(p) => p.id} bind:sort rowMenu={menuFor} rowLabel={(p) => p.name}>
|
|
10
|
+
* {#snippet cell(person, col)}
|
|
11
|
+
* {#if col.key === 'name'}<a href="/people/{person.id}">{person.name}</a>{:else}{col.value?.(person)}{/if}
|
|
12
|
+
* {/snippet}
|
|
13
|
+
* </Table>
|
|
14
|
+
*
|
|
15
|
+
* Props:
|
|
16
|
+
* - `columns`: [{ key, label, title?, value?, sortValue?, desc?, num?, center?, shrink?, header?, hideLabel? }]
|
|
17
|
+
* `value(row)`: the cell's text when there is no `cell` snippet. `sortValue(row)`: a comparable value; the column is
|
|
18
|
+
* sortable only with it. `desc`: the first click sorts descending (the default for `num` columns). `num`: right-
|
|
19
|
+
* aligned tabular figures. `center`: centred. `shrink`: as narrow as its content. `header`: the cell is the row's
|
|
20
|
+
* header (<th scope="row">), normally the name column. `hideLabel`: the label is for screen readers only.
|
|
21
|
+
* `title`: a longer name for the sort tooltip.
|
|
22
|
+
* - `rows`: the rows, for a table without groups. Or
|
|
23
|
+
* - `groups`: [{ key, label, rows, sub?, tone?, info? }], each a collapsible section with a header row showing its row
|
|
24
|
+
* count. `tone` puts a coloured dot before the label (any `data-tone`); `info` is InfoTip lines about the group.
|
|
25
|
+
* - `key(row)`: a unique id per row. It also lands on the row as `data-row`, so an app can find it again.
|
|
26
|
+
* - `cell`: snippet (row, column) drawing a cell's content. Without it a cell shows `column.value(row)`.
|
|
27
|
+
* - `sort` (bindable): { key, dir } with dir 1 ascending or -1 descending; null keeps the given order. Equal values
|
|
28
|
+
* keep their given order too.
|
|
29
|
+
* - `collapsed` (bindable): keys of the closed groups.
|
|
30
|
+
* - `selected`, `onselect(row)`: with `onselect`, rows are focusable and Enter, Space or a click selects one;
|
|
31
|
+
* `selected` is the key of the one to highlight. Leave both out when rows hold their own links and buttons.
|
|
32
|
+
* - `rowMenu(row)`: context menu items for a row (see contextMenu), with a ⋯ button in a last column. `rowLabel(row)`
|
|
33
|
+
* names the row for both.
|
|
34
|
+
* - `label`: the table's accessible name. `emptyGroup`: the text in an open group with no rows.
|
|
35
|
+
*
|
|
36
|
+
* Keyboard: the sort and group buttons are ordinary buttons. Selectable rows take Tab, Enter and Space. Shift+F10 or
|
|
37
|
+
* the Menu key opens a row's menu, as does its ⋯ button.
|
|
38
|
+
*/
|
|
39
|
+
import Icon from './Icon.svelte'
|
|
40
|
+
import InfoTip from './InfoTip.svelte'
|
|
41
|
+
import MenuButton from './menu/MenuButton.svelte'
|
|
42
|
+
import { contextMenu } from '../lib/menu.svelte.js'
|
|
43
|
+
import { announce } from '../lib/announce.js'
|
|
44
|
+
import { scrollFade } from '../lib/scroll-fade.js'
|
|
45
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} Column
|
|
49
|
+
* @property {string} key
|
|
50
|
+
* @property {string} label
|
|
51
|
+
* @property {string} [title] names the column in its sort tooltip when `label` is terse
|
|
52
|
+
* @property {boolean} [hideLabel]
|
|
53
|
+
* @property {boolean} [header] cells are row headers (<th scope="row">)
|
|
54
|
+
* @property {boolean} [num]
|
|
55
|
+
* @property {boolean} [center]
|
|
56
|
+
* @property {boolean} [shrink]
|
|
57
|
+
* @property {boolean} [desc] sorts descending first
|
|
58
|
+
* @property {(row: any) => string | number} [sortValue] makes the column sortable
|
|
59
|
+
* @property {(row: any) => unknown} [value] the cell's text when there is no `cell` snippet
|
|
60
|
+
*
|
|
61
|
+
* @typedef {object} Group
|
|
62
|
+
* @property {string} key
|
|
63
|
+
* @property {string} label
|
|
64
|
+
* @property {any[]} rows
|
|
65
|
+
* @property {string} [sub]
|
|
66
|
+
* @property {string} [tone]
|
|
67
|
+
* @property {{ label?: string, text: string }[]} [info]
|
|
68
|
+
*
|
|
69
|
+
* @typedef {object} Props
|
|
70
|
+
* @property {Column[]} columns
|
|
71
|
+
* @property {any[]} [rows]
|
|
72
|
+
* @property {Group[] | null} [groups]
|
|
73
|
+
* @property {(row: any) => string | number} key
|
|
74
|
+
* @property {import('svelte').Snippet<[any, Column]>} [cell]
|
|
75
|
+
* @property {{ key: string, dir: number } | null} [sort] bindable
|
|
76
|
+
* @property {string[]} [collapsed] bindable
|
|
77
|
+
* @property {string | number | null} [selected]
|
|
78
|
+
* @property {(row: any) => void} [onselect]
|
|
79
|
+
* @property {(row: any) => import('../lib/menu.svelte.js').MenuItem[]} [rowMenu]
|
|
80
|
+
* @property {(row: any) => string} [rowLabel]
|
|
81
|
+
* @property {string} [label]
|
|
82
|
+
* @property {string} [emptyGroup]
|
|
83
|
+
*/
|
|
84
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
|
|
85
|
+
let {
|
|
86
|
+
columns,
|
|
87
|
+
rows = [],
|
|
88
|
+
groups = null,
|
|
89
|
+
key,
|
|
90
|
+
cell = undefined,
|
|
91
|
+
sort = $bindable(null),
|
|
92
|
+
collapsed = $bindable([]),
|
|
93
|
+
selected = null,
|
|
94
|
+
onselect = undefined,
|
|
95
|
+
rowMenu = undefined,
|
|
96
|
+
rowLabel = (row) => String(key(row)),
|
|
97
|
+
label = undefined,
|
|
98
|
+
emptyGroup = 'Nothing here.',
|
|
99
|
+
class: className,
|
|
100
|
+
...rest
|
|
101
|
+
} = $props()
|
|
102
|
+
|
|
103
|
+
const grouped = $derived(Boolean(groups))
|
|
104
|
+
const span = $derived(columns.length + (rowMenu ? 1 : 0))
|
|
105
|
+
|
|
106
|
+
const list = $derived(groups ?? [{ key: '', label: '', rows }])
|
|
107
|
+
|
|
108
|
+
// The comparator for the sorted column, or null to keep the given order. toSorted is stable: ties keep their order.
|
|
109
|
+
const compare = $derived.by(() => {
|
|
110
|
+
const column = sort && columns.find((c) => c.key === sort.key && c.sortValue)
|
|
111
|
+
if (!column) return null
|
|
112
|
+
return (a, b) => {
|
|
113
|
+
const x = column.sortValue(a)
|
|
114
|
+
const y = column.sortValue(b)
|
|
115
|
+
const order = typeof x === 'string' && typeof y === 'string' ? collator.compare(x, y) : x < y ? -1 : x > y ? 1 : 0
|
|
116
|
+
return order * sort.dir
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
// Text sorts the way people read it: "app2" before "app10", case and accents aside.
|
|
120
|
+
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
|
121
|
+
const ordered = (items) => (compare ? items.toSorted(compare) : items)
|
|
122
|
+
|
|
123
|
+
function sortBy(column) {
|
|
124
|
+
if (sort?.key === column.key) sort = { key: column.key, dir: -sort.dir }
|
|
125
|
+
else sort = { key: column.key, dir: (column.desc ?? column.num) ? -1 : 1 }
|
|
126
|
+
// The new order is said once (the header's aria-sort isn't reliably read out when it changes under the focus).
|
|
127
|
+
announce(`Sorted by ${(column.title ?? column.label).toLowerCase()}, ${sort.dir > 0 ? 'ascending' : 'descending'}`, { delay: 0 })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const isOpen = (group) => !collapsed.includes(group.key)
|
|
131
|
+
function toggle(group) {
|
|
132
|
+
collapsed = isOpen(group) ? [...collapsed, group.key] : collapsed.filter((k) => k !== group.key)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function rowKeydown(e, row) {
|
|
136
|
+
if (e.target !== e.currentTarget || (e.key !== 'Enter' && e.key !== ' ')) return
|
|
137
|
+
e.preventDefault()
|
|
138
|
+
onselect(row)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// A no-op attachment for rows without a menu, so the markup needs no branch.
|
|
142
|
+
const noMenu = () => {}
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<div class={['table-card', className]} {...rest}>
|
|
146
|
+
<div class="table-scroll" {@attach scrollFade()}>
|
|
147
|
+
<table aria-label={label}>
|
|
148
|
+
<thead>
|
|
149
|
+
<tr>
|
|
150
|
+
{#each columns as column (column.key)}
|
|
151
|
+
{@const active = sort?.key === column.key && column.sortValue}
|
|
152
|
+
<th
|
|
153
|
+
scope="col"
|
|
154
|
+
class:num={column.num}
|
|
155
|
+
class:center={column.center}
|
|
156
|
+
class:shrink={column.shrink}
|
|
157
|
+
aria-sort={active ? (sort.dir > 0 ? 'ascending' : 'descending') : undefined}
|
|
158
|
+
>
|
|
159
|
+
{#if column.sortValue}
|
|
160
|
+
<button type="button" class="sort" {@attach tooltip(`Sort by ${(column.title ?? column.label).toLowerCase()}`)} onclick={() => sortBy(column)}>
|
|
161
|
+
<span class:sr-only={column.hideLabel}>{column.label}</span>
|
|
162
|
+
{#if active}<span class="caret" class:up={sort.dir > 0}><Icon name="caretDown" size="sm" /></span>{/if}
|
|
163
|
+
</button>
|
|
164
|
+
{:else}
|
|
165
|
+
<span class="head" class:sr-only={column.hideLabel}>{column.label}</span>
|
|
166
|
+
{/if}
|
|
167
|
+
</th>
|
|
168
|
+
{/each}
|
|
169
|
+
{#if rowMenu}<th scope="col" class="shrink"><span class="sr-only">Actions</span></th>{/if}
|
|
170
|
+
</tr>
|
|
171
|
+
</thead>
|
|
172
|
+
{#each list as group (group.key)}
|
|
173
|
+
<tbody>
|
|
174
|
+
{#if grouped}
|
|
175
|
+
<tr class="group-row" data-tone={group.tone}>
|
|
176
|
+
<th scope="rowgroup" colspan={span}>
|
|
177
|
+
<div class="group-head">
|
|
178
|
+
<button type="button" aria-expanded={isOpen(group)} onclick={() => toggle(group)}>
|
|
179
|
+
<span class="chev" class:open={isOpen(group)}><Icon name="caretRight" size="sm" /></span>
|
|
180
|
+
{#if group.tone}<span class="swatch" aria-hidden="true"></span>{/if}
|
|
181
|
+
<span class="group-label">{group.label}</span>
|
|
182
|
+
{#if group.sub}<span class="group-sub">{group.sub}</span>{/if}
|
|
183
|
+
</button>
|
|
184
|
+
{#if group.info?.length}<InfoTip pinnable label="About {group.label}" lines={group.info} />{/if}
|
|
185
|
+
<span class="group-count">{group.rows.length}</span>
|
|
186
|
+
</div>
|
|
187
|
+
</th>
|
|
188
|
+
</tr>
|
|
189
|
+
{/if}
|
|
190
|
+
{#if !grouped || isOpen(group)}
|
|
191
|
+
{#each ordered(group.rows) as row (key(row))}
|
|
192
|
+
{@const id = key(row)}
|
|
193
|
+
<tr
|
|
194
|
+
data-row={id}
|
|
195
|
+
class:selectable={onselect}
|
|
196
|
+
class:is-selected={onselect && id === selected}
|
|
197
|
+
tabindex={onselect ? 0 : undefined}
|
|
198
|
+
aria-selected={onselect ? id === selected : undefined}
|
|
199
|
+
onclick={onselect ? () => onselect(row) : undefined}
|
|
200
|
+
onkeydown={onselect ? (e) => rowKeydown(e, row) : undefined}
|
|
201
|
+
{@attach rowMenu ? contextMenu(() => rowMenu(row), rowLabel(row)) : noMenu}
|
|
202
|
+
>
|
|
203
|
+
{#each columns as column (column.key)}
|
|
204
|
+
<svelte:element
|
|
205
|
+
this={column.header ? 'th' : 'td'}
|
|
206
|
+
scope={column.header ? 'row' : undefined}
|
|
207
|
+
class:num={column.num}
|
|
208
|
+
class:center={column.center}
|
|
209
|
+
class:shrink={column.shrink}
|
|
210
|
+
class:row-head={column.header}
|
|
211
|
+
>
|
|
212
|
+
{#if cell}{@render cell(row, column)}{:else}{column.value?.(row) ?? ''}{/if}
|
|
213
|
+
</svelte:element>
|
|
214
|
+
{/each}
|
|
215
|
+
{#if rowMenu}<td class="shrink actions"><MenuButton items={() => rowMenu(row)} label={rowLabel(row)} /></td>{/if}
|
|
216
|
+
</tr>
|
|
217
|
+
{:else}
|
|
218
|
+
{#if grouped}
|
|
219
|
+
<tr class="empty-row"><td colspan={span} class="muted small">{emptyGroup}</td></tr>
|
|
220
|
+
{/if}
|
|
221
|
+
{/each}
|
|
222
|
+
{/if}
|
|
223
|
+
</tbody>
|
|
224
|
+
{/each}
|
|
225
|
+
</table>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
<style>
|
|
230
|
+
/* The card is the outer box; the scroller inside it carries the fade, so the card's own edge stays solid. */
|
|
231
|
+
.table-card {
|
|
232
|
+
flex: 0 1 auto;
|
|
233
|
+
display: flex;
|
|
234
|
+
flex-direction: column;
|
|
235
|
+
min-height: 0;
|
|
236
|
+
overflow: clip;
|
|
237
|
+
border: 1px solid transparent;
|
|
238
|
+
border-radius: var(--r-lg);
|
|
239
|
+
background:
|
|
240
|
+
linear-gradient(var(--surface), var(--surface)) padding-box,
|
|
241
|
+
var(--edge-grad);
|
|
242
|
+
box-shadow: var(--edge-shadow);
|
|
243
|
+
}
|
|
244
|
+
/* Positioned, so visually hidden labels inside it scroll with it and cannot widen the page. scroll-padding-top keeps
|
|
245
|
+
rows scrolled to from under the sticky header (36px and its hairline). */
|
|
246
|
+
.table-scroll {
|
|
247
|
+
position: relative;
|
|
248
|
+
min-height: 0;
|
|
249
|
+
overflow: auto;
|
|
250
|
+
overscroll-behavior-x: contain;
|
|
251
|
+
scroll-padding-top: 37px;
|
|
252
|
+
}
|
|
253
|
+
table {
|
|
254
|
+
width: 100%;
|
|
255
|
+
border-collapse: collapse;
|
|
256
|
+
font-size: 13px;
|
|
257
|
+
color: var(--fg-2);
|
|
258
|
+
}
|
|
259
|
+
th,
|
|
260
|
+
td {
|
|
261
|
+
padding: 8px 12px;
|
|
262
|
+
border-bottom: 1px solid var(--line);
|
|
263
|
+
text-align: left;
|
|
264
|
+
vertical-align: middle;
|
|
265
|
+
font-weight: inherit;
|
|
266
|
+
}
|
|
267
|
+
:is(th, td):first-child {
|
|
268
|
+
padding-left: 16px;
|
|
269
|
+
}
|
|
270
|
+
:is(th, td):last-child {
|
|
271
|
+
padding-right: 16px;
|
|
272
|
+
}
|
|
273
|
+
tbody:last-child tr:last-child :is(th, td) {
|
|
274
|
+
border-bottom: 0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* ----- header ----- */
|
|
278
|
+
thead th {
|
|
279
|
+
position: sticky;
|
|
280
|
+
top: 0;
|
|
281
|
+
z-index: var(--z-sticky);
|
|
282
|
+
height: 36px;
|
|
283
|
+
padding-block: 0;
|
|
284
|
+
background: var(--surface);
|
|
285
|
+
font-size: 12px;
|
|
286
|
+
font-weight: var(--w-medium);
|
|
287
|
+
color: var(--muted);
|
|
288
|
+
white-space: nowrap;
|
|
289
|
+
}
|
|
290
|
+
.sort {
|
|
291
|
+
all: unset;
|
|
292
|
+
display: inline-flex;
|
|
293
|
+
align-items: center;
|
|
294
|
+
gap: var(--space-1);
|
|
295
|
+
min-height: 24px;
|
|
296
|
+
color: var(--muted);
|
|
297
|
+
cursor: pointer;
|
|
298
|
+
white-space: nowrap;
|
|
299
|
+
transition: color var(--dur) var(--ease-out);
|
|
300
|
+
}
|
|
301
|
+
.sort:hover {
|
|
302
|
+
color: var(--fg-2);
|
|
303
|
+
}
|
|
304
|
+
.sort:focus-visible {
|
|
305
|
+
border-radius: var(--r-sm);
|
|
306
|
+
box-shadow: var(--ring);
|
|
307
|
+
}
|
|
308
|
+
th[aria-sort='ascending'] .sort,
|
|
309
|
+
th[aria-sort='descending'] .sort {
|
|
310
|
+
color: var(--fg);
|
|
311
|
+
}
|
|
312
|
+
th.num .sort {
|
|
313
|
+
flex-direction: row-reverse;
|
|
314
|
+
}
|
|
315
|
+
.caret {
|
|
316
|
+
display: inline-flex;
|
|
317
|
+
color: var(--muted);
|
|
318
|
+
}
|
|
319
|
+
.caret.up {
|
|
320
|
+
rotate: 180deg;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/* ----- cells ----- */
|
|
324
|
+
.num {
|
|
325
|
+
text-align: right;
|
|
326
|
+
white-space: nowrap;
|
|
327
|
+
font-family: var(--font-data);
|
|
328
|
+
font-variant-numeric: tabular-nums;
|
|
329
|
+
}
|
|
330
|
+
.center {
|
|
331
|
+
text-align: center;
|
|
332
|
+
}
|
|
333
|
+
.shrink {
|
|
334
|
+
width: 1%;
|
|
335
|
+
white-space: nowrap;
|
|
336
|
+
}
|
|
337
|
+
.row-head {
|
|
338
|
+
color: var(--fg);
|
|
339
|
+
font-weight: var(--w-medium);
|
|
340
|
+
white-space: nowrap;
|
|
341
|
+
}
|
|
342
|
+
.actions {
|
|
343
|
+
padding-block: 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/* ----- rows ----- */
|
|
347
|
+
tbody tr:not(.group-row, .empty-row) {
|
|
348
|
+
transition: background-color var(--dur-fast) var(--ease-out);
|
|
349
|
+
}
|
|
350
|
+
tbody tr:not(.group-row, .empty-row):hover {
|
|
351
|
+
background: var(--fill-2);
|
|
352
|
+
}
|
|
353
|
+
tr.selectable {
|
|
354
|
+
cursor: pointer;
|
|
355
|
+
}
|
|
356
|
+
tr.selectable:focus-visible {
|
|
357
|
+
outline: none;
|
|
358
|
+
box-shadow: inset 0 0 0 2px var(--accent);
|
|
359
|
+
}
|
|
360
|
+
tr.is-selected,
|
|
361
|
+
tr.is-selected:hover {
|
|
362
|
+
background: var(--accent-soft);
|
|
363
|
+
box-shadow: inset 2px 0 0 var(--accent);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/* ----- groups ----- */
|
|
367
|
+
.group-row th {
|
|
368
|
+
padding: 0;
|
|
369
|
+
background: var(--fill-1);
|
|
370
|
+
}
|
|
371
|
+
.group-head {
|
|
372
|
+
position: relative;
|
|
373
|
+
display: flex;
|
|
374
|
+
align-items: center;
|
|
375
|
+
gap: var(--space-1);
|
|
376
|
+
padding-right: 16px;
|
|
377
|
+
transition: background-color var(--dur-fast) var(--ease-out);
|
|
378
|
+
}
|
|
379
|
+
.group-head:hover {
|
|
380
|
+
background: var(--control-2);
|
|
381
|
+
}
|
|
382
|
+
/* The toggle's hit area covers the whole header row; the ⓘ sits above it. */
|
|
383
|
+
.group-head > button {
|
|
384
|
+
all: unset;
|
|
385
|
+
display: flex;
|
|
386
|
+
align-items: center;
|
|
387
|
+
gap: var(--space-2);
|
|
388
|
+
min-width: 0;
|
|
389
|
+
min-height: 24px;
|
|
390
|
+
padding: 8px 12px 8px 16px;
|
|
391
|
+
font-size: 13px;
|
|
392
|
+
color: var(--fg);
|
|
393
|
+
cursor: pointer;
|
|
394
|
+
}
|
|
395
|
+
.group-head > button::after {
|
|
396
|
+
content: '';
|
|
397
|
+
position: absolute;
|
|
398
|
+
inset: 0;
|
|
399
|
+
}
|
|
400
|
+
.group-head > button:focus-visible::after {
|
|
401
|
+
box-shadow: inset 0 0 0 2px var(--accent);
|
|
402
|
+
}
|
|
403
|
+
.group-head > :global(.info) {
|
|
404
|
+
position: relative;
|
|
405
|
+
z-index: 1;
|
|
406
|
+
}
|
|
407
|
+
.chev {
|
|
408
|
+
display: inline-flex;
|
|
409
|
+
color: var(--muted);
|
|
410
|
+
rotate: 0deg;
|
|
411
|
+
transition: rotate var(--dur) var(--ease-out);
|
|
412
|
+
}
|
|
413
|
+
.chev.open {
|
|
414
|
+
rotate: 90deg;
|
|
415
|
+
}
|
|
416
|
+
.swatch {
|
|
417
|
+
width: 8px;
|
|
418
|
+
height: 8px;
|
|
419
|
+
border-radius: 50%;
|
|
420
|
+
background: var(--tone);
|
|
421
|
+
}
|
|
422
|
+
.group-label {
|
|
423
|
+
font-weight: var(--w-medium);
|
|
424
|
+
}
|
|
425
|
+
.group-sub {
|
|
426
|
+
color: var(--muted);
|
|
427
|
+
font-size: 12px;
|
|
428
|
+
}
|
|
429
|
+
.group-count {
|
|
430
|
+
margin-left: auto;
|
|
431
|
+
font: var(--w-medium) 11px var(--font-data);
|
|
432
|
+
font-variant-numeric: tabular-nums;
|
|
433
|
+
color: var(--muted);
|
|
434
|
+
pointer-events: none;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
@media (prefers-reduced-motion: reduce) {
|
|
438
|
+
.chev {
|
|
439
|
+
transition: none;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
@media (pointer: coarse) {
|
|
443
|
+
.sort,
|
|
444
|
+
.group-head > button {
|
|
445
|
+
min-height: 44px;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
</style>
|