@sveltia/ui 0.83.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,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.83.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.83.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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.83.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",