@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,296 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* A list of short values (tags) edited in one field: what is typed turns into a tag as soon as a separator is typed,
|
|
4
|
+
* on Enter, on paste, and when the field is left. Each tag has an × to remove it. Duplicates are dropped.
|
|
5
|
+
*
|
|
6
|
+
* <TagInput bind:value={names} id="names" label="Names" placeholder="Add a name" separator={/[\s,]+/} />
|
|
7
|
+
*
|
|
8
|
+
* Props:
|
|
9
|
+
* value (bindable): the tags, an array of strings. Changes only by whole tags, so it can be saved on every change.
|
|
10
|
+
* id, label, hideLabel, placeholder, info (an ⓘ next to the label, see InfoTip), note (dimmed text after the label, such as '(optional)'), error (a message from the app).
|
|
11
|
+
* separator: a RegExp for what splits typed text into tags (default commas and line breaks).
|
|
12
|
+
* normalize(text): turns typed text into a tag (default: trimmed). Return '' to drop it.
|
|
13
|
+
* validate(tag): a message when the tag isn't allowed, else ''. A rejected tag stays in the input, with the
|
|
14
|
+
* message in a bubble underneath, so it can be fixed.
|
|
15
|
+
* Keyboard: Backspace or ← at the start of the input selects the last tag; ← and → move between tags and back to the
|
|
16
|
+
* input; Backspace or Delete removes the selected tag; Escape clears what is typed; typing goes back to the input.
|
|
17
|
+
* Clicking a tag selects it. Additions and removals are announced to screen readers.
|
|
18
|
+
* Other attributes and attachments go to the <input>.
|
|
19
|
+
*/
|
|
20
|
+
import { tick } from 'svelte'
|
|
21
|
+
import ErrorMessage from '../ErrorMessage.svelte'
|
|
22
|
+
import Icon from '../Icon.svelte'
|
|
23
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
24
|
+
import { flip, scale, durations } from '../../lib/motion.js'
|
|
25
|
+
import { tooltip } from '../../lib/tooltip.js'
|
|
26
|
+
import { composing } from '../../lib/dom.js'
|
|
27
|
+
import { announce } from '../../lib/announce.js'
|
|
28
|
+
import { invalid } from '../../lib/invalid.js'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} Props
|
|
32
|
+
* @property {string[]} [value] bindable
|
|
33
|
+
* @property {string} id
|
|
34
|
+
* @property {string} label
|
|
35
|
+
* @property {boolean} [hideLabel]
|
|
36
|
+
* @property {string} [placeholder]
|
|
37
|
+
* @property {string} [info]
|
|
38
|
+
* @property {string} [note] dimmed text after the label, e.g. '(optional)'
|
|
39
|
+
* @property {string} [error]
|
|
40
|
+
* @property {RegExp} [separator]
|
|
41
|
+
* @property {(text: string) => string} [normalize]
|
|
42
|
+
* @property {((tag: string) => string | null | undefined) | null} [validate]
|
|
43
|
+
*/
|
|
44
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLInputAttributes, keyof Props>} */
|
|
45
|
+
let {
|
|
46
|
+
value = $bindable([]),
|
|
47
|
+
id,
|
|
48
|
+
label,
|
|
49
|
+
hideLabel = false,
|
|
50
|
+
placeholder = '',
|
|
51
|
+
info = '',
|
|
52
|
+
note = '',
|
|
53
|
+
error = '',
|
|
54
|
+
separator = /[,\n]+/,
|
|
55
|
+
normalize = (text) => text.trim(),
|
|
56
|
+
validate = null,
|
|
57
|
+
...rest
|
|
58
|
+
} = $props()
|
|
59
|
+
|
|
60
|
+
let input = $state()
|
|
61
|
+
let box = $state()
|
|
62
|
+
let draft = $state('')
|
|
63
|
+
let rejected = $state('') // validate's message for the text left in the input
|
|
64
|
+
const problem = $derived(rejected || error)
|
|
65
|
+
|
|
66
|
+
/** Adds the pieces as tags in one change; returns the ones validate turned down. */
|
|
67
|
+
function add(pieces) {
|
|
68
|
+
const next = [...value]
|
|
69
|
+
const refused = []
|
|
70
|
+
rejected = ''
|
|
71
|
+
for (const piece of pieces) {
|
|
72
|
+
const tag = normalize(piece)
|
|
73
|
+
if (!tag) continue
|
|
74
|
+
const message = validate?.(tag)
|
|
75
|
+
if (message) {
|
|
76
|
+
refused.push(piece.trim())
|
|
77
|
+
rejected = message
|
|
78
|
+
announce(message, { delay: 0 })
|
|
79
|
+
} else if (!next.includes(tag)) next.push(tag)
|
|
80
|
+
}
|
|
81
|
+
if (next.length !== value.length) {
|
|
82
|
+
announce(`Added ${next.slice(value.length).join(', ')}`, { delay: 0 })
|
|
83
|
+
value = next
|
|
84
|
+
}
|
|
85
|
+
return refused
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Turns the typed text into tags. `all`: the last piece too (Enter, paste, leaving); otherwise it may still be typed. */
|
|
89
|
+
function commit(all) {
|
|
90
|
+
const pieces = draft.split(separator)
|
|
91
|
+
const unfinished = all ? '' : pieces.pop()
|
|
92
|
+
const refused = add(pieces)
|
|
93
|
+
draft = [...refused, unfinished].filter(Boolean).join(', ')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function remove(i, focusAfter) {
|
|
97
|
+
const tag = value[i]
|
|
98
|
+
value = value.filter((_, j) => j !== i)
|
|
99
|
+
announce(`Removed ${tag}`, { delay: 0 })
|
|
100
|
+
// Once the list has updated, focus where the selection goes next.
|
|
101
|
+
void tick().then(() => focusAt(focusAfter))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Focuses tag i, or the input when there is no such tag. Found by its text: a removed tag may still be fading out. */
|
|
105
|
+
function focusAt(i) {
|
|
106
|
+
const tag = value[i]
|
|
107
|
+
if (tag != null) box?.querySelector(`[data-tag="${CSS.escape(tag)}"]`)?.focus()
|
|
108
|
+
else input?.focus()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function oninput(e) {
|
|
112
|
+
// Text still being composed (IME) isn't split into tags until it is confirmed.
|
|
113
|
+
if (e.isComposing) return
|
|
114
|
+
rejected = ''
|
|
115
|
+
if (e.inputType === 'insertFromPaste') commit(true)
|
|
116
|
+
else if (separator.test(draft)) commit(false)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function onInputKeydown(e) {
|
|
120
|
+
// Enter, Esc and Backspace inside an IME composition belong to the input method.
|
|
121
|
+
if (composing(e)) return
|
|
122
|
+
const atStart = input.selectionStart === 0 && input.selectionEnd === 0
|
|
123
|
+
if (e.key === 'Enter' && draft.trim()) {
|
|
124
|
+
e.preventDefault()
|
|
125
|
+
commit(true)
|
|
126
|
+
} else if (e.key === 'Escape' && draft) {
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
e.stopPropagation()
|
|
129
|
+
draft = ''
|
|
130
|
+
rejected = ''
|
|
131
|
+
} else if ((e.key === 'Backspace' || e.key === 'ArrowLeft') && atStart && value.length) {
|
|
132
|
+
e.preventDefault()
|
|
133
|
+
focusAt(value.length - 1)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Keys on a selected tag (handled on the box: a tag is a list item, not a control of its own).
|
|
138
|
+
function onTagKeydown(e) {
|
|
139
|
+
const tag = e.target.dataset?.tag
|
|
140
|
+
if (tag == null) return
|
|
141
|
+
const i = value.indexOf(tag)
|
|
142
|
+
if (e.key === 'Backspace') {
|
|
143
|
+
e.preventDefault()
|
|
144
|
+
remove(i, i > 0 ? i - 1 : value.length > 1 ? 0 : -1)
|
|
145
|
+
} else if (e.key === 'Delete') {
|
|
146
|
+
e.preventDefault()
|
|
147
|
+
remove(i, i < value.length - 1 ? i : -1)
|
|
148
|
+
} else if (e.key === 'ArrowLeft') {
|
|
149
|
+
e.preventDefault()
|
|
150
|
+
if (i > 0) focusAt(i - 1)
|
|
151
|
+
} else if (e.key === 'ArrowRight') {
|
|
152
|
+
e.preventDefault()
|
|
153
|
+
focusAt(i + 1)
|
|
154
|
+
} else if (e.key === 'Escape') {
|
|
155
|
+
e.preventDefault()
|
|
156
|
+
e.stopPropagation()
|
|
157
|
+
focusAt(-1)
|
|
158
|
+
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
159
|
+
// Typing goes back to the input; the key lands there.
|
|
160
|
+
focusAt(-1)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Leaving the whole field (not just moving between its tags and input) commits what was typed.
|
|
165
|
+
function onfocusout(e) {
|
|
166
|
+
if (!e.currentTarget.contains(e.relatedTarget) && draft.trim()) commit(true)
|
|
167
|
+
}
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<div class="field">
|
|
171
|
+
<FieldLabel for={id} id="{id}-label" {label} {note} {info} {hideLabel} />
|
|
172
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
173
|
+
<div bind:this={box} class="box field-box" {onfocusout} onkeydown={onTagKeydown} onclick={(e) => e.target === e.currentTarget && input.focus()}>
|
|
174
|
+
<ul aria-labelledby="{id}-label">
|
|
175
|
+
{#each value as tag, i (tag)}
|
|
176
|
+
<li
|
|
177
|
+
data-tag={tag}
|
|
178
|
+
class="tag"
|
|
179
|
+
tabindex="-1"
|
|
180
|
+
animate:flip={{ duration: durations.short4 }}
|
|
181
|
+
transition:scale={{ start: 0.85, duration: durations.short3 }}
|
|
182
|
+
>
|
|
183
|
+
<span class="text">{tag}</span>
|
|
184
|
+
<button type="button" class="remove" tabindex="-1" aria-label="Remove {tag}" {@attach tooltip('Remove')} onclick={() => remove(i, -1)}
|
|
185
|
+
><Icon name="x" size="sm" /></button
|
|
186
|
+
>
|
|
187
|
+
</li>
|
|
188
|
+
{/each}
|
|
189
|
+
</ul>
|
|
190
|
+
<input
|
|
191
|
+
{id}
|
|
192
|
+
bind:this={input}
|
|
193
|
+
bind:value={draft}
|
|
194
|
+
{...rest}
|
|
195
|
+
type="text"
|
|
196
|
+
placeholder={value.length ? '' : placeholder}
|
|
197
|
+
autocomplete="off"
|
|
198
|
+
spellcheck="false"
|
|
199
|
+
autocapitalize="none"
|
|
200
|
+
autocorrect="off"
|
|
201
|
+
aria-describedby="{id}-keys"
|
|
202
|
+
{@attach invalid(problem && `${id}-error`)}
|
|
203
|
+
{oninput}
|
|
204
|
+
onkeydown={onInputKeydown}
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
<span id="{id}-keys" class="sr-only">Enter or a comma adds what is typed. Backspace selects the last one; Backspace again removes it.</span>
|
|
208
|
+
<ErrorMessage floating id="{id}-error" message={problem} ondismiss={() => input?.focus()} />
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<style>
|
|
212
|
+
.field {
|
|
213
|
+
position: relative;
|
|
214
|
+
display: flex;
|
|
215
|
+
flex-direction: column;
|
|
216
|
+
gap: 3px;
|
|
217
|
+
min-width: min(100%, 240px);
|
|
218
|
+
}
|
|
219
|
+
/* The same box as TextField, wrapping its tags and the input onto as many rows as they need. Its width doesn't
|
|
220
|
+
follow the tags (contain): where the field sizes to its content (a flex row), it keeps its 240px and the tags
|
|
221
|
+
wrap, rather than widening with every tag added. */
|
|
222
|
+
.box {
|
|
223
|
+
contain: inline-size;
|
|
224
|
+
display: flex;
|
|
225
|
+
flex-wrap: wrap;
|
|
226
|
+
align-items: center;
|
|
227
|
+
gap: 4px;
|
|
228
|
+
min-height: 32px;
|
|
229
|
+
padding: 3px 6px 3px 4px;
|
|
230
|
+
cursor: text;
|
|
231
|
+
}
|
|
232
|
+
/* The list's items flow in the box's own rows, beside the input. */
|
|
233
|
+
ul {
|
|
234
|
+
display: contents;
|
|
235
|
+
}
|
|
236
|
+
.tag {
|
|
237
|
+
display: inline-flex;
|
|
238
|
+
align-items: center;
|
|
239
|
+
max-width: 100%;
|
|
240
|
+
min-height: 24px;
|
|
241
|
+
padding-left: 8px;
|
|
242
|
+
cursor: default;
|
|
243
|
+
border-radius: var(--r-pill);
|
|
244
|
+
background: var(--fill-3);
|
|
245
|
+
box-shadow: inset 0 0 0 1px var(--line);
|
|
246
|
+
font-size: 12px;
|
|
247
|
+
font-weight: var(--w-medium);
|
|
248
|
+
color: var(--fg);
|
|
249
|
+
outline: none;
|
|
250
|
+
transition:
|
|
251
|
+
background-color var(--dur-fast) var(--ease-out),
|
|
252
|
+
box-shadow var(--dur-fast) var(--ease-out);
|
|
253
|
+
}
|
|
254
|
+
/* The selected tag: the one Backspace or Delete would remove. */
|
|
255
|
+
.tag:focus {
|
|
256
|
+
background: var(--accent-soft);
|
|
257
|
+
box-shadow: inset 0 0 0 1px var(--accent-line);
|
|
258
|
+
}
|
|
259
|
+
.text {
|
|
260
|
+
min-width: 0;
|
|
261
|
+
overflow: clip;
|
|
262
|
+
text-overflow: ellipsis;
|
|
263
|
+
white-space: nowrap;
|
|
264
|
+
}
|
|
265
|
+
/* A 24px target with an 18px circle drawn inside it (the padding keeps the fill off the edge). */
|
|
266
|
+
.remove {
|
|
267
|
+
display: inline-grid;
|
|
268
|
+
place-items: center;
|
|
269
|
+
flex: none;
|
|
270
|
+
width: 24px;
|
|
271
|
+
height: 24px;
|
|
272
|
+
padding: 3px;
|
|
273
|
+
border: 0;
|
|
274
|
+
border-radius: 50%;
|
|
275
|
+
background: none;
|
|
276
|
+
background-clip: content-box;
|
|
277
|
+
color: var(--muted);
|
|
278
|
+
cursor: pointer;
|
|
279
|
+
}
|
|
280
|
+
.remove:hover {
|
|
281
|
+
color: var(--fg);
|
|
282
|
+
background-color: var(--control-4);
|
|
283
|
+
}
|
|
284
|
+
input {
|
|
285
|
+
all: unset;
|
|
286
|
+
flex: 1 1 80px;
|
|
287
|
+
min-width: 80px;
|
|
288
|
+
padding: 3px 0 3px 6px;
|
|
289
|
+
font-size: 13px;
|
|
290
|
+
color: var(--fg);
|
|
291
|
+
}
|
|
292
|
+
input::placeholder {
|
|
293
|
+
color: var(--faint);
|
|
294
|
+
opacity: 1;
|
|
295
|
+
}
|
|
296
|
+
</style>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export default TagInput;
|
|
2
|
+
type TagInput = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLInputAttributes, keyof Props>>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const TagInput: import("svelte").Component<{
|
|
7
|
+
/**
|
|
8
|
+
* bindable
|
|
9
|
+
*/
|
|
10
|
+
value?: string[] | undefined;
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
hideLabel?: boolean | undefined;
|
|
14
|
+
placeholder?: string | undefined;
|
|
15
|
+
info?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
18
|
+
*/
|
|
19
|
+
note?: string | undefined;
|
|
20
|
+
error?: string | undefined;
|
|
21
|
+
separator?: RegExp | undefined;
|
|
22
|
+
normalize?: ((text: string) => string) | undefined;
|
|
23
|
+
validate?: ((tag: string) => string | null | undefined) | null | undefined;
|
|
24
|
+
} & Omit<import("svelte/elements").HTMLInputAttributes, keyof {
|
|
25
|
+
/**
|
|
26
|
+
* bindable
|
|
27
|
+
*/
|
|
28
|
+
value?: string[] | undefined;
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
hideLabel?: boolean | undefined;
|
|
32
|
+
placeholder?: string | undefined;
|
|
33
|
+
info?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
36
|
+
*/
|
|
37
|
+
note?: string | undefined;
|
|
38
|
+
error?: string | undefined;
|
|
39
|
+
separator?: RegExp | undefined;
|
|
40
|
+
normalize?: ((text: string) => string) | undefined;
|
|
41
|
+
validate?: ((tag: string) => string | null | undefined) | null | undefined;
|
|
42
|
+
}>, {}, "value">;
|
|
43
|
+
type Props = {
|
|
44
|
+
/**
|
|
45
|
+
* bindable
|
|
46
|
+
*/
|
|
47
|
+
value?: string[] | undefined;
|
|
48
|
+
id: string;
|
|
49
|
+
label: string;
|
|
50
|
+
hideLabel?: boolean | undefined;
|
|
51
|
+
placeholder?: string | undefined;
|
|
52
|
+
info?: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
55
|
+
*/
|
|
56
|
+
note?: string | undefined;
|
|
57
|
+
error?: string | undefined;
|
|
58
|
+
separator?: RegExp | undefined;
|
|
59
|
+
normalize?: ((text: string) => string) | undefined;
|
|
60
|
+
validate?: ((tag: string) => string | null | undefined) | null | undefined;
|
|
61
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Multi-line text field matching TextField (Linear's composer): the shared .field-box (faint fill, inset hairline
|
|
4
|
+
* with a lit top edge, 8px corners, indigo hairline and ring while focused). Grows with its content up to 40% of the window, then scrolls; resizable.
|
|
5
|
+
* Other props (placeholder, events, autofocus, data-*) go to the <textarea>. Call focus() to jump into it.
|
|
6
|
+
* error: a message from the app; the field turns red and shows it in a bubble underneath, which can be dismissed. Native constraints (`required`,
|
|
7
|
+
* `minlength`…) report the browser's own message the same way. See lib/validity.js.
|
|
8
|
+
* info: what the field is for or how to fill it, behind an ⓘ next to the label (see InfoTip).
|
|
9
|
+
* note: dimmed text after the label, such as '(optional)' (see .label-note); screen readers read it as part of the label.
|
|
10
|
+
*/
|
|
11
|
+
import ErrorMessage from '../ErrorMessage.svelte'
|
|
12
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
13
|
+
import { validity } from '../../lib/validity.js'
|
|
14
|
+
import { invalid } from '../../lib/invalid.js'
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} Props
|
|
17
|
+
* @property {string} [value] bindable
|
|
18
|
+
* @property {string} id
|
|
19
|
+
* @property {string} label
|
|
20
|
+
* @property {boolean} [hideLabel]
|
|
21
|
+
* @property {number} [rows]
|
|
22
|
+
* @property {string} [error]
|
|
23
|
+
* @property {string} [info]
|
|
24
|
+
* @property {string} [note] dimmed text after the label, e.g. '(optional)'
|
|
25
|
+
*/
|
|
26
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLTextareaAttributes, keyof Props>} */
|
|
27
|
+
let { value = $bindable(''), id, label, hideLabel = false, rows = 3, error = '', info = '', note = '', ...rest } = $props()
|
|
28
|
+
let area = $state()
|
|
29
|
+
let native = $state('') // the browser's message for a failed native constraint
|
|
30
|
+
const problem = $derived(error || native)
|
|
31
|
+
export const focus = () => area?.focus()
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<div class="field">
|
|
35
|
+
<FieldLabel for={id} {label} {note} {info} {hideLabel} />
|
|
36
|
+
<!-- The box draws the field; the textarea inside is bare. -->
|
|
37
|
+
<div class="box field-box">
|
|
38
|
+
<!-- svelte-ignore a11y_autofocus -->
|
|
39
|
+
<textarea
|
|
40
|
+
{id}
|
|
41
|
+
{rows}
|
|
42
|
+
bind:this={area}
|
|
43
|
+
bind:value
|
|
44
|
+
{...rest}
|
|
45
|
+
{@attach invalid(problem && `${id}-error`)}
|
|
46
|
+
{@attach validity(
|
|
47
|
+
() => error,
|
|
48
|
+
(message) => (native = message),
|
|
49
|
+
)}></textarea>
|
|
50
|
+
</div>
|
|
51
|
+
<ErrorMessage floating id="{id}-error" message={problem} ondismiss={() => area?.focus()} />
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<style>
|
|
55
|
+
.field {
|
|
56
|
+
position: relative;
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
gap: 3px;
|
|
60
|
+
min-width: min(100%, 240px);
|
|
61
|
+
}
|
|
62
|
+
/* Its width doesn't follow the text (contain): field-sizing would otherwise widen it with every long line where
|
|
63
|
+
the field sizes to its content (a flex row). It keeps its 240px and grows only downward. */
|
|
64
|
+
.box {
|
|
65
|
+
contain: inline-size;
|
|
66
|
+
}
|
|
67
|
+
textarea {
|
|
68
|
+
display: block;
|
|
69
|
+
width: 100%;
|
|
70
|
+
min-height: 72px;
|
|
71
|
+
max-height: 40dvh;
|
|
72
|
+
resize: vertical;
|
|
73
|
+
field-sizing: content;
|
|
74
|
+
padding: 10px 12px 12px;
|
|
75
|
+
border: 0;
|
|
76
|
+
border-radius: inherit;
|
|
77
|
+
background: none;
|
|
78
|
+
outline: none;
|
|
79
|
+
font: 400 13px/20px var(--font-body);
|
|
80
|
+
color: var(--fg);
|
|
81
|
+
}
|
|
82
|
+
textarea::placeholder {
|
|
83
|
+
color: var(--faint);
|
|
84
|
+
opacity: 1;
|
|
85
|
+
}
|
|
86
|
+
</style>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export default TextArea;
|
|
2
|
+
type TextArea = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props & Omit<HTMLTextareaAttributes, keyof Props>>): void;
|
|
5
|
+
} & {
|
|
6
|
+
focus: () => any;
|
|
7
|
+
};
|
|
8
|
+
declare const TextArea: import("svelte").Component<{
|
|
9
|
+
/**
|
|
10
|
+
* bindable
|
|
11
|
+
*/
|
|
12
|
+
value?: string | undefined;
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
hideLabel?: boolean | undefined;
|
|
16
|
+
rows?: number | undefined;
|
|
17
|
+
error?: string | undefined;
|
|
18
|
+
info?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
21
|
+
*/
|
|
22
|
+
note?: string | undefined;
|
|
23
|
+
} & Omit<import("svelte/elements").HTMLTextareaAttributes, keyof {
|
|
24
|
+
/**
|
|
25
|
+
* bindable
|
|
26
|
+
*/
|
|
27
|
+
value?: string | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
label: string;
|
|
30
|
+
hideLabel?: boolean | undefined;
|
|
31
|
+
rows?: number | undefined;
|
|
32
|
+
error?: string | undefined;
|
|
33
|
+
info?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
36
|
+
*/
|
|
37
|
+
note?: string | undefined;
|
|
38
|
+
}>, {
|
|
39
|
+
focus: () => any;
|
|
40
|
+
}, "value">;
|
|
41
|
+
type Props = {
|
|
42
|
+
/**
|
|
43
|
+
* bindable
|
|
44
|
+
*/
|
|
45
|
+
value?: string | undefined;
|
|
46
|
+
id: string;
|
|
47
|
+
label: string;
|
|
48
|
+
hideLabel?: boolean | undefined;
|
|
49
|
+
rows?: number | undefined;
|
|
50
|
+
error?: string | undefined;
|
|
51
|
+
info?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* dimmed text after the label, e.g. '(optional)'
|
|
54
|
+
*/
|
|
55
|
+
note?: string | undefined;
|
|
56
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import ErrorMessage from '../ErrorMessage.svelte'
|
|
3
|
+
import Icon from '../Icon.svelte'
|
|
4
|
+
import FieldLabel from './FieldLabel.svelte'
|
|
5
|
+
import { tooltip } from '../../lib/tooltip.js'
|
|
6
|
+
import { validity } from '../../lib/validity.js'
|
|
7
|
+
import { composing } from '../../lib/dom.js'
|
|
8
|
+
import { invalid } from '../../lib/invalid.js'
|
|
9
|
+
/**
|
|
10
|
+
* Text input with optional search icon and shortcut hint; search fields (type 'search') also get a clear button, and Esc clears them. `compact`: 28px, for toolbars (see SearchField).
|
|
11
|
+
* error: a message from the app; the field turns red and shows it in a bubble underneath, which can be dismissed. Native constraints work the same way:
|
|
12
|
+
* pass `required`, `pattern`, `minlength`… (any other attribute goes to the <input>) and the browser's own message
|
|
13
|
+
* shows there once its form is validated (never just for leaving the field). See lib/validity.js, and lib/field-errors.svelte.js
|
|
14
|
+
* for a form's worth of them.
|
|
15
|
+
* info: what the field is for or how to fill it, behind an ⓘ next to the label (see InfoTip).
|
|
16
|
+
* note: dimmed text after the label, such as '(optional)' (see .label-note); screen readers read it as part of the label.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} Props
|
|
20
|
+
* @property {string} [value] bindable
|
|
21
|
+
* @property {string} id
|
|
22
|
+
* @property {string} label
|
|
23
|
+
* @property {string} [placeholder]
|
|
24
|
+
* @property {string} [type] 'search' (the default) adds the search icon, the clear button and Esc to clear
|
|
25
|
+
* @property {boolean} [icon]
|
|
26
|
+
* @property {string | null} [shortcut]
|
|
27
|
+
* @property {boolean} [hideLabel]
|
|
28
|
+
* @property {boolean} [compact]
|
|
29
|
+
* @property {((value: string) => void) | null} [onenter]
|
|
30
|
+
* @property {string} [error]
|
|
31
|
+
* @property {string} [info]
|
|
32
|
+
* @property {string} [note] dimmed text after the label, e.g. '(optional)'
|
|
33
|
+
*/
|
|
34
|
+
/** @type {Props & Omit<import('svelte/elements').HTMLInputAttributes, keyof Props>} */
|
|
35
|
+
let {
|
|
36
|
+
value = $bindable(''),
|
|
37
|
+
id,
|
|
38
|
+
label,
|
|
39
|
+
placeholder = '',
|
|
40
|
+
type = 'search',
|
|
41
|
+
icon = type === 'search',
|
|
42
|
+
shortcut = null,
|
|
43
|
+
hideLabel = false,
|
|
44
|
+
compact = false,
|
|
45
|
+
onenter = null,
|
|
46
|
+
error = '',
|
|
47
|
+
info = '',
|
|
48
|
+
note = '',
|
|
49
|
+
...rest
|
|
50
|
+
} = $props()
|
|
51
|
+
let input = $state()
|
|
52
|
+
let native = $state('') // the browser's message for a failed native constraint
|
|
53
|
+
const problem = $derived(error || native)
|
|
54
|
+
export const focus = () => input?.focus()
|
|
55
|
+
|
|
56
|
+
function onkeydown(e) {
|
|
57
|
+
// Enter and Esc inside an IME composition belong to the input method.
|
|
58
|
+
if (composing(e)) return
|
|
59
|
+
if (e.key === 'Escape' && value && type === 'search') {
|
|
60
|
+
e.preventDefault()
|
|
61
|
+
e.stopPropagation()
|
|
62
|
+
value = ''
|
|
63
|
+
} else if (e.key === 'Enter' && onenter) {
|
|
64
|
+
e.preventDefault()
|
|
65
|
+
onenter(value)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div class="field">
|
|
71
|
+
<FieldLabel for={id} {label} {note} {info} {hideLabel} />
|
|
72
|
+
<div class="box field-box" class:compact>
|
|
73
|
+
{#if icon}
|
|
74
|
+
<span class="lead"><Icon name="search" /></span>
|
|
75
|
+
{/if}
|
|
76
|
+
<input
|
|
77
|
+
{id}
|
|
78
|
+
bind:this={input}
|
|
79
|
+
bind:value
|
|
80
|
+
type="text"
|
|
81
|
+
inputmode={type === 'search' ? 'search' : undefined}
|
|
82
|
+
{placeholder}
|
|
83
|
+
autocomplete="off"
|
|
84
|
+
spellcheck="false"
|
|
85
|
+
autocapitalize="none"
|
|
86
|
+
autocorrect="off"
|
|
87
|
+
enterkeyhint={type === 'search' ? 'search' : undefined}
|
|
88
|
+
{...rest}
|
|
89
|
+
{@attach invalid(problem && `${id}-error`)}
|
|
90
|
+
{onkeydown}
|
|
91
|
+
{@attach validity(
|
|
92
|
+
() => error,
|
|
93
|
+
(message) => (native = message),
|
|
94
|
+
)}
|
|
95
|
+
/>
|
|
96
|
+
{#if value && type === 'search'}
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
class="clear"
|
|
100
|
+
aria-label="Clear {label}"
|
|
101
|
+
{@attach tooltip('Clear')}
|
|
102
|
+
onclick={() => {
|
|
103
|
+
value = ''
|
|
104
|
+
input.focus()
|
|
105
|
+
}}><Icon name="x" size="sm" /></button
|
|
106
|
+
>
|
|
107
|
+
{:else if shortcut}
|
|
108
|
+
<kbd aria-hidden="true">{shortcut}</kbd>
|
|
109
|
+
{/if}
|
|
110
|
+
</div>
|
|
111
|
+
<ErrorMessage floating id="{id}-error" message={problem} ondismiss={() => input?.focus()} />
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<style>
|
|
115
|
+
.field {
|
|
116
|
+
position: relative;
|
|
117
|
+
display: flex;
|
|
118
|
+
flex-direction: column;
|
|
119
|
+
gap: 3px;
|
|
120
|
+
min-width: 0;
|
|
121
|
+
}
|
|
122
|
+
.box {
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
gap: 6px;
|
|
126
|
+
min-height: 32px;
|
|
127
|
+
padding: 0 6px 0 10px;
|
|
128
|
+
}
|
|
129
|
+
/* Compact (toolbars): shorter. */
|
|
130
|
+
.compact {
|
|
131
|
+
min-height: 28px;
|
|
132
|
+
}
|
|
133
|
+
.lead {
|
|
134
|
+
display: inline-flex;
|
|
135
|
+
color: var(--faint);
|
|
136
|
+
}
|
|
137
|
+
input {
|
|
138
|
+
all: unset;
|
|
139
|
+
flex: 1;
|
|
140
|
+
min-width: 0;
|
|
141
|
+
font-size: 13px;
|
|
142
|
+
color: var(--fg);
|
|
143
|
+
padding-block: 6px;
|
|
144
|
+
}
|
|
145
|
+
input::placeholder {
|
|
146
|
+
color: var(--faint);
|
|
147
|
+
opacity: 1;
|
|
148
|
+
}
|
|
149
|
+
@media (hover: none) {
|
|
150
|
+
kbd {
|
|
151
|
+
display: none;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
.clear {
|
|
155
|
+
display: inline-grid;
|
|
156
|
+
place-items: center;
|
|
157
|
+
border: 0;
|
|
158
|
+
background: none;
|
|
159
|
+
color: var(--muted);
|
|
160
|
+
width: 22px;
|
|
161
|
+
height: 22px;
|
|
162
|
+
border-radius: 50%;
|
|
163
|
+
padding: 0;
|
|
164
|
+
flex: none;
|
|
165
|
+
}
|
|
166
|
+
.clear:hover {
|
|
167
|
+
color: var(--fg);
|
|
168
|
+
background: var(--control-3);
|
|
169
|
+
}
|
|
170
|
+
</style>
|