@dcs-tech/ui-native 0.0.0-stage → 0.15.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 (187) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/README.md +178 -2
  3. package/dist/components/Button/Button.js +61 -0
  4. package/dist/components/Button/buttonStyle.js +100 -0
  5. package/dist/components/Button/index.js +1 -0
  6. package/dist/components/Checkbox/Checkbox.js +60 -0
  7. package/dist/components/Checkbox/checkboxStyle.js +44 -0
  8. package/dist/components/Checkbox/index.js +1 -0
  9. package/dist/components/DataTable/BulkRun.js +85 -0
  10. package/dist/components/DataTable/CardList.js +70 -0
  11. package/dist/components/DataTable/DataTable.js +53 -0
  12. package/dist/components/DataTable/DataTableScrollView.js +33 -0
  13. package/dist/components/DataTable/DragSelect.js +153 -0
  14. package/dist/components/DataTable/LayoutSwitcher.js +48 -0
  15. package/dist/components/DataTable/Pager.js +15 -0
  16. package/dist/components/DataTable/RowActions.js +28 -0
  17. package/dist/components/DataTable/RowDetail.js +80 -0
  18. package/dist/components/DataTable/RowMenuSheet.js +72 -0
  19. package/dist/components/DataTable/SortSheet.js +25 -0
  20. package/dist/components/DataTable/SplitList.js +30 -0
  21. package/dist/components/DataTable/StatusRow.js +48 -0
  22. package/dist/components/DataTable/SwipeRow.js +125 -0
  23. package/dist/components/DataTable/ToolButton.js +9 -0
  24. package/dist/components/DataTable/Toolbar.js +53 -0
  25. package/dist/components/DataTable/cells.js +21 -0
  26. package/dist/components/DataTable/dataTableStyle.js +218 -0
  27. package/dist/components/DataTable/filters/FilterConditionRow.js +48 -0
  28. package/dist/components/DataTable/filters/FilterGroupEditor.js +21 -0
  29. package/dist/components/DataTable/filters/FilterSheet.js +67 -0
  30. package/dist/components/DataTable/filters/SavedFilterBar.js +39 -0
  31. package/dist/components/DataTable/filters/filterStyle.js +82 -0
  32. package/dist/components/DataTable/index.js +3 -0
  33. package/dist/components/DataTable/persistence/adapters.js +78 -0
  34. package/dist/components/DataTable/persistence/useViewPrefs.js +76 -0
  35. package/dist/components/DataTable/rowParts.js +47 -0
  36. package/dist/components/DataTable/useTableState.js +328 -0
  37. package/dist/components/DatePicker/Calendar.js +28 -0
  38. package/dist/components/DatePicker/DatePicker.js +296 -0
  39. package/dist/components/DatePicker/PeriodGrid.js +17 -0
  40. package/dist/components/DatePicker/PeriodPicker.js +213 -0
  41. package/dist/components/DatePicker/TimeField.js +50 -0
  42. package/dist/components/DatePicker/datePickerStyle.js +157 -0
  43. package/dist/components/DatePicker/index.js +2 -0
  44. package/dist/components/Dialog/Dialog.js +104 -0
  45. package/dist/components/Dialog/DialogHost.js +71 -0
  46. package/dist/components/Dialog/dialogStyle.js +72 -0
  47. package/dist/components/Dialog/index.js +2 -0
  48. package/dist/components/FieldContext/FieldContext.js +50 -0
  49. package/dist/components/FieldContext/index.js +1 -0
  50. package/dist/components/FieldWrapper/FieldWrapper.js +23 -0
  51. package/dist/components/FieldWrapper/fieldWrapperStyle.js +64 -0
  52. package/dist/components/FieldWrapper/index.js +1 -0
  53. package/dist/components/Icon/Icon.js +124 -0
  54. package/dist/components/Icon/IconContext.js +12 -0
  55. package/dist/components/Icon/iconStyle.js +59 -0
  56. package/dist/components/Icon/icons.js +239 -0
  57. package/dist/components/Icon/index.js +4 -0
  58. package/dist/components/Icon/useIconDone.js +19 -0
  59. package/dist/components/Input/Input.js +71 -0
  60. package/dist/components/Input/index.js +1 -0
  61. package/dist/components/Input/inputStyle.js +47 -0
  62. package/dist/components/Press/Ripple.js +92 -0
  63. package/dist/components/Press/index.js +1 -0
  64. package/dist/components/Press/measure.js +3 -0
  65. package/dist/components/Radio/Radio.js +54 -0
  66. package/dist/components/Radio/index.js +1 -0
  67. package/dist/components/Radio/radioStyle.js +45 -0
  68. package/dist/components/Select/Select.js +83 -0
  69. package/dist/components/Select/SelectSheet.js +85 -0
  70. package/dist/components/Select/index.js +1 -0
  71. package/dist/components/Suggest/Suggest.js +101 -0
  72. package/dist/components/Suggest/index.js +1 -0
  73. package/dist/components/Switch/Switch.js +71 -0
  74. package/dist/components/Switch/index.js +1 -0
  75. package/dist/components/Switch/switchStyle.js +59 -0
  76. package/dist/components/Toast/ToastHost.js +76 -0
  77. package/dist/components/Toast/ToastItem.js +115 -0
  78. package/dist/components/Toast/ToastLayer.js +21 -0
  79. package/dist/components/Toast/index.js +2 -0
  80. package/dist/components/Toast/toast.types.js +1 -0
  81. package/dist/components/Toast/toastStyle.js +73 -0
  82. package/dist/components/Toggle/ToggleField.js +20 -0
  83. package/dist/components/Toggle/ToggleGroupFrame.js +10 -0
  84. package/dist/components/UIProvider/UIProvider.js +14 -0
  85. package/dist/components/UIProvider/context.js +57 -0
  86. package/dist/components/UIProvider/index.js +1 -0
  87. package/dist/components/styles/color.js +35 -0
  88. package/dist/components/styles/fieldControl.js +102 -0
  89. package/dist/components/styles/popupList.js +102 -0
  90. package/dist/components/styles/toggle.js +64 -0
  91. package/dist/components/styles/webValues.js +147 -0
  92. package/dist/index.js +15 -0
  93. package/dist/locales/hi.js +1 -0
  94. package/dist/locales/ta.js +1 -0
  95. package/dist/types/components/Button/Button.d.ts +31 -0
  96. package/dist/types/components/Button/buttonStyle.d.ts +46 -0
  97. package/dist/types/components/Button/index.d.ts +3 -0
  98. package/dist/types/components/Checkbox/Checkbox.d.ts +60 -0
  99. package/dist/types/components/Checkbox/checkboxStyle.d.ts +16 -0
  100. package/dist/types/components/Checkbox/index.d.ts +3 -0
  101. package/dist/types/components/DataTable/BulkRun.d.ts +11 -0
  102. package/dist/types/components/DataTable/CardList.d.ts +18 -0
  103. package/dist/types/components/DataTable/DataTable.d.ts +11 -0
  104. package/dist/types/components/DataTable/DataTableScrollView.d.ts +10 -0
  105. package/dist/types/components/DataTable/DragSelect.d.ts +12 -0
  106. package/dist/types/components/DataTable/LayoutSwitcher.d.ts +23 -0
  107. package/dist/types/components/DataTable/Pager.d.ts +5 -0
  108. package/dist/types/components/DataTable/RowActions.d.ts +13 -0
  109. package/dist/types/components/DataTable/RowDetail.d.ts +15 -0
  110. package/dist/types/components/DataTable/RowMenuSheet.d.ts +5 -0
  111. package/dist/types/components/DataTable/SortSheet.d.ts +8 -0
  112. package/dist/types/components/DataTable/SplitList.d.ts +9 -0
  113. package/dist/types/components/DataTable/StatusRow.d.ts +7 -0
  114. package/dist/types/components/DataTable/SwipeRow.d.ts +25 -0
  115. package/dist/types/components/DataTable/ToolButton.d.ts +13 -0
  116. package/dist/types/components/DataTable/Toolbar.d.ts +8 -0
  117. package/dist/types/components/DataTable/cells.d.ts +13 -0
  118. package/dist/types/components/DataTable/dataTableStyle.d.ts +139 -0
  119. package/dist/types/components/DataTable/filters/FilterConditionRow.d.ts +12 -0
  120. package/dist/types/components/DataTable/filters/FilterGroupEditor.d.ts +13 -0
  121. package/dist/types/components/DataTable/filters/FilterSheet.d.ts +5 -0
  122. package/dist/types/components/DataTable/filters/SavedFilterBar.d.ts +20 -0
  123. package/dist/types/components/DataTable/filters/filterStyle.d.ts +46 -0
  124. package/dist/types/components/DataTable/index.d.ts +5 -0
  125. package/dist/types/components/DataTable/persistence/adapters.d.ts +12 -0
  126. package/dist/types/components/DataTable/persistence/useViewPrefs.d.ts +20 -0
  127. package/dist/types/components/DataTable/rowParts.d.ts +32 -0
  128. package/dist/types/components/DataTable/useTableState.d.ts +103 -0
  129. package/dist/types/components/DatePicker/Calendar.d.ts +11 -0
  130. package/dist/types/components/DatePicker/DatePicker.d.ts +65 -0
  131. package/dist/types/components/DatePicker/PeriodGrid.d.ts +11 -0
  132. package/dist/types/components/DatePicker/PeriodPicker.d.ts +10 -0
  133. package/dist/types/components/DatePicker/TimeField.d.ts +15 -0
  134. package/dist/types/components/DatePicker/datePickerStyle.d.ts +75 -0
  135. package/dist/types/components/DatePicker/index.d.ts +4 -0
  136. package/dist/types/components/Dialog/Dialog.d.ts +35 -0
  137. package/dist/types/components/Dialog/DialogHost.d.ts +45 -0
  138. package/dist/types/components/Dialog/dialogStyle.d.ts +23 -0
  139. package/dist/types/components/Dialog/index.d.ts +4 -0
  140. package/dist/types/components/FieldContext/FieldContext.d.ts +43 -0
  141. package/dist/types/components/FieldContext/index.d.ts +3 -0
  142. package/dist/types/components/FieldWrapper/FieldWrapper.d.ts +23 -0
  143. package/dist/types/components/FieldWrapper/fieldWrapperStyle.d.ts +24 -0
  144. package/dist/types/components/FieldWrapper/index.d.ts +3 -0
  145. package/dist/types/components/Icon/Icon.d.ts +37 -0
  146. package/dist/types/components/Icon/IconContext.d.ts +12 -0
  147. package/dist/types/components/Icon/iconStyle.d.ts +10 -0
  148. package/dist/types/components/Icon/icons.d.ts +237 -0
  149. package/dist/types/components/Icon/index.d.ts +7 -0
  150. package/dist/types/components/Icon/useIconDone.d.ts +4 -0
  151. package/dist/types/components/Input/Input.d.ts +53 -0
  152. package/dist/types/components/Input/index.d.ts +3 -0
  153. package/dist/types/components/Input/inputStyle.d.ts +11 -0
  154. package/dist/types/components/Press/Ripple.d.ts +20 -0
  155. package/dist/types/components/Press/index.d.ts +2 -0
  156. package/dist/types/components/Press/measure.d.ts +8 -0
  157. package/dist/types/components/Radio/Radio.d.ts +58 -0
  158. package/dist/types/components/Radio/index.d.ts +3 -0
  159. package/dist/types/components/Radio/radioStyle.d.ts +17 -0
  160. package/dist/types/components/Select/Select.d.ts +49 -0
  161. package/dist/types/components/Select/SelectSheet.d.ts +34 -0
  162. package/dist/types/components/Select/index.d.ts +3 -0
  163. package/dist/types/components/Suggest/Suggest.d.ts +44 -0
  164. package/dist/types/components/Suggest/index.d.ts +3 -0
  165. package/dist/types/components/Switch/Switch.d.ts +42 -0
  166. package/dist/types/components/Switch/index.d.ts +3 -0
  167. package/dist/types/components/Switch/switchStyle.d.ts +29 -0
  168. package/dist/types/components/Toast/ToastHost.d.ts +12 -0
  169. package/dist/types/components/Toast/ToastItem.d.ts +17 -0
  170. package/dist/types/components/Toast/ToastLayer.d.ts +11 -0
  171. package/dist/types/components/Toast/index.d.ts +5 -0
  172. package/dist/types/components/Toast/toast.types.d.ts +37 -0
  173. package/dist/types/components/Toast/toastStyle.d.ts +22 -0
  174. package/dist/types/components/Toggle/ToggleField.d.ts +31 -0
  175. package/dist/types/components/Toggle/ToggleGroupFrame.d.ts +14 -0
  176. package/dist/types/components/UIProvider/UIProvider.d.ts +16 -0
  177. package/dist/types/components/UIProvider/context.d.ts +20 -0
  178. package/dist/types/components/UIProvider/index.d.ts +2 -0
  179. package/dist/types/components/styles/color.d.ts +2 -0
  180. package/dist/types/components/styles/fieldControl.d.ts +26 -0
  181. package/dist/types/components/styles/popupList.d.ts +48 -0
  182. package/dist/types/components/styles/toggle.d.ts +26 -0
  183. package/dist/types/components/styles/webValues.d.ts +157 -0
  184. package/dist/types/index.d.ts +15 -0
  185. package/dist/types/locales/hi.d.ts +1 -0
  186. package/dist/types/locales/ta.d.ts +1 -0
  187. package/package.json +85 -4
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { Animated, Easing, StyleSheet, View } from 'react-native';
4
+ import { pressReleaseDelay, rippleGeometry } from '@dcs-tech/core';
5
+ import { useTokens } from '../UIProvider/context';
6
+ import { measureOnPage } from './measure';
7
+ let nextId = 1;
8
+ export function useRipple({ color, centered = false, enabled = true }, radius) {
9
+ const t = useTokens();
10
+ const ref = useRef(null);
11
+ const [waves, setWaves] = useState([]);
12
+ const live = useRef([]);
13
+ const mounted = useRef(true);
14
+ useEffect(() => () => { mounted.current = false; }, []);
15
+ const duration = t.rippleDuration;
16
+ const reduced = t.motionScale === 0;
17
+ const e = t.easeInOut;
18
+ const easing = e.type === 'cubicBezier' ? Easing.bezier(e.x1, e.y1, e.x2, e.y2) : Easing.inOut(Easing.ease);
19
+ const drop = useCallback((id) => {
20
+ live.current = live.current.filter(w => w.id !== id);
21
+ if (mounted.current)
22
+ setWaves(live.current);
23
+ }, []);
24
+ const fadeOut = useCallback((w) => {
25
+ Animated.timing(w.fade, { toValue: 0, duration, easing, useNativeDriver: true }).start(() => drop(w.id));
26
+ }, [duration, easing, drop]);
27
+ const onPressIn = useCallback((ev) => {
28
+ const el = ref.current;
29
+ if (!enabled || !el)
30
+ return;
31
+ const { pageX, pageY } = ev.nativeEvent;
32
+ const wave = { id: nextId++, x: 0, y: 0, size: 0, grow: new Animated.Value(reduced ? 1 : 0), fade: new Animated.Value(1), released: false, started: false };
33
+ live.current = [...live.current, wave];
34
+ measureOnPage(el, ({ width, height, left, top }) => {
35
+ if (!mounted.current || !live.current.includes(wave))
36
+ return;
37
+ const g = rippleGeometry({ width, height }, centered ? null : { x: pageX - left, y: pageY - top });
38
+ Object.assign(wave, { x: g.x, y: g.y, size: g.size, started: true });
39
+ setWaves([...live.current]);
40
+ if (!reduced)
41
+ Animated.timing(wave.grow, { toValue: 1, duration, easing, useNativeDriver: true }).start();
42
+ if (wave.released)
43
+ fadeOut(wave);
44
+ });
45
+ }, [enabled, centered, reduced, duration, easing, fadeOut]);
46
+ const onPressOut = useCallback(() => {
47
+ for (const w of live.current) {
48
+ if (w.released)
49
+ continue;
50
+ w.released = true;
51
+ if (w.started)
52
+ fadeOut(w);
53
+ }
54
+ }, [fadeOut]);
55
+ const layer = waves.length ? (_jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { overflow: 'hidden', borderRadius: radius }], children: waves.filter(w => w.started).map(w => (_jsx(Animated.View, { style: {
56
+ position: 'absolute',
57
+ left: w.x - w.size / 2,
58
+ top: w.y - w.size / 2,
59
+ width: w.size,
60
+ height: w.size,
61
+ borderRadius: w.size / 2,
62
+ opacity: reduced ? 1 : w.grow.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] }),
63
+ transform: [{ scale: reduced ? 1 : w.grow.interpolate({ inputRange: [0, 1], outputRange: [0.1, 1] }) }],
64
+ }, children: _jsx(Animated.View, { style: { flex: 1, borderRadius: w.size / 2, backgroundColor: color, opacity: Animated.multiply(w.fade, t.rippleOpacity) } }) }, w.id))) })) : null;
65
+ return { ref, onPressIn, onPressOut, layer };
66
+ }
67
+ export function usePressHold(enabled = true) {
68
+ const t = useTokens();
69
+ const [pressed, setPressed] = useState(false);
70
+ const since = useRef(0);
71
+ const timer = useRef(null);
72
+ useEffect(() => () => { if (timer.current)
73
+ clearTimeout(timer.current); }, []);
74
+ const onPressIn = useCallback(() => {
75
+ if (!enabled)
76
+ return;
77
+ if (timer.current)
78
+ clearTimeout(timer.current);
79
+ since.current = Date.now();
80
+ setPressed(true);
81
+ }, [enabled]);
82
+ const onPressOut = useCallback(() => {
83
+ if (timer.current)
84
+ clearTimeout(timer.current);
85
+ const wait = pressReleaseDelay(Date.now() - since.current, t.durationShort);
86
+ if (wait <= 0)
87
+ setPressed(false);
88
+ else
89
+ timer.current = setTimeout(() => setPressed(false), wait);
90
+ }, [t.durationShort]);
91
+ return { pressed: pressed && enabled, onPressIn, onPressOut };
92
+ }
@@ -0,0 +1 @@
1
+ export { useRipple, usePressHold } from './Ripple';
@@ -0,0 +1,3 @@
1
+ export function measureOnPage(el, done) {
2
+ el.measure((_x, _y, width, height, left, top) => done({ width, height, left, top }));
3
+ }
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useCallback, useContext, useMemo, useState } from 'react';
3
+ import { View } from 'react-native';
4
+ import { useTokens } from '../UIProvider/context';
5
+ import { useToggleSurface } from '../FieldContext/FieldContext';
6
+ import { ToggleField } from '../Toggle/ToggleField';
7
+ import { ToggleGroupFrame } from '../Toggle/ToggleGroupFrame';
8
+ import { toggleColor, toggleHaloStyle, toggleLine, toggleSize } from '../styles/toggle';
9
+ import { useRipple } from '../Press';
10
+ import { radioCircleLook } from './radioStyle';
11
+ const RadioGroupContext = createContext(null);
12
+ export function RadioGroup({ name, value, defaultValue, onChange, onChangeEvent, label, helperText, error, disabled = false, readOnly = false, required = false, orientation = 'vertical', size, variant, color, style, 'aria-label': ariaLabel, children }) {
13
+ const [own, setOwn] = useState(defaultValue);
14
+ const chosen = value ?? own;
15
+ const choose = useCallback((v) => {
16
+ if (disabled || readOnly)
17
+ return;
18
+ if (value === undefined)
19
+ setOwn(v);
20
+ onChange?.(v);
21
+ onChangeEvent?.({ target: { name, value: v, type: 'radio', checked: true } });
22
+ }, [disabled, readOnly, value, onChange, onChangeEvent, name]);
23
+ const ctx = useMemo(() => ({ name, value: chosen, choose, disabled, readOnly, size, variant, color }), [name, chosen, choose, disabled, readOnly, size, variant, color]);
24
+ return (_jsx(RadioGroupContext.Provider, { value: ctx, children: _jsx(ToggleGroupFrame, { role: "radiogroup", label: label, required: required, helper: helperText, error: error, disabled: disabled, orientation: orientation, style: style, "aria-label": ariaLabel, children: children }) }));
25
+ }
26
+ RadioGroup.displayName = 'RadioGroup';
27
+ export function Radio({ name, value, checked, defaultChecked, onChange, label, hint, error, required = false, labelPosition = 'end', disabled, readOnly, size, variant, color, fullWidth = false, checkedIcon, uncheckedIcon, ripple = true, style, testID, 'aria-label': ariaLabel, }) {
28
+ const t = useTokens();
29
+ const group = useContext(RadioGroupContext);
30
+ const surface = useToggleSurface({ size: size ?? group?.size, variant: variant ?? group?.variant, disabled: disabled ?? group?.disabled, readOnly: readOnly ?? group?.readOnly });
31
+ const resolvedColor = color ?? group?.color ?? 'primary';
32
+ const [own, setOwn] = useState(!!defaultChecked);
33
+ const isOn = group ? group.value === value : checked ?? own;
34
+ const hasError = error !== undefined && error !== null && error !== false && error !== '';
35
+ const choose = () => {
36
+ if (isOn)
37
+ return;
38
+ if (group)
39
+ group.choose(value);
40
+ else if (checked === undefined)
41
+ setOwn(true);
42
+ onChange?.({ target: { name: name ?? group?.name, value, type: 'radio', checked: true } });
43
+ };
44
+ const { box } = toggleSize(t, surface.size);
45
+ const wave = useRipple({ color: isOn ? toggleColor(t, resolvedColor).solid : t.textSecondary, centered: true, enabled: ripple && !surface.disabled && !surface.readOnly }, undefined);
46
+ const renderControl = (pressed) => {
47
+ const look = radioCircleLook(t, { size: surface.size, variant: surface.variant, color: resolvedColor, checked: isOn, error: hasError, pressed });
48
+ const custom = isOn ? checkedIcon : uncheckedIcon;
49
+ const halo = box * t.controlHaloSize;
50
+ return (_jsx(View, { style: { minHeight: toggleLine(t, surface.size), justifyContent: 'center' }, children: _jsxs(View, { style: { width: box, height: box }, children: [_jsx(View, { ref: wave.ref, style: [toggleHaloStyle(t, box, toggleColor(t, resolvedColor).solid, isOn, pressed, surface.disabled), { left: (box - halo) / 2, top: (box - halo) / 2 }], children: wave.layer }), _jsx(View, { style: look.circle, children: custom ?? _jsx(View, { style: look.dot }) })] }) }));
51
+ };
52
+ return (_jsx(ToggleField, { role: "radio", checked: isOn, onToggle: choose, size: surface.size, layout: surface.layout, disabled: surface.disabled, readOnly: surface.readOnly, label: label, required: required, labelPosition: labelPosition, error: error, hint: hint, fullWidth: fullWidth, rowLine: toggleLine(t, surface.size), renderControl: renderControl, ripple: wave, style: style, testID: testID, "aria-label": ariaLabel }));
53
+ }
54
+ Radio.displayName = 'Radio';
@@ -0,0 +1 @@
1
+ export { Radio, RadioGroup } from './Radio';
@@ -0,0 +1,45 @@
1
+ import { toggleColor, toggleSize } from '../styles/toggle';
2
+ import { TOGGLE_PRESSED_SCALE } from '../styles/webValues';
3
+ export function radioCircleLook(t, s) {
4
+ const { box: size } = toggleSize(t, s.size);
5
+ const c = toggleColor(t, s.color);
6
+ let border;
7
+ let background;
8
+ let mark;
9
+ switch (s.variant) {
10
+ case 'filled':
11
+ border = s.checked ? c.solid : t.borderColor;
12
+ background = s.checked ? c.solid : t.bgSecondary;
13
+ mark = t.bgSecondary;
14
+ break;
15
+ case 'standard':
16
+ border = s.checked ? c.solid : t.borderHover;
17
+ background = s.checked ? c.light : t.bgTertiary;
18
+ mark = c.solid;
19
+ break;
20
+ case 'outlined':
21
+ case 'cell':
22
+ border = s.checked ? c.solid : t.borderColor;
23
+ background = 'transparent';
24
+ mark = c.solid;
25
+ break;
26
+ }
27
+ if (s.error && !s.checked)
28
+ border = t.error;
29
+ return {
30
+ size,
31
+ markColor: mark,
32
+ circle: {
33
+ width: size,
34
+ height: size,
35
+ borderRadius: size / 2,
36
+ borderWidth: 2,
37
+ borderColor: border,
38
+ backgroundColor: background,
39
+ alignItems: 'center',
40
+ justifyContent: 'center',
41
+ ...(s.pressed ? { transform: [{ scale: TOGGLE_PRESSED_SCALE }] } : {}),
42
+ },
43
+ dot: { width: '50%', height: '50%', borderRadius: size, backgroundColor: mark, opacity: s.checked ? 1 : 0 },
44
+ };
45
+ }
@@ -0,0 +1,83 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { Pressable, Text, View } from 'react-native';
4
+ import { chevronDownIcon, closeIcon, multiSelectRules, normalizeSelectOptions, selectAllValue, selectClearValue, selectDisplay, selectIsAllSelected, selectIsEmpty, selectToggleValue, sortSelectOptions, } from '@dcs-tech/core';
5
+ import { useTokens, useUILabels } from '../UIProvider/context';
6
+ import { useFieldSurface } from '../FieldContext/FieldContext';
7
+ import { FieldWrapper } from '../FieldWrapper/FieldWrapper';
8
+ import { Icon } from '../Icon/Icon';
9
+ import { fieldControlLook } from '../styles/fieldControl';
10
+ import { clearButtonStyle } from '../Input/inputStyle';
11
+ import { SelectSheet } from './SelectSheet';
12
+ const flag = (v, fallback) => (typeof v === 'object' ? v : { enabled: v ?? fallback });
13
+ export function Select({ name, options, value, defaultValue, onChange, label, hint, error, required = false, defaultText, placeholder, disabled: disabledProp, readOnly: readOnlyProp, size: sizeProp, variant: variantProp, layout: layoutProp, width, style, clearable = false, multiSelect, search, autoFocusSearch = false, sort, group, emptyState, loading, renderOption, renderSelectedValue, open: openProp, defaultOpen = false, onOpenChange, onOpen, onClose, onSearch, onSelect, onDeselect, onClear, testID, 'aria-label': ariaLabel, }) {
14
+ const t = useTokens();
15
+ const words = useUILabels();
16
+ const surface = useFieldSurface({ size: sizeProp, variant: variantProp, layout: layoutProp, disabled: disabledProp, readOnly: readOnlyProp });
17
+ const { size, variant, shownLayout: layout, disabled, readOnly } = surface;
18
+ const rules = multiSelectRules(multiSelect);
19
+ const multi = rules.enabled;
20
+ const searchConfig = flag(search, true);
21
+ const sortConfig = useMemo(() => (typeof sort === 'object' ? sort : { enabled: sort ?? true, caseInsensitive: true }), [sort]);
22
+ const groupConfig = typeof group === 'object' ? group : group ? { enabled: true } : undefined;
23
+ const normalized = useMemo(() => {
24
+ const list = normalizeSelectOptions(options);
25
+ return sortConfig.enabled ? sortSelectOptions(list, sortConfig) : list;
26
+ }, [options, sortConfig]);
27
+ const [own, setOwn] = useState(defaultValue ?? (multi ? [] : ''));
28
+ const current = value === undefined ? own : value;
29
+ const [ownOpen, setOwnOpen] = useState(defaultOpen);
30
+ const isOpen = openProp ?? ownOpen;
31
+ const editable = !disabled && !readOnly;
32
+ const emit = (next) => {
33
+ if (value === undefined)
34
+ setOwn(next);
35
+ onChange?.({ target: { name, value: next, type: 'select' } });
36
+ };
37
+ const setOpen = (next, reason) => {
38
+ if (next === isOpen)
39
+ return;
40
+ if (openProp === undefined)
41
+ setOwnOpen(next);
42
+ onOpenChange?.(next, reason);
43
+ (next ? onOpen : onClose)?.();
44
+ };
45
+ const isSelected = (o) => (multi ? Array.isArray(current) && current.includes(o.value) : current === o.value);
46
+ const picked = Array.isArray(current) ? current.length : 0;
47
+ const isBlocked = (o) => !!o.disabled
48
+ || (multi && (rules.alwaysDisabled ?? []).includes(o.value))
49
+ || (multi && !!rules.maxSelection && picked >= rules.maxSelection && !isSelected(o));
50
+ const pick = (o) => {
51
+ if (isBlocked(o))
52
+ return;
53
+ if (!multi) {
54
+ emit(o.value);
55
+ onSelect?.(o.value);
56
+ setOpen(false, 'select');
57
+ return;
58
+ }
59
+ const was = isSelected(o);
60
+ const next = selectToggleValue(current, o, rules);
61
+ if (!next)
62
+ return;
63
+ emit(next);
64
+ (was ? onDeselect : onSelect)?.(o.value);
65
+ };
66
+ const clear = () => {
67
+ emit(selectClearValue(current, multi, rules));
68
+ onClear?.();
69
+ };
70
+ const empty = selectIsEmpty(current, multi);
71
+ const display = selectDisplay(current, normalized, multi, rules.maxDisplayItems);
72
+ const text = display.kind === 'names' ? display.names.join(', ') : display.kind === 'count' ? words.select.itemsSelected(String(display.count)) : (placeholder ?? defaultText ?? '--Select--');
73
+ const hasError = error !== undefined && error !== null && error !== false && error !== '';
74
+ const look = fieldControlLook(t, { size, variant, error: hasError, disabled, readOnly, focused: isOpen });
75
+ const iconSize = t.iconSlotInline;
76
+ const describe = (node) => (typeof node === 'string' ? node : undefined);
77
+ return (_jsxs(FieldWrapper, { label: label, hint: hint, error: error, required: required, size: size, layout: layout, disabled: disabled, width: width, focused: isOpen, style: [layout === 'cell' ? undefined : { marginBottom: t.fieldBlockSpacing }, style], children: [_jsxs(Pressable, { testID: testID, role: "combobox", "aria-expanded": isOpen, "aria-label": ariaLabel ?? describe(label), accessibilityValue: { text }, accessibilityHint: describe(hasError ? error : hint), accessibilityState: { disabled }, disabled: !editable, onPress: () => setOpen(true, 'click'), style: look.box, children: [_jsx(View, { style: { flex: 1, minWidth: 0 }, children: renderSelectedValue && !empty
78
+ ? renderSelectedValue(current, normalized)
79
+ : _jsx(Text, { numberOfLines: 1, style: [look.text, empty && { color: look.placeholderColor }], children: text }) }), clearable && !empty && editable && (_jsx(Pressable, { role: "button", "aria-label": words.select.clear, onPress: clear, hitSlop: t.spacingSm, style: ({ pressed }) => clearButtonStyle(t, pressed), children: _jsx(Icon, { icon: closeIcon, size: t.iconSlotInline, color: t.textSecondary }) })), _jsx(Icon, { icon: chevronDownIcon, size: iconSize, color: isOpen ? t.accentPrimaryText : t.textSecondary })] }), _jsx(SelectSheet, { open: isOpen, title: describe(label) ?? ariaLabel ?? words.select.options, size: size, options: normalized, multi: multi, isSelected: isSelected, isBlocked: isBlocked, onPick: pick, onClose: (reason) => setOpen(false, reason), search: searchConfig, autoFocusSearch: autoFocusSearch, onSearch: onSearch, group: groupConfig, selectAll: multi && rules.showSelectAll
80
+ ? { all: selectIsAllSelected(current, normalized, rules), onPress: shown => emit(selectAllValue(current, shown, rules)) }
81
+ : undefined, loading: loading, emptyState: emptyState, renderOption: renderOption })] }));
82
+ }
83
+ Select.displayName = 'Select';
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { ActivityIndicator, Modal, Pressable, SectionList, Text, TextInput, View, useWindowDimensions } from 'react-native';
4
+ import { checkIcon, closeIcon, filterSelectOptions, groupSelectOptions, searchIcon } from '@dcs-tech/core';
5
+ import { useTokens, useUILabels } from '../UIProvider/context';
6
+ import { Icon } from '../Icon/Icon';
7
+ import { boxShadow } from '../Button/buttonStyle';
8
+ import { checkboxBoxLook } from '../Checkbox/checkboxStyle';
9
+ import { popupGroupHeaderStyle, popupMarkStyle, popupMessageStyle, popupRowLook, popupSize } from '../styles/popupList';
10
+ import { fieldSize } from '../styles/fieldControl';
11
+ function marked(name, term, caseSensitive) {
12
+ if (!term)
13
+ return [{ text: name, hit: false }];
14
+ const hay = caseSensitive ? name : name.toLowerCase();
15
+ const needle = caseSensitive ? term : term.toLowerCase();
16
+ const out = [];
17
+ let from = 0;
18
+ for (let at = hay.indexOf(needle); at >= 0 && needle; at = hay.indexOf(needle, from)) {
19
+ if (at > from)
20
+ out.push({ text: name.slice(from, at), hit: false });
21
+ out.push({ text: name.slice(at, at + needle.length), hit: true });
22
+ from = at + needle.length;
23
+ }
24
+ if (from < name.length)
25
+ out.push({ text: name.slice(from), hit: false });
26
+ return out;
27
+ }
28
+ export function SelectSheet(p) {
29
+ const t = useTokens();
30
+ const words = useUILabels();
31
+ const { height } = useWindowDimensions();
32
+ const [term, setTerm] = useState('');
33
+ const [searchFocused, setSearchFocused] = useState(false);
34
+ const z = popupSize(t, p.size);
35
+ const shown = useMemo(() => filterSelectOptions(p.options, term, p.search), [p.options, term, p.search]);
36
+ const sections = useMemo(() => groupSelectOptions(shown, p.group).filter(g => g.options.length > 0).map(g => ({ title: g.name, data: g.options })), [shown, p.group]);
37
+ const close = (reason) => {
38
+ setTerm('');
39
+ p.onClose(reason);
40
+ };
41
+ const type = (next) => {
42
+ setTerm(next);
43
+ p.onSearch?.(next);
44
+ };
45
+ const header = popupGroupHeaderStyle(t, p.size);
46
+ const message = (empty) => popupMessageStyle(t, p.size, empty);
47
+ const highlight = p.search.highlightMatches !== false;
48
+ const renderRow = (option) => {
49
+ const selected = p.isSelected(option);
50
+ const blocked = p.isBlocked(option);
51
+ return (_jsx(Pressable, { role: p.multi ? 'checkbox' : 'radio', "aria-checked": selected, "aria-label": option.name, accessibilityState: { disabled: blocked }, disabled: blocked, onPress: () => p.onPick(option), children: ({ pressed }) => {
52
+ const look = popupRowLook(t, { size: p.size, selected, disabled: blocked, pressed });
53
+ if (p.renderOption)
54
+ return _jsx(View, { style: look.row, children: p.renderOption(option, selected, false) });
55
+ const box = p.multi ? checkboxBoxLook(t, { size: p.size, variant: 'filled', color: 'primary', on: selected, error: false, pressed: false }) : undefined;
56
+ return (_jsxs(View, { style: look.row, children: [box && (_jsx(View, { style: box.box, children: selected && _jsx(Icon, { icon: checkIcon, size: box.size, color: box.iconColor, weight: "bold" }) })), _jsx(Text, { style: look.text, numberOfLines: 1, children: highlight
57
+ ? marked(option.name, term, !!p.search.caseSensitive).map((part, i) => part.hit ? _jsx(Text, { style: popupMarkStyle(t, selected), children: part.text }, i) : part.text)
58
+ : option.name }), selected && !p.multi && _jsx(Icon, { icon: checkIcon, size: look.tickSize, color: look.tickColor })] }));
59
+ } }));
60
+ };
61
+ let body;
62
+ if (p.loading?.loading) {
63
+ body = p.loading.renderLoadingState?.() ?? (_jsxs(View, { style: message(false).box, children: [_jsx(ActivityIndicator, { color: t.accentPrimary }), _jsx(Text, { style: message(false).text, children: p.loading.loadingText ?? words.common.loading })] }));
64
+ }
65
+ else if (shown.length === 0) {
66
+ body = p.emptyState?.renderEmptyState?.(term) ?? (_jsx(View, { style: message(true).box, children: _jsx(Text, { style: message(true).text, children: p.options.length === 0 ? p.emptyState?.noOptionsText ?? words.select.noOptions : p.emptyState?.noResultsText ?? words.select.noResults }) }));
67
+ }
68
+ else {
69
+ body = (_jsx(SectionList, { sections: sections, keyExtractor: o => String(o.value), renderItem: ({ item }) => renderRow(item), renderSectionHeader: ({ section }) => (section.title ? (_jsx(View, { style: header.box, children: p.group?.renderGroupHeader
70
+ ? p.group.renderGroupHeader(section.title, section.data.length)
71
+ : _jsx(Text, { style: header.text, children: section.title }) })) : null), stickySectionHeadersEnabled: true, keyboardShouldPersistTaps: "handled" }));
72
+ }
73
+ return (_jsx(Modal, { visible: p.open, transparent: true, animationType: t.motionScale > 0 ? 'slide' : 'none', onRequestClose: () => close('escape'), children: _jsxs(View, { style: { flex: 1, justifyContent: 'flex-end' }, children: [_jsx(Pressable, { accessible: false, style: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: t.scrim }, onPress: () => close('blur') }), _jsxs(View, { role: "dialog", "aria-label": p.title, style: {
74
+ maxHeight: height * 0.8,
75
+ backgroundColor: t.bgSecondary,
76
+ borderTopLeftRadius: t.borderRadiusLg,
77
+ borderTopRightRadius: t.borderRadiusLg,
78
+ paddingBottom: t.spacing2xl,
79
+ boxShadow: boxShadow(t.shadowDialog),
80
+ }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, paddingHorizontal: z.padX, paddingVertical: t.spacingLg }, children: [_jsx(Text, { style: { flex: 1, fontSize: t.fontSizeLg, fontWeight: String(t.fontWeightSemibold), color: t.textPrimary }, numberOfLines: 1, children: p.title }), p.multi ? (_jsx(Pressable, { role: "button", onPress: () => close('click'), hitSlop: t.spacingMd, children: _jsx(Text, { style: { fontSize: t.fontSizeMd, fontWeight: String(t.fontWeightSemibold), color: t.accentPrimaryText }, children: words.dialog.ok }) })) : (_jsx(Pressable, { role: "button", "aria-label": words.dialog.close, onPress: () => close('click'), hitSlop: t.spacingMd, children: _jsx(Icon, { icon: closeIcon, size: t.iconSlotProminent, color: t.textSecondary }) }))] }), p.search.enabled && (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, paddingHorizontal: z.padX, borderBottomWidth: 1, borderBottomColor: searchFocused ? t.accentPrimary : t.borderColor }, children: [_jsx(Icon, { icon: searchIcon, size: t.iconSlotField, color: t.textSecondary }), _jsx(TextInput, { value: term, onChangeText: type, placeholder: p.search.placeholder ?? words.select.search, placeholderTextColor: t.textTertiary, autoFocus: p.autoFocusSearch, autoCorrect: false, "aria-label": p.search.placeholder ?? words.select.search, onFocus: () => setSearchFocused(true), onBlur: () => setSearchFocused(false), style: { flex: 1, padding: 0, paddingVertical: fieldSize(t, p.size).padY, fontSize: z.primary, color: t.textPrimary } })] })), p.selectAll && shown.length > 0 && !p.loading?.loading && (_jsx(Pressable, { role: "checkbox", "aria-checked": p.selectAll.all, onPress: () => p.selectAll.onPress(shown), children: ({ pressed }) => {
81
+ const look = popupRowLook(t, { size: p.size, selected: false, disabled: false, pressed });
82
+ const box = checkboxBoxLook(t, { size: p.size, variant: 'filled', color: 'primary', on: p.selectAll.all, error: false, pressed: false });
83
+ return (_jsxs(View, { style: [look.row, { borderBottomWidth: 1, borderBottomColor: t.borderColor }], children: [_jsx(View, { style: box.box, children: p.selectAll.all && _jsx(Icon, { icon: checkIcon, size: box.size, color: box.iconColor, weight: "bold" }) }), _jsx(Text, { style: look.text, children: p.selectAll.all ? words.select.deselectAll : words.select.selectAll })] }));
84
+ } })), body] })] }) }));
85
+ }
@@ -0,0 +1 @@
1
+ export { Select } from './Select';
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useRef, useState } from 'react';
3
+ import { ActivityIndicator, Pressable, ScrollView, Text, TextInput, View, useWindowDimensions } from 'react-native';
4
+ import { getNestedValue, getUniqueKey, highlightParts, normalizeRenderKey } from '@dcs-tech/core';
5
+ import { useSuggest } from '@dcs-tech/core/hooks';
6
+ import { useTokens, useUILabels } from '../UIProvider/context';
7
+ import { useFieldSurface } from '../FieldContext/FieldContext';
8
+ import { FieldWrapper } from '../FieldWrapper/FieldWrapper';
9
+ import { fieldControlLook } from '../styles/fieldControl';
10
+ import { popupGroupHeaderStyle, popupMarkStyle, popupMessageStyle, popupRowLook, suggestLineStyles, suggestPopupStyle } from '../styles/popupList';
11
+ import { POPUP_LIST_MAX_HEIGHT } from '../styles/webValues';
12
+ export function Suggest({ name, data, config, value, defaultValue, onChange, onChangeText, onSelect, label, placeholder, hint, error, required = false, disabled: disabledProp, readOnly: readOnlyProp, size: sizeProp, variant: variantProp, layout: layoutProp, width, style, minSearchLength, debounceMs, showAllOnFocus, openOnFocus = true, clearOnSelect = false, closeOnSelect = true, renderItem, renderGroup, inputMode, returnKeyType, onFocus, onBlur, testID, 'aria-label': ariaLabel, }) {
13
+ const t = useTokens();
14
+ const words = useUILabels();
15
+ const { height } = useWindowDimensions();
16
+ const surface = useFieldSurface({ size: sizeProp, variant: variantProp, layout: layoutProp, disabled: disabledProp, readOnly: readOnlyProp });
17
+ const { size, variant, shownLayout: layout, disabled, readOnly } = surface;
18
+ const [own, setOwn] = useState(defaultValue ?? '');
19
+ const text = value ?? own;
20
+ const [focused, setFocused] = useState(false);
21
+ const inputRef = useRef(null);
22
+ const picking = useRef(false);
23
+ const suggest = useSuggest({
24
+ data,
25
+ config,
26
+ value: text,
27
+ minSearchLength,
28
+ debounceMs,
29
+ showAllOnFocus,
30
+ disabled: disabled || readOnly,
31
+ onSelect: item => {
32
+ onSelect?.(item, name);
33
+ if (clearOnSelect)
34
+ suggest.clear();
35
+ if (closeOnSelect)
36
+ suggest.close();
37
+ },
38
+ });
39
+ const type = (next) => {
40
+ if (value === undefined)
41
+ setOwn(next);
42
+ onChangeText?.(next);
43
+ onChange?.({ target: { name, value: next, type: 'text' } });
44
+ suggest.handleInputChange({ target: { value: next } });
45
+ };
46
+ const hasError = error !== undefined && error !== null && error !== false && error !== '';
47
+ const look = fieldControlLook(t, { size, variant, error: hasError, disabled, readOnly, focused });
48
+ const lines = suggestLineStyles(t, size);
49
+ const highlight = config.highlightMatches ?? true;
50
+ const renderKeys = useMemo(() => (config.renderKeys ?? config.searchKeys ?? []).map(normalizeRenderKey), [config.renderKeys, config.searchKeys]);
51
+ const content = (formatted, style) => {
52
+ const marked = (s) => highlightParts(s, text, highlight).map((part, i) => part.hit ? _jsx(Text, { style: popupMarkStyle(t, false), children: part.text }, i) : part.text);
53
+ if (typeof formatted === 'string')
54
+ return _jsx(Text, { style: style, children: marked(formatted) });
55
+ return formatted.map((el, i) => (_jsx(Text, { style: [style, el.tag === 'strong' && { fontWeight: String(t.fontWeightBold) }, el.tag === 'em' && { fontStyle: 'italic' }], children: marked(el.content) }, i)));
56
+ };
57
+ const line = (item, type) => {
58
+ const keys = renderKeys.filter(k => k.rendertype === type);
59
+ const parts = keys.map(k => {
60
+ const raw = typeof item === 'string' && !k.key ? item : getNestedValue(item, k.key);
61
+ if (k.hideWhenEmpty && (!raw || raw === ''))
62
+ return null;
63
+ const formatted = k.formatter ? k.formatter(raw) : String(raw ?? '');
64
+ const set = type === 'p' ? lines.primary : type === 's' ? lines.secondary : lines.tertiary;
65
+ const body = (_jsxs(_Fragment, { children: [k.label ? _jsx(Text, { style: [set.text, lines.label], children: `${k.label}: ` }) : null, content(formatted, set.text)] }));
66
+ return (_jsx(View, { style: [{ flexDirection: 'row', flexWrap: 'wrap' }, type === 't' && lines.tertiary.chip], children: body }, k.key || 'value'));
67
+ }).filter(Boolean);
68
+ if (parts.length === 0)
69
+ return null;
70
+ const set = type === 'p' ? lines.primary : type === 's' ? lines.secondary : lines.tertiary;
71
+ return _jsx(View, { style: set.line, children: parts });
72
+ };
73
+ const row = (item, index) => (_jsx(Pressable, { role: "button", onPressIn: () => { picking.current = true; }, onPress: () => { picking.current = false; suggest.handleSelect(item, index); }, children: ({ pressed }) => (_jsx(View, { style: popupRowLook(t, { size, selected: false, disabled: false, pressed }).row, children: renderItem ? renderItem(item, pressed, text) : (_jsxs(View, { style: { flex: 1, minWidth: 0, gap: t.spacingXxs }, children: [line(item, 'p'), line(item, 's'), line(item, 't')] })) })) }, getUniqueKey(item, config.uniqueKey, index)));
74
+ const groups = useMemo(() => {
75
+ if (!config.groupBy)
76
+ return null;
77
+ const map = new Map();
78
+ suggest.suggestions.forEach(item => {
79
+ const key = String(getNestedValue(item, config.groupBy) || words.suggest.otherGroup);
80
+ map.set(key, [...(map.get(key) ?? []), item]);
81
+ });
82
+ return [...map.entries()];
83
+ }, [suggest.suggestions, config.groupBy, words.suggest.otherGroup]);
84
+ const header = popupGroupHeaderStyle(t, size);
85
+ let index = 0;
86
+ const list = suggest.isOpen || suggest.loading ? (_jsx(View, { style: suggestPopupStyle(t, Math.min(POPUP_LIST_MAX_HEIGHT, height * 0.4)), role: "list", "aria-label": words.suggest.suggestions, children: suggest.loading && suggest.suggestions.length === 0 ? (_jsxs(View, { style: popupMessageStyle(t, size, false).box, children: [_jsx(ActivityIndicator, { color: t.accentPrimary }), _jsx(Text, { style: popupMessageStyle(t, size, false).text, children: words.suggest.loading })] })) : (_jsx(ScrollView, { nestedScrollEnabled: true, keyboardShouldPersistTaps: "handled", children: groups
87
+ ? groups.map(([group, items]) => (_jsxs(View, { children: [renderGroup ? renderGroup(group, items) : _jsx(View, { style: header.box, children: _jsx(Text, { style: header.text, children: group }) }), items.map(item => row(item, index++))] }, group)))
88
+ : suggest.suggestions.map((item, i) => row(item, i)) })) })) : null;
89
+ const describe = (node) => (typeof node === 'string' ? node : undefined);
90
+ return (_jsxs(FieldWrapper, { label: label, hint: hint, error: error, required: required, size: size, layout: layout, disabled: disabled, width: width, focused: focused, style: [layout === 'cell' ? undefined : { marginBottom: t.fieldBlockSpacing }, style], children: [_jsx(Pressable, { accessible: false, onPress: () => { if (!disabled)
91
+ inputRef.current?.focus(); }, style: look.box, children: _jsx(TextInput, { ref: inputRef, testID: testID, value: text, onChangeText: type, placeholder: placeholder ?? words.suggest.placeholder, placeholderTextColor: look.placeholderColor, editable: !disabled && !readOnly, autoCorrect: false, inputMode: inputMode, returnKeyType: returnKeyType, accessibilityLabel: ariaLabel ?? describe(label), accessibilityHint: describe(hasError ? error : hint), accessibilityState: { disabled, expanded: suggest.isOpen }, onFocus: () => { setFocused(true); if (openOnFocus)
92
+ suggest.handleFocus(); onFocus?.(); }, onBlur: () => {
93
+ setFocused(false);
94
+ if (picking.current)
95
+ picking.current = false;
96
+ else
97
+ suggest.handleBlur();
98
+ onBlur?.();
99
+ }, style: look.text }) }), list] }));
100
+ }
101
+ Suggest.displayName = 'Suggest';
@@ -0,0 +1 @@
1
+ export { Suggest } from './Suggest';
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { ActivityIndicator, Animated, Easing, Pressable, Text, View } from 'react-native';
4
+ import { useTokens, useUILabels } from '../UIProvider/context';
5
+ import { useToggleSurface } from '../FieldContext/FieldContext';
6
+ import { IconSlotContext } from '../Icon/IconContext';
7
+ import { ToggleField } from '../Toggle/ToggleField';
8
+ import { toggleHaloStyle } from '../styles/toggle';
9
+ import { useRipple } from '../Press';
10
+ import { switchLook, switchStateLabelStyle } from './switchStyle';
11
+ const present = (node) => node !== undefined && node !== null && node !== false && node !== '';
12
+ export function Switch({ name, value, checked, defaultChecked, onChange, onCheckedChange, label, hint, error, required = false, labelPosition = 'end', onText, offText, onIcon, offIcon, labelOn, labelOff, stateLabelMode = 'replace', justSwitch = false, disabled, readOnly, loading = false, loadingIndicator, size, color = 'primary', fullWidth = false, animated = true, style, testID, 'aria-label': ariaLabel, }) {
13
+ const t = useTokens();
14
+ const words = useUILabels();
15
+ const surface = useToggleSurface({ size, disabled, readOnly });
16
+ const [own, setOwn] = useState(!!defaultChecked);
17
+ const isOn = checked ?? own;
18
+ const hasError = present(error);
19
+ const choiceMode = justSwitch && (present(labelOn) || present(labelOff));
20
+ const sides = stateLabelMode === 'sides';
21
+ const inactive = surface.disabled || surface.readOnly || loading;
22
+ const toggle = () => {
23
+ const next = !isOn;
24
+ if (checked === undefined)
25
+ setOwn(next);
26
+ onCheckedChange?.(next);
27
+ onChange?.({ target: { name, value, type: 'checkbox', checked: next } });
28
+ };
29
+ const rest = switchLook(t, { size: surface.size, color, checked: isOn, pressed: false, error: hasError, choiceMode });
30
+ const travel = useRef(new Animated.Value(isOn ? 1 : 0)).current;
31
+ useEffect(() => {
32
+ const to = isOn ? 1 : 0;
33
+ const ms = animated ? t.durationLong * t.motionScale : 0;
34
+ if (ms <= 0) {
35
+ travel.setValue(to);
36
+ return;
37
+ }
38
+ const e = t.easeInOut;
39
+ const ease = e.type === 'cubicBezier' ? Easing.bezier(e.x1, e.y1, e.x2, e.y2) : Easing.linear;
40
+ const run = Animated.timing(travel, { toValue: to, duration: ms, easing: ease, useNativeDriver: true });
41
+ run.start();
42
+ return () => run.stop();
43
+ }, [isOn, animated, t, travel]);
44
+ const shift = travel.interpolate({ inputRange: [0, 1], outputRange: [0, rest.travel] });
45
+ const shownLabel = !sides && (present(labelOn) || present(labelOff)) ? (isOn ? labelOn : labelOff) : label;
46
+ const stateLabel = (which) => {
47
+ const node = which === 'on' ? labelOn : labelOff;
48
+ if (!present(node))
49
+ return null;
50
+ const active = which === 'on' ? isOn : !isOn;
51
+ const look = switchStateLabelStyle(t, surface.size, active, surface.disabled, rest.rowLine);
52
+ return (_jsx(Pressable, { accessible: false, disabled: inactive, onPress: () => { if (!active)
53
+ toggle(); }, style: look.box, children: typeof node === 'string' ? _jsx(Text, { style: look.text, children: node }) : node }));
54
+ };
55
+ const wave = useRipple({ color: isOn ? rest.accent : t.textSecondary, centered: true, enabled: !inactive }, undefined);
56
+ const renderControl = (pressed) => {
57
+ const look = pressed ? switchLook(t, { size: surface.size, color, checked: isOn, pressed, error: hasError, choiceMode }) : rest;
58
+ const halo = look.box * t.controlHaloSize;
59
+ const thumbContent = loading
60
+ ? loadingIndicator ?? _jsx(ActivityIndicator, { size: "small", color: look.accent, accessibilityLabel: words.common.loading, style: { transform: [{ scale: look.thumbIconSize / 20 }] } })
61
+ : isOn ? onIcon : offIcon;
62
+ const control = (_jsx(View, { style: { minHeight: look.rowLine, justifyContent: 'center' }, children: _jsxs(View, { style: look.track, children: [_jsx(Animated.View, { ref: wave.ref, style: [
63
+ toggleHaloStyle(t, look.box, look.accent, isOn, pressed, surface.disabled),
64
+ { left: look.pad + look.box / 2 - halo / 2, top: look.pad + look.box / 2 - halo / 2, transform: [{ translateX: shift }] },
65
+ ], children: wave.layer }), !justSwitch && onText ? _jsx(Text, { style: look.onText, children: onText }) : null, !justSwitch && offText ? _jsx(Text, { style: look.offText, children: offText }) : null, _jsx(Animated.View, { style: [look.thumb, { transform: [{ translateX: shift }] }], children: _jsx(IconSlotContext.Provider, { value: { size: look.thumbIconSize, color: look.thumbIconColor }, children: thumbContent }) })] }) }));
66
+ return sides ? _jsxs(_Fragment, { children: [stateLabel('off'), control, stateLabel('on')] }) : control;
67
+ };
68
+ const stateName = typeof (isOn ? labelOn : labelOff) === 'string' ? (isOn ? labelOn : labelOff) : undefined;
69
+ return (_jsx(ToggleField, { role: "switch", checked: isOn, onToggle: toggle, size: surface.size, layout: surface.layout, disabled: surface.disabled, readOnly: surface.readOnly, busy: loading, label: sides ? undefined : shownLabel, required: required, labelPosition: sides ? 'end' : labelPosition, error: error, hint: hint, fullWidth: fullWidth, rowLine: rest.rowLine, renderControl: renderControl, ripple: wave, style: style, testID: testID, "aria-label": ariaLabel ?? (typeof label === 'string' ? label : stateName) }));
70
+ }
71
+ Switch.displayName = 'Switch';
@@ -0,0 +1 @@
1
+ export { Switch } from './Switch';
@@ -0,0 +1,59 @@
1
+ import { boxShadow } from '../Button/buttonStyle';
2
+ import { toggleColor, toggleSize } from '../styles/toggle';
3
+ import { STATE_LABEL_DISABLED_OPACITY, STATE_LABEL_OPACITY, SWITCH_TEXT_INSET } from '../styles/webValues';
4
+ function choiceColors(t, color) {
5
+ switch (color) {
6
+ case 'primary': return [t.accentPrimary, t.success];
7
+ case 'secondary': return [t.accentSecondary, t.accentPrimary];
8
+ case 'success': return [t.success, t.info];
9
+ case 'error': return [t.error, t.warning];
10
+ case 'warning': return [t.warning, t.accentSecondary];
11
+ case 'info': return [t.info, t.success];
12
+ }
13
+ }
14
+ export function switchLook(t, s) {
15
+ const { box, font } = toggleSize(t, s.size);
16
+ const c = toggleColor(t, s.color);
17
+ const pad = 2 * t.uiScale;
18
+ const trackHeight = box + pad * 2;
19
+ const [choiceOff, choiceOn] = choiceColors(t, s.color);
20
+ const textSize = box * 0.5;
21
+ const text = { position: 'absolute', fontSize: textSize, fontWeight: String(t.fontWeightSemibold) };
22
+ return {
23
+ pad,
24
+ box,
25
+ travel: box - pad * 2,
26
+ rowLine: Math.max(trackHeight, Math.round(font * t.lineHeightNormal)),
27
+ track: {
28
+ width: box * 2,
29
+ height: trackHeight,
30
+ padding: pad,
31
+ borderRadius: t.borderRadiusFull,
32
+ flexDirection: 'row',
33
+ alignItems: 'center',
34
+ backgroundColor: s.checked && !s.choiceMode ? c.solid : t.borderColor,
35
+ ...(s.error ? { outlineWidth: t.focusRingWidth, outlineStyle: 'solid', outlineColor: t.error, outlineOffset: 1 } : {}),
36
+ },
37
+ thumb: {
38
+ width: s.pressed ? box + pad * 2 : box,
39
+ height: box,
40
+ borderRadius: s.pressed ? box * 0.4 : box / 2,
41
+ backgroundColor: s.choiceMode ? (s.checked ? choiceOn : choiceOff) : t.bgSecondary,
42
+ boxShadow: boxShadow(t.shadowControl),
43
+ alignItems: 'center',
44
+ justifyContent: 'center',
45
+ },
46
+ onText: { ...text, left: SWITCH_TEXT_INSET, color: c.on, opacity: s.checked ? 1 : 0 },
47
+ offText: { ...text, right: SWITCH_TEXT_INSET, color: t.textPrimary, opacity: s.checked ? 0 : 1 },
48
+ thumbIconSize: Math.round(box * 0.6),
49
+ thumbIconColor: s.checked ? c.solid : t.textTertiary,
50
+ accent: c.solid,
51
+ };
52
+ }
53
+ export function switchStateLabelStyle(t, size, active, disabled, rowLine) {
54
+ const { font } = toggleSize(t, size);
55
+ return {
56
+ box: { minHeight: rowLine, justifyContent: 'center', paddingHorizontal: t.spacingLg, opacity: disabled ? STATE_LABEL_DISABLED_OPACITY : active ? 1 : STATE_LABEL_OPACITY },
57
+ text: { fontSize: font, color: t.textPrimary, fontWeight: String(active ? t.fontWeightSemibold : t.fontWeightRegular) },
58
+ };
59
+ }