@sveltia/ui 0.82.0 → 0.84.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.
@@ -1,20 +1,34 @@
1
1
  <!--
2
2
  @component
3
- The interactive version of `<TableColHeader>`.
3
+ The interactive version of `<TableColHeader>`. With `sortOrder` set, the header becomes sortable:
4
+ its content is wrapped in a button that indicates the current order and requests a new one.
4
5
  @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
5
6
  @see https://w3c.github.io/aria/#columnheader
7
+ @see https://www.w3.org/WAI/ARIA/apg/patterns/table/examples/sortable-table/
6
8
  -->
7
9
  <script>
10
+ import Button from '../button/button.svelte';
11
+ import Icon from '../icon/icon.svelte';
8
12
  import TablePart from '../table/table-part.svelte';
9
13
 
10
14
  /**
11
15
  * @import { Snippet } from 'svelte';
16
+ * @import { Attachment } from 'svelte/attachments';
12
17
  */
13
18
 
14
19
  /**
15
20
  * @typedef {object} Props
16
21
  * @property {string} [class] The `class` attribute on the wrapper element.
22
+ * @property {'ascending' | 'descending' | 'none'} [sortOrder] The order the column is sorted in,
23
+ * or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
24
+ * is only set on the sorted column, as the sortable table pattern recommends. When set, the
25
+ * content is rendered in a button that requests a new order with `onSort`; the button covers the
26
+ * whole cell, padding included. Leave it out for a header that can’t be sorted.
17
27
  * @property {Snippet} [children] Primary slot content.
28
+ * @property {(event: CustomEvent<{ sortOrder: 'ascending' | 'descending' }>) => void} [onSort]
29
+ * Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
30
+ * suggested next order: `descending` if the column is currently sorted in ascending order,
31
+ * otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
18
32
  */
19
33
 
20
34
  /**
@@ -22,9 +36,114 @@
22
36
  */
23
37
  let {
24
38
  /* eslint-disable prefer-const */
39
+ class: className,
40
+ sortOrder = undefined,
41
+ children,
42
+ onSort,
25
43
  ...restProps
26
44
  /* eslint-enable prefer-const */
27
45
  } = $props();
46
+
47
+ /**
48
+ * Keep the sort button’s clicks and activation keys from the `<Grid>`, which would otherwise
49
+ * select or focus the header row, or prevent the key’s default action, and call `onSort` instead.
50
+ * Native listeners are used because the grid listens on its own element, which a delegated Svelte
51
+ * event handler would only reach after the grid has handled the event. The arrow keys are left
52
+ * alone, so they still move from the header row to the data rows.
53
+ * @type {Attachment}
54
+ */
55
+ const handleSortButton = (element) => {
56
+ /**
57
+ * Handle the `click` event on the button.
58
+ * @param {Event} event `click` event.
59
+ */
60
+ const onClick = (event) => {
61
+ event.stopPropagation();
62
+ onSort?.(
63
+ new CustomEvent('Sort', {
64
+ detail: { sortOrder: sortOrder === 'ascending' ? 'descending' : 'ascending' },
65
+ }),
66
+ );
67
+ };
68
+
69
+ /**
70
+ * Handle the `keydown` event on the button.
71
+ * @param {Event} event `keydown` event.
72
+ */
73
+ const onKeyDown = (event) => {
74
+ const { key } = /** @type {KeyboardEvent} */ (event);
75
+
76
+ if (key === 'Enter' || key === ' ') {
77
+ event.stopPropagation();
78
+ }
79
+ };
80
+
81
+ element.addEventListener('click', onClick);
82
+ element.addEventListener('keydown', onKeyDown);
83
+
84
+ return () => {
85
+ element.removeEventListener('click', onClick);
86
+ element.removeEventListener('keydown', onKeyDown);
87
+ };
88
+ };
28
89
  </script>
29
90
 
