@primitiv-ui/core 0.1.59 → 0.1.60
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/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { resolveRovingTarget, type ResolveRovingTargetOptions, } from "./keyboar
|
|
|
4
4
|
export { tabsClick, tabsKeydown, tabsTabStop, type TabsActivationMode, type TabsKeyOutcome, type TabsOrientation, type TabsReadingDirection, type TabsState, } from "./tabs/policy.js";
|
|
5
5
|
export { accordionKeydown, accordionToggle, type AccordionKeyOutcome, type AccordionOrientation, type AccordionReadingDirection, type AccordionState, } from "./accordion/policy.js";
|
|
6
6
|
export { toggleGroupKeydown, toggleGroupTabStop, toggleGroupToggle, type ToggleGroupKeyOutcome, type ToggleGroupOrientation, type ToggleGroupReadingDirection, type ToggleGroupState, } from "./toggle-group/policy.js";
|
|
7
|
+
export { segmentedControlKeydown, segmentedControlSelect, segmentedControlTabStop, type SegmentedControlKeyOutcome, type SegmentedControlOrientation, type SegmentedControlReadingDirection, type SegmentedControlState, } from "./segmented-control/policy.js";
|
|
7
8
|
export { collapsibleKeydown, collapsibleToggle, type CollapsibleKeyOutcome, type CollapsibleState, } from "./collapsible/policy.js";
|
|
8
9
|
export { FOCUSABLE_SELECTOR } from "./focus/focusable.js";
|
|
9
10
|
export { MENU_ITEM_SELECTOR, MENU_TYPEAHEAD_RESET_MS, menuKeydown, menuTypeahead, type MenuKeyOutcome, type MenuKeyState, type MenuTypeaheadOutcome, type MenuTypeaheadState, } from "./menu/policy.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { resolveRovingTarget, } from "./keyboard/resolveRovingTarget.js";
|
|
|
4
4
|
export { tabsClick, tabsKeydown, tabsTabStop, } from "./tabs/policy.js";
|
|
5
5
|
export { accordionKeydown, accordionToggle, } from "./accordion/policy.js";
|
|
6
6
|
export { toggleGroupKeydown, toggleGroupTabStop, toggleGroupToggle, } from "./toggle-group/policy.js";
|
|
7
|
+
export { segmentedControlKeydown, segmentedControlSelect, segmentedControlTabStop, } from "./segmented-control/policy.js";
|
|
7
8
|
export { collapsibleKeydown, collapsibleToggle, } from "./collapsible/policy.js";
|
|
8
9
|
export { FOCUSABLE_SELECTOR } from "./focus/focusable.js";
|
|
9
10
|
export { MENU_ITEM_SELECTOR, MENU_TYPEAHEAD_RESET_MS, menuKeydown, menuTypeahead, } from "./menu/policy.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Layout axis of the control: which arrow pair moves between segments. */
|
|
2
|
+
export type SegmentedControlOrientation = "horizontal" | "vertical";
|
|
3
|
+
/** Reading direction. Under `"rtl"` the horizontal arrows are mirrored. */
|
|
4
|
+
export type SegmentedControlReadingDirection = "ltr" | "rtl";
|
|
5
|
+
/**
|
|
6
|
+
* Everything SegmentedControl's selection and keyboard rules depend on, as
|
|
7
|
+
* plain data. Each surface builds it from wherever it keeps state — React
|
|
8
|
+
* state, or a custom element's attributes — and applies the outcome back the
|
|
9
|
+
* same way. A whole-control disable is every value in `disabled`.
|
|
10
|
+
*/
|
|
11
|
+
export type SegmentedControlState = {
|
|
12
|
+
/** Every segment's value, in DOM order, disabled ones included. */
|
|
13
|
+
values: readonly string[];
|
|
14
|
+
/** The values of the disabled segments. */
|
|
15
|
+
disabled: ReadonlySet<string>;
|
|
16
|
+
/** The selected segment's value, or `undefined` while none is selected. */
|
|
17
|
+
selected: string | undefined;
|
|
18
|
+
orientation: SegmentedControlOrientation;
|
|
19
|
+
dir: SegmentedControlReadingDirection;
|
|
20
|
+
};
|
|
21
|
+
/** What a key press on a segment asks for: a segment to focus, and the segment
|
|
22
|
+
* to select — `null` when it is already selected, so no change is reported. */
|
|
23
|
+
export type SegmentedControlKeyOutcome = {
|
|
24
|
+
focus: string;
|
|
25
|
+
select: string | null;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The segment a click on `value` selects: `null` when it is disabled or
|
|
29
|
+
* already selected. A selected segment never lets go, so — unlike a toggle
|
|
30
|
+
* group — the selection cannot be cleared to nothing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function segmentedControlSelect(state: Pick<SegmentedControlState, "disabled" | "selected">, value: string): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* SegmentedControl's keyboard contract — the WAI-ARIA radio group's — for a key
|
|
35
|
+
* press on the segment `focused`: the arrows follow `orientation`, mirrored
|
|
36
|
+
* under RTL, wrap at the ends and skip disabled segments, and each one moves
|
|
37
|
+
* focus **and** selection. While focus sits on a disabled segment they do
|
|
38
|
+
* nothing. There is no Home / End, and Enter / Space are the native button's
|
|
39
|
+
* click.
|
|
40
|
+
*
|
|
41
|
+
* Returns `null` for a key the control does not handle, which tells the caller
|
|
42
|
+
* to leave the event alone (no `preventDefault`).
|
|
43
|
+
*/
|
|
44
|
+
export declare function segmentedControlKeydown(state: SegmentedControlState, focused: string, key: string): SegmentedControlKeyOutcome | null;
|
|
45
|
+
/**
|
|
46
|
+
* The segment that takes part in the page's Tab order (the roving tab stop):
|
|
47
|
+
* the selected segment, else the first enabled one so the control is still
|
|
48
|
+
* reachable by keyboard — or none, while nothing is selected and every segment
|
|
49
|
+
* is disabled.
|
|
50
|
+
*/
|
|
51
|
+
export declare function segmentedControlTabStop(state: Pick<SegmentedControlState, "values" | "disabled" | "selected">): string | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getKeyToActionMap } from "../keyboard/getKeyToActionMap.js";
|
|
2
|
+
import { resolveRovingTarget } from "../keyboard/resolveRovingTarget.js";
|
|
3
|
+
/**
|
|
4
|
+
* The segment a click on `value` selects: `null` when it is disabled or
|
|
5
|
+
* already selected. A selected segment never lets go, so — unlike a toggle
|
|
6
|
+
* group — the selection cannot be cleared to nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function segmentedControlSelect(state, value) {
|
|
9
|
+
return state.disabled.has(value) || state.selected === value ? null : value;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SegmentedControl's keyboard contract — the WAI-ARIA radio group's — for a key
|
|
13
|
+
* press on the segment `focused`: the arrows follow `orientation`, mirrored
|
|
14
|
+
* under RTL, wrap at the ends and skip disabled segments, and each one moves
|
|
15
|
+
* focus **and** selection. While focus sits on a disabled segment they do
|
|
16
|
+
* nothing. There is no Home / End, and Enter / Space are the native button's
|
|
17
|
+
* click.
|
|
18
|
+
*
|
|
19
|
+
* Returns `null` for a key the control does not handle, which tells the caller
|
|
20
|
+
* to leave the event alone (no `preventDefault`).
|
|
21
|
+
*/
|
|
22
|
+
export function segmentedControlKeydown(state, focused, key) {
|
|
23
|
+
const action = getKeyToActionMap({ orientation: state.orientation, dir: state.dir })[key];
|
|
24
|
+
const navigable = state.values.filter((value) => !state.disabled.has(value));
|
|
25
|
+
const result = resolveRovingTarget({ action, navigable, currentKey: focused });
|
|
26
|
+
return result && { focus: result.target, select: segmentedControlSelect(state, result.target) };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The segment that takes part in the page's Tab order (the roving tab stop):
|
|
30
|
+
* the selected segment, else the first enabled one so the control is still
|
|
31
|
+
* reachable by keyboard — or none, while nothing is selected and every segment
|
|
32
|
+
* is disabled.
|
|
33
|
+
*/
|
|
34
|
+
export function segmentedControlTabStop(state) {
|
|
35
|
+
return state.selected ?? state.values.find((value) => !state.disabled.has(value));
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primitiv-ui/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "The framework-free behaviour core shared by every Primitiv surface — keyboard maps, roving-focus targets, id derivation and per-component policy, as pure functions with no DOM and no dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|