@bacon-pos/ui 0.9.0 → 0.10.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/lib/commonjs/components/EmptyState/EmptyState.js +88 -0
- package/lib/commonjs/components/EmptyState/EmptyState.js.map +1 -0
- package/lib/commonjs/components/EmptyState/EmptyState.stories.js +46 -0
- package/lib/commonjs/components/EmptyState/EmptyState.stories.js.map +1 -0
- package/lib/commonjs/components/EmptyState/EmptyState.test.js +40 -0
- package/lib/commonjs/components/EmptyState/EmptyState.test.js.map +1 -0
- package/lib/commonjs/components/EmptyState/index.js +13 -0
- package/lib/commonjs/components/EmptyState/index.js.map +1 -0
- package/lib/commonjs/components/Sidebar/Sidebar.js +264 -0
- package/lib/commonjs/components/Sidebar/Sidebar.js.map +1 -0
- package/lib/commonjs/components/Sidebar/Sidebar.stories.js +229 -0
- package/lib/commonjs/components/Sidebar/Sidebar.stories.js.map +1 -0
- package/lib/commonjs/components/Sidebar/Sidebar.test.js +131 -0
- package/lib/commonjs/components/Sidebar/Sidebar.test.js.map +1 -0
- package/lib/commonjs/components/Sidebar/index.js +13 -0
- package/lib/commonjs/components/Sidebar/index.js.map +1 -0
- package/lib/commonjs/components/Table/DataTable.js +149 -0
- package/lib/commonjs/components/Table/DataTable.js.map +1 -0
- package/lib/commonjs/components/Table/DataTable.stories.js +214 -0
- package/lib/commonjs/components/Table/DataTable.stories.js.map +1 -0
- package/lib/commonjs/components/Table/DataTable.test.js +143 -0
- package/lib/commonjs/components/Table/DataTable.test.js.map +1 -0
- package/lib/commonjs/components/Table/Table.js +520 -0
- package/lib/commonjs/components/Table/Table.js.map +1 -0
- package/lib/commonjs/components/Table/Table.stories.js +385 -0
- package/lib/commonjs/components/Table/Table.stories.js.map +1 -0
- package/lib/commonjs/components/Table/Table.test.js +278 -0
- package/lib/commonjs/components/Table/Table.test.js.map +1 -0
- package/lib/commonjs/components/Table/index.js +20 -0
- package/lib/commonjs/components/Table/index.js.map +1 -0
- package/lib/commonjs/components/brand/BaconLogo.js +29 -0
- package/lib/commonjs/components/brand/BaconLogo.js.map +1 -0
- package/lib/commonjs/components/brand/index.js +7 -0
- package/lib/commonjs/components/brand/index.js.map +1 -1
- package/lib/commonjs/components/index.js +50 -17
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/module/components/EmptyState/EmptyState.js +84 -0
- package/lib/module/components/EmptyState/EmptyState.js.map +1 -0
- package/lib/module/components/EmptyState/EmptyState.stories.js +42 -0
- package/lib/module/components/EmptyState/EmptyState.stories.js.map +1 -0
- package/lib/module/components/EmptyState/EmptyState.test.js +40 -0
- package/lib/module/components/EmptyState/EmptyState.test.js.map +1 -0
- package/lib/module/components/EmptyState/index.js +4 -0
- package/lib/module/components/EmptyState/index.js.map +1 -0
- package/lib/module/components/Sidebar/Sidebar.js +260 -0
- package/lib/module/components/Sidebar/Sidebar.js.map +1 -0
- package/lib/module/components/Sidebar/Sidebar.stories.js +225 -0
- package/lib/module/components/Sidebar/Sidebar.stories.js.map +1 -0
- package/lib/module/components/Sidebar/Sidebar.test.js +131 -0
- package/lib/module/components/Sidebar/Sidebar.test.js.map +1 -0
- package/lib/module/components/Sidebar/index.js +4 -0
- package/lib/module/components/Sidebar/index.js.map +1 -0
- package/lib/module/components/Table/DataTable.js +145 -0
- package/lib/module/components/Table/DataTable.js.map +1 -0
- package/lib/module/components/Table/DataTable.stories.js +210 -0
- package/lib/module/components/Table/DataTable.stories.js.map +1 -0
- package/lib/module/components/Table/DataTable.test.js +143 -0
- package/lib/module/components/Table/DataTable.test.js.map +1 -0
- package/lib/module/components/Table/Table.js +516 -0
- package/lib/module/components/Table/Table.js.map +1 -0
- package/lib/module/components/Table/Table.stories.js +381 -0
- package/lib/module/components/Table/Table.stories.js.map +1 -0
- package/lib/module/components/Table/Table.test.js +278 -0
- package/lib/module/components/Table/Table.test.js.map +1 -0
- package/lib/module/components/Table/index.js +5 -0
- package/lib/module/components/Table/index.js.map +1 -0
- package/lib/module/components/brand/BaconLogo.js +25 -0
- package/lib/module/components/brand/BaconLogo.js.map +1 -0
- package/lib/module/components/brand/index.js +1 -0
- package/lib/module/components/brand/index.js.map +1 -1
- package/lib/module/components/index.js +3 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/typescript/commonjs/components/EmptyState/EmptyState.d.ts +30 -0
- package/lib/typescript/commonjs/components/EmptyState/EmptyState.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/EmptyState/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/EmptyState/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Sidebar/Sidebar.d.ts +57 -0
- package/lib/typescript/commonjs/components/Sidebar/Sidebar.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Sidebar/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/Sidebar/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Table/DataTable.d.ts +53 -0
- package/lib/typescript/commonjs/components/Table/DataTable.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Table/Table.d.ts +85 -0
- package/lib/typescript/commonjs/components/Table/Table.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Table/index.d.ts +5 -0
- package/lib/typescript/commonjs/components/Table/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/brand/BaconLogo.d.ts +13 -0
- package/lib/typescript/commonjs/components/brand/BaconLogo.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/brand/index.d.ts +1 -0
- package/lib/typescript/commonjs/components/brand/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/components/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/index.d.ts.map +1 -1
- package/lib/typescript/module/components/EmptyState/EmptyState.d.ts +30 -0
- package/lib/typescript/module/components/EmptyState/EmptyState.d.ts.map +1 -0
- package/lib/typescript/module/components/EmptyState/index.d.ts +3 -0
- package/lib/typescript/module/components/EmptyState/index.d.ts.map +1 -0
- package/lib/typescript/module/components/Sidebar/Sidebar.d.ts +57 -0
- package/lib/typescript/module/components/Sidebar/Sidebar.d.ts.map +1 -0
- package/lib/typescript/module/components/Sidebar/index.d.ts +3 -0
- package/lib/typescript/module/components/Sidebar/index.d.ts.map +1 -0
- package/lib/typescript/module/components/Table/DataTable.d.ts +53 -0
- package/lib/typescript/module/components/Table/DataTable.d.ts.map +1 -0
- package/lib/typescript/module/components/Table/Table.d.ts +85 -0
- package/lib/typescript/module/components/Table/Table.d.ts.map +1 -0
- package/lib/typescript/module/components/Table/index.d.ts +5 -0
- package/lib/typescript/module/components/Table/index.d.ts.map +1 -0
- package/lib/typescript/module/components/brand/BaconLogo.d.ts +13 -0
- package/lib/typescript/module/components/brand/BaconLogo.d.ts.map +1 -0
- package/lib/typescript/module/components/brand/index.d.ts +1 -0
- package/lib/typescript/module/components/brand/index.d.ts.map +1 -1
- package/lib/typescript/module/components/index.d.ts +3 -0
- package/lib/typescript/module/components/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/EmptyState/EmptyState.tsx +91 -0
- package/src/components/EmptyState/index.ts +2 -0
- package/src/components/Sidebar/Sidebar.tsx +320 -0
- package/src/components/Sidebar/index.ts +2 -0
- package/src/components/Table/DataTable.tsx +173 -0
- package/src/components/Table/Table.tsx +556 -0
- package/src/components/Table/index.ts +10 -0
- package/src/components/brand/BaconLogo.tsx +25 -0
- package/src/components/brand/index.ts +1 -0
- package/src/components/index.ts +3 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import { useTheme } from '../../theme';
|
|
4
|
+
import { Button } from '../Button/Button';
|
|
5
|
+
import { ChipGroup } from '../Chip/ChipGroup';
|
|
6
|
+
import { EmptyState, type EmptyStateProps } from '../EmptyState/EmptyState';
|
|
7
|
+
import { Icon } from '../Icon/Icon';
|
|
8
|
+
import type { IconName } from '../Icon/icons.generated';
|
|
9
|
+
import { IconButton } from '../IconButton/IconButton';
|
|
10
|
+
import { Input } from '../Input/Input';
|
|
11
|
+
import { Text } from '../Text/Text';
|
|
12
|
+
import { Table, type TableProps } from './Table';
|
|
13
|
+
|
|
14
|
+
export interface DataTableTab {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
icon?: IconName;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DataTablePagination {
|
|
21
|
+
/** 1-based current page. */
|
|
22
|
+
page: number;
|
|
23
|
+
pageSize: number;
|
|
24
|
+
/** Total row count (across pages). */
|
|
25
|
+
total: number;
|
|
26
|
+
onPageChange: (page: number) => void;
|
|
27
|
+
/** Customize the range label. Defaults to `${from}–${to} of ${total}`. */
|
|
28
|
+
formatRange?: (from: number, to: number, total: number) => string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DataTableProps<T> extends Omit<TableProps<T>, 'empty'> {
|
|
32
|
+
/** Tabs above the toolbar (reuses `ChipGroup`). */
|
|
33
|
+
tabs?: DataTableTab[];
|
|
34
|
+
/** Active tab (controlled). */
|
|
35
|
+
activeTab?: string;
|
|
36
|
+
defaultTab?: string;
|
|
37
|
+
onTabChange?: (value: string) => void;
|
|
38
|
+
|
|
39
|
+
/** Show the search field. */
|
|
40
|
+
searchable?: boolean;
|
|
41
|
+
searchValue?: string;
|
|
42
|
+
onSearchChange?: (value: string) => void;
|
|
43
|
+
searchPlaceholder?: string;
|
|
44
|
+
|
|
45
|
+
/** Show a create button on the right of the toolbar. */
|
|
46
|
+
createLabel?: string;
|
|
47
|
+
onCreate?: () => void;
|
|
48
|
+
createIcon?: IconName;
|
|
49
|
+
|
|
50
|
+
/** Structured empty state (alternative to Table's `empty` node). */
|
|
51
|
+
emptyState?: EmptyStateProps;
|
|
52
|
+
/** Raw empty node (wins over `emptyState`). */
|
|
53
|
+
empty?: React.ReactNode;
|
|
54
|
+
|
|
55
|
+
/** Pagination controls below the table. */
|
|
56
|
+
pagination?: DataTablePagination;
|
|
57
|
+
|
|
58
|
+
/** Gap between toolbar sections. Defaults to 16. */
|
|
59
|
+
gap?: number;
|
|
60
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* DataTable — the turnkey management table (Figma): optional tabs (`ChipGroup`),
|
|
65
|
+
* a search + create toolbar, the `Table` body, a structured `EmptyState`, and
|
|
66
|
+
* optional pagination — assembled with consistent spacing. For bespoke layouts,
|
|
67
|
+
* compose `Table` + `EmptyState` yourself.
|
|
68
|
+
*/
|
|
69
|
+
export function DataTable<T>({
|
|
70
|
+
tabs,
|
|
71
|
+
activeTab,
|
|
72
|
+
defaultTab,
|
|
73
|
+
onTabChange,
|
|
74
|
+
searchable = false,
|
|
75
|
+
searchValue,
|
|
76
|
+
onSearchChange,
|
|
77
|
+
searchPlaceholder = 'Search…',
|
|
78
|
+
createLabel,
|
|
79
|
+
onCreate,
|
|
80
|
+
createIcon = 'plus',
|
|
81
|
+
emptyState,
|
|
82
|
+
empty,
|
|
83
|
+
pagination,
|
|
84
|
+
gap = 16,
|
|
85
|
+
containerStyle,
|
|
86
|
+
...tableProps
|
|
87
|
+
}: DataTableProps<T>) {
|
|
88
|
+
const theme = useTheme();
|
|
89
|
+
|
|
90
|
+
const tabControlled = activeTab !== undefined;
|
|
91
|
+
const [tabInternal, setTabInternal] = useState<string | null>(defaultTab ?? tabs?.[0]?.value ?? null);
|
|
92
|
+
const currentTab = tabControlled ? activeTab : tabInternal;
|
|
93
|
+
const setTab = (value: string | null) => {
|
|
94
|
+
if (value == null) return; // tabs are not deselectable
|
|
95
|
+
if (!tabControlled) setTabInternal(value);
|
|
96
|
+
onTabChange?.(value);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const emptyNode = empty ?? (emptyState ? <EmptyState {...emptyState} /> : undefined);
|
|
100
|
+
|
|
101
|
+
const showToolbar = searchable || !!createLabel;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<View style={[{ gap }, containerStyle]}>
|
|
105
|
+
{tabs && tabs.length > 0 ? (
|
|
106
|
+
<ChipGroup
|
|
107
|
+
tone="dark"
|
|
108
|
+
options={tabs.map((t) => ({ value: t.value, label: t.label, icon: t.icon }))}
|
|
109
|
+
value={currentTab}
|
|
110
|
+
onChange={setTab}
|
|
111
|
+
/>
|
|
112
|
+
) : null}
|
|
113
|
+
|
|
114
|
+
{showToolbar ? (
|
|
115
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12, flexWrap: 'wrap' }}>
|
|
116
|
+
{searchable ? (
|
|
117
|
+
<View style={{ flex: 1, minWidth: 220 }}>
|
|
118
|
+
<Input
|
|
119
|
+
value={searchValue}
|
|
120
|
+
onChangeText={onSearchChange}
|
|
121
|
+
placeholder={searchPlaceholder}
|
|
122
|
+
leftIcon={<Icon name="search" size={24} color="tertiary" />}
|
|
123
|
+
/>
|
|
124
|
+
</View>
|
|
125
|
+
) : null}
|
|
126
|
+
{createLabel ? (
|
|
127
|
+
<Button
|
|
128
|
+
label={createLabel}
|
|
129
|
+
variant="inverse"
|
|
130
|
+
size="md"
|
|
131
|
+
onPress={onCreate}
|
|
132
|
+
leftIcon={<Icon name={createIcon} size={24} color={theme.colors.action.inverseForeground} />}
|
|
133
|
+
/>
|
|
134
|
+
) : null}
|
|
135
|
+
</View>
|
|
136
|
+
) : null}
|
|
137
|
+
|
|
138
|
+
<Table {...tableProps} empty={emptyNode} />
|
|
139
|
+
|
|
140
|
+
{pagination ? <Paginator {...pagination} /> : null}
|
|
141
|
+
</View>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function Paginator({ page, pageSize, total, onPageChange, formatRange }: DataTablePagination) {
|
|
146
|
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
|
147
|
+
const from = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
148
|
+
const to = Math.min(page * pageSize, total);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-end', gap: 12 }}>
|
|
152
|
+
<Text variant="bodySmall" color="secondary">
|
|
153
|
+
{formatRange ? formatRange(from, to, total) : `${from}–${to} of ${total}`}
|
|
154
|
+
</Text>
|
|
155
|
+
<IconButton
|
|
156
|
+
icon="arrow-left"
|
|
157
|
+
accessibilityLabel="Previous page"
|
|
158
|
+
variant="secondary"
|
|
159
|
+
size="sm"
|
|
160
|
+
disabled={page <= 1}
|
|
161
|
+
onPress={() => onPageChange(page - 1)}
|
|
162
|
+
/>
|
|
163
|
+
<IconButton
|
|
164
|
+
icon="arrow-right"
|
|
165
|
+
accessibilityLabel="Next page"
|
|
166
|
+
variant="secondary"
|
|
167
|
+
size="sm"
|
|
168
|
+
disabled={page >= totalPages}
|
|
169
|
+
onPress={() => onPageChange(page + 1)}
|
|
170
|
+
/>
|
|
171
|
+
</View>
|
|
172
|
+
);
|
|
173
|
+
}
|