@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.7

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 (59) hide show
  1. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  2. package/dist/button/root/button-root.svelte +9 -0
  3. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  4. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  5. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  6. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  7. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  8. package/dist/checkbox-group/README.md +95 -0
  9. package/dist/checkbox-group/index.d.ts +15 -0
  10. package/dist/checkbox-group/index.js +6 -0
  11. package/dist/checkbox-group/index.parts.d.ts +4 -0
  12. package/dist/checkbox-group/index.parts.js +7 -0
  13. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  14. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  15. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  16. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  17. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  18. package/dist/checkbox-group/root/context.svelte.js +251 -0
  19. package/dist/checkbox-group/types.d.ts +57 -0
  20. package/dist/checkbox-group/types.js +1 -0
  21. package/dist/index.d.ts +4 -0
  22. package/dist/index.js +4 -0
  23. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  24. package/dist/primitives/focus-visible.svelte.js +19 -0
  25. package/dist/primitives/index.d.ts +1 -0
  26. package/dist/primitives/index.js +1 -0
  27. package/dist/primitives/input-modality.d.ts +7 -0
  28. package/dist/primitives/input-modality.js +32 -5
  29. package/dist/radio-group/README.md +103 -0
  30. package/dist/radio-group/index.d.ts +18 -0
  31. package/dist/radio-group/index.js +9 -0
  32. package/dist/radio-group/index.parts.d.ts +4 -0
  33. package/dist/radio-group/index.parts.js +4 -0
  34. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  35. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  36. package/dist/radio-group/item/context.d.ts +18 -0
  37. package/dist/radio-group/item/context.js +15 -0
  38. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  39. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  40. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  41. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  42. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  43. package/dist/radio-group/root/context.svelte.js +284 -0
  44. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  45. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  46. package/dist/radio-group/types.d.ts +50 -0
  47. package/dist/radio-group/types.js +1 -0
  48. package/dist/switch/root/switch-root.svelte +9 -0
  49. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  50. package/dist/table/root/table-root.svelte +29 -6
  51. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  52. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  53. package/dist/toggle/root/toggle-root.svelte +28 -0
  54. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  55. package/dist/toggle-group/README.md +6 -4
  56. package/dist/toggle-group/index.d.ts +2 -0
  57. package/dist/toggle-group/index.parts.d.ts +1 -0
  58. package/dist/toggle-group/index.parts.js +4 -0
  59. package/package.json +11 -1
@@ -8,6 +8,20 @@ let currentModality = 'virtual';
8
8
  const RECENT_INPUT_WINDOW_MS = 50;
9
9
  let lastInputEventTime = Number.NEGATIVE_INFINITY;
10
10
  const listenedWindows = new WeakSet();
11
+ /**
12
+ * Notified whenever the modality changes. `data-focus-visible` is otherwise a snapshot taken
13
+ * when the element took focus, so a pointer press followed by a key press left the ring off
14
+ * while the browser had already flipped `:focus-visible` back on.
15
+ */
16
+ const modalityListeners = new Set();
17
+ function setModality(next) {
18
+ if (currentModality === next)
19
+ return;
20
+ currentModality = next;
21
+ for (const listener of [...modalityListeners]) {
22
+ listener(next);
23
+ }
24
+ }
11
25
  let forcedFocusTarget = null;
12
26
  let forcedFocusModality = null;
