@colixsystems/widget-sdk 0.207.0 → 0.212.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.
Files changed (42) hide show
  1. package/README.md +97 -2
  2. package/dist/checkbox-view.js +150 -0
  3. package/dist/checkbox.js +11 -0
  4. package/dist/checkbox.native.js +7 -0
  5. package/dist/contract.cjs +78 -4
  6. package/dist/contract.js +78 -4
  7. package/dist/form-control-logic.js +55 -0
  8. package/dist/form-control-tokens.js +121 -0
  9. package/dist/form-control-view.js +98 -0
  10. package/dist/hooks.js +13 -0
  11. package/dist/host.d.ts +46 -0
  12. package/dist/host.js +4 -0
  13. package/dist/index.d.ts +230 -6
  14. package/dist/index.js +11 -1
  15. package/dist/index.native.js +11 -1
  16. package/dist/markdown-input-view.js +2 -3
  17. package/dist/markdown-input.js +4 -2
  18. package/dist/markdown-input.native.js +4 -2
  19. package/dist/markdown-link-dialog.js +94 -108
  20. package/dist/modal-tokens.js +107 -0
  21. package/dist/modal-view.js +255 -0
  22. package/dist/modal.js +8 -0
  23. package/dist/modal.native.js +45 -0
  24. package/dist/overlay-tokens.js +69 -5
  25. package/dist/overlay-view.js +52 -16
  26. package/dist/overlay.native.js +8 -1
  27. package/dist/search-field-view.js +155 -0
  28. package/dist/search-field.js +13 -0
  29. package/dist/search-field.native.js +9 -0
  30. package/dist/select-view.js +312 -0
  31. package/dist/select.js +15 -0
  32. package/dist/select.native.js +9 -0
  33. package/dist/surface-theme.js +108 -0
  34. package/dist/switch-view.js +149 -0
  35. package/dist/switch.js +80 -0
  36. package/dist/switch.native.js +7 -0
  37. package/dist/text-field-view.js +54 -8
  38. package/dist/text-field.js +6 -1
  39. package/dist/text-field.native.js +3 -3
  40. package/dist/web-modal.js +24 -5
  41. package/package.json +1 -1
  42. package/src/contract.js +78 -4
