@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,218 @@
|
|
|
1
|
+
import { boxShadow } from '../Button/buttonStyle';
|
|
2
|
+
import { mixColors, oklchToHex } from '../styles/color';
|
|
3
|
+
import { DT_ACCENT_SOFT_MIX, DT_BULK_BUSY_OPACITY, DT_BULK_BUTTON_HEIGHT, DT_BULK_DISABLED_OPACITY, DT_BULK_EDGE_MIX, DT_BULK_TEXT_MIX, DT_CARD_CHECK_BOX, DT_CARD_CHECK_HEAD_PAD, DT_CARD_CHECK_LEFT, DT_CARD_CHECK_TOP, DT_ACTIVE_EDGE_MIX, DT_AVATAR_CARD, DT_AVATAR_CARD_PHONE, DT_AVATAR_CHROMA, DT_AVATAR_LETTER_SPACING_EM, DT_AVATAR_LIGHTNESS, DT_AVATAR_SPLIT, DT_AVATAR_TEXT_SCALE, DT_CARD_EXPAND, DT_CARD_EXPAND_PHONE, DT_CARD_FOOT_MIN_HEIGHT, DT_CARD_HEAD_PAD_BOTTOM, DT_CARD_PAD, DT_CARD_TITLE_LINE_HEIGHT, DT_CARDS_GAP_PHONE, DT_DETAIL_BAR_MIN_HEIGHT, DT_DETAIL_EMPTY_MIN_HEIGHT, DT_DETAIL_LABEL_MIN_WIDTH, DT_DETAIL_NAV_BUTTON, DT_DETAIL_NAV_RADIUS, DT_EMPTY_PAD_Y, DT_FIELD_NAME_LETTER_SPACING_EM, DT_LINE_SOFT_MIX, DT_PAGER_MIN_HEIGHT, DT_ROW_HOVER_MIX, DT_SPLIT_ITEM_PAD_Y, DT_SPLIT_ITEM_PHONE_MIN_HEIGHT, DT_SPLIT_ACTIONS_TUCK, DT_SPLIT_CHECK_HEIGHT, DT_SPLIT_CHECK_WIDTH, DT_STATUS_CHIP_HEIGHT, DT_CHIP_OPERATOR_OPACITY, DT_CHIP_VALUE_MAX, DT_STATUS_CHIP_PAD_END, DT_STATUS_CHIP_PAD_START, DT_STATUS_CHIP_REMOVE, DT_STATUS_DIVIDER_HEIGHT, DT_STATUS_DIVIDER_MIX, DT_STATUS_DIVIDER_SOFT_HEIGHT, DT_STATUS_IDLE_MIX, DT_STATUS_LINK_PAD, DT_STATUS_LINK_RADIUS, DT_STATUS_ROW_HEIGHT, DT_STATUS_ROW_HEIGHT_PHONE, DT_STATUS_SELECTING_MIX, DT_STATUS_SPACER_MIN, DT_SPLIT_OPEN_BAR, DT_SPLIT_SIDE, DT_SPLIT_SIDE_MAX, DT_SPLIT_SIDE_NARROW, DT_QUICK_BASIS, DT_QUICK_MAX, DT_QUICK_MIN, DT_SEARCH_BASIS, DT_SEARCH_MAX, DT_SEARCH_MIN, DT_TOOLBAR_BUTTON, DT_TOOLBAR_BUTTON_PHONE, DT_TOOLBAR_MIN_HEIGHT, DT_TOOLBAR_MIN_HEIGHT_PHONE, DT_TOOLBAR_PAD_Y, DT_VIEW_TAB_BAR, DT_VIEW_TAB_HEIGHT, DT_VIEW_TAB_HEIGHT_PHONE, } from '../styles/webValues';
|
|
4
|
+
export function tableColors(t) {
|
|
5
|
+
return {
|
|
6
|
+
surface: t.bgSecondary,
|
|
7
|
+
canvas: t.bgPrimary,
|
|
8
|
+
line: t.borderColor,
|
|
9
|
+
lineSoft: mixColors(t.borderColor, DT_LINE_SOFT_MIX, t.bgSecondary),
|
|
10
|
+
rowHover: mixColors(t.accentPrimary, DT_ROW_HOVER_MIX, t.bgSecondary),
|
|
11
|
+
accentSoft: mixColors(t.accentPrimary, DT_ACCENT_SOFT_MIX, t.bgSecondary),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function containerLook(t) {
|
|
15
|
+
const c = tableColors(t);
|
|
16
|
+
return { backgroundColor: c.surface, borderWidth: 1, borderColor: c.line, borderRadius: t.borderRadiusLg, boxShadow: boxShadow(t.shadowSm), overflow: 'hidden' };
|
|
17
|
+
}
|
|
18
|
+
const AVATAR_SIZES = { card: DT_AVATAR_CARD, cardPhone: DT_AVATAR_CARD_PHONE, split: DT_AVATAR_SPLIT };
|
|
19
|
+
export function avatarLook(t, hue, place) {
|
|
20
|
+
const size = AVATAR_SIZES[place];
|
|
21
|
+
const fontSize = size * DT_AVATAR_TEXT_SCALE;
|
|
22
|
+
return {
|
|
23
|
+
box: { width: size, height: size, borderRadius: size / 2, alignItems: 'center', justifyContent: 'center', backgroundColor: oklchToHex(DT_AVATAR_LIGHTNESS, DT_AVATAR_CHROMA, hue) },
|
|
24
|
+
text: { color: '#ffffff', fontSize, fontWeight: String(t.fontWeightBold), letterSpacing: fontSize * DT_AVATAR_LETTER_SPACING_EM },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function cardLook(t, phone) {
|
|
28
|
+
const c = tableColors(t);
|
|
29
|
+
const gap = phone ? DT_CARDS_GAP_PHONE : t.spacingLg;
|
|
30
|
+
const expand = phone ? DT_CARD_EXPAND_PHONE : DT_CARD_EXPAND;
|
|
31
|
+
return {
|
|
32
|
+
list: phone
|
|
33
|
+
? { padding: t.spacingLg, backgroundColor: c.canvas }
|
|
34
|
+
: { paddingTop: t.spacingLg, paddingHorizontal: DT_CARD_PAD, paddingBottom: t.spacingXl, backgroundColor: c.canvas },
|
|
35
|
+
gap,
|
|
36
|
+
card: { minWidth: 0, backgroundColor: t.cardBg, borderRadius: t.borderRadius, borderWidth: 1, borderColor: t.cardBorder },
|
|
37
|
+
head: { flexDirection: 'row', alignItems: 'center', gap: t.spacingLg, paddingTop: DT_CARD_PAD, paddingHorizontal: DT_CARD_PAD, paddingBottom: DT_CARD_HEAD_PAD_BOTTOM, minWidth: 0 },
|
|
38
|
+
titles: { flex: 1, minWidth: 0 },
|
|
39
|
+
title: { fontSize: t.fontSizeLg, fontWeight: String(t.fontWeightBold), lineHeight: Math.round(t.fontSizeLg * DT_CARD_TITLE_LINE_HEIGHT), color: t.textPrimary },
|
|
40
|
+
subtitle: { marginTop: t.spacingXxs, fontSize: t.fontSizeXs, color: t.textSecondary },
|
|
41
|
+
badge: { flexShrink: 0, maxWidth: '50%', flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: t.spacingXs },
|
|
42
|
+
badgeText: { fontSize: t.fontSizeMd, color: t.textPrimary },
|
|
43
|
+
fields: { gap: t.spacingMd, paddingHorizontal: DT_CARD_PAD, paddingBottom: t.spacingLg },
|
|
44
|
+
fieldLine: { flexDirection: 'row', gap: t.spacingLg },
|
|
45
|
+
moreFields: { paddingTop: DT_CARD_HEAD_PAD_BOTTOM, borderTopWidth: 1, borderStyle: 'dashed', borderTopColor: c.line },
|
|
46
|
+
field: { flex: 1, minWidth: 0 },
|
|
47
|
+
fieldName: { fontSize: t.fontSizeXxs, fontWeight: String(t.fontWeightBold), letterSpacing: t.fontSizeXxs * DT_FIELD_NAME_LETTER_SPACING_EM, textTransform: 'uppercase', color: t.textSecondary },
|
|
48
|
+
fieldValue: { marginTop: t.spacingXxs, fontSize: t.fontSizeMd, color: t.textPrimary },
|
|
49
|
+
foot: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXxs, marginTop: 'auto', paddingVertical: t.spacingXs, paddingRight: t.spacingSm, paddingLeft: DT_CARD_PAD, borderTopWidth: 1, borderTopColor: c.lineSoft, minHeight: DT_CARD_FOOT_MIN_HEIGHT },
|
|
50
|
+
expand: { width: expand, height: expand, alignItems: 'center', justifyContent: 'center', borderRadius: 10 },
|
|
51
|
+
expandIcon: phone ? t.controlSizeLg : t.iconSizeAction,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function splitLook(t, phone, both, narrowList) {
|
|
55
|
+
const c = tableColors(t);
|
|
56
|
+
return {
|
|
57
|
+
split: { flex: 1, flexDirection: 'row', alignItems: 'stretch', backgroundColor: c.surface },
|
|
58
|
+
side: both
|
|
59
|
+
? { flexGrow: 0, flexShrink: 0, flexBasis: narrowList ? DT_SPLIT_SIDE_NARROW : DT_SPLIT_SIDE, maxWidth: DT_SPLIT_SIDE_MAX, borderRightWidth: 1, borderRightColor: c.lineSoft }
|
|
60
|
+
: { flex: 1, minWidth: 0 },
|
|
61
|
+
pane: { flex: 1, minWidth: 0, backgroundColor: c.surface },
|
|
62
|
+
item: {
|
|
63
|
+
flexDirection: 'row', alignItems: 'center', gap: 10,
|
|
64
|
+
paddingVertical: DT_SPLIT_ITEM_PAD_Y, paddingHorizontal: t.spacingLg,
|
|
65
|
+
borderBottomWidth: 1, borderBottomColor: c.lineSoft, backgroundColor: c.surface,
|
|
66
|
+
...(phone ? { minHeight: DT_SPLIT_ITEM_PHONE_MIN_HEIGHT } : {}),
|
|
67
|
+
},
|
|
68
|
+
itemPressed: { backgroundColor: c.rowHover },
|
|
69
|
+
itemOpen: { backgroundColor: c.accentSoft, boxShadow: [{ offsetX: DT_SPLIT_OPEN_BAR, offsetY: 0, blurRadius: 0, spreadDistance: 0, color: t.accentPrimary, inset: true }] },
|
|
70
|
+
text: { flex: 1, minWidth: 0, gap: 1 },
|
|
71
|
+
line: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', rowGap: t.spacingXxs, columnGap: t.spacingMd, minWidth: 0 },
|
|
72
|
+
title: { flexGrow: 1, flexShrink: 1, minWidth: 0, fontSize: t.fontSizeMd, fontWeight: String(t.fontWeightBold), color: t.textPrimary },
|
|
73
|
+
subtitle: { fontSize: t.fontSizeXs, color: t.textSecondary },
|
|
74
|
+
badge: { flexShrink: 1, flexDirection: 'row', flexWrap: 'wrap', gap: t.spacingXs, maxWidth: '100%', minWidth: 0 },
|
|
75
|
+
badgeText: { fontSize: t.fontSizeMd, color: t.textPrimary },
|
|
76
|
+
actions: { flexShrink: 0, marginRight: -DT_SPLIT_ACTIONS_TUCK },
|
|
77
|
+
group: { paddingVertical: t.spacingSm, paddingHorizontal: t.spacingLg, backgroundColor: c.surface },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function emptyLook(t) {
|
|
81
|
+
return {
|
|
82
|
+
box: { paddingVertical: DT_EMPTY_PAD_Y, paddingHorizontal: t.spacingXl, alignItems: 'center', backgroundColor: tableColors(t).surface },
|
|
83
|
+
text: { textAlign: 'center', color: t.textSecondary, fontSize: t.fontSizeMd },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function pagerLook(t) {
|
|
87
|
+
return {
|
|
88
|
+
bar: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXs, padding: t.spacingSm, minHeight: DT_PAGER_MIN_HEIGHT, borderTopWidth: 1, borderTopColor: tableColors(t).lineSoft, backgroundColor: tableColors(t).surface },
|
|
89
|
+
info: { paddingHorizontal: t.spacingXxs, color: t.textPrimary, fontSize: t.fontSizeSm },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function detailLook(t) {
|
|
93
|
+
const c = tableColors(t);
|
|
94
|
+
return {
|
|
95
|
+
bar: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, minHeight: DT_DETAIL_BAR_MIN_HEIGHT, paddingVertical: t.spacingXs, paddingLeft: t.spacingLg, paddingRight: t.spacingMd, borderBottomWidth: 1, borderBottomColor: c.lineSoft, backgroundColor: t.bgSecondary },
|
|
96
|
+
nav: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXxs },
|
|
97
|
+
position: { paddingHorizontal: t.spacingXs, fontSize: t.fontSizeSm, color: t.textSecondary, fontVariant: ['tabular-nums'] },
|
|
98
|
+
navButton: { width: DT_DETAIL_NAV_BUTTON, height: DT_DETAIL_NAV_BUTTON, alignItems: 'center', justifyContent: 'center', borderRadius: DT_DETAIL_NAV_RADIUS },
|
|
99
|
+
body: { paddingTop: t.spacingXl, paddingHorizontal: 20, paddingBottom: t.spacing2xl },
|
|
100
|
+
empty: { flex: 1, alignItems: 'center', justifyContent: 'center', minHeight: DT_DETAIL_EMPTY_MIN_HEIGHT, padding: t.spacing2xl },
|
|
101
|
+
emptyText: { color: t.textTertiary, fontSize: t.fontSizeMd },
|
|
102
|
+
fields: { gap: t.spacingMd },
|
|
103
|
+
field: { flexDirection: 'row', gap: t.spacingMd, paddingVertical: t.spacingSm, borderBottomWidth: 1, borderBottomColor: t.borderColor },
|
|
104
|
+
fieldLast: { borderBottomWidth: 0 },
|
|
105
|
+
label: { minWidth: DT_DETAIL_LABEL_MIN_WIDTH, flexShrink: 0, fontSize: t.fontSizeSm, fontWeight: String(t.fontWeightSemibold), color: t.textSecondary },
|
|
106
|
+
value: { flex: 1, fontSize: t.fontSizeSm, color: t.textPrimary },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function viewTabsLook(t, phone) {
|
|
110
|
+
return phone
|
|
111
|
+
? { frame: { paddingTop: t.spacingLg, paddingHorizontal: t.spacingLg, paddingBottom: t.spacingXs, backgroundColor: tableColors(t).surface }, tabs: { flexDirection: 'row', alignItems: 'center', gap: t.spacingSm } }
|
|
112
|
+
: { frame: { paddingHorizontal: t.spacingXl, backgroundColor: tableColors(t).surface, borderBottomWidth: 1, borderBottomColor: tableColors(t).lineSoft }, tabs: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXs } };
|
|
113
|
+
}
|
|
114
|
+
export function viewTabLook(t, phone, active) {
|
|
115
|
+
const weight = (w) => String(w);
|
|
116
|
+
if (phone) {
|
|
117
|
+
return {
|
|
118
|
+
tab: { height: DT_VIEW_TAB_HEIGHT_PHONE, justifyContent: 'center', paddingHorizontal: t.spacingLg, borderRadius: t.borderRadiusLg, backgroundColor: active ? t.accentPrimary : t.bgTertiary },
|
|
119
|
+
text: { fontSize: t.fontSizeSm, fontWeight: weight(t.fontWeightBold), color: active ? t.onPrimary : t.textPrimary },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
tab: {
|
|
124
|
+
height: DT_VIEW_TAB_HEIGHT, justifyContent: 'center', paddingHorizontal: t.spacingLg,
|
|
125
|
+
...(active ? { boxShadow: [{ offsetX: 0, offsetY: -DT_VIEW_TAB_BAR, blurRadius: 0, spreadDistance: 0, color: t.accentPrimary, inset: true }] } : {}),
|
|
126
|
+
},
|
|
127
|
+
text: { fontSize: t.fontSizeMd, fontWeight: weight(active ? t.fontWeightBold : t.fontWeightSemibold), color: active ? t.accentPrimaryText : t.textSecondary },
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function toolbarLook(t, phone) {
|
|
131
|
+
return {
|
|
132
|
+
bar: phone
|
|
133
|
+
? { flexDirection: 'row', alignItems: 'center', minHeight: DT_TOOLBAR_MIN_HEIGHT_PHONE, padding: t.spacingSm, backgroundColor: tableColors(t).surface }
|
|
134
|
+
: { flexDirection: 'row', alignItems: 'center', minHeight: DT_TOOLBAR_MIN_HEIGHT, gap: t.spacingMd, paddingVertical: DT_TOOLBAR_PAD_Y, paddingHorizontal: t.spacingLg, backgroundColor: tableColors(t).surface },
|
|
135
|
+
search: phone ? { flex: 1, minWidth: 0 } : { flexGrow: 1, flexShrink: 1, flexBasis: DT_SEARCH_BASIS, minWidth: DT_SEARCH_MIN, maxWidth: DT_SEARCH_MAX },
|
|
136
|
+
quick: { flexGrow: 0, flexShrink: 1, flexBasis: DT_QUICK_BASIS, minWidth: DT_QUICK_MIN, maxWidth: DT_QUICK_MAX },
|
|
137
|
+
tools: { flexDirection: 'row', alignItems: 'center', marginLeft: 'auto', gap: phone ? 0 : t.spacingXxs },
|
|
138
|
+
button: phone ? DT_TOOLBAR_BUTTON_PHONE : DT_TOOLBAR_BUTTON,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function iconButtonLook(t, size, active, pressed) {
|
|
142
|
+
const c = tableColors(t);
|
|
143
|
+
const lit = active || pressed;
|
|
144
|
+
return {
|
|
145
|
+
box: {
|
|
146
|
+
width: size, height: size, alignItems: 'center', justifyContent: 'center',
|
|
147
|
+
borderWidth: 1, borderRadius: t.borderRadiusSm,
|
|
148
|
+
borderColor: active ? mixColors(t.accentPrimary, DT_ACTIVE_EDGE_MIX, c.line) : 'transparent',
|
|
149
|
+
backgroundColor: lit ? c.accentSoft : 'transparent',
|
|
150
|
+
},
|
|
151
|
+
color: lit ? t.accentPrimaryText : t.textSecondary,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const fw = (w) => String(w);
|
|
155
|
+
export function statusLook(t, phone, mode) {
|
|
156
|
+
const c = tableColors(t);
|
|
157
|
+
const bg = mode === 'selecting'
|
|
158
|
+
? mixColors(t.accentPrimary, DT_STATUS_SELECTING_MIX, t.bgSecondary)
|
|
159
|
+
: mode === 'idle' ? mixColors(t.bgPrimary, DT_STATUS_IDLE_MIX, t.bgSecondary) : c.surface;
|
|
160
|
+
const small = { fontSize: t.fontSizeSm };
|
|
161
|
+
const linkBase = { height: DT_STATUS_CHIP_HEIGHT, paddingHorizontal: DT_STATUS_LINK_PAD, borderRadius: DT_STATUS_LINK_RADIUS, justifyContent: 'center' };
|
|
162
|
+
return {
|
|
163
|
+
row: { height: phone ? DT_STATUS_ROW_HEIGHT_PHONE : DT_STATUS_ROW_HEIGHT, borderTopWidth: 1, borderBottomWidth: 1, borderColor: c.lineSoft, backgroundColor: bg, overflow: 'hidden' },
|
|
164
|
+
inner: { flexGrow: 1, flexDirection: 'row', alignItems: 'center', gap: phone ? t.spacingSm : t.spacingMd, paddingHorizontal: (phone ? t.spacingSm : t.spacingMd) + t.spacingXs },
|
|
165
|
+
summary: { ...small, color: t.textSecondary },
|
|
166
|
+
order: { ...small, color: t.textSecondary },
|
|
167
|
+
selected: { ...small, fontWeight: fw(t.fontWeightBold), color: t.accentPrimaryText },
|
|
168
|
+
link: linkBase,
|
|
169
|
+
linkText: { ...small, fontWeight: fw(t.fontWeightSemibold), color: t.accentPrimaryText },
|
|
170
|
+
clearText: { ...small, fontWeight: fw(t.fontWeightSemibold), color: t.textSecondary },
|
|
171
|
+
linkPressed: { backgroundColor: t.hoverOverlay },
|
|
172
|
+
chip: {
|
|
173
|
+
height: DT_STATUS_CHIP_HEIGHT, flexDirection: 'row', alignItems: 'center', gap: t.spacingXs,
|
|
174
|
+
paddingLeft: DT_STATUS_CHIP_PAD_START, paddingRight: DT_STATUS_CHIP_PAD_END,
|
|
175
|
+
borderRadius: DT_STATUS_CHIP_HEIGHT / 2, backgroundColor: t.bgTertiary,
|
|
176
|
+
},
|
|
177
|
+
chipBody: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXs, flexShrink: 1 },
|
|
178
|
+
chipText: { ...small, fontWeight: fw(t.fontWeightSemibold), color: t.textSecondary },
|
|
179
|
+
filterChip: { backgroundColor: c.accentSoft },
|
|
180
|
+
filterChipText: { color: t.accentPrimaryText },
|
|
181
|
+
chipOperator: { ...small, opacity: DT_CHIP_OPERATOR_OPACITY },
|
|
182
|
+
chipValue: { ...small, maxWidth: DT_CHIP_VALUE_MAX },
|
|
183
|
+
chipIcon: t.iconSizeMarker,
|
|
184
|
+
chipRemove: { width: DT_STATUS_CHIP_REMOVE, height: DT_STATUS_CHIP_REMOVE, borderRadius: DT_STATUS_CHIP_REMOVE / 2, alignItems: 'center', justifyContent: 'center' },
|
|
185
|
+
chipRemovePressed: { backgroundColor: t.hoverOverlay },
|
|
186
|
+
divider: { width: 1, height: DT_STATUS_DIVIDER_HEIGHT, marginHorizontal: t.spacingSm, backgroundColor: mixColors(t.accentPrimary, DT_STATUS_DIVIDER_MIX, c.line) },
|
|
187
|
+
dividerSoft: { width: 1, height: DT_STATUS_DIVIDER_SOFT_HEIGHT, marginHorizontal: t.spacingXxs, backgroundColor: c.line },
|
|
188
|
+
spacer: { flexGrow: 1, minWidth: DT_STATUS_SPACER_MIN },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function bulkButtonLook(t, variant, first, state) {
|
|
192
|
+
const c = tableColors(t);
|
|
193
|
+
const v = variant ?? 'primary';
|
|
194
|
+
const color = v === 'success' ? t.success : v === 'warning' ? t.warning : v === 'danger' ? t.error : v === 'secondary' ? t.textSecondary : t.accentPrimary;
|
|
195
|
+
const on = v === 'success' ? t.onSuccess : v === 'warning' ? t.onWarning : v === 'danger' ? t.onError : t.onPrimary;
|
|
196
|
+
const ink = first ? on : mixColors(color, DT_BULK_TEXT_MIX, t.textPrimary);
|
|
197
|
+
return {
|
|
198
|
+
box: {
|
|
199
|
+
height: DT_BULK_BUTTON_HEIGHT, flexDirection: 'row', alignItems: 'center', gap: t.spacingSm,
|
|
200
|
+
paddingHorizontal: t.spacingLg, borderRadius: t.borderRadiusSm, borderWidth: 1,
|
|
201
|
+
borderColor: first ? 'transparent' : mixColors(color, DT_BULK_EDGE_MIX, c.line),
|
|
202
|
+
backgroundColor: first ? color : state.pressed ? mixColors(color, DT_ACCENT_SOFT_MIX, t.bgSecondary) : t.bgSecondary,
|
|
203
|
+
opacity: state.busy ? DT_BULK_BUSY_OPACITY : state.disabled ? DT_BULK_DISABLED_OPACITY : 1,
|
|
204
|
+
},
|
|
205
|
+
text: { fontSize: t.fontSizeSm, fontWeight: fw(first ? t.fontWeightBold : t.fontWeightSemibold), color: ink },
|
|
206
|
+
color: ink,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function cardCheckLook() {
|
|
210
|
+
return {
|
|
211
|
+
box: { position: 'absolute', top: DT_CARD_CHECK_TOP, left: DT_CARD_CHECK_LEFT, width: DT_CARD_CHECK_BOX, height: DT_CARD_CHECK_BOX, alignItems: 'center', justifyContent: 'center', zIndex: 1 },
|
|
212
|
+
headPad: DT_CARD_CHECK_HEAD_PAD,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
export function cardTickedLook(t) {
|
|
216
|
+
return { borderColor: t.accentPrimary, boxShadow: [{ offsetX: 0, offsetY: 0, blurRadius: 0, spreadDistance: 1, color: t.accentPrimary }] };
|
|
217
|
+
}
|
|
218
|
+
export const splitCheckLook = () => ({ width: DT_SPLIT_CHECK_WIDTH, height: DT_SPLIT_CHECK_HEIGHT, alignItems: 'center', justifyContent: 'center', flexShrink: 0 });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Text, View } from 'react-native';
|
|
4
|
+
import { betweenValueOf, conditionWithColumn, conditionWithOperator, dateFilterValueOf, filterColumnOptions, filterOperatorsFor, filterValueInput, filterValueOptions, operatorLabel, } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../../UIProvider/context';
|
|
6
|
+
import { Select } from '../../Select/Select';
|
|
7
|
+
import { Input } from '../../Input/Input';
|
|
8
|
+
import { Switch } from '../../Switch/Switch';
|
|
9
|
+
import { Button } from '../../Button/Button';
|
|
10
|
+
import { DatePicker } from '../../DatePicker/DatePicker';
|
|
11
|
+
import { IconDelete } from '../../Icon';
|
|
12
|
+
import { filterLook } from './filterStyle';
|
|
13
|
+
const NO_MARGIN = { marginBottom: 0 };
|
|
14
|
+
export function FilterConditionRow({ condition, columns, onChange, onRemove, L, operators, rows }) {
|
|
15
|
+
const t = useTokens();
|
|
16
|
+
const look = filterLook(t);
|
|
17
|
+
const columnOptions = useMemo(() => filterColumnOptions(columns), [columns]);
|
|
18
|
+
const column = useMemo(() => columns.find(c => c.key === condition.column), [columns, condition.column]);
|
|
19
|
+
const type = column?.type || 'string';
|
|
20
|
+
const operatorOptions = useMemo(() => filterOperatorsFor(type, operators).map(op => ({ name: operatorLabel(op, L), value: op })), [type, operators, L]);
|
|
21
|
+
const valueOptions = useMemo(() => filterValueOptions(column, rows), [column, rows]);
|
|
22
|
+
const set = (value) => onChange({ ...condition, value });
|
|
23
|
+
const valueInput = () => {
|
|
24
|
+
const input = filterValueInput(type, condition.operator, valueOptions.length > 0);
|
|
25
|
+
switch (input.kind) {
|
|
26
|
+
case 'none':
|
|
27
|
+
return null;
|
|
28
|
+
case 'date': {
|
|
29
|
+
const ends = dateFilterValueOf(condition.value);
|
|
30
|
+
return input.range ? (_jsx(DatePicker, { range: true, size: "small", value: ends, onChange: e => set({ from: e.target.value.from, to: e.target.value.to }), "aria-label": L.filterValue, style: NO_MARGIN })) : (_jsx(DatePicker, { size: "small", value: ends.from, onChange: e => set(e.target.value), "aria-label": L.filterValue, style: NO_MARGIN }));
|
|
31
|
+
}
|
|
32
|
+
case 'between': {
|
|
33
|
+
const { from, to } = betweenValueOf(condition.value);
|
|
34
|
+
return (_jsxs(View, { style: look.between, children: [_jsx(View, { style: { flex: 1 }, children: _jsx(Input, { type: "number", size: "small", placeholder: L.filterFrom, "aria-label": L.filterFrom, value: from, onChangeText: v => set({ from: v, to }), style: NO_MARGIN }) }), _jsx(Text, { style: look.betweenText, children: L.filterRangeSeparator }), _jsx(View, { style: { flex: 1 }, children: _jsx(Input, { type: "number", size: "small", placeholder: L.filterTo, "aria-label": L.filterTo, value: to, onChangeText: v => set({ from, to: v }), style: NO_MARGIN }) })] }));
|
|
35
|
+
}
|
|
36
|
+
case 'options':
|
|
37
|
+
return (_jsx(Select, { size: "small", options: valueOptions, value: input.multi ? (Array.isArray(condition.value) ? condition.value : []) : condition.value ?? '', onChange: e => set(e.target.value), multiSelect: input.multi, search: valueOptions.length > 8, clearable: true, "aria-label": L.filterValue, style: NO_MARGIN }));
|
|
38
|
+
case 'number':
|
|
39
|
+
case 'count':
|
|
40
|
+
return (_jsx(Input, { type: "number", size: "small", placeholder: input.kind === 'count' ? L.filterCount : L.filterValue, "aria-label": input.kind === 'count' ? L.filterCount : L.filterValue, value: String(condition.value ?? ''), onChangeText: set, clearable: true, style: NO_MARGIN }));
|
|
41
|
+
case 'list':
|
|
42
|
+
return (_jsx(Input, { size: "small", placeholder: L.filterCommaValues, "aria-label": L.filterValue, value: Array.isArray(condition.value) ? condition.value.join(', ') : String(condition.value ?? ''), onChangeText: v => set(v ? v.split(',').map(s => s.trim()) : []), clearable: true, style: NO_MARGIN }));
|
|
43
|
+
case 'text':
|
|
44
|
+
return (_jsx(Input, { size: "small", placeholder: L.filterValue, "aria-label": L.filterValue, value: String(condition.value ?? ''), onChangeText: set, clearable: true, style: NO_MARGIN }));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return (_jsxs(View, { style: look.condition(condition.enabled), children: [_jsxs(View, { style: look.fields, children: [_jsx(Select, { size: "small", options: columnOptions, value: condition.column, onChange: e => onChange(conditionWithColumn(condition, String(e.target.value), columns, operators)), placeholder: L.filterColumnPlaceholder, "aria-label": L.filterColumnPlaceholder, search: columnOptions.length > 8, style: NO_MARGIN }), _jsx(Select, { size: "small", options: operatorOptions, value: condition.operator, onChange: e => onChange(conditionWithOperator(condition, String(e.target.value))), search: false, "aria-label": L.filterOperator, style: NO_MARGIN }), valueInput()] }), _jsxs(View, { style: look.conditionActions, children: [_jsx(Switch, { size: "small", justSwitch: true, checked: condition.enabled, onCheckedChange: on => onChange({ ...condition, enabled: on }), "aria-label": L.filterEnabled }), _jsx(Button, { icon: _jsx(IconDelete, {}), variant: "text", color: "error", size: "small", onPress: onRemove, "aria-label": L.filterRemoveCondition })] })] }));
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import { emptyFilterCondition, emptyFilterSubgroup, isFilterGroup } from '@dcs-tech/core';
|
|
4
|
+
import { useTokens } from '../../UIProvider/context';
|
|
5
|
+
import { Switch } from '../../Switch/Switch';
|
|
6
|
+
import { Button } from '../../Button/Button';
|
|
7
|
+
import { IconAdd, IconDelete, IconFolder } from '../../Icon';
|
|
8
|
+
import { FilterConditionRow } from './FilterConditionRow';
|
|
9
|
+
import { filterLook } from './filterStyle';
|
|
10
|
+
export function FilterGroupEditor({ group, columns, onChange, onRemove, L, operators, rows, depth = 0 }) {
|
|
11
|
+
const t = useTokens();
|
|
12
|
+
const look = filterLook(t);
|
|
13
|
+
const or = group.logic === 'OR';
|
|
14
|
+
const replace = (index, next) => onChange({ ...group, conditions: group.conditions.map((c, i) => (i === index ? next : c)) });
|
|
15
|
+
const remove = (index) => onChange({ ...group, conditions: group.conditions.filter((_, i) => i !== index) });
|
|
16
|
+
const tab = (logic, label) => {
|
|
17
|
+
const on = group.logic === logic;
|
|
18
|
+
return (_jsx(Pressable, { role: "tab", "aria-selected": on, accessibilityState: { selected: on }, onPress: () => onChange({ ...group, logic }), style: look.tab(on), children: _jsx(Text, { style: look.tabText(on, logic === 'OR'), children: label }) }));
|
|
19
|
+
};
|
|
20
|
+
return (_jsxs(View, { style: look.group(or, depth), children: [_jsxs(View, { style: look.groupHead, children: [_jsxs(View, { style: look.tabs, role: "tablist", children: [tab('AND', L.filterAnd), tab('OR', L.filterOr)] }), depth > 0 && (_jsxs(View, { style: look.groupHeadRight, children: [_jsx(Switch, { size: "small", label: L.filterNot, labelPosition: "start", checked: !!group.negated, onCheckedChange: on => onChange({ ...group, negated: on }) }), onRemove && _jsx(Button, { icon: _jsx(IconDelete, {}), variant: "text", color: "error", size: "small", onPress: onRemove, "aria-label": L.filterRemoveGroup })] }))] }), group.conditions.map((item, index) => (isFilterGroup(item) ? (_jsx(FilterGroupEditor, { group: item, columns: columns, onChange: next => replace(index, next), onRemove: () => remove(index), L: L, operators: operators, rows: rows, depth: depth + 1 }, item.id)) : (_jsx(FilterConditionRow, { condition: item, columns: columns, onChange: next => replace(index, next), onRemove: () => remove(index), L: L, operators: operators, rows: rows }, item.id)))), _jsxs(View, { style: look.groupActions, children: [_jsx(Button, { startIcon: _jsx(IconAdd, {}), label: L.filterAddCondition, variant: "text", size: "small", onPress: () => onChange({ ...group, conditions: [...group.conditions, emptyFilterCondition()] }) }), _jsx(Button, { startIcon: _jsx(IconFolder, {}), label: L.filterAddGroup, variant: "text", size: "small", onPress: () => onChange({ ...group, conditions: [...group.conditions, emptyFilterSubgroup()] }) })] })] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
4
|
+
import { countActiveConditions, createEmptyFilterGroup, newSavedFilter, savedFilterActions, updatedSavedFilter, withBlankCondition } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../../UIProvider/context';
|
|
6
|
+
import { Dialog } from '../../Dialog/Dialog';
|
|
7
|
+
import { Button } from '../../Button/Button';
|
|
8
|
+
import { IconBraces, IconChevronDown, IconFilter } from '../../Icon';
|
|
9
|
+
import { FilterGroupEditor } from './FilterGroupEditor';
|
|
10
|
+
import { SavedFilterBar } from './SavedFilterBar';
|
|
11
|
+
import { filterLook } from './filterStyle';
|
|
12
|
+
const copy = (group) => JSON.parse(JSON.stringify(group));
|
|
13
|
+
export function FilterSheet({ state }) {
|
|
14
|
+
const t = useTokens();
|
|
15
|
+
const look = filterLook(t);
|
|
16
|
+
const { L } = state;
|
|
17
|
+
const [local, setLocal] = useState(() => copy(state.filterGroup));
|
|
18
|
+
const [jsonOpen, setJsonOpen] = useState(false);
|
|
19
|
+
const [activeId, setActiveId] = useState(null);
|
|
20
|
+
const [name, setName] = useState(null);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (state.filtersOpen) {
|
|
23
|
+
setLocal(copy(state.filterGroup));
|
|
24
|
+
setJsonOpen(false);
|
|
25
|
+
setActiveId(null);
|
|
26
|
+
setName(null);
|
|
27
|
+
}
|
|
28
|
+
}, [state.filtersOpen]);
|
|
29
|
+
const shown = useMemo(() => withBlankCondition(local), [local]);
|
|
30
|
+
const count = countActiveConditions(local);
|
|
31
|
+
const close = () => state.setFiltersOpen(false);
|
|
32
|
+
const apply = () => { state.setFilterGroup(local); close(); };
|
|
33
|
+
const saved = state.allSavedFilters;
|
|
34
|
+
const offer = savedFilterActions({ saved, activeId, group: local, activeCount: count, canSave: state.canSaveFilters });
|
|
35
|
+
const pick = (id) => {
|
|
36
|
+
const preset = id ? saved.find(sf => sf.id === id) : undefined;
|
|
37
|
+
if (!preset) {
|
|
38
|
+
setActiveId(null);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (preset.disabled)
|
|
42
|
+
return;
|
|
43
|
+
setLocal(copy(preset.filterGroup));
|
|
44
|
+
setActiveId(preset.id);
|
|
45
|
+
};
|
|
46
|
+
const remove = (id) => {
|
|
47
|
+
state.deleteFilter(id);
|
|
48
|
+
if (activeId === id)
|
|
49
|
+
setActiveId(null);
|
|
50
|
+
};
|
|
51
|
+
const update = () => {
|
|
52
|
+
const existing = saved.find(sf => sf.id === activeId);
|
|
53
|
+
if (existing)
|
|
54
|
+
state.saveFilter(updatedSavedFilter(existing, local));
|
|
55
|
+
};
|
|
56
|
+
const saveAsNew = () => {
|
|
57
|
+
if (!name || !name.trim())
|
|
58
|
+
return;
|
|
59
|
+
const preset = newSavedFilter(name, local);
|
|
60
|
+
state.saveFilter(preset);
|
|
61
|
+
setActiveId(preset.id);
|
|
62
|
+
setName(null);
|
|
63
|
+
};
|
|
64
|
+
const title = (_jsxs(View, { style: look.headRow, children: [_jsx(View, { style: look.tile, children: _jsx(IconFilter, { size: "action", color: t.onPrimary }) }), _jsxs(View, { style: { flex: 1 }, children: [_jsxs(View, { style: look.titleRow, children: [_jsx(Text, { role: "heading", style: look.title, children: L.filterTitle }), count > 0 && _jsx(View, { style: look.badge, children: _jsx(Text, { style: look.badgeText, children: state.format.number(count) }) })] }), _jsx(Text, { style: look.subtitle, children: L.filterHint })] })] }));
|
|
65
|
+
const footer = (_jsxs(View, { style: look.foot, children: [_jsx(Button, { label: L.clearAll, variant: "text", color: "error", size: "small", onPress: () => { setLocal(createEmptyFilterGroup()); setActiveId(null); } }), _jsxs(View, { style: look.footRight, children: [_jsx(Button, { label: L.cancel, variant: "outlined", size: "small", onPress: close }), _jsx(Button, { label: L.apply, variant: "filled", size: "small", onPress: apply })] })] }));
|
|
66
|
+
return (_jsxs(Dialog, { open: state.filtersOpen, onClose: close, placement: "bottom", title: title, footer: footer, "aria-label": L.filterTitle, children: [(saved.length > 0 || state.canSaveFilters) && (_jsx(SavedFilterBar, { saved: saved, columns: state.columns, activeId: activeId, onPick: pick, onDelete: state.canSaveFilters ? remove : undefined, offer: offer, onUpdate: update, name: name, onName: setName, onSaveAsNew: saveAsNew, L: L, format: state.format })), _jsx(FilterGroupEditor, { group: shown, columns: state.columns, onChange: setLocal, L: L, operators: state.operators, rows: state.filterOptionRows }), _jsxs(View, { style: look.json, children: [_jsxs(Pressable, { role: "button", "aria-expanded": jsonOpen, onPress: () => setJsonOpen(v => !v), style: ({ pressed }) => look.jsonToggle(pressed), children: [_jsx(IconBraces, { size: "sm", color: t.textSecondary }), _jsx(Text, { style: look.jsonToggleText, children: L.filterJson }), _jsx(View, { style: { transform: [{ rotate: jsonOpen ? '180deg' : '0deg' }] }, children: _jsx(IconChevronDown, { size: "sm", color: t.textSecondary }) })] }), jsonOpen && (_jsx(ScrollView, { style: look.jsonBody, nestedScrollEnabled: true, children: _jsx(Text, { selectable: true, style: look.jsonText, children: JSON.stringify(shown, null, 2) }) }))] })] }));
|
|
67
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { countFilterConditions, savedFilterOffText } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../../UIProvider/context';
|
|
6
|
+
import { Select } from '../../Select/Select';
|
|
7
|
+
import { Input } from '../../Input/Input';
|
|
8
|
+
import { Button } from '../../Button/Button';
|
|
9
|
+
import { IconBookmark, IconBookmarkAdd, IconDelete, IconEdit, IconStar } from '../../Icon';
|
|
10
|
+
import { filterLook } from './filterStyle';
|
|
11
|
+
const NO_MARGIN = { marginBottom: 0 };
|
|
12
|
+
export function SavedFilterBar(p) {
|
|
13
|
+
const t = useTokens();
|
|
14
|
+
const look = filterLook(t);
|
|
15
|
+
const { L } = p;
|
|
16
|
+
const has = p.saved.length > 0;
|
|
17
|
+
const options = useMemo(() => p.saved.map(sf => ({
|
|
18
|
+
name: sf.label,
|
|
19
|
+
value: sf.id,
|
|
20
|
+
group: sf.isDefault ? L.filterDefaultGroup : L.savedFilterGroup,
|
|
21
|
+
...(sf.disabled ? { disabled: true } : {}),
|
|
22
|
+
metadata: { isDefault: !!sf.isDefault, count: countFilterConditions(sf.filterGroup), off: sf.disabled ? savedFilterOffText(sf.disabled, p.columns, L) : undefined },
|
|
23
|
+
})), [p.saved, p.columns, L]);
|
|
24
|
+
const closeBox = () => p.onName(null);
|
|
25
|
+
const typed = (p.name ?? '').trim();
|
|
26
|
+
return (_jsxs(View, { style: look.saved, children: [_jsxs(View, { style: look.savedRow, children: [has && (_jsx(View, { style: look.savedSelect, children: _jsx(Select, { size: "small", options: options, value: p.activeId ?? '', onChange: e => {
|
|
27
|
+
const id = String(e.target.value ?? '');
|
|
28
|
+
p.onPick(id || null);
|
|
29
|
+
}, placeholder: L.filterLoadSaved, "aria-label": L.filterLoadSaved, clearable: true, search: true, group: {
|
|
30
|
+
enabled: true,
|
|
31
|
+
renderGroupHeader: (title, count) => (_jsxs(View, { style: look.optionHead, children: [_jsx(Text, { style: look.optionHeadText, children: title.toUpperCase() }), _jsx(View, { style: look.optionHeadCount, children: _jsx(Text, { style: look.optionHeadCountText, children: p.format.number(count) }) })] })),
|
|
32
|
+
}, renderOption: (option, selected) => {
|
|
33
|
+
const meta = option.metadata;
|
|
34
|
+
return (_jsxs(View, { style: look.option, children: [meta.isDefault
|
|
35
|
+
? _jsx(IconStar, { filled: true, size: "sm", color: t.warning })
|
|
36
|
+
: _jsx(IconBookmark, { filled: true, size: "sm", color: t.accentPrimary }), _jsxs(View, { style: look.optionLabel, children: [_jsx(Text, { style: look.optionName(selected, !!meta.off), numberOfLines: 1, children: option.name }), !!meta.off && _jsx(Text, { style: look.optionReason, numberOfLines: 1, children: meta.off })] }), _jsx(Text, { style: look.optionCount, children: L.filterConditionCount(p.format.number(meta.count), meta.count) }), !meta.isDefault && p.onDelete && (_jsx(Pressable, { role: "button", "aria-label": L.delete, hitSlop: t.spacingSm, onPress: () => p.onDelete(String(option.value)), style: ({ pressed }) => look.optionDelete(pressed), children: ({ pressed }) => _jsx(IconDelete, { size: "sm", color: pressed ? t.error : t.disabledText }) }))] }));
|
|
37
|
+
}, style: NO_MARGIN }) })), _jsxs(View, { style: look.savedActions, children: [p.offer.update && _jsx(Button, { icon: _jsx(IconEdit, {}), variant: "text", color: "primary", size: "small", onPress: p.onUpdate, "aria-label": L.filterUpdateSaved }), p.offer.saveAsNew && p.name === null && (_jsx(Button, { icon: _jsx(IconBookmarkAdd, {}), variant: "text", color: "neutral", size: "small", onPress: () => p.onName(''), "aria-label": L.filterSaveAsNew }))] })] }), p.name !== null && (_jsxs(View, { style: look.saveRow, children: [_jsx(View, { style: look.saveInput, children: _jsx(Input, { size: "small", placeholder: L.filterSaveName, "aria-label": L.filterSaveName, value: p.name, onChangeText: p.onName, autoFocus: true, returnKeyType: "done", onSubmitEditing: () => { if (typed)
|
|
38
|
+
p.onSaveAsNew(); }, style: NO_MARGIN }) }), _jsx(Button, { label: L.save, variant: "filled", size: "small", onPress: p.onSaveAsNew, disabled: !typed }), _jsx(Button, { label: L.cancel, variant: "text", size: "small", onPress: closeBox })] }))] }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { boxShadow } from '../../Button/buttonStyle';
|
|
3
|
+
import { DT_FM_BADGE, DT_FM_BADGE_PAD, DT_FM_CONDITION_OFF_OPACITY, DT_FM_CONDITION_PAD_Y, DT_FM_CONDITION_RADIUS, DT_FM_GROUP_EDGE, DT_FM_GROUP_GAP, DT_FM_HEAD_TRACKING, DT_FM_ICON_TILE, DT_FM_ICON_TILE_RADIUS, DT_FM_JSON_MAX, DT_FM_JSON_RADIUS, DT_FM_TAB_PAD_X, DT_FM_TAB_RADIUS, } from '../../styles/webValues';
|
|
4
|
+
const fw = (w) => String(w);
|
|
5
|
+
const MONO = Platform.select({ ios: 'Menlo', default: 'monospace' });
|
|
6
|
+
export function filterLook(t) {
|
|
7
|
+
return {
|
|
8
|
+
headRow: { flexDirection: 'row', alignItems: 'center', gap: t.spacingLg },
|
|
9
|
+
tile: {
|
|
10
|
+
width: DT_FM_ICON_TILE, height: DT_FM_ICON_TILE, borderRadius: DT_FM_ICON_TILE_RADIUS,
|
|
11
|
+
backgroundColor: t.accentPrimary, alignItems: 'center', justifyContent: 'center',
|
|
12
|
+
},
|
|
13
|
+
titleRow: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd },
|
|
14
|
+
title: { fontSize: t.fontSizeLg, fontWeight: fw(t.fontWeightBold), color: t.textPrimary },
|
|
15
|
+
badge: {
|
|
16
|
+
minWidth: DT_FM_BADGE, height: DT_FM_BADGE, borderRadius: DT_FM_BADGE / 2, paddingHorizontal: DT_FM_BADGE_PAD,
|
|
17
|
+
backgroundColor: t.accentPrimary, alignItems: 'center', justifyContent: 'center',
|
|
18
|
+
},
|
|
19
|
+
badgeText: { fontSize: t.fontSizeXxs, fontWeight: fw(t.fontWeightBold), color: t.onPrimary },
|
|
20
|
+
subtitle: { fontSize: t.fontSizeXs, color: t.textTertiary, marginTop: t.spacingXxs },
|
|
21
|
+
saved: { paddingBottom: t.spacingMd, marginBottom: t.spacingXl, borderBottomWidth: 1, borderBottomColor: t.borderColor, gap: t.spacingMd },
|
|
22
|
+
savedRow: { flexDirection: 'row', alignItems: 'center', gap: t.spacingSm },
|
|
23
|
+
savedSelect: { flex: 1, minWidth: 0 },
|
|
24
|
+
savedActions: { flexDirection: 'row', alignItems: 'center', gap: t.spacingXxs, marginLeft: 'auto' },
|
|
25
|
+
saveRow: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd },
|
|
26
|
+
saveInput: { flex: 1, minWidth: 0 },
|
|
27
|
+
option: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, paddingVertical: t.spacingXxs },
|
|
28
|
+
optionLabel: { flex: 1, minWidth: 0 },
|
|
29
|
+
optionName: (active, off) => ({
|
|
30
|
+
fontSize: t.fontSizeSm,
|
|
31
|
+
fontWeight: active ? fw(t.fontWeightSemibold) : undefined,
|
|
32
|
+
color: off ? t.textSecondary : active ? t.accentPrimaryText : t.textPrimary,
|
|
33
|
+
}),
|
|
34
|
+
optionReason: { fontSize: t.fontSizeXxs, color: t.textSecondary },
|
|
35
|
+
optionCount: { fontSize: t.fontSizeXxs, color: t.disabledText },
|
|
36
|
+
optionDelete: (pressed) => ({
|
|
37
|
+
padding: t.spacingXxs, borderRadius: t.borderRadiusSm, backgroundColor: pressed ? t.errorLight : 'transparent',
|
|
38
|
+
}),
|
|
39
|
+
optionHead: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
|
|
40
|
+
optionHeadText: { fontSize: t.fontSizeXxs, fontWeight: fw(t.fontWeightSemibold), letterSpacing: DT_FM_HEAD_TRACKING, color: t.disabledText },
|
|
41
|
+
optionHeadCount: { backgroundColor: t.hoverOverlay, paddingHorizontal: t.spacingSm, paddingVertical: 1, borderRadius: t.borderRadiusFull },
|
|
42
|
+
optionHeadCountText: { fontSize: t.fontSizeXxs, fontWeight: fw(t.fontWeightMedium), color: t.disabledText },
|
|
43
|
+
group: (or, depth) => ({
|
|
44
|
+
borderWidth: 1, borderColor: t.borderColor, borderLeftWidth: DT_FM_GROUP_EDGE, borderLeftColor: or ? t.warning : t.accentPrimary,
|
|
45
|
+
borderTopRightRadius: t.borderRadius, borderBottomRightRadius: t.borderRadius,
|
|
46
|
+
padding: t.spacingLg, gap: DT_FM_GROUP_GAP,
|
|
47
|
+
backgroundColor: depth === 0 ? t.bgPrimary : depth % 2 === 1 ? t.bgTertiary : t.bgSecondary,
|
|
48
|
+
}),
|
|
49
|
+
groupHead: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: DT_FM_GROUP_GAP },
|
|
50
|
+
tabs: { flexDirection: 'row', backgroundColor: t.bgTertiary, borderRadius: t.borderRadiusSm, padding: t.spacingXxs },
|
|
51
|
+
tab: (on) => ({
|
|
52
|
+
paddingVertical: t.spacingXs, paddingHorizontal: DT_FM_TAB_PAD_X, borderRadius: DT_FM_TAB_RADIUS,
|
|
53
|
+
backgroundColor: on ? t.bgSecondary : 'transparent',
|
|
54
|
+
boxShadow: on ? boxShadow(t.shadowMd) : undefined,
|
|
55
|
+
}),
|
|
56
|
+
tabText: (on, or) => ({
|
|
57
|
+
fontSize: t.fontSizeXxs, fontWeight: fw(t.fontWeightSemibold),
|
|
58
|
+
color: on ? (or ? t.warningText : t.accentPrimaryText) : t.textTertiary,
|
|
59
|
+
}),
|
|
60
|
+
groupHeadRight: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, marginLeft: 'auto' },
|
|
61
|
+
groupActions: { flexDirection: 'row', flexWrap: 'wrap', gap: t.spacingSm, paddingTop: t.spacingXs },
|
|
62
|
+
condition: (on) => ({
|
|
63
|
+
gap: t.spacingMd, paddingVertical: DT_FM_CONDITION_PAD_Y, paddingHorizontal: t.spacingLg,
|
|
64
|
+
borderWidth: 1, borderColor: t.borderColor, borderRadius: DT_FM_CONDITION_RADIUS, backgroundColor: t.bgSecondary,
|
|
65
|
+
opacity: on ? 1 : DT_FM_CONDITION_OFF_OPACITY,
|
|
66
|
+
}),
|
|
67
|
+
fields: { gap: t.spacingMd },
|
|
68
|
+
between: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd },
|
|
69
|
+
betweenText: { fontSize: t.fontSizeXs, color: t.textTertiary },
|
|
70
|
+
conditionActions: { flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: t.spacingXxs },
|
|
71
|
+
json: { marginTop: t.spacingLg, borderWidth: 1, borderColor: t.borderColor, borderRadius: DT_FM_JSON_RADIUS, overflow: 'hidden' },
|
|
72
|
+
jsonToggle: (pressed) => ({
|
|
73
|
+
flexDirection: 'row', alignItems: 'center', gap: t.spacingSm, paddingVertical: t.spacingMd, paddingHorizontal: t.spacingLg,
|
|
74
|
+
backgroundColor: pressed ? t.hoverOverlay : t.bgTertiary,
|
|
75
|
+
}),
|
|
76
|
+
jsonToggleText: { flex: 1, fontSize: t.fontSizeXxs, fontWeight: fw(t.fontWeightSemibold), color: t.textSecondary },
|
|
77
|
+
jsonBody: { maxHeight: DT_FM_JSON_MAX, padding: t.spacingLg, backgroundColor: t.bgPrimary, borderTopWidth: 1, borderTopColor: t.borderColor },
|
|
78
|
+
jsonText: { fontFamily: MONO, fontSize: t.fontSizeXxs, color: t.textSecondary },
|
|
79
|
+
foot: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: t.spacingMd },
|
|
80
|
+
footRight: { flexDirection: 'row', gap: t.spacingMd },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const isDoc = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
2
|
+
export function asyncStorageAdapter(storage, prefix = 'dt-prefs:') {
|
|
3
|
+
return {
|
|
4
|
+
async load(key) {
|
|
5
|
+
try {
|
|
6
|
+
const raw = await storage.getItem(prefix + key);
|
|
7
|
+
if (!raw)
|
|
8
|
+
return null;
|
|
9
|
+
const parsed = JSON.parse(raw);
|
|
10
|
+
return isDoc(parsed) ? parsed : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
async save(key, doc) {
|
|
17
|
+
try {
|
|
18
|
+
await storage.setItem(prefix + key, JSON.stringify(doc));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
async list(keyPrefix) {
|
|
24
|
+
try {
|
|
25
|
+
const keys = (await storage.getAllKeys?.()) ?? [];
|
|
26
|
+
return keys.filter(k => k.startsWith(prefix + keyPrefix)).map(k => k.slice(prefix.length));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async remove(key) {
|
|
33
|
+
try {
|
|
34
|
+
await storage.removeItem?.(prefix + key);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function memoryAdapter(initial = {}) {
|
|
42
|
+
const copy = (doc) => JSON.parse(JSON.stringify(doc));
|
|
43
|
+
const store = new Map(Object.entries(initial).map(([k, v]) => [k, copy(v)]));
|
|
44
|
+
return {
|
|
45
|
+
store,
|
|
46
|
+
async load(key) {
|
|
47
|
+
const v = store.get(key);
|
|
48
|
+
return v ? copy(v) : null;
|
|
49
|
+
},
|
|
50
|
+
async save(key, doc) {
|
|
51
|
+
store.set(key, copy(doc));
|
|
52
|
+
},
|
|
53
|
+
async list(keyPrefix) {
|
|
54
|
+
return [...store.keys()].filter(k => k.startsWith(keyPrefix));
|
|
55
|
+
},
|
|
56
|
+
async remove(key) {
|
|
57
|
+
store.delete(key);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function installedAsyncStorage() {
|
|
62
|
+
try {
|
|
63
|
+
const mod = require('@react-native-async-storage/async-storage');
|
|
64
|
+
const storage = (mod && (mod.default ?? mod));
|
|
65
|
+
return storage && typeof storage.getItem === 'function' ? storage : null;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let fallback = null;
|
|
72
|
+
export function defaultPersistence() {
|
|
73
|
+
if (!fallback) {
|
|
74
|
+
const storage = installedAsyncStorage();
|
|
75
|
+
fallback = storage ? asyncStorageAdapter(storage) : memoryAdapter();
|
|
76
|
+
}
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|