13
27
  function isModifierOnlyKey(event) {
@@ -29,11 +43,11 @@ function ensureWindowListeners(win) {
29
43
  lastInputEventTime = Date.now();
30
44
  if (!isKeyboardModalityKey(event))
31
45
  return;
32
- currentModality = 'keyboard';
46
+ setModality('keyboard');
33
47
  };
34
48
  const onPointerDown = () => {
35
49
  lastInputEventTime = Date.now();
36
- currentModality = 'pointer';
50
+ setModality('pointer');
37
51
  };
38
52
  const onFocusIn = (event) => {
39
53
  // A programmatic focus with an explicit modality (`focusWithModality`) must keep it —
@@ -45,7 +59,7 @@ function ensureWindowListeners(win) {
45
59
  return;
46
60
  // No recent keyboard/pointer input: this focus move came from an assistive technology
47
61
  // (or a script), so focus rings must show again.
48
- currentModality = 'virtual';
62
+ setModality('virtual');
49
63
  };
50
64
  win.addEventListener('keydown', onKeyDown, true);
51
65
  win.addEventListener('pointerdown', onPointerDown, true);
@@ -90,12 +104,25 @@ export function trackInteractionModality(event, target) {
90
104
  initInputModality(target);
91
105
  const inferred = inferModalityFromEvent(event);
92
106
  if (inferred) {
93
- currentModality = inferred;
107
+ setModality(inferred);
94
108
  }
95
109
  }
96
110
  export function getInteractionModality() {
97
111
  return currentModality;
98
112
  }
113
+ /**
114
+ * Calls `listener` whenever the interaction modality changes, and returns the unsubscribe
115
+ * function. Components use it to re-read `shouldShowFocusVisible` for an element that already
116
+ * holds focus: the browser re-evaluates `:focus-visible` on its own, and this is what lets a
117
+ * component notice.
118
+ */
119
+ export function subscribeInputModality(listener) {
120
+ initInputModality();
121
+ modalityListeners.add(listener);
122
+ return () => {
123
+ modalityListeners.delete(listener);
124
+ };
125
+ }
99
126
  export function shouldShowFocusVisible(target) {
100
127
  if (!target)
101
128
  return false;
@@ -111,7 +138,7 @@ export function focusWithModality(target, modality, options) {
111
138
  // If it is consumed later, currentModality still preserves the same modality as fallback.
112
139
  forcedFocusTarget = target;
113
140
  forcedFocusModality = modality;
114
- currentModality = modality;
141
+ setModality(modality);
115
142
  if (modality === 'pointer') {
116
143
  const pointerFocusOptions = {
117
144
  ...(options ?? {}),
@@ -0,0 +1,103 @@
1
+ # RadioGroup
2
+
3
+ ## Description
4
+
5
+ `RadioGroup` coordinates a set of `RadioGroup.Item` buttons as one field. It holds a single value, and
6
+ it shares a `name` for form submission. It also spreads group-wide disabled, read-only and required
7
+ state, and it controls the roving focus the pattern asks for.
8
+
9
+ ## Anatomy
10
+
11
+ - `RadioGroup.Root`
12
+ - `RadioGroup.Label`
13
+ - `RadioGroup.Item`
14
+ - `RadioGroup.Indicator`
15
+
16
+ ```svelte
17
+ <RadioGroup.Root name="size" defaultValue="medium">
18
+ <RadioGroup.Label>Size</RadioGroup.Label>
19
+ <RadioGroup.Item value="small">
20
+ <RadioGroup.Indicator>x</RadioGroup.Indicator>
21
+ Small
22
+ </RadioGroup.Item>
23
+ <RadioGroup.Item value="medium">
24
+ <RadioGroup.Indicator>x</RadioGroup.Indicator>
25
+ Medium
26
+ </RadioGroup.Item>
27
+ </RadioGroup.Root>
28
+ ```
29
+
30
+ ## Usage guidelines
31
+
32
+ - Use `bind:value` to hand the group your state, or plain `value` + `onChange` to own it yourself.
33
+ There is no flag to declare which: supplying `value` makes it the source of truth either way, and
34
+ `onChange` always reports.
35
+ - A parent that holds `value` and refuses a change — it sends no new value down — still sees the
36
+ group move. The group then goes back to the value of the parent at the next render.
37
+ - Give the group a `name` to submit the answer as one field.
38
+ - Every `RadioGroup.Item` must provide a unique `value`, and it must sit inside a `RadioGroup.Root`. A
39
+ radio on its own has nothing to answer, and the component reports that rather than guessing.
40
+
41
+ ## API reference
42
+
43
+ `RadioGroup.Root` supports:
44
+
45
+ - `value?: string | null`
46
+ - `defaultValue?: string | null`
47
+ - `onChange?: (value: string) => void`
48
+ - `name?: string`
49
+ - `form?: string`
50
+ - `disabled?: boolean`
51
+ - `readonly?: boolean`
52
+ - `required?: boolean`
53
+ - `orientation?: 'horizontal' | 'vertical'`
54
+ - `context?: RadioGroupContext`
55
+ - `children?: Snippet`
56
+ - `...restProps: HTMLAttributes<HTMLDivElement>`
57
+
58
+ `RadioGroup.Item` supports `value` (required), `disabled`, `children`, `class`, `element` and the
59
+ usual `HTMLAttributes<HTMLSpanElement>`. It makes a span with `role="radio"` and a hidden radio
60
+ input for the form.
61
+
62
+ `RadioGroup.Indicator` supports `forceMount`. It is in the DOM only while its radio is checked.
63
+
64
+ `RadioGroup.Label` supports `children`, `class`, `id` and the usual `HTMLAttributes<HTMLSpanElement>`.
65
+ It renders a span, and it registers its id with the group as `aria-labelledby`.
66
+
67
+ ## Accessibility
68
+
69
+ - `RadioGroup.Root` renders `role="radiogroup"`, with `aria-orientation`, `aria-required`,
70
+ `aria-disabled` and `aria-readonly`. That role supports all four, which the plain `group` role of
71
+ a checkbox group does not.
72
+ - Give the group an accessible name with `RadioGroup.Label`, or with `aria-label` on the root for a
73
+ name the user does not see. Two labels read as one name, in the order they appear. An
74
+ `aria-labelledby` that the caller gives stands, thus an element of your own wins.
75
+ - `RadioGroup.Label` renders a span, and not a `<label>`: a `<label>` names one control, thus it
76
+ cannot name a set.
77
+ - The id reaches the group through the context. The server cannot do that: the group tag is
78
+ already written when the label registers. Thus `aria-labelledby` appears at hydration. Give
79
+ `aria-label` as well when the name must be there on the first paint.
80
+ - The group holds **one** tab stop, on the checked radio, and on the first enabled radio while
81
+ nothing is checked. Thus Tab enters the group where the user left it, and Tab leaves the group
82
+ rather than walking through it.
83
+ - The arrow keys move the focus **and** the selection, and they wrap at both ends. `Home` and `End`
84
+ jump to the bounds. Both axes work in either orientation, the way a native radio group does.
85
+ - `Space` selects the focused radio. `Enter` does not: it submits the form of a native radio.
86
+ - `aria-readonly` and `aria-required` are on the group, and never on an item: the `radio` role
87
+ does not support them.
88
+ - Give each radio an accessible name with its content, `aria-label` or `aria-labelledby`.
89
+
90
+ ## Notes
91
+
92
+ - There is no unselecting. The platform gives the user no way to take a radio answer back, so a
93
+ second press on the selected radio reports nothing.
94
+ - A radio that leaves a mounted group keeps its value in the group. Its hidden input goes with it,
95
+ so the form stops submitting that answer, which is what a native radio group does. A parent
96
+ that holds the value keeps it. The group gives the tab stop to the first enabled radio.
97
+ - Values are strings only. A radio carries its value on a native `<input>`, which stores it as a
98
+ string. A number would thus let `value={1}` miss a radio declared as `value="1"`.
99
+ - Both parts show each visual state in `data-*` attributes: `data-checked`, `data-unchecked`,
100
+ `data-pressed`, `data-disabled`, `data-readonly`, `data-required`, `data-focused` and
101
+ `data-focus-visible`.
102
+ - The selection follows the focus. This is the rule that parts a radio group from every other group
103
+ in this library. In a `ToggleGroup` or a `CheckboxGroup` the arrows only move.
@@ -0,0 +1,18 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type RadioGroupIndicatorComponent from './indicator/radio-group-indicator.svelte';
3
+ import type RadioGroupLabelComponent from './label/radio-group-label.svelte';
4
+ import type RadioGroupItemComponent from './item/radio-group-item.svelte';
5
+ import type RadioGroupRootComponent from './root/radio-group-root.svelte';
6
+ export * as RadioGroup from './index.parts.js';
7
+ export { default as RadioGroupRoot } from './root/radio-group-root.svelte';
8
+ export { default as RadioGroupLabel } from './label/radio-group-label.svelte';
9
+ export { default as RadioGroupItem } from './item/radio-group-item.svelte';
10
+ export { default as RadioGroupIndicator } from './indicator/radio-group-indicator.svelte';
11
+ export type RadioGroupRootProps = ComponentProps<typeof RadioGroupRootComponent>;
12
+ export type RadioGroupLabelProps = ComponentProps<typeof RadioGroupLabelComponent>;
13
+ export type RadioGroupItemProps = ComponentProps<typeof RadioGroupItemComponent>;
14
+ export type RadioGroupIndicatorProps = ComponentProps<typeof RadioGroupIndicatorComponent>;
15
+ export { createRadioGroupContext, getRadioGroupContext, setRadioGroupContext, useRadioGroupContext, type CreateRadioGroupContextOptions, type RadioGroupContext, type RadioGroupOrientation, type RadioGroupValue } from './root/context.svelte';
16
+ export { getRadioGroupItemContext, setRadioGroupItemContext, useRadioGroupItemContext, type RadioGroupItemContext, type RadioGroupItemState } from './item/context.js';
17
+ import * as RadioGroupParts from './index.parts.js';
18
+ export default RadioGroupParts;
@@ -0,0 +1,9 @@
1
+ export * as RadioGroup from './index.parts.js';
2
+ export { default as RadioGroupRoot } from './root/radio-group-root.svelte';
3
+ export { default as RadioGroupLabel } from './label/radio-group-label.svelte';
4
+ export { default as RadioGroupItem } from './item/radio-group-item.svelte';
5
+ export { default as RadioGroupIndicator } from './indicator/radio-group-indicator.svelte';
6
+ export { createRadioGroupContext, getRadioGroupContext, setRadioGroupContext, useRadioGroupContext } from './root/context.svelte';
7
+ export { getRadioGroupItemContext, setRadioGroupItemContext, useRadioGroupItemContext } from './item/context.js';
8
+ import * as RadioGroupParts from './index.parts.js';
9
+ export default RadioGroupParts;
@@ -0,0 +1,4 @@
1
+ export { default as Root } from './root/radio-group-root.svelte';
2
+ export { default as Label } from './label/radio-group-label.svelte';
3
+ export { default as Item } from './item/radio-group-item.svelte';
4
+ export { default as Indicator } from './indicator/radio-group-indicator.svelte';
@@ -0,0 +1,4 @@
1
+ export { default as Root } from './root/radio-group-root.svelte';
2
+ export { default as Label } from './label/radio-group-label.svelte';
3
+ export { default as Item } from './item/radio-group-item.svelte';
4
+ export { default as Indicator } from './indicator/radio-group-indicator.svelte';
@@ -0,0 +1,43 @@
1
+ <script lang="ts">
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { Snippet } from 'svelte';
4
+ import { useRadioGroupItemContext } from '../item/context';
5
+
6
+ type RadioGroupIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
7
+ /** Keeps the indicator in the DOM while the radio is not checked, for exit animations. */
8
+ forceMount?: boolean;
9
+ /** The mark itself. */
10
+ children?: Snippet;
11
+ class?: string;
12
+ };
13
+
14
+ let {
15
+ forceMount = false,
16
+ children,
17
+ class: className = '',
18
+ ...restProps
19
+ }: RadioGroupIndicatorProps = $props();
20
+
21
+ const radio = useRadioGroupItemContext();
22
+ const visible = $derived(radio.isChecked);
23
+ </script>
24
+
25
+ {#if forceMount || visible}
26
+ <span
27
+ {...restProps}
28
+ data-radio-group-indicator="true"
29
+ data-checked={radio.isChecked || undefined}
30
+ data-unchecked={!radio.isChecked || undefined}
31
+ data-pressed={radio.pressed || undefined}
32
+ data-disabled={radio.isDisabled || undefined}
33
+ data-readonly={radio.isReadOnly || undefined}
34
+ data-required={radio.required || undefined}
35
+ data-focused={radio.focused || undefined}
36
+ data-focus-visible={radio.focusVisible || undefined}
37
+ hidden={forceMount && !visible}
38
+ aria-hidden={forceMount && !visible ? 'true' : undefined}
39
+ class={className}
40
+ >
41
+ {@render children?.()}
42
+ </span>
43
+ {/if}
@@ -0,0 +1,12 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { Snippet } from 'svelte';
3
+ type RadioGroupIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class'> & {
4
+ /** Keeps the indicator in the DOM while the radio is not checked, for exit animations. */
5
+ forceMount?: boolean;
6
+ /** The mark itself. */
7
+ children?: Snippet;
8
+ class?: string;
9
+ };
10
+ declare const RadioGroupIndicator: import("svelte").Component<RadioGroupIndicatorProps, {}, "">;
11
+ type RadioGroupIndicator = ReturnType<typeof RadioGroupIndicator>;
12
+ export default RadioGroupIndicator;
@@ -0,0 +1,18 @@
1
+ export type RadioGroupItemState = 'checked' | 'unchecked';
2
+ export type RadioGroupItemContext = {
3
+ id: string;
4
+ inputId: string;
5
+ value: string;
6
+ state: RadioGroupItemState;
7
+ pressed: boolean;
8
+ isChecked: boolean;
9
+ isDisabled: boolean;
10
+ isReadOnly: boolean;
11
+ required: boolean;
12
+ focused: boolean;
13
+ focusVisible: boolean;
14
+ select: (event?: Event) => void;
15
+ };
16
+ export declare function setRadioGroupItemContext(context: RadioGroupItemContext): void;
17
+ export declare function getRadioGroupItemContext(): RadioGroupItemContext | undefined;
18
+ export declare function useRadioGroupItemContext(): RadioGroupItemContext;
@@ -0,0 +1,15 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ const RADIO_GROUP_ITEM_CONTEXT_KEY = Symbol('radio-group-item');
3
+ export function setRadioGroupItemContext(context) {
4
+ setContext(RADIO_GROUP_ITEM_CONTEXT_KEY, context);
5
+ }
6
+ export function getRadioGroupItemContext() {
7
+ return getContext(RADIO_GROUP_ITEM_CONTEXT_KEY);
8
+ }
9
+ export function useRadioGroupItemContext() {
10
+ const context = getRadioGroupItemContext();
11
+ if (!context) {
12
+ throw new Error('Radio components must be used within RadioGroup.Item.');
13
+ }
14
+ return context;
15
+ }