30
- <TablePart {...restProps} role="columnheader" kind="grid-col-header" />
91
+ {#if sortOrder === undefined}
92
+ <TablePart {...restProps} role="columnheader" kind="grid-col-header" class={className}>
93
+ {@render children?.()}
94
+ </TablePart>
95
+ {:else}
96
+ <TablePart
97
+ {...restProps}
98
+ role="columnheader"
99
+ kind="grid-col-header"
100
+ class={className ? `sortable ${className}` : 'sortable'}
101
+ aria-sort={sortOrder === 'none' ? undefined : sortOrder}
102
+ >
103
+ <Button class="sort-button" {@attach handleSortButton}>
104
+ {@render children?.()}
105
+ {#snippet endIcon()}
106
+ <Icon
107
+ class="sort-icon {sortOrder}"
108
+ name={sortOrder === 'descending' ? 'arrow_downward' : 'arrow_upward'}
109
+ />
110
+ {/snippet}
111
+ </Button>
112
+ </TablePart>
113
+ {/if}
114
+
115
+ <style>:global(:where(.sui.grid-col-header.sortable)) {
116
+ position: relative;
117
+ }
118
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) {
119
+ justify-content: flex-start;
120
+ margin: 0;
121
+ border-radius: 0;
122
+ padding: 0;
123
+ width: 100%;
124
+ height: auto;
125
+ color: inherit;
126
+ font: inherit;
127
+ text-align: start;
128
+ }
129
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button::after) {
130
+ position: absolute;
131
+ inset: 0;
132
+ content: "";
133
+ }
134
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon) {
135
+ flex: none;
136
+ font-size: 16px;
137
+ transition: opacity 200ms;
138
+ }
139
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon.none) {
140
+ opacity: 0;
141
+ }
142
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button:is(:hover, :focus-visible)) :global(.sort-icon.none) {
143
+ opacity: 0.4;
144
+ }
145
+ @media (hover: none) {
146
+ :global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon.none) {
147
+ opacity: 0.4;
148
+ }
149
+ }</style>
@@ -4,28 +4,62 @@ type GridColHeader = {
4
4
  $set?(props: Partial<Props & Record<string, any>>): void;
5
5
  };
6
6
  /**
7
- * The interactive version of `<TableColHeader>`.
7
+ * The interactive version of `<TableColHeader>`. With `sortOrder` set, the header becomes sortable:
8
+ * its content is wrapped in a button that indicates the current order and requests a new one.
8
9
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
9
10
  * @see https://w3c.github.io/aria/#columnheader
11
+ * @see https://www.w3.org/WAI/ARIA/apg/patterns/table/examples/sortable-table/
10
12
  */
11
13
  declare const GridColHeader: import("svelte").Component<{
12
14
  /**
13
15
  * The `class` attribute on the wrapper element.
14
16
  */
15
17
  class?: string | undefined;
18
+ /**
19
+ * The order the column is sorted in,
20
+ * or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
21
+ * is only set on the sorted column, as the sortable table pattern recommends. When set, the
22
+ * content is rendered in a button that requests a new order with `onSort`; the button covers the
23
+ * whole cell, padding included. Leave it out for a header that can’t be sorted.
24
+ */
25
+ sortOrder?: "none" | "ascending" | "descending" | undefined;
16
26
  /**
17
27
  * Primary slot content.
18
28
  */
19
29
  children?: Snippet<[]> | undefined;
30
+ /**
31
+ * Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
32
+ * suggested next order: `descending` if the column is currently sorted in ascending order,
33
+ * otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
34
+ */
35
+ onSort?: ((event: CustomEvent<{
36
+ sortOrder: "ascending" | "descending";
37
+ }>) => void) | undefined;
20
38
  } & Record<string, any>, {}, "">;
21
39
  type Props = {
22
40
  /**
23
41
  * The `class` attribute on the wrapper element.
24
42
  */
25
43
  class?: string | undefined;
44
+ /**
45
+ * The order the column is sorted in,
46
+ * or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
47
+ * is only set on the sorted column, as the sortable table pattern recommends. When set, the
48
+ * content is rendered in a button that requests a new order with `onSort`; the button covers the
49
+ * whole cell, padding included. Leave it out for a header that can’t be sorted.
50
+ */
51
+ sortOrder?: "none" | "ascending" | "descending" | undefined;
26
52
  /**
27
53
  * Primary slot content.
28
54
  */
29
55
  children?: Snippet<[]> | undefined;
56
+ /**
57
+ * Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
58
+ * suggested next order: `descending` if the column is currently sorted in ascending order,
59
+ * otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
60
+ */
61
+ onSort?: ((event: CustomEvent<{
62
+ sortOrder: "ascending" | "descending";
63
+ }>) => void) | undefined;
30
64
  };
31
65
  import type { Snippet } from 'svelte';
@@ -6,6 +6,7 @@
6
6
  -->
7
7
  <script>
8
8
  import { _ } from '@sveltia/i18n';
9
+ import { setContext } from 'svelte';
9
10
  import TablePart from '../table/table-part.svelte';
10
11
 
11
12
  /**
@@ -26,6 +27,10 @@
26
27
  ...restProps
27
28
  /* eslint-enable prefer-const */
28
29
  } = $props();
30
+
31
+ // Tell the `<GridRow>`s inside that they are footer rows, such as a totals row, which can be
32
+ // focused but not selected, like header rows
33
+ setContext('sui:grid-unselectable-rows', true);
29
34
  </script>
30
35
 
31
36
  <TablePart
@@ -6,6 +6,7 @@
6
6
  -->
7
7
  <script>
8
8
  import { _ } from '@sveltia/i18n';
9
+ import { setContext } from 'svelte';
9
10
  import TablePart from '../table/table-part.svelte';
10
11
 
