@archbase/components 3.0.25 → 4.0.1
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/dist/buttons/ArchbaseSpeedDial.d.ts +59 -0
- package/dist/buttons/index.d.ts +2 -0
- package/dist/charts/ArchbaseArcGauge.d.ts +55 -0
- package/dist/charts/ArchbaseGantt.d.ts +70 -0
- package/dist/charts/ArchbaseLinearGauge.d.ts +55 -0
- package/dist/charts/ArchbaseResourceTimeline.d.ts +61 -0
- package/dist/charts/ArchbaseSparkline.d.ts +45 -0
- package/dist/charts/index.d.ts +10 -0
- package/dist/containers/ArchbaseExpansionPanel.d.ts +60 -0
- package/dist/containers/ArchbaseFloatingPanel.d.ts +91 -0
- package/dist/containers/index.d.ts +4 -0
- package/dist/datagrid/export/ArchbaseDataGridExcelExport.d.ts +67 -0
- package/dist/datagrid/export/index.d.ts +2 -0
- package/dist/datagrid/index.d.ts +1 -0
- package/dist/display/ArchbaseAnimationWrapper.d.ts +73 -0
- package/dist/display/ArchbaseBarcodeGenerator.d.ts +50 -0
- package/dist/display/ArchbaseCarousel.d.ts +100 -0
- package/dist/display/ArchbaseCodeViewer.d.ts +63 -0
- package/dist/display/ArchbaseDiffViewer.d.ts +41 -0
- package/dist/display/ArchbaseJsonTree.d.ts +34 -0
- package/dist/display/ArchbaseLightbox.d.ts +89 -0
- package/dist/display/ArchbaseMarquee.d.ts +46 -0
- package/dist/display/ArchbasePhotoAlbum.d.ts +58 -0
- package/dist/display/ArchbaseQRCode.d.ts +44 -0
- package/dist/display/ArchbaseTooltipRich.d.ts +82 -0
- package/dist/display/ArchbaseVirtualList.d.ts +116 -0
- package/dist/display/index.d.ts +24 -0
- package/dist/editors/ArchbaseAIPromptInput.d.ts +69 -0
- package/dist/editors/ArchbaseAsyncMultiSelect.d.ts +1 -1
- package/dist/editors/ArchbaseAsyncSelect.d.ts +1 -1
- package/dist/editors/ArchbaseBarcodeScanner.d.ts +63 -0
- package/dist/editors/ArchbaseCepInput.d.ts +26 -0
- package/dist/editors/ArchbaseColorGradientPicker.d.ts +80 -0
- package/dist/editors/ArchbaseCpfCnpjInput.d.ts +21 -0
- package/dist/editors/ArchbaseCurrencyInput.d.ts +25 -0
- package/dist/editors/ArchbaseDualListbox.d.ts +61 -0
- package/dist/editors/ArchbaseInPlaceEditor.d.ts +67 -0
- package/dist/editors/ArchbaseLightGrid.d.ts +56 -0
- package/dist/editors/ArchbaseMentionInput.d.ts +75 -0
- package/dist/editors/ArchbaseMultiEmail.d.ts +53 -0
- package/dist/editors/ArchbaseMultiViewCalendar.d.ts +47 -0
- package/dist/editors/ArchbaseNumberStepper.d.ts +66 -0
- package/dist/editors/ArchbaseOTPInput.d.ts +27 -0
- package/dist/editors/ArchbasePhoneInput.d.ts +52 -0
- package/dist/editors/ArchbaseRangeSlider.d.ts +22 -0
- package/dist/editors/ArchbaseSignaturePad.d.ts +60 -0
- package/dist/editors/ArchbaseSpeechToTextInput.d.ts +106 -0
- package/dist/editors/ArchbaseSpreadsheet.d.ts +56 -0
- package/dist/editors/ArchbaseTagInput.d.ts +55 -0
- package/dist/editors/index.d.ts +40 -0
- package/dist/feedback/ArchbaseChunkProgressBar.d.ts +35 -0
- package/dist/feedback/ArchbaseRipple.d.ts +43 -0
- package/dist/feedback/ArchbaseSkeleton.d.ts +115 -0
- package/dist/feedback/index.d.ts +6 -0
- package/dist/filters/ArchbaseColumnSelector.d.ts +38 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/forms/ArchbaseFieldArray.d.ts +80 -0
- package/dist/forms/ArchbaseFormWizard.d.ts +73 -0
- package/dist/forms/ArchbaseStepper.d.ts +51 -0
- package/dist/forms/index.d.ts +8 -0
- package/dist/forms/useArchbaseFormWizard.d.ts +74 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useArchbaseConfirm.d.ts +59 -0
- package/dist/image/editor/index.d.ts +43 -4
- package/dist/image/index.d.ts +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22510 -13820
- package/dist/list/ArchbaseTreeList.d.ts +76 -0
- package/dist/list/index.d.ts +2 -0
- package/dist/navigation/ArchbaseActionSheet.d.ts +70 -0
- package/dist/navigation/ArchbaseAppBar.d.ts +63 -0
- package/dist/navigation/ArchbaseBottomNavigation.d.ts +61 -0
- package/dist/navigation/ArchbaseContextMenu.d.ts +76 -0
- package/dist/navigation/ArchbaseKeyboardShortcuts.d.ts +85 -0
- package/dist/navigation/ArchbaseSpotlight.d.ts +69 -0
- package/dist/navigation/index.d.ts +12 -0
- package/dist/notification/ArchbaseNotificationCenter.d.ts +56 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/onboarding/ArchbaseOnboardingTour.d.ts +27 -76
- package/dist/viewers/ArchbaseDocViewer.d.ts +40 -0
- package/dist/viewers/ArchbasePdfBuilder.d.ts +53 -0
- package/dist/viewers/ArchbaseXmlViewer.d.ts +36 -0
- package/dist/viewers/index.d.ts +6 -0
- package/package.json +41 -18
- package/src/buttons/ArchbaseSpeedDial.tsx +282 -0
- package/src/buttons/index.ts +3 -0
- package/src/charts/ArchbaseArcGauge.tsx +325 -0
- package/src/charts/ArchbaseGantt.tsx +494 -0
- package/src/charts/ArchbaseLinearGauge.tsx +288 -0
- package/src/charts/ArchbaseResourceTimeline.tsx +433 -0
- package/src/charts/ArchbaseSparkline.tsx +193 -0
- package/src/charts/index.ts +20 -1
- package/src/containers/ArchbaseExpansionPanel.tsx +208 -0
- package/src/containers/ArchbaseFloatingPanel.tsx +448 -0
- package/src/containers/index.ts +17 -0
- package/src/datagrid/components/pagination/grid-pagination.tsx +2 -2
- package/src/datagrid/export/ArchbaseDataGridExcelExport.tsx +293 -0
- package/src/datagrid/export/index.ts +8 -0
- package/src/datagrid/index.tsx +2 -0
- package/src/display/ArchbaseAnimationWrapper.tsx +272 -0
- package/src/display/ArchbaseBarcodeGenerator.tsx +303 -0
- package/src/display/ArchbaseCarousel.tsx +679 -0
- package/src/display/ArchbaseCodeViewer.tsx +271 -0
- package/src/display/ArchbaseDiffViewer.tsx +108 -0
- package/src/display/ArchbaseJsonTree.tsx +150 -0
- package/src/display/ArchbaseLightbox.tsx +279 -0
- package/src/display/ArchbaseMarquee.tsx +268 -0
- package/src/display/ArchbasePhotoAlbum.tsx +415 -0
- package/src/display/ArchbaseQRCode.tsx +137 -0
- package/src/display/ArchbaseTooltipRich.tsx +317 -0
- package/src/display/ArchbaseVirtualList.tsx +618 -0
- package/src/display/index.ts +94 -1
- package/src/editors/ArchbaseAIPromptInput.tsx +432 -0
- package/src/editors/ArchbaseBarcodeScanner.tsx +570 -0
- package/src/editors/ArchbaseCepInput.tsx +173 -0
- package/src/editors/ArchbaseColorGradientPicker.tsx +460 -0
- package/src/editors/ArchbaseCpfCnpjInput.tsx +193 -0
- package/src/editors/ArchbaseCurrencyInput.tsx +100 -0
- package/src/editors/ArchbaseDualListbox.tsx +671 -0
- package/src/editors/ArchbaseInPlaceEditor.tsx +406 -0
- package/src/editors/ArchbaseLightGrid.tsx +538 -0
- package/src/editors/ArchbaseMentionInput.tsx +384 -0
- package/src/editors/ArchbaseMultiEmail.tsx +367 -0
- package/src/editors/ArchbaseMultiViewCalendar.tsx +439 -0
- package/src/editors/ArchbaseNumberStepper.tsx +219 -0
- package/src/editors/ArchbaseOTPInput.tsx +133 -0
- package/src/editors/ArchbaseOperationHoursEditor.tsx +1 -1
- package/src/editors/ArchbasePhoneInput.tsx +355 -0
- package/src/editors/ArchbaseRangeSlider.tsx +109 -0
- package/src/editors/ArchbaseSignaturePad.tsx +425 -0
- package/src/editors/ArchbaseSpeechToTextInput.tsx +444 -0
- package/src/editors/ArchbaseSpreadsheet.tsx +388 -0
- package/src/editors/ArchbaseTagInput.tsx +326 -0
- package/src/editors/index.tsx +92 -0
- package/src/feedback/ArchbaseChunkProgressBar.tsx +156 -0
- package/src/feedback/ArchbaseRipple.tsx +278 -0
- package/src/feedback/ArchbaseSkeleton.tsx +419 -0
- package/src/feedback/index.ts +22 -1
- package/src/filters/ArchbaseColumnSelector.tsx +268 -0
- package/src/filters/index.ts +2 -0
- package/src/forms/ArchbaseFieldArray.tsx +305 -0
- package/src/forms/ArchbaseFormWizard.tsx +284 -0
- package/src/forms/ArchbaseStepper.tsx +137 -0
- package/src/forms/index.ts +24 -2
- package/src/forms/useArchbaseFormWizard.ts +283 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useArchbaseConfirm.ts +293 -0
- package/src/image/editor/functions/image-processing.ts +5 -0
- package/src/image/editor/index.tsx +305 -391
- package/src/image/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/list/ArchbaseTreeList.tsx +422 -0
- package/src/list/index.ts +3 -0
- package/src/navigation/ArchbaseActionSheet.tsx +301 -0
- package/src/navigation/ArchbaseAppBar.tsx +233 -0
- package/src/navigation/ArchbaseBottomNavigation.tsx +243 -0
- package/src/navigation/ArchbaseContextMenu.tsx +298 -0
- package/src/navigation/ArchbaseKeyboardShortcuts.tsx +472 -0
- package/src/navigation/ArchbaseSpotlight.tsx +483 -0
- package/src/navigation/index.ts +48 -1
- package/src/notification/ArchbaseNotificationCenter.tsx +502 -0
- package/src/notification/index.ts +2 -0
- package/src/onboarding/ArchbaseOnboardingTour.tsx +229 -102
- package/src/viewers/ArchbaseDocViewer.tsx +584 -0
- package/src/viewers/ArchbasePdfBuilder.tsx +291 -0
- package/src/viewers/ArchbaseXmlViewer.tsx +142 -0
- package/src/viewers/index.ts +12 -0
package/src/image/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { ArchbaseImage } from './ArchbaseImage';
|
|
|
2
2
|
export type { ArchbaseImageProps } from './ArchbaseImage';
|
|
3
3
|
export type { ArchbaseImagePickerConf } from './editor';
|
|
4
4
|
export { ArchbaseImagePickerEditor } from './editor';
|
|
5
|
+
export type { ArchbaseImagePickerEditorProps } from './editor';
|
|
5
6
|
export { ArchbaseMicrosoftAvatar, DEFAULT_AVATAR } from './ArchbaseMicrosoftAvatar';
|
|
6
7
|
export type { ArchbaseMicrosoftAvatarProps } from './ArchbaseMicrosoftAvatar';
|
|
7
8
|
export { languages } from './languages';
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo, useState, ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Box,
|
|
4
|
+
Table,
|
|
5
|
+
Checkbox,
|
|
6
|
+
Text,
|
|
7
|
+
ActionIcon,
|
|
8
|
+
Group,
|
|
9
|
+
ScrollArea,
|
|
10
|
+
MantineColor,
|
|
11
|
+
MantineSize,
|
|
12
|
+
} from '@mantine/core';
|
|
13
|
+
import { IconChevronRight, IconChevronDown } from '@tabler/icons-react';
|
|
14
|
+
import { ArchbaseDataSource, DataSourceEvent, DataSourceEventNames } from '@archbase/data';
|
|
15
|
+
import { useArchbaseDidMount, useArchbaseDidUpdate, useArchbaseWillUnmount } from '@archbase/core';
|
|
16
|
+
|
|
17
|
+
export interface ArchbaseTreeListColumn<T> {
|
|
18
|
+
/** ID da coluna */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Header da coluna */
|
|
21
|
+
header: string;
|
|
22
|
+
/** Accessor do campo */
|
|
23
|
+
accessor: keyof T | ((row: T) => any);
|
|
24
|
+
/** Largura da coluna */
|
|
25
|
+
width?: number | string;
|
|
26
|
+
/** Alinhamento */
|
|
27
|
+
align?: 'left' | 'center' | 'right';
|
|
28
|
+
/** Renderizador customizado */
|
|
29
|
+
render?: (value: any, row: T, index: number) => ReactNode;
|
|
30
|
+
/** Se é a coluna de árvore (com indent e expand) */
|
|
31
|
+
isTreeColumn?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ArchbaseTreeListProps<T extends object, ID> {
|
|
35
|
+
/** Dados da árvore */
|
|
36
|
+
data?: T[];
|
|
37
|
+
/** Fonte de dados */
|
|
38
|
+
dataSource?: ArchbaseDataSource<T, ID>;
|
|
39
|
+
/** Colunas */
|
|
40
|
+
columns: ArchbaseTreeListColumn<T>[];
|
|
41
|
+
/** Função para obter filhos de um item */
|
|
42
|
+
getSubRows?: (row: T) => T[] | undefined;
|
|
43
|
+
/** Campo que contém os filhos */
|
|
44
|
+
childrenField?: string;
|
|
45
|
+
/** Campo de ID único */
|
|
46
|
+
idField?: keyof T;
|
|
47
|
+
/** IDs expandidos (controlado) */
|
|
48
|
+
expandedIds?: Set<any>;
|
|
49
|
+
/** IDs expandidos por padrão */
|
|
50
|
+
defaultExpandedIds?: Set<any>;
|
|
51
|
+
/** Se deve expandir todos por padrão */
|
|
52
|
+
defaultExpandAll?: boolean;
|
|
53
|
+
/** Callback ao expandir/colapsar */
|
|
54
|
+
onExpandChange?: (expandedIds: Set<any>) => void;
|
|
55
|
+
/** Profundidade máxima */
|
|
56
|
+
maxDepth?: number;
|
|
57
|
+
/** Indentação por nível em pixels */
|
|
58
|
+
indentSize?: number;
|
|
59
|
+
/** Se deve mostrar linhas de conexão */
|
|
60
|
+
showLines?: boolean;
|
|
61
|
+
/** Se permite seleção */
|
|
62
|
+
selectable?: boolean;
|
|
63
|
+
/** Modo de seleção */
|
|
64
|
+
selectionMode?: 'single' | 'multiple';
|
|
65
|
+
/** IDs selecionados */
|
|
66
|
+
selectedIds?: Set<any>;
|
|
67
|
+
/** Callback ao selecionar */
|
|
68
|
+
onSelectionChange?: (selectedIds: Set<any>) => void;
|
|
69
|
+
/** Cor de destaque */
|
|
70
|
+
highlightColor?: MantineColor;
|
|
71
|
+
/** Altura da linha */
|
|
72
|
+
rowHeight?: number;
|
|
73
|
+
/** Altura máxima (scroll) */
|
|
74
|
+
maxHeight?: number | string;
|
|
75
|
+
/** Tamanho */
|
|
76
|
+
size?: MantineSize;
|
|
77
|
+
/** Se deve ter bordas */
|
|
78
|
+
withBorder?: boolean;
|
|
79
|
+
/** Se deve ter listras */
|
|
80
|
+
striped?: boolean;
|
|
81
|
+
/** Se deve destacar no hover */
|
|
82
|
+
highlightOnHover?: boolean;
|
|
83
|
+
/** Classe CSS */
|
|
84
|
+
className?: string;
|
|
85
|
+
/** Estilo */
|
|
86
|
+
style?: React.CSSProperties;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface FlattenedRow<T> {
|
|
90
|
+
data: T;
|
|
91
|
+
id: any;
|
|
92
|
+
depth: number;
|
|
93
|
+
hasChildren: boolean;
|
|
94
|
+
isExpanded: boolean;
|
|
95
|
+
parentId: any | null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function ArchbaseTreeListInner<T extends object, ID>(
|
|
99
|
+
{
|
|
100
|
+
data: controlledData,
|
|
101
|
+
dataSource,
|
|
102
|
+
columns,
|
|
103
|
+
getSubRows,
|
|
104
|
+
childrenField = 'children',
|
|
105
|
+
idField = 'id' as keyof T,
|
|
106
|
+
expandedIds: controlledExpandedIds,
|
|
107
|
+
defaultExpandedIds,
|
|
108
|
+
defaultExpandAll = false,
|
|
109
|
+
onExpandChange,
|
|
110
|
+
maxDepth = Infinity,
|
|
111
|
+
indentSize = 24,
|
|
112
|
+
showLines = false,
|
|
113
|
+
selectable = false,
|
|
114
|
+
selectionMode = 'single',
|
|
115
|
+
selectedIds: controlledSelectedIds,
|
|
116
|
+
onSelectionChange,
|
|
117
|
+
highlightColor = 'blue',
|
|
118
|
+
rowHeight = 40,
|
|
119
|
+
maxHeight,
|
|
120
|
+
size = 'sm',
|
|
121
|
+
withBorder = true,
|
|
122
|
+
striped = false,
|
|
123
|
+
highlightOnHover = true,
|
|
124
|
+
className,
|
|
125
|
+
style,
|
|
126
|
+
}: ArchbaseTreeListProps<T, ID>,
|
|
127
|
+
ref: React.Ref<HTMLDivElement>
|
|
128
|
+
) {
|
|
129
|
+
const [internalData, setInternalData] = useState<T[]>([]);
|
|
130
|
+
const [internalExpandedIds, setInternalExpandedIds] = useState<Set<any>>(
|
|
131
|
+
defaultExpandedIds || new Set()
|
|
132
|
+
);
|
|
133
|
+
const [internalSelectedIds, setInternalSelectedIds] = useState<Set<any>>(new Set());
|
|
134
|
+
|
|
135
|
+
// Dados atuais
|
|
136
|
+
const currentData = controlledData || internalData;
|
|
137
|
+
const expandedIds = controlledExpandedIds || internalExpandedIds;
|
|
138
|
+
const selectedIds = controlledSelectedIds || internalSelectedIds;
|
|
139
|
+
|
|
140
|
+
// Carrega dados do DataSource
|
|
141
|
+
const loadDataSourceData = useCallback(() => {
|
|
142
|
+
if (dataSource) {
|
|
143
|
+
const records = dataSource.browseRecords();
|
|
144
|
+
setInternalData(records as T[]);
|
|
145
|
+
}
|
|
146
|
+
}, [dataSource]);
|
|
147
|
+
|
|
148
|
+
const dataSourceEvent = useCallback(
|
|
149
|
+
(event: DataSourceEvent<T>) => {
|
|
150
|
+
if (
|
|
151
|
+
event.type === DataSourceEventNames.dataChanged ||
|
|
152
|
+
event.type === DataSourceEventNames.recordChanged ||
|
|
153
|
+
event.type === DataSourceEventNames.afterScroll
|
|
154
|
+
) {
|
|
155
|
+
loadDataSourceData();
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
[loadDataSourceData]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
useArchbaseDidMount(() => {
|
|
162
|
+
loadDataSourceData();
|
|
163
|
+
if (dataSource) {
|
|
164
|
+
dataSource.addListener(dataSourceEvent);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Expande todos se defaultExpandAll
|
|
168
|
+
if (defaultExpandAll && currentData.length > 0) {
|
|
169
|
+
const allIds = new Set<any>();
|
|
170
|
+
const collectIds = (items: T[]) => {
|
|
171
|
+
items.forEach((item) => {
|
|
172
|
+
allIds.add(item[idField]);
|
|
173
|
+
const children = getSubRows?.(item) || (item as any)[childrenField];
|
|
174
|
+
if (children?.length) {
|
|
175
|
+
collectIds(children);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
collectIds(currentData);
|
|
180
|
+
setInternalExpandedIds(allIds);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
useArchbaseWillUnmount(() => {
|
|
185
|
+
if (dataSource) {
|
|
186
|
+
dataSource.removeListener(dataSourceEvent);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
useArchbaseDidUpdate(() => {
|
|
191
|
+
loadDataSourceData();
|
|
192
|
+
}, []);
|
|
193
|
+
|
|
194
|
+
// Função para obter filhos
|
|
195
|
+
const getChildren = useCallback(
|
|
196
|
+
(row: T): T[] | undefined => {
|
|
197
|
+
if (getSubRows) {
|
|
198
|
+
return getSubRows(row);
|
|
199
|
+
}
|
|
200
|
+
return (row as any)[childrenField];
|
|
201
|
+
},
|
|
202
|
+
[childrenField, getSubRows]
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// Achata a árvore para renderização
|
|
206
|
+
const flattenedRows = useMemo((): FlattenedRow<T>[] => {
|
|
207
|
+
const result: FlattenedRow<T>[] = [];
|
|
208
|
+
|
|
209
|
+
const flatten = (items: T[], depth: number, parentId: any | null) => {
|
|
210
|
+
if (depth > maxDepth) return;
|
|
211
|
+
|
|
212
|
+
items.forEach((item) => {
|
|
213
|
+
const id = item[idField];
|
|
214
|
+
const children = getChildren(item);
|
|
215
|
+
const hasChildren = children && children.length > 0;
|
|
216
|
+
const isExpanded = expandedIds.has(id);
|
|
217
|
+
|
|
218
|
+
result.push({
|
|
219
|
+
data: item,
|
|
220
|
+
id,
|
|
221
|
+
depth,
|
|
222
|
+
hasChildren,
|
|
223
|
+
isExpanded,
|
|
224
|
+
parentId,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (hasChildren && isExpanded) {
|
|
228
|
+
flatten(children, depth + 1, id);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
flatten(currentData, 0, null);
|
|
234
|
+
return result;
|
|
235
|
+
}, [currentData, expandedIds, getChildren, idField, maxDepth]);
|
|
236
|
+
|
|
237
|
+
// Toggle expand
|
|
238
|
+
const toggleExpand = useCallback(
|
|
239
|
+
(id: any) => {
|
|
240
|
+
const newExpanded = new Set(expandedIds);
|
|
241
|
+
if (newExpanded.has(id)) {
|
|
242
|
+
newExpanded.delete(id);
|
|
243
|
+
} else {
|
|
244
|
+
newExpanded.add(id);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (controlledExpandedIds === undefined) {
|
|
248
|
+
setInternalExpandedIds(newExpanded);
|
|
249
|
+
}
|
|
250
|
+
onExpandChange?.(newExpanded);
|
|
251
|
+
},
|
|
252
|
+
[controlledExpandedIds, expandedIds, onExpandChange]
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Toggle seleção
|
|
256
|
+
const toggleSelection = useCallback(
|
|
257
|
+
(id: any) => {
|
|
258
|
+
let newSelected: Set<any>;
|
|
259
|
+
|
|
260
|
+
if (selectionMode === 'single') {
|
|
261
|
+
newSelected = selectedIds.has(id) ? new Set() : new Set([id]);
|
|
262
|
+
} else {
|
|
263
|
+
newSelected = new Set(selectedIds);
|
|
264
|
+
if (newSelected.has(id)) {
|
|
265
|
+
newSelected.delete(id);
|
|
266
|
+
} else {
|
|
267
|
+
newSelected.add(id);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (controlledSelectedIds === undefined) {
|
|
272
|
+
setInternalSelectedIds(newSelected);
|
|
273
|
+
}
|
|
274
|
+
onSelectionChange?.(newSelected);
|
|
275
|
+
},
|
|
276
|
+
[controlledSelectedIds, onSelectionChange, selectedIds, selectionMode]
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// Obtém valor de uma coluna
|
|
280
|
+
const getCellValue = useCallback((row: T, column: ArchbaseTreeListColumn<T>) => {
|
|
281
|
+
if (typeof column.accessor === 'function') {
|
|
282
|
+
return column.accessor(row);
|
|
283
|
+
}
|
|
284
|
+
return row[column.accessor];
|
|
285
|
+
}, []);
|
|
286
|
+
|
|
287
|
+
// Encontra a coluna de árvore
|
|
288
|
+
const treeColumnIndex = useMemo(() => {
|
|
289
|
+
const index = columns.findIndex((col) => col.isTreeColumn);
|
|
290
|
+
return index >= 0 ? index : 0;
|
|
291
|
+
}, [columns]);
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<Box ref={ref} className={className} style={style}>
|
|
295
|
+
<ScrollArea style={{ maxHeight }}>
|
|
296
|
+
<Table
|
|
297
|
+
withTableBorder={withBorder}
|
|
298
|
+
withColumnBorders
|
|
299
|
+
striped={striped}
|
|
300
|
+
highlightOnHover={highlightOnHover}
|
|
301
|
+
verticalSpacing="xs"
|
|
302
|
+
horizontalSpacing="sm"
|
|
303
|
+
>
|
|
304
|
+
<Table.Thead>
|
|
305
|
+
<Table.Tr>
|
|
306
|
+
{selectable && <Table.Th style={{ width: 40 }} />}
|
|
307
|
+
{columns.map((column) => (
|
|
308
|
+
<Table.Th
|
|
309
|
+
key={column.id}
|
|
310
|
+
style={{
|
|
311
|
+
width: column.width,
|
|
312
|
+
textAlign: column.align || 'left',
|
|
313
|
+
}}
|
|
314
|
+
>
|
|
315
|
+
{column.header}
|
|
316
|
+
</Table.Th>
|
|
317
|
+
))}
|
|
318
|
+
</Table.Tr>
|
|
319
|
+
</Table.Thead>
|
|
320
|
+
<Table.Tbody>
|
|
321
|
+
{flattenedRows.map((row, rowIndex) => {
|
|
322
|
+
const isSelected = selectedIds.has(row.id);
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<Table.Tr
|
|
326
|
+
key={row.id}
|
|
327
|
+
style={{
|
|
328
|
+
height: rowHeight,
|
|
329
|
+
backgroundColor: isSelected
|
|
330
|
+
? `var(--mantine-color-${highlightColor}-1)`
|
|
331
|
+
: undefined,
|
|
332
|
+
}}
|
|
333
|
+
>
|
|
334
|
+
{selectable && (
|
|
335
|
+
<Table.Td>
|
|
336
|
+
<Checkbox
|
|
337
|
+
checked={isSelected}
|
|
338
|
+
onChange={() => toggleSelection(row.id)}
|
|
339
|
+
size={size}
|
|
340
|
+
/>
|
|
341
|
+
</Table.Td>
|
|
342
|
+
)}
|
|
343
|
+
{columns.map((column, colIndex) => {
|
|
344
|
+
const value = getCellValue(row.data, column);
|
|
345
|
+
const isTreeCol = colIndex === treeColumnIndex;
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<Table.Td
|
|
349
|
+
key={column.id}
|
|
350
|
+
style={{
|
|
351
|
+
textAlign: column.align || 'left',
|
|
352
|
+
}}
|
|
353
|
+
>
|
|
354
|
+
<Group gap={4} wrap="nowrap">
|
|
355
|
+
{isTreeCol && (
|
|
356
|
+
<>
|
|
357
|
+
{/* Indent spacer */}
|
|
358
|
+
<Box style={{ width: row.depth * indentSize }} />
|
|
359
|
+
|
|
360
|
+
{/* Lines (optional) */}
|
|
361
|
+
{showLines && row.depth > 0 && (
|
|
362
|
+
<Box
|
|
363
|
+
style={{
|
|
364
|
+
position: 'absolute',
|
|
365
|
+
left: row.depth * indentSize - indentSize / 2,
|
|
366
|
+
top: 0,
|
|
367
|
+
bottom: '50%',
|
|
368
|
+
width: 1,
|
|
369
|
+
borderLeft: '1px solid var(--mantine-color-gray-4)',
|
|
370
|
+
}}
|
|
371
|
+
/>
|
|
372
|
+
)}
|
|
373
|
+
|
|
374
|
+
{/* Expand button */}
|
|
375
|
+
{row.hasChildren ? (
|
|
376
|
+
<ActionIcon
|
|
377
|
+
variant="subtle"
|
|
378
|
+
size="xs"
|
|
379
|
+
onClick={() => toggleExpand(row.id)}
|
|
380
|
+
>
|
|
381
|
+
{row.isExpanded ? (
|
|
382
|
+
<IconChevronDown size={14} />
|
|
383
|
+
) : (
|
|
384
|
+
<IconChevronRight size={14} />
|
|
385
|
+
)}
|
|
386
|
+
</ActionIcon>
|
|
387
|
+
) : (
|
|
388
|
+
<Box style={{ width: 22 }} />
|
|
389
|
+
)}
|
|
390
|
+
</>
|
|
391
|
+
)}
|
|
392
|
+
|
|
393
|
+
{/* Cell content */}
|
|
394
|
+
{column.render ? (
|
|
395
|
+
column.render(value, row.data, rowIndex)
|
|
396
|
+
) : (
|
|
397
|
+
<Text size={size} truncate>
|
|
398
|
+
{value?.toString() || ''}
|
|
399
|
+
</Text>
|
|
400
|
+
)}
|
|
401
|
+
</Group>
|
|
402
|
+
</Table.Td>
|
|
403
|
+
);
|
|
404
|
+
})}
|
|
405
|
+
</Table.Tr>
|
|
406
|
+
);
|
|
407
|
+
})}
|
|
408
|
+
</Table.Tbody>
|
|
409
|
+
</Table>
|
|
410
|
+
</ScrollArea>
|
|
411
|
+
</Box>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export const ArchbaseTreeList = forwardRef(ArchbaseTreeListInner) as unknown as <
|
|
416
|
+
T extends object = any,
|
|
417
|
+
ID = string
|
|
418
|
+
>(
|
|
419
|
+
props: ArchbaseTreeListProps<T, ID> & { ref?: React.Ref<HTMLDivElement> }
|
|
420
|
+
) => React.ReactElement;
|
|
421
|
+
|
|
422
|
+
(ArchbaseTreeList as any).displayName = 'ArchbaseTreeList';
|
package/src/list/index.ts
CHANGED
|
@@ -7,3 +7,6 @@ export type { ArchbaseListItemProps } from './ArchbaseListItem';
|
|
|
7
7
|
export type { ArchbaseListContextValue } from './ArchbaseList.context';
|
|
8
8
|
export { ArchbaseListContext };
|
|
9
9
|
export * from './treeview';
|
|
10
|
+
|
|
11
|
+
export { ArchbaseTreeList } from './ArchbaseTreeList';
|
|
12
|
+
export type { ArchbaseTreeListProps, ArchbaseTreeListColumn } from './ArchbaseTreeList';
|