@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.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -2
  3. package/dist/components/AnchorHeading.svelte +79 -0
  4. package/dist/components/AnchorHeading.svelte.d.ts +28 -0
  5. package/dist/components/Breadcrumbs.svelte +216 -0
  6. package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
  7. package/dist/components/Button.svelte +178 -0
  8. package/dist/components/Button.svelte.d.ts +58 -0
  9. package/dist/components/Canvas.svelte +248 -0
  10. package/dist/components/Canvas.svelte.d.ts +91 -0
  11. package/dist/components/Collapsible.svelte +139 -0
  12. package/dist/components/Collapsible.svelte.d.ts +52 -0
  13. package/dist/components/CollapsibleAdvanced.svelte +174 -0
  14. package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
  15. package/dist/components/DashOutline.svelte +47 -0
  16. package/dist/components/DashOutline.svelte.d.ts +6 -0
  17. package/dist/components/Dialogs.svelte +123 -0
  18. package/dist/components/Dialogs.svelte.d.ts +6 -0
  19. package/dist/components/Drawer.svelte +231 -0
  20. package/dist/components/Drawer.svelte.d.ts +62 -0
  21. package/dist/components/ErrorMessage.svelte +140 -0
  22. package/dist/components/ErrorMessage.svelte.d.ts +41 -0
  23. package/dist/components/Icon.svelte +94 -0
  24. package/dist/components/Icon.svelte.d.ts +33 -0
  25. package/dist/components/InfoTip.svelte +183 -0
  26. package/dist/components/InfoTip.svelte.d.ts +28 -0
  27. package/dist/components/Md.svelte +28 -0
  28. package/dist/components/Md.svelte.d.ts +11 -0
  29. package/dist/components/Modal.svelte +91 -0
  30. package/dist/components/Modal.svelte.d.ts +41 -0
  31. package/dist/components/Notice.svelte +50 -0
  32. package/dist/components/Notice.svelte.d.ts +30 -0
  33. package/dist/components/Popover.svelte +212 -0
  34. package/dist/components/Popover.svelte.d.ts +70 -0
  35. package/dist/components/Shimmer.svelte +27 -0
  36. package/dist/components/Shimmer.svelte.d.ts +22 -0
  37. package/dist/components/Splitter.svelte +152 -0
  38. package/dist/components/Splitter.svelte.d.ts +41 -0
  39. package/dist/components/Table.svelte +448 -0
  40. package/dist/components/Table.svelte.d.ts +268 -0
  41. package/dist/components/Toast.svelte +273 -0
  42. package/dist/components/Toast.svelte.d.ts +31 -0
  43. package/dist/components/Tooltip.svelte +97 -0
  44. package/dist/components/Tooltip.svelte.d.ts +19 -0
  45. package/dist/components/WorkingBorder.svelte +105 -0
  46. package/dist/components/WorkingBorder.svelte.d.ts +26 -0
  47. package/dist/components/empty/Empty.svelte +55 -0
  48. package/dist/components/empty/Empty.svelte.d.ts +39 -0
  49. package/dist/components/empty/EmptyError.svelte +47 -0
  50. package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
  51. package/dist/components/empty/index.d.ts +18 -0
  52. package/dist/components/empty/index.js +10 -0
  53. package/dist/components/filters/DateFilter.svelte +59 -0
  54. package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
  55. package/dist/components/filters/FilterBar.svelte +342 -0
  56. package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
  57. package/dist/components/filters/FilterChip.svelte +235 -0
  58. package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
  59. package/dist/components/filters/OptionList.svelte +352 -0
  60. package/dist/components/filters/OptionList.svelte.d.ts +91 -0
  61. package/dist/components/filters/Panel.svelte +123 -0
  62. package/dist/components/filters/Panel.svelte.d.ts +25 -0
  63. package/dist/components/filters/index.d.ts +288 -0
  64. package/dist/components/filters/index.js +12 -0
  65. package/dist/components/icons.d.ts +54 -0
  66. package/dist/components/icons.js +58 -0
  67. package/dist/components/inputs/ButtonGroup.svelte +104 -0
  68. package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
  69. package/dist/components/inputs/Calendar.svelte +535 -0
  70. package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
  71. package/dist/components/inputs/DateField.svelte +247 -0
  72. package/dist/components/inputs/DateField.svelte.d.ts +74 -0
  73. package/dist/components/inputs/DateInput.svelte +118 -0
  74. package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
  75. package/dist/components/inputs/DatePicker.svelte +102 -0
  76. package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
  77. package/dist/components/inputs/DateRangePicker.svelte +208 -0
  78. package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
  79. package/dist/components/inputs/DateRangeSelect.svelte +548 -0
  80. package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
  81. package/dist/components/inputs/FieldLabel.svelte +43 -0
  82. package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
  83. package/dist/components/inputs/ListSearch.svelte +142 -0
  84. package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
  85. package/dist/components/inputs/RadioGroup.svelte +153 -0
  86. package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
  87. package/dist/components/inputs/RangeShortcuts.svelte +90 -0
  88. package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
  89. package/dist/components/inputs/RangeSlider.svelte +225 -0
  90. package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
  91. package/dist/components/inputs/SearchField.svelte +24 -0
  92. package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
  93. package/dist/components/inputs/Segmented.svelte +76 -0
  94. package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
  95. package/dist/components/inputs/Select.svelte +552 -0
  96. package/dist/components/inputs/Select.svelte.d.ts +100 -0
  97. package/dist/components/inputs/Slider.svelte +177 -0
  98. package/dist/components/inputs/Slider.svelte.d.ts +33 -0
  99. package/dist/components/inputs/SliderTicks.svelte +62 -0
  100. package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
  101. package/dist/components/inputs/Switch.svelte +120 -0
  102. package/dist/components/inputs/Switch.svelte.d.ts +31 -0
  103. package/dist/components/inputs/TagInput.svelte +296 -0
  104. package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
  105. package/dist/components/inputs/TextArea.svelte +86 -0
  106. package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
  107. package/dist/components/inputs/TextField.svelte +170 -0
  108. package/dist/components/inputs/TextField.svelte.d.ts +80 -0
  109. package/dist/components/menu/ContextMenu.svelte +25 -0
  110. package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
  111. package/dist/components/menu/MenuButton.svelte +46 -0
  112. package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
  113. package/dist/components/menu/MenuList.svelte +319 -0
  114. package/dist/components/menu/MenuList.svelte.d.ts +30 -0
  115. package/dist/components/metadata/Metadata.svelte +38 -0
  116. package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
  117. package/dist/components/metadata/MetadataRow.svelte +84 -0
  118. package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
  119. package/dist/components/metadata/index.d.ts +8 -0
  120. package/dist/components/metadata/index.js +13 -0
  121. package/dist/components/side-menu/SideMenu.svelte +138 -0
  122. package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
  123. package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
  124. package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
  125. package/dist/components/side-menu/SideMenuItem.svelte +221 -0
  126. package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
  127. package/dist/components/side-menu/context.d.ts +1 -0
  128. package/dist/components/side-menu/context.js +3 -0
  129. package/dist/components/side-menu/index.d.ts +62 -0
  130. package/dist/components/side-menu/index.js +15 -0
  131. package/dist/components/tiles/Tile.svelte +419 -0
  132. package/dist/components/tiles/Tile.svelte.d.ts +58 -0
  133. package/dist/components/tiles/TileGroup.svelte +135 -0
  134. package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
  135. package/dist/components/tiles/context.d.ts +35 -0
  136. package/dist/components/tiles/context.js +14 -0
  137. package/dist/components/tiles/index.d.ts +6 -0
  138. package/dist/components/tiles/index.js +13 -0
  139. package/dist/components/upload/FileCard.svelte +301 -0
  140. package/dist/components/upload/FileCard.svelte.d.ts +127 -0
  141. package/dist/components/upload/Thumb.svelte +274 -0
  142. package/dist/components/upload/Thumb.svelte.d.ts +101 -0
  143. package/dist/components/upload/UploadFile.svelte +123 -0
  144. package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
  145. package/dist/components/upload/UploadFiles.svelte +177 -0
  146. package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
  147. package/dist/components/upload/UploadFolder.svelte +153 -0
  148. package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
  149. package/dist/components/upload/UploadImage.svelte +137 -0
  150. package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
  151. package/dist/components/upload/UploadImages.svelte +172 -0
  152. package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
  153. package/dist/components/upload/UploadZone.svelte +130 -0
  154. package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
  155. package/dist/components/upload/common.d.ts +31 -0
  156. package/dist/components/upload/common.js +103 -0
  157. package/dist/components/upload/context.d.ts +18 -0
  158. package/dist/components/upload/context.js +10 -0
  159. package/dist/components/upload/index.d.ts +16 -0
  160. package/dist/components/upload/index.js +18 -0
  161. package/dist/css/atoms.css +892 -0
  162. package/dist/css/base.css +333 -0
  163. package/dist/css/effects.css +430 -0
  164. package/dist/css/index.css +10 -0
  165. package/dist/css/tokens.css +296 -0
  166. package/dist/fonts.d.ts +1 -0
  167. package/dist/fonts.js +7 -0
  168. package/dist/index.d.ts +68 -0
  169. package/dist/index.js +77 -0
  170. package/dist/lib/announce.d.ts +8 -0
  171. package/dist/lib/announce.js +48 -0
  172. package/dist/lib/controls.d.ts +10 -0
  173. package/dist/lib/controls.js +42 -0
  174. package/dist/lib/dates.d.ts +104 -0
  175. package/dist/lib/dates.js +235 -0
  176. package/dist/lib/dialogs.svelte.d.ts +8 -0
  177. package/dist/lib/dialogs.svelte.js +45 -0
  178. package/dist/lib/dom.d.ts +34 -0
  179. package/dist/lib/dom.js +90 -0
  180. package/dist/lib/field-errors.svelte.d.ts +40 -0
  181. package/dist/lib/field-errors.svelte.js +89 -0
  182. package/dist/lib/files.d.ts +74 -0
  183. package/dist/lib/files.js +215 -0
  184. package/dist/lib/inline-md.d.ts +1 -0
  185. package/dist/lib/inline-md.js +36 -0
  186. package/dist/lib/invalid.d.ts +4 -0
  187. package/dist/lib/invalid.js +35 -0
  188. package/dist/lib/list-search.d.ts +9 -0
  189. package/dist/lib/list-search.js +27 -0
  190. package/dist/lib/menu.svelte.d.ts +39 -0
  191. package/dist/lib/menu.svelte.js +98 -0
  192. package/dist/lib/morph.svelte.d.ts +17 -0
  193. package/dist/lib/morph.svelte.js +46 -0
  194. package/dist/lib/motion.d.ts +115 -0
  195. package/dist/lib/motion.js +174 -0
  196. package/dist/lib/observe.d.ts +36 -0
  197. package/dist/lib/observe.js +142 -0
  198. package/dist/lib/reveal.d.ts +7 -0
  199. package/dist/lib/reveal.js +28 -0
  200. package/dist/lib/roving.d.ts +16 -0
  201. package/dist/lib/roving.js +35 -0
  202. package/dist/lib/runs.d.ts +18 -0
  203. package/dist/lib/runs.js +25 -0
  204. package/dist/lib/scroll-fade.d.ts +4 -0
  205. package/dist/lib/scroll-fade.js +71 -0
  206. package/dist/lib/spotlight.d.ts +4 -0
  207. package/dist/lib/spotlight.js +109 -0
  208. package/dist/lib/ticks.d.ts +12 -0
  209. package/dist/lib/ticks.js +24 -0
  210. package/dist/lib/tooltip.d.ts +4 -0
  211. package/dist/lib/tooltip.js +110 -0
  212. package/dist/lib/validity.d.ts +16 -0
  213. package/dist/lib/validity.js +36 -0
  214. 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>