11
12
  /**
@@ -26,6 +27,9 @@
26
27
  ...restProps
27
28
  /* eslint-enable prefer-const */
28
29
  } = $props();
30
+
31
+ // Tell the `<GridRow>`s inside that they are header rows, which can be focused but not selected
32
+ setContext('sui:grid-unselectable-rows', true);
29
33
  </script>
30
34
 
31
35
  <TablePart
@@ -5,17 +5,20 @@
5
5
  @see https://w3c.github.io/aria/#row
6
6
  -->
7
7
  <script>
8
+ import { getContext } from 'svelte';
8
9
  import TablePart from '../table/table-part.svelte';
9
10
 
10
11
  /**
11
12
  * @import { Snippet } from 'svelte';
13
+ * @import { Attachment } from 'svelte/attachments';
12
14
  */
13
15
 
14
16
  /**
15
17
  * @typedef {object} Props
16
18
  * @property {string} [class] The `class` attribute on the wrapper element.
17
19
  * @property {boolean} [selected] Whether to select the widget. An alias of the `aria-selected`
18
- * attribute.
20
+ * attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
21
+ * never be selected.
19
22
  * @property {Snippet} [children] Primary slot content.
20
23
  * @property {(event: CustomEvent) => void} [onChange] Custom `Change` event handler.
21
24
  * @property {(event: CustomEvent) => void} [onSelect] Custom `Select` event handler.
@@ -30,6 +33,56 @@
30
33
  ...restProps
31
34
  /* eslint-enable prefer-const */
32
35
  } = $props();
36
+
37
+ /**
38
+ * Whether the row is a header or footer row inside `<GridHead>` or `<GridFoot>`. The grid’s arrow
39
+ * keys still land on it, but it can’t be selected, so it has no `aria-selected` state, even one
40
+ * passed as an attribute, and is marked for the group service to leave out of the selection.
41
+ */
42
+ const isUnselectableRow = getContext('sui:grid-unselectable-rows') === true;
43
+
44
+ const attributes = $derived.by(() => {
45
+ if (!isUnselectableRow) {
46
+ return { ...restProps, 'aria-selected': selected };
47
+ }
48
+
49
+ const { 'aria-selected': _ariaSelected, ...rest } = restProps;
50
+
51
+ return { ...rest, 'data-selectable': 'false' };
52
+ });
53
+
54
+ /**
55
+ * Move the focus from a header row to the first sort button in it when the row is activated,
56
+ * which the grid does by clicking the focused row on Enter. The arrow keys move from row to row,
57
+ * so this is how a keyboard user gets from the header row to the sort buttons, and on from there
58
+ * with Tab. A click on a cell is left alone, as the button covers its sortable cell.
59
+ * @type {Attachment}
60
+ */
61
+ const focusSortButton = (element) => {
62
+ /**
63
+ * Handle the `click` event on the row.
64
+ * @param {Event} event `click` event.
65
+ */
66
+ const listener = (event) => {
67
+ const button = /** @type {HTMLElement | null} */ (element.querySelector('.sort-button'));
68
+
69
+ if (event.target === element && button) {
70
+ // The grid would otherwise move the focus back to the row it has just clicked
71
+ event.stopPropagation();
72
+ button.focus();
73
+ }
74
+ };
75
+
76
+ element.addEventListener('click', listener);
77
+
78
+ return () => {
79
+ element.removeEventListener('click', listener);
80
+ };
81
+ };
33
82
  </script>
34
83
 
