@xerios/design-system 0.0.0-stage → 0.1.1
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 +185 -0
- package/dist/components/Button.svelte.d.ts +70 -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 +401 -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 +110 -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 +151 -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 +79 -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 +899 -0
- package/dist/css/base.css +334 -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,140 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from './Icon.svelte'
|
|
3
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
4
|
+
import { fly, durations } from '../lib/motion.js'
|
|
5
|
+
/**
|
|
6
|
+
* One line of error text with a warning icon. Draws nothing while `message` is empty, so it can stay in the
|
|
7
|
+
* markup. Inline, it is an alert (role="alert"): read out as it appears, for a failure no field owns. Floating, it is
|
|
8
|
+
* not: the field points at it (aria-describedby), so it is read when the field gets focus (a failed submit moves the
|
|
9
|
+
* focus there), and fieldErrors announces it once when the field is left (lib/announce.js). An alert per field would
|
|
10
|
+
* read every message at once.
|
|
11
|
+
*
|
|
12
|
+
* <ErrorMessage message={failure} /> inline: next to a form's buttons, or where no single control is at fault
|
|
13
|
+
* <ErrorMessage floating message={error} /> a bubble under its control, with a button to dismiss it
|
|
14
|
+
*
|
|
15
|
+
* floating: a red bubble with an arrow, hanging under the nearest positioned ancestor (the field), over what follows, so nothing
|
|
16
|
+
* shifts when it appears. Dismissing hides it until the message changes; the control keeps its invalid style.
|
|
17
|
+
* It drops in from its control and lifts away as it goes; the inline one fades in and goes at once, so the layout
|
|
18
|
+
* after it doesn't wait on a fade.
|
|
19
|
+
* TextField, TextArea and Select draw a floating one themselves from their `error` prop.
|
|
20
|
+
*
|
|
21
|
+
* message: the text. id: so a control can point at it with aria-describedby. ondismiss: runs after the bubble
|
|
22
|
+
* is dismissed (the fields use it to take the focus back). Other attributes (class…) and attachments go to the <p>.
|
|
23
|
+
*
|
|
24
|
+
* @typedef {object} Props
|
|
25
|
+
* @property {string} [message]
|
|
26
|
+
* @property {string} [id]
|
|
27
|
+
* @property {boolean} [floating]
|
|
28
|
+
* @property {(() => void) | null} [ondismiss]
|
|
29
|
+
*/
|
|
30
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLParagraphElement>, keyof Props>} */
|
|
31
|
+
let { message = '', id = undefined, floating = false, ondismiss = null, class: className, ...rest } = $props()
|
|
32
|
+
// Set by the dismiss button; a new message resets it, so that one shows again.
|
|
33
|
+
let dismissed = $derived.by(() => {
|
|
34
|
+
void message
|
|
35
|
+
return false
|
|
36
|
+
})
|
|
37
|
+
const shown = $derived(message && !(floating && dismissed))
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
{#if shown}
|
|
41
|
+
<p
|
|
42
|
+
{id}
|
|
43
|
+
class={['error', className]}
|
|
44
|
+
class:floating
|
|
45
|
+
data-tone="danger"
|
|
46
|
+
role={floating ? undefined : 'alert'}
|
|
47
|
+
{...rest}
|
|
48
|
+
in:fly={{ y: floating ? -4 : 0, duration: durations.short3 }}
|
|
49
|
+
out:fly={{ y: floating ? -4 : 0, duration: floating ? durations.short2 : 0 }}
|
|
50
|
+
>
|
|
51
|
+
<Icon name="warning" size="sm" />
|
|
52
|
+
<span class="text">{message}</span>
|
|
53
|
+
{#if floating}
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
class="dismiss"
|
|
57
|
+
aria-label="Dismiss"
|
|
58
|
+
{@attach tooltip('Dismiss')}
|
|
59
|
+
onclick={() => {
|
|
60
|
+
dismissed = true
|
|
61
|
+
ondismiss?.()
|
|
62
|
+
}}><Icon name="x" size="sm" /></button
|
|
63
|
+
>
|
|
64
|
+
{/if}
|
|
65
|
+
</p>
|
|
66
|
+
{/if}
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
.error {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: flex-start;
|
|
72
|
+
gap: var(--space-1);
|
|
73
|
+
min-width: 0;
|
|
74
|
+
font-size: 12px;
|
|
75
|
+
color: var(--tone);
|
|
76
|
+
}
|
|
77
|
+
/* One line tall, so the icon sits centred on the first line of text and stays at the top when the text wraps. */
|
|
78
|
+
.error > :global(.icon) {
|
|
79
|
+
flex: none;
|
|
80
|
+
height: 1lh;
|
|
81
|
+
}
|
|
82
|
+
.floating {
|
|
83
|
+
position: absolute;
|
|
84
|
+
top: calc(100% + var(--space-2));
|
|
85
|
+
left: 0;
|
|
86
|
+
z-index: var(--z-sticky);
|
|
87
|
+
/* As wide as its text, up to a cap of its own rather than the control's width, so a narrow field doesn't squeeze the
|
|
88
|
+
message into a column of short lines. */
|
|
89
|
+
width: max-content;
|
|
90
|
+
max-width: min(320px, calc(100dvw - 32px));
|
|
91
|
+
padding: var(--space-1) var(--space-1) var(--space-1) var(--space-2);
|
|
92
|
+
border: 1px solid var(--tone);
|
|
93
|
+
border-radius: var(--r);
|
|
94
|
+
/* Tinted red over the floating surface, so it reads as an error and not as an ordinary tooltip. */
|
|
95
|
+
background: linear-gradient(var(--tone-soft), var(--tone-soft)), var(--elevated);
|
|
96
|
+
box-shadow: var(--shadow);
|
|
97
|
+
color: var(--fg);
|
|
98
|
+
}
|
|
99
|
+
/* The arrow: a small square turned 45°, half above the bubble, pointing at the control. */
|
|
100
|
+
.floating::before {
|
|
101
|
+
content: '';
|
|
102
|
+
position: absolute;
|
|
103
|
+
top: calc(var(--space-1) * -1 - 1px);
|
|
104
|
+
left: var(--space-3);
|
|
105
|
+
width: var(--space-2);
|
|
106
|
+
height: var(--space-2);
|
|
107
|
+
border: 1px solid var(--tone);
|
|
108
|
+
border-right: 0;
|
|
109
|
+
border-bottom: 0;
|
|
110
|
+
background: inherit;
|
|
111
|
+
rotate: 45deg;
|
|
112
|
+
}
|
|
113
|
+
.floating > :global(.icon) {
|
|
114
|
+
color: var(--tone);
|
|
115
|
+
}
|
|
116
|
+
.floating .text {
|
|
117
|
+
padding-right: var(--space-1);
|
|
118
|
+
}
|
|
119
|
+
/* The icon and the first line of text centre on the 24px dismiss button; all three stay at the top as the text wraps. */
|
|
120
|
+
.floating > :global(.icon),
|
|
121
|
+
.floating .text {
|
|
122
|
+
margin-block: calc((24px - 1lh) / 2);
|
|
123
|
+
}
|
|
124
|
+
.dismiss {
|
|
125
|
+
display: inline-grid;
|
|
126
|
+
place-items: center;
|
|
127
|
+
flex: none;
|
|
128
|
+
width: 24px;
|
|
129
|
+
height: 24px;
|
|
130
|
+
padding: 0;
|
|
131
|
+
border: 0;
|
|
132
|
+
border-radius: var(--r-pill);
|
|
133
|
+
background: none;
|
|
134
|
+
color: var(--tone);
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
}
|
|
137
|
+
.dismiss:hover {
|
|
138
|
+
background: var(--tone-soft);
|
|
139
|
+
}
|
|
140
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default ErrorMessage;
|
|
2
|
+
type ErrorMessage = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLParagraphElement>, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const ErrorMessage: import("svelte").Component<{
|
|
7
|
+
message?: string | undefined;
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
floating?: boolean | undefined;
|
|
10
|
+
ondismiss?: (() => void) | null | undefined;
|
|
11
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLParagraphElement>, keyof {
|
|
12
|
+
message?: string | undefined;
|
|
13
|
+
id?: string | undefined;
|
|
14
|
+
floating?: boolean | undefined;
|
|
15
|
+
ondismiss?: (() => void) | null | undefined;
|
|
16
|
+
}>, {}, "">;
|
|
17
|
+
/**
|
|
18
|
+
* One line of error text with a warning icon. Draws nothing while `message` is empty, so it can stay in the
|
|
19
|
+
* markup. Inline, it is an alert (role="alert"): read out as it appears, for a failure no field owns. Floating, it is
|
|
20
|
+
* not: the field points at it (aria-describedby), so it is read when the field gets focus (a failed submit moves the
|
|
21
|
+
* focus there), and fieldErrors announces it once when the field is left (lib/announce.js). An alert per field would
|
|
22
|
+
* read every message at once.
|
|
23
|
+
*
|
|
24
|
+
* <ErrorMessage message={failure} /> inline: next to a form's buttons, or where no single control is at fault
|
|
25
|
+
* <ErrorMessage floating message={error} /> a bubble under its control, with a button to dismiss it
|
|
26
|
+
*
|
|
27
|
+
* floating: a red bubble with an arrow, hanging under the nearest positioned ancestor (the field), over what follows, so nothing
|
|
28
|
+
* shifts when it appears. Dismissing hides it until the message changes; the control keeps its invalid style.
|
|
29
|
+
* It drops in from its control and lifts away as it goes; the inline one fades in and goes at once, so the layout
|
|
30
|
+
* after it doesn't wait on a fade.
|
|
31
|
+
* TextField, TextArea and Select draw a floating one themselves from their `error` prop.
|
|
32
|
+
*
|
|
33
|
+
* message: the text. id: so a control can point at it with aria-describedby. ondismiss: runs after the bubble
|
|
34
|
+
* is dismissed (the fields use it to take the focus back). Other attributes (class…) and attachments go to the <p>.
|
|
35
|
+
*/
|
|
36
|
+
type Props = {
|
|
37
|
+
message?: string | undefined;
|
|
38
|
+
id?: string | undefined;
|
|
39
|
+
floating?: boolean | undefined;
|
|
40
|
+
ondismiss?: (() => void) | null | undefined;
|
|
41
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
// Phosphor icons (regular weight, one family everywhere), as inline SVG strings. This file draws the
|
|
3
|
+
// general-purpose set the design system's own components use (src/components/icons.js, generated by
|
|
4
|
+
// scripts/icons.js). An app adds its own once, before it mounts; with Vite, `?raw` gives the markup:
|
|
5
|
+
//
|
|
6
|
+
// import { registerIcons } from '@xerios/design-system/components/Icon.svelte';
|
|
7
|
+
// import briefcase from '@phosphor-icons/core/regular/briefcase.svg?raw';
|
|
8
|
+
// registerIcons({ briefcase });
|
|
9
|
+
//
|
|
10
|
+
// Then <Icon name="briefcase" /> works everywhere, including in options and menu items that take an icon name.
|
|
11
|
+
import BUILT_IN, { MISSING } from './icons.js'
|
|
12
|
+
|
|
13
|
+
/** @type {Record<string, string>} */
|
|
14
|
+
const ICONS = { ...BUILT_IN }
|
|
15
|
+
|
|
16
|
+
/** Names already reported, so a missing icon drawn in a list logs once, not once per row. */
|
|
17
|
+
const reported = new Set()
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Adds icons (name → SVG markup using currentColor) to the registry, replacing any of the same name. Call before mounting.
|
|
21
|
+
* @param {Record<string, string>} icons
|
|
22
|
+
*/
|
|
23
|
+
export function registerIcons(icons) {
|
|
24
|
+
Object.assign(ICONS, icons)
|
|
25
|
+
}
|
|
26
|
+
/** Every registered name (for a gallery, or to check a name exists). */
|
|
27
|
+
export const iconNames = () => Object.keys(ICONS)
|
|
28
|
+
/** @param {string} name */
|
|
29
|
+
export const hasIcon = (name) => Object.hasOwn(ICONS, name)
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<script>
|
|
33
|
+
/**
|
|
34
|
+
* size: sm (14px) | md (16px) | lg (20px), from the --icon-* tokens.
|
|
35
|
+
* label: give one only when the icon carries meaning that no visible text repeats;
|
|
36
|
+
* otherwise it is decorative and hidden from assistive tech.
|
|
37
|
+
* Other attributes (class…) and attachments go to the wrapping <span>.
|
|
38
|
+
* A name nobody registered draws a question mark in the danger colour instead, and logs a console error once per name.
|
|
39
|
+
*
|
|
40
|
+
* @typedef {object} Props
|
|
41
|
+
* @property {string} name
|
|
42
|
+
* @property {'sm' | 'md' | 'lg'} [size]
|
|
43
|
+
* @property {string | null} [label]
|
|
44
|
+
*/
|
|
45
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLSpanElement>, keyof Props>} */
|
|
46
|
+
let { name, size = 'md', label = null, class: className, ...rest } = $props()
|
|
47
|
+
|
|
48
|
+
const missing = $derived(!hasIcon(name))
|
|
49
|
+
|
|
50
|
+
$effect(() => {
|
|
51
|
+
if (!missing || reported.has(name)) return
|
|
52
|
+
reported.add(name)
|
|
53
|
+
// oxlint-disable-next-line no-console -- the point: a developer sees which name is missing
|
|
54
|
+
console.error(`Icon: no icon named "${name}". Register it with registerIcons({ ${name}: svgMarkup }) before mounting.`)
|
|
55
|
+
})
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<!-- allow-html: ICONS holds SVG markup bundled at build time or passed to registerIcons by app code, never user input -->
|
|
59
|
+
<span
|
|
60
|
+
class={['icon', size, className]}
|
|
61
|
+
role={label ? 'img' : undefined}
|
|
62
|
+
aria-label={label}
|
|
63
|
+
aria-hidden={label ? undefined : 'true'}
|
|
64
|
+
data-missing={missing || undefined}
|
|
65
|
+
{...rest}>{@html missing ? MISSING : ICONS[name]}</span
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
/* Never the target of a click: the press belongs to the button or link around it. */
|
|
70
|
+
.icon {
|
|
71
|
+
display: inline-flex;
|
|
72
|
+
flex: none;
|
|
73
|
+
pointer-events: none;
|
|
74
|
+
width: var(--icon-size);
|
|
75
|
+
height: var(--icon-size);
|
|
76
|
+
}
|
|
77
|
+
.icon[data-missing] {
|
|
78
|
+
color: var(--danger);
|
|
79
|
+
}
|
|
80
|
+
.icon :global(svg) {
|
|
81
|
+
width: 100%;
|
|
82
|
+
height: 100%;
|
|
83
|
+
display: block;
|
|
84
|
+
}
|
|
85
|
+
.sm {
|
|
86
|
+
--icon-size: var(--icon-sm);
|
|
87
|
+
}
|
|
88
|
+
.md {
|
|
89
|
+
--icon-size: var(--icon-md);
|
|
90
|
+
}
|
|
91
|
+
.lg {
|
|
92
|
+
--icon-size: var(--icon-lg);
|
|
93
|
+
}
|
|
94
|
+
</style>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds icons (name → SVG markup using currentColor) to the registry, replacing any of the same name. Call before mounting.
|
|
3
|
+
* @param {Record<string, string>} icons
|
|
4
|
+
*/
|
|
5
|
+
export function registerIcons(icons: Record<string, string>): void;
|
|
6
|
+
export function iconNames(): string[];
|
|
7
|
+
export function hasIcon(name: string): boolean;
|
|
8
|
+
export default Icon;
|
|
9
|
+
type Icon = {
|
|
10
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
11
|
+
$set?(props: Partial<Props & Omit<HTMLAttributes<HTMLSpanElement>, keyof Props>>): void;
|
|
12
|
+
};
|
|
13
|
+
declare const Icon: import("svelte").Component<{
|
|
14
|
+
name: string;
|
|
15
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
16
|
+
label?: string | null | undefined;
|
|
17
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLSpanElement>, keyof {
|
|
18
|
+
name: string;
|
|
19
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
20
|
+
label?: string | null | undefined;
|
|
21
|
+
}>, {}, "">;
|
|
22
|
+
/**
|
|
23
|
+
* size: sm (14px) | md (16px) | lg (20px), from the --icon-* tokens.
|
|
24
|
+
* label: give one only when the icon carries meaning that no visible text repeats;
|
|
25
|
+
* otherwise it is decorative and hidden from assistive tech.
|
|
26
|
+
* Other attributes (class…) and attachments go to the wrapping <span>.
|
|
27
|
+
* A name nobody registered draws a question mark in the danger colour instead, and logs a console error once per name.
|
|
28
|
+
*/
|
|
29
|
+
type Props = {
|
|
30
|
+
name: string;
|
|
31
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
32
|
+
label?: string | null | undefined;
|
|
33
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Small ⓘ button with a tooltip that opens on hover or keyboard focus (Esc only closes it, not a dialog around it). With `pinnable`, clicking pins
|
|
4
|
+
* it open over a dimmed page so its text can be selected and copied; a press outside it, Esc, scrolling the page, or
|
|
5
|
+
* clicking the ⓘ again closes it.
|
|
6
|
+
* Lives in the top layer (fixed, below the button, flipping above when there's no room, with an arrow pointing at it), so modal dialogs, scrolling
|
|
7
|
+
* panes, sticky headers and clipping cards can't cover or cut it.
|
|
8
|
+
* `lines`: [{ label?, text }]; `label`: the button's accessible name.
|
|
9
|
+
* The tip fades in and out with a small slide away from the ⓘ (instant under reduced motion).
|
|
10
|
+
* Other attributes (class…) and attachments go to the ⓘ button.
|
|
11
|
+
*/
|
|
12
|
+
import Icon from './Icon.svelte'
|
|
13
|
+
import { topLayer } from '../lib/dom.js'
|
|
14
|
+
import { fade, motion, durations, easings } from '../lib/motion.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} Props
|
|
18
|
+
* @property {string} [label]
|
|
19
|
+
* @property {{ label?: string, text: string }[]} [lines]
|
|
20
|
+
* @property {boolean} [pinnable]
|
|
21
|
+
*/
|
|
22
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
|
|
23
|
+
let { label = 'More information', lines = [], pinnable = false, class: className, ...rest } = $props()
|
|
24
|
+
const propsId = $props.id()
|
|
25
|
+
const uid = 'tip-' + propsId
|
|
26
|
+
let btn = $state()
|
|
27
|
+
let tipEl = $state()
|
|
28
|
+
let open = $state(false)
|
|
29
|
+
let pinned = $state(false)
|
|
30
|
+
|
|
31
|
+
const show = () => (open = true)
|
|
32
|
+
const hide = () => {
|
|
33
|
+
open = false
|
|
34
|
+
pinned = false
|
|
35
|
+
}
|
|
36
|
+
const softHide = () => !pinned && (open = false)
|
|
37
|
+
|
|
38
|
+
/** Attachment: places the tip against the button once it has rendered (and so has a size). */
|
|
39
|
+
function place(tip) {
|
|
40
|
+
const r = btn.getBoundingClientRect()
|
|
41
|
+
const w = tip.offsetWidth,
|
|
42
|
+
h = tip.offsetHeight
|
|
43
|
+
const above = r.bottom + 8 + h > innerHeight - 8 && r.top - 8 - h > 8
|
|
44
|
+
const left = Math.max(8, Math.min(r.left, innerWidth - w - 8))
|
|
45
|
+
tip.style.top = `${above ? r.top - 8 - h : r.bottom + 8}px`
|
|
46
|
+
tip.style.left = `${left}px`
|
|
47
|
+
// The arrow points back at the ⓘ.
|
|
48
|
+
tip.dataset.arrow = above ? 'down' : 'up'
|
|
49
|
+
tip.style.setProperty('--arrow-x', `${r.left + r.width / 2 - left}px`)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Svelte transition for the tip: fades and slides 3px toward the side it opens on. Deferred a microtask so `place` has
|
|
53
|
+
* already set which side that is. */
|
|
54
|
+
function pop(node) {
|
|
55
|
+
return ({ direction }) => {
|
|
56
|
+
const dy = node.dataset.arrow === 'down' ? 3 : -3
|
|
57
|
+
return {
|
|
58
|
+
duration: motion(direction === 'out' ? durations.short2 : durations.short3),
|
|
59
|
+
easing: easings.standard[direction === 'out' ? 'accelerate' : 'decelerate'],
|
|
60
|
+
css: (t, u) => `opacity: ${t}; translate: 0 ${u * dy}px;`,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Attachment on the scrim: the top layer stacks by show order, so once the scrim is up the tip is shown again above it. */
|
|
66
|
+
function raiseTip() {
|
|
67
|
+
if (!tipEl?.matches(':popover-open')) return
|
|
68
|
+
tipEl.hidePopover()
|
|
69
|
+
tipEl.showPopover()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// While pinned: a press or scroll outside it, or Esc anywhere, closes it.
|
|
73
|
+
const inside = (t) => btn?.contains(t) || t.closest?.(`#${uid}`)
|
|
74
|
+
const outside = (e) => pinned && !inside(e.target) && hide()
|
|
75
|
+
const escape = (e) => pinned && e.key === 'Escape' && (e.preventDefault(), e.stopPropagation(), hide())
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<svelte:document onpointerdowncapture={outside} onkeydowncapture={escape} onscrollcapture={outside} />
|
|
79
|
+
|
|
80
|
+
<button
|
|
81
|
+
bind:this={btn}
|
|
82
|
+
type="button"
|
|
83
|
+
class={['info', className]}
|
|
84
|
+
{...rest}
|
|
85
|
+
class:pinned
|
|
86
|
+
aria-label={label}
|
|
87
|
+
aria-expanded={pinnable ? pinned : undefined}
|
|
88
|
+
aria-describedby={open ? uid : undefined}
|
|
89
|
+
onpointerenter={show}
|
|
90
|
+
onpointerleave={softHide}
|
|
91
|
+
onfocus={show}
|
|
92
|
+
onblur={softHide}
|
|
93
|
+
onclick={(e) => {
|
|
94
|
+
e.stopPropagation()
|
|
95
|
+
if (!pinnable) show()
|
|
96
|
+
else if (pinned) hide()
|
|
97
|
+
else {
|
|
98
|
+
pinned = true
|
|
99
|
+
show()
|
|
100
|
+
}
|
|
101
|
+
}}
|
|
102
|
+
onkeydown={(e) => e.key === 'Escape' && open && (e.preventDefault(), e.stopPropagation(), hide())}
|
|
103
|
+
>
|
|
104
|
+
<Icon name="infoCircle" size="sm" />
|
|
105
|
+
</button>
|
|
106
|
+
{#if pinned}
|
|
107
|
+
<!-- Swallows the outside press that closes the pinned tip, so it doesn't also hit what's underneath. -->
|
|
108
|
+
<div class="scrim" aria-hidden="true" {@attach topLayer(btn)} {@attach raiseTip} transition:fade></div>
|
|
109
|
+
{/if}
|
|
110
|
+
{#if open}
|
|
111
|
+
<div bind:this={tipEl} id={uid} class="tip" class:pinned role="tooltip" data-floating {@attach topLayer(btn)} {@attach place} transition:pop>
|
|
112
|
+
{#each lines as l, i (i)}
|
|
113
|
+
<p>
|
|
114
|
+
{#if l.label}<span class="k">{l.label}</span>{/if}<span>{l.text}</span>
|
|
115
|
+
</p>
|
|
116
|
+
{/each}
|
|
117
|
+
</div>
|
|
118
|
+
{/if}
|
|
119
|
+
|
|
120
|
+
<style>
|
|
121
|
+
.info {
|
|
122
|
+
display: inline-grid;
|
|
123
|
+
place-items: center;
|
|
124
|
+
width: 24px;
|
|
125
|
+
height: 24px;
|
|
126
|
+
flex: none;
|
|
127
|
+
padding: 0;
|
|
128
|
+
border: 0;
|
|
129
|
+
border-radius: var(--r-pill);
|
|
130
|
+
background: none;
|
|
131
|
+
color: var(--faint);
|
|
132
|
+
}
|
|
133
|
+
.info:hover,
|
|
134
|
+
.info:focus-visible,
|
|
135
|
+
.info.pinned {
|
|
136
|
+
color: var(--fg-2);
|
|
137
|
+
background: var(--control-3);
|
|
138
|
+
}
|
|
139
|
+
.tip {
|
|
140
|
+
position: fixed;
|
|
141
|
+
top: 0;
|
|
142
|
+
left: 0;
|
|
143
|
+
z-index: var(--z-menu);
|
|
144
|
+
width: max-content;
|
|
145
|
+
max-width: min(328px, calc(100dvw - 16px));
|
|
146
|
+
pointer-events: none;
|
|
147
|
+
display: grid;
|
|
148
|
+
gap: 4px;
|
|
149
|
+
padding: var(--space-2) var(--space-3);
|
|
150
|
+
border: 1px solid var(--line-float);
|
|
151
|
+
background: var(--elevated);
|
|
152
|
+
border-radius: var(--r-lg);
|
|
153
|
+
box-shadow: var(--shadow);
|
|
154
|
+
font: 400 12px/1.5 var(--font-body);
|
|
155
|
+
color: var(--fg-2);
|
|
156
|
+
text-align: left;
|
|
157
|
+
white-space: normal;
|
|
158
|
+
overflow-wrap: anywhere;
|
|
159
|
+
letter-spacing: normal;
|
|
160
|
+
text-transform: none;
|
|
161
|
+
}
|
|
162
|
+
.scrim {
|
|
163
|
+
position: fixed;
|
|
164
|
+
inset: 0;
|
|
165
|
+
z-index: calc(var(--z-menu) - 1);
|
|
166
|
+
background: var(--scrim);
|
|
167
|
+
}
|
|
168
|
+
.tip.pinned {
|
|
169
|
+
pointer-events: auto;
|
|
170
|
+
user-select: text;
|
|
171
|
+
-webkit-user-select: text;
|
|
172
|
+
cursor: text;
|
|
173
|
+
}
|
|
174
|
+
p {
|
|
175
|
+
display: grid;
|
|
176
|
+
grid-template-columns: auto 1fr;
|
|
177
|
+
gap: var(--space-2);
|
|
178
|
+
}
|
|
179
|
+
.k {
|
|
180
|
+
color: var(--muted);
|
|
181
|
+
min-width: 52px;
|
|
182
|
+
}
|
|
183
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default InfoTip;
|
|
2
|
+
type InfoTip = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const InfoTip: import("svelte").Component<{
|
|
7
|
+
label?: string | undefined;
|
|
8
|
+
lines?: {
|
|
9
|
+
label?: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}[] | undefined;
|
|
12
|
+
pinnable?: boolean | undefined;
|
|
13
|
+
} & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
|
|
14
|
+
label?: string | undefined;
|
|
15
|
+
lines?: {
|
|
16
|
+
label?: string;
|
|
17
|
+
text: string;
|
|
18
|
+
}[] | undefined;
|
|
19
|
+
pinnable?: boolean | undefined;
|
|
20
|
+
}>, {}, "">;
|
|
21
|
+
type Props = {
|
|
22
|
+
label?: string | undefined;
|
|
23
|
+
lines?: {
|
|
24
|
+
label?: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}[] | undefined;
|
|
27
|
+
pinnable?: boolean | undefined;
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** Inline markdown (**bold**, *italic*, `code`, [links](…), bare URLs) without {@html}. See lib/inline-md.js. */
|
|
3
|
+
import { inlineMd } from '../lib/inline-md.js'
|
|
4
|
+
/** @type {{ text: string }} */
|
|
5
|
+
let { text } = $props()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#each inlineMd(text) as p, k (k)}{#if p.href}<a class="md-link" href={p.href} target="_blank" rel="noopener"
|
|
9
|
+
>{#if p.b}<strong>{p.text}</strong>{:else}{p.text}{/if}</a
|
|
10
|
+
>{:else if p.code}<code class="md-code">{p.text}</code>{:else if p.b && p.i}<strong><em>{p.text}</em></strong>{:else if p.b}<strong>{p.text}</strong
|
|
11
|
+
>{:else if p.i}<em>{p.text}</em>{:else}{p.text}{/if}{/each}
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
.md-link {
|
|
15
|
+
color: var(--accent);
|
|
16
|
+
}
|
|
17
|
+
.md-code {
|
|
18
|
+
font: 400 0.88em var(--font-mono);
|
|
19
|
+
padding: 1px 5px;
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
background: var(--fill-2);
|
|
22
|
+
border: 1px solid var(--line-strong);
|
|
23
|
+
color: var(--fg-2);
|
|
24
|
+
}
|
|
25
|
+
strong {
|
|
26
|
+
font-weight: var(--w-semibold);
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Md;
|
|
2
|
+
type Md = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Md: import("svelte").Component<{
|
|
7
|
+
text: string;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A modal dialog: the .dialog panel in the top layer, with a header holding its title and a ✕. The body and footer
|
|
4
|
+
* are the children, so each step of a flow can swap them: use .dialog-body (a <form> is fine) and .dialog-foot.
|
|
5
|
+
*
|
|
6
|
+
* <Modal bind:this={modal} title="New site" canClose={confirmDiscard} onclose={reset}>
|
|
7
|
+
* <form id="new-site" class="dialog-body" novalidate onsubmit={submit}>…</form>
|
|
8
|
+
* <footer class="dialog-foot">
|
|
9
|
+
* <span class="spacer"></span>
|
|
10
|
+
* <button type="button" class="btn" onclick={() => modal.requestClose()}>Cancel</button>
|
|
11
|
+
* <button type="submit" form="new-site" class="btn btn-primary">Create</button>
|
|
12
|
+
* </footer>
|
|
13
|
+
* </Modal>
|
|
14
|
+
*
|
|
15
|
+
* modal.show() opens it (does nothing while it is open)
|
|
16
|
+
* modal.requestClose() closes it the way the ✕ does, through `locked` and `canClose`
|
|
17
|
+
* modal.close() closes it now
|
|
18
|
+
* modal.isOpen()
|
|
19
|
+
*
|
|
20
|
+
* title: the heading, which names the dialog. narrow: the 420px size for a question (.dialog.confirm).
|
|
21
|
+
* closeButton (default true): the ✕. A question usually drops it and has Cancel in its footer.
|
|
22
|
+
* locked: only close() closes it and the ✕ is disabled, for work that has to finish on screen.
|
|
23
|
+
* canClose(): asked on every request to close (the ✕, Esc, a backdrop click, requestClose). Return false, or a promise
|
|
24
|
+
* of false, to keep it open: pair it with confirmDialog to ask before unsaved input is thrown away. One question at a
|
|
25
|
+
* time: requests while it is asking are ignored.
|
|
26
|
+
* onclose(): after it has closed, however that happened.
|
|
27
|
+
* Other attributes (class, aria-describedby…) and attachments go to the <dialog>.
|
|
28
|
+
*
|
|
29
|
+
* Keyboard: Esc requests closing, through canClose however fast it is repeated (see closeRequests in lib/dom.js). The
|
|
30
|
+
* focus starts on the first [autofocus] control, else the first focusable one, and goes back where it was on close.
|
|
31
|
+
*/
|
|
32
|
+
import Icon from './Icon.svelte'
|
|
33
|
+
import { backdropClose, closeRequests } from '../lib/dom.js'
|
|
34
|
+
import { tooltip } from '../lib/tooltip.js'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} Props
|
|
38
|
+
* @property {string} title
|
|
39
|
+
* @property {boolean} [narrow]
|
|
40
|
+
* @property {boolean} [closeButton]
|
|
41
|
+
* @property {boolean} [locked]
|
|
42
|
+
* @property {() => boolean | Promise<boolean>} [canClose]
|
|
43
|
+
* @property {(event: Event) => void} [onclose]
|
|
44
|
+
* @property {import('svelte').Snippet} [children]
|
|
45
|
+
*/
|
|
46
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLDialogAttributes, keyof Props>} */
|
|
47
|
+
let { title, narrow = false, closeButton = true, locked = false, canClose, onclose, class: className, children, ...rest } = $props()
|
|
48
|
+
const uid = $props.id()
|
|
49
|
+
|
|
50
|
+
/** @type {HTMLDialogElement | undefined} */
|
|
51
|
+
let dialog
|
|
52
|
+
let asking = false
|
|
53
|
+
|
|
54
|
+
export function show() {
|
|
55
|
+
if (!dialog?.open) dialog?.showModal()
|
|
56
|
+
}
|
|
57
|
+
export function close() {
|
|
58
|
+
dialog?.close()
|
|
59
|
+
}
|
|
60
|
+
export function isOpen() {
|
|
61
|
+
return dialog?.open ?? false
|
|
62
|
+
}
|
|
63
|
+
export async function requestClose() {
|
|
64
|
+
if (locked || asking || !dialog?.open) return
|
|
65
|
+
asking = true
|
|
66
|
+
try {
|
|
67
|
+
if ((await canClose?.()) === false) return
|
|
68
|
+
} finally {
|
|
69
|
+
asking = false
|
|
70
|
+
}
|
|
71
|
+
dialog?.close()
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<dialog
|
|
76
|
+
bind:this={dialog}
|
|
77
|
+
class={['dialog', narrow && 'confirm', className]}
|
|
78
|
+
aria-labelledby="{uid}-title"
|
|
79
|
+
{...backdropClose(requestClose)}
|
|
80
|
+
{...closeRequests(requestClose)}
|
|
81
|
+
{...rest}
|
|
82
|
+
{onclose}
|
|
83
|
+
>
|
|
84
|
+
<header class="dialog-head">
|
|
85
|
+
<h2 id="{uid}-title">{title}</h2>
|
|
86
|
+
{#if closeButton}
|
|
87
|
+
<button type="button" class="icon-btn" aria-label="Close" {@attach tooltip('Close')} onclick={requestClose} disabled={locked}><Icon name="x" /></button>
|
|
88
|
+
{/if}
|
|
89
|
+
</header>
|
|
90
|
+
{@render children?.()}
|
|
91
|
+
</dialog>
|