@dcs-tech/ui-native 0.0.0-stage → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +186 -0
- package/README.md +179 -2
- package/dist/components/Button/Button.js +61 -0
- package/dist/components/Button/buttonStyle.js +100 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Checkbox/Checkbox.js +60 -0
- package/dist/components/Checkbox/checkboxStyle.js +44 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/DataTable/BulkRun.js +85 -0
- package/dist/components/DataTable/CardList.js +70 -0
- package/dist/components/DataTable/DataTable.js +53 -0
- package/dist/components/DataTable/DataTableScrollView.js +33 -0
- package/dist/components/DataTable/DragSelect.js +153 -0
- package/dist/components/DataTable/LayoutSwitcher.js +48 -0
- package/dist/components/DataTable/Pager.js +15 -0
- package/dist/components/DataTable/RowActions.js +28 -0
- package/dist/components/DataTable/RowDetail.js +80 -0
- package/dist/components/DataTable/RowMenuSheet.js +72 -0
- package/dist/components/DataTable/SortSheet.js +25 -0
- package/dist/components/DataTable/SplitList.js +30 -0
- package/dist/components/DataTable/StatusRow.js +48 -0
- package/dist/components/DataTable/SwipeRow.js +125 -0
- package/dist/components/DataTable/ToolButton.js +9 -0
- package/dist/components/DataTable/Toolbar.js +53 -0
- package/dist/components/DataTable/cells.js +21 -0
- package/dist/components/DataTable/dataTableStyle.js +218 -0
- package/dist/components/DataTable/filters/FilterConditionRow.js +49 -0
- package/dist/components/DataTable/filters/FilterGroupEditor.js +21 -0
- package/dist/components/DataTable/filters/FilterSheet.js +69 -0
- package/dist/components/DataTable/filters/SavedFilterBar.js +39 -0
- package/dist/components/DataTable/filters/filterStyle.js +82 -0
- package/dist/components/DataTable/index.js +3 -0
- package/dist/components/DataTable/persistence/adapters.js +78 -0
- package/dist/components/DataTable/persistence/useViewPrefs.js +76 -0
- package/dist/components/DataTable/rowParts.js +47 -0
- package/dist/components/DataTable/useTableState.js +345 -0
- package/dist/components/DatePicker/Calendar.js +28 -0
- package/dist/components/DatePicker/DatePicker.js +300 -0
- package/dist/components/DatePicker/PeriodGrid.js +17 -0
- package/dist/components/DatePicker/PeriodPicker.js +216 -0
- package/dist/components/DatePicker/TimeField.js +50 -0
- package/dist/components/DatePicker/datePickerStyle.js +157 -0
- package/dist/components/DatePicker/index.js +2 -0
- package/dist/components/Dialog/Dialog.js +104 -0
- package/dist/components/Dialog/DialogHost.js +71 -0
- package/dist/components/Dialog/dialogStyle.js +72 -0
- package/dist/components/Dialog/index.js +2 -0
- package/dist/components/FieldContext/FieldContext.js +50 -0
- package/dist/components/FieldContext/index.js +1 -0
- package/dist/components/FieldWrapper/FieldWrapper.js +23 -0
- package/dist/components/FieldWrapper/fieldWrapperStyle.js +64 -0
- package/dist/components/FieldWrapper/index.js +1 -0
- package/dist/components/Icon/Icon.js +124 -0
- package/dist/components/Icon/IconContext.js +12 -0
- package/dist/components/Icon/iconStyle.js +59 -0
- package/dist/components/Icon/icons.js +252 -0
- package/dist/components/Icon/index.js +4 -0
- package/dist/components/Icon/useIconDone.js +19 -0
- package/dist/components/Input/Input.js +71 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/Input/inputStyle.js +47 -0
- package/dist/components/Press/Ripple.js +92 -0
- package/dist/components/Press/index.js +1 -0
- package/dist/components/Press/measure.js +3 -0
- package/dist/components/Radio/Radio.js +54 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/Radio/radioStyle.js +45 -0
- package/dist/components/Select/Select.js +83 -0
- package/dist/components/Select/SelectSheet.js +85 -0
- package/dist/components/Select/index.js +1 -0
- package/dist/components/Suggest/Suggest.js +101 -0
- package/dist/components/Suggest/index.js +1 -0
- package/dist/components/Switch/Switch.js +71 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Switch/switchStyle.js +59 -0
- package/dist/components/Toast/ToastHost.js +76 -0
- package/dist/components/Toast/ToastItem.js +115 -0
- package/dist/components/Toast/ToastLayer.js +21 -0
- package/dist/components/Toast/index.js +2 -0
- package/dist/components/Toast/toast.types.js +1 -0
- package/dist/components/Toast/toastStyle.js +73 -0
- package/dist/components/Toggle/ToggleField.js +20 -0
- package/dist/components/Toggle/ToggleGroupFrame.js +10 -0
- package/dist/components/UIProvider/UIProvider.js +14 -0
- package/dist/components/UIProvider/context.js +58 -0
- package/dist/components/UIProvider/index.js +1 -0
- package/dist/components/styles/color.js +35 -0
- package/dist/components/styles/fieldControl.js +102 -0
- package/dist/components/styles/popupList.js +102 -0
- package/dist/components/styles/toggle.js +64 -0
- package/dist/components/styles/webValues.js +147 -0
- package/dist/index.js +15 -0
- package/dist/locales/hi.js +1 -0
- package/dist/locales/ta.js +1 -0
- package/dist/types/components/Button/Button.d.ts +31 -0
- package/dist/types/components/Button/buttonStyle.d.ts +46 -0
- package/dist/types/components/Button/index.d.ts +3 -0
- package/dist/types/components/Checkbox/Checkbox.d.ts +60 -0
- package/dist/types/components/Checkbox/checkboxStyle.d.ts +16 -0
- package/dist/types/components/Checkbox/index.d.ts +3 -0
- package/dist/types/components/DataTable/BulkRun.d.ts +11 -0
- package/dist/types/components/DataTable/CardList.d.ts +18 -0
- package/dist/types/components/DataTable/DataTable.d.ts +11 -0
- package/dist/types/components/DataTable/DataTableScrollView.d.ts +10 -0
- package/dist/types/components/DataTable/DragSelect.d.ts +12 -0
- package/dist/types/components/DataTable/LayoutSwitcher.d.ts +23 -0
- package/dist/types/components/DataTable/Pager.d.ts +5 -0
- package/dist/types/components/DataTable/RowActions.d.ts +13 -0
- package/dist/types/components/DataTable/RowDetail.d.ts +15 -0
- package/dist/types/components/DataTable/RowMenuSheet.d.ts +5 -0
- package/dist/types/components/DataTable/SortSheet.d.ts +8 -0
- package/dist/types/components/DataTable/SplitList.d.ts +9 -0
- package/dist/types/components/DataTable/StatusRow.d.ts +7 -0
- package/dist/types/components/DataTable/SwipeRow.d.ts +25 -0
- package/dist/types/components/DataTable/ToolButton.d.ts +13 -0
- package/dist/types/components/DataTable/Toolbar.d.ts +8 -0
- package/dist/types/components/DataTable/cells.d.ts +13 -0
- package/dist/types/components/DataTable/dataTableStyle.d.ts +139 -0
- package/dist/types/components/DataTable/filters/FilterConditionRow.d.ts +12 -0
- package/dist/types/components/DataTable/filters/FilterGroupEditor.d.ts +13 -0
- package/dist/types/components/DataTable/filters/FilterSheet.d.ts +5 -0
- package/dist/types/components/DataTable/filters/SavedFilterBar.d.ts +20 -0
- package/dist/types/components/DataTable/filters/filterStyle.d.ts +46 -0
- package/dist/types/components/DataTable/index.d.ts +5 -0
- package/dist/types/components/DataTable/persistence/adapters.d.ts +12 -0
- package/dist/types/components/DataTable/persistence/useViewPrefs.d.ts +20 -0
- package/dist/types/components/DataTable/rowParts.d.ts +32 -0
- package/dist/types/components/DataTable/useTableState.d.ts +103 -0
- package/dist/types/components/DatePicker/Calendar.d.ts +11 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +65 -0
- package/dist/types/components/DatePicker/PeriodGrid.d.ts +11 -0
- package/dist/types/components/DatePicker/PeriodPicker.d.ts +10 -0
- package/dist/types/components/DatePicker/TimeField.d.ts +15 -0
- package/dist/types/components/DatePicker/datePickerStyle.d.ts +75 -0
- package/dist/types/components/DatePicker/index.d.ts +4 -0
- package/dist/types/components/Dialog/Dialog.d.ts +35 -0
- package/dist/types/components/Dialog/DialogHost.d.ts +45 -0
- package/dist/types/components/Dialog/dialogStyle.d.ts +23 -0
- package/dist/types/components/Dialog/index.d.ts +4 -0
- package/dist/types/components/FieldContext/FieldContext.d.ts +43 -0
- package/dist/types/components/FieldContext/index.d.ts +3 -0
- package/dist/types/components/FieldWrapper/FieldWrapper.d.ts +23 -0
- package/dist/types/components/FieldWrapper/fieldWrapperStyle.d.ts +24 -0
- package/dist/types/components/FieldWrapper/index.d.ts +3 -0
- package/dist/types/components/Icon/Icon.d.ts +37 -0
- package/dist/types/components/Icon/IconContext.d.ts +12 -0
- package/dist/types/components/Icon/iconStyle.d.ts +10 -0
- package/dist/types/components/Icon/icons.d.ts +250 -0
- package/dist/types/components/Icon/index.d.ts +7 -0
- package/dist/types/components/Icon/useIconDone.d.ts +4 -0
- package/dist/types/components/Input/Input.d.ts +53 -0
- package/dist/types/components/Input/index.d.ts +3 -0
- package/dist/types/components/Input/inputStyle.d.ts +11 -0
- package/dist/types/components/Press/Ripple.d.ts +20 -0
- package/dist/types/components/Press/index.d.ts +2 -0
- package/dist/types/components/Press/measure.d.ts +8 -0
- package/dist/types/components/Radio/Radio.d.ts +58 -0
- package/dist/types/components/Radio/index.d.ts +3 -0
- package/dist/types/components/Radio/radioStyle.d.ts +17 -0
- package/dist/types/components/Select/Select.d.ts +49 -0
- package/dist/types/components/Select/SelectSheet.d.ts +34 -0
- package/dist/types/components/Select/index.d.ts +3 -0
- package/dist/types/components/Suggest/Suggest.d.ts +44 -0
- package/dist/types/components/Suggest/index.d.ts +3 -0
- package/dist/types/components/Switch/Switch.d.ts +42 -0
- package/dist/types/components/Switch/index.d.ts +3 -0
- package/dist/types/components/Switch/switchStyle.d.ts +29 -0
- package/dist/types/components/Toast/ToastHost.d.ts +12 -0
- package/dist/types/components/Toast/ToastItem.d.ts +17 -0
- package/dist/types/components/Toast/ToastLayer.d.ts +11 -0
- package/dist/types/components/Toast/index.d.ts +5 -0
- package/dist/types/components/Toast/toast.types.d.ts +37 -0
- package/dist/types/components/Toast/toastStyle.d.ts +22 -0
- package/dist/types/components/Toggle/ToggleField.d.ts +31 -0
- package/dist/types/components/Toggle/ToggleGroupFrame.d.ts +14 -0
- package/dist/types/components/UIProvider/UIProvider.d.ts +17 -0
- package/dist/types/components/UIProvider/context.d.ts +22 -0
- package/dist/types/components/UIProvider/index.d.ts +2 -0
- package/dist/types/components/styles/color.d.ts +2 -0
- package/dist/types/components/styles/fieldControl.d.ts +26 -0
- package/dist/types/components/styles/popupList.d.ts +48 -0
- package/dist/types/components/styles/toggle.d.ts +26 -0
- package/dist/types/components/styles/webValues.d.ts +157 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/locales/hi.d.ts +1 -0
- package/dist/types/locales/ta.d.ts +1 -0
- package/package.json +85 -4
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
4
|
+
import { cellText, columnValueOf, valueText } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { IconChevronLeft, IconChevronRight, IconClose } from '../Icon';
|
|
7
|
+
import { Dialog } from '../Dialog/Dialog';
|
|
8
|
+
import { CellNode } from './cells';
|
|
9
|
+
import { detailLook } from './dataTableStyle';
|
|
10
|
+
import { DT_DETAIL_NAV_DISABLED_OPACITY } from '../styles/webValues';
|
|
11
|
+
const resolve = (v, row) => (typeof v === 'function' ? v(row) : v);
|
|
12
|
+
export function BuiltInDetail({ row, state, close }) {
|
|
13
|
+
const t = useTokens();
|
|
14
|
+
const look = detailLook(t);
|
|
15
|
+
const menu = state.view.rowMenu;
|
|
16
|
+
const OwnView = menu?.openView?.(row) ?? null;
|
|
17
|
+
const header = menu?.openHeader !== undefined ? resolve(menu.openHeader, row) : null;
|
|
18
|
+
const subheader = menu?.openSubheader !== undefined ? resolve(menu.openSubheader, row) : null;
|
|
19
|
+
const footer = menu?.openFooter !== undefined ? resolve(menu.openFooter, row) : null;
|
|
20
|
+
const shown = state.columns
|
|
21
|
+
.filter(c => c.authorized !== false && !c.dataOnly)
|
|
22
|
+
.map(col => ({ col, value: columnValueOf(col, row) }))
|
|
23
|
+
.filter(f => f.value !== null && f.value !== undefined && f.value !== '');
|
|
24
|
+
return (_jsxs(View, { style: { gap: t.spacingLg }, children: [_jsx(CellNode, { node: header, style: { fontSize: t.fontSizeLg, fontWeight: String(t.fontWeightBold), color: t.textPrimary } }), _jsx(CellNode, { node: subheader, style: { fontSize: t.fontSizeSm, color: t.textSecondary } }), OwnView ? _jsx(OwnView, { row: row, closeModal: close }) : (_jsx(View, { style: look.fields, children: shown.map(({ col, value }, i) => (_jsxs(View, { style: [look.field, i === shown.length - 1 && look.fieldLast], children: [_jsx(Text, { style: look.label, children: col.header }), _jsx(View, { style: { flex: 1 }, children: _jsx(CellNode, { node: col.cell ? col.cell(value, row, 0) : valueText(col, value, state.ctx, row), style: look.value }) })] }, col.key))) })), _jsx(CellNode, { node: footer, style: { fontSize: t.fontSizeSm, color: t.textSecondary } })] }));
|
|
25
|
+
}
|
|
26
|
+
function DetailNav({ ctx, state }) {
|
|
27
|
+
const t = useTokens();
|
|
28
|
+
const look = detailLook(t);
|
|
29
|
+
const { L, format } = state;
|
|
30
|
+
if (!ctx.position || ctx.position.count < 2)
|
|
31
|
+
return null;
|
|
32
|
+
const button = (label, go, Icon) => (_jsx(Pressable, { onPress: go, disabled: !go, accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled: !go }, style: ({ pressed }) => [look.navButton, pressed && { backgroundColor: t.hoverOverlay }, !go && { opacity: DT_DETAIL_NAV_DISABLED_OPACITY }], children: _jsx(Icon, { size: "action", color: t.textSecondary }) }));
|
|
33
|
+
return (_jsxs(View, { style: look.nav, children: [button(L.detailPrevious, ctx.prev, IconChevronLeft), _jsx(Text, { style: look.position, children: L.detailPosition(format.number(ctx.position.index + 1), format.number(ctx.position.count)) }), button(L.detailNext, ctx.next, IconChevronRight)] }));
|
|
34
|
+
}
|
|
35
|
+
function DetailContent({ row, ctx, state, renderDetail }) {
|
|
36
|
+
const render = state.view.renderDetail ?? renderDetail;
|
|
37
|
+
if (render)
|
|
38
|
+
return _jsx(_Fragment, { children: render(row, ctx) });
|
|
39
|
+
return row === null ? null : _jsx(BuiltInDetail, { row: row, state: state, close: ctx.close });
|
|
40
|
+
}
|
|
41
|
+
function detailContextOf(state) {
|
|
42
|
+
const { openId, rows, open, detailMode } = state;
|
|
43
|
+
if (openId === null)
|
|
44
|
+
return null;
|
|
45
|
+
const at = rows.findIndex(r => r.id === openId);
|
|
46
|
+
const ctx = {
|
|
47
|
+
id: openId,
|
|
48
|
+
mode: detailMode,
|
|
49
|
+
close: () => open(null),
|
|
50
|
+
...(at >= 0 ? {
|
|
51
|
+
position: { index: at, count: rows.length },
|
|
52
|
+
...(at > 0 ? { prev: () => open(rows[at - 1].id) } : {}),
|
|
53
|
+
...(at < rows.length - 1 ? { next: () => open(rows[at + 1].id) } : {}),
|
|
54
|
+
} : {}),
|
|
55
|
+
};
|
|
56
|
+
return { row: at >= 0 ? rows[at].row : state.rowOf(openId), ctx };
|
|
57
|
+
}
|
|
58
|
+
export function DetailPane({ state, renderDetail, bar }) {
|
|
59
|
+
const t = useTokens();
|
|
60
|
+
const look = detailLook(t);
|
|
61
|
+
const shown = detailContextOf(state);
|
|
62
|
+
const scroll = useRef(null);
|
|
63
|
+
useEffect(() => { scroll.current?.scrollTo({ y: 0, animated: false }); }, [shown?.ctx.id]);
|
|
64
|
+
if (!shown) {
|
|
65
|
+
return _jsx(View, { style: look.empty, children: _jsx(Text, { style: look.emptyText, children: state.L.detailEmpty }) });
|
|
66
|
+
}
|
|
67
|
+
return (_jsxs(View, { style: { flex: 1 }, accessibilityLabel: state.L.open, children: [bar && (_jsxs(View, { style: look.bar, children: [_jsx(View, { style: { flex: 1 } }), _jsx(DetailNav, { ctx: shown.ctx, state: state }), _jsx(Pressable, { onPress: shown.ctx.close, accessibilityRole: "button", accessibilityLabel: state.L.closeDetail, style: ({ pressed }) => [look.navButton, { borderWidth: 1, borderColor: t.borderColor, marginLeft: t.spacingXs }, pressed && { backgroundColor: t.hoverOverlay }], children: _jsx(IconClose, { size: "action", color: t.textSecondary }) })] })), _jsx(ScrollView, { ref: scroll, contentContainerStyle: bar ? look.body : undefined, children: _jsx(DetailContent, { row: shown.row, ctx: shown.ctx, state: state, renderDetail: renderDetail }) })] }));
|
|
68
|
+
}
|
|
69
|
+
export function DetailSheet({ state, renderDetail, bar }) {
|
|
70
|
+
const t = useTokens();
|
|
71
|
+
const look = detailLook(t);
|
|
72
|
+
const shown = detailContextOf(state);
|
|
73
|
+
const last = useRef(shown);
|
|
74
|
+
if (shown)
|
|
75
|
+
last.current = shown;
|
|
76
|
+
const drawn = shown ?? last.current;
|
|
77
|
+
const titleCol = state.byKey.get(state.cardFields.title[0] ?? '');
|
|
78
|
+
const title = drawn?.row != null && titleCol ? cellText(titleCol, drawn.row, state.ctx) : undefined;
|
|
79
|
+
return (_jsx(Dialog, { open: !!shown, onClose: () => state.open(null), placement: state.detailMode === 'drawer' ? 'right' : 'bottom', size: "md", title: bar ? title : undefined, showCloseButton: bar, padded: false, children: drawn && (_jsxs(_Fragment, { children: [bar && drawn.ctx.position && drawn.ctx.position.count > 1 && (_jsx(View, { style: [look.bar, { justifyContent: 'center' }], children: _jsx(DetailNav, { ctx: drawn.ctx, state: state }) })), _jsx(View, { style: bar ? look.body : undefined, children: _jsx(DetailContent, { row: drawn.row, ctx: drawn.ctx, state: state, renderDetail: renderDetail }) })] })) }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { rowMenuEntries, rowMenuHostIcons, valueFilterEntries } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { IconArrowLeft, IconCheckbox, IconFilter, IconOpenDetail } from '../Icon';
|
|
7
|
+
import { IconSlotContext } from '../Icon/IconContext';
|
|
8
|
+
import { Dialog } from '../Dialog/Dialog';
|
|
9
|
+
import { popupRowLook } from '../styles/popupList';
|
|
10
|
+
import { DT_BULK_EDGE_MIX, DT_FIELD_NAME_LETTER_SPACING_EM, DT_LAYOUT_ITEM_PAD, DT_MENU_BACK_HEIGHT, DT_MENU_CHIP_HEIGHT, DT_MENU_FILTER_ENTRY_HEIGHT, MENU_RAIL_DISABLED_OPACITY, MENU_RAIL_ITEM_MIN_WIDTH } from '../styles/webValues';
|
|
11
|
+
import { mixColors } from '../styles/color';
|
|
12
|
+
import { RowAvatarView } from './cells';
|
|
13
|
+
import { tableColors } from './dataTableStyle';
|
|
14
|
+
import { rowParts } from './rowParts';
|
|
15
|
+
const DEFAULT_BUILT_INS = ['open', 'copyCell', 'copyRow', 'select', 'only', 'hide', 'openInNewTab'];
|
|
16
|
+
export function RowMenuSheet({ state }) {
|
|
17
|
+
const t = useTokens();
|
|
18
|
+
const { L, view, menuRow } = state;
|
|
19
|
+
const last = React.useRef(menuRow);
|
|
20
|
+
if (menuRow)
|
|
21
|
+
last.current = menuRow;
|
|
22
|
+
const item = menuRow ?? last.current;
|
|
23
|
+
const [pane, setPane] = React.useState('menu');
|
|
24
|
+
React.useEffect(() => { if (menuRow)
|
|
25
|
+
setPane('menu'); }, [menuRow?.id]);
|
|
26
|
+
const close = () => state.openMenu(null);
|
|
27
|
+
const run = (fn) => { close(); fn(); };
|
|
28
|
+
if (!item)
|
|
29
|
+
return null;
|
|
30
|
+
const parts = rowParts(item.row, item.index, state.cardFields, state.byKey, view.avatar, state.ctx);
|
|
31
|
+
const builtIns = view.rowMenu?.builtIns ?? DEFAULT_BUILT_INS;
|
|
32
|
+
const canOpen = state.opens || !!view.rowMenu?.onOpen;
|
|
33
|
+
const ticked = state.isTicked(item.id);
|
|
34
|
+
const builtIn = [];
|
|
35
|
+
for (const b of builtIns.filter((x, i, a) => a.indexOf(x) === i)) {
|
|
36
|
+
if (b === 'open' && canOpen)
|
|
37
|
+
builtIn.push({ id: 'open', label: L.open, shortLabel: L.open, icon: _jsx(IconOpenDetail, {}), onSelect: () => state.open(item.id) });
|
|
38
|
+
if (b === 'select' && state.canTick(item.row)) {
|
|
39
|
+
const label = ticked ? L.unselectRowMenu : L.selectRowMenu;
|
|
40
|
+
builtIn.push({ id: 'select', label, shortLabel: label, icon: _jsx(IconCheckbox, { filled: ticked }), onSelect: () => state.toggleTick(item.id) });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const slots = state.layout === 'split' ? [...state.listFields.title, ...state.listFields.subtitle, ...state.listFields.badge] : [...state.cardFields.title, ...state.cardFields.subtitle, ...state.cardFields.badge, ...state.cardFields.details];
|
|
44
|
+
const filterEntries = state.filterOn ? valueFilterEntries(item.row, state.columns, slots, state.filterGroup, L, state.operators) : [];
|
|
45
|
+
if (filterEntries.length)
|
|
46
|
+
builtIn.push({ id: 'filterBy', label: L.filterBy, shortLabel: L.filterByShort, icon: _jsx(IconFilter, {}), onSelect: () => setPane('filter') });
|
|
47
|
+
const icons = [...builtIn, ...rowMenuHostIcons(item.row, view.rowMenu?.iconActions)];
|
|
48
|
+
const { items, danger } = rowMenuEntries(item.row, item.index, state.actionsOf(item.row), view.rowMenu?.items);
|
|
49
|
+
const line = tableColors(t).lineSoft;
|
|
50
|
+
const filterPane = (_jsxs(View, { style: { paddingHorizontal: t.spacingMd, paddingVertical: t.spacingXs, gap: t.spacingXs }, children: [_jsxs(Pressable, { onPress: () => setPane('menu'), accessibilityRole: "button", accessibilityLabel: L.back, style: ({ pressed }) => [{ alignSelf: 'flex-start', flexDirection: 'row', alignItems: 'center', gap: t.spacingXs, height: DT_MENU_BACK_HEIGHT, paddingLeft: t.spacingXs, paddingRight: t.spacingMd, borderRadius: t.borderRadiusSm }, pressed && { backgroundColor: t.hoverOverlay }], children: [_jsx(IconArrowLeft, { size: "action", color: t.textPrimary }), _jsx(Text, { style: { fontSize: t.fontSizeMd, fontWeight: String(t.fontWeightBold), color: t.textPrimary }, children: L.filterBy })] }), filterEntries.map(entry => _jsx(FilterEntry, { entry: entry, L: L, onPick: group => run(() => state.setFilterGroup(group)) }, entry.id))] }));
|
|
51
|
+
const content = pane === 'filter' && filterEntries.length ? filterPane : (_jsxs(View, { children: [icons.length > 0 && (_jsx(View, { style: { flexDirection: 'row', flexWrap: 'wrap', gap: t.spacingXxs, paddingHorizontal: t.spacingMd, paddingBottom: t.spacingLg, paddingTop: t.spacingSm, borderBottomWidth: 1, borderBottomColor: line }, children: icons.map(ic => (_jsxs(Pressable, { onPress: () => (ic.id === 'filterBy' ? ic.onSelect() : run(ic.onSelect)), disabled: ic.disabled, accessibilityRole: "button", accessibilityLabel: ic.label, accessibilityState: { disabled: !!ic.disabled }, style: ({ pressed }) => [
|
|
52
|
+
{ minWidth: MENU_RAIL_ITEM_MIN_WIDTH, padding: t.spacingSm, alignItems: 'center', gap: t.spacingXxs, borderRadius: t.borderRadiusSm },
|
|
53
|
+
pressed && { backgroundColor: t.hoverOverlay },
|
|
54
|
+
ic.disabled && { opacity: MENU_RAIL_DISABLED_OPACITY },
|
|
55
|
+
], children: [_jsx(IconSlotContext.Provider, { value: { size: t.iconSizeAction, color: t.textSecondary }, children: ic.icon }), _jsx(Text, { style: { fontSize: t.fontSizeXxs, lineHeight: Math.round(t.fontSizeXxs * t.lineHeightTight), color: t.textPrimary }, numberOfLines: 1, children: ic.shortLabel })] }, ic.id))) })), _jsxs(View, { style: { paddingVertical: t.spacingXs }, children: [items.map(it => _jsx(MenuItem, { entry: it, onSelect: () => run(it.onSelect) }, it.id)), danger.length > 0 && items.length > 0 && _jsx(View, { style: { height: 1, backgroundColor: t.borderColor, marginVertical: t.spacingXs } }), danger.map(it => _jsx(MenuItem, { entry: it, danger: true, onSelect: () => run(it.onSelect) }, it.id))] })] }));
|
|
56
|
+
return (_jsx(Dialog, { open: !!menuRow, onClose: close, placement: "bottom", size: "md", padded: false, "aria-label": L.rowMenu(parts.title), title: (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingLg }, children: [_jsx(RowAvatarView, { avatar: parts.avatar, place: "cardPhone" }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontSize: t.fontSizeLg, fontWeight: String(t.fontWeightBold), color: t.textPrimary }, numberOfLines: 1, children: parts.title }), !!parts.subtitle && _jsx(Text, { style: { fontSize: t.fontSizeXs, color: t.textSecondary }, numberOfLines: 1, children: parts.subtitle })] })] })), children: content }));
|
|
57
|
+
}
|
|
58
|
+
function FilterEntry({ entry, L, onPick }) {
|
|
59
|
+
const t = useTokens();
|
|
60
|
+
const c = tableColors(t);
|
|
61
|
+
return (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingMd, minHeight: DT_MENU_FILTER_ENTRY_HEIGHT, paddingVertical: t.spacingXs, paddingLeft: DT_LAYOUT_ITEM_PAD, paddingRight: t.spacingSm }, children: [_jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontSize: t.fontSizeXxs, fontWeight: String(t.fontWeightBold), textTransform: 'uppercase', letterSpacing: t.fontSizeXxs * DT_FIELD_NAME_LETTER_SPACING_EM, color: t.textSecondary }, numberOfLines: 1, children: entry.field }), _jsx(Text, { style: { fontSize: t.fontSizeMd, color: t.textPrimary }, numberOfLines: 1, children: entry.value })] }), _jsx(View, { style: { flexDirection: 'row', gap: t.spacingXs }, children: entry.options.map(o => (_jsx(Pressable, { onPress: () => onPick(o.group), accessibilityRole: "menuitem", accessibilityLabel: o.label, style: ({ pressed }) => [
|
|
62
|
+
{ height: DT_MENU_CHIP_HEIGHT, paddingHorizontal: DT_LAYOUT_ITEM_PAD, borderRadius: DT_MENU_CHIP_HEIGHT / 2, borderWidth: 1, justifyContent: 'center', backgroundColor: pressed ? c.accentSoft : t.bgSecondary, borderColor: o.kind === 'hide' ? c.line : mixColors(t.accentPrimary, DT_BULK_EDGE_MIX, c.line) },
|
|
63
|
+
], children: _jsx(Text, { style: { fontSize: t.fontSizeXs, fontWeight: String(t.fontWeightBold), color: o.kind === 'hide' ? t.textPrimary : t.accentPrimaryText }, children: o.kind === 'only' ? L.filterOnlyShort : o.kind === 'add' ? L.filterAddShort : L.filterHideShort }) }, o.kind))) })] }));
|
|
64
|
+
}
|
|
65
|
+
function MenuItem({ entry, danger = false, onSelect }) {
|
|
66
|
+
const t = useTokens();
|
|
67
|
+
const color = danger ? t.errorText : undefined;
|
|
68
|
+
return (_jsx(Pressable, { onPress: onSelect, disabled: entry.disabled, accessibilityRole: "menuitem", accessibilityLabel: entry.label, accessibilityState: { disabled: !!entry.disabled }, children: ({ pressed }) => {
|
|
69
|
+
const look = popupRowLook(t, { size: 'medium', selected: false, disabled: !!entry.disabled, pressed });
|
|
70
|
+
return (_jsxs(View, { style: look.row, children: [entry.icon != null && (_jsx(IconSlotContext.Provider, { value: { size: look.tickSize, color: color ?? t.textSecondary }, children: entry.icon })), _jsx(Text, { style: [look.text, color ? { color } : null], numberOfLines: 1, children: entry.label })] }));
|
|
71
|
+
} }));
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
import { sortWords } from '@dcs-tech/core';
|
|
4
|
+
import { useTokens } from '../UIProvider/context';
|
|
5
|
+
import { IconArrowDown, IconArrowUp } from '../Icon';
|
|
6
|
+
import { Dialog } from '../Dialog/Dialog';
|
|
7
|
+
import { Button } from '../Button/Button';
|
|
8
|
+
import { popupRowLook } from '../styles/popupList';
|
|
9
|
+
export function sortableColumns(state) {
|
|
10
|
+
return state.columns.filter(c => c.authorized !== false && c.sortable !== false && !c.dataOnly);
|
|
11
|
+
}
|
|
12
|
+
export function SortSheet({ state, open, onClose }) {
|
|
13
|
+
const t = useTokens();
|
|
14
|
+
const { L, sorting, setSorting } = state;
|
|
15
|
+
const current = sorting[0];
|
|
16
|
+
const pick = (key) => setSorting([{ key, desc: current?.key === key ? !current.desc : false }]);
|
|
17
|
+
return (_jsx(Dialog, { open: open, onClose: onClose, placement: "bottom", size: "sm", title: L.sortTitle, padded: false, footer: sorting.length > 0 ? _jsx(Button, { variant: "outlined", color: "neutral", onPress: () => setSorting([]), children: L.clear }) : undefined, children: _jsx(View, { accessibilityRole: "list", children: sortableColumns(state).map(col => {
|
|
18
|
+
const on = current?.key === col.key;
|
|
19
|
+
const Arrow = current?.desc ? IconArrowDown : IconArrowUp;
|
|
20
|
+
return (_jsx(Pressable, { onPress: () => pick(col.key), accessibilityRole: "button", accessibilityLabel: on ? `${col.header}, ${sortWords(col, !!current?.desc, L)}` : col.header, accessibilityState: { selected: on }, children: ({ pressed }) => {
|
|
21
|
+
const look = popupRowLook(t, { size: 'medium', selected: on, disabled: false, pressed });
|
|
22
|
+
return (_jsxs(View, { style: look.row, children: [_jsx(Text, { style: look.text, numberOfLines: 1, children: col.header }), on && _jsx(Text, { style: [look.text, { flex: 0 }], children: sortWords(col, !!current?.desc, L) }), on && _jsx(Arrow, { size: look.tickSize, color: look.tickColor })] }));
|
|
23
|
+
} }, col.key));
|
|
24
|
+
}) }) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { useTokens } from '../UIProvider/context';
|
|
5
|
+
import { splitCheckLook, splitLook } from './dataTableStyle';
|
|
6
|
+
import { CellNode, RowAvatarView } from './cells';
|
|
7
|
+
import { listParts } from './rowParts';
|
|
8
|
+
import { RowActions, hasRowActions } from './RowActions';
|
|
9
|
+
import { RowCheck, longPressOf, pressOf } from './CardList';
|
|
10
|
+
import { useDragTick } from './DragSelect';
|
|
11
|
+
import { DataTableScrollView } from './DataTableScrollView';
|
|
12
|
+
import { SwipeRow, swipeOf } from './SwipeRow';
|
|
13
|
+
export function SplitList({ state, pane, height }) {
|
|
14
|
+
const t = useTokens();
|
|
15
|
+
const phone = state.size === 'phone';
|
|
16
|
+
const look = splitLook(t, phone, !!pane, state.size === 'tablet');
|
|
17
|
+
const { view, rows, listFields, byKey, ctx, openId } = state;
|
|
18
|
+
const parts = useMemo(() => rows.map(r => listParts(r.row, r.index, listFields, byKey, view.avatar, ctx)), [rows, listFields, byKey, view.avatar, ctx]);
|
|
19
|
+
const drag = useDragTick(state);
|
|
20
|
+
const list = (_jsx(View, { accessibilityRole: "list", accessibilityLabel: state.L.detailList, ref: drag.listRef, ...drag.handlers, children: rows.map((r, i) => {
|
|
21
|
+
const p = parts[i];
|
|
22
|
+
const isOpen = r.id === openId;
|
|
23
|
+
const swipe = swipeOf(state, r);
|
|
24
|
+
const item = (_jsxs(Pressable, { onPress: pressOf(state, r.id), onLongPress: longPressOf(state, r.id, drag), onPressOut: drag.release, onLayout: swipe ? undefined : drag.onRowLayout(r.id), disabled: !pressOf(state, r.id) && !longPressOf(state, r.id), accessibilityRole: pressOf(state, r.id) ? 'button' : undefined, accessibilityLabel: p.title || undefined, accessibilityState: state.checkboxes ? { selected: isOpen, checked: state.isTicked(r.id) } : { selected: isOpen }, style: ({ pressed }) => [look.item, pressed && look.itemPressed, isOpen && look.itemOpen], children: [state.checkboxes && _jsx(View, { style: splitCheckLook(), children: _jsx(RowCheck, { state: state, id: r.id, row: r.row, title: p.title }) }), _jsx(RowAvatarView, { avatar: p.avatar, place: "split" }), _jsxs(View, { style: look.text, children: [_jsxs(View, { style: look.line, children: [_jsx(Text, { style: look.title, numberOfLines: 1, children: p.title }), p.badge && _jsx(View, { style: look.badge, children: _jsx(CellNode, { node: p.badge.node, style: look.badgeText }) })] }), p.subtitle.length > 0 && _jsx(Text, { style: look.subtitle, numberOfLines: 1, children: p.subtitle.map(s => s.text).join(' · ') })] }), hasRowActions(state, r, 'list') && _jsx(View, { style: look.actions, children: _jsx(RowActions, { state: state, item: r, surface: "list", title: p.title }) })] }, r.id));
|
|
25
|
+
return swipe ? _jsx(SwipeRow, { ...swipe, onLayout: drag.onRowLayout(r.id), children: item }, r.id) : item;
|
|
26
|
+
}) }));
|
|
27
|
+
if (!pane)
|
|
28
|
+
return list;
|
|
29
|
+
return (_jsxs(View, { style: [look.split, { height }], children: [_jsx(DataTableScrollView, { style: look.side, children: list }), _jsx(View, { style: look.pane, children: pane })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
|
+
import { defaultOrderWords, filterChipText, planBulkAction, sortWords, statusSummaryText } from '@dcs-tech/core';
|
|
4
|
+
import { useTokens } from '../UIProvider/context';
|
|
5
|
+
import { IconArrowDown, IconArrowUp, IconClose } from '../Icon';
|
|
6
|
+
import { IconSlotContext } from '../Icon/IconContext';
|
|
7
|
+
import { bulkButtonLook, statusLook } from './dataTableStyle';
|
|
8
|
+
export function StatusRow({ state, bulk }) {
|
|
9
|
+
const t = useTokens();
|
|
10
|
+
const { L, format, selecting } = state;
|
|
11
|
+
const phone = state.size === 'phone';
|
|
12
|
+
if (!state.selectionOn && !state.sortOn && !state.filterOn)
|
|
13
|
+
return null;
|
|
14
|
+
const defaultOrder = state.sortIsDefault ? defaultOrderWords(state.defaultSorting, k => state.byKey.get(k), L) : undefined;
|
|
15
|
+
const summary = !selecting && state.sortIsDefault && state.activeFilters.length === 0 ? statusSummaryText(state.total, state.search.trim() !== '', L, format) : undefined;
|
|
16
|
+
if (summary && !defaultOrder)
|
|
17
|
+
return null;
|
|
18
|
+
const chips = state.sortIsDefault ? [] : state.sorting;
|
|
19
|
+
const chipCount = chips.length + state.activeFilters.length;
|
|
20
|
+
const mode = selecting ? 'selecting' : summary ? 'idle' : 'chips';
|
|
21
|
+
const look = statusLook(t, phone, mode);
|
|
22
|
+
const order = defaultOrder && _jsx(Text, { style: look.order, accessibilityLabel: defaultOrder.title, numberOfLines: 1, children: defaultOrder.text });
|
|
23
|
+
const link = (label, onPress, quiet = false, name) => (_jsx(Pressable, { onPress: onPress, accessibilityRole: "button", accessibilityLabel: name ?? label, style: ({ pressed }) => [look.link, pressed && look.linkPressed], children: _jsx(Text, { style: quiet ? look.clearText : look.linkText, numberOfLines: 1, children: label }) }));
|
|
24
|
+
return (_jsx(View, { style: look.row, accessibilityLabel: L.statusRow, children: _jsx(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerStyle: look.inner, keyboardShouldPersistTaps: "handled", children: summary ? (_jsxs(_Fragment, { children: [_jsx(Text, { style: look.summary, numberOfLines: 1, children: summary }), _jsx(View, { style: look.spacer }), order] })) : (_jsxs(_Fragment, { children: [selecting && (_jsxs(_Fragment, { children: [state.bulkActions.length > 0 && (_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: t.spacingSm }, accessibilityLabel: L.bulkActions, children: [state.bulkActions.map((action, i) => {
|
|
25
|
+
const why = planBulkAction(action, state.selection, L, format).disabledReason;
|
|
26
|
+
const busy = bulk.busyId === action.id;
|
|
27
|
+
const disabled = !!why || !!bulk.busyId;
|
|
28
|
+
const display = action.display ?? 'icon-label';
|
|
29
|
+
const showIcon = display !== 'label' && !!action.icon;
|
|
30
|
+
const showLabel = display !== 'icon' || !action.icon;
|
|
31
|
+
return (_jsx(Pressable, { onPress: () => bulk.run(action), disabled: disabled, accessibilityRole: "button", accessibilityLabel: action.label, accessibilityHint: why ?? action.tooltip, accessibilityState: { disabled, busy }, children: ({ pressed }) => {
|
|
32
|
+
const b = bulkButtonLook(t, action.variant, i === 0, { disabled, busy, pressed });
|
|
33
|
+
return (_jsxs(View, { style: b.box, children: [showIcon && _jsx(IconSlotContext.Provider, { value: { size: t.iconSizeSm, color: b.color }, children: action.icon }), showLabel && _jsx(Text, { style: b.text, numberOfLines: 1, children: busy ? L.bulkRunning : action.label })] }));
|
|
34
|
+
} }, action.id));
|
|
35
|
+
}), _jsx(View, { style: look.divider })] })), _jsx(Text, { style: look.selected, accessibilityLiveRegion: "polite", numberOfLines: 1, children: state.selectedCount > 0
|
|
36
|
+
? (state.allMatching ? L.allMatchingSelected(format.number(state.selectedCount)) : L.selectedCount(format.number(state.selectedCount)))
|
|
37
|
+
: L.selectingHint }), state.selectAll && link(state.selectAll.label, state.selectAll.run), link(L.clear, state.clearSelection, true, L.clearSelection), chipCount > 0 && _jsx(View, { style: look.dividerSoft })] })), chips.map(s => {
|
|
38
|
+
const col = state.byKey.get(s.key);
|
|
39
|
+
const name = String(col?.header ?? s.key);
|
|
40
|
+
const words = sortWords(col, s.desc, L);
|
|
41
|
+
const Arrow = s.desc ? IconArrowDown : IconArrowUp;
|
|
42
|
+
return (_jsxs(View, { style: look.chip, accessibilityLabel: `${name} · ${words}`, children: [_jsx(Text, { style: look.chipText, numberOfLines: 1, children: name }), _jsx(Arrow, { size: look.chipIcon, color: t.textSecondary }), _jsx(Pressable, { onPress: () => state.setSortingOrDefault(state.sorting.filter(r => r.key !== s.key)), accessibilityRole: "button", accessibilityLabel: L.removeSort(name), hitSlop: t.spacingXs, style: ({ pressed }) => [look.chipRemove, pressed && look.chipRemovePressed], children: _jsx(IconClose, { size: look.chipIcon, color: t.textSecondary }) })] }, s.key));
|
|
43
|
+
}), state.activeFilters.map(f => {
|
|
44
|
+
const c = filterChipText(f, L);
|
|
45
|
+
const text = `${c.label} ${c.sep} ${c.value}`.trim();
|
|
46
|
+
return (_jsxs(View, { style: [look.chip, look.filterChip], children: [_jsxs(Pressable, { onPress: () => state.setFiltersOpen(true), accessibilityRole: "button", accessibilityLabel: text, style: look.chipBody, children: [_jsx(Text, { style: [look.chipText, look.filterChipText], numberOfLines: 1, children: c.sep === ':' ? `${c.label}:` : c.label }), c.sep !== ':' && _jsx(Text, { style: [look.chipOperator, look.filterChipText], numberOfLines: 1, children: c.sep }), !!c.value && _jsx(Text, { style: [look.chipValue, look.filterChipText], numberOfLines: 1, children: c.value })] }), _jsx(Pressable, { onPress: () => state.removeFilter(f.id), accessibilityRole: "button", accessibilityLabel: L.removeFilter(f.columnLabel), hitSlop: t.spacingXs, style: ({ pressed }) => [look.chipRemove, pressed && look.chipRemovePressed], children: _jsx(IconClose, { size: look.chipIcon, color: t.accentPrimaryText }) })] }, f.id));
|
|
47
|
+
}), _jsx(View, { style: look.spacer }), order, chipCount > 0 && link(L.clearAllChips, state.clearAll)] })) }, mode) }));
|
|
48
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, PanResponder, Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { fullSwipeRuns, swipeEntries } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { IconSlotContext } from '../Icon/IconContext';
|
|
7
|
+
import { DISABLED_OPACITY } from '../styles/webValues';
|
|
8
|
+
const ACTION_WIDTH = 80;
|
|
9
|
+
const SWIPE_START = 10;
|
|
10
|
+
const FULL_SHARE = 0.6;
|
|
11
|
+
export function swipeActionLook(t, tone) {
|
|
12
|
+
const [bg, ink] = tone === 'danger' ? [t.error, t.onError]
|
|
13
|
+
: tone === 'success' ? [t.success, t.onSuccess]
|
|
14
|
+
: tone === 'warning' ? [t.warning, t.onWarning]
|
|
15
|
+
: tone === 'secondary' ? [t.textSecondary, t.bgSecondary]
|
|
16
|
+
: [t.accentPrimary, t.onPrimary];
|
|
17
|
+
return {
|
|
18
|
+
box: { backgroundColor: bg, alignItems: 'center', justifyContent: 'center', gap: t.spacingXxs, paddingHorizontal: t.spacingXs, overflow: 'hidden' },
|
|
19
|
+
text: { color: ink, fontSize: t.fontSizeXs, fontWeight: String(t.fontWeightSemibold) },
|
|
20
|
+
ink,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function swipeOf(state, item) {
|
|
24
|
+
const cfg = state.view.swipeActions;
|
|
25
|
+
if (!cfg)
|
|
26
|
+
return null;
|
|
27
|
+
const actions = state.actionsOf(item.row);
|
|
28
|
+
const right = swipeEntries(item.row, item.index, actions, cfg.right);
|
|
29
|
+
const left = swipeEntries(item.row, item.index, actions, cfg.left);
|
|
30
|
+
const open = state.swiped?.id === item.id ? state.swiped.side : null;
|
|
31
|
+
return {
|
|
32
|
+
right, left, fullSwipe: cfg.fullSwipe !== false, open,
|
|
33
|
+
onOpen: side => state.setSwiped(side ? { id: item.id, side } : null),
|
|
34
|
+
enabled: !state.checkboxes && right.length + left.length > 0,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function SwipeRow({ right, left, fullSwipe, open, onOpen, enabled, radius = 0, style, onLayout, children }) {
|
|
38
|
+
const t = useTokens();
|
|
39
|
+
const [width, setWidth] = useState(0);
|
|
40
|
+
const x = useRef(new Animated.Value(0)).current;
|
|
41
|
+
const at = useRef(0);
|
|
42
|
+
const [side, setSide] = useState(null);
|
|
43
|
+
const [full, setFull] = useState(false);
|
|
44
|
+
const live = useRef({ right, left, fullSwipe, enabled, width, onOpen });
|
|
45
|
+
live.current = { right, left, fullSwipe, enabled, width, onOpen };
|
|
46
|
+
const reveal = (s) => (s === 'right' ? right.length : left.length) * ACTION_WIDTH;
|
|
47
|
+
const moveTo = (to, done) => {
|
|
48
|
+
at.current = to;
|
|
49
|
+
Animated.spring(x, { toValue: to, useNativeDriver: false, bounciness: 0, speed: 20 }).start(() => done?.());
|
|
50
|
+
};
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const to = open === 'right' ? reveal('right') : open === 'left' ? -reveal('left') : 0;
|
|
53
|
+
if (open)
|
|
54
|
+
setSide(open);
|
|
55
|
+
if (to !== at.current)
|
|
56
|
+
moveTo(to, () => { if (!open)
|
|
57
|
+
setSide(null); });
|
|
58
|
+
}, [open]);
|
|
59
|
+
const pan = useMemo(() => PanResponder.create({
|
|
60
|
+
onMoveShouldSetPanResponder: (_, g) => {
|
|
61
|
+
const l = live.current;
|
|
62
|
+
if (!l.enabled || Math.abs(g.dx) < SWIPE_START || Math.abs(g.dx) < Math.abs(g.dy) * 2)
|
|
63
|
+
return false;
|
|
64
|
+
return at.current !== 0 || (g.dx > 0 ? l.right.length > 0 : l.left.length > 0);
|
|
65
|
+
},
|
|
66
|
+
onPanResponderTerminationRequest: () => false,
|
|
67
|
+
onPanResponderGrant: () => { x.stopAnimation(v => { at.current = v; }); },
|
|
68
|
+
onPanResponderMove: (_, g) => {
|
|
69
|
+
const l = live.current;
|
|
70
|
+
let next = at.current + g.dx;
|
|
71
|
+
if (next > 0 && !l.right.length)
|
|
72
|
+
next = 0;
|
|
73
|
+
if (next < 0 && !l.left.length)
|
|
74
|
+
next = 0;
|
|
75
|
+
if (l.width)
|
|
76
|
+
next = Math.max(-l.width, Math.min(l.width, next));
|
|
77
|
+
x.setValue(next);
|
|
78
|
+
const s = next > 0 ? 'right' : next < 0 ? 'left' : null;
|
|
79
|
+
setSide(s);
|
|
80
|
+
const entries = s === 'right' ? l.right : l.left;
|
|
81
|
+
setFull(!!s && !!l.width && Math.abs(next) > l.width * FULL_SHARE && fullSwipeRuns(entries, l.fullSwipe));
|
|
82
|
+
},
|
|
83
|
+
onPanResponderRelease: (_, g) => {
|
|
84
|
+
const l = live.current;
|
|
85
|
+
const now = at.current + g.dx;
|
|
86
|
+
const s = now > 0 ? 'right' : now < 0 ? 'left' : null;
|
|
87
|
+
const entries = s === 'right' ? l.right : l.left;
|
|
88
|
+
setFull(false);
|
|
89
|
+
if (s && l.width && Math.abs(now) > l.width * FULL_SHARE && fullSwipeRuns(entries, l.fullSwipe)) {
|
|
90
|
+
at.current = 0;
|
|
91
|
+
Animated.timing(x, { toValue: s === 'right' ? l.width : -l.width, duration: t.durationShort, useNativeDriver: false }).start(() => {
|
|
92
|
+
entries[0].onSelect();
|
|
93
|
+
moveTo(0, () => setSide(null));
|
|
94
|
+
l.onOpen(null);
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const shown = s ? entries.length * ACTION_WIDTH : 0;
|
|
99
|
+
if (s && Math.abs(now) > shown / 2) {
|
|
100
|
+
moveTo(s === 'right' ? shown : -shown);
|
|
101
|
+
l.onOpen(s);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
moveTo(0, () => setSide(null));
|
|
105
|
+
l.onOpen(null);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
onPanResponderTerminate: () => {
|
|
109
|
+
setFull(false);
|
|
110
|
+
moveTo(0, () => setSide(null));
|
|
111
|
+
live.current.onOpen(null);
|
|
112
|
+
},
|
|
113
|
+
}), [x]);
|
|
114
|
+
const entries = side === 'right' ? right : side === 'left' ? left : [];
|
|
115
|
+
const room = x.interpolate({ inputRange: [-1, 0, 1], outputRange: [1, 0, 1], extrapolate: 'extend' });
|
|
116
|
+
return (_jsxs(View, { style: [{ borderRadius: radius }, side ? { overflow: 'hidden' } : null, style], onLayout: e => { setWidth(e.nativeEvent.layout.width); onLayout?.(e); }, children: [side && entries.length > 0 && (_jsx(Animated.View, { style: [
|
|
117
|
+
{ position: 'absolute', top: 0, bottom: 0, flexDirection: side === 'right' ? 'row' : 'row-reverse', borderRadius: radius, overflow: 'hidden' },
|
|
118
|
+
side === 'right' ? { left: 0 } : { right: 0 },
|
|
119
|
+
{ width: room },
|
|
120
|
+
], children: entries.map((e, i) => {
|
|
121
|
+
const look = swipeActionLook(t, e.tone);
|
|
122
|
+
const hidden = full && i > 0;
|
|
123
|
+
return (_jsx(Pressable, { onPress: () => { onOpen(null); e.onSelect(); }, disabled: e.disabled, accessibilityRole: "button", accessibilityLabel: e.label, accessibilityState: { disabled: !!e.disabled }, style: [look.box, { flex: hidden ? 0 : 1, width: hidden ? 0 : undefined }, e.disabled && { opacity: DISABLED_OPACITY }], children: !hidden && (_jsxs(_Fragment, { children: [e.icon != null && _jsx(IconSlotContext.Provider, { value: { size: t.iconSizeAction, color: look.ink }, children: e.icon }), _jsx(Text, { style: look.text, numberOfLines: 1, children: e.label })] })) }, e.id));
|
|
124
|
+
}) })), _jsx(Animated.View, { style: { transform: [{ translateX: x }] }, children: _jsxs(View, { ...pan.panHandlers, children: [children, open && _jsx(Pressable, { accessible: false, style: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0 }, onPress: () => onOpen(null) })] }) })] }));
|
|
125
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import { useTokens } from '../UIProvider/context';
|
|
4
|
+
import { iconButtonLook } from './dataTableStyle';
|
|
5
|
+
import { DISABLED_OPACITY } from '../styles/webValues';
|
|
6
|
+
export function ToolButton({ icon: Icon, label, onPress, size, active = false, disabled = false, badge }) {
|
|
7
|
+
const t = useTokens();
|
|
8
|
+
return (_jsx(Pressable, { onPress: onPress, disabled: disabled, accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled, selected: active }, hitSlop: 4, style: ({ pressed }) => [iconButtonLook(t, size, active, pressed && !disabled).box, disabled && { opacity: DISABLED_OPACITY }], children: ({ pressed }) => _jsx(Icon, { size: "action", color: iconButtonLook(t, size, active, pressed && !disabled).color, badge: badge || undefined }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
4
|
+
import { quickFilterOptions } from '@dcs-tech/core';
|
|
5
|
+
import { useTokens } from '../UIProvider/context';
|
|
6
|
+
import { IconArrowLeft, IconBolt, IconFilter, IconSearch, IconSelectRows, IconSort } from '../Icon';
|
|
7
|
+
import { Select } from '../Select/Select';
|
|
8
|
+
import { Input } from '../Input/Input';
|
|
9
|
+
import { toolbarLook, viewTabLook, viewTabsLook } from './dataTableStyle';
|
|
10
|
+
import { SortSheet, sortableColumns } from './SortSheet';
|
|
11
|
+
import { ToolButton } from './ToolButton';
|
|
12
|
+
import { LayoutSwitcher } from './LayoutSwitcher';
|
|
13
|
+
export function ViewTabs({ state }) {
|
|
14
|
+
const t = useTokens();
|
|
15
|
+
const phone = state.size === 'phone';
|
|
16
|
+
const frame = viewTabsLook(t, phone);
|
|
17
|
+
if (state.views.length < 2)
|
|
18
|
+
return null;
|
|
19
|
+
return (_jsx(View, { style: frame.frame, children: _jsx(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerStyle: frame.tabs, accessibilityRole: "tablist", children: state.views.map(v => {
|
|
20
|
+
const active = v.id === state.view.id;
|
|
21
|
+
const look = viewTabLook(t, phone, active);
|
|
22
|
+
return (_jsx(Pressable, { onPress: () => state.setViewId(v.id), accessibilityRole: "tab", accessibilityState: { selected: active }, accessibilityHint: v.hint, style: look.tab, children: _jsx(Text, { style: look.text, numberOfLines: 1, children: v.label ?? v.id }) }, v.id));
|
|
23
|
+
}) }) }));
|
|
24
|
+
}
|
|
25
|
+
export function Toolbar({ state }) {
|
|
26
|
+
const t = useTokens();
|
|
27
|
+
const phone = state.size === 'phone';
|
|
28
|
+
const look = toolbarLook(t, phone);
|
|
29
|
+
const [sortOpen, setSortOpen] = useState(false);
|
|
30
|
+
const canSort = state.sortOn && sortableColumns(state).length > 0;
|
|
31
|
+
const layouts = state.layouts.length > 1 ? state.layouts : [];
|
|
32
|
+
const canSelect = state.selectionOn && state.selectionShow === 'onDemand';
|
|
33
|
+
const { L } = state;
|
|
34
|
+
const hasQuick = state.filterOn && (state.quickFilters.length > 0 || state.savedFilters.length > 0);
|
|
35
|
+
const [quickOpen, setQuickOpen] = useState(false);
|
|
36
|
+
if (!state.searchOn && !canSort && !canSelect && !layouts.length && !hasQuick && !state.filterOn)
|
|
37
|
+
return null;
|
|
38
|
+
const single = state.quickFilterMode === 'single';
|
|
39
|
+
const quickLabel = state.quickFilterLabel || L.quickFilter;
|
|
40
|
+
const quickOptions = quickFilterOptions(state.quickFilters, state.savedFilters, state.quickFilterMode, L, state.format.number);
|
|
41
|
+
const activeName = state.quickFilterIds.map(id => quickOptions.find(o => o.value === id)?.name ?? id).join(', ');
|
|
42
|
+
const quickSelect = (openNow) => (_jsx(Select, { size: phone ? 'small' : 'xs', options: quickOptions, value: single ? state.quickFilterIds[0] ?? '' : state.quickFilterIds, onChange: e => {
|
|
43
|
+
const v = e.target.value;
|
|
44
|
+
if (single)
|
|
45
|
+
state.setQuickFilters(v ? [v] : []);
|
|
46
|
+
else
|
|
47
|
+
state.setQuickFilters(Array.isArray(v) ? v : [v]);
|
|
48
|
+
}, multiSelect: !single, group: state.savedFilters.length > 0, placeholder: quickLabel, defaultText: single ? L.quickFilterAll : quickLabel, "aria-label": quickLabel, defaultOpen: openNow, style: { marginBottom: 0 } }));
|
|
49
|
+
if (phone && quickOpen && hasQuick) {
|
|
50
|
+
return (_jsxs(View, { style: look.bar, children: [_jsx(ToolButton, { icon: IconArrowLeft, label: L.closeQuickFilter, size: look.button, onPress: () => setQuickOpen(false) }), _jsx(View, { style: look.search, children: quickSelect(true) })] }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsxs(View, { style: look.bar, children: [state.searchOn && (_jsx(View, { style: look.search, children: _jsx(Input, { type: "search", size: phone ? 'small' : 'xs', value: state.search, onChangeText: state.setSearch, placeholder: state.L.searchPlaceholder, "aria-label": state.L.search, clearable: true, icon: { start: _jsx(IconSearch, { size: "sm" }) }, style: { marginBottom: 0 } }) })), hasQuick && !phone && _jsx(View, { style: look.quick, children: quickSelect(false) }), _jsxs(View, { style: look.tools, children: [hasQuick && phone && (_jsx(ToolButton, { icon: IconBolt, label: state.quickFilterIds.length ? L.quickFilterOn(activeName) : quickLabel, size: look.button, active: state.quickFilterIds.length > 0, onPress: () => setQuickOpen(true) })), canSelect && (_jsx(ToolButton, { icon: IconSelectRows, label: state.selecting ? state.L.stopSelecting : state.L.selectRows, size: look.button, active: state.selecting, onPress: state.toggleSelecting })), canSort && (_jsx(ToolButton, { icon: IconSort, label: state.L.sort, size: look.button, active: state.sorting.length > 0, onPress: () => setSortOpen(true) })), layouts.length > 1 && (_jsx(LayoutSwitcher, { layouts: layouts, layout: state.layout, onChange: state.setLayout, L: state.L, size: look.button, compact: phone })), state.filterOn && (_jsx(ToolButton, { icon: IconFilter, label: state.activeFilters.length ? L.filtersOn(state.format.number(state.activeFilters.length)) : L.filters, size: look.button, badge: state.activeFilters.length, onPress: () => state.setFiltersOpen(true) }))] }), canSort && _jsx(SortSheet, { state: state, open: sortOpen, onClose: () => setSortOpen(false) })] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Text, View } from 'react-native';
|
|
3
|
+
import { hueOf, initialsOf } from '@dcs-tech/core';
|
|
4
|
+
import { useTokens } from '../UIProvider/context';
|
|
5
|
+
import { avatarLook } from './dataTableStyle';
|
|
6
|
+
export function CellNode({ node, style, lines }) {
|
|
7
|
+
if (node === null || node === undefined || node === false || node === '')
|
|
8
|
+
return null;
|
|
9
|
+
if (typeof node === 'string' || typeof node === 'number')
|
|
10
|
+
return _jsx(Text, { style: style, numberOfLines: lines, children: node });
|
|
11
|
+
return _jsx(_Fragment, { children: node });
|
|
12
|
+
}
|
|
13
|
+
export function RowAvatarView({ avatar, place }) {
|
|
14
|
+
const t = useTokens();
|
|
15
|
+
if (!avatar)
|
|
16
|
+
return null;
|
|
17
|
+
if ('node' in avatar)
|
|
18
|
+
return _jsx(_Fragment, { children: avatar.node });
|
|
19
|
+
const look = avatarLook(t, hueOf(avatar.initials), place);
|
|
20
|
+
return (_jsx(View, { style: look.box, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: _jsx(Text, { style: look.text, allowFontScaling: false, children: initialsOf(avatar.initials) }) }));
|
|
21
|
+
}
|