35
- <TablePart {...restProps} role="row" kind="grid-row" tabindex="0" aria-selected={selected} />
84
+ {#if isUnselectableRow}
85
+ <TablePart {...attributes} role="row" kind="grid-row" tabindex="0" {@attach focusSortButton} />
86
+ {:else}
87
+ <TablePart {...attributes} role="row" kind="grid-row" tabindex="0" />
88
+ {/if}
@@ -15,7 +15,8 @@ declare const GridRow: import("svelte").Component<{
15
15
  class?: string | undefined;
16
16
  /**
17
17
  * Whether to select the widget. An alias of the `aria-selected`
18
- * attribute.
18
+ * attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
19
+ * never be selected.
19
20
  */
20
21
  selected?: boolean | undefined;
21
22
  /**
@@ -38,7 +39,8 @@ type Props = {
38
39
  class?: string | undefined;
39
40
  /**
40
41
  * Whether to select the widget. An alias of the `aria-selected`
41
- * attribute.
42
+ * attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
43
+ * never be selected.
42
44
  */
43
45
  selected?: boolean | undefined;
44
46
  /**
@@ -5,6 +5,7 @@
5
5
  @see https://w3c.github.io/aria/#grid
6
6
  -->
7
7
  <script>
8
+ import { setContext } from 'svelte';
8
9
  import { activateGroup } from '../../services/group.svelte.js';
9
10
 
10
11
  /**
@@ -38,6 +39,10 @@
38
39
  ...restProps
39
40
  /* eslint-enable prefer-const */
40
41
  } = $props();
42
+
43
+ // A grid nested in a header or footer cell of another grid has data rows of its own, so the
44
+ // outer grid’s `<GridHead>` or `<GridFoot>` doesn’t make them unselectable
45
+ setContext('sui:grid-unselectable-rows', false);
41
46
  </script>
42
47
 
43
48
  <div
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
3
3
  */
4
- export const UI_VERSION: "0.82.0";
4
+ export const UI_VERSION: "0.84.0";
@@ -3,4 +3,4 @@
3
3
  /**
4
4
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
5
5
  */
6
- export const UI_VERSION = '0.82.0';
6
+ export const UI_VERSION = '0.84.0';
@@ -0,0 +1,129 @@
1
+ <!--
2
+ @component
3
+ A color swatch button that opens the browser’s color picker. The equivalent of the HTML
4
+ `<input type="color">` element, styled like the other controls.
5
+ @todo Replace the native `<input>` with a custom component.
6
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
7
+ -->
8
+ <script>
9
+ /**
10
+ * @import { CommonEventHandlers, InputEventHandlers } from '../../typedefs.js';
11
+ */
12
+
13
+ /**
14
+ * @typedef {object} Props
15
+ * @property {string} [value] Input value, a lowercase hex color in the `#rrggbb` format. The
16
+ * swatch shows black if no value is given.
17
+ * @property {HTMLInputElement} [element] Reference to the `<input>` element.
18
+ * @property {string} [class] The `class` attribute on the `<input>` element.
19
+ * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
20
+ * attribute.
21
+ * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
22
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
23
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
24
+ * can still be reached and read by keyboard and assistive technology users, unlike with
25
+ * `disabled`.
26
+ * @property {boolean} [required] Whether to mark the widget required. An alias of the
27
+ * `aria-required` attribute.
28
+ * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
29
+ * `aria-invalid` attribute.
30
+ * @property {string} [ariaLabel] `aria-label` attribute.
31
+ */
32
+
33
+ /**
34
+ * @type {CommonEventHandlers & InputEventHandlers & Props & Record<string, any>}
35
+ */
36
+ let {
37
+ /* eslint-disable prefer-const */
38
+ value = $bindable(),
39
+ element = $bindable(),
40
+ class: className,
41
+ disabled = false,
42
+ readonly = false,
43
+ required = false,
44
+ invalid = false,
45
+ ariaLabel = undefined,
46
+ onclick,
47
+ oninput,
48
+ ...restProps
49
+ /* eslint-enable prefer-const */
50
+ } = $props();
51
+
52
+ /**
53
+ * Handle the `click` event. Prevent the picker from opening while read-only; the keyboard
54
+ * activation with the Enter or Space key also fires a `click` event.
55
+ * @param {MouseEvent} event The `click` event object.
56
+ */
57
+ const handleClick = (event) => {
58
+ if (readonly) {
59
+ event.preventDefault();
60
+ }
61
+
62
+ onclick?.(event);
63
+ };
64
+
65
+ /**
66
+ * Update the `value` and call the `oninput` callback.
67
+ * @param {Event} event The `input` event object.
68
+ */
69
+ const handleInput = (event) => {
70
+ value = /** @type {HTMLInputElement} */ (event.currentTarget).value;
71
+ oninput?.(event);
72
+ };
73
+ </script>
74
+
75
+ <input
76
+ bind:this={element}
77
+ {...restProps}
78
+ value={value ?? ''}
79
+ type="color"
80
+ class="sui color-input {className}"
81
+ disabled={disabled || undefined}
82
+ aria-label={ariaLabel ?? restProps['aria-label']}
83
+ aria-disabled={disabled}
84
+ aria-readonly={readonly}
85
+ aria-required={required}
86
+ aria-invalid={invalid}
87
+ onclick={handleClick}
88
+ oninput={handleInput}
89
+ />
90
+
91
+ <style>.color-input {
92
+ display: inline-block;
93
+ margin: var(--sui-focus-ring-width);
94
+ border-width: var(--sui-color-input-border-width, 1px);
95
+ border-color: var(--sui-color-input-border-color, var(--sui-control-border-color));
96
+ border-radius: var(--sui-color-input-border-radius, var(--sui-button-medium-border-radius));
97
+ padding: var(--sui-color-input-padding, 3px);
98
+ width: var(--sui-color-input-width, calc(var(--sui-button-medium-height) * 1.5));
99
+ height: var(--sui-color-input-height, var(--sui-button-medium-height));
100
+ color: inherit;
101
+ background-color: var(--sui-color-input-background-color, var(--sui-textbox-background-color));
102
+ font-family: var(--sui-textbox-font-family);
103
+ cursor: pointer;
104
+ transition: all 200ms;
105
+ }
106
+ .color-input:is(:hover, :focus-visible) {
107
+ background-color: var(--sui-color-input-background-color-focus, var(--sui-hover-background-color));
108
+ }
109
+ .color-input:active {
110
+ background-color: var(--sui-color-input-background-color-active, var(--sui-active-background-color));
111
+ }
112
+ .color-input[aria-readonly=true] {
113
+ cursor: default;
114
+ background-color: var(--sui-disabled-background-color);
115
+ }
116
+ .color-input[aria-invalid=true] {
117
+ border-color: var(--sui-error-border-color);
118
+ }
119
+ .color-input::-webkit-color-swatch-wrapper {
120
+ padding: 0;
121
+ }
122
+ .color-input::-webkit-color-swatch {
123
+ border: 1px solid var(--sui-secondary-border-color);
124
+ border-radius: calc(var(--sui-button-medium-border-radius) / 2);
125
+ }
126
+ .color-input::-moz-color-swatch {
127
+ border: 1px solid var(--sui-secondary-border-color);
128
+ border-radius: calc(var(--sui-button-medium-border-radius) / 2);
129
+ }</style>
@@ -0,0 +1,96 @@
1
+ export default ColorInput;
2
+ type ColorInput = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<KeyboardEventHandlers & MouseEventHandlers & PointerEventHandlers & FocusEventHandlers & DragEventHandlers & InputEventHandlers & Props & Record<string, any>>): void;
5
+ };
6
+ /**
7
+ * A color swatch button that opens the browser’s color picker. The equivalent of the HTML
8
+ * `<input type="color">` element, styled like the other controls.
9
+ * @todo Replace the native `<input>` with a custom component.
10
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
11
+ */
12
+ declare const ColorInput: import("svelte").Component<import("../../typedefs.js").KeyboardEventHandlers & import("../../typedefs.js").MouseEventHandlers & import("../../typedefs.js").PointerEventHandlers & import("../../typedefs.js").FocusEventHandlers & import("../../typedefs.js").DragEventHandlers & InputEventHandlers & {
13
+ /**
14
+ * Input value, a lowercase hex color in the `#rrggbb` format. The
15
+ * swatch shows black if no value is given.
16
+ */
17
+ value?: string | undefined;
18
+ /**
19
+ * Reference to the `<input>` element.
20
+ */
21
+ element?: HTMLInputElement | undefined;
22
+ /**
23
+ * The `class` attribute on the `<input>` element.
24
+ */
25
+ class?: string | undefined;
26
+ /**
27
+ * Whether to disable the widget. An alias of the `aria-disabled`
28
+ * attribute.
29
+ */
30
+ disabled?: boolean | undefined;
31
+ /**
32
+ * Whether to make the widget read-only. An alias of the
33
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
34
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
35
+ * can still be reached and read by keyboard and assistive technology users, unlike with
36
+ * `disabled`.
37
+ */
38
+ readonly?: boolean | undefined;
39
+ /**
40
+ * Whether to mark the widget required. An alias of the
41
+ * `aria-required` attribute.
42
+ */
43
+ required?: boolean | undefined;
44
+ /**
45
+ * Whether to mark the widget invalid. An alias of the
46
+ * `aria-invalid` attribute.
47
+ */
48
+ invalid?: boolean | undefined;
49
+ /**
50
+ * `aria-label` attribute.
51
+ */
52
+ ariaLabel?: string | undefined;
53
+ } & Record<string, any>, {}, "value" | "element">;
54
+ type Props = {
55
+ /**
56
+ * Input value, a lowercase hex color in the `#rrggbb` format. The
57
+ * swatch shows black if no value is given.
58
+ */
59
+ value?: string | undefined;
60
+ /**
61
+ * Reference to the `<input>` element.
62
+ */
63
+ element?: HTMLInputElement | undefined;
64
+ /**
65
+ * The `class` attribute on the `<input>` element.
66
+ */
67
+ class?: string | undefined;
68
+ /**
69
+ * Whether to disable the widget. An alias of the `aria-disabled`
70
+ * attribute.
71
+ */
72
+ disabled?: boolean | undefined;
73
+ /**
74
+ * Whether to make the widget read-only. An alias of the
75
+ * `aria-readonly` attribute. A native color input doesn’t support the `readonly` attribute, so
76
+ * the picker is kept from opening instead, while the input stays focusable, so the current color
77
+ * can still be reached and read by keyboard and assistive technology users, unlike with
78
+ * `disabled`.
79
+ */
80
+ readonly?: boolean | undefined;
81
+ /**
82
+ * Whether to mark the widget required. An alias of the
83
+ * `aria-required` attribute.
84
+ */
85
+ required?: boolean | undefined;
86
+ /**
87
+ * Whether to mark the widget invalid. An alias of the
88
+ * `aria-invalid` attribute.
89
+ */
90
+ invalid?: boolean | undefined;
91
+ /**
92
+ * `aria-label` attribute.
93
+ */
94
+ ariaLabel?: string | undefined;
95
+ };
96
+ import type { InputEventHandlers } from '../../typedefs.js';
@@ -0,0 +1,131 @@
1
+ <!--
2
+ @component
3
+ A date and/or time field. The equivalent of the HTML `<input type="date">`,
4
+ `<input type="datetime-local">` and `<input type="time">` elements, styled like the other text
5
+ fields. The browser’s native picker is kept, and follows the light or dark theme through the
6
+ inherited `color-scheme`.
7
+ @todo Replace the native `<input>` with a custom component.
8
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
9
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
10
+ @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time
11
+ -->
12
+ <script>
13
+ /**
14
+ * @import { CommonEventHandlers, InputEventHandlers } from '../../typedefs.js';
15
+ */
16
+
17
+ /**
18
+ * @typedef {object} Props
19
+ * @property {string} [value] Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
20
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
21
+ * seconds) for `time`. An empty string if no value is entered.
22
+ * @property {HTMLInputElement} [element] Reference to the `<input>` element.
23
+ * @property {'date' | 'datetime-local' | 'time'} [type] The `type` attribute on the `<input>`.
24
+ * @property {string} [min] Minimum allowed value, in the same format as `value`.
25
+ * @property {string} [max] Maximum allowed value, in the same format as `value`.
26
+ * @property {number | 'any'} [step] Stepping interval: in days for `date`, in seconds for
27
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
28
+ * @property {string} [class] The `class` attribute on the `<input>` element.
29
+ * @property {boolean} [disabled] Whether to disable the widget. An alias of the `aria-disabled`
30
+ * attribute.
31
+ * @property {boolean} [readonly] Whether to make the widget read-only. An alias of the
32
+ * `aria-readonly` attribute.
33
+ * @property {boolean} [required] Whether to mark the widget required. An alias of the
34
+ * `aria-required` attribute.
35
+ * @property {boolean} [invalid] Whether to mark the widget invalid. An alias of the
36
+ * `aria-invalid` attribute.
37
+ * @property {string} [ariaLabel] `aria-label` attribute.
38
+ */
39
+
40
+ /**
41
+ * @type {CommonEventHandlers & InputEventHandlers & Props & Record<string, any>}
42
+ */
43
+ let {
44
+ /* eslint-disable prefer-const */
45
+ value = $bindable(),
46
+ element = $bindable(),
47
+ type = 'date',
48
+ min = undefined,
49
+ max = undefined,
50
+ step = undefined,
51
+ class: className,
52
+ disabled = false,
53
+ readonly = false,
54
+ required = false,
55
+ invalid = false,
56
+ ariaLabel = undefined,
57
+ oninput,
58
+ ...restProps
59
+ /* eslint-enable prefer-const */
60
+ } = $props();
61
+
62
+ /**
63
+ * Update the `value` and call the `oninput` callback.
64
+ * @param {Event} event The `input` event object.
65
+ */
66
+ const handleInput = (event) => {
67
+ value = /** @type {HTMLInputElement} */ (event.currentTarget).value;
68
+ oninput?.(event);
69
+ };
70
+ </script>
71
+
72
+ <input
73
+ bind:this={element}
74
+ {...restProps}
75
+ value={value ?? ''}
76
+ {type}
77
+ {min}
78
+ {max}
79
+ {step}
80
+ class="sui date-time-input {className}"
81
+ disabled={disabled || undefined}
82
+ readonly={readonly || undefined}
83
+ aria-label={ariaLabel ?? restProps['aria-label']}
84
+ aria-disabled={disabled}
85
+ aria-readonly={readonly}
86
+ aria-required={required}
87
+ aria-invalid={invalid}
88
+ oninput={handleInput}
89
+ />
90
+
91
+ <style>.date-time-input {
92
+ display: inline-block;
93
+ margin: var(--sui-focus-ring-width);
94
+ border-width: var(--sui-textbox-border-width, 1px);
95
+ border-color: var(--sui-textbox-border-color);
96
+ border-radius: var(--sui-textbox-border-radius);
97
+ padding: var(--sui-textbox-singleline-padding);
98
+ width: auto;
99
+ min-width: 0;
100
+ height: var(--sui-textbox-height);
101
+ color: var(--sui-textbox-foreground-color);
102
+ background-color: var(--sui-textbox-background-color);
103
+ font-family: var(--sui-textbox-font-family);
104
+ font-size: var(--sui-textbox-font-size);
105
+ line-height: var(--sui-textbox-singleline-line-height);
106
+ font-weight: var(--sui-textbox-font-weight, var(--sui-font-weight-normal, normal));
107
+ text-transform: var(--sui-date-time-input-text-transform, uppercase);
108
+ letter-spacing: var(--sui-textbox-letter-spacing, normal);
109
+ font-variant-numeric: tabular-nums;
110
+ transition: all 200ms;
111
+ }
112
+ .date-time-input:focus {
113
+ color: var(--sui-textbox-foreground-color-focus, var(--sui-textbox-foreground-color));
114
+ background-color: var(--sui-textbox-background-color-focus, var(--sui-textbox-background-color));
115
+ }
116
+ .date-time-input:read-only {
117
+ color: var(--sui-secondary-foreground-color);
118
+ border-color: var(--sui-textbox-border-color) !important;
119
+ }
120
+ .date-time-input:is(:disabled, :read-only) {
121
+ background-color: var(--sui-disabled-background-color);
122
+ }
123
+ .date-time-input[aria-invalid=true] {
124
+ border-color: var(--sui-error-border-color);
125
+ }
126
+ .date-time-input::-webkit-calendar-picker-indicator {
127
+ cursor: pointer;
128
+ }
129
+ .date-time-input:is(:disabled, :read-only)::-webkit-calendar-picker-indicator {
130
+ cursor: default;
131
+ }</style>
@@ -0,0 +1,130 @@
1
+ export default DateTimeInput;
2
+ type DateTimeInput = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<KeyboardEventHandlers & MouseEventHandlers & PointerEventHandlers & FocusEventHandlers & DragEventHandlers & InputEventHandlers & Props & Record<string, any>>): void;
5
+ };
6
+ /**
7
+ * A date and/or time field. The equivalent of the HTML `<input type="date">`,
8
+ * `<input type="datetime-local">` and `<input type="time">` elements, styled like the other text
9
+ * fields. The browser’s native picker is kept, and follows the light or dark theme through the
10
+ * inherited `color-scheme`.
11
+ * @todo Replace the native `<input>` with a custom component.
12
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
14
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time
15
+ */
16
+ declare const DateTimeInput: import("svelte").Component<import("../../typedefs.js").KeyboardEventHandlers & import("../../typedefs.js").MouseEventHandlers & import("../../typedefs.js").PointerEventHandlers & import("../../typedefs.js").FocusEventHandlers & import("../../typedefs.js").DragEventHandlers & InputEventHandlers & {
17
+ /**
18
+ * Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
19
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
20
+ * seconds) for `time`. An empty string if no value is entered.
21
+ */
22
+ value?: string | undefined;
23
+ /**
24
+ * Reference to the `<input>` element.
25
+ */
26
+ element?: HTMLInputElement | undefined;
27
+ /**
28
+ * The `type` attribute on the `<input>`.
29
+ */
30
+ type?: "time" | "date" | "datetime-local" | undefined;
31
+ /**
32
+ * Minimum allowed value, in the same format as `value`.
33
+ */
34
+ min?: string | undefined;
35
+ /**
36
+ * Maximum allowed value, in the same format as `value`.
37
+ */
38
+ max?: string | undefined;
39
+ /**
40
+ * Stepping interval: in days for `date`, in seconds for
41
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
42
+ */
43
+ step?: number | "any" | undefined;
44
+ /**
45
+ * The `class` attribute on the `<input>` element.
46
+ */
47
+ class?: string | undefined;
48
+ /**
49
+ * Whether to disable the widget. An alias of the `aria-disabled`
50
+ * attribute.
51
+ */
52
+ disabled?: boolean | undefined;
53
+ /**
54
+ * Whether to make the widget read-only. An alias of the
55
+ * `aria-readonly` attribute.
56
+ */
57
+ readonly?: boolean | undefined;
58
+ /**
59
+ * Whether to mark the widget required. An alias of the
60
+ * `aria-required` attribute.
61
+ */
62
+ required?: boolean | undefined;
63
+ /**
64
+ * Whether to mark the widget invalid. An alias of the
65
+ * `aria-invalid` attribute.
66
+ */
67
+ invalid?: boolean | undefined;
68
+ /**
69
+ * `aria-label` attribute.
70
+ */
71
+ ariaLabel?: string | undefined;
72
+ } & Record<string, any>, {}, "value" | "element">;
73
+ type Props = {
74
+ /**
75
+ * Input value, in the native input’s format: `YYYY-MM-DD` for `date`,
76
+ * `YYYY-MM-DDTHH:mm` (with optional seconds) for `datetime-local`, and `HH:mm` (with optional
77
+ * seconds) for `time`. An empty string if no value is entered.
78
+ */
79
+ value?: string | undefined;
80
+ /**
81
+ * Reference to the `<input>` element.
82
+ */
83
+ element?: HTMLInputElement | undefined;
84
+ /**
85
+ * The `type` attribute on the `<input>`.
86
+ */
87
+ type?: "time" | "date" | "datetime-local" | undefined;
88
+ /**
89
+ * Minimum allowed value, in the same format as `value`.
90
+ */
91
+ min?: string | undefined;
92
+ /**
93
+ * Maximum allowed value, in the same format as `value`.
94
+ */
95
+ max?: string | undefined;
96
+ /**
97
+ * Stepping interval: in days for `date`, in seconds for
98
+ * `datetime-local` and `time`. A step under 60 for the latter two shows the seconds.
99
+ */
100
+ step?: number | "any" | undefined;
101
+ /**
102
+ * The `class` attribute on the `<input>` element.
103
+ */
104
+ class?: string | undefined;
105
+ /**
106
+ * Whether to disable the widget. An alias of the `aria-disabled`
107
+ * attribute.
108
+ */
109
+ disabled?: boolean | undefined;
110
+ /**
111
+ * Whether to make the widget read-only. An alias of the
112
+ * `aria-readonly` attribute.
113
+ */
114
+ readonly?: boolean | undefined;
115
+ /**
116
+ * Whether to mark the widget required. An alias of the
117
+ * `aria-required` attribute.
118
+ */
119
+ required?: boolean | undefined;
120
+ /**
121
+ * Whether to mark the widget invalid. An alias of the
122
+ * `aria-invalid` attribute.
123
+ */
124
+ invalid?: boolean | undefined;
125
+ /**
126
+ * `aria-label` attribute.
127
+ */
128
+ ariaLabel?: string | undefined;
129
+ };
130
+ import type { InputEventHandlers } from '../../typedefs.js';
package/dist/index.d.ts CHANGED
@@ -64,6 +64,8 @@ export { default as TabPanels } from "./components/tabs/tab-panels.svelte";
64
64
  export { default as Tab } from "./components/tabs/tab.svelte";
