@dcs-tech/ui-native 0.0.0-stage → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -0
- package/README.md +178 -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 +48 -0
- package/dist/components/DataTable/filters/FilterGroupEditor.js +21 -0
- package/dist/components/DataTable/filters/FilterSheet.js +67 -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 +328 -0
- package/dist/components/DatePicker/Calendar.js +28 -0
- package/dist/components/DatePicker/DatePicker.js +296 -0
- package/dist/components/DatePicker/PeriodGrid.js +17 -0
- package/dist/components/DatePicker/PeriodPicker.js +213 -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 +239 -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 +57 -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 +237 -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 +16 -0
- package/dist/types/components/UIProvider/context.d.ts +20 -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,157 @@
|
|
|
1
|
+
import { DP_CELL_EM, DP_DAY_FONT_EM, DP_PERIOD_DOT_BOTTOM_EM, DP_PERIOD_ROW_EM, DP_ENTRY_LABEL_EM, DP_ENTRY_LABEL_LETTER_SPACING_EM, DP_NAV_ICON_RATIO, DP_ROW_EM, DP_SMALL_TEXT_EM, DP_TIME_COLS_HEIGHT_EM, DP_TIME_OPT_RADIUS, DP_TODAY_DOT, DP_TODAY_DOT_BOTTOM_EM, DP_WEEKDAY_FONT_EM, DP_WEEKDAY_HEIGHT_EM, DP_WEEKDAY_LETTER_SPACING_EM, } from '../styles/webValues';
|
|
2
|
+
const fw = (w) => String(w);
|
|
3
|
+
export function calendarSize(fontSize, width) {
|
|
4
|
+
const row = 2 * Math.round((fontSize * DP_ROW_EM) / 2);
|
|
5
|
+
const cell = width > 0 ? Math.min(Math.round(fontSize * DP_CELL_EM), Math.floor(width / 7)) : Math.round(fontSize * DP_CELL_EM);
|
|
6
|
+
return { row, cell: Math.max(cell, row) };
|
|
7
|
+
}
|
|
8
|
+
export function dayLook(t, fontSize, size, s) {
|
|
9
|
+
const { row, cell } = size;
|
|
10
|
+
const half = row / 2;
|
|
11
|
+
const inset = cell / 2 - half;
|
|
12
|
+
const filled = s.filled && !s.disabled;
|
|
13
|
+
let color = s.inMonth ? t.textPrimary : t.textTertiary;
|
|
14
|
+
if (s.disabled)
|
|
15
|
+
color = t.disabledText;
|
|
16
|
+
if (filled)
|
|
17
|
+
color = t.onPrimary;
|
|
18
|
+
let background = 'transparent';
|
|
19
|
+
if (filled)
|
|
20
|
+
background = s.pressed ? t.accentPrimaryHover : t.accentPrimary;
|
|
21
|
+
let cap;
|
|
22
|
+
if (s.start && !s.end)
|
|
23
|
+
cap = { position: 'absolute', top: 0, bottom: 0, left: inset, right: 0, backgroundColor: t.accentPrimaryLight, borderTopLeftRadius: half, borderBottomLeftRadius: half };
|
|
24
|
+
if (s.end && !s.start)
|
|
25
|
+
cap = { position: 'absolute', top: 0, bottom: 0, left: 0, right: inset, backgroundColor: t.accentPrimaryLight, borderTopRightRadius: half, borderBottomRightRadius: half };
|
|
26
|
+
return {
|
|
27
|
+
cell: { width: cell, height: row, alignItems: 'center', justifyContent: 'center', backgroundColor: s.band ? t.accentPrimaryLight : 'transparent' },
|
|
28
|
+
cap,
|
|
29
|
+
circle: { width: row, height: row, borderRadius: half, alignItems: 'center', justifyContent: 'center', backgroundColor: background },
|
|
30
|
+
tint: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, borderRadius: half, backgroundColor: t.hoverOverlay, opacity: s.pressed && !filled && !s.disabled ? 1 : 0 },
|
|
31
|
+
text: {
|
|
32
|
+
fontSize: fontSize * DP_DAY_FONT_EM,
|
|
33
|
+
color,
|
|
34
|
+
fontWeight: filled ? fw(t.fontWeightSemibold) : undefined,
|
|
35
|
+
fontVariant: ['tabular-nums'],
|
|
36
|
+
},
|
|
37
|
+
dot: s.isToday
|
|
38
|
+
? { position: 'absolute', bottom: fontSize * DP_TODAY_DOT_BOTTOM_EM, width: DP_TODAY_DOT, height: DP_TODAY_DOT, borderRadius: DP_TODAY_DOT / 2, backgroundColor: filled ? t.onPrimary : t.error }
|
|
39
|
+
: undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function panelLook(t, fontSize) {
|
|
43
|
+
const small = fontSize * DP_SMALL_TEXT_EM;
|
|
44
|
+
const nav = t.iconSizeAction * DP_NAV_ICON_RATIO;
|
|
45
|
+
return {
|
|
46
|
+
weekday: {
|
|
47
|
+
height: fontSize * DP_WEEKDAY_HEIGHT_EM,
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
},
|
|
51
|
+
weekdayText: {
|
|
52
|
+
fontSize: fontSize * DP_WEEKDAY_FONT_EM,
|
|
53
|
+
fontWeight: fw(t.fontWeightMedium),
|
|
54
|
+
letterSpacing: fontSize * DP_WEEKDAY_FONT_EM * DP_WEEKDAY_LETTER_SPACING_EM,
|
|
55
|
+
textTransform: 'uppercase',
|
|
56
|
+
color: t.textTertiary,
|
|
57
|
+
},
|
|
58
|
+
head: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXs },
|
|
59
|
+
nav: (pressed) => ({
|
|
60
|
+
width: nav, height: nav, alignItems: 'center', justifyContent: 'center', borderRadius: t.borderRadiusSm,
|
|
61
|
+
backgroundColor: pressed ? t.hoverOverlay : 'transparent',
|
|
62
|
+
}),
|
|
63
|
+
navIcon: t.iconSlotButton,
|
|
64
|
+
jumps: { flex: 1, flexDirection: 'row', justifyContent: 'center', gap: t.spacingXs },
|
|
65
|
+
entryLabel: {
|
|
66
|
+
fontSize: fontSize * DP_ENTRY_LABEL_EM,
|
|
67
|
+
fontWeight: fw(t.fontWeightMedium),
|
|
68
|
+
letterSpacing: fontSize * DP_ENTRY_LABEL_EM * DP_ENTRY_LABEL_LETTER_SPACING_EM,
|
|
69
|
+
textTransform: 'uppercase',
|
|
70
|
+
color: t.textTertiary,
|
|
71
|
+
},
|
|
72
|
+
entries: { flexDirection: 'row', gap: t.spacingSm },
|
|
73
|
+
rail: { flexDirection: 'row', flexWrap: 'wrap', borderTopWidth: 1, borderTopColor: t.borderColor, paddingTop: t.spacingSm },
|
|
74
|
+
preset: (active, pressed) => ({
|
|
75
|
+
width: '50%',
|
|
76
|
+
paddingVertical: t.spacingXs,
|
|
77
|
+
paddingHorizontal: t.spacingMd,
|
|
78
|
+
borderRadius: t.borderRadiusSm,
|
|
79
|
+
backgroundColor: active ? t.accentPrimary : pressed ? t.cardBg : 'transparent',
|
|
80
|
+
}),
|
|
81
|
+
presetText: (active) => ({
|
|
82
|
+
fontSize: small,
|
|
83
|
+
color: active ? t.onPrimary : t.textSecondary,
|
|
84
|
+
fontWeight: active ? fw(t.fontWeightMedium) : undefined,
|
|
85
|
+
}),
|
|
86
|
+
foot: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: t.spacingMd },
|
|
87
|
+
footRead: { flex: 1, minWidth: 0, fontSize: small, color: t.textSecondary, fontVariant: ['tabular-nums'] },
|
|
88
|
+
footReadValue: { color: t.textPrimary, fontWeight: fw(t.fontWeightSemibold) },
|
|
89
|
+
footAct: { flexDirection: 'row', alignItems: 'center', gap: t.spacingSm },
|
|
90
|
+
footBtn: (pressed) => ({
|
|
91
|
+
paddingVertical: t.spacingXs, paddingHorizontal: t.spacingMd, borderRadius: t.borderRadiusSm,
|
|
92
|
+
backgroundColor: pressed ? t.hoverOverlay : 'transparent',
|
|
93
|
+
}),
|
|
94
|
+
footBtnText: { fontSize: small, fontWeight: fw(t.fontWeightMedium), color: t.accentPrimaryText },
|
|
95
|
+
apply: (pressed) => ({
|
|
96
|
+
paddingVertical: t.spacingXs, paddingHorizontal: t.spacingXl, borderRadius: t.borderRadiusSm,
|
|
97
|
+
backgroundColor: pressed ? t.accentPrimaryHover : t.accentPrimary,
|
|
98
|
+
}),
|
|
99
|
+
applyText: { fontSize: small, fontWeight: fw(t.fontWeightMedium), color: t.onPrimary },
|
|
100
|
+
navOn: (pressed) => ({
|
|
101
|
+
width: nav, height: nav, alignItems: 'center', justifyContent: 'center', borderRadius: t.borderRadiusSm,
|
|
102
|
+
backgroundColor: pressed ? t.accentPrimaryHover : t.accentPrimary,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function timeLook(t, fontSize) {
|
|
107
|
+
const height = fontSize * DP_TIME_COLS_HEIGHT_EM;
|
|
108
|
+
return {
|
|
109
|
+
viewport: height - 2 * t.spacingXxs - 2,
|
|
110
|
+
cols: {
|
|
111
|
+
flexDirection: 'row', gap: t.spacingXxs, height, marginTop: t.spacingXxs,
|
|
112
|
+
padding: t.spacingXxs, borderWidth: 1, borderColor: t.borderColor, borderRadius: t.borderRadiusSm, backgroundColor: t.bgPrimary,
|
|
113
|
+
},
|
|
114
|
+
col: { flex: 1, minWidth: 0 },
|
|
115
|
+
opt: (lit) => ({
|
|
116
|
+
paddingVertical: t.spacingXxs, borderRadius: DP_TIME_OPT_RADIUS, alignItems: 'center',
|
|
117
|
+
backgroundColor: lit ? t.accentPrimary : 'transparent',
|
|
118
|
+
}),
|
|
119
|
+
optText: (lit, pressed) => ({
|
|
120
|
+
fontSize: fontSize * DP_SMALL_TEXT_EM,
|
|
121
|
+
fontVariant: ['tabular-nums'],
|
|
122
|
+
color: lit ? t.onPrimary : pressed ? t.textPrimary : t.textSecondary,
|
|
123
|
+
fontWeight: lit ? fw(t.fontWeightMedium) : undefined,
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function periodLook(t, fontSize, width, s) {
|
|
128
|
+
const row = 2 * Math.round((fontSize * DP_PERIOD_ROW_EM) / 2);
|
|
129
|
+
const cell = Math.floor(width / 3);
|
|
130
|
+
const inset = t.spacingXs;
|
|
131
|
+
const half = row / 2;
|
|
132
|
+
const filled = s.filled && !s.disabled;
|
|
133
|
+
let color = t.textPrimary;
|
|
134
|
+
if (s.disabled)
|
|
135
|
+
color = t.disabledText;
|
|
136
|
+
if (filled)
|
|
137
|
+
color = t.onPrimary;
|
|
138
|
+
let cap;
|
|
139
|
+
if (s.start && !s.end)
|
|
140
|
+
cap = { position: 'absolute', top: 0, bottom: 0, left: inset, right: 0, backgroundColor: t.accentPrimaryLight, borderTopLeftRadius: half, borderBottomLeftRadius: half };
|
|
141
|
+
if (s.end && !s.start)
|
|
142
|
+
cap = { position: 'absolute', top: 0, bottom: 0, left: 0, right: inset, backgroundColor: t.accentPrimaryLight, borderTopRightRadius: half, borderBottomRightRadius: half };
|
|
143
|
+
return {
|
|
144
|
+
cell: { width: cell, height: row, alignItems: 'center', justifyContent: 'center', backgroundColor: s.band ? t.accentPrimaryLight : 'transparent' },
|
|
145
|
+
cap,
|
|
146
|
+
pill: {
|
|
147
|
+
width: cell - 2 * inset, height: row, borderRadius: half, alignItems: 'center', justifyContent: 'center', overflow: 'hidden',
|
|
148
|
+
backgroundColor: filled ? (s.pressed ? t.accentPrimaryHover : t.accentPrimary) : 'transparent',
|
|
149
|
+
},
|
|
150
|
+
tint: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, borderRadius: half, backgroundColor: t.hoverOverlay, opacity: s.pressed && !filled && !s.disabled ? 1 : 0 },
|
|
151
|
+
text: { fontSize, color, fontVariant: ['tabular-nums'], fontWeight: filled ? fw(t.fontWeightSemibold) : undefined },
|
|
152
|
+
dot: s.isCurrent
|
|
153
|
+
? { position: 'absolute', bottom: fontSize * DP_PERIOD_DOT_BOTTOM_EM, width: DP_TODAY_DOT, height: DP_TODAY_DOT, borderRadius: DP_TODAY_DOT / 2, backgroundColor: filled ? t.onPrimary : t.error }
|
|
154
|
+
: undefined,
|
|
155
|
+
title: { fontSize, fontWeight: fw(t.fontWeightSemibold), color: t.textPrimary, fontVariant: ['tabular-nums'] },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, Keyboard, KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, Text, View, useWindowDimensions } from 'react-native';
|
|
4
|
+
import { closeIcon } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens, useUILabels } from '../UIProvider/context';
|
|
6
|
+
import { Icon } from '../Icon/Icon';
|
|
7
|
+
import { DIALOG_ANIMATION_MS, DIALOG_NARROW_BELOW, DIALOG_POP_SCALE } from '../styles/webValues';
|
|
8
|
+
import { NO_INSETS, dialogLook } from './dialogStyle';
|
|
9
|
+
import { SafeAreaInsetsContext, SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context';
|
|
10
|
+
import { ToastLayer } from '../Toast/ToastLayer';
|
|
11
|
+
const NO_METRICS = { frame: { x: 0, y: 0, width: 0, height: 0 }, insets: NO_INSETS };
|
|
12
|
+
const RegisterContext = createContext(null);
|
|
13
|
+
const NO_DIALOGS = [];
|
|
14
|
+
const StackContext = createContext(NO_DIALOGS);
|
|
15
|
+
export function DialogOpenProvider({ children }) {
|
|
16
|
+
const [stack, setStack] = useState(NO_DIALOGS);
|
|
17
|
+
const register = useMemo(() => (key) => {
|
|
18
|
+
setStack(s => [...s, key]);
|
|
19
|
+
let done = false;
|
|
20
|
+
return () => {
|
|
21
|
+
if (done)
|
|
22
|
+
return;
|
|
23
|
+
done = true;
|
|
24
|
+
setStack(s => s.filter(k => k !== key));
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
return (_jsx(RegisterContext.Provider, { value: register, children: _jsx(StackContext.Provider, { value: stack, children: children }) }));
|
|
28
|
+
}
|
|
29
|
+
export const useDialogOpen = () => useContext(StackContext).length > 0;
|
|
30
|
+
export const useTopDialog = () => {
|
|
31
|
+
const stack = useContext(StackContext);
|
|
32
|
+
return stack[stack.length - 1] ?? null;
|
|
33
|
+
};
|
|
34
|
+
function useKeyboardUp(on) {
|
|
35
|
+
const [up, setUp] = useState(false);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!on)
|
|
38
|
+
return;
|
|
39
|
+
const ios = Platform.OS === 'ios';
|
|
40
|
+
const show = Keyboard.addListener(ios ? 'keyboardWillShow' : 'keyboardDidShow', () => setUp(true));
|
|
41
|
+
const hide = Keyboard.addListener(ios ? 'keyboardWillHide' : 'keyboardDidHide', () => setUp(false));
|
|
42
|
+
return () => { show.remove(); hide.remove(); setUp(false); };
|
|
43
|
+
}, [on]);
|
|
44
|
+
return up;
|
|
45
|
+
}
|
|
46
|
+
export function Dialog({ open, onClose, onBeforeClose, onBackdropPress, onAnimationEnd, children, title, subtitle, footer, placement = 'center', size = 'md', closeOnBackdrop = true, closeOnEscape = true, showCloseButton = true, closeIcon: ownCloseIcon, animationDuration = DIALOG_ANIMATION_MS, padded = true, style, testID, 'aria-label': ariaLabel, }) {
|
|
47
|
+
const t = useTokens();
|
|
48
|
+
const words = useUILabels();
|
|
49
|
+
const { width, height } = useWindowDimensions();
|
|
50
|
+
const narrow = width < DIALOG_NARROW_BELOW;
|
|
51
|
+
const look = dialogLook(t, placement, size, narrow, padded);
|
|
52
|
+
const [mounted, setMounted] = useState(open);
|
|
53
|
+
const progress = useRef(new Animated.Value(open ? 1 : 0)).current;
|
|
54
|
+
const register = useContext(RegisterContext);
|
|
55
|
+
const ms = animationDuration * t.motionScale;
|
|
56
|
+
const key = useRef({}).current;
|
|
57
|
+
const onTop = useTopDialog() === key;
|
|
58
|
+
const keyboardUp = useKeyboardUp(mounted);
|
|
59
|
+
useEffect(() => (mounted && register ? register(key) : undefined), [mounted, register]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (open) {
|
|
62
|
+
setMounted(true);
|
|
63
|
+
const run = Animated.timing(progress, { toValue: 1, duration: ms, useNativeDriver: true });
|
|
64
|
+
run.start();
|
|
65
|
+
return () => run.stop();
|
|
66
|
+
}
|
|
67
|
+
if (!mounted)
|
|
68
|
+
return;
|
|
69
|
+
const run = Animated.timing(progress, { toValue: 0, duration: ms, useNativeDriver: true });
|
|
70
|
+
run.start(({ finished }) => {
|
|
71
|
+
if (!finished)
|
|
72
|
+
return;
|
|
73
|
+
setMounted(false);
|
|
74
|
+
onAnimationEnd?.();
|
|
75
|
+
});
|
|
76
|
+
return () => run.stop();
|
|
77
|
+
}, [open]);
|
|
78
|
+
const requestClose = () => {
|
|
79
|
+
if (onBeforeClose && onBeforeClose() === false)
|
|
80
|
+
return;
|
|
81
|
+
onClose?.();
|
|
82
|
+
};
|
|
83
|
+
const move = placement === 'center'
|
|
84
|
+
? [
|
|
85
|
+
{ translateY: progress.interpolate({ inputRange: [0, 1], outputRange: [-t.motionEnterOffset, 0] }) },
|
|
86
|
+
{ scale: progress.interpolate({ inputRange: [0, 1], outputRange: [DIALOG_POP_SCALE, 1] }) },
|
|
87
|
+
]
|
|
88
|
+
: placement === 'bottom' || placement === 'top'
|
|
89
|
+
? [{ translateY: progress.interpolate({ inputRange: [0, 1], outputRange: [placement === 'bottom' ? height : -height, 0] }) }]
|
|
90
|
+
: [{ translateX: progress.interpolate({ inputRange: [0, 1], outputRange: [placement === 'right' ? width : -width, 0] }) }];
|
|
91
|
+
const name = ariaLabel ?? (typeof title === 'string' ? title : undefined);
|
|
92
|
+
const hasHeader = title !== undefined || subtitle !== undefined || showCloseButton;
|
|
93
|
+
return (_jsx(Modal, { visible: mounted, transparent: true, animationType: "none", statusBarTranslucent: true, navigationBarTranslucent: true, onRequestClose: () => { if (closeOnEscape)
|
|
94
|
+
requestClose(); }, children: _jsxs(SafeAreaProvider, { style: { flex: 1 }, initialMetrics: initialWindowMetrics ?? NO_METRICS, children: [_jsx(Animated.View, { style: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: t.scrim, opacity: progress }, children: _jsx(Pressable, { accessible: false, style: { flex: 1 }, onPress: () => {
|
|
95
|
+
onBackdropPress?.();
|
|
96
|
+
if (closeOnBackdrop)
|
|
97
|
+
requestClose();
|
|
98
|
+
} }) }), _jsx(SafeAreaInsetsContext.Consumer, { children: edges => {
|
|
99
|
+
const bars = edges ?? NO_INSETS;
|
|
100
|
+
const framed = dialogLook(t, placement, size, narrow, padded, keyboardUp ? { ...bars, bottom: 0 } : bars);
|
|
101
|
+
return (_jsx(KeyboardAvoidingView, { behavior: "padding", style: { flex: 1 }, pointerEvents: "box-none", children: _jsx(View, { style: framed.frame, pointerEvents: "box-none", children: _jsxs(Animated.View, { testID: testID, role: "dialog", "aria-modal": true, "aria-label": name, accessibilityViewIsModal: true, style: [framed.panel, style, { opacity: placement === 'center' ? progress : 1, transform: move }], children: [hasHeader && (_jsxs(View, { style: look.header, children: [_jsxs(View, { style: { flex: 1, minWidth: 0, gap: t.spacingXxs }, children: [title !== undefined && (typeof title === 'string' ? _jsx(Text, { role: "heading", style: look.title, children: title }) : title), subtitle !== undefined && (typeof subtitle === 'string' ? _jsx(Text, { style: look.subtitle, children: subtitle }) : subtitle)] }), showCloseButton && (_jsx(Pressable, { role: "button", "aria-label": words.dialog.close, onPress: requestClose, hitSlop: t.spacingSm, style: ({ pressed }) => [look.close, pressed && { backgroundColor: t.bgTertiary }], children: ownCloseIcon ?? _jsx(Icon, { icon: closeIcon, size: look.closeIconSize, color: t.textSecondary }) }))] })), _jsx(ScrollView, { style: { flexGrow: 1, flexShrink: 1 }, contentContainerStyle: look.body, keyboardShouldPersistTaps: "handled", children: typeof children === 'string' ? _jsx(Text, { style: { color: t.textPrimary, fontSize: t.fontSizeMd }, children: children }) : children }), footer !== undefined && footer !== null && _jsx(View, { style: look.footer, children: footer })] }) }) }));
|
|
102
|
+
} }), onTop && _jsx(ToastLayer, {})] }) }));
|
|
103
|
+
}
|
|
104
|
+
Dialog.displayName = 'Dialog';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Text } from 'react-native';
|
|
4
|
+
import { useTokens, useUILabels } from '../UIProvider/context';
|
|
5
|
+
import { Button } from '../Button/Button';
|
|
6
|
+
import { Dialog } from './Dialog';
|
|
7
|
+
const DialogApiContext = createContext(null);
|
|
8
|
+
export const useDialog = () => {
|
|
9
|
+
const api = useContext(DialogApiContext);
|
|
10
|
+
if (!api)
|
|
11
|
+
throw new Error('useDialog() requires a <UIProvider> (or a <DialogHost>) above it — that is what renders the dialog.');
|
|
12
|
+
return api;
|
|
13
|
+
};
|
|
14
|
+
export function DialogHost({ children }) {
|
|
15
|
+
const t = useTokens();
|
|
16
|
+
const words = useUILabels();
|
|
17
|
+
const [state, setState] = useState(null);
|
|
18
|
+
const [busy, setBusy] = useState(null);
|
|
19
|
+
const settler = useRef(null);
|
|
20
|
+
const open = useCallback((next, dismissValue) => {
|
|
21
|
+
settler.current?.resolve(dismissValue);
|
|
22
|
+
settler.current = null;
|
|
23
|
+
setBusy(null);
|
|
24
|
+
setState(next);
|
|
25
|
+
return new Promise((resolve, reject) => { settler.current = { resolve, reject }; });
|
|
26
|
+
}, []);
|
|
27
|
+
const settle = useCallback((value) => {
|
|
28
|
+
setState(null);
|
|
29
|
+
setBusy(null);
|
|
30
|
+
const s = settler.current;
|
|
31
|
+
settler.current = null;
|
|
32
|
+
s?.resolve(value);
|
|
33
|
+
}, []);
|
|
34
|
+
const pick = useCallback(async (key, value, action, args) => {
|
|
35
|
+
if (!action)
|
|
36
|
+
return settle(value);
|
|
37
|
+
setBusy(key);
|
|
38
|
+
try {
|
|
39
|
+
await action(...(args ?? []));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
setState(null);
|
|
43
|
+
setBusy(null);
|
|
44
|
+
const s = settler.current;
|
|
45
|
+
settler.current = null;
|
|
46
|
+
s?.reject(err);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
settle(value);
|
|
50
|
+
}, [settle]);
|
|
51
|
+
const api = useMemo(() => ({
|
|
52
|
+
confirm: opts => open({ kind: 'confirm', opts }, false),
|
|
53
|
+
choose: opts => open({ kind: 'choose', opts }, null),
|
|
54
|
+
alert: opts => open({ kind: 'alert', opts }, undefined),
|
|
55
|
+
}), [open]);
|
|
56
|
+
const last = useRef(null);
|
|
57
|
+
if (state)
|
|
58
|
+
last.current = state;
|
|
59
|
+
const shown = state ?? last.current;
|
|
60
|
+
const dismissValue = state?.kind === 'choose' ? null : state?.kind === 'alert' ? undefined : false;
|
|
61
|
+
const cancelOpts = shown && shown.kind !== 'alert' ? shown.opts : undefined;
|
|
62
|
+
const showCancel = cancelOpts ? cancelOpts.cancelLabel !== null : false;
|
|
63
|
+
const footer = !shown ? null : (_jsxs(_Fragment, { children: [shown.kind === 'confirm' && (_jsx(Button, { label: shown.opts.confirmLabel ?? words.dialog.confirm, variant: "filled", color: shown.opts.tone === 'danger' ? 'error' : 'primary', ...shown.opts.confirmButton, loading: busy === 'confirm', disabled: !!busy && busy !== 'confirm', onPress: () => pick('confirm', true, shown.opts.action, shown.opts.args) })), shown.kind === 'choose' && shown.opts.choices.map(c => {
|
|
64
|
+
const { value, action, args, ...button } = c;
|
|
65
|
+
return (_jsx(Button, { variant: "filled", ...button, loading: busy === value, disabled: !!busy && busy !== value, onPress: () => pick(value, value, action, args) }, value));
|
|
66
|
+
}), shown.kind === 'alert' && (_jsx(Button, { label: shown.opts.okLabel ?? words.dialog.ok, variant: "filled", color: shown.opts.tone === 'danger' ? 'error' : 'primary', ...shown.opts.okButton, onPress: () => settle(undefined) })), showCancel && (_jsx(Button, { label: cancelOpts?.cancelLabel ?? words.dialog.cancel, variant: "outlined", color: "neutral", ...cancelOpts?.cancelButton, disabled: !!busy, onPress: () => settle(dismissValue) }))] }));
|
|
67
|
+
return (_jsxs(DialogApiContext.Provider, { value: api, children: [children, _jsx(Dialog, { open: !!state, size: "sm", title: shown?.opts.title, onClose: () => settle(dismissValue), closeOnEscape: !busy, closeOnBackdrop: !busy, showCloseButton: !busy, footer: footer, children: typeof shown?.opts.message === 'string'
|
|
68
|
+
? _jsx(Text, { style: { color: t.textPrimary, fontSize: t.fontSizeMd, lineHeight: Math.round(t.fontSizeMd * t.lineHeightNormal) }, children: shown.opts.message })
|
|
69
|
+
: shown?.opts.message })] }));
|
|
70
|
+
}
|
|
71
|
+
DialogHost.displayName = 'DialogHost';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { boxShadow } from '../Button/buttonStyle';
|
|
2
|
+
import { DIALOG_TITLE_LINE_HEIGHT, DIALOG_WIDTHS } from '../styles/webValues';
|
|
3
|
+
export const NO_INSETS = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
4
|
+
export function dialogLook(t, placement, size, narrow, padded, insets = NO_INSETS) {
|
|
5
|
+
const full = size === 'full';
|
|
6
|
+
const width = full ? '100%' : DIALOG_WIDTHS[size];
|
|
7
|
+
const padX = narrow ? t.spacingLg : t.spacingXl;
|
|
8
|
+
const frame = { flex: 1 };
|
|
9
|
+
const panel = {
|
|
10
|
+
flexDirection: 'column',
|
|
11
|
+
maxWidth: '100%',
|
|
12
|
+
maxHeight: '100%',
|
|
13
|
+
backgroundColor: t.cardBg,
|
|
14
|
+
borderWidth: 1,
|
|
15
|
+
borderColor: t.cardBorder,
|
|
16
|
+
boxShadow: boxShadow(t.shadowXl),
|
|
17
|
+
borderRadius: t.borderRadius,
|
|
18
|
+
overflow: 'hidden',
|
|
19
|
+
};
|
|
20
|
+
const lg = t.borderRadiusLg;
|
|
21
|
+
switch (placement) {
|
|
22
|
+
case 'center':
|
|
23
|
+
Object.assign(frame, { alignItems: 'center', justifyContent: 'center', padding: narrow ? t.spacingMd : t.spacingXl });
|
|
24
|
+
Object.assign(panel, { width: narrow && !full ? '100%' : width });
|
|
25
|
+
break;
|
|
26
|
+
case 'right':
|
|
27
|
+
case 'left':
|
|
28
|
+
Object.assign(frame, { flexDirection: 'row', alignItems: 'stretch', justifyContent: placement === 'right' ? 'flex-end' : 'flex-start' });
|
|
29
|
+
Object.assign(panel, placement === 'right'
|
|
30
|
+
? { width, height: '100%', borderTopRightRadius: 0, borderBottomRightRadius: 0, borderTopLeftRadius: lg, borderBottomLeftRadius: lg, borderRightWidth: 0 }
|
|
31
|
+
: { width, height: '100%', borderTopLeftRadius: 0, borderBottomLeftRadius: 0, borderTopRightRadius: lg, borderBottomRightRadius: lg, borderLeftWidth: 0 });
|
|
32
|
+
break;
|
|
33
|
+
case 'top':
|
|
34
|
+
case 'bottom':
|
|
35
|
+
Object.assign(frame, { flexDirection: 'column', alignItems: 'center', justifyContent: placement === 'top' ? 'flex-start' : 'flex-end' });
|
|
36
|
+
Object.assign(panel, { width: '100%', maxWidth: full ? '100%' : DIALOG_WIDTHS[size] }, placement === 'top'
|
|
37
|
+
? { borderTopLeftRadius: 0, borderTopRightRadius: 0, borderBottomLeftRadius: lg, borderBottomRightRadius: lg, borderTopWidth: 0 }
|
|
38
|
+
: { borderTopLeftRadius: lg, borderTopRightRadius: lg, borderBottomLeftRadius: 0, borderBottomRightRadius: 0, borderBottomWidth: 0 });
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (full)
|
|
42
|
+
Object.assign(panel, { height: '100%', borderRadius: 0, borderTopLeftRadius: 0, borderTopRightRadius: 0, borderBottomLeftRadius: 0, borderBottomRightRadius: 0 });
|
|
43
|
+
const i = insets;
|
|
44
|
+
if (full)
|
|
45
|
+
Object.assign(panel, { paddingTop: i.top, paddingRight: i.right, paddingBottom: i.bottom, paddingLeft: i.left });
|
|
46
|
+
else if (placement === 'center') {
|
|
47
|
+
const pad = frame.padding;
|
|
48
|
+
Object.assign(frame, { padding: undefined, paddingTop: pad + i.top, paddingRight: pad + i.right, paddingBottom: pad + i.bottom, paddingLeft: pad + i.left });
|
|
49
|
+
}
|
|
50
|
+
else if (placement === 'bottom') {
|
|
51
|
+
Object.assign(frame, { paddingTop: i.top });
|
|
52
|
+
Object.assign(panel, { paddingBottom: i.bottom, paddingLeft: i.left, paddingRight: i.right });
|
|
53
|
+
}
|
|
54
|
+
else if (placement === 'top') {
|
|
55
|
+
Object.assign(frame, { paddingBottom: i.bottom });
|
|
56
|
+
Object.assign(panel, { paddingTop: i.top, paddingLeft: i.left, paddingRight: i.right });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
Object.assign(panel, { paddingTop: i.top, paddingBottom: i.bottom }, placement === 'right' ? { paddingRight: i.right } : { paddingLeft: i.left });
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
frame,
|
|
63
|
+
panel,
|
|
64
|
+
header: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'space-between', gap: t.spacingLg, paddingVertical: t.spacingLg, paddingHorizontal: padX, borderBottomWidth: 1, borderBottomColor: t.cardBorder },
|
|
65
|
+
title: { fontSize: t.fontSizeLg, fontWeight: String(t.fontWeightSemibold), lineHeight: Math.round(t.fontSizeLg * DIALOG_TITLE_LINE_HEIGHT), color: t.textPrimary },
|
|
66
|
+
subtitle: { fontSize: t.fontSizeSm, color: t.textSecondary, lineHeight: Math.round(t.fontSizeSm * t.lineHeightSnug) },
|
|
67
|
+
body: padded ? { paddingVertical: t.spacingLg, paddingHorizontal: padX } : {},
|
|
68
|
+
footer: { flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', flexWrap: 'wrap', gap: t.spacingSm, paddingVertical: t.spacingMd, paddingHorizontal: padX, borderTopWidth: 1, borderTopColor: t.cardBorder },
|
|
69
|
+
close: { width: t.fieldHeightXxs, height: t.fieldHeightXxs, alignItems: 'center', justifyContent: 'center', borderRadius: t.borderRadiusSm },
|
|
70
|
+
closeIconSize: t.iconSlotButton,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { useWindowDimensions } from 'react-native';
|
|
4
|
+
import { DEFAULT_CONTROL_SIZE } from '@dcs-tech/core';
|
|
5
|
+
export const FieldContext = createContext({});
|
|
6
|
+
FieldContext.displayName = 'FieldContext';
|
|
7
|
+
export const useFieldContext = () => useContext(FieldContext);
|
|
8
|
+
export const FieldProvider = ({ size, variant, layout, disabled, readOnly, children }) => {
|
|
9
|
+
const parent = useFieldContext();
|
|
10
|
+
const value = useMemo(() => ({
|
|
11
|
+
...parent,
|
|
12
|
+
size: size ?? parent.size,
|
|
13
|
+
variant: variant ?? parent.variant,
|
|
14
|
+
layout: layout ?? parent.layout,
|
|
15
|
+
disabled: disabled ?? parent.disabled,
|
|
16
|
+
readOnly: readOnly ?? parent.readOnly,
|
|
17
|
+
}), [parent, size, variant, layout, disabled, readOnly]);
|
|
18
|
+
return _jsx(FieldContext.Provider, { value: value, children: children });
|
|
19
|
+
};
|
|
20
|
+
FieldProvider.displayName = 'FieldProvider';
|
|
21
|
+
export const STACK_BELOW_WIDTH = 640;
|
|
22
|
+
export function useFieldSurface(own) {
|
|
23
|
+
const ctx = useFieldContext();
|
|
24
|
+
const { width } = useWindowDimensions();
|
|
25
|
+
const narrow = width < STACK_BELOW_WIDTH;
|
|
26
|
+
const { size, variant, layout, disabled, readOnly } = own;
|
|
27
|
+
return useMemo(() => {
|
|
28
|
+
const resolvedLayout = layout ?? ctx.layout ?? 'horizontal';
|
|
29
|
+
return {
|
|
30
|
+
size: size ?? ctx.size ?? DEFAULT_CONTROL_SIZE,
|
|
31
|
+
variant: variant ?? ctx.variant ?? 'outlined',
|
|
32
|
+
layout: resolvedLayout,
|
|
33
|
+
shownLayout: resolvedLayout === 'horizontal' && narrow ? 'default' : resolvedLayout,
|
|
34
|
+
disabled: disabled ?? ctx.disabled ?? false,
|
|
35
|
+
readOnly: readOnly ?? ctx.readOnly ?? false,
|
|
36
|
+
};
|
|
37
|
+
}, [size, variant, layout, disabled, readOnly, ctx.size, ctx.variant, ctx.layout, ctx.disabled, ctx.readOnly, narrow]);
|
|
38
|
+
}
|
|
39
|
+
export function useToggleSurface(own) {
|
|
40
|
+
const ctx = useFieldContext();
|
|
41
|
+
const inherited = ctx.variant === 'underlined' ? undefined : ctx.variant;
|
|
42
|
+
const { size, variant, disabled, readOnly } = own;
|
|
43
|
+
return useMemo(() => ({
|
|
44
|
+
size: size ?? ctx.size ?? DEFAULT_CONTROL_SIZE,
|
|
45
|
+
variant: variant ?? inherited ?? 'filled',
|
|
46
|
+
layout: ctx.layout === 'cell' ? 'cell' : 'inline',
|
|
47
|
+
disabled: disabled ?? ctx.disabled ?? false,
|
|
48
|
+
readOnly: readOnly ?? ctx.readOnly ?? false,
|
|
49
|
+
}), [size, variant, disabled, readOnly, ctx.size, inherited, ctx.layout, ctx.disabled, ctx.readOnly]);
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldContext, FieldProvider, useFieldContext, useFieldSurface, useToggleSurface, STACK_BELOW_WIDTH } from './FieldContext';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Text, View } from 'react-native';
|
|
4
|
+
import { warningIcon } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { useFieldSurface } from '../FieldContext/FieldContext';
|
|
7
|
+
import { Icon } from '../Icon/Icon';
|
|
8
|
+
import { fieldWidthStyle, fieldWrapperLook } from './fieldWrapperStyle';
|
|
9
|
+
const asText = (node, style) => typeof node === 'string' || typeof node === 'number' ? _jsx(Text, { style: style, children: node }) : node;
|
|
10
|
+
export function FieldWrapper({ label, error, hint, required = false, size: sizeProp, layout: layoutProp, disabled: disabledProp, width, focused = false, extraMessages, labelId, style, testID, children, }) {
|
|
11
|
+
const t = useTokens();
|
|
12
|
+
const { size, shownLayout: layout, disabled } = useFieldSurface({ size: sizeProp, layout: layoutProp, disabled: disabledProp });
|
|
13
|
+
const hasError = error !== undefined && error !== null && error !== false && error !== '';
|
|
14
|
+
const cell = layout === 'cell';
|
|
15
|
+
const showLabel = !cell && label !== undefined && label !== null && label !== false && label !== '';
|
|
16
|
+
const look = useMemo(() => fieldWrapperLook(t, { size, layout, disabled, error: hasError, focused, labelled: showLabel }), [t, size, layout, disabled, hasError, focused, showLabel]);
|
|
17
|
+
const showHint = hint !== undefined && hint !== null && hint !== false && hint !== '';
|
|
18
|
+
const showMessages = !cell && (hasError || showHint || !!extraMessages);
|
|
19
|
+
const messages = showMessages ? (_jsxs(View, { style: look.messages, children: [hasError ? (_jsxs(View, { style: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: t.spacingXs }, children: [_jsx(Icon, { icon: warningIcon, size: look.errorIconSize, color: t.errorText }), asText(error, look.error)] })) : showHint ? asText(hint, look.hint) : _jsx(View, { style: { flex: 1 } }), extraMessages] })) : null;
|
|
20
|
+
const control = _jsx(View, { style: [look.content, fieldWidthStyle(t, width, layout)], children: children });
|
|
21
|
+
return (_jsxs(View, { style: [look.root, style], testID: testID, children: [showLabel && (_jsx(View, { style: look.labelRow, children: _jsxs(Text, { nativeID: labelId, style: look.label, children: [label, required && _jsx(Text, { style: look.required, children: ' *' })] }) })), layout === 'horizontal' && showLabel ? (_jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [control, messages] })) : (_jsxs(_Fragment, { children: [control, messages] }))] }));
|
|
22
|
+
}
|
|
23
|
+
FieldWrapper.displayName = 'FieldWrapper';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { fieldSize } from '../styles/fieldControl';
|
|
2
|
+
function labelSize(t, size) {
|
|
3
|
+
switch (size) {
|
|
4
|
+
case 'xxs': return t.fontSizeXxs;
|
|
5
|
+
case 'xs': return t.fontSizeXs;
|
|
6
|
+
case 'small': return t.fontSizeSm;
|
|
7
|
+
case 'medium': return t.fontSizeMd;
|
|
8
|
+
case 'large': return t.fontSizeLg;
|
|
9
|
+
case 'xl': return t.fontSizeXl;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function fieldWrapperLook(t, s) {
|
|
13
|
+
const horizontal = s.layout === 'horizontal' && s.labelled;
|
|
14
|
+
const cell = s.layout === 'cell';
|
|
15
|
+
let labelColor = t.textSecondary;
|
|
16
|
+
if (s.focused)
|
|
17
|
+
labelColor = t.accentPrimaryText;
|
|
18
|
+
if (s.error)
|
|
19
|
+
labelColor = t.errorText;
|
|
20
|
+
if (s.disabled)
|
|
21
|
+
labelColor = t.textTertiary;
|
|
22
|
+
const fontSize = labelSize(t, s.size);
|
|
23
|
+
const messageSize = t.fontSizeXs;
|
|
24
|
+
return {
|
|
25
|
+
root: horizontal
|
|
26
|
+
? { flexDirection: 'row', alignItems: 'flex-start', columnGap: t.spacingLg }
|
|
27
|
+
: cell ? { width: '100%', height: '100%' } : {},
|
|
28
|
+
labelRow: horizontal
|
|
29
|
+
? { flexDirection: 'row', alignItems: 'flex-start', width: t.fieldLabelWidth, paddingTop: fieldSize(t, s.size).padY }
|
|
30
|
+
: { flexDirection: 'row', alignItems: 'center', marginBottom: t.labelSpacing },
|
|
31
|
+
label: {
|
|
32
|
+
fontSize,
|
|
33
|
+
lineHeight: Math.round(fontSize * t.lineHeightNormal),
|
|
34
|
+
fontWeight: String(t.fontWeightMedium),
|
|
35
|
+
color: labelColor,
|
|
36
|
+
},
|
|
37
|
+
required: { color: t.errorText },
|
|
38
|
+
content: cell
|
|
39
|
+
? { flex: 1, flexDirection: 'row', alignItems: 'center', width: '100%', height: '100%', ...(s.error ? { boxShadow: [{ offsetX: 3, offsetY: 0, blurRadius: 0, spreadDistance: 0, color: t.error, inset: true }] } : {}) }
|
|
40
|
+
: {},
|
|
41
|
+
messages: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', marginTop: t.messageSpacing, gap: t.spacingLg },
|
|
42
|
+
error: { flex: 1, fontSize: messageSize, lineHeight: Math.round(messageSize * t.lineHeightNormal), color: t.errorText },
|
|
43
|
+
hint: { flex: 1, fontSize: messageSize, lineHeight: Math.round(messageSize * t.lineHeightNormal), color: t.textTertiary },
|
|
44
|
+
errorIconSize: Math.round(messageSize * t.iconTextRatio),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function fieldWidthStyle(t, width, layout) {
|
|
48
|
+
if (layout === 'cell')
|
|
49
|
+
return {};
|
|
50
|
+
if (width === undefined)
|
|
51
|
+
return { width: '100%', maxWidth: t.fieldControlMaxWidth };
|
|
52
|
+
if (width === 'full')
|
|
53
|
+
return { width: '100%' };
|
|
54
|
+
if (width === 'auto')
|
|
55
|
+
return { alignSelf: 'flex-start', maxWidth: '100%' };
|
|
56
|
+
if (typeof width === 'number')
|
|
57
|
+
return { width, maxWidth: '100%' };
|
|
58
|
+
const px = /^(\d+(?:\.\d+)?)px$/.exec(width.trim());
|
|
59
|
+
if (px)
|
|
60
|
+
return { width: Number(px[1]), maxWidth: '100%' };
|
|
61
|
+
if (/^\d+(?:\.\d+)?%$/.test(width.trim()))
|
|
62
|
+
return { width: width.trim(), maxWidth: '100%' };
|
|
63
|
+
return { width: '100%', maxWidth: t.fieldControlMaxWidth };
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldWrapper } from './FieldWrapper';
|