@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.
- package/CHANGELOG.md +186 -0
- package/README.md +179 -2
- package/dist/components/Button/Button.js +61 -0
- package/dist/components/Button/buttonStyle.js +100 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Checkbox/Checkbox.js +60 -0
- package/dist/components/Checkbox/checkboxStyle.js +44 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/DataTable/BulkRun.js +85 -0
- package/dist/components/DataTable/CardList.js +70 -0
- package/dist/components/DataTable/DataTable.js +53 -0
- package/dist/components/DataTable/DataTableScrollView.js +33 -0
- package/dist/components/DataTable/DragSelect.js +153 -0
- package/dist/components/DataTable/LayoutSwitcher.js +48 -0
- package/dist/components/DataTable/Pager.js +15 -0
- package/dist/components/DataTable/RowActions.js +28 -0
- package/dist/components/DataTable/RowDetail.js +80 -0
- package/dist/components/DataTable/RowMenuSheet.js +72 -0
- package/dist/components/DataTable/SortSheet.js +25 -0
- package/dist/components/DataTable/SplitList.js +30 -0
- package/dist/components/DataTable/StatusRow.js +48 -0
- package/dist/components/DataTable/SwipeRow.js +125 -0
- package/dist/components/DataTable/ToolButton.js +9 -0
- package/dist/components/DataTable/Toolbar.js +53 -0
- package/dist/components/DataTable/cells.js +21 -0
- package/dist/components/DataTable/dataTableStyle.js +218 -0
- package/dist/components/DataTable/filters/FilterConditionRow.js +49 -0
- package/dist/components/DataTable/filters/FilterGroupEditor.js +21 -0
- package/dist/components/DataTable/filters/FilterSheet.js +69 -0
- package/dist/components/DataTable/filters/SavedFilterBar.js +39 -0
- package/dist/components/DataTable/filters/filterStyle.js +82 -0
- package/dist/components/DataTable/index.js +3 -0
- package/dist/components/DataTable/persistence/adapters.js +78 -0
- package/dist/components/DataTable/persistence/useViewPrefs.js +76 -0
- package/dist/components/DataTable/rowParts.js +47 -0
- package/dist/components/DataTable/useTableState.js +345 -0
- package/dist/components/DatePicker/Calendar.js +28 -0
- package/dist/components/DatePicker/DatePicker.js +300 -0
- package/dist/components/DatePicker/PeriodGrid.js +17 -0
- package/dist/components/DatePicker/PeriodPicker.js +216 -0
- package/dist/components/DatePicker/TimeField.js +50 -0
- package/dist/components/DatePicker/datePickerStyle.js +157 -0
- package/dist/components/DatePicker/index.js +2 -0
- package/dist/components/Dialog/Dialog.js +104 -0
- package/dist/components/Dialog/DialogHost.js +71 -0
- package/dist/components/Dialog/dialogStyle.js +72 -0
- package/dist/components/Dialog/index.js +2 -0
- package/dist/components/FieldContext/FieldContext.js +50 -0
- package/dist/components/FieldContext/index.js +1 -0
- package/dist/components/FieldWrapper/FieldWrapper.js +23 -0
- package/dist/components/FieldWrapper/fieldWrapperStyle.js +64 -0
- package/dist/components/FieldWrapper/index.js +1 -0
- package/dist/components/Icon/Icon.js +124 -0
- package/dist/components/Icon/IconContext.js +12 -0
- package/dist/components/Icon/iconStyle.js +59 -0
- package/dist/components/Icon/icons.js +252 -0
- package/dist/components/Icon/index.js +4 -0
- package/dist/components/Icon/useIconDone.js +19 -0
- package/dist/components/Input/Input.js +71 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/Input/inputStyle.js +47 -0
- package/dist/components/Press/Ripple.js +92 -0
- package/dist/components/Press/index.js +1 -0
- package/dist/components/Press/measure.js +3 -0
- package/dist/components/Radio/Radio.js +54 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/Radio/radioStyle.js +45 -0
- package/dist/components/Select/Select.js +83 -0
- package/dist/components/Select/SelectSheet.js +85 -0
- package/dist/components/Select/index.js +1 -0
- package/dist/components/Suggest/Suggest.js +101 -0
- package/dist/components/Suggest/index.js +1 -0
- package/dist/components/Switch/Switch.js +71 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Switch/switchStyle.js +59 -0
- package/dist/components/Toast/ToastHost.js +76 -0
- package/dist/components/Toast/ToastItem.js +115 -0
- package/dist/components/Toast/ToastLayer.js +21 -0
- package/dist/components/Toast/index.js +2 -0
- package/dist/components/Toast/toast.types.js +1 -0
- package/dist/components/Toast/toastStyle.js +73 -0
- package/dist/components/Toggle/ToggleField.js +20 -0
- package/dist/components/Toggle/ToggleGroupFrame.js +10 -0
- package/dist/components/UIProvider/UIProvider.js +14 -0
- package/dist/components/UIProvider/context.js +58 -0
- package/dist/components/UIProvider/index.js +1 -0
- package/dist/components/styles/color.js +35 -0
- package/dist/components/styles/fieldControl.js +102 -0
- package/dist/components/styles/popupList.js +102 -0
- package/dist/components/styles/toggle.js +64 -0
- package/dist/components/styles/webValues.js +147 -0
- package/dist/index.js +15 -0
- package/dist/locales/hi.js +1 -0
- package/dist/locales/ta.js +1 -0
- package/dist/types/components/Button/Button.d.ts +31 -0
- package/dist/types/components/Button/buttonStyle.d.ts +46 -0
- package/dist/types/components/Button/index.d.ts +3 -0
- package/dist/types/components/Checkbox/Checkbox.d.ts +60 -0
- package/dist/types/components/Checkbox/checkboxStyle.d.ts +16 -0
- package/dist/types/components/Checkbox/index.d.ts +3 -0
- package/dist/types/components/DataTable/BulkRun.d.ts +11 -0
- package/dist/types/components/DataTable/CardList.d.ts +18 -0
- package/dist/types/components/DataTable/DataTable.d.ts +11 -0
- package/dist/types/components/DataTable/DataTableScrollView.d.ts +10 -0
- package/dist/types/components/DataTable/DragSelect.d.ts +12 -0
- package/dist/types/components/DataTable/LayoutSwitcher.d.ts +23 -0
- package/dist/types/components/DataTable/Pager.d.ts +5 -0
- package/dist/types/components/DataTable/RowActions.d.ts +13 -0
- package/dist/types/components/DataTable/RowDetail.d.ts +15 -0
- package/dist/types/components/DataTable/RowMenuSheet.d.ts +5 -0
- package/dist/types/components/DataTable/SortSheet.d.ts +8 -0
- package/dist/types/components/DataTable/SplitList.d.ts +9 -0
- package/dist/types/components/DataTable/StatusRow.d.ts +7 -0
- package/dist/types/components/DataTable/SwipeRow.d.ts +25 -0
- package/dist/types/components/DataTable/ToolButton.d.ts +13 -0
- package/dist/types/components/DataTable/Toolbar.d.ts +8 -0
- package/dist/types/components/DataTable/cells.d.ts +13 -0
- package/dist/types/components/DataTable/dataTableStyle.d.ts +139 -0
- package/dist/types/components/DataTable/filters/FilterConditionRow.d.ts +12 -0
- package/dist/types/components/DataTable/filters/FilterGroupEditor.d.ts +13 -0
- package/dist/types/components/DataTable/filters/FilterSheet.d.ts +5 -0
- package/dist/types/components/DataTable/filters/SavedFilterBar.d.ts +20 -0
- package/dist/types/components/DataTable/filters/filterStyle.d.ts +46 -0
- package/dist/types/components/DataTable/index.d.ts +5 -0
- package/dist/types/components/DataTable/persistence/adapters.d.ts +12 -0
- package/dist/types/components/DataTable/persistence/useViewPrefs.d.ts +20 -0
- package/dist/types/components/DataTable/rowParts.d.ts +32 -0
- package/dist/types/components/DataTable/useTableState.d.ts +103 -0
- package/dist/types/components/DatePicker/Calendar.d.ts +11 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +65 -0
- package/dist/types/components/DatePicker/PeriodGrid.d.ts +11 -0
- package/dist/types/components/DatePicker/PeriodPicker.d.ts +10 -0
- package/dist/types/components/DatePicker/TimeField.d.ts +15 -0
- package/dist/types/components/DatePicker/datePickerStyle.d.ts +75 -0
- package/dist/types/components/DatePicker/index.d.ts +4 -0
- package/dist/types/components/Dialog/Dialog.d.ts +35 -0
- package/dist/types/components/Dialog/DialogHost.d.ts +45 -0
- package/dist/types/components/Dialog/dialogStyle.d.ts +23 -0
- package/dist/types/components/Dialog/index.d.ts +4 -0
- package/dist/types/components/FieldContext/FieldContext.d.ts +43 -0
- package/dist/types/components/FieldContext/index.d.ts +3 -0
- package/dist/types/components/FieldWrapper/FieldWrapper.d.ts +23 -0
- package/dist/types/components/FieldWrapper/fieldWrapperStyle.d.ts +24 -0
- package/dist/types/components/FieldWrapper/index.d.ts +3 -0
- package/dist/types/components/Icon/Icon.d.ts +37 -0
- package/dist/types/components/Icon/IconContext.d.ts +12 -0
- package/dist/types/components/Icon/iconStyle.d.ts +10 -0
- package/dist/types/components/Icon/icons.d.ts +250 -0
- package/dist/types/components/Icon/index.d.ts +7 -0
- package/dist/types/components/Icon/useIconDone.d.ts +4 -0
- package/dist/types/components/Input/Input.d.ts +53 -0
- package/dist/types/components/Input/index.d.ts +3 -0
- package/dist/types/components/Input/inputStyle.d.ts +11 -0
- package/dist/types/components/Press/Ripple.d.ts +20 -0
- package/dist/types/components/Press/index.d.ts +2 -0
- package/dist/types/components/Press/measure.d.ts +8 -0
- package/dist/types/components/Radio/Radio.d.ts +58 -0
- package/dist/types/components/Radio/index.d.ts +3 -0
- package/dist/types/components/Radio/radioStyle.d.ts +17 -0
- package/dist/types/components/Select/Select.d.ts +49 -0
- package/dist/types/components/Select/SelectSheet.d.ts +34 -0
- package/dist/types/components/Select/index.d.ts +3 -0
- package/dist/types/components/Suggest/Suggest.d.ts +44 -0
- package/dist/types/components/Suggest/index.d.ts +3 -0
- package/dist/types/components/Switch/Switch.d.ts +42 -0
- package/dist/types/components/Switch/index.d.ts +3 -0
- package/dist/types/components/Switch/switchStyle.d.ts +29 -0
- package/dist/types/components/Toast/ToastHost.d.ts +12 -0
- package/dist/types/components/Toast/ToastItem.d.ts +17 -0
- package/dist/types/components/Toast/ToastLayer.d.ts +11 -0
- package/dist/types/components/Toast/index.d.ts +5 -0
- package/dist/types/components/Toast/toast.types.d.ts +37 -0
- package/dist/types/components/Toast/toastStyle.d.ts +22 -0
- package/dist/types/components/Toggle/ToggleField.d.ts +31 -0
- package/dist/types/components/Toggle/ToggleGroupFrame.d.ts +14 -0
- package/dist/types/components/UIProvider/UIProvider.d.ts +17 -0
- package/dist/types/components/UIProvider/context.d.ts +22 -0
- package/dist/types/components/UIProvider/index.d.ts +2 -0
- package/dist/types/components/styles/color.d.ts +2 -0
- package/dist/types/components/styles/fieldControl.d.ts +26 -0
- package/dist/types/components/styles/popupList.d.ts +48 -0
- package/dist/types/components/styles/toggle.d.ts +26 -0
- package/dist/types/components/styles/webValues.d.ts +157 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/locales/hi.d.ts +1 -0
- package/dist/types/locales/ta.d.ts +1 -0
- package/package.json +85 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { AppState } from 'react-native';
|
|
4
|
+
import { useTopDialog } from '../Dialog/Dialog';
|
|
5
|
+
import { ToastLayer, ToastLayerContext } from './ToastLayer';
|
|
6
|
+
const ToastApiContext = createContext(null);
|
|
7
|
+
export const useToast = () => {
|
|
8
|
+
const api = useContext(ToastApiContext);
|
|
9
|
+
if (!api)
|
|
10
|
+
throw new Error('useToast() requires a <UIProvider> above it — that is what renders the toast host.');
|
|
11
|
+
return api;
|
|
12
|
+
};
|
|
13
|
+
export const useOptionalToast = () => useContext(ToastApiContext);
|
|
14
|
+
let seq = 0;
|
|
15
|
+
const nextId = () => `t${++seq}`;
|
|
16
|
+
const foreground = (s) => s !== 'background' && s !== 'inactive';
|
|
17
|
+
export function ToastHost({ defaults = {}, children }) {
|
|
18
|
+
const { newestOnTop = false, limit = 4, position: defaultPosition = 'top-center', autoClose: defaultAutoClose = 5000, ...restDefaults } = defaults;
|
|
19
|
+
const [toasts, setToasts] = useState([]);
|
|
20
|
+
const [active, setActive] = useState(() => foreground(AppState.currentState));
|
|
21
|
+
const memory = useRef(new Map()).current;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const sub = AppState.addEventListener('change', s => setActive(foreground(s)));
|
|
24
|
+
return () => sub.remove();
|
|
25
|
+
}, []);
|
|
26
|
+
const dismiss = useCallback((id) => {
|
|
27
|
+
if (id === undefined)
|
|
28
|
+
memory.clear();
|
|
29
|
+
else
|
|
30
|
+
memory.delete(id);
|
|
31
|
+
setToasts(prev => (id === undefined ? [] : prev.filter(x => x.id !== id)));
|
|
32
|
+
}, [memory]);
|
|
33
|
+
const restKey = JSON.stringify(restDefaults);
|
|
34
|
+
const push = useCallback((message, opts = {}) => {
|
|
35
|
+
const id = opts.id ?? nextId();
|
|
36
|
+
const record = {
|
|
37
|
+
position: defaultPosition,
|
|
38
|
+
autoClose: defaultAutoClose,
|
|
39
|
+
...restDefaults,
|
|
40
|
+
...opts,
|
|
41
|
+
id,
|
|
42
|
+
message,
|
|
43
|
+
};
|
|
44
|
+
setToasts(prev => {
|
|
45
|
+
const at = prev.findIndex(x => x.id === id);
|
|
46
|
+
if (at < 0)
|
|
47
|
+
return [...prev, record];
|
|
48
|
+
const next = [...prev];
|
|
49
|
+
next[at] = record;
|
|
50
|
+
return next;
|
|
51
|
+
});
|
|
52
|
+
return id;
|
|
53
|
+
}, [defaultPosition, defaultAutoClose, restKey]);
|
|
54
|
+
const api = useMemo(() => ({
|
|
55
|
+
toast: (m, o) => push(m, o),
|
|
56
|
+
success: (m, o) => push(m, { ...o, type: 'success' }),
|
|
57
|
+
error: (m, o) => push(m, { ...o, type: 'error' }),
|
|
58
|
+
warning: (m, o) => push(m, { ...o, type: 'warning' }),
|
|
59
|
+
info: (m, o) => push(m, { ...o, type: 'info' }),
|
|
60
|
+
update: (id, m, o) => { push(m, { ...o, id }); },
|
|
61
|
+
dismiss,
|
|
62
|
+
isActive: id => toasts.some(x => x.id === id),
|
|
63
|
+
}), [push, dismiss, toasts]);
|
|
64
|
+
const layer = useMemo(() => {
|
|
65
|
+
const map = new Map();
|
|
66
|
+
for (const x of toasts) {
|
|
67
|
+
const p = x.position ?? defaultPosition;
|
|
68
|
+
map.set(p, [...(map.get(p) ?? []), x]);
|
|
69
|
+
}
|
|
70
|
+
const regions = [...map.entries()].map(([p, list]) => [p, (newestOnTop ? [...list].reverse() : list).slice(0, limit)]);
|
|
71
|
+
return { regions, active, dismiss, memory };
|
|
72
|
+
}, [toasts, defaultPosition, newestOnTop, limit, active, dismiss, memory]);
|
|
73
|
+
const inDialog = useTopDialog() !== null;
|
|
74
|
+
return (_jsx(ToastApiContext.Provider, { value: api, children: _jsxs(ToastLayerContext.Provider, { value: layer, children: [children, !inDialog && _jsx(ToastLayer, {})] }) }));
|
|
75
|
+
}
|
|
76
|
+
ToastHost.displayName = 'ToastHost';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { AccessibilityInfo, Animated, Easing, PanResponder, Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { useTokens, useUILabels } from '../UIProvider/context';
|
|
5
|
+
import { IconSlotContext } from '../Icon/IconContext';
|
|
6
|
+
import { IconClose, IconError, IconInfo, IconSuccess, IconWarning } from '../Icon/icons';
|
|
7
|
+
import { CSS_EASE, TOAST_ENTER_OFFSET, TOAST_EXIT_MS, TOAST_MOTION_SCALE, TOAST_SWIPE_DISMISS, TOAST_SWIPE_FADE } from '../styles/webValues';
|
|
8
|
+
import { toastLook } from './toastStyle';
|
|
9
|
+
const ICONS = {
|
|
10
|
+
success: IconSuccess,
|
|
11
|
+
error: IconError,
|
|
12
|
+
warning: IconWarning,
|
|
13
|
+
info: IconInfo,
|
|
14
|
+
};
|
|
15
|
+
const leftOf = (m) => (m ? m.left - (m.since === null ? 0 : Date.now() - m.since) : undefined);
|
|
16
|
+
const SWIPE_START = 4;
|
|
17
|
+
const ease = Easing.bezier(CSS_EASE.x1, CSS_EASE.y1, CSS_EASE.x2, CSS_EASE.y2);
|
|
18
|
+
export function ToastItem({ toast, active, onDismiss, narrow, memory }) {
|
|
19
|
+
const t = useTokens();
|
|
20
|
+
const words = useUILabels();
|
|
21
|
+
const { id, type = 'default', message, autoClose = 5000, hideProgressBar = false, closeOnClick = true, pauseOnFocusLoss = true, draggable = true, closeButton = true, icon, style, testID, } = toast;
|
|
22
|
+
const look = toastLook(t, type, narrow);
|
|
23
|
+
const reduced = t.motionScale === 0;
|
|
24
|
+
const [held, setHeld] = useState(false);
|
|
25
|
+
const [dragging, setDragging] = useState(false);
|
|
26
|
+
const [leaving, setLeaving] = useState(false);
|
|
27
|
+
const full = typeof autoClose === 'number' ? autoClose : 0;
|
|
28
|
+
const kept = useRef(leftOf(memory?.get(id))).current;
|
|
29
|
+
const enter = useRef(new Animated.Value(reduced || kept !== undefined ? 1 : 0)).current;
|
|
30
|
+
const exit = useRef(new Animated.Value(1)).current;
|
|
31
|
+
const drag = useRef(new Animated.Value(0)).current;
|
|
32
|
+
const bar = useRef(new Animated.Value(kept !== undefined && full > 0 ? Math.max(0, kept) / full : 1)).current;
|
|
33
|
+
const timer = useRef(null);
|
|
34
|
+
const remaining = useRef(kept ?? full);
|
|
35
|
+
const startedAt = useRef(0);
|
|
36
|
+
const keep = (since = null) => memory?.set(id, { left: remaining.current, since });
|
|
37
|
+
const paused = held || dragging || (pauseOnFocusLoss && !active);
|
|
38
|
+
const close = useCallback(() => {
|
|
39
|
+
if (leaving)
|
|
40
|
+
return;
|
|
41
|
+
setLeaving(true);
|
|
42
|
+
toast.onClose?.();
|
|
43
|
+
Animated.timing(exit, { toValue: 0, duration: TOAST_EXIT_MS * t.motionScale, easing: ease, useNativeDriver: true })
|
|
44
|
+
.start(() => onDismiss(id));
|
|
45
|
+
}, [leaving, toast, exit, t.motionScale, onDismiss, id]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
keep();
|
|
48
|
+
if (kept !== undefined)
|
|
49
|
+
return;
|
|
50
|
+
Animated.timing(enter, { toValue: 1, duration: t.transitionBase * t.motionScale, easing: ease, useNativeDriver: true }).start();
|
|
51
|
+
if (typeof message === 'string')
|
|
52
|
+
AccessibilityInfo.announceForAccessibility(message);
|
|
53
|
+
}, []);
|
|
54
|
+
const shownAs = useRef({ message, autoClose });
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (shownAs.current.message === message && shownAs.current.autoClose === autoClose)
|
|
57
|
+
return;
|
|
58
|
+
shownAs.current = { message, autoClose };
|
|
59
|
+
remaining.current = full;
|
|
60
|
+
bar.setValue(1);
|
|
61
|
+
keep();
|
|
62
|
+
}, [message, autoClose]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (autoClose === false || leaving || paused)
|
|
65
|
+
return;
|
|
66
|
+
startedAt.current = Date.now();
|
|
67
|
+
keep(startedAt.current);
|
|
68
|
+
const left = Math.max(0, remaining.current);
|
|
69
|
+
timer.current = setTimeout(close, left);
|
|
70
|
+
const run = reduced ? null : Animated.timing(bar, { toValue: 0, duration: left, easing: Easing.linear, useNativeDriver: true });
|
|
71
|
+
run?.start();
|
|
72
|
+
return () => {
|
|
73
|
+
if (timer.current)
|
|
74
|
+
clearTimeout(timer.current);
|
|
75
|
+
timer.current = null;
|
|
76
|
+
remaining.current -= Date.now() - startedAt.current;
|
|
77
|
+
keep();
|
|
78
|
+
run?.stop();
|
|
79
|
+
};
|
|
80
|
+
}, [paused, autoClose, leaving, close, message, reduced]);
|
|
81
|
+
const pan = useMemo(() => PanResponder.create({
|
|
82
|
+
onMoveShouldSetPanResponder: (_, g) => draggable && Math.abs(g.dx) > SWIPE_START && Math.abs(g.dx) > Math.abs(g.dy),
|
|
83
|
+
onPanResponderGrant: () => setDragging(true),
|
|
84
|
+
onPanResponderMove: (_, g) => drag.setValue(g.dx),
|
|
85
|
+
onPanResponderRelease: (_, g) => {
|
|
86
|
+
setDragging(false);
|
|
87
|
+
if (Math.abs(g.dx) > TOAST_SWIPE_DISMISS)
|
|
88
|
+
close();
|
|
89
|
+
else
|
|
90
|
+
Animated.spring(drag, { toValue: 0, useNativeDriver: true }).start();
|
|
91
|
+
},
|
|
92
|
+
onPanResponderTerminate: () => {
|
|
93
|
+
setDragging(false);
|
|
94
|
+
Animated.spring(drag, { toValue: 0, useNativeDriver: true }).start();
|
|
95
|
+
},
|
|
96
|
+
}), [draggable, drag, close]);
|
|
97
|
+
const urgent = type === 'error' || type === 'warning';
|
|
98
|
+
const Glyph = ICONS[type];
|
|
99
|
+
const shownIcon = icon === false ? null : icon ?? (Glyph ? _jsx(Glyph, {}) : null);
|
|
100
|
+
const fade = drag.interpolate({ inputRange: [-TOAST_SWIPE_FADE, 0, TOAST_SWIPE_FADE], outputRange: [0, 1, 0], extrapolate: 'clamp' });
|
|
101
|
+
return (_jsxs(Animated.View, { testID: testID, role: urgent ? 'alert' : 'status', accessibilityLiveRegion: urgent ? 'assertive' : 'polite', style: [
|
|
102
|
+
look.toast,
|
|
103
|
+
style,
|
|
104
|
+
{
|
|
105
|
+
opacity: Animated.multiply(Animated.multiply(enter, exit), fade),
|
|
106
|
+
transform: [
|
|
107
|
+
{ translateX: drag },
|
|
108
|
+
{ translateY: enter.interpolate({ inputRange: [0, 1], outputRange: [-TOAST_ENTER_OFFSET, 0] }) },
|
|
109
|
+
{ scale: enter.interpolate({ inputRange: [0, 1], outputRange: [TOAST_MOTION_SCALE, 1] }) },
|
|
110
|
+
{ scale: exit.interpolate({ inputRange: [0, 1], outputRange: [TOAST_MOTION_SCALE, 1] }) },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
], ...pan.panHandlers, children: [_jsx(View, { style: look.rail }), _jsxs(Pressable, { accessible: false, style: { flex: 1, flexDirection: 'row', alignItems: 'flex-start', gap: t.spacingMd }, onPress: closeOnClick ? close : undefined, onLongPress: () => { }, onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), children: [shownIcon && (_jsx(View, { style: look.icon, children: _jsx(IconSlotContext.Provider, { value: { size: look.iconSize, color: look.accent }, children: shownIcon }) })), _jsx(View, { style: look.body, children: typeof message === 'string' || typeof message === 'number' ? _jsx(Text, { style: look.text, children: message }) : message })] }), closeButton !== false && (_jsx(Pressable, { role: "button", "aria-label": words.toast.dismiss, onPress: close, onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), style: ({ pressed }) => [look.close, pressed && look.closePressed], children: ({ pressed }) => (_jsx(IconSlotContext.Provider, { value: { size: look.closeIconSize, color: pressed ? look.closePressedColor : look.closeColor }, children: closeButton === true ? _jsx(IconClose, {}) : closeButton })) })), !hideProgressBar && typeof autoClose === 'number' && !leaving && (_jsx(Animated.View, { testID: testID ? `${testID}-progress` : undefined, style: [look.progress, { transform: [{ scaleX: bar }] }] }))] }));
|
|
114
|
+
}
|
|
115
|
+
ToastItem.displayName = 'ToastItem';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
import { StyleSheet, View, useWindowDimensions } from 'react-native';
|
|
4
|
+
import { SafeAreaInsetsContext, initialWindowMetrics } from 'react-native-safe-area-context';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { NO_INSETS } from '../Dialog/dialogStyle';
|
|
7
|
+
import { TOAST_NARROW_BELOW } from '../styles/webValues';
|
|
8
|
+
import { ToastItem } from './ToastItem';
|
|
9
|
+
import { toastRegionLook } from './toastStyle';
|
|
10
|
+
export const ToastLayerContext = createContext(null);
|
|
11
|
+
export function ToastLayer() {
|
|
12
|
+
const layer = useContext(ToastLayerContext);
|
|
13
|
+
const measured = useContext(SafeAreaInsetsContext);
|
|
14
|
+
const t = useTokens();
|
|
15
|
+
const { width } = useWindowDimensions();
|
|
16
|
+
if (!layer || layer.regions.length === 0)
|
|
17
|
+
return null;
|
|
18
|
+
const narrow = width < TOAST_NARROW_BELOW;
|
|
19
|
+
const insets = measured ?? initialWindowMetrics?.insets ?? NO_INSETS;
|
|
20
|
+
return (_jsx(View, { style: [StyleSheet.absoluteFill, { zIndex: t.zToast }], pointerEvents: "box-none", children: layer.regions.map(([position, list]) => (_jsx(View, { pointerEvents: "box-none", style: toastRegionLook(t, position, narrow, insets), children: list.map(r => _jsx(ToastItem, { toast: r, active: layer.active, onDismiss: layer.dismiss, narrow: narrow, memory: layer.memory }, r.id)) }, position))) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { boxShadow } from '../Button/buttonStyle';
|
|
2
|
+
import { TOAST_ICON_NUDGE, TOAST_LINE_HEIGHT, TOAST_PROGRESS_HEIGHT, TOAST_PROGRESS_OPACITY, TOAST_RAIL_WIDTH, TOAST_WIDTH, } from '../styles/webValues';
|
|
3
|
+
export function toastAccent(t, type) {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case 'success': return t.success;
|
|
6
|
+
case 'error': return t.error;
|
|
7
|
+
case 'warning': return t.warning;
|
|
8
|
+
case 'info': return t.info;
|
|
9
|
+
default: return t.textSecondary;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function toastLook(t, type, narrow) {
|
|
13
|
+
const accent = toastAccent(t, type);
|
|
14
|
+
return {
|
|
15
|
+
toast: {
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
alignItems: 'flex-start',
|
|
18
|
+
gap: t.spacingMd,
|
|
19
|
+
...(narrow ? { alignSelf: 'stretch' } : { width: TOAST_WIDTH, maxWidth: '100%' }),
|
|
20
|
+
padding: t.spacingLg,
|
|
21
|
+
borderRadius: t.borderRadiusSm,
|
|
22
|
+
borderWidth: 1,
|
|
23
|
+
borderColor: t.cardBorder,
|
|
24
|
+
backgroundColor: t.cardBg,
|
|
25
|
+
boxShadow: boxShadow(t.shadowLg),
|
|
26
|
+
overflow: 'hidden',
|
|
27
|
+
},
|
|
28
|
+
rail: { position: 'absolute', top: 0, bottom: 0, left: 0, width: TOAST_RAIL_WIDTH, backgroundColor: accent },
|
|
29
|
+
icon: { flexShrink: 0, alignItems: 'center', justifyContent: 'center', marginTop: TOAST_ICON_NUDGE },
|
|
30
|
+
iconSize: t.iconSlotDefault,
|
|
31
|
+
accent,
|
|
32
|
+
body: { flex: 1, minWidth: 0 },
|
|
33
|
+
text: { color: t.textPrimary, fontSize: t.fontSizeMd, lineHeight: Math.round(t.fontSizeMd * TOAST_LINE_HEIGHT) },
|
|
34
|
+
close: {
|
|
35
|
+
flexShrink: 0,
|
|
36
|
+
width: t.fieldHeightXxs,
|
|
37
|
+
height: t.fieldHeightXxs,
|
|
38
|
+
borderRadius: t.borderRadiusSm,
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
},
|
|
42
|
+
closePressed: { backgroundColor: t.bgTertiary },
|
|
43
|
+
closeIconSize: t.iconSlotButton,
|
|
44
|
+
closeColor: t.textTertiary,
|
|
45
|
+
closePressedColor: t.textPrimary,
|
|
46
|
+
progress: {
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
left: 0,
|
|
49
|
+
bottom: 0,
|
|
50
|
+
width: '100%',
|
|
51
|
+
height: TOAST_PROGRESS_HEIGHT,
|
|
52
|
+
backgroundColor: accent,
|
|
53
|
+
opacity: TOAST_PROGRESS_OPACITY,
|
|
54
|
+
transformOrigin: 'left',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function toastRegionLook(t, position, narrow, insets) {
|
|
59
|
+
const pad = narrow ? t.spacingMd : t.spacingXl;
|
|
60
|
+
const bottom = position.startsWith('bottom');
|
|
61
|
+
const side = position.endsWith('left') ? 'flex-start' : position.endsWith('right') ? 'flex-end' : 'center';
|
|
62
|
+
return {
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
left: 0,
|
|
65
|
+
right: 0,
|
|
66
|
+
...(bottom ? { bottom: 0, paddingBottom: pad + insets.bottom } : { top: 0, paddingTop: pad + insets.top }),
|
|
67
|
+
paddingLeft: pad + insets.left,
|
|
68
|
+
paddingRight: pad + insets.right,
|
|
69
|
+
flexDirection: bottom ? 'column-reverse' : 'column',
|
|
70
|
+
alignItems: narrow ? 'stretch' : side,
|
|
71
|
+
gap: t.spacingMd,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import { useTokens } from '../UIProvider/context';
|
|
4
|
+
import { FieldWrapper } from '../FieldWrapper/FieldWrapper';
|
|
5
|
+
import { toggleLabelStyle, toggleRequiredStyle, toggleRowStyle } from '../styles/toggle';
|
|
6
|
+
import { usePressHold } from '../Press';
|
|
7
|
+
const present = (node) => node !== undefined && node !== null && node !== false && node !== '';
|
|
8
|
+
const asString = (node) => (typeof node === 'string' ? node : undefined);
|
|
9
|
+
export function ToggleField(p) {
|
|
10
|
+
const t = useTokens();
|
|
11
|
+
const error = present(p.error);
|
|
12
|
+
const row = { labelPosition: p.labelPosition, disabled: p.disabled, error, fullWidth: !!p.fullWidth };
|
|
13
|
+
const label = toggleLabelStyle(t, p.size, row, p.rowLine);
|
|
14
|
+
const inactive = p.disabled || p.readOnly || !!p.busy;
|
|
15
|
+
const hold = usePressHold(!inactive);
|
|
16
|
+
return (_jsx(FieldWrapper, { layout: p.layout, size: p.size, error: p.error, hint: p.hint, disabled: p.disabled, style: p.style, children: _jsx(Pressable, { testID: p.testID, role: p.role, "aria-checked": p.checked, "aria-label": p['aria-label'] ?? asString(p.label), accessibilityHint: asString(error ? p.error : p.hint), accessibilityState: { disabled: p.disabled, busy: !!p.busy }, disabled: p.disabled, onPress: inactive ? undefined : p.onToggle, onPressIn: e => { hold.onPressIn(); if (!inactive)
|
|
17
|
+
p.ripple?.onPressIn(e); }, onPressOut: () => { hold.onPressOut(); p.ripple?.onPressOut(); }, style: toggleRowStyle(row), children: (_jsxs(_Fragment, { children: [p.renderControl(hold.pressed), p.renderLabels
|
|
18
|
+
? p.renderLabels(label)
|
|
19
|
+
: present(p.label) && (_jsx(View, { style: label.box, children: _jsxs(Text, { style: label.text, children: [p.label, p.required && _jsx(Text, { style: toggleRequiredStyle(t), children: ' *' })] }) }))] })) }) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export function ToggleGroupFrame({ role, label, required, helper, error, disabled, orientation, style, 'aria-label': ariaLabel, children }) {
|
|
5
|
+
const t = useTokens();
|
|
6
|
+
const horizontal = orientation === 'horizontal';
|
|
7
|
+
const message = error || helper;
|
|
8
|
+
const flow = horizontal ? { flexDirection: 'row', flexWrap: 'wrap', gap: t.spacingXl } : { flexDirection: 'column', gap: t.spacingMd };
|
|
9
|
+
return (_jsxs(View, { role: role, "aria-label": ariaLabel ?? (typeof label === 'string' ? label : undefined), style: [flow, style], children: [label !== undefined && label !== null && label !== '' && (_jsxs(Text, { style: { fontSize: t.fontSizeMd, fontWeight: String(t.fontWeightMedium), color: disabled ? t.textTertiary : t.textPrimary, marginBottom: t.spacingMd }, children: [label, required && _jsx(Text, { style: { color: t.errorText, fontWeight: String(t.fontWeightSemibold) }, children: ' *' })] })), _jsx(View, { style: flow, children: children }), message ? (_jsx(Text, { style: { fontSize: t.fontSizeXs, color: error ? t.errorText : t.textSecondary, marginTop: t.spacingXs }, children: message })) : null] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from 'react';
|
|
3
|
+
import { IconProvider } from '../Icon/IconContext';
|
|
4
|
+
import { DialogOpenProvider } from '../Dialog/Dialog';
|
|
5
|
+
import { DialogHost } from '../Dialog/DialogHost';
|
|
6
|
+
import { ToastHost } from '../Toast/ToastHost';
|
|
7
|
+
import { LabelsContext, ThemeContext, resolveLabelsState } from './context';
|
|
8
|
+
export { useTokens, useUIDateFormat, useUILabels, useUILocale } from './context';
|
|
9
|
+
export const UIProvider = ({ children, theme = 'system', icons, labels, messages, locale, dateFormat, toast }) => {
|
|
10
|
+
const parent = useContext(LabelsContext);
|
|
11
|
+
const words = useMemo(() => resolveLabelsState(parent, labels, messages, locale, dateFormat), [parent, labels, messages, locale, dateFormat]);
|
|
12
|
+
return (_jsx(ThemeContext.Provider, { value: theme, children: _jsx(LabelsContext.Provider, { value: words, children: _jsx(IconProvider, { ...icons, children: _jsx(DialogOpenProvider, { children: _jsx(ToastHost, { defaults: toast, children: _jsx(DialogHost, { children: children }) }) }) }) }) }));
|
|
13
|
+
};
|
|
14
|
+
UIProvider.displayName = 'UIProvider';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
+
import { AccessibilityInfo, useColorScheme } from 'react-native';
|
|
3
|
+
import { dark, light, reducedMotion } from '@dcs-tech/tokens';
|
|
4
|
+
import { DEFAULT_UI_LABELS, localeMessages, mergeLabels } from '@dcs-tech/core';
|
|
5
|
+
export const ThemeContext = createContext('system');
|
|
6
|
+
export const LabelsContext = createContext({ value: DEFAULT_UI_LABELS, labels: undefined, packs: [], locale: undefined });
|
|
7
|
+
export function resolveLabelsState(parent, labels, messages, locale, dateFormat) {
|
|
8
|
+
const allLabels = labels ? (parent.labels ? mergeLabels(parent.labels, labels) : labels) : parent.labels;
|
|
9
|
+
const packs = messages?.length ? [...parent.packs, ...messages] : parent.packs;
|
|
10
|
+
const wordsLocale = locale ?? parent.locale;
|
|
11
|
+
const pack = localeMessages(packs, wordsLocale);
|
|
12
|
+
const value = mergeLabels(mergeLabels(DEFAULT_UI_LABELS, pack), allLabels);
|
|
13
|
+
return { value, labels: allLabels, packs, locale: wordsLocale, dateFormat: dateFormat ?? parent.dateFormat };
|
|
14
|
+
}
|
|
15
|
+
export const useUILabels = () => useContext(LabelsContext).value;
|
|
16
|
+
export const useUILocale = () => useContext(LabelsContext).locale;
|
|
17
|
+
export const useUIDateFormat = () => useContext(LabelsContext).dateFormat;
|
|
18
|
+
const reduceMotion = (() => {
|
|
19
|
+
let value = false;
|
|
20
|
+
const listeners = new Set();
|
|
21
|
+
let stop;
|
|
22
|
+
const set = (on) => {
|
|
23
|
+
if (on === value)
|
|
24
|
+
return;
|
|
25
|
+
value = on;
|
|
26
|
+
listeners.forEach(l => l());
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
get: () => value,
|
|
30
|
+
subscribe(listener) {
|
|
31
|
+
listeners.add(listener);
|
|
32
|
+
if (!stop) {
|
|
33
|
+
const sub = AccessibilityInfo.addEventListener('reduceMotionChanged', set);
|
|
34
|
+
let live = true;
|
|
35
|
+
AccessibilityInfo.isReduceMotionEnabled().then(on => { if (live)
|
|
36
|
+
set(on); }, () => { });
|
|
37
|
+
stop = () => { live = false; sub.remove(); };
|
|
38
|
+
}
|
|
39
|
+
return () => {
|
|
40
|
+
listeners.delete(listener);
|
|
41
|
+
if (listeners.size === 0 && stop) {
|
|
42
|
+
stop();
|
|
43
|
+
stop = undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
export function useTokens() {
|
|
50
|
+
const theme = useContext(ThemeContext);
|
|
51
|
+
const system = useColorScheme();
|
|
52
|
+
const reduce = useSyncExternalStore(reduceMotion.subscribe, reduceMotion.get);
|
|
53
|
+
const scheme = theme === 'system' ? (system === 'dark' ? 'dark' : 'light') : theme;
|
|
54
|
+
return useMemo(() => {
|
|
55
|
+
const base = scheme === 'dark' ? dark : light;
|
|
56
|
+
return reduce ? { ...base, ...reducedMotion } : base;
|
|
57
|
+
}, [scheme, reduce]);
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UIProvider, useTokens, useUIDateFormat, useUILabels, useUILocale } from './UIProvider';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function parseHex(color) {
|
|
2
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color)?.[1];
|
|
3
|
+
if (!hex)
|
|
4
|
+
return null;
|
|
5
|
+
const full = hex.length === 3 ? [...hex].map(c => c + c).join('') : hex;
|
|
6
|
+
const n = parseInt(full, 16);
|
|
7
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
8
|
+
}
|
|
9
|
+
const toHex = ([r, g, b]) => '#' + [r, g, b].map(v => Math.round(Math.min(255, Math.max(0, v))).toString(16).padStart(2, '0')).join('');
|
|
10
|
+
export function mixColors(a, percent, b) {
|
|
11
|
+
const x = parseHex(a);
|
|
12
|
+
const y = parseHex(b);
|
|
13
|
+
if (!x || !y)
|
|
14
|
+
return a;
|
|
15
|
+
const p = percent / 100;
|
|
16
|
+
return toHex([x[0] * p + y[0] * (1 - p), x[1] * p + y[1] * (1 - p), x[2] * p + y[2] * (1 - p)]);
|
|
17
|
+
}
|
|
18
|
+
export function oklchToHex(l, c, h) {
|
|
19
|
+
const rad = (h * Math.PI) / 180;
|
|
20
|
+
const A = c * Math.cos(rad);
|
|
21
|
+
const B = c * Math.sin(rad);
|
|
22
|
+
const l_ = (l + 0.3963377774 * A + 0.2158037573 * B) ** 3;
|
|
23
|
+
const m_ = (l - 0.1055613458 * A - 0.0638541728 * B) ** 3;
|
|
24
|
+
const s_ = (l - 0.0894841775 * A - 1.291485548 * B) ** 3;
|
|
25
|
+
const linear = [
|
|
26
|
+
4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
|
|
27
|
+
-1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
|
|
28
|
+
-0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_,
|
|
29
|
+
];
|
|
30
|
+
const gamma = (v) => {
|
|
31
|
+
const x = Math.min(1, Math.max(0, v));
|
|
32
|
+
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055);
|
|
33
|
+
};
|
|
34
|
+
return toHex([gamma(linear[0]), gamma(linear[1]), gamma(linear[2])]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export function fieldSize(t, size) {
|
|
2
|
+
switch (size) {
|
|
3
|
+
case 'xxs': return { height: t.fieldHeightXxs, padY: t.fieldPaddingYXxs, padX: t.fieldPaddingXXxs, fontSize: t.fontSizeXxs };
|
|
4
|
+
case 'xs': return { height: t.fieldHeightXs, padY: t.fieldPaddingYXs, padX: t.fieldPaddingXXs, fontSize: t.fontSizeXs };
|
|
5
|
+
case 'small': return { height: t.fieldHeightSm, padY: t.fieldPaddingYSm, padX: t.fieldPaddingXSm, fontSize: t.fontSizeSm };
|
|
6
|
+
case 'medium': return { height: t.fieldHeightMd, padY: t.fieldPaddingYMd, padX: t.fieldPaddingXMd, fontSize: t.fontSizeMd };
|
|
7
|
+
case 'large': return { height: t.fieldHeightLg, padY: t.fieldPaddingYLg, padX: t.fieldPaddingXLg, fontSize: t.fontSizeLg };
|
|
8
|
+
case 'xl': return { height: t.fieldHeightXl, padY: t.fieldPaddingYXl, padX: t.fieldPaddingXXl, fontSize: t.fontSizeXl };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const halo = (t, color) => [{ offsetX: 0, offsetY: 0, blurRadius: 0, spreadDistance: t.focusHaloWidth, color }];
|
|
12
|
+
export function fieldControlLook(t, s) {
|
|
13
|
+
const z = fieldSize(t, s.size);
|
|
14
|
+
const focused = s.focused && !s.disabled;
|
|
15
|
+
let background = t.bgSecondary;
|
|
16
|
+
let edge = { width: 1, bottomWidth: 1, color: t.borderColor, bottomColor: t.borderColor };
|
|
17
|
+
let radius = t.borderRadiusSm;
|
|
18
|
+
let color = t.textPrimary;
|
|
19
|
+
let shadow;
|
|
20
|
+
let padLeft = z.padX;
|
|
21
|
+
const setColor = (c) => { edge = { ...edge, color: c, bottomColor: c }; };
|
|
22
|
+
if (focused) {
|
|
23
|
+
setColor(t.accentPrimary);
|
|
24
|
+
shadow = halo(t, t.accentPrimaryLight);
|
|
25
|
+
}
|
|
26
|
+
if (s.error) {
|
|
27
|
+
setColor(t.error);
|
|
28
|
+
if (focused)
|
|
29
|
+
shadow = halo(t, t.errorLight);
|
|
30
|
+
}
|
|
31
|
+
if (s.disabled) {
|
|
32
|
+
background = t.disabledBg;
|
|
33
|
+
setColor(t.disabledBorder);
|
|
34
|
+
color = t.disabledText;
|
|
35
|
+
}
|
|
36
|
+
if (s.readOnly)
|
|
37
|
+
background = t.bgTertiary;
|
|
38
|
+
switch (s.variant) {
|
|
39
|
+
case 'outlined':
|
|
40
|
+
background = t.bgSecondary;
|
|
41
|
+
break;
|
|
42
|
+
case 'filled':
|
|
43
|
+
background = t.bgTertiary;
|
|
44
|
+
if (!focused)
|
|
45
|
+
setColor('transparent');
|
|
46
|
+
if (s.error) {
|
|
47
|
+
background = t.errorLight;
|
|
48
|
+
setColor(t.error);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'standard':
|
|
52
|
+
case 'underlined':
|
|
53
|
+
padLeft = 0;
|
|
54
|
+
background = 'transparent';
|
|
55
|
+
edge = { width: 0, bottomWidth: 1, color: 'transparent', bottomColor: t.borderColor };
|
|
56
|
+
radius = 0;
|
|
57
|
+
if (focused) {
|
|
58
|
+
edge = { ...edge, bottomWidth: 2, bottomColor: t.accentPrimary };
|
|
59
|
+
shadow = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (s.error)
|
|
62
|
+
edge = { ...edge, bottomColor: t.error };
|
|
63
|
+
break;
|
|
64
|
+
case 'cell':
|
|
65
|
+
edge = { width: 0, bottomWidth: 0, color: 'transparent', bottomColor: 'transparent' };
|
|
66
|
+
radius = 0;
|
|
67
|
+
background = 'transparent';
|
|
68
|
+
shadow = undefined;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const box = {
|
|
72
|
+
flexDirection: 'row',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
gap: t.spacingMd,
|
|
75
|
+
width: '100%',
|
|
76
|
+
minHeight: z.height,
|
|
77
|
+
paddingVertical: z.padY,
|
|
78
|
+
paddingRight: z.padX,
|
|
79
|
+
paddingLeft: padLeft,
|
|
80
|
+
backgroundColor: background,
|
|
81
|
+
borderRadius: radius,
|
|
82
|
+
borderTopWidth: edge.width,
|
|
83
|
+
borderLeftWidth: edge.width,
|
|
84
|
+
borderRightWidth: edge.width,
|
|
85
|
+
borderBottomWidth: edge.bottomWidth,
|
|
86
|
+
borderTopColor: edge.color,
|
|
87
|
+
borderLeftColor: edge.color,
|
|
88
|
+
borderRightColor: edge.color,
|
|
89
|
+
borderBottomColor: edge.bottomColor,
|
|
90
|
+
...(s.variant === 'cell' ? { height: '100%' } : {}),
|
|
91
|
+
...(shadow ? { boxShadow: shadow } : {}),
|
|
92
|
+
};
|
|
93
|
+
const text = {
|
|
94
|
+
flex: 1,
|
|
95
|
+
minWidth: 0,
|
|
96
|
+
margin: 0,
|
|
97
|
+
padding: 0,
|
|
98
|
+
fontSize: z.fontSize,
|
|
99
|
+
color,
|
|
100
|
+
};
|
|
101
|
+
return { box, text, placeholderColor: t.textTertiary, color, fontSize: z.fontSize };
|
|
102
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { CAPS_LETTER_SPACING, POPUP_DISABLED_ROW_OPACITY, SUGGEST_SECONDARY_LINE_HEIGHT } from './webValues';
|
|
2
|
+
export function popupSize(t, size) {
|
|
3
|
+
switch (size) {
|
|
4
|
+
case 'xxs': return { padY: t.fieldPaddingYXxs, padX: t.fieldPaddingXXxs, primary: t.fontSizeXxs, secondary: t.fontSizeXxs, tertiary: t.fontSizeXxs };
|
|
5
|
+
case 'xs': return { padY: t.fieldPaddingYXxs, padX: t.fieldPaddingXXs, primary: t.fontSizeXs, secondary: t.fontSizeXxs, tertiary: t.fontSizeXxs };
|
|
6
|
+
case 'small': return { padY: t.fieldPaddingYXs, padX: t.fieldPaddingXSm, primary: t.fontSizeSm, secondary: t.fontSizeXs, tertiary: t.fontSizeXxs };
|
|
7
|
+
case 'medium': return { padY: t.fieldPaddingYSm, padX: t.fieldPaddingXMd, primary: t.fontSizeMd, secondary: t.fontSizeSm, tertiary: t.fontSizeXs };
|
|
8
|
+
case 'large': return { padY: t.fieldPaddingYMd, padX: t.fieldPaddingXLg, primary: t.fontSizeLg, secondary: t.fontSizeMd, tertiary: t.fontSizeSm };
|
|
9
|
+
case 'xl': return { padY: t.fieldPaddingYLg, padX: t.fieldPaddingXXl, primary: t.fontSizeXl, secondary: t.fontSizeLg, tertiary: t.fontSizeMd };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function popupRowLook(t, s) {
|
|
13
|
+
const z = popupSize(t, s.size);
|
|
14
|
+
let background = 'transparent';
|
|
15
|
+
if (s.pressed && !s.selected && !s.disabled)
|
|
16
|
+
background = t.bgTertiary;
|
|
17
|
+
if (s.selected)
|
|
18
|
+
background = t.accentPrimaryLight;
|
|
19
|
+
const color = s.disabled ? t.textTertiary : s.selected ? t.accentPrimaryText : t.textPrimary;
|
|
20
|
+
return {
|
|
21
|
+
row: {
|
|
22
|
+
flexDirection: 'row',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
gap: t.spacingMd,
|
|
25
|
+
paddingVertical: z.padY,
|
|
26
|
+
paddingHorizontal: z.padX,
|
|
27
|
+
backgroundColor: background,
|
|
28
|
+
...(s.disabled ? { opacity: POPUP_DISABLED_ROW_OPACITY } : {}),
|
|
29
|
+
},
|
|
30
|
+
text: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
fontSize: z.primary,
|
|
33
|
+
lineHeight: Math.round(z.primary * t.lineHeightNormal),
|
|
34
|
+
color,
|
|
35
|
+
...(s.selected ? { fontWeight: String(t.fontWeightMedium) } : {}),
|
|
36
|
+
},
|
|
37
|
+
tickColor: color,
|
|
38
|
+
tickSize: t.iconSlotNav,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function popupMarkStyle(t, selected) {
|
|
42
|
+
return selected
|
|
43
|
+
? { fontWeight: String(t.fontWeightBold) }
|
|
44
|
+
: { backgroundColor: t.accentPrimaryLight, color: t.accentPrimaryText, fontWeight: String(t.fontWeightSemibold) };
|
|
45
|
+
}
|
|
46
|
+
export function popupGroupHeaderStyle(t, size) {
|
|
47
|
+
return {
|
|
48
|
+
box: {
|
|
49
|
+
paddingTop: t.spacingMd,
|
|
50
|
+
paddingBottom: t.spacingXs,
|
|
51
|
+
paddingHorizontal: popupSize(t, size).padX,
|
|
52
|
+
backgroundColor: t.bgTertiary,
|
|
53
|
+
borderBottomWidth: 1,
|
|
54
|
+
borderBottomColor: t.borderColor,
|
|
55
|
+
},
|
|
56
|
+
text: {
|
|
57
|
+
fontSize: t.fontSizeXs,
|
|
58
|
+
fontWeight: String(t.fontWeightSemibold),
|
|
59
|
+
color: t.textSecondary,
|
|
60
|
+
textTransform: 'uppercase',
|
|
61
|
+
letterSpacing: CAPS_LETTER_SPACING,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function popupMessageStyle(t, size, empty) {
|
|
66
|
+
const z = popupSize(t, size);
|
|
67
|
+
return {
|
|
68
|
+
box: { paddingVertical: t.spacingXl, paddingHorizontal: z.padX, alignItems: 'center', gap: t.spacingMd },
|
|
69
|
+
text: { textAlign: 'center', color: t.textSecondary, fontSize: z.primary, ...(empty ? { fontStyle: 'italic' } : {}) },
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function suggestLineStyles(t, size) {
|
|
73
|
+
const z = popupSize(t, size);
|
|
74
|
+
return {
|
|
75
|
+
primary: {
|
|
76
|
+
line: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: t.spacingMd },
|
|
77
|
+
text: { fontSize: z.primary, lineHeight: Math.round(z.primary * t.lineHeightSnug), fontWeight: String(t.fontWeightMedium), color: t.textPrimary },
|
|
78
|
+
},
|
|
79
|
+
secondary: {
|
|
80
|
+
line: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: t.spacingLg },
|
|
81
|
+
text: { fontSize: z.secondary, lineHeight: Math.round(z.secondary * SUGGEST_SECONDARY_LINE_HEIGHT), color: t.textSecondary },
|
|
82
|
+
},
|
|
83
|
+
tertiary: {
|
|
84
|
+
line: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: t.spacingMd },
|
|
85
|
+
chip: { paddingVertical: t.spacingXxs, paddingHorizontal: t.spacingSm, backgroundColor: t.bgTertiary, borderRadius: t.borderRadiusSm },
|
|
86
|
+
text: { fontSize: z.tertiary, lineHeight: Math.round(z.tertiary * t.lineHeightTight), color: t.textTertiary },
|
|
87
|
+
},
|
|
88
|
+
label: { fontWeight: String(t.fontWeightSemibold) },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function suggestPopupStyle(t, maxHeight) {
|
|
92
|
+
return {
|
|
93
|
+
marginTop: t.spacingXs,
|
|
94
|
+
maxHeight,
|
|
95
|
+
backgroundColor: t.bgSecondary,
|
|
96
|
+
borderWidth: 1,
|
|
97
|
+
borderColor: t.accentPrimary,
|
|
98
|
+
borderRadius: t.borderRadius,
|
|
99
|
+
overflow: 'hidden',
|
|
100
|
+
boxShadow: [...t.shadowLg].map(s => ({ offsetX: s.offsetX, offsetY: s.offsetY, blurRadius: s.blur, spreadDistance: s.spread, color: s.color, inset: s.inset })),
|
|
101
|
+
};
|
|
102
|
+
}
|