65
65
  export { default as CodeEditor } from "./components/text-editor/code-editor.svelte";
66
66
  export { default as TextEditor } from "./components/text-editor/text-editor.svelte";
67
+ export { default as ColorInput } from "./components/text-field/color-input.svelte";
68
+ export { default as DateTimeInput } from "./components/text-field/date-time-input.svelte";
67
69
  export { default as NumberInput } from "./components/text-field/number-input.svelte";
68
70
  export { default as PasswordInput } from "./components/text-field/password-input.svelte";
69
71
  export { default as SearchBar } from "./components/text-field/search-bar.svelte";
package/dist/index.js CHANGED
@@ -64,6 +64,8 @@ export { default as TabPanels } from './components/tabs/tab-panels.svelte';
64
64
  export { default as Tab } from './components/tabs/tab.svelte';
65
65
  export { default as CodeEditor } from './components/text-editor/code-editor.svelte';
66
66
  export { default as TextEditor } from './components/text-editor/text-editor.svelte';
67
+ export { default as ColorInput } from './components/text-field/color-input.svelte';
68
+ export { default as DateTimeInput } from './components/text-field/date-time-input.svelte';
67
69
  export { default as NumberInput } from './components/text-field/number-input.svelte';
68
70
  export { default as PasswordInput } from './components/text-field/password-input.svelte';
