@xerios/design-system 0.1.0 → 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/README.md CHANGED
@@ -168,7 +168,7 @@ wrapper for display components, the control itself (input, button) for inputs, P
168
168
  | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
169
169
  | `Icon` | Any icon (Phosphor regular) | `name`, `size` sm/md/lg, `label` (only if it carries meaning) |
170
170
  | `empty/` (`Empty`, `Empty.Error`) | Empty state; `Empty.Error` for a view that failed to load, with a retry (an alert) | `title`, `body`, `level`, `icon`, children for actions; Error: `title`, `message`, `onretry` (may be async), `retryLabel` |
171
- | `Button` | Every `.btn` / `.icon-btn` with behaviour: an icon, async actions (spinner and `pendingLabel` while the promise runs, presses ignored meanwhile, a rejection's message in a bubble under it), links drawn as buttons | `variant` secondary/primary/danger, `small`, `icon`, `iconOnly` + `label`, `href`, `type`, `onclick` (may return a promise), `pending`, `pendingLabel`, `onerror` |
171
+ | `Button` | Every `.btn` / `.icon-btn` with behaviour: an icon, async actions (spinner and `pendingLabel` while the promise runs, presses ignored meanwhile, a rejection's message in a bubble under it), links drawn as buttons | `variant` secondary/primary/danger, `small`, `icon`, `iconOnly` + `label`, `href`, `type`, `onclick` (may return a promise), `pending`, `pendingLabel`, `onerror`, `pressed` (bindable; a toggle) |
172
172
  | `ErrorMessage` | Error text: inline, or a dismissible bubble under a control | `message`, `id`, `floating`, `ondismiss` |
173
173
  | `Notice` | Inline notice about a standing condition | `tone`, `icon`, children for the text |
174
174
  | `Shimmer` | "Working…" text | `text` or children, `active`, `as` |
@@ -7,6 +7,7 @@
7
7
  * <Button iconOnly icon="refresh" label="Refresh" onclick={reload} />
8
8
  * <Button type="submit" form="new-site" variant="primary" pending={submitting}>Create</Button>
9
9
  * <Button href="/">Go to apps</Button>
10
+ * <Button icon="eye" bind:pressed={showHidden}>Show hidden</Button>
10
11
  *
11
12
  * onclick may return a promise. Until it settles the button is busy, drawn as Select is while loading: it drops its
12
13
  * fill (a solid one becomes an outlined pill), the working sweep runs along its edge (.shimmer) and its label shimmers
@@ -19,6 +20,8 @@
19
20
  * pending: busy from outside, e.g. a form submit button while its form's request runs.
20
21
  *
21
22
  * variant: secondary (default) | primary | danger. small: the 24px size. icon: an Icon name, before the label.
23
+ * pressed: makes it a toggle button (aria-pressed); each press flips it before onclick runs, so use bind:pressed.
24
+ * Toggled on, a secondary button drops its fill and keeps only its hairline. Leave it undefined for an ordinary button.
22
25
  * iconOnly: the round .icon-btn showing just the icon; `label` is then required, and becomes its accessible name and
23
26
  * its tooltip. href: a link drawn as a button (navigation, never an action). disabled: as on any button.
24
27
  * Other attributes (class, form, autofocus…) and attachments go to the <button> (or <a>).
@@ -42,6 +45,7 @@
42
45
  * @property {boolean} [pending]
43
46
  * @property {string} [pendingLabel]
44
47
  * @property {(error: unknown) => void} [onerror]
48
+ * @property {boolean} [pressed] a toggle button's state (bindable); undefined for an ordinary button
45
49
  * @property {boolean} [disabled]
46
50
  * @property {import('svelte').Snippet} [children]
47
51
  */
@@ -58,6 +62,7 @@
58
62
  pending = false,
59
63
  pendingLabel,
60
64
  onerror,
65
+ pressed = $bindable(),
61
66
  disabled = false,
62
67
  class: className,
63
68
  children,
@@ -89,6 +94,7 @@
89
94
  return
90
95
  }
91
96
  error = ''
97
+ if (pressed !== undefined) pressed = !pressed
92
98
  const result = onclick?.(event)
93
99
  if (!(result instanceof Promise)) return
94
100
  running = true
@@ -122,6 +128,7 @@
122
128
  style:anchor-name={anchor}
123
129
  {disabled}
124
130
  aria-label={iconOnly ? label : undefined}
131
+ aria-pressed={pressed}
125
132
  aria-busy={busy || undefined}
126
133
  aria-disabled={busy || undefined}
127
134
  aria-describedby={error ? `${uid}-error` : undefined}
@@ -18,6 +18,10 @@ declare const Button: import("svelte").Component<{
18
18
  pending?: boolean | undefined;
19
19
  pendingLabel?: string | undefined;
20
20
  onerror?: ((error: unknown) => void) | undefined;
21
+ /**
22
+ * a toggle button's state (bindable); undefined for an ordinary button
23
+ */
24
+ pressed?: boolean | undefined;
21
25
  disabled?: boolean | undefined;
22
26
  children?: import("svelte").Snippet<[]> | undefined;
23
27
  } & Omit<import("svelte/elements").HTMLButtonAttributes & import("svelte/elements").HTMLAnchorAttributes, keyof {
@@ -35,9 +39,13 @@ declare const Button: import("svelte").Component<{
35
39
  pending?: boolean | undefined;
36
40
  pendingLabel?: string | undefined;
37
41
  onerror?: ((error: unknown) => void) | undefined;
42
+ /**
43
+ * a toggle button's state (bindable); undefined for an ordinary button
44
+ */
45
+ pressed?: boolean | undefined;
38
46
  disabled?: boolean | undefined;
39
47
  children?: import("svelte").Snippet<[]> | undefined;
40
- }>, {}, "">;
48
+ }>, {}, "pressed">;
41
49
  type Props = {
42
50
  variant?: "secondary" | "primary" | "danger" | undefined;
43
51
  small?: boolean | undefined;
@@ -53,6 +61,10 @@ type Props = {
53
61
  pending?: boolean | undefined;
54
62
  pendingLabel?: string | undefined;
55
63
  onerror?: ((error: unknown) => void) | undefined;
64
+ /**
65
+ * a toggle button's state (bindable); undefined for an ordinary button
66
+ */
67
+ pressed?: boolean | undefined;
56
68
  disabled?: boolean | undefined;
57
69
  children?: import("svelte").Snippet<[]> | undefined;
58
70
  };
@@ -3,7 +3,9 @@
3
3
  * A row of filters drawn from data (Linear's view filters): one FilterChip per filter, then a funnel button that adds
4
4
  * one. The button lists the fields (with a search field when there are many); picking one shows its value editor in
5
5
  * the same panel, and the filter joins the row as soon as it has a value. A field already filtered opens its chip
6
- * instead, so each field has one filter. Unticking every value of a filter removes it as its panel closes.
6
+ * instead, so each field has one filter. A filter left with no value (every value unticked, every word removed) leaves
7
+ * `filters` at once, so nothing filters by it; its chip stays on the row until its panel closes, and picking a value
8
+ * again puts it back in its place.
7
9
  *
8
10
  * <FilterBar bind:filters fields={[
9
11
  * { key: 'status', label: 'Status', icon: 'circleDashed', options: [{ value: 'open', label: 'Open', icon: 'checkCircle', tone: 'success', hint: '12 items' }, …], plural: 'statuses' },
@@ -28,8 +30,9 @@
28
30
  * onchange(filters): after every edit. label: the row's accessible name ("Filters"). addLabel: the button's ("Add filter").
29
31
  * panel: snippet ({ filter, field, set, close }) for a custom field's editor: set(value) stores a value, close() closes.
30
32
  * summary: snippet ({ filter, field }) drawing a custom field's value on its chip (default: the value as text).
31
- * Keyboard: the chips' parts and the add button are in the tab order. In the add panel, Backspace in an empty search
32
- * goes from a field's values back to the field list. Removing a filter moves the focus to the next one, else the button.
33
+ * Keyboard: the chips' parts and the add button are in the tab order. In the add panel, Backspace on a field's values
34
+ * goes back to the field list, unless it deletes something there (typed text, a word). Removing a filter moves the focus
35
+ * to the next one, else the button.
33
36
  * Other attributes (class…) and attachments go to the row.
34
37
  */
35
38
  import { tick } from 'svelte'
@@ -40,6 +43,7 @@
40
43
  import TagInput from '../inputs/TagInput.svelte'
41
44
  import Panel from './Panel.svelte'
42
45
  import { tooltip } from '../../lib/tooltip.js'
46
+ import { composing } from '../../lib/dom.js'
43
47
  import { datePresets, formatDay, relativeDay } from '../../lib/dates.js'
44
48
 
45
49
  /**
@@ -78,6 +82,14 @@
78
82
  let openKey = $state(/** @type {string | null} */ (null))
79
83
  /** The add panel: closed, listing the fields, or showing one field's values. */
80
84
  let adding = $state(/** @type {null | { key: string | null }} */ (null))
85
+ /** A filter emptied while its panel is open: out of `filters`, but its chip stays on the row (at `at`) until it closes. */
86
+ let held = $state(/** @type {null | { at: number, filter: Filter }} */ (null))
87
+ /** The chips on the row: the filters, with the held one back in its place. */
88
+ const rows = $derived.by(() => {
89
+ if (!held || filters.some((x) => x.field === held?.filter.field)) return filters
90
+ const at = Math.min(held.at, filters.length)
91
+ return [...filters.slice(0, at), held.filter, ...filters.slice(at)]
92
+ })
81
93
 
82
94
  const byKey = $derived(new Map(fields.map((f) => [f.key, f])))
83
95
  /** @param {Field} f */
@@ -91,7 +103,9 @@
91
103
  /** @param {any} v */
92
104
  const isEmpty = (v) => v == null || v === '' || (Array.isArray(v) && !v.length)
93
105
  /** @param {string} key */
94
- const find = (key) => filters.find((x) => x.field === key)
106
+ const find = (key) => rows.find((x) => x.field === key)
107
+ /** @param {string} key */
108
+ const isHeld = (key) => held?.filter.field === key
95
109
 
96
110
  /** @param {Filter[]} next */
97
111
  function commitAll(next) {
@@ -100,7 +114,24 @@
100
114
  }
101
115
  /** @param {string} key @param {Partial<Filter>} patch */
102
116
  function update(key, patch) {
103
- commitAll(filters.map((x) => (x.field === key ? { ...x, ...patch } : x)))
117
+ if (held && isHeld(key)) {
118
+ const filter = { ...held.filter, ...patch }
119
+ if (isEmpty(filter.value)) held = { ...held, filter }
120
+ else {
121
+ const at = Math.min(held.at, filters.length)
122
+ held = null
123
+ commitAll([...filters.slice(0, at), filter, ...filters.slice(at)])
124
+ }
125
+ return
126
+ }
127
+ const at = filters.findIndex((x) => x.field === key)
128
+ if (at < 0) return
129
+ const filter = { ...filters[at], ...patch }
130
+ if (isEmpty(filter.value)) {
131
+ // Nothing to filter by: out of `filters` now, its chip held on the row until its panel closes.
132
+ held = { at, filter }
133
+ commitAll(filters.filter((_, i) => i !== at))
134
+ } else commitAll(filters.map((x, i) => (i === at ? filter : x)))
104
135
  }
105
136
  /** Stores a value for a field: on its filter, or as a new one once there is something to filter by. @param {string} key @param {any} value */
106
137
  function put(key, value) {
@@ -109,19 +140,21 @@
109
140
  if (find(key)) update(key, { value })
110
141
  else if (!isEmpty(value)) commitAll([...filters, { field: key, op: operatorsOf(field)[0], value }])
111
142
  }
112
- /** Drops a field's filter if it has nothing left to filter by. @param {string} key */
143
+ /** Drops a field's chip if it has nothing left to filter by. @param {string} key */
113
144
  function prune(key) {
114
- const f = find(key)
145
+ if (isHeld(key)) held = null
146
+ const f = filters.find((x) => x.field === key)
115
147
  if (f && isEmpty(f.value)) commitAll(filters.filter((x) => x !== f))
116
148
  }
117
149
  /** @param {string} key */
118
150
  async function remove(key) {
119
- const at = filters.findIndex((x) => x.field === key)
151
+ const at = rows.findIndex((x) => x.field === key)
120
152
  if (at < 0) return
121
153
  if (openKey === key) openKey = null
154
+ if (isHeld(key)) held = null
122
155
  commitAll(filters.filter((x) => x.field !== key))
123
156
  await tick()
124
- const next = filters[at] ?? filters[at - 1]
157
+ const next = rows[at] ?? rows[at - 1]
125
158
  if (next) chips[next.field]?.focus()
126
159
  else addButton?.focus()
127
160
  }
@@ -150,6 +183,26 @@
150
183
  })
151
184
  }
152
185
 
186
+ /** Attachment on the add panel's value step: Backspace goes back to the field list, whichever editor has the focus,
187
+ * unless the editor used it (a TagInput removing a word) or it deletes text where it was pressed.
188
+ * @param {() => void} back */
189
+ const NOT_TYPED = new Set(['checkbox', 'radio', 'button', 'submit', 'reset', 'range', 'color', 'file', 'image'])
190
+ const backOnBackspace = (back) => (/** @type {HTMLElement} */ node) => {
191
+ /** @param {KeyboardEvent} e */
192
+ const onkeydown = (e) => {
193
+ if (e.key !== 'Backspace' || e.defaultPrevented || composing(e) || e.ctrlKey || e.metaKey || e.altKey) return
194
+ const t = /** @type {HTMLElement} */ (e.target)
195
+ if (t.isContentEditable && t.textContent) return
196
+ // Text a Backspace would delete (a checkbox's or a button-like input's value isn't).
197
+ if (t instanceof HTMLTextAreaElement && t.value && !t.readOnly) return
198
+ if (t instanceof HTMLInputElement && t.value && !t.readOnly && !NOT_TYPED.has(t.type)) return
199
+ e.preventDefault()
200
+ back()
201
+ }
202
+ node.addEventListener('keydown', onkeydown)
203
+ return () => node.removeEventListener('keydown', onkeydown)
204
+ }
205
+
153
206
  /** @param {Filter} filter @param {Field} field */
154
207
  const presetOf = (filter, field) => (field.presets ?? datePresets()).find((p) => p.value === filter.value)
155
208
  /** @param {Filter} filter @param {Field} field */
@@ -164,7 +217,7 @@
164
217
  }
