@dcs-tech/ui-native 0.0.0-stage → 0.16.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 +186 -0
  2. package/README.md +179 -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 +49 -0
  28. package/dist/components/DataTable/filters/FilterGroupEditor.js +21 -0
  29. package/dist/components/DataTable/filters/FilterSheet.js +69 -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 +345 -0
  37. package/dist/components/DatePicker/Calendar.js +28 -0
  38. package/dist/components/DatePicker/DatePicker.js +300 -0
  39. package/dist/components/DatePicker/PeriodGrid.js +17 -0
  40. package/dist/components/DatePicker/PeriodPicker.js +216 -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 +252 -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 +58 -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 +250 -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 +17 -0
  177. package/dist/types/components/UIProvider/context.d.ts +22 -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,60 @@
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 Svg, { Line, Polyline } from 'react-native-svg';
5
+ import { useTokens } from '../UIProvider/context';
6
+ import { useToggleSurface } from '../FieldContext/FieldContext';
7
+ import { ToggleField } from '../Toggle/ToggleField';
8
+ import { ToggleGroupFrame } from '../Toggle/ToggleGroupFrame';
9
+ import { toggleColor, toggleHaloStyle, toggleLine, toggleSize } from '../styles/toggle';
10
+ import { useRipple } from '../Press';
11
+ import { checkboxBoxLook } from './checkboxStyle';
12
+ const CheckboxGroupContext = createContext(null);
13
+ export function CheckboxGroup({ name, value, defaultValue, onChange, label, helperText, error, disabled = false, readOnly = false, required = false, orientation = 'vertical', size, variant, color, style, 'aria-label': ariaLabel, children }) {
14
+ const [own, setOwn] = useState(defaultValue ?? []);
15
+ const values = value ?? own;
16
+ const toggle = useCallback((v, checked) => {
17
+ if (disabled || readOnly)
18
+ return;
19
+ const next = checked ? (values.includes(v) ? values : [...values, v]) : values.filter(x => x !== v);
20
+ if (value === undefined)
21
+ setOwn(next);
22
+ onChange?.(next);
23
+ }, [disabled, readOnly, values, value, onChange]);
24
+ const ctx = useMemo(() => ({ name, value: values, toggle, disabled, readOnly, size, variant, color }), [name, values, toggle, disabled, readOnly, size, variant, color]);
25
+ return (_jsx(CheckboxGroupContext.Provider, { value: ctx, children: _jsx(ToggleGroupFrame, { role: "group", label: label, required: required, helper: helperText, error: error, disabled: disabled, orientation: orientation, style: style, "aria-label": ariaLabel, children: children }) }));
26
+ }
27
+ CheckboxGroup.displayName = 'CheckboxGroup';
28
+ const Tick = ({ color }) => (_jsx(Svg, { width: "100%", height: "100%", viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: 3, strokeLinecap: "round", strokeLinejoin: "round", children: _jsx(Polyline, { points: "20 6 9 17 4 12" }) }));
29
+ const Dash = ({ color }) => (_jsx(Svg, { width: "100%", height: "100%", viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: 3, strokeLinecap: "round", children: _jsx(Line, { x1: 5, y1: 12, x2: 19, y2: 12 }) }));
30
+ export function Checkbox({ name, value, checked, defaultChecked, indeterminate = false, onChange, onCheckedChange, label, hint, error, required = false, labelPosition = 'end', disabled, readOnly, size, variant, color, fullWidth = false, checkedIcon, uncheckedIcon, indeterminateIcon, ripple = true, style, testID, 'aria-label': ariaLabel, }) {
31
+ const t = useTokens();
32
+ const group = useContext(CheckboxGroupContext);
33
+ const surface = useToggleSurface({ size: size ?? group?.size, variant: variant ?? group?.variant, disabled: disabled ?? group?.disabled, readOnly: readOnly ?? group?.readOnly });
34
+ const resolvedColor = color ?? group?.color ?? 'primary';
35
+ const [own, setOwn] = useState(!!defaultChecked);
36
+ const isOn = group && value !== undefined ? group.value.includes(value) : checked ?? own;
37
+ const on = isOn || indeterminate;
38
+ const hasError = error !== undefined && error !== null && error !== false && error !== '';
39
+ const toggle = () => {
40
+ const next = !isOn;
41
+ if (group && value !== undefined)
42
+ group.toggle(value, next);
43
+ else if (checked === undefined)
44
+ setOwn(next);
45
+ onCheckedChange?.(next);
46
+ onChange?.({ target: { name: name ?? group?.name, value, type: 'checkbox', checked: next } });
47
+ };
48
+ const { box } = toggleSize(t, surface.size);
49
+ const wave = useRipple({ color: on ? toggleColor(t, resolvedColor).solid : t.textSecondary, centered: true, enabled: ripple && !surface.disabled && !surface.readOnly }, undefined);
50
+ const renderControl = (pressed) => {
51
+ const look = checkboxBoxLook(t, { size: surface.size, variant: surface.variant, color: resolvedColor, on, error: hasError, pressed });
52
+ const mark = indeterminate
53
+ ? indeterminateIcon ?? _jsx(Dash, { color: look.iconColor })
54
+ : isOn ? checkedIcon ?? _jsx(Tick, { color: look.iconColor }) : uncheckedIcon ?? null;
55
+ const halo = box * t.controlHaloSize;
56
+ 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, on, pressed, surface.disabled), { left: (box - halo) / 2, top: (box - halo) / 2 }], children: wave.layer }), _jsx(View, { style: look.box, children: mark })] }) }));
57
+ };
58
+ return (_jsx(ToggleField, { role: "checkbox", checked: indeterminate ? 'mixed' : isOn, onToggle: toggle, 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 }));
59
+ }
60
+ Checkbox.displayName = 'Checkbox';
@@ -0,0 +1,44 @@
1
+ import { toggleColor, toggleSize } from '../styles/toggle';
2
+ import { TOGGLE_PRESSED_SCALE } from '../styles/webValues';
3
+ export function checkboxBoxLook(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 iconColor;
9
+ switch (s.variant) {
10
+ case 'filled':
11
+ border = s.on ? c.solid : t.borderColor;
12
+ background = s.on ? c.solid : t.bgSecondary;
13
+ iconColor = t.bgSecondary;
14
+ break;
15
+ case 'standard':
16
+ border = s.on ? c.solid : t.borderHover;
17
+ background = s.on ? c.light : t.bgTertiary;
18
+ iconColor = c.solid;
19
+ break;
20
+ case 'outlined':
21
+ case 'cell':
22
+ border = s.on ? c.solid : t.borderColor;
23
+ background = 'transparent';
24
+ iconColor = c.solid;
25
+ break;
26
+ }
27
+ if (s.error && !s.on)
28
+ border = t.error;
29
+ return {
30
+ size,
31
+ iconColor,
32
+ box: {
33
+ width: size,
34
+ height: size,
35
+ borderRadius: size * 0.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
+ };
44
+ }
@@ -0,0 +1 @@
1
+ export { Checkbox, CheckboxGroup } from './Checkbox';
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useCallback, useId, useRef, useState } from 'react';
3
+ import { Text, View } from 'react-native';
4
+ import { bulkResultOf, planBulkAction, resolveConfirm, summarizeBulkResult, summarizeReasons, } from '@dcs-tech/core';
5
+ import { useTokens } from '../UIProvider/context';
6
+ import { Button } from '../Button/Button';
7
+ import { Dialog } from '../Dialog/Dialog';
8
+ import { Input } from '../Input/Input';
9
+ import { useOptionalToast } from '../Toast/ToastHost';
10
+ import { DT_RESULT_TOAST_MS, DT_UNDO_TOAST_MS } from '../styles/webValues';
11
+ export function useBulkRun(state) {
12
+ const { L, format } = state;
13
+ const toast = useOptionalToast();
14
+ const toastId = `dt-result-${useId()}`;
15
+ const [busyId, setBusyId] = useState(null);
16
+ const [asking, setAsking] = useState(null);
17
+ const say = useCallback((message, type, autoClose) => {
18
+ toast?.toast(message, { id: toastId, type, autoClose, position: 'bottom-center' });
19
+ }, [toast, toastId]);
20
+ const runUndo = useCallback(async (undo) => {
21
+ toast?.dismiss(toastId);
22
+ try {
23
+ await undo();
24
+ say(L.undone, 'success', DT_RESULT_TOAST_MS);
25
+ }
26
+ catch (err) {
27
+ say(err?.message || L.undoFailed, 'error', DT_UNDO_TOAST_MS);
28
+ }
29
+ if (state.serverMode)
30
+ state.retry();
31
+ }, [toast, toastId, say, L, state]);
32
+ const execute = useCallback(async (action, plan, selection, input) => {
33
+ setBusyId(action.id);
34
+ try {
35
+ const result = bulkResultOf(await action.onRun({ selection, rows: plan.rows, skipped: plan.skipped, input }));
36
+ if (result) {
37
+ const line = summarizeBulkResult(plan, result, L, format);
38
+ const undo = result.undo;
39
+ say(undo ? _jsx(ResultLine, { text: line.text, undoLabel: L.undo, onUndo: () => { void runUndo(undo); } }) : line.text, line.status, undo ? action.undoTimeoutMs ?? DT_UNDO_TOAST_MS : DT_RESULT_TOAST_MS);
40
+ if (!result.keepSelection)
41
+ state.clearSelection();
42
+ }
43
+ if (state.serverMode)
44
+ state.retry();
45
+ }
46
+ catch (err) {
47
+ say(err?.message || L.bulkFailed, 'error', DT_UNDO_TOAST_MS);
48
+ }
49
+ finally {
50
+ setBusyId(null);
51
+ setAsking(null);
52
+ }
53
+ }, [L, format, say, runUndo, state]);
54
+ const run = useCallback((action) => {
55
+ const plan = planBulkAction(action, state.selection, L, format);
56
+ if (plan.disabledReason)
57
+ return;
58
+ const confirm = resolveConfirm(action, plan, state.selection);
59
+ if (confirm)
60
+ setAsking({ action, plan, selection: state.selection, confirm });
61
+ else
62
+ void execute(action, plan, state.selection);
63
+ }, [state.selection, L, format, execute]);
64
+ const last = useRef(null);
65
+ if (asking)
66
+ last.current = asking;
67
+ const shown = asking ?? last.current;
68
+ const dialog = shown && (_jsx(BulkConfirmDialog, { state: state, asking: shown, open: !!asking, busy: !!busyId, onConfirm: input => { void execute(shown.action, shown.plan, shown.selection, input); }, onClose: () => setAsking(null) }));
69
+ return { runner: { busyId, run }, dialog };
70
+ }
71
+ function ResultLine({ text, undoLabel, onUndo }) {
72
+ const t = useTokens();
73
+ return (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd }, children: [_jsx(Text, { style: { flex: 1, color: t.textPrimary, fontSize: t.fontSizeMd }, children: text }), _jsx(Button, { variant: "text", size: "small", onPress: onUndo, children: undoLabel })] }));
74
+ }
75
+ function BulkConfirmDialog({ state, asking, open, busy, onConfirm, onClose }) {
76
+ const t = useTokens();
77
+ const { L, format } = state;
78
+ const { action, plan, confirm } = asking;
79
+ const [input, setInput] = useState('');
80
+ const count = format.number(plan.count);
81
+ const needsInput = !!confirm.input?.required && !input.trim();
82
+ const text = { color: t.textPrimary, fontSize: t.fontSizeMd, lineHeight: Math.round(t.fontSizeMd * t.lineHeightNormal) };
83
+ return (_jsx(Dialog, { open: open, size: "sm", title: confirm.title ?? L.bulkConfirmTitle(action.label, count), onClose: busy ? undefined : onClose, onAnimationEnd: () => setInput(''), closeOnBackdrop: !busy, closeOnEscape: !busy, showCloseButton: !busy, footer: (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outlined", color: "neutral", size: "small", disabled: busy, onPress: onClose, children: L.cancel }), _jsx(Button, { variant: "filled", size: "small", color: confirm.danger || action.variant === 'danger' ? 'error' : 'primary', loading: busy, disabled: busy || needsInput, onPress: () => { if (!needsInput && !busy)
84
+ onConfirm(confirm.input ? input.trim() : undefined); }, children: busy ? L.bulkRunning : confirm.confirmLabel ?? L.bulkConfirm })] })), children: _jsxs(View, { style: { gap: t.spacingMd }, children: [confirm.message != null && (typeof confirm.message === 'string' ? _jsx(Text, { style: text, children: confirm.message }) : confirm.message), _jsx(Text, { style: text, children: L.bulkConfirmCount(count) }), plan.skipped.length > 0 && (_jsxs(Text, { style: [text, { color: t.textSecondary }], children: [L.bulkConfirmSkipped(format.number(plan.skipped.length)), " ", summarizeReasons(plan.skipped, format)] })), confirm.input && (_jsx(Input, { label: confirm.input.label, placeholder: confirm.input.placeholder, maxLength: confirm.input.maxLength, required: confirm.input.required, multiline: true, rows: 3, value: input, onChangeText: setInput }))] }) }));
85
+ }
@@ -0,0 +1,70 @@
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 { cardsPerLine } from '@dcs-tech/core';
5
+ import { useTokens } from '../UIProvider/context';
6
+ import { IconChevronDown, IconChevronUp } from '../Icon';
7
+ import { Checkbox } from '../Checkbox/Checkbox';
8
+ import { cardCheckLook, cardLook, cardTickedLook, tableColors } from './dataTableStyle';
9
+ import { CellNode, RowAvatarView } from './cells';
10
+ import { rowParts } from './rowParts';
11
+ import { RowActions, hasRowActions } from './RowActions';
12
+ import { useDragTick } from './DragSelect';
13
+ import { SwipeRow, swipeOf } from './SwipeRow';
14
+ import { DT_CARD_MIN_WIDTH, DT_CARD_PAD } from '../styles/webValues';
15
+ export function CardList({ state }) {
16
+ const t = useTokens();
17
+ const phone = state.size === 'phone';
18
+ const look = cardLook(t, phone);
19
+ const { view, rows, cardFields, byKey, ctx } = state;
20
+ const [flipped, setFlipped] = useState(new Set());
21
+ const allOpen = !!view.cardsExpanded;
22
+ const toggle = (id) => setFlipped(prev => {
23
+ const next = new Set(prev);
24
+ if (next.has(id))
25
+ next.delete(id);
26
+ else
27
+ next.add(id);
28
+ return next;
29
+ });
30
+ const [inner, setInner] = useState(0);
31
+ const side = phone ? t.spacingLg : DT_CARD_PAD;
32
+ const perLine = phone ? 1 : cardsPerLine(inner, view.cardMinWidth ?? DT_CARD_MIN_WIDTH, look.gap);
33
+ const cardWidth = perLine > 1 ? Math.floor((inner - look.gap * (perLine - 1)) / perLine) : undefined;
34
+ const parts = useMemo(() => rows.map(r => rowParts(r.row, r.index, cardFields, byKey, view.avatar, ctx)), [rows, cardFields, byKey, view.avatar, ctx]);
35
+ const drag = useDragTick(state);
36
+ return (_jsx(View, { style: [look.list, { gap: look.gap }, perLine > 1 && { flexDirection: 'row', flexWrap: 'wrap' }], onLayout: e => setInner(e.nativeEvent.layout.width - side * 2), accessibilityRole: "list", accessibilityLabel: state.L.dataTable, ref: drag.listRef, ...drag.handlers, children: rows.map((r, i) => {
37
+ const swipe = swipeOf(state, r);
38
+ const card = (_jsx(Card, { parts: parts[i], open: allOpen ? !flipped.has(r.id) : flipped.has(r.id), onToggle: () => toggle(r.id), onPress: pressOf(state, r.id), onLongPress: longPressOf(state, r.id, drag), onPressOut: drag.release, onLayout: swipe ? undefined : drag.onRowLayout(r.id), check: state.checkboxes ? _jsx(RowCheck, { state: state, id: r.id, row: r.row, title: parts[i].title }) : null, ticked: state.checkboxes && state.isTicked(r.id), actions: hasRowActions(state, r, 'card') ? _jsx(RowActions, { state: state, item: r, surface: "card", title: parts[i].title }) : null, width: swipe ? undefined : cardWidth, phone: phone, showMore: state.L.showMore, showLess: state.L.showLess }, r.id));
39
+ return swipe ? (_jsx(SwipeRow, { ...swipe, radius: look.card.borderRadius, style: cardWidth !== undefined ? { width: cardWidth } : undefined, onLayout: drag.onRowLayout(r.id), children: card }, r.id)) : card;
40
+ }) }));
41
+ }
42
+ export function pairsOf(list) {
43
+ const out = [];
44
+ for (let i = 0; i < list.length; i += 2)
45
+ out.push([list[i], list[i + 1] ?? null]);
46
+ return out;
47
+ }
48
+ export function pressOf(state, id) {
49
+ if (state.tapTicks)
50
+ return () => state.toggleTick(id);
51
+ return state.opens || state.view.rowMenu?.onOpen ? () => state.open(id) : undefined;
52
+ }
53
+ export function longPressOf(state, id, drag) {
54
+ if (state.view.rowMenu?.longPress === 'open')
55
+ return state.opens || state.view.rowMenu?.onOpen ? () => state.open(id) : undefined;
56
+ if (state.pressTicks)
57
+ return e => (drag && state.multiple ? drag.start(id, e) : state.toggleTick(id));
58
+ return state.menuOn ? () => state.openMenu(id) : undefined;
59
+ }
60
+ export function RowCheck({ state, id, row, title }) {
61
+ return (_jsx(Checkbox, { size: "small", checked: state.isTicked(id), disabled: !state.canTick(row), onCheckedChange: () => state.toggleTick(id), "aria-label": `${state.L.selectRowMenu} ${title}`.trim() }));
62
+ }
63
+ function Card({ parts, open, onToggle, onPress, onLongPress, onPressOut, onLayout, actions, check, ticked, width, phone, showMore, showLess }) {
64
+ const t = useTokens();
65
+ const look = cardLook(t, phone);
66
+ const pressed = tableColors(t).rowHover;
67
+ const fields = (list, more) => (_jsx(View, { style: [look.fields, more && look.moreFields], children: pairsOf(list).map(pair => (_jsx(View, { style: look.fieldLine, children: pair.map((f, i) => f ? (_jsxs(View, { style: look.field, children: [_jsx(Text, { style: look.fieldName, numberOfLines: 1, children: f.header }), _jsx(CellNode, { node: f.node, style: look.fieldValue })] }, f.key)) : _jsx(View, { style: look.field }, i)) }, pair[0].key))) }));
68
+ const Chevron = open ? IconChevronUp : IconChevronDown;
69
+ return (_jsxs(Pressable, { onPress: onPress, onLongPress: onLongPress, onPressOut: onPressOut, onLayout: onLayout, disabled: !onPress && !onLongPress, accessibilityRole: onPress ? 'button' : undefined, accessibilityLabel: parts.title || undefined, accessibilityState: check ? { checked: ticked } : undefined, style: ({ pressed: down }) => [look.card, width !== undefined && { width }, ticked && cardTickedLook(t), down && { backgroundColor: pressed }], children: [check && _jsx(View, { style: cardCheckLook().box, children: check }), _jsxs(View, { style: [look.head, check ? { paddingLeft: cardCheckLook().headPad } : null], children: [_jsx(RowAvatarView, { avatar: parts.avatar, place: phone ? 'cardPhone' : 'card' }), _jsxs(View, { style: look.titles, children: [!!parts.title && _jsx(Text, { style: look.title, numberOfLines: 1, children: parts.title }), !!parts.subtitle && _jsx(Text, { style: look.subtitle, numberOfLines: 1, children: parts.subtitle })] }), parts.badge && _jsx(View, { style: look.badge, children: _jsx(CellNode, { node: parts.badge.node, style: look.badgeText }) })] }), parts.details.length > 0 && fields(parts.details), open && parts.more.length > 0 && fields(parts.more, true), (parts.more.length > 0 || actions) && (_jsxs(View, { style: look.foot, children: [_jsx(View, { style: { flex: 1 } }), parts.more.length > 0 && (_jsx(Pressable, { onPress: onToggle, accessibilityRole: "button", accessibilityLabel: open ? showLess : showMore, accessibilityState: { expanded: open }, hitSlop: 4, style: ({ pressed: down }) => [look.expand, down && { backgroundColor: t.hoverOverlay }], children: _jsx(Chevron, { size: look.expandIcon, color: t.textSecondary }) })), actions] }))] }));
70
+ }
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { ActivityIndicator, Text, View, useWindowDimensions } from 'react-native';
4
+ import { useTokens } from '../UIProvider/context';
5
+ import { Button } from '../Button/Button';
6
+ import { CardList } from './CardList';
7
+ import { containerLook, emptyLook } from './dataTableStyle';
8
+ import { Pager } from './Pager';
9
+ import { DetailPane, DetailSheet } from './RowDetail';
10
+ import { SplitList } from './SplitList';
11
+ import { RowMenuSheet } from './RowMenuSheet';
12
+ import { FilterSheet } from './filters/FilterSheet';
13
+ import { StatusRow } from './StatusRow';
14
+ import { useBulkRun } from './BulkRun';
15
+ import { ToastHost, useOptionalToast } from '../Toast/ToastHost';
16
+ import { Toolbar, ViewTabs } from './Toolbar';
17
+ import { useTableState } from './useTableState';
18
+ import { DT_LOADING_OPACITY } from '../styles/webValues';
19
+ const SPLIT_HEIGHT_SHARE = 0.7;
20
+ const SPLIT_MIN_HEIGHT = 320;
21
+ export function DataTable(props) {
22
+ const host = useOptionalToast();
23
+ return host ? _jsx(Table, { ...props }) : _jsx(ToastHost, { children: _jsx(Table, { ...props }) });
24
+ }
25
+ DataTable.displayName = 'DataTable';
26
+ function Table(props) {
27
+ const t = useTokens();
28
+ const window = useWindowDimensions();
29
+ const [measured, setMeasured] = useState(0);
30
+ const width = measured || window.width;
31
+ const state = useTableState(props, width);
32
+ const bulk = useBulkRun(state);
33
+ const empty = emptyLook(t);
34
+ const { view, L } = state;
35
+ const message = (text, extra) => (_jsxs(View, { style: empty.box, children: [_jsx(Text, { style: empty.text, children: text }), extra] }));
36
+ let placeholder = null;
37
+ if (view.loading || state.loading) {
38
+ placeholder = message(view.loadingMessage ?? L.loading, _jsx(ActivityIndicator, { color: t.accentPrimary, style: { marginTop: t.spacingMd } }));
39
+ }
40
+ else if (state.error) {
41
+ placeholder = message(L.loadError, _jsx(Button, { variant: "outlined", color: "neutral", onPress: state.retry, style: { marginTop: t.spacingMd }, children: L.retry }));
42
+ }
43
+ else if (state.rows.length === 0) {
44
+ placeholder = message(state.search ? view.noResultsMessage ?? L.noResults : view.emptyMessage ?? L.empty);
45
+ }
46
+ const pane = state.layout === 'split' && state.detailMode === 'pane' && state.opens
47
+ ? _jsx(DetailPane, { state: state, renderDetail: props.renderDetail, bar: props.detailBar !== false })
48
+ : null;
49
+ const body = placeholder ?? (state.layout === 'split'
50
+ ? _jsx(SplitList, { state: state, pane: pane, height: Math.max(SPLIT_MIN_HEIGHT, window.height * SPLIT_HEIGHT_SHARE) })
51
+ : _jsx(CardList, { state: state }));
52
+ return (_jsxs(View, { style: [containerLook(t), props.style], onLayout: e => setMeasured(e.nativeEvent.layout.width), testID: props.testID, children: [_jsx(ViewTabs, { state: state }), _jsx(Toolbar, { state: state }), _jsx(StatusRow, { state: state, bulk: bulk.runner }), _jsx(View, { style: state.fetching && !placeholder ? { opacity: DT_LOADING_OPACITY } : undefined, accessibilityState: { busy: state.fetching }, children: body }), _jsx(Pager, { state: state }), state.opens && !pane && _jsx(DetailSheet, { state: state, renderDetail: props.renderDetail, bar: props.detailBar !== false }), state.menuOn && _jsx(RowMenuSheet, { state: state }), state.filterOn && _jsx(FilterSheet, { state: state }), bulk.dialog] }));
53
+ }
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, forwardRef, useCallback, useContext, useMemo, useRef, useState } from 'react';
3
+ import { ScrollView } from 'react-native';
4
+ const TableScrollContext = createContext(null);
5
+ export const useTableScroll = () => useContext(TableScrollContext);
6
+ export const DataTableScrollView = forwardRef(function DataTableScrollView(props, ref) {
7
+ const { scrollEnabled, onScroll, scrollEventThrottle, children, ...rest } = props;
8
+ const [held, setHeld] = useState(false);
9
+ const inner = useRef(null);
10
+ const offset = useRef(0);
11
+ const setRef = useCallback((node) => {
12
+ inner.current = node;
13
+ if (typeof ref === 'function')
14
+ ref(node);
15
+ else if (ref)
16
+ ref.current = node;
17
+ }, [ref]);
18
+ const handleScroll = useCallback((e) => {
19
+ offset.current = e.nativeEvent.contentOffset.y;
20
+ onScroll?.(e);
21
+ }, [onScroll]);
22
+ const api = useMemo(() => ({
23
+ hold: setHeld,
24
+ offset: () => offset.current,
25
+ scrollTo: y => {
26
+ offset.current = y;
27
+ inner.current?.scrollTo({ y, animated: false });
28
+ },
29
+ view: () => inner.current?.getNativeScrollRef?.() ?? null,
30
+ }), []);
31
+ return (_jsx(TableScrollContext.Provider, { value: api, children: _jsx(ScrollView, { ...rest, ref: setRef, scrollEnabled: scrollEnabled !== false && !held, onScroll: handleScroll, scrollEventThrottle: scrollEventThrottle ?? 16, children: children }) }));
32
+ });
33
+ DataTableScrollView.displayName = 'DataTableScrollView';
@@ -0,0 +1,153 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { PanResponder } from 'react-native';
3
+ import { measureOnPage } from '../Press/measure';
4
+ import { useTableScroll } from './DataTableScrollView';
5
+ const EDGE = 64;
6
+ const SCROLL_MAX = 12;
7
+ const FRAME_MS = 16;
8
+ export function useDragTick(state) {
9
+ const scroll = useTableScroll();
10
+ const listRef = useRef(null);
11
+ const boxes = useRef(new Map());
12
+ const drag = useRef(null);
13
+ const timer = useRef(null);
14
+ const live = useRef({ state, scroll });
15
+ live.current = { state, scroll };
16
+ const onRowLayout = useCallback((id) => (e) => {
17
+ const { x, y, width, height } = e.nativeEvent.layout;
18
+ boxes.current.set(id, { x, y, width, height });
19
+ }, []);
20
+ const stopScroll = () => {
21
+ if (timer.current)
22
+ clearInterval(timer.current);
23
+ timer.current = null;
24
+ };
25
+ const rowAt = (x, y) => {
26
+ const rows = live.current.state.rows;
27
+ let best = -1;
28
+ for (let i = 0; i < rows.length; i++) {
29
+ const b = boxes.current.get(rows[i].id);
30
+ if (!b)
31
+ continue;
32
+ if (y >= b.y && y < b.y + b.height && x >= b.x && x < b.x + b.width)
33
+ return i;
34
+ if (b.y <= y)
35
+ best = i;
36
+ }
37
+ return best < 0 ? 0 : best;
38
+ };
39
+ const pointInList = (d) => {
40
+ const moved = (live.current.scroll?.offset() ?? 0) - d.offsetStart;
41
+ return { x: d.last.x - d.listLeft, y: d.last.y - d.listTop + moved };
42
+ };
43
+ const apply = (d) => {
44
+ const s = live.current.state;
45
+ const p = pointInList(d);
46
+ const at = drag.current === d && d.taken ? rowAt(p.x, p.y) : d.anchor;
47
+ const [from, to] = at < d.anchor ? [at, d.anchor] : [d.anchor, at];
48
+ const range = `${from}:${to}`;
49
+ if (range === d.range)
50
+ return;
51
+ d.range = range;
52
+ const next = { ...d.before };
53
+ s.rows.forEach((r, i) => {
54
+ if (i < from || i > to)
55
+ return;
56
+ if (d.on)
57
+ next[r.id] = true;
58
+ else
59
+ delete next[r.id];
60
+ });
61
+ s.setTicks(next);
62
+ };
63
+ const follow = () => { if (drag.current)
64
+ apply(drag.current); };
65
+ const speedAt = (d) => {
66
+ if (d.edgeBottom <= d.edgeTop)
67
+ return 0;
68
+ const y = d.last.y;
69
+ const up = y < d.edgeTop + EDGE ? (d.edgeTop + EDGE - y) / EDGE : 0;
70
+ const down = y > d.edgeBottom - EDGE ? (y - (d.edgeBottom - EDGE)) / EDGE : 0;
71
+ return Math.round(Math.min(1, down) * SCROLL_MAX - Math.min(1, up) * SCROLL_MAX);
72
+ };
73
+ const edgeScroll = () => {
74
+ const d = drag.current;
75
+ if (!d || !live.current.scroll || speedAt(d) === 0) {
76
+ stopScroll();
77
+ return;
78
+ }
79
+ if (timer.current)
80
+ return;
81
+ timer.current = setInterval(() => {
82
+ const dd = drag.current;
83
+ const sc = live.current.scroll;
84
+ const v = dd ? speedAt(dd) : 0;
85
+ if (!dd || !sc || v === 0) {
86
+ stopScroll();
87
+ return;
88
+ }
89
+ const rows = live.current.state.rows;
90
+ const lastBox = rows.length ? boxes.current.get(rows[rows.length - 1].id) : undefined;
91
+ const at = sc.offset();
92
+ if ((v < 0 && at <= 0) || (v > 0 && lastBox && pointInList(dd).y > lastBox.y + lastBox.height)) {
93
+ stopScroll();
94
+ return;
95
+ }
96
+ sc.scrollTo(Math.max(0, at + v));
97
+ follow();
98
+ }, FRAME_MS);
99
+ };
100
+ const end = useCallback(() => {
101
+ stopScroll();
102
+ if (drag.current)
103
+ live.current.scroll?.hold(false);
104
+ drag.current = null;
105
+ }, []);
106
+ useEffect(() => end, [end]);
107
+ const start = useCallback((id, event) => {
108
+ const { state: s, scroll: sc } = live.current;
109
+ const anchor = s.rows.findIndex(r => r.id === id);
110
+ if (anchor < 0)
111
+ return;
112
+ const before = { ...s.ticks };
113
+ sc?.hold(true);
114
+ const { pageX = 0, pageY = 0 } = event?.nativeEvent ?? {};
115
+ const d = {
116
+ anchor, on: !before[id], before, listLeft: 0, listTop: 0, offsetStart: sc?.offset() ?? 0,
117
+ edgeTop: 0, edgeBottom: 0, last: { x: pageX, y: pageY }, taken: false, range: '',
118
+ };
119
+ drag.current = d;
120
+ setTimeout(() => apply(d), 0);
121
+ const list = listRef.current;
122
+ if (list)
123
+ measureOnPage(list, box => { d.listLeft = box.left; d.listTop = box.top; });
124
+ const frame = sc?.view();
125
+ if (frame)
126
+ measureOnPage(frame, box => { d.edgeTop = box.top; d.edgeBottom = box.top + box.height; });
127
+ }, []);
128
+ const handlers = useMemo(() => PanResponder.create({
129
+ onMoveShouldSetPanResponderCapture: () => {
130
+ const d = drag.current;
131
+ if (!d)
132
+ return false;
133
+ d.taken = true;
134
+ return true;
135
+ },
136
+ onPanResponderTerminationRequest: () => false,
137
+ onPanResponderMove: e => {
138
+ const d = drag.current;
139
+ if (!d)
140
+ return;
141
+ d.last = { x: e.nativeEvent.pageX, y: e.nativeEvent.pageY };
142
+ follow();
143
+ edgeScroll();
144
+ },
145
+ onPanResponderRelease: () => end(),
146
+ onPanResponderTerminate: () => end(),
147
+ }).panHandlers, [end]);
148
+ const release = useCallback(() => {
149
+ if (drag.current && !drag.current.taken)
150
+ end();
151
+ }, [end]);
152
+ return { start, release, onRowLayout, listRef, handlers };
153
+ }
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState } from 'react';
3
+ import { Modal, Pressable, Text, View, useWindowDimensions } from 'react-native';
4
+ import { useTokens } from '../UIProvider/context';
5
+ import { IconCheck, IconChevronDown, IconLayoutCards, IconLayoutSplit, IconLayoutTable } from '../Icon';
6
+ import { boxShadow } from '../Button/buttonStyle';
7
+ import { measureOnPage } from '../Press/measure';
8
+ import { iconButtonLook, tableColors } from './dataTableStyle';
9
+ import { DT_LAYOUT_ITEM_MIN_HEIGHT, DT_LAYOUT_ITEM_PAD, DT_POP_EDGE, DT_POP_MIN_WIDTH, DT_POP_OFFSET } from '../styles/webValues';
10
+ export const LAYOUT_ICONS = { table: IconLayoutTable, cards: IconLayoutCards, split: IconLayoutSplit };
11
+ export function popMenuLook(t) {
12
+ return {
13
+ box: {
14
+ position: 'absolute', minWidth: DT_POP_MIN_WIDTH, padding: t.spacingSm,
15
+ backgroundColor: t.bgSecondary, borderWidth: 1, borderColor: t.borderColor, borderRadius: t.borderRadius,
16
+ boxShadow: boxShadow(t.shadowPopover),
17
+ },
18
+ item: { minHeight: DT_LAYOUT_ITEM_MIN_HEIGHT, flexDirection: 'row', alignItems: 'center', gap: DT_LAYOUT_ITEM_PAD, paddingHorizontal: DT_LAYOUT_ITEM_PAD, borderRadius: t.borderRadiusSm },
19
+ itemPressed: { backgroundColor: tableColors(t).rowHover },
20
+ label: { flex: 1, fontSize: t.fontSizeMd, color: t.textPrimary },
21
+ labelOn: { fontWeight: String(t.fontWeightBold) },
22
+ };
23
+ }
24
+ export function LayoutSwitcher({ layouts, layout, onChange, L, size, compact }) {
25
+ const t = useTokens();
26
+ const window = useWindowDimensions();
27
+ const button = useRef(null);
28
+ const [at, setAt] = useState(null);
29
+ const name = { table: L.layoutTable, cards: L.layoutCards, split: L.layoutSplit };
30
+ if (layouts.length < 2)
31
+ return null;
32
+ const look = popMenuLook(t);
33
+ const Icon = LAYOUT_ICONS[layout];
34
+ const open = () => { if (button.current)
35
+ measureOnPage(button.current, setAt); };
36
+ const close = () => setAt(null);
37
+ return (_jsxs(_Fragment, { children: [_jsx(Pressable, { ref: button, onPress: open, accessibilityRole: "button", accessibilityLabel: L.layoutCurrent(name[layout]), accessibilityState: { expanded: !!at }, hitSlop: 4, style: ({ pressed }) => [
38
+ iconButtonLook(t, size, false, pressed || !!at).box,
39
+ { width: undefined, minWidth: size, flexDirection: 'row', gap: t.spacingXxs, paddingLeft: t.spacingSm, paddingRight: t.spacingXs },
40
+ ], children: ({ pressed }) => {
41
+ const color = iconButtonLook(t, size, false, pressed || !!at).color;
42
+ return (_jsxs(_Fragment, { children: [_jsx(Icon, { size: "action", color: color }), !compact && _jsx(Text, { style: { fontSize: t.fontSizeXs, fontWeight: String(t.fontWeightMedium), color }, numberOfLines: 1, children: name[layout] }), _jsx(IconChevronDown, { size: t.iconSlotInline, color: color })] }));
43
+ } }), _jsx(Modal, { visible: !!at, transparent: true, animationType: "fade", onRequestClose: close, children: _jsx(Pressable, { accessible: false, style: { flex: 1 }, onPress: close, children: at && (_jsx(View, { role: "menu", "aria-label": L.layout, style: [look.box, { top: at.top + at.height + DT_POP_OFFSET, right: Math.max(DT_POP_EDGE, window.width - (at.left + at.width)) }], children: layouts.map(l => {
44
+ const on = l === layout;
45
+ const ItemIcon = LAYOUT_ICONS[l];
46
+ return (_jsxs(Pressable, { role: "menuitem", accessibilityState: { checked: on }, accessibilityLabel: name[l], onPress: () => { close(); onChange(l); }, style: ({ pressed }) => [look.item, pressed && look.itemPressed], children: [_jsx(ItemIcon, { size: "action", color: on ? t.accentPrimaryText : t.textSecondary }), _jsx(Text, { style: [look.label, on && look.labelOn], numberOfLines: 1, children: name[l] }), on ? _jsx(IconCheck, { size: "action", color: t.accentPrimaryText }) : _jsx(View, { style: { width: t.iconSizeAction } })] }, l));
47
+ }) })) }) })] }));
48
+ }
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Text, View } from 'react-native';
3
+ import { useTokens } from '../UIProvider/context';
4
+ import { IconChevronLeft, IconChevronRight } from '../Icon';
5
+ import { pagerLook } from './dataTableStyle';
6
+ import { ToolButton } from './ToolButton';
7
+ import { DT_PAGER_BUTTON } from '../styles/webValues';
8
+ export function Pager({ state }) {
9
+ const t = useTokens();
10
+ const look = pagerLook(t);
11
+ const { L, format, pageIndex, pageCount, setPageIndex } = state;
12
+ if (!state.pageOn || pageCount < 2)
13
+ return null;
14
+ return (_jsxs(View, { style: look.bar, children: [_jsx(ToolButton, { icon: IconChevronLeft, label: L.previousPage, size: DT_PAGER_BUTTON, disabled: pageIndex <= 0, onPress: () => setPageIndex(pageIndex - 1) }), _jsx(Text, { style: look.info, accessibilityRole: "text", accessibilityLiveRegion: "polite", children: L.pageOf(format.number(pageIndex + 1), format.number(pageCount)) }), _jsx(ToolButton, { icon: IconChevronRight, label: L.nextPage, size: DT_PAGER_BUTTON, disabled: pageIndex >= pageCount - 1, onPress: () => setPageIndex(pageIndex + 1) })] }));
15
+ }
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { View } from 'react-native';
3
+ import { inlineActionsOf, rowActionButtons } from '@dcs-tech/core';
4
+ import { useTokens } from '../UIProvider/context';
5
+ import { Button } from '../Button/Button';
6
+ import { IconMoreVertical } from '../Icon';
7
+ const colorOf = (variant) => (variant === 'danger' ? 'error' : variant ?? 'primary');
8
+ export function rowButtonsOf(state, item, surface) {
9
+ const buttons = surface === 'card' ? rowActionButtons('card', undefined, state.view.inlineActions) : { count: 1, primaryOnly: true };
10
+ return inlineActionsOf(state.actionsOf(item.row), item.row, buttons.count, buttons.primaryOnly);
11
+ }
12
+ export const hasRowActions = (state, item, surface) => state.menuOn || rowButtonsOf(state, item, surface).length > 0;
13
+ export function RowActions({ state, item, surface, title }) {
14
+ const t = useTokens();
15
+ const { L } = state;
16
+ const shown = rowButtonsOf(state, item, surface);
17
+ if (!shown.length && !state.menuOn)
18
+ return null;
19
+ return (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXxs }, children: [shown.map(action => _jsx(ActionButton, { action: action, item: item, listItem: surface === 'list', title: title }, action.id)), state.menuOn && (_jsx(Button, { icon: _jsx(IconMoreVertical, {}), size: "xxs", variant: "text", color: "secondary", "aria-label": L.rowMenu(title), onPress: () => state.openMenu(item.id) }))] }));
20
+ }
21
+ function ActionButton({ action, item, listItem, title }) {
22
+ const row = item.row;
23
+ const label = (typeof action.label === 'function' ? action.label(row) : action.label) ?? '';
24
+ const icon = typeof action.icon === 'function' ? action.icon(row) : action.icon;
25
+ const variant = typeof action.variant === 'function' ? action.variant(row) : action.variant;
26
+ const iconOnly = listItem && !!icon;
27
+ return (_jsx(Button, { icon: iconOnly ? icon : undefined, startIcon: iconOnly ? undefined : icon, label: iconOnly ? undefined : label, size: "xxs", variant: "text", color: colorOf(variant), disableTextTransform: action.disableTextTransform, "aria-label": iconOnly ? `${label} ${title}`.trim() : undefined, disabled: action.disabledWhen?.(row), onPress: () => action.onClick(row, item.index) }));
28
+ }