69
71
  export { default as SearchBar } from './components/text-field/search-bar.svelte';
@@ -480,7 +480,12 @@ export class Group {
480
480
  focused ??
481
481
  (holders.length === 1
482
482
  ? holders[0]
483
- : ((this.rovingTabStop === 'selected' ? this.selected : undefined) ?? activeMembers[0]));
483
+ : ((this.rovingTabStop === 'selected' ? this.selected : undefined) ??
484
+ // The first member not marked as unselectable, so a grid’s header row or a row group
485
+ // caption isn’t where the user lands when they tab into it. A plain menu item can’t be
486
+ // selected either, but it’s still where a menu starts
487
+ activeMembers.find((element) => element.dataset.selectable !== 'false') ??
488
+ activeMembers[0]));
484
489
 
485
490
  allMembers.forEach((element) => {
486
491
  // Only touch the DOM when it changes; this runs on every mutation of a large widget. The
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.82.0",
3
+ "version": "0.84.0",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,14 +81,14 @@
81
81
  "eslint-config-airbnb-extended": "^3.3.0",
82
82
  "eslint-config-prettier": "^10.1.8",
83
83
  "eslint-plugin-import": "^2.32.0",
84
- "eslint-plugin-jsdoc": "^65.3.1",
84
+ "eslint-plugin-jsdoc": "^65.3.2",
85
85
  "eslint-plugin-package-json": "^1.10.1",
86
86
  "eslint-plugin-svelte": "^3.23.1",
87
87
  "globals": "^17.13.0",
88
88
  "happy-dom": "^21.0.1",
89
- "oxlint": "^1.87.0",
89
+ "oxlint": "^1.88.0",
90
90
  "playwright": "^1.64.0",
91
- "postcss": "^8.5.29",
91
+ "postcss": "^8.5.30",
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",
94
94
  "prettier-plugin-svelte": "^4.1.1",