package/dist/contract.js CHANGED
@@ -618,6 +618,8 @@ const THEME_COMPONENTS = Object.freeze({
618
618
  // `text` scope already owns.
619
619
  muted: Object.freeze({
620
620
  label: "Muted",
621
+ // The SDK's form controls read this scope directly, in every widget.
622
+ sdkComponents: Object.freeze(["TextField", "Checkbox", "Switch", "Select", "SearchField"]),
621
623
  tokens: Object.freeze({
622
624
  background: Object.freeze({ type: "color", uiDefault: "colors.surfaceMuted" }),
623
625
  textColor: Object.freeze({ type: "color", uiDefault: "colors.onSurfaceMuted" }),
@@ -635,6 +637,7 @@ const THEME_COMPONENTS = Object.freeze({
635
637
  // list is the closest thing the built-in catalog has to a popover panel.
636
638
  popover: Object.freeze({
637
639
  label: "Popover",
640
+ sdkComponents: Object.freeze(["Select"]),
638
641
  tokens: Object.freeze({
639
642
  background: Object.freeze({ type: "color", uiDefault: "colors.surface" }),
640
643
  textColor: Object.freeze({ type: "color", uiDefault: "colors.onSurface" }),
@@ -723,6 +726,25 @@ const THEME_COMPONENTS = Object.freeze({
723
726
  }),
724
727
  targets: Object.freeze({}),
725
728
  }),
729
+ // Dialogs: `<Modal>` reads this scope directly, so it names the SDK component
730
+ // it styles and binds no widget field. `<Overlay>` reads the scrim alone.
731
+ modal: Object.freeze({
732
+ label: "Dialogs",
733
+ sdkComponents: Object.freeze(["Modal"]),
734
+ tokens: Object.freeze({
735
+ background: Object.freeze({ type: "color", uiDefault: "colors.surface" }),
736
+ titleColor: Object.freeze({ type: "color" }),
737
+ scrim: Object.freeze({
738
+ type: "color",
739
+ translucent: true,
740
+ note: "also the backdrop behind every <Overlay>",
741
+ }),
742
+ radius: Object.freeze({ type: "size", min: 0, max: 48, uiDefault: "radii.lg" }),
743
+ padding: Object.freeze({ type: "size", min: 0, max: 64, uiDefault: "spacing.lg" }),
744
+ shadow: Object.freeze({ type: "shadow" }),
745
+ }),
746
+ targets: Object.freeze({}),
747
+ }),
726
748
  });
727
749
 
728
750
  // sc-4505 — the value types a widget event payload field may declare. Narrower
@@ -2792,7 +2814,7 @@ const PRIMITIVES = [
2792
2814
  {
2793
2815
  name: "Switch",
2794
2816
  description:
2795
- "Toggle. Controlled — `value` + `onValueChange`. See https://reactnative.dev/docs/switch.",
2817
+ 'Themed on/off toggle. `<Switch label="Email me updates" value={on} onValueChange={setOn} />` — THE way to draw a setting that takes effect at once. It is the platform\'s own switch, so each host gives it its switch role, state and keys; its "on" track is the app\'s primary colour and its "off" track the input border (Design > Components > Muted). `label` draws the text beside it and makes the text tappable too, `helper` a hint below, `error` a message in its place (or `true` to mark it without one), `disabled` stops it (a device greys it; on the web it is drawn at half strength unless you passed your own colours). Always pass `label`, or `accessibilityLabel` when a visible label already sits next to it. Controlled — `value` + `onValueChange(next)`. Every React Native `Switch` prop still works: a `trackColor` you pass overrides the theme for the states it names, and `thumbColor` colours the thumb. Never hand-roll a toggle from `Pressable` + a sliding `View`.',
2796
2818
  rnComponent: "Switch",
2797
2819
  docsUrl: "https://reactnative.dev/docs/switch",
2798
2820
  },
@@ -2886,7 +2908,15 @@ const PRIMITIVES = [
2886
2908
  {
2887
2909
  name: "Overlay",
2888
2910
  description:
2889
- 'Screen-level overlay. `<Overlay visible={open} onRequestClose={() => setOpen(false)} size="md">…panel…</Overlay>`. THE way to open anything that must cover the SCREEN rather than the widget — a preview (PDF, image, video), a lightbox, a confirm dialog, a full detail panel. It renders OUTSIDE the widget layout box on both hosts (react-native-web portals it to the document root; native uses the OS modal), so no `overflow: hidden` card, scroll container or sibling widget can clip or cover it — which absolute positioning inside the widget cannot achieve on either host. Children stay in your own React tree, so state and hooks work normally. Props: `visible` (boolean, required to show), `onRequestClose` (fired by the backdrop press, the Escape key on web, and the Android back button — always wire it or the overlay cannot be closed), `size` ("sm" | "md" | "lg" | "full", default "md"; `full` runs edge to edge for media), `dismissOnBackdropPress` (default true), `accessibilityLabel`, and `style` for extra panel styles. The scrim, surface, radius, padding and elevation come from the workspace theme — never re-style them. Keep it for screen-level surfaces: a dropdown anchored to its trigger still belongs inside the widget.',
2911
+ 'Screen-level overlay. `<Overlay visible={open} onRequestClose={() => setOpen(false)} size="md">…panel…</Overlay>`. THE way to open anything that must cover the SCREEN rather than the widget and is not a dialog — a preview (PDF, image, video), a lightbox, a full-screen viewer. A dialog (a title, a close button, actions) is `<Modal>`, which is built on this. It renders OUTSIDE the widget layout box on both hosts (react-native-web portals it to the document root; native uses the OS modal), so no `overflow: hidden` card, scroll container or sibling widget can clip or cover it — which absolute positioning inside the widget cannot achieve on either host. Children stay in your own React tree, so state and hooks work normally. Props: `visible` (boolean, required to show), `onRequestClose` (fired by the backdrop press, the Escape key on web, and the Android back button — always wire it or the overlay cannot be closed), `size` ("sm" | "md" | "lg" | "full", default "md"; `full` runs edge to edge for media), `presentation` ("dialog", centred, the default | "sheet", anchored to the bottom edge), `dismissOnBackdropPress` (default true), `role` ("dialog" default | "alertdialog"; web only), `initialFocusRef` (web only), `accessibilityLabel` (names the dialog), `testID`, and `style` for extra panel styles. The scrim, surface, radius, padding and elevation come from the workspace theme (the scrim from Design > Components > Dialogs) — never re-style them. Keep it for screen-level surfaces: a dropdown anchored to its trigger still belongs inside the widget.',
2912
+ rnComponent: null,
2913
+ docsUrl: null,
2914
+ },
2915
+ // The standard dialog, built on `<Overlay>`, so widgets stop hand-building one.
2916
+ {
2917
+ name: "Modal",
2918
+ description:
2919
+ 'Standard dialog. `<Modal visible={open} onRequestClose={() => setOpen(false)} title="Edit order" footer={<><Button variant="secondary" title="Cancel" onPress={() => setOpen(false)} /><Button title="Save" onPress={save} /></>}>…body…</Modal>`. THE way to open a dialog, a form in a pop-up, a detail panel or a bottom sheet: it draws the title, the close button, a body that scrolls when it is long, and a footer action row laid out below it, and its background, corner radius, padding, scrim, shadow and title colour come from the theme (Design > Components > Dialogs), so every dialog in the app matches. It is built on `<Overlay>`, so it renders OUTSIDE the widget layout box on both hosts and nothing can clip it. Never hand-build a header, a close button or an action row inside a bare `<Overlay>`; keep `<Overlay>` for surfaces that are not a dialog (a media or document preview, a lightbox). Props: `visible` (boolean), `onRequestClose` (fired by the close button, the backdrop press, the Escape key on web and the Android back button — always wire it), `dismissible` (default true; false hides the close button and stops the backdrop, Escape and Android back from closing it, for a dialog that must stay open while it saves — only while that work runs, and always restore it, or nobody can close the dialog), `title` (string), `footer` (the action buttons, laid out as one right-aligned row that wraps on a phone; omit for no footer), `presentation` ("dialog", centred, the default | "sheet", anchored to the bottom edge; keep a form with text inputs in "dialog" — in the exported app the keyboard handling of a sheet is not yet verified on a device), `size` ("sm" | "md" | "lg" | "full", default "md"), `dismissOnBackdropPress` (default true), `role` ("dialog" default | "alertdialog"; web only), `initialFocusRef` (a ref to the control focused on open; web only), `closeAccessibilityLabel` (default "Close" — pass your translated label), `accessibilityLabel` (names a dialog with no title) and `testID`. With no `onRequestClose` it draws no close button. Components rendered inside it read a theme re-inked for the background the dialog paints, so build the body as its own component. Do not wrap the body in your own `ScrollView` and do not re-style the panel.',
2890
2920
  rnComponent: null,
2891
2921
  docsUrl: null,
2892
2922
  },
@@ -3026,7 +3056,35 @@ const PRIMITIVES = [
3026
3056
  {
3027
3057
  name: "TextField",
3028
3058
  description:
3029
- 'Themed text-entry field. `<TextField value={name} onChangeText={setName} placeholder="Your name" accessibilityLabel="Name" />` — every `TextInput` prop works, and its background, text colour, border, corner radius and height come from the app\'s input look (Theme Settings > Muted), so a widget\'s fields match the built-in forms. `multiline` grows the field to a ceiling and then scrolls inside it. Override one field with `background`, `textColor`, `borderColor`, `radius` or `height`; `style` is merged last. Use it instead of styling a bare `TextInput`.',
3059
+ 'Themed text-entry field. `<TextField value={name} onChangeText={setName} placeholder="Your name" accessibilityLabel="Name" />` — every `TextInput` prop works, and its background, text colour, border, corner radius and height come from the app\'s input look (Theme Settings > Muted), so a widget\'s fields match the built-in forms. `multiline` grows the field to a ceiling and then scrolls inside it. Override one field with `background`, `textColor`, `borderColor`, `radius` or `height`; `style` is merged last. `label` draws a label above the field and names it for a screen reader, `helper` a hint below, `error` a message in the helper\'s place with a danger border (`true` marks it without a message), `disabled` makes it read-only and dimmed; `containerStyle` styles the box around a labelled field. Use it instead of styling a bare `TextInput`.',
3060
+ rnComponent: null,
3061
+ docsUrl: null,
3062
+ },
3063
+ {
3064
+ name: "Checkbox",
3065
+ description:
3066
+ 'Themed tick box. `<Checkbox label="Remember me" value={checked} onValueChange={setChecked} />` — THE way to draw a yes/no choice that is submitted with a form, or one row of a multi-select list. The box is the app\'s input surface (Design > Components > Muted) and fills with the primary colour when checked; focus draws a ring in the primary colour around it. The whole row is one 44px target with the checkbox role and checked state on both hosts, and Space toggles it on the web. Props: `value` (boolean), `onValueChange(next)`, `label` (text, or an element), `helper`, `error` (a message, or `true`), `disabled`, `accessibilityLabel` (required when there is no text `label`), `style` (the row), `containerStyle` (the box around a row that shows a helper or error), `testID`; any other prop lands on the row. Never hand-roll a tick box from `Pressable` + a bordered `View` + a "✓".',
3067
+ rnComponent: null,
3068
+ docsUrl: null,
3069
+ },
3070
+ {
3071
+ name: "Select",
3072
+ description:
3073
+ 'Themed single-choice picker. `<Select label="Status" value={status} onValueChange={setStatus} options={[{ value: "open", label: "Open" }, { value: "done", label: "Done" }]} placeholder="Choose a status" />` — THE way to let the user pick ONE of a known list. The trigger is the app\'s input field (Design > Components > Muted) showing the chosen label; pressing it opens the options at SCREEN level, in a sheet painted from Design > Components > Popover, so no card or scroll container can clip them, and a long list scrolls inside the sheet. The trigger is a button that opens a dialog (expanded state included) and each option carries the option role and its selected state on both hosts; the list around them is a listbox on the web only. On the web Enter, Space or an arrow key opens it, the arrow keys, Home and End move between options, Enter or Space chooses, Escape closes, and focus returns to the trigger; on Android the back button closes it. Props: `options` (`[{ value, label, disabled?, testID? }]`, `value` a string or number, unique), `value`, `onValueChange(value, option)`, `placeholder` (default "Select"), `title` (the sheet\'s heading; defaults to a text `label`), `emptyText` (default "No options"), `label`, `helper`, `error`, `disabled`, `accessibilityLabel`, `closeAccessibilityLabel`, `background` / `textColor` / `borderColor` / `radius` / `height` to override one field, `style` (the trigger), `containerStyle`, `testID`; any other prop lands on the trigger. Never hand-roll a dropdown from `Pressable` + an absolutely positioned list: it is clipped by the widget\'s container on both hosts.',
3074
+ rnComponent: null,
3075
+ docsUrl: null,
3076
+ },
3077
+ {
3078
+ name: "SearchField",
3079
+ description:
3080
+ 'Themed search box. `<SearchField value={query} onChangeText={setQuery} placeholder="Search orders" />` — THE way to draw a field that filters or searches. It IS a `TextField` (same look, same props, same `label` / `helper` / `error` / `disabled`) with a search glyph, the search key on the on-screen keyboard and a clear control that appears once there is text; clearing calls `onChangeText("")`, then `onClear` if you passed one, and keeps focus in the field. `placeholder` defaults to "Search" and `clearAccessibilityLabel` to "Clear search" — pass translated ones. `style` styles the input and `containerStyle` the box around it (use it for `flex: 1` in a toolbar). Debounce the query yourself before you fetch. Never hand-roll a search box from a `TextInput` + an icon.',
3081
+ rnComponent: null,
3082
+ docsUrl: null,
3083
+ },
3084
+ {
3085
+ name: "spaceActivates",
3086
+ description:
3087
+ 'Space-key activation for a control whose role is not a button. `<Pressable accessibilityRole="radio" aria-checked={on} onPress={pick} onKeyDown={spaceActivates(pick)} />`. On the web a `Pressable` answers Enter for every role but Space only for a button, and Space is the key a checkbox, radio, switch or option is operated with; this restores it, once per key press. Native ignores `onKeyDown`, so it is safe on both hosts. `<Checkbox>` and `<Select>` already use it — reach for it only for a control you build yourself.',
3030
3088
  rnComponent: null,
3031
3089
  docsUrl: null,
3032
3090
  },
@@ -5550,7 +5608,23 @@ const CONTRACT = deepFreeze({
5550
5608
  // 1.166.0: additive (sc-10927) — the `Banner` primitive (a themed inline
5551
5609
  // error, warning, success or notice) and the `alert` component scope it
5552
5610
  // reads.
5553
- version: "1.166.0",
5611
+ // 1.169.0: additive (sc-10924) — the `Modal` primitive: the standard dialog
5612
+ // (title, close button, scrolling body, footer action row; `presentation`
5613
+ // "dialog" | "sheet") built on `Overlay`. New `themeComponents.modal`
5614
+ // scope (background, titleColor, scrim, radius, padding, shadow), read by
5615
+ // `Modal`; `Overlay` reads its `scrim` and gains `presentation`, `role`,
5616
+ // `initialFocusRef`, `backdropAccessible` and `testID`. A scope may now
5617
+ // name `sdkComponents` and bind no widget field; a colour token may be
5618
+ // `translucent` (always painted see-through) and carry a `note`.
5619
+ // 1.171.0: (sc-10929) — the form controls `Checkbox`, `Select` and
5620
+ // `SearchField`, and the `spaceActivates` helper. `TextField` gains
5621
+ // `label`, `helper`, `error`, `disabled` and `containerStyle`. The `muted`
5622
+ // and `popover` scopes name the `sdkComponents` that read them directly.
5623
+ // VISIBLE CHANGE, not additive: `Switch` is now the themed platform
5624
+ // switch, so an existing `<Switch>` with no colour props is repainted:
5625
+ // its tracks follow the theme on both hosts and its "on" thumb is white
5626
+ // on the web. A caller's `trackColor` / `thumbColor` still win.
5627
+ version: "1.171.0",
5554
5628
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
5555
5629
  hooks: HOOKS,
5556
5630
  primitives: PRIMITIVES,
@@ -0,0 +1,55 @@
1
+ // The form controls' pure rules: what counts as shown, how a control is
2
+ // named, when the frame is needed, and the keys a non-button role answers.
3
+ // No renderer here, so the node suite can test them and both hosts share them.
4
+
5
+ export function isShown(value) {
6
+ return value !== undefined && value !== null && value !== false && value !== "";
7
+ }
8
+
9
+ export function isText(value) {
10
+ return typeof value === "string" || typeof value === "number";
11
+ }
12
+
13
+ /** The spoken name of a control: its own label, else its visible one. */
14
+ export function spokenLabel(accessibilityLabel, label) {
15
+ if (isShown(accessibilityLabel)) return accessibilityLabel;
16
+ return isText(label) ? String(label) : undefined;
17
+ }
18
+
19
+ /** An `error` that carries a message (`true` only marks the control). */
20
+ export function errorMessage(error) {
21
+ return isShown(error) && error !== true ? error : null;
22
+ }
23
+
24
+ /** Whether the frame draws a helper or an error line under the control. */
25
+ export function hasNote({ helper, error }) {
26
+ return errorMessage(error) !== null || isShown(helper);
27
+ }
28
+
29
+ /** Whether a control needs the frame at all, or renders bare. */
30
+ export function needsFrame({ label, helper, error }) {
31
+ return isShown(label) || hasNote({ helper, error });
32
+ }
33
+
34
+ /** Hand one node to both a forwarded ref and the control's own. */
35
+ export function shareRef(forwarded, own) {
36
+ return (node) => {
37
+ own.current = node;
38
+ if (typeof forwarded === "function") forwarded(node);
39
+ else if (forwarded) forwarded.current = node;
40
+ };
41
+ }
42
+
43
+ // The web host presses a non-button role on Enter only; Space is the key a
44
+ // checkbox, a radio and an option are operated with. Native ignores onKeyDown.
45
+ export function spaceActivates(onPress) {
46
+ return (event) => {
47
+ if (event.key !== " " && event.key !== "Spacebar") return;
48
+ // A shortcut, or a space typed into a field nested in the control.
49
+ if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return;
50
+ if (event.target && event.currentTarget && event.target !== event.currentTarget) return;
51
+ event.preventDefault();
52
+ // A held key must not also act on whatever its first press focused.
53
+ if (!event.repeat) onPress();
54
+ };
55
+ }
@@ -0,0 +1,121 @@
1
+ // The values the form controls (`<Checkbox>`, `<Switch>`, `<Select>`,
2
+ // `<SearchField>`) paint with. The field itself is `<TextField>`'s own
3
+ // resolution, so all five follow the theme's `muted` scope as one and show
4
+ // focus in the accent; the Select's option list adds the `popover` scope.
5
+ // Platform-free.
6
+
7
+ import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
8
+ import { resolveTextFieldTokens } from "./text-field-tokens.js";
9
+
10
+ // The smallest target a finger can hit reliably, as the field's own floor.
11
+ export const CONTROL_MIN_TARGET = 44;
12
+ export const CHECKBOX_SIZE = 22;
13
+ export const CHECKBOX_MAX_RADIUS = 6;
14
+ export const HALO_WIDTH = 2;
15
+ export const HALO_GAP = 2;
16
+ export const DISABLED_OPACITY = 0.5;
17
+
18
+ function isSet(value) {
19
+ return value !== undefined && value !== null && value !== "";
20
+ }
21
+
22
+ /**
23
+ * Resolve one form control from the workspace theme.
24
+ *
25
+ * @param {object} theme — the resolved workspace theme (`useTheme()` shape).
26
+ * @param {object} [overrides] — per-control values keyed by TEXT_FIELD_TOKEN_NAMES.
27
+ */
28
+ export function resolveFormControlTokens(theme, overrides) {
29
+ const base = theme && typeof theme === "object" ? theme : DEFAULT_THEME_TOKENS;
30
+ const colors = base.colors || DEFAULT_THEME_TOKENS.colors;
31
+ const spacing = base.spacing || DEFAULT_THEME_TOKENS.spacing;
32
+ const typography = base.typography || DEFAULT_THEME_TOKENS.typography;
33
+ const popover = (base.components && base.components.popover) || {};
34
+ const field = resolveTextFieldTokens(base, overrides);
35
+ return {
36
+ ...field,
37
+ // The checked and on states are the accent, as a primary button is.
38
+ accent: colors.primary,
39
+ onAccent: colors.onPrimary,
40
+ labelColor: colors.onSurface,
41
+ helperColor: colors.onSurfaceMuted,
42
+ labelSize: typography.sizes.sm,
43
+ helperSize: typography.sizes.xs,
44
+ gap: spacing.xs,
45
+ rowGap: spacing.sm,
46
+ disabledOpacity: DISABLED_OPACITY,
47
+ errorColor: colors.danger,
48
+ popover: {
49
+ background: isSet(popover.background) ? popover.background : colors.surface,
50
+ textColor: isSet(popover.textColor) ? popover.textColor : colors.onSurface,
51
+ borderColor: isSet(popover.borderColor) ? popover.borderColor : colors.border,
52
+ },
53
+ };
54
+ }
55
+
56
+ /**
57
+ * The ring drawn AROUND a filled control (a checkbox, a switch), whose own
58
+ * border cannot show focus once it is the accent. Its width is always
59
+ * reserved, so focusing never moves the control.
60
+ *
61
+ * @param {object} t — resolved form-control tokens.
62
+ * @param {boolean} focused
63
+ * @param {number} radius — the control's own corner radius.
64
+ */
65
+ export function focusHaloStyle(t, focused, radius) {
66
+ return {
67
+ padding: HALO_GAP,
68
+ borderWidth: HALO_WIDTH,
69
+ borderRadius: radius + HALO_GAP + HALO_WIDTH,
70
+ borderColor: focused ? t.focusColor : "transparent",
71
+ };
72
+ }
73
+
74
+ /**
75
+ * The colours a switch hands the platform control. A caller's `trackColor`
76
+ * overrides the theme per state, and iOS, which paints the off track from
77
+ * `ios_backgroundColor`, follows the off colour unless told otherwise.
78
+ *
79
+ * @param {object} t — resolved form-control tokens.
80
+ * @param {{trackColor?: object, iosBackgroundColor?: string, invalid?: boolean}} own
81
+ */
82
+ export function resolveSwitchColors(t, own) {
83
+ const { trackColor, iosBackgroundColor, invalid } = own || {};
84
+ const offTrack = invalid ? t.errorColor : t.borderColor;
85
+ const track = {
86
+ false: offTrack,
87
+ true: t.accent,
88
+ ...(trackColor && typeof trackColor === "object" ? trackColor : null),
89
+ };
90
+ return { trackColor: track, iosBackgroundColor: iosBackgroundColor ?? track.false };
91
+ }
92
+
93
+ /** The option whose `value` is the selected one, or `undefined`. */
94
+ export function selectedOption(options, value) {
95
+ if (!Array.isArray(options)) return undefined;
96
+ return options.find((option) => option && option.value === value);
97
+ }
98
+
99
+ /**
100
+ * The index focus moves to for a navigation key, skipping disabled options
101
+ * and stopping at either end. Returns `from` when the key moves nothing.
102
+ *
103
+ * @param {Array<{disabled?: boolean}>} options
104
+ * @param {number} from — the focused option's index.
105
+ * @param {string} key — a KeyboardEvent `key`.
106
+ */
107
+ export function nextOptionIndex(options, from, key) {
108
+ const list = Array.isArray(options) ? options : [];
109
+ const enabled = (i) => list[i] && !list[i].disabled;
110
+ const scan = (start, step) => {
111
+ for (let i = start; i >= 0 && i < list.length; i += step) {
112
+ if (enabled(i)) return i;
113
+ }
114
+ return from;
115
+ };
116
+ if (key === "ArrowDown") return scan(from + 1, 1);
117
+ if (key === "ArrowUp") return scan(from - 1, -1);
118
+ if (key === "Home") return scan(0, 1);
119
+ if (key === "End") return scan(list.length - 1, -1);
120
+ return from;
121
+ }
@@ -0,0 +1,98 @@
1
+ // What every form control shares on screen: the label above it and the helper
2
+ // or error below it. One frame, so `<TextField>`, `<Checkbox>`, `<Switch>`,
3
+ // `<Select>` and `<SearchField>` cannot drift apart. Its rules, which need no
4
+ // renderer, live in ./form-control-logic.js.
5
+
6
+ import React from "react";
7
+ import { errorMessage, isShown, isText } from "./form-control-logic.js";
8
+
9
+ const h = React.createElement;
10
+
11
+ /**
12
+ * Bind the shared frame to one platform's primitives.
13
+ *
14
+ * @param {{View: any, Text: any, Pressable: any}} rn
15
+ */
16
+ export function makeFieldFrame(rn) {
17
+ const { View, Text, Pressable } = rn;
18
+
19
+ /**
20
+ * @param {object} props
21
+ * @param {object} props.t — resolved form-control tokens.
22
+ * @param {any} [props.label] — text, or an element rendered as given.
23
+ * @param {any} [props.helper]
24
+ * @param {any} [props.error] — a message replaces the helper; `true` shows none.
25
+ * @param {string} [props.noteId] — the id the control's `aria-describedby` names.
26
+ * @param {() => void} [props.onLabelPress] — a text label then acts for the control.
27
+ * @param {boolean} [props.noteDisabled] — dim the note alone, when the
28
+ * control dims itself and `disabled` would dim it twice.
29
+ */
30
+ function FieldFrame({
31
+ t,
32
+ label,
33
+ helper,
34
+ error,
35
+ disabled,
36
+ noteId,
37
+ onLabelPress,
38
+ noteDisabled,
39
+ style,
40
+ children,
41
+ }) {
42
+ const message = errorMessage(error);
43
+ const note = message || (isShown(helper) ? helper : null);
44
+ const labelText = isText(label)
45
+ ? h(
46
+ Text,
47
+ {
48
+ style: {
49
+ color: t.labelColor,
50
+ fontFamily: t.fontFamily,
51
+ fontSize: t.labelSize,
52
+ fontWeight: "500",
53
+ },
54
+ },
55
+ label,
56
+ )
57
+ : null;
58
+ return h(
59
+ View,
60
+ { style: [{ gap: t.gap }, disabled ? { opacity: t.disabledOpacity } : null, style] },
61
+ labelText && typeof onLabelPress === "function"
62
+ ? h(
63
+ Pressable,
64
+ {
65
+ onPress: onLabelPress,
66
+ disabled,
67
+ // The control is the one stop for a keyboard and a reader.
68
+ tabIndex: -1,
69
+ accessible: false,
70
+ style: { alignSelf: "flex-start" },
71
+ },
72
+ labelText,
73
+ )
74
+ : labelText || (isShown(label) ? label : null),
75
+ children,
76
+ isText(note)
77
+ ? h(
78
+ Text,
79
+ {
80
+ nativeID: noteId,
81
+ // Announced where the host can: the web and Android.
82
+ ...(message ? { accessibilityLiveRegion: "polite" } : null),
83
+ style: {
84
+ color: message ? t.errorColor : t.helperColor,
85
+ fontFamily: t.fontFamily,
86
+ fontSize: t.helperSize,
87
+ ...(noteDisabled ? { opacity: t.disabledOpacity } : null),
88
+ },
89
+ },
90
+ note,
91
+ )
92
+ : note,
93
+ );
94
+ }
95
+
96
+ FieldFrame.displayName = "FieldFrame";
97
+ return FieldFrame;
98
+ }
package/dist/hooks.js CHANGED
@@ -89,6 +89,19 @@ export function BackdropScope({ basis, children }) {
89
89
  return React.createElement(HostWidgetContext.Provider, { value }, children);
90
90
  }
91
91
 
92
+ /**
93
+ * @internal — hands a subtree `theme` in place of the host's (`<Modal>` uses
94
+ * it for the theme re-inked for its own background). No theme, no change.
95
+ */
96
+ export function ThemeScope({ theme, children }) {
97
+ const ctx = useContext(HostWidgetContext);
98
+ const value = useMemo(
99
+ () => (theme && ctx ? { ...ctx, workspace: { ...ctx.workspace, theme } } : ctx),
100
+ [ctx, theme],
101
+ );
102
+ return React.createElement(HostWidgetContext.Provider, { value }, children);
103
+ }
104
+
92
105
  // Exported for ./toast.js + future hook modules outside hooks.js. Internal
93
106
  // utility — widget code should not import this directly.
94
107
  export function useWidgetContextOrThrow(hookName) {
package/dist/host.d.ts CHANGED
@@ -45,6 +45,13 @@ export function normaliseThemeComponents(raw: unknown): ThemeComponents;
45
45
  */
46
46
  export function bannerScopeDefaults(theme: unknown): Record<string, string | number>;
47
47
 
48
+ /**
49
+ * The theme a surface painting `backgroundColor` hands its subtree: surface
50
+ * tokens derived for that fill, and any type tier whose own ink cannot be read
51
+ * on it re-inked. Returns `theme` itself when the colour is unusable.
52
+ */
53
+ export function surfaceAwareTheme<T>(theme: T, backgroundColor: unknown): T;
54
+
48
55
  /** Minimum contrast: `text` for labels (WCAG 1.4.3), `boundary` for edges (1.4.11). */
49
56
  export const INK_CONTRAST: Readonly<{ text: number; boundary: number }>;
50
57
 
@@ -152,6 +159,45 @@ export interface ToastControllerOptions {
152
159
  clearTimer?: (handle: unknown) => void;
153
160
  }
154
161
 
162
+ /** What one `<Modal>` paints with; see `resolveModalTokens`. */
163
+ export interface ModalTokens {
164
+ size: "sm" | "md" | "lg" | "full";
165
+ presentation: "dialog" | "sheet";
166
+ scrim: string;
167
+ /** The `background` token as set (it may be see-through), else the surface. */
168
+ background: string;
169
+ /** What the panel paints: `background` composited over the overlay surface. */
170
+ panelColor: string;
171
+ /** `panelColor` when a background is set, for re-inking the body; else null. */
172
+ bodyBackdrop: string | null;
173
+ radius: number;
174
+ padding: number;
175
+ /** The themed elevation as a style, or null for the overlay's own. */
176
+ shadow: Record<string, unknown> | null;
177
+ /** The elevation level in force: the themed one, else the overlay's. */
178
+ shadowLevel: "none" | "sm" | "md" | "lg";
179
+ titleColor: string;
180
+ closeColor: string;
181
+ sectionGap: number;
182
+ actionGap: number;
183
+ }
184
+
185
+ /**
186
+ * The look of the SDK `<Modal>` under a resolved theme: its `modal` component
187
+ * scope over the overlay's defaults. For a host previewing Theme Settings >
188
+ * Dialogs with the values the dialog itself paints.
189
+ */
190
+ export function resolveModalTokens(
191
+ theme: unknown,
192
+ options?: { size?: string; presentation?: string },
193
+ ): ModalTokens;
194
+
195
+ /**
196
+ * What the `modal` scope's tokens without a `uiDefault` path resolve to while
197
+ * unset: the scrim, and the title colour on the background currently set.
198
+ */
199
+ export function modalScopeDefaults(theme: unknown): { scrim: string; titleColor: string };
200
+
155
201
  export const TOAST_DEFAULTS: { durationMs: number; maxVisible: number };
156
202
 
157
203
  export function normalizeToastKind(kind: unknown): ToastKind;
package/dist/host.js CHANGED
@@ -42,12 +42,16 @@ export {
42
42
  // Host plumbing, deliberately off the author entry point: a widget reads the
43
43
  // already-correct `useTheme().colors`, it never derives them itself.
44
44
  export { deriveSurfaceTokens, inkForBackdrop, INK_CONTRAST } from "./contract.js";
45
+ export { surfaceAwareTheme } from "./surface-theme.js";
45
46
 
46
47
  // REQ-WSDK-PLATFORM §6: the host half of `useToast()` — the queue, the
47
48
  // auto-dismiss timing, and the themed values a toast is painted with. The
48
49
  // widget-facing hook only forwards to `ctx.toast.showToast`; the host owns the
49
50
  // surface, and sharing everything but the JSX is what keeps the web Player and
50
51
  // the Expo export rendering the same notification (CLAUDE.md §8).
52
+ // The dialog's resolved look, for the Studio's Design > Components > Dialogs preview.
53
+ export { resolveModalTokens, modalScopeDefaults } from "./modal-tokens.js";
54
+
51
55
  export {
52
56
  createToastController,
53
57
  resolveToastTokens,