165
218
  </script>
166
219
 
167
- {#snippet editor(/** @type {Field} */ field, /** @type {Filter} */ current, /** @type {() => void} */ close, /** @type {(() => void) | undefined} */ back)}
220
+ {#snippet editor(/** @type {Field} */ field, /** @type {Filter} */ current, /** @type {() => void} */ close)}
168
221
  {#if kindOf(field) === 'options'}
169
222
  <OptionList
170
223
  value={current.value ?? []}
@@ -172,7 +225,6 @@
172
225
  label={field.label}
173
226
  search={field.search ?? 'auto'}
174
227
  onchange={(v) => put(field.key, v)}
175
- onback={back}
176
228
  />
177
229
  {:else if kindOf(field) === 'date'}
178
230
  <DateFilter
@@ -227,10 +279,10 @@
227
279
  {/snippet}
228
280
 
229
281
  <div class={['filter-bar', className]} role="group" aria-label={label} {...rest}>
230
- {#each filters as filter (filter.field)}
282
+ {#each rows as filter (filter.field)}
231
283
  {@const field = byKey.get(filter.field)}
232
284
  {#if field}
233
- {#snippet editPanel(/** @type {{ close: () => void }} */ { close })}{@render editor(field, filter, close, undefined)}{/snippet}
285
+ {#snippet editPanel(/** @type {{ close: () => void }} */ { close })}{@render editor(field, filter, close)}{/snippet}
234
286
  <FilterChip
235
287
  bind:this={chips[filter.field]}
236
288
  field={{ label: field.label, icon: field.icon }}
@@ -266,8 +318,15 @@
266
318
  <Panel anchor={addButton} name={anchor} label={field ? field.label : addLabel} onclose={closeAdding}>
267
319
  {#if field}
268
320
  {#key field.key}
269
- <div class="step" {@attach focusIn}>
270
- {@render editor(field, find(field.key) ?? { field: field.key, op: operatorsOf(field)[0], value: null }, () => closeAdding(true), () => (adding = { key: null }))}
321
+ <div
322
+ class="step"
323
+ {@attach focusIn}
324
+ {@attach backOnBackspace(() => {
325
+ prune(field.key)
326
+ adding = { key: null }
327
+ })}
328
+ >
329
+ {@render editor(field, find(field.key) ?? { field: field.key, op: operatorsOf(field)[0], value: null }, () => closeAdding(true))}
271
330
  </div>
272
331
  {/key}
273
332
  {:else}
@@ -48,10 +48,9 @@
48
48
  width: fit-content;
49
49
  max-width: 100%;
50
50
  border-radius: var(--r-pill);
51
- background: var(--control-2);
52
- box-shadow:
53
- inset 0 0 0 1px var(--line),
54
- var(--shadow-btn);
51
+ /* Flat at rest; only the chosen option is raised. */
52
+ background: var(--control-1);
53
+ box-shadow: inset 0 0 0 1px var(--line);
55
54
  }
56
55
  button {
57
56
  display: inline-flex;
@@ -72,7 +71,8 @@
72
71
  white-space: nowrap;
73
72
  transition:
74
73
  color var(--dur) var(--ease-out),
75
- background-color var(--dur) var(--ease-out);
74
+ background-color var(--dur) var(--ease-out),
75
+ box-shadow var(--dur) var(--ease-out);
76
76
  }
77
77
  button + button {
78
78
  box-shadow: inset 1px 0 0 var(--line);
@@ -92,6 +92,12 @@
92
92
  }
93
93
  [aria-checked='true'] {
94
94
  background: var(--control-4);
95
+ box-shadow: var(--shadow-btn);
96
+ }
97
+ button + [aria-checked='true'] {
98
+ box-shadow:
99
+ inset 1px 0 0 var(--line),
100
+ var(--shadow-btn);
95
101
  }
96
102
  button :global(.icon) {
97
103
  flex: none;
@@ -78,12 +78,10 @@
78
78
  width: fit-content;
79
79
  max-width: 100%;
80
80
  padding: 2px;
81
- /* Sunken like a field (--sunken-*), so the raised thumb reads as sitting in a track. */
81
+ /* A clear track under a hairline, so only the raised thumb is filled and casts a shadow. */
82
82
  border-radius: var(--r);
83
- background: var(--control-2);
84
- box-shadow:
85
- inset 0 0 0 1px var(--line),
86
- var(--shadow-sm);
83
+ background: transparent;
84
+ box-shadow: inset 0 0 0 1px var(--line);
87
85
  /* The thumb sits at z-index -1 in here: under every segment's content, even while it slides across them. */
88
86
  isolation: isolate;
89
87
  }
@@ -120,7 +118,7 @@
120
118
  box-shadow var(--dur) var(--ease-out);
121
119
  }
122
120
  button:not([aria-checked='true']):hover {
123
- background: var(--control-3);
121
+ background: var(--control-2);
124
122
  }
125
123
  [aria-checked='true'] {
126
124
  color: var(--fg);
@@ -132,8 +130,8 @@
132
130
  z-index: -1;
133
131
  border-radius: inherit;
134
132
  pointer-events: none;
135
- /* Raised (--shadow-btn) out of the sunken track, with a hairline so light's white thumb has an edge. */
136
- background: var(--elevated);
133
+ /* Filled like ButtonGroup's chosen option (--control-4) and raised (--shadow-btn), with a hairline for an edge. */
134
+ background: var(--control-4);
137
135
  box-shadow:
138
136
  inset 0 0 0 1px var(--line),
139
137
  var(--shadow-btn);
@@ -50,10 +50,9 @@
50
50
  border: 0;
51
51
  border-radius: var(--r-pill);
52
52
  padding: 0 10px;
53
- background: var(--control-2);
54
- box-shadow:
55
- inset 0 0 0 1px var(--line),
56
- var(--shadow-btn);
53
+ /* Flat at rest; only the chosen option is raised. */
54
+ background: var(--control-1);
55
+ box-shadow: inset 0 0 0 1px var(--line);
57
56
  font-size: 12px;
58
57
  line-height: 14px;
59
58
  font-weight: var(--w-medium);
@@ -61,13 +60,17 @@
61
60
  color: var(--fg);
62
61
  transition:
63
62
  color var(--dur) var(--ease-out),
64
- background-color var(--dur) var(--ease-out);
63
+ background-color var(--dur) var(--ease-out),
64
+ box-shadow var(--dur) var(--ease-out);
65
65
  }
66
66
  button:not([aria-checked='true']):hover {
67
- background: var(--control-3);
67
+ background: var(--control-2);
68
68
  }
69
69
  [aria-checked='true'] {
70
70
  background: var(--control-4);
71
+ box-shadow:
72
+ inset 0 0 0 1px var(--line),
73
+ var(--shadow-btn);
71
74
  }
72
75
  /* Something finished behind this option (e.g. research done): its icon turns green. */
73
76
  [data-done] :global(.icon) {
@@ -2,7 +2,9 @@
2
2
 
3
3
  /* ---------- controls ---------- */
4
4
  /* Linear's pill buttons: secondary is a translucent fill with an inset hairline; primary is solid indigo; icon buttons are ghost circles.
5
- The solid buttons (primary, danger) are raised: their top inner edge catches the light. */
5
+ The solid buttons (primary, danger) are raised: their top inner edge catches the light.
6
+ A toggled secondary button (aria-pressed="true", Button's `pressed`) is flat: just its usual hairline, no fill at rest. It
7
+ still fills on hover and press (the rules below outrank it), and its text stays --fg. */
6
8
  .btn {
7
9
  display: inline-flex;
8
10
  align-items: center;
@@ -32,6 +34,11 @@
32
34
  filter var(--dur) var(--ease-out);
33
35
  }
34
36
 
37
+ .btn:where([aria-pressed='true']) {
38
+ background: none;
39
+ box-shadow: none;
40
+ }
41
+
35
42
  .btn :where(.icon) {
36
43
  color: var(--muted);
37
44
  transition: color var(--dur) var(--ease-out);
package/dist/css/base.css CHANGED
@@ -294,7 +294,8 @@ kbd {
294
294
  [role='radio'][aria-checked='true'],
295
295
  [role='option'].active,
296
296
  [role^='menuitem']:focus,
297
- .icon-btn:is([aria-pressed='true'], [aria-expanded='true']) {
297
+ .icon-btn:is([aria-pressed='true'], [aria-expanded='true']),
298
+ .btn[aria-pressed='true'] {
298
299
  background: Highlight !important;
299
300
  color: HighlightText !important;
300
301
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xerios/design-system",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Linear-style design system for Svelte 5: theme tokens, global CSS and generic components",
5
5
  "keywords": [
6
6
  "svelte",