@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,79 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A heading with a link to itself: a link glyph after the text, shown while the heading is hovered or the link has
|
|
4
|
+
* focus (always, faintly, on touch screens), that puts the heading's address in the location bar. For long pages and
|
|
5
|
+
* docs, so a reader can share a part of them. Its size comes from where it sits (`.prose`, or the app's own heading
|
|
6
|
+
* styles); it only adds the link.
|
|
7
|
+
*
|
|
8
|
+
* <div class="prose">
|
|
9
|
+
* <AnchorHeading id="install" level={2}>Install</AnchorHeading>
|
|
10
|
+
* </div>
|
|
11
|
+
*
|
|
12
|
+
* level: 1 to 6, the heading's rank (default 2).
|
|
13
|
+
* id: the heading's id, and the fragment the link points to (#id). Unique on the page.
|
|
14
|
+
* label: the link's name and tooltip (default "Link to this section").
|
|
15
|
+
* Children: the heading's text. Other attributes, the class and attachments go to the heading element.
|
|
16
|
+
* Keyboard: the link is in the tab order after the heading's text; Enter follows it.
|
|
17
|
+
*
|
|
18
|
+
* @typedef {object} Props
|
|
19
|
+
* @property {string} id
|
|
20
|
+
* @property {1 | 2 | 3 | 4 | 5 | 6} [level]
|
|
21
|
+
* @property {string} [label]
|
|
22
|
+
* @property {import('svelte').Snippet} children
|
|
23
|
+
*/
|
|
24
|
+
import Icon from './Icon.svelte'
|
|
25
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
26
|
+
|
|
27
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLHeadingElement>, keyof Props>} */
|
|
28
|
+
let { id, level = 2, label = 'Link to this section', children, class: className, ...rest } = $props()
|
|
29
|
+
const tag = $derived(`h${level}`)
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<svelte:element this={tag} {id} class={['anchor-heading', className]} {...rest}
|
|
33
|
+
>{@render children()}<a class="anchor" href="#{id}" aria-label={label} {@attach tooltip(label)}><Icon name="link" size="sm" /></a></svelte:element
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
<style>
|
|
37
|
+
.anchor-heading {
|
|
38
|
+
scroll-margin-top: var(--space-8);
|
|
39
|
+
}
|
|
40
|
+
/* A 24px target that doesn't stretch the line it sits on: its margins take back what it is taller than one line. */
|
|
41
|
+
.anchor {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
width: 24px;
|
|
46
|
+
height: 24px;
|
|
47
|
+
margin-block: calc((1lh - 24px) / 2);
|
|
48
|
+
margin-inline-start: var(--space-1);
|
|
49
|
+
vertical-align: top;
|
|
50
|
+
border-radius: var(--r-sm);
|
|
51
|
+
color: var(--faint);
|
|
52
|
+
opacity: 0;
|
|
53
|
+
transition:
|
|
54
|
+
opacity var(--dur) var(--ease-out),
|
|
55
|
+
color var(--dur) var(--ease-out),
|
|
56
|
+
background-color var(--dur) var(--ease-out);
|
|
57
|
+
}
|
|
58
|
+
.anchor-heading:hover .anchor,
|
|
59
|
+
.anchor:focus-visible {
|
|
60
|
+
opacity: 1;
|
|
61
|
+
}
|
|
62
|
+
.anchor:hover {
|
|
63
|
+
background: var(--control-2);
|
|
64
|
+
color: var(--fg-2);
|
|
65
|
+
}
|
|
66
|
+
@media (hover: none) {
|
|
67
|
+
.anchor {
|
|
68
|
+
opacity: 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/* A finger needs 44px; the margins still keep the line as it was. */
|
|
72
|
+
@media (pointer: coarse) {
|
|
73
|
+
.anchor {
|
|
74
|
+
width: 44px;
|
|
75
|
+
height: 44px;
|
|
76
|
+
margin-block: calc((1lh - 44px) / 2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default AnchorHeading;
|
|
2
|
+
/**
|
|
3
|
+
* A heading with a link to itself: a link glyph after the text, shown while the heading is hovered or the link has
|
|
4
|
+
* focus (always, faintly, on touch screens), that puts the heading's address in the location bar. For long pages and
|
|
5
|
+
* docs, so a reader can share a part of them. Its size comes from where it sits (`.prose`, or the app's own heading
|
|
6
|
+
* styles); it only adds the link.
|
|
7
|
+
*
|
|
8
|
+
* <div class="prose">
|
|
9
|
+
* <AnchorHeading id="install" level={2}>Install</AnchorHeading>
|
|
10
|
+
* </div>
|
|
11
|
+
*
|
|
12
|
+
* level: 1 to 6, the heading's rank (default 2).
|
|
13
|
+
* id: the heading's id, and the fragment the link points to (#id). Unique on the page.
|
|
14
|
+
* label: the link's name and tooltip (default "Link to this section").
|
|
15
|
+
* Children: the heading's text. Other attributes, the class and attachments go to the heading element.
|
|
16
|
+
* Keyboard: the link is in the tab order after the heading's text; Enter follows it.
|
|
17
|
+
*/
|
|
18
|
+
export type Props = {
|
|
19
|
+
id: string;
|
|
20
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
21
|
+
label?: string | undefined;
|
|
22
|
+
children: import("svelte").Snippet;
|
|
23
|
+
};
|
|
24
|
+
type AnchorHeading = {
|
|
25
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
26
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLHeadingElement>, keyof Props>>): void;
|
|
27
|
+
};
|
|
28
|
+
declare const AnchorHeading: import("svelte").Component<Props & Omit<import("svelte/elements").HTMLAttributes<HTMLHeadingElement>, keyof Props>, {}, "">;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Breadcrumbs: the path from the top of a hierarchy down to the page you are on, each level a link back up. Levels
|
|
4
|
+
* are split by a caret; the last one is the current page (aria-current="page"), drawn as plain text in the brighter
|
|
5
|
+
* colour. A long path folds its middle levels behind a "…" button that shows them in place, so the first level and
|
|
6
|
+
* the nearest ones stay in view. A label longer than its room is cut short with an ellipsis and has a tooltip giving
|
|
7
|
+
* it in full.
|
|
8
|
+
*
|
|
9
|
+
* <Breadcrumbs items={[{ label: 'Projects', href: '/projects' }, { label: 'Atlas', href: '/projects/atlas' }, { label: 'Settings' }]} />
|
|
10
|
+
* <Breadcrumbs items={path} max={3} /> first level, "…", then the last two
|
|
11
|
+
* <Breadcrumbs items={[{ label: 'Home', icon: 'house', href: '/' }, …]} /> an icon before a label
|
|
12
|
+
* <Breadcrumbs items={[{ label: 'Inbox', onclick: () => go('inbox') }, …]} /> a button, for navigation without URLs
|
|
13
|
+
*
|
|
14
|
+
* items: the levels, top first. Each has a label, and an href (a link), an onclick (a button, or the link's own
|
|
15
|
+
* handler, for a router), or neither (plain text, for a level with no page of its own); icon: an Icon name before it.
|
|
16
|
+
* current: the last item is the page you are on (default true); false makes it a link like the rest, for a trail
|
|
17
|
+
* that stops at the parent. max: the most levels shown before the middle ones fold (default 4; 0 never folds); the
|
|
18
|
+
* fold opens again when the items change. label: the navigation landmark's name (default "Breadcrumb").
|
|
19
|
+
* Other attributes (class…) and attachments go to the <nav>.
|
|
20
|
+
* Keyboard: each link or button is in the Tab order. "…" shows the folded levels and moves the focus to the first.
|
|
21
|
+
*/
|
|
22
|
+
import { tick } from 'svelte'
|
|
23
|
+
|
|
24
|
+
import Icon from './Icon.svelte'
|
|
25
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
26
|
+
import { observeSize } from '../lib/observe.js'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} Crumb
|
|
30
|
+
* @property {string} label
|
|
31
|
+
* @property {string} [href]
|
|
32
|
+
* @property {string} [icon]
|
|
33
|
+
* @property {(e: MouseEvent) => void} [onclick]
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {object} Props
|
|
37
|
+
* @property {Crumb[]} items
|
|
38
|
+
* @property {boolean} [current]
|
|
39
|
+
* @property {number} [max]
|
|
40
|
+
* @property {string} [label]
|
|
41
|
+
*/
|
|
42
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLElement>, keyof Props>} */
|
|
43
|
+
let { items, current = true, max = 4, label = 'Breadcrumb', class: className, ...rest } = $props()
|
|
44
|
+
|
|
45
|
+
// Shown in full once "…" is pressed; new items fold again.
|
|
46
|
+
let unfolded = $derived.by(() => {
|
|
47
|
+
void items
|
|
48
|
+
return false
|
|
49
|
+
})
|
|
50
|
+
// The first level stays, then the last max - 1; the ones between fold. Folding a single level would save nothing.
|
|
51
|
+
const keep = $derived(Math.max(max, 2) - 1)
|
|
52
|
+
const folds = $derived(max > 0 && !unfolded && items.length - 1 - keep > 1)
|
|
53
|
+
const shown = $derived(folds ? [0, ...items.map((_, i) => i).slice(-keep)] : items.map((_, i) => i))
|
|
54
|
+
|
|
55
|
+
/** @type {HTMLOListElement | undefined} */
|
|
56
|
+
let list = $state()
|
|
57
|
+
|
|
58
|
+
async function unfold() {
|
|
59
|
+
unfolded = true
|
|
60
|
+
await tick()
|
|
61
|
+
list?.querySelectorAll('li')[1]?.querySelector('a, button')?.focus()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Attachment: the tooltip with the whole label, only while the label is cut short.
|
|
66
|
+
* @param {string} text
|
|
67
|
+
* @returns {import('svelte/attachments').Attachment<HTMLElement>}
|
|
68
|
+
*/
|
|
69
|
+
const whole = (text) => (node) => {
|
|
70
|
+
const label = /** @type {HTMLElement | null} */ (node.querySelector('.text'))
|
|
71
|
+
if (!label) return
|
|
72
|
+
/** @type {(() => void) | null} */
|
|
73
|
+
let off = null
|
|
74
|
+
const check = () => {
|
|
75
|
+
const cut = label.scrollWidth > label.clientWidth
|
|
76
|
+
if (cut && !off) off = tooltip(text)(node) ?? (() => {})
|
|
77
|
+
else if (!cut && off) {
|
|
78
|
+
off()
|
|
79
|
+
off = null
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const stop = observeSize(label, check)
|
|
83
|
+
return () => {
|
|
84
|
+
stop()
|
|
85
|
+
off?.()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
{#snippet content(/** @type {Crumb} */ item)}
|
|
91
|
+
{#if item.icon}<Icon name={item.icon} size="sm" />{/if}
|
|
92
|
+
<span class="text">{item.label}</span>
|
|
93
|
+
{/snippet}
|
|
94
|
+
|
|
95
|
+
<nav class={['breadcrumbs', className]} aria-label={label} {...rest}>
|
|
96
|
+
<ol bind:this={list}>
|
|
97
|
+
{#each shown as i, at (i)}
|
|
98
|
+
{@const item = items[i]}
|
|
99
|
+
{@const here = current && i === items.length - 1}
|
|
100
|
+
<li>
|
|
101
|
+
{#if at > 0}<span class="sep"><Icon name="caretRight" size="sm" /></span>{/if}
|
|
102
|
+
{#if here}
|
|
103
|
+
<span class="crumb" aria-current="page" {@attach whole(item.label)}>{@render content(item)}</span>
|
|
104
|
+
{:else if item.href}
|
|
105
|
+
<a class="crumb link" href={item.href} onclick={item.onclick} {@attach whole(item.label)}>{@render content(item)}</a>
|
|
106
|
+
{:else if item.onclick}
|
|
107
|
+
<button type="button" class="crumb link" onclick={item.onclick} {@attach whole(item.label)}>{@render content(item)}</button>
|
|
108
|
+
{:else}
|
|
109
|
+
<span class="crumb" {@attach whole(item.label)}>{@render content(item)}</span>
|
|
110
|
+
{/if}
|
|
111
|
+
</li>
|
|
112
|
+
{#if folds && at === 0}
|
|
113
|
+
<li>
|
|
114
|
+
<span class="sep"><Icon name="caretRight" size="sm" /></span>
|
|
115
|
+
<button type="button" class="crumb link more" aria-label="Show the full path" {@attach tooltip('Show the full path')} onclick={unfold}>
|
|
116
|
+
<Icon name="more" size="sm" />
|
|
117
|
+
</button>
|
|
118
|
+
</li>
|
|
119
|
+
{/if}
|
|
120
|
+
{/each}
|
|
121
|
+
</ol>
|
|
122
|
+
</nav>
|
|
123
|
+
|
|
124
|
+
<style>
|
|
125
|
+
/* Pulled back by the crumbs' padding, so the first label lines up with the content around it. */
|
|
126
|
+
ol {
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-wrap: wrap;
|
|
129
|
+
align-items: center;
|
|
130
|
+
gap: 2px;
|
|
131
|
+
margin: 0;
|
|
132
|
+
margin-inline-start: calc(var(--space-1) * -1);
|
|
133
|
+
padding: 0;
|
|
134
|
+
list-style: none;
|
|
135
|
+
font-size: 13px;
|
|
136
|
+
}
|
|
137
|
+
li {
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
gap: 2px;
|
|
141
|
+
min-width: 0;
|
|
142
|
+
}
|
|
143
|
+
.sep {
|
|
144
|
+
display: inline-flex;
|
|
145
|
+
flex: none;
|
|
146
|
+
color: var(--faint);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.crumb {
|
|
150
|
+
all: unset;
|
|
151
|
+
box-sizing: border-box;
|
|
152
|
+
display: inline-flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
gap: var(--space-1);
|
|
155
|
+
min-width: 0;
|
|
156
|
+
min-height: 24px;
|
|
157
|
+
padding-inline: var(--space-1);
|
|
158
|
+
border-radius: var(--r-sm);
|
|
159
|
+
color: var(--muted);
|
|
160
|
+
font-weight: var(--w-medium);
|
|
161
|
+
text-decoration: none;
|
|
162
|
+
}
|
|
163
|
+
.crumb > :global(.icon) {
|
|
164
|
+
flex: none;
|
|
165
|
+
}
|
|
166
|
+
.text {
|
|
167
|
+
max-inline-size: 200px;
|
|
168
|
+
overflow: clip;
|
|
169
|
+
text-overflow: ellipsis;
|
|
170
|
+
white-space: nowrap;
|
|
171
|
+
}
|
|
172
|
+
.crumb[aria-current] {
|
|
173
|
+
color: var(--fg);
|
|
174
|
+
}
|
|
175
|
+
/* The page you are on may take what room there is. */
|
|
176
|
+
.crumb[aria-current] .text {
|
|
177
|
+
max-inline-size: none;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* A link is readable at rest, as hovering changes only its fill; the page you are on stays the brightest. */
|
|
181
|
+
.link {
|
|
182
|
+
color: var(--fg-2);
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
transition:
|
|
185
|
+
background-color var(--dur) var(--ease-out),
|
|
186
|
+
color var(--dur) var(--ease-out);
|
|
187
|
+
}
|
|
188
|
+
.link:hover {
|
|
189
|
+
background: var(--control-2);
|
|
190
|
+
}
|
|
191
|
+
.link:active {
|
|
192
|
+
background: var(--control-3);
|
|
193
|
+
}
|
|
194
|
+
.link:focus-visible {
|
|
195
|
+
outline: 2px solid var(--accent);
|
|
196
|
+
outline-offset: -2px;
|
|
197
|
+
}
|
|
198
|
+
.more {
|
|
199
|
+
justify-content: center;
|
|
200
|
+
min-width: 24px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@media (max-width: 859px) {
|
|
204
|
+
.text {
|
|
205
|
+
max-inline-size: 120px;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
@media (pointer: coarse) {
|
|
209
|
+
.crumb {
|
|
210
|
+
min-height: 32px;
|
|
211
|
+
}
|
|
212
|
+
.more {
|
|
213
|
+
min-width: 32px;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default Breadcrumbs;
|
|
2
|
+
type Breadcrumbs = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLElement>, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Breadcrumbs: import("svelte").Component<{
|
|
7
|
+
items: {
|
|
8
|
+
label: string;
|
|
9
|
+
href?: string | undefined;
|
|
10
|
+
icon?: string | undefined;
|
|
11
|
+
onclick?: ((e: MouseEvent) => void) | undefined;
|
|
12
|
+
}[];
|
|
13
|
+
current?: boolean | undefined;
|
|
14
|
+
max?: number | undefined;
|
|
15
|
+
label?: string | undefined;
|
|
16
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLElement>, keyof {
|
|
17
|
+
items: {
|
|
18
|
+
label: string;
|
|
19
|
+
href?: string | undefined;
|
|
20
|
+
icon?: string | undefined;
|
|
21
|
+
onclick?: ((e: MouseEvent) => void) | undefined;
|
|
22
|
+
}[];
|
|
23
|
+
current?: boolean | undefined;
|
|
24
|
+
max?: number | undefined;
|
|
25
|
+
label?: string | undefined;
|
|
26
|
+
}>, {}, "">;
|
|
27
|
+
type Props = {
|
|
28
|
+
items: {
|
|
29
|
+
label: string;
|
|
30
|
+
href?: string | undefined;
|
|
31
|
+
icon?: string | undefined;
|
|
32
|
+
onclick?: ((e: MouseEvent) => void) | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
current?: boolean | undefined;
|
|
35
|
+
max?: number | undefined;
|
|
36
|
+
label?: string | undefined;
|
|
37
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* The .btn pill (or an .icon-btn), with an optional icon, that runs an async action and shows how it went.
|
|
4
|
+
*
|
|
5
|
+
* <Button icon="refresh" onclick={() => refreshAll()}>Try again</Button>
|
|
6
|
+
* <Button variant="danger" icon="trash" pendingLabel="Removing…" onclick={remove}>Remove subdomain</Button>
|
|
7
|
+
* <Button iconOnly icon="refresh" label="Refresh" onclick={reload} />
|
|
8
|
+
* <Button type="submit" form="new-site" variant="primary" pending={submitting}>Create</Button>
|
|
9
|
+
* <Button href="/">Go to apps</Button>
|
|
10
|
+
*
|
|
11
|
+
* onclick may return a promise. Until it settles the button is busy, drawn as Select is while loading: it drops its
|
|
12
|
+
* fill (a solid one becomes an outlined pill), the working sweep runs along its edge (.shimmer) and its label shimmers
|
|
13
|
+
* (Shimmer), `pendingLabel` (if given) in its place; an
|
|
14
|
+
* icon-only button shows a spinner instead of its icon. It is aria-busy, and further presses are ignored (a flag, not
|
|
15
|
+
* only the look), so the action can't run twice; the focus stays on it. Under reduced motion the sweep and the spinner
|
|
16
|
+
* hold still, so give a `pendingLabel` where you can: it says what is happening in words. If the promise rejects, the
|
|
17
|
+
* error's message shows in a bubble under
|
|
18
|
+
* the button (read out as an alert, dismissible) until the next press; pass `onerror` to handle it yourself instead.
|
|
19
|
+
* pending: busy from outside, e.g. a form submit button while its form's request runs.
|
|
20
|
+
*
|
|
21
|
+
* variant: secondary (default) | primary | danger. small: the 24px size. icon: an Icon name, before the label.
|
|
22
|
+
* iconOnly: the round .icon-btn showing just the icon; `label` is then required, and becomes its accessible name and
|
|
23
|
+
* its tooltip. href: a link drawn as a button (navigation, never an action). disabled: as on any button.
|
|
24
|
+
* Other attributes (class, form, autofocus…) and attachments go to the <button> (or <a>).
|
|
25
|
+
*/
|
|
26
|
+
import Icon from './Icon.svelte'
|
|
27
|
+
import ErrorMessage from './ErrorMessage.svelte'
|
|
28
|
+
import Shimmer from './Shimmer.svelte'
|
|
29
|
+
import { topLayer } from '../lib/dom.js'
|
|
30
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {object} Props
|
|
34
|
+
* @property {'secondary' | 'primary' | 'danger'} [variant]
|
|
35
|
+
* @property {boolean} [small]
|
|
36
|
+
* @property {string} [icon]
|
|
37
|
+
* @property {boolean} [iconOnly]
|
|
38
|
+
* @property {string} [label] the accessible name and tooltip of an iconOnly button
|
|
39
|
+
* @property {string} [href]
|
|
40
|
+
* @property {'button' | 'submit' | 'reset'} [type]
|
|
41
|
+
* @property {(event: MouseEvent) => unknown} [onclick]
|
|
42
|
+
* @property {boolean} [pending]
|
|
43
|
+
* @property {string} [pendingLabel]
|
|
44
|
+
* @property {(error: unknown) => void} [onerror]
|
|
45
|
+
* @property {boolean} [disabled]
|
|
46
|
+
* @property {import('svelte').Snippet} [children]
|
|
47
|
+
*/
|
|
48
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes & import('svelte/elements').HTMLAnchorAttributes, keyof Props>} */
|
|
49
|
+
let {
|
|
50
|
+
variant = 'secondary',
|
|
51
|
+
small = false,
|
|
52
|
+
icon,
|
|
53
|
+
iconOnly = false,
|
|
54
|
+
label,
|
|
55
|
+
href,
|
|
56
|
+
type = 'button',
|
|
57
|
+
onclick,
|
|
58
|
+
pending = false,
|
|
59
|
+
pendingLabel,
|
|
60
|
+
onerror,
|
|
61
|
+
disabled = false,
|
|
62
|
+
class: className,
|
|
63
|
+
children,
|
|
64
|
+
...rest
|
|
65
|
+
} = $props()
|
|
66
|
+
|
|
67
|
+
const uid = $props.id()
|
|
68
|
+
const anchor = `--button-${uid}`
|
|
69
|
+
/** @type {HTMLButtonElement | undefined} */
|
|
70
|
+
let button = $state()
|
|
71
|
+
let running = $state(false)
|
|
72
|
+
let error = $state('')
|
|
73
|
+
const busy = $derived(pending || running)
|
|
74
|
+
|
|
75
|
+
const classes = $derived([
|
|
76
|
+
iconOnly ? 'icon-btn' : 'btn',
|
|
77
|
+
!iconOnly && variant === 'primary' && 'btn-primary',
|
|
78
|
+
!iconOnly && variant === 'danger' && 'btn-danger',
|
|
79
|
+
!iconOnly && small && 'btn-small',
|
|
80
|
+
busy && 'shimmer',
|
|
81
|
+
className,
|
|
82
|
+
])
|
|
83
|
+
|
|
84
|
+
/** @param {MouseEvent} event */
|
|
85
|
+
async function run(event) {
|
|
86
|
+
if (busy) {
|
|
87
|
+
// A press while busy does nothing, a submit included.
|
|
88
|
+
event.preventDefault()
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
error = ''
|
|
92
|
+
const result = onclick?.(event)
|
|
93
|
+
if (!(result instanceof Promise)) return
|
|
94
|
+
running = true
|
|
95
|
+
try {
|
|
96
|
+
await result
|
|
97
|
+
} catch (failure) {
|
|
98
|
+
if (onerror) onerror(failure)
|
|
99
|
+
else error = failure instanceof Error && failure.message ? failure.message : 'That didn’t work. Try again.'
|
|
100
|
+
} finally {
|
|
101
|
+
running = false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
{#snippet content()}
|
|
107
|
+
{#if busy && iconOnly}<span class="spin"><Icon name="spinner" /></span>{:else if icon}<Icon name={icon} size={iconOnly ? 'md' : 'sm'} />{/if}
|
|
108
|
+
{#if !iconOnly}
|
|
109
|
+
{#if busy}<Shimmer
|
|
110
|
+
>{#if pendingLabel}{pendingLabel}{:else}{@render children?.()}{/if}</Shimmer
|
|
111
|
+
>{:else}{@render children?.()}{/if}
|
|
112
|
+
{/if}
|
|
113
|
+
{/snippet}
|
|
114
|
+
|
|
115
|
+
{#if href}
|
|
116
|
+
<a {href} class={classes} aria-label={iconOnly ? label : undefined} {@attach tooltip(iconOnly ? label : '')} {...rest}>{@render content()}</a>
|
|
117
|
+
{:else}
|
|
118
|
+
<button
|
|
119
|
+
bind:this={button}
|
|
120
|
+
{type}
|
|
121
|
+
class={classes}
|
|
122
|
+
style:anchor-name={anchor}
|
|
123
|
+
{disabled}
|
|
124
|
+
aria-label={iconOnly ? label : undefined}
|
|
125
|
+
aria-busy={busy || undefined}
|
|
126
|
+
aria-disabled={busy || undefined}
|
|
127
|
+
aria-describedby={error ? `${uid}-error` : undefined}
|
|
128
|
+
{@attach tooltip(iconOnly ? label : '')}
|
|
129
|
+
{...rest}
|
|
130
|
+
onclick={run}>{@render content()}</button
|
|
131
|
+
>
|
|
132
|
+
{#if error}
|
|
133
|
+
<!-- Hung under the button in the top layer, so it needs no wrapper around the button and nothing clips it. -->
|
|
134
|
+
<span class="error-host" style:position-anchor={anchor} data-floating {@attach topLayer(button)}>
|
|
135
|
+
<ErrorMessage floating id="{uid}-error" role="alert" message={error} ondismiss={() => ((error = ''), button?.focus())} />
|
|
136
|
+
</span>
|
|
137
|
+
{/if}
|
|
138
|
+
{/if}
|
|
139
|
+
|
|
140
|
+
<style>
|
|
141
|
+
/* While busy the button keeps its place and its focus, but drops its fill, so the sweep along its edge (.shimmer) is
|
|
142
|
+
what you see: an outlined pill with a shimmering label. A solid button (primary, danger) loses its colour with it,
|
|
143
|
+
so it takes the secondary button's text and hairline (its white label would vanish without the fill). The fill eases
|
|
144
|
+
back when the work is done (.btn transitions it). */
|
|
145
|
+
[aria-busy='true'] {
|
|
146
|
+
cursor: progress;
|
|
147
|
+
background: none;
|
|
148
|
+
box-shadow: none;
|
|
149
|
+
filter: none;
|
|
150
|
+
}
|
|
151
|
+
.btn-primary[aria-busy='true'],
|
|
152
|
+
.btn-danger[aria-busy='true'] {
|
|
153
|
+
border-color: var(--line-strong);
|
|
154
|
+
color: var(--fg-2);
|
|
155
|
+
}
|
|
156
|
+
.spin {
|
|
157
|
+
display: inline-flex;
|
|
158
|
+
animation: spin 0.9s linear infinite;
|
|
159
|
+
}
|
|
160
|
+
@keyframes spin {
|
|
161
|
+
to {
|
|
162
|
+
rotate: 1turn;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/* A box just under the button, as wide as the bubble may grow; the bubble (absolutely placed) hangs from it. */
|
|
166
|
+
.error-host {
|
|
167
|
+
position: fixed;
|
|
168
|
+
position-area: block-end span-inline-end;
|
|
169
|
+
position-try-fallbacks: flip-inline;
|
|
170
|
+
width: min(320px, calc(100dvw - 32px));
|
|
171
|
+
height: 0;
|
|
172
|
+
overflow: visible;
|
|
173
|
+
pointer-events: none;
|
|
174
|
+
}
|
|
175
|
+
.error-host > :global(*) {
|
|
176
|
+
pointer-events: auto;
|
|
177
|
+
}
|
|
178
|
+
</style>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export default Button;
|
|
2
|
+
type Button = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLButtonAttributes & HTMLAnchorAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Button: import("svelte").Component<{
|
|
7
|
+
variant?: "secondary" | "primary" | "danger" | undefined;
|
|
8
|
+
small?: boolean | undefined;
|
|
9
|
+
icon?: string | undefined;
|
|
10
|
+
iconOnly?: boolean | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* the accessible name and tooltip of an iconOnly button
|
|
13
|
+
*/
|
|
14
|
+
label?: string | undefined;
|
|
15
|
+
href?: string | undefined;
|
|
16
|
+
type?: "submit" | "reset" | "button" | undefined;
|
|
17
|
+
onclick?: ((event: MouseEvent) => unknown) | undefined;
|
|
18
|
+
pending?: boolean | undefined;
|
|
19
|
+
pendingLabel?: string | undefined;
|
|
20
|
+
onerror?: ((error: unknown) => void) | undefined;
|
|
21
|
+
disabled?: boolean | undefined;
|
|
22
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
23
|
+
} & Omit<import("svelte/elements").HTMLButtonAttributes & import("svelte/elements").HTMLAnchorAttributes, keyof {
|
|
24
|
+
variant?: "secondary" | "primary" | "danger" | undefined;
|
|
25
|
+
small?: boolean | undefined;
|
|
26
|
+
icon?: string | undefined;
|
|
27
|
+
iconOnly?: boolean | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* the accessible name and tooltip of an iconOnly button
|
|
30
|
+
*/
|
|
31
|
+
label?: string | undefined;
|
|
32
|
+
href?: string | undefined;
|
|
33
|
+
type?: "submit" | "reset" | "button" | undefined;
|
|
34
|
+
onclick?: ((event: MouseEvent) => unknown) | undefined;
|
|
35
|
+
pending?: boolean | undefined;
|
|
36
|
+
pendingLabel?: string | undefined;
|
|
37
|
+
onerror?: ((error: unknown) => void) | undefined;
|
|
38
|
+
disabled?: boolean | undefined;
|
|
39
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
40
|
+
}>, {}, "">;
|
|
41
|
+
type Props = {
|
|
42
|
+
variant?: "secondary" | "primary" | "danger" | undefined;
|
|
43
|
+
small?: boolean | undefined;
|
|
44
|
+
icon?: string | undefined;
|
|
45
|
+
iconOnly?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* the accessible name and tooltip of an iconOnly button
|
|
48
|
+
*/
|
|
49
|
+
label?: string | undefined;
|
|
50
|
+
href?: string | undefined;
|
|
51
|
+
type?: "submit" | "reset" | "button" | undefined;
|
|
52
|
+
onclick?: ((event: MouseEvent) => unknown) | undefined;
|
|
53
|
+
pending?: boolean | undefined;
|
|
54
|
+
pendingLabel?: string | undefined;
|
|
55
|
+
onerror?: ((error: unknown) => void) | undefined;
|
|
56
|
+
disabled?: boolean | undefined;
|
|
57
|
+
children?: import("svelte").Snippet<[]> | undefined;
|
|
58
|
+
};
|