@ayasofyazilim/ui 0.0.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/__mocks__/canvas.ts +8 -0
- package/components.json +21 -0
- package/eslint.config.js +4 -0
- package/jest-environment.js +37 -0
- package/jest.config.ts +47 -0
- package/jest.setup.ts +69 -0
- package/package.json +124 -0
- package/postcss.config.mjs +6 -0
- package/src/aria/index.tsx +1 -0
- package/src/aria/number-field.tsx +41 -0
- package/src/components/.gitkeep +0 -0
- package/src/components/accordion.tsx +66 -0
- package/src/components/alert-dialog.tsx +157 -0
- package/src/components/alert.tsx +70 -0
- package/src/components/aspect-ratio.tsx +11 -0
- package/src/components/avatar.tsx +53 -0
- package/src/components/badge.tsx +67 -0
- package/src/components/breadcrumb.tsx +109 -0
- package/src/components/button-group.tsx +83 -0
- package/src/components/button.tsx +68 -0
- package/src/components/calendar.tsx +219 -0
- package/src/components/card.tsx +92 -0
- package/src/components/carousel.tsx +241 -0
- package/src/components/chart.tsx +363 -0
- package/src/components/checkbox.tsx +32 -0
- package/src/components/collapsible.tsx +33 -0
- package/src/components/command.tsx +184 -0
- package/src/components/context-menu.tsx +252 -0
- package/src/components/dialog.tsx +144 -0
- package/src/components/drawer.tsx +135 -0
- package/src/components/dropdown-menu.tsx +258 -0
- package/src/components/empty.tsx +100 -0
- package/src/components/field.tsx +248 -0
- package/src/components/form.tsx +169 -0
- package/src/components/hover-card.tsx +44 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.tsx +77 -0
- package/src/components/input.tsx +21 -0
- package/src/components/item.tsx +193 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +24 -0
- package/src/components/menubar.tsx +276 -0
- package/src/components/navigation-menu.tsx +168 -0
- package/src/components/pagination.tsx +130 -0
- package/src/components/popover.tsx +88 -0
- package/src/components/progress.tsx +31 -0
- package/src/components/radio-group.tsx +45 -0
- package/src/components/resizable.tsx +56 -0
- package/src/components/scroll-area.tsx +58 -0
- package/src/components/select.tsx +189 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/sidebar.tsx +862 -0
- package/src/components/skeleton.tsx +13 -0
- package/src/components/slider.tsx +63 -0
- package/src/components/sonner.tsx +40 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/stepper.tsx +291 -0
- package/src/components/switch.tsx +31 -0
- package/src/components/table.tsx +133 -0
- package/src/components/tabs.tsx +66 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/toggle-group.tsx +83 -0
- package/src/components/toggle.tsx +47 -0
- package/src/components/tooltip.tsx +66 -0
- package/src/custom/action-button.tsx +48 -0
- package/src/custom/async-select.tsx +287 -0
- package/src/custom/awesome-not-found.tsx +116 -0
- package/src/custom/charts/area-chart.tsx +147 -0
- package/src/custom/charts/bar-chart.tsx +233 -0
- package/src/custom/charts/chart-card.tsx +103 -0
- package/src/custom/charts/index.tsx +16 -0
- package/src/custom/charts/pie-chart.tsx +168 -0
- package/src/custom/charts/radar-chart.tsx +126 -0
- package/src/custom/checkbox-tree.tsx +100 -0
- package/src/custom/combobox.tsx +296 -0
- package/src/custom/confirm-dialog.tsx +102 -0
- package/src/custom/country-selector.tsx +204 -0
- package/src/custom/date-picker/calendar-rac.tsx +109 -0
- package/src/custom/date-picker/datefield-rac.tsx +84 -0
- package/src/custom/date-picker/index.tsx +273 -0
- package/src/custom/date-picker/types/index.ts +4 -0
- package/src/custom/date-picker/utils/index.ts +42 -0
- package/src/custom/date-picker-old.tsx +50 -0
- package/src/custom/date-tooltip.tsx +98 -0
- package/src/custom/document-scanner/consts.ts +5 -0
- package/src/custom/document-scanner/corner-adjustment/action-buttons.tsx +33 -0
- package/src/custom/document-scanner/corner-adjustment/corner-handle.tsx +43 -0
- package/src/custom/document-scanner/corner-adjustment/hooks/use-corner-drag.ts +85 -0
- package/src/custom/document-scanner/corner-adjustment/index.tsx +125 -0
- package/src/custom/document-scanner/corner-adjustment/types.ts +53 -0
- package/src/custom/document-scanner/corner-adjustment/utils/clip-path.ts +22 -0
- package/src/custom/document-scanner/corner-adjustment/zoom-magnifier.tsx +115 -0
- package/src/custom/document-scanner/hooks/use-document-capture.ts +81 -0
- package/src/custom/document-scanner/hooks/use-document-scanner.ts +80 -0
- package/src/custom/document-scanner/hooks/use-perspective-crop.ts +38 -0
- package/src/custom/document-scanner/index.tsx +255 -0
- package/src/custom/document-scanner/lib.ts +407 -0
- package/src/custom/document-scanner/types.ts +205 -0
- package/src/custom/document-scanner/utils/perspective-correction.ts +139 -0
- package/src/custom/document-viewer/controllers.tsx +98 -0
- package/src/custom/document-viewer/index.tsx +43 -0
- package/src/custom/document-viewer/renderers/image.tsx +37 -0
- package/src/custom/document-viewer/renderers/index.tsx +2 -0
- package/src/custom/document-viewer/renderers/pdf.tsx +105 -0
- package/src/custom/email-input/domains.json +159 -0
- package/src/custom/email-input/email.tsx +229 -0
- package/src/custom/email-input/index.tsx +4 -0
- package/src/custom/email-input/types.ts +104 -0
- package/src/custom/file-uploader.tsx +541 -0
- package/src/custom/filter-component/fields/async-select.tsx +33 -0
- package/src/custom/filter-component/fields/date.tsx +60 -0
- package/src/custom/filter-component/fields/multi-select.tsx +30 -0
- package/src/custom/filter-component/index.tsx +217 -0
- package/src/custom/image-canvas.tsx +260 -0
- package/src/custom/json-editor.tsx +22 -0
- package/src/custom/master-data-grid/components/dialogs/column-settings-dialog.tsx +100 -0
- package/src/custom/master-data-grid/components/dialogs/index.ts +1 -0
- package/src/custom/master-data-grid/components/filters/client-filter.tsx +368 -0
- package/src/custom/master-data-grid/components/filters/filter-input.tsx +256 -0
- package/src/custom/master-data-grid/components/filters/index.ts +3 -0
- package/src/custom/master-data-grid/components/filters/inline-column-filter.tsx +233 -0
- package/src/custom/master-data-grid/components/filters/multi-filter-dialog.tsx +90 -0
- package/src/custom/master-data-grid/components/filters/server-filter.tsx +255 -0
- package/src/custom/master-data-grid/components/master-data-grid.tsx +472 -0
- package/src/custom/master-data-grid/components/pagination/index.ts +1 -0
- package/src/custom/master-data-grid/components/pagination/pagination.tsx +178 -0
- package/src/custom/master-data-grid/components/table/cell-renderer.tsx +634 -0
- package/src/custom/master-data-grid/components/table/header-cell.tsx +162 -0
- package/src/custom/master-data-grid/components/table/index.ts +4 -0
- package/src/custom/master-data-grid/components/table/table-body-renderer.tsx +113 -0
- package/src/custom/master-data-grid/components/table/virtual-body.tsx +138 -0
- package/src/custom/master-data-grid/components/toolbar/index.ts +1 -0
- package/src/custom/master-data-grid/components/toolbar/toolbar.tsx +314 -0
- package/src/custom/master-data-grid/hooks/index.ts +3 -0
- package/src/custom/master-data-grid/hooks/use-columns.tsx +332 -0
- package/src/custom/master-data-grid/hooks/use-editing.ts +106 -0
- package/src/custom/master-data-grid/hooks/use-table-state-reducer.ts +157 -0
- package/src/custom/master-data-grid/hooks/use-table-state.ts +31 -0
- package/src/custom/master-data-grid/index.ts +16 -0
- package/src/custom/master-data-grid/types.ts +466 -0
- package/src/custom/master-data-grid/utils/column-generator.tsx +306 -0
- package/src/custom/master-data-grid/utils/export-utils.ts +67 -0
- package/src/custom/master-data-grid/utils/filter-fns.ts +290 -0
- package/src/custom/master-data-grid/utils/index.ts +8 -0
- package/src/custom/master-data-grid/utils/pinning-utils.ts +88 -0
- package/src/custom/master-data-grid/utils/translation-utils.ts +42 -0
- package/src/custom/multi-select.tsx +432 -0
- package/src/custom/password-input.tsx +194 -0
- package/src/custom/phone-input.tsx +172 -0
- package/src/custom/schema-form/custom/index.tsx +1 -0
- package/src/custom/schema-form/custom/label.tsx +53 -0
- package/src/custom/schema-form/fields/base-input-field.tsx +82 -0
- package/src/custom/schema-form/fields/field.tsx +67 -0
- package/src/custom/schema-form/fields/index.tsx +5 -0
- package/src/custom/schema-form/fields/object.tsx +12 -0
- package/src/custom/schema-form/fields/table-array/array-field-item.tsx +90 -0
- package/src/custom/schema-form/fields/table-array/array-field-template.tsx +115 -0
- package/src/custom/schema-form/index.tsx +259 -0
- package/src/custom/schema-form/templates/description.tsx +20 -0
- package/src/custom/schema-form/templates/index.tsx +2 -0
- package/src/custom/schema-form/templates/submit.tsx +32 -0
- package/src/custom/schema-form/types.ts +64 -0
- package/src/custom/schema-form/utils/index.ts +4 -0
- package/src/custom/schema-form/utils/schema-dependency.ts +655 -0
- package/src/custom/schema-form/utils/schemas.ts +289 -0
- package/src/custom/schema-form/utils/validation.ts +23 -0
- package/src/custom/schema-form/widgets/boolean.tsx +77 -0
- package/src/custom/schema-form/widgets/combobox.tsx +274 -0
- package/src/custom/schema-form/widgets/date.tsx +59 -0
- package/src/custom/schema-form/widgets/email.tsx +34 -0
- package/src/custom/schema-form/widgets/index.tsx +10 -0
- package/src/custom/schema-form/widgets/password.tsx +40 -0
- package/src/custom/schema-form/widgets/phone.tsx +40 -0
- package/src/custom/schema-form/widgets/select.tsx +105 -0
- package/src/custom/schema-form/widgets/selectable.tsx +25 -0
- package/src/custom/schema-form/widgets/string-array.tsx +296 -0
- package/src/custom/schema-form/widgets/url.tsx +56 -0
- package/src/custom/section-layout-v2.tsx +212 -0
- package/src/custom/select-tabs.tsx +109 -0
- package/src/custom/selectable.tsx +316 -0
- package/src/custom/stepper.tsx +236 -0
- package/src/custom/tab-layout.tsx +213 -0
- package/src/custom/tanstack-table/fields/index.tsx +12 -0
- package/src/custom/tanstack-table/fields/tanstack-table-action-dialogs.tsx +89 -0
- package/src/custom/tanstack-table/fields/tanstack-table-column-header.tsx +66 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-date.tsx +180 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-faceted.tsx +158 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-text.tsx +76 -0
- package/src/custom/tanstack-table/fields/tanstack-table-pagination.tsx +136 -0
- package/src/custom/tanstack-table/fields/tanstack-table-plain-table.tsx +142 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-confirmation.tsx +77 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-custom-dialog.tsx +87 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions.tsx +151 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-custom-dialog.tsx +88 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-schemaform-dialog.tsx +47 -0
- package/src/custom/tanstack-table/fields/tanstack-table-toolbar.tsx +143 -0
- package/src/custom/tanstack-table/fields/tanstack-table-view-options.tsx +171 -0
- package/src/custom/tanstack-table/index.tsx +244 -0
- package/src/custom/tanstack-table/types/index.ts +328 -0
- package/src/custom/tanstack-table/utils/cell-with-actions.tsx +21 -0
- package/src/custom/tanstack-table/utils/column-names.ts +26 -0
- package/src/custom/tanstack-table/utils/columns-by-row-data.tsx +312 -0
- package/src/custom/tanstack-table/utils/editable-columns-by-row-data.tsx +219 -0
- package/src/custom/tanstack-table/utils/faceted-boolean-options.tsx +22 -0
- package/src/custom/tanstack-table/utils/index.tsx +10 -0
- package/src/custom/tanstack-table/utils/pinning-styles.ts +57 -0
- package/src/custom/tanstack-table/utils/table.tsx +83 -0
- package/src/custom/tanstack-table/utils/test-conditions.ts +17 -0
- package/src/custom/timeline.tsx +208 -0
- package/src/custom/tree.tsx +200 -0
- package/src/custom/tscanify/browser.ts +66 -0
- package/src/custom/tscanify/index.ts +51 -0
- package/src/custom/tscanify/tscanify-browser.ts +522 -0
- package/src/custom/tscanify/tscanify.ts +262 -0
- package/src/custom/tscanify/types.ts +22 -0
- package/src/custom/webcam.tsx +737 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/hooks/use-callback-ref.ts +27 -0
- package/src/hooks/use-controllable-state.ts +67 -0
- package/src/hooks/use-debounce.ts +19 -0
- package/src/hooks/use-is-visible.ts +23 -0
- package/src/hooks/use-media-query.ts +21 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/hooks/use-on-window-resize.ts +15 -0
- package/src/hooks/use-scroll.tsx +22 -0
- package/src/lib/utils.ts +61 -0
- package/src/lib/zod.ts +2 -0
- package/src/styles/core.css +57 -0
- package/src/styles/globals.css +130 -0
- package/src/test/email-input.test.tsx +217 -0
- package/src/test/password-input.test.tsx +92 -0
- package/src/test/select-tabs.test.tsx +302 -0
- package/src/test/selectable.test.tsx +1093 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lint.json +8 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import type { Table as TanStackTable } from "@tanstack/react-table";
|
|
2
|
+
import {
|
|
3
|
+
Columns3,
|
|
4
|
+
Download,
|
|
5
|
+
Filter,
|
|
6
|
+
Menu,
|
|
7
|
+
RefreshCw,
|
|
8
|
+
RotateCcw,
|
|
9
|
+
} from "lucide-react";
|
|
10
|
+
import { useEffect, useState, useCallback, useRef } from "react";
|
|
11
|
+
import { Button } from "../../../../components/button";
|
|
12
|
+
import { ButtonGroup } from "../../../../components/button-group";
|
|
13
|
+
import { Input } from "../../../../components/input";
|
|
14
|
+
import {
|
|
15
|
+
Drawer,
|
|
16
|
+
DrawerContent,
|
|
17
|
+
DrawerHeader,
|
|
18
|
+
DrawerTitle,
|
|
19
|
+
DrawerTrigger,
|
|
20
|
+
} from "../../../../components/drawer";
|
|
21
|
+
import type { MasterDataGridConfig, ServerFilterConfig } from "../../types";
|
|
22
|
+
import { getTranslations } from "../../utils/translation-utils";
|
|
23
|
+
import { MultiFilterDialog } from "../filters";
|
|
24
|
+
|
|
25
|
+
interface ToolbarProps<TData> {
|
|
26
|
+
table: TanStackTable<TData>;
|
|
27
|
+
config: MasterDataGridConfig<TData>;
|
|
28
|
+
selectedRows: TData[];
|
|
29
|
+
serverFilters?: ServerFilterConfig[];
|
|
30
|
+
onExport?: (format: string) => void;
|
|
31
|
+
onRefresh?: () => void;
|
|
32
|
+
onReset?: () => void;
|
|
33
|
+
onOpenColumnSettings?: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function Toolbar<TData>({
|
|
37
|
+
table,
|
|
38
|
+
config,
|
|
39
|
+
selectedRows,
|
|
40
|
+
onExport,
|
|
41
|
+
onRefresh,
|
|
42
|
+
onReset,
|
|
43
|
+
onOpenColumnSettings,
|
|
44
|
+
}: ToolbarProps<TData>) {
|
|
45
|
+
const { t, tableActions, enableExport } = config;
|
|
46
|
+
|
|
47
|
+
const [searchValue, setSearchValue] = useState<string>("");
|
|
48
|
+
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
|
49
|
+
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null);
|
|
50
|
+
|
|
51
|
+
const initialStateRef = useRef<{
|
|
52
|
+
globalFilter: string | undefined;
|
|
53
|
+
columnFilters: any[];
|
|
54
|
+
sorting: any[];
|
|
55
|
+
columnVisibility: Record<string, boolean>;
|
|
56
|
+
columnPinning: { left?: string[]; right?: string[] };
|
|
57
|
+
} | null>(null);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!initialStateRef.current) {
|
|
61
|
+
const state = table.getState();
|
|
62
|
+
initialStateRef.current = {
|
|
63
|
+
globalFilter: state.globalFilter as string | undefined,
|
|
64
|
+
columnFilters: [...state.columnFilters],
|
|
65
|
+
sorting: [...state.sorting],
|
|
66
|
+
columnVisibility: { ...state.columnVisibility },
|
|
67
|
+
columnPinning: {
|
|
68
|
+
left: state.columnPinning?.left ? [...state.columnPinning.left] : [],
|
|
69
|
+
right: state.columnPinning?.right
|
|
70
|
+
? [...state.columnPinning.right]
|
|
71
|
+
: [],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const currentFilter = table.getState().globalFilter as string;
|
|
79
|
+
if (currentFilter !== searchValue) {
|
|
80
|
+
setSearchValue(currentFilter ?? "");
|
|
81
|
+
}
|
|
82
|
+
}, [table.getState().globalFilter]);
|
|
83
|
+
|
|
84
|
+
const handleSearchChange = useCallback(
|
|
85
|
+
(value: string) => {
|
|
86
|
+
setSearchValue(value);
|
|
87
|
+
|
|
88
|
+
if (debounceTimerRef.current) {
|
|
89
|
+
clearTimeout(debounceTimerRef.current);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
93
|
+
table.setGlobalFilter(value);
|
|
94
|
+
}, 300);
|
|
95
|
+
},
|
|
96
|
+
[table]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
return () => {
|
|
101
|
+
if (debounceTimerRef.current) {
|
|
102
|
+
clearTimeout(debounceTimerRef.current);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}, []);
|
|
106
|
+
|
|
107
|
+
const hasTableChanges = () => {
|
|
108
|
+
if (!initialStateRef.current) return false;
|
|
109
|
+
|
|
110
|
+
const state = table.getState();
|
|
111
|
+
const initial = initialStateRef.current;
|
|
112
|
+
|
|
113
|
+
const hasGlobalFilterChanged = state.globalFilter !== initial.globalFilter;
|
|
114
|
+
|
|
115
|
+
const hasColumnFiltersChanged =
|
|
116
|
+
state.columnFilters.length !== initial.columnFilters.length ||
|
|
117
|
+
JSON.stringify(state.columnFilters) !==
|
|
118
|
+
JSON.stringify(initial.columnFilters);
|
|
119
|
+
|
|
120
|
+
const hasSortingChanged =
|
|
121
|
+
state.sorting.length !== initial.sorting.length ||
|
|
122
|
+
JSON.stringify(state.sorting) !== JSON.stringify(initial.sorting);
|
|
123
|
+
|
|
124
|
+
const hasColumnVisibilityChanged =
|
|
125
|
+
JSON.stringify(state.columnVisibility) !==
|
|
126
|
+
JSON.stringify(initial.columnVisibility);
|
|
127
|
+
|
|
128
|
+
const currentPinning = {
|
|
129
|
+
left: state.columnPinning?.left || [],
|
|
130
|
+
right: state.columnPinning?.right || [],
|
|
131
|
+
};
|
|
132
|
+
const initialPinning = {
|
|
133
|
+
left: initial.columnPinning?.left || [],
|
|
134
|
+
right: initial.columnPinning?.right || [],
|
|
135
|
+
};
|
|
136
|
+
const hasColumnPinningChanged =
|
|
137
|
+
JSON.stringify(currentPinning) !== JSON.stringify(initialPinning);
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
hasGlobalFilterChanged ||
|
|
141
|
+
hasColumnFiltersChanged ||
|
|
142
|
+
hasSortingChanged ||
|
|
143
|
+
hasColumnVisibilityChanged ||
|
|
144
|
+
hasColumnPinningChanged
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const renderTableButtons = (isMobile = false) => (
|
|
149
|
+
<>
|
|
150
|
+
{config.enableFiltering && (
|
|
151
|
+
<MultiFilterDialog table={table} config={config}>
|
|
152
|
+
<Button
|
|
153
|
+
variant="outline"
|
|
154
|
+
className={isMobile ? "w-full justify-start" : ""}
|
|
155
|
+
>
|
|
156
|
+
<Filter className="mr-2 h-4 w-4" />
|
|
157
|
+
<span>{getTranslations("toolbar.filters", t)}</span>
|
|
158
|
+
{table.getState().columnFilters.length > 0 && (
|
|
159
|
+
<span
|
|
160
|
+
className={
|
|
161
|
+
(isMobile ? "ml-auto" : "ml-2") +
|
|
162
|
+
" rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground"
|
|
163
|
+
}
|
|
164
|
+
>
|
|
165
|
+
{table.getState().columnFilters.length}
|
|
166
|
+
</span>
|
|
167
|
+
)}
|
|
168
|
+
</Button>
|
|
169
|
+
</MultiFilterDialog>
|
|
170
|
+
)}
|
|
171
|
+
{config.enableColumnVisibility && (
|
|
172
|
+
<Button
|
|
173
|
+
variant="outline"
|
|
174
|
+
onClick={() => {
|
|
175
|
+
onOpenColumnSettings?.();
|
|
176
|
+
if (isMobile) setMobileMenuOpen(false);
|
|
177
|
+
}}
|
|
178
|
+
className={isMobile ? "w-full justify-start" : ""}
|
|
179
|
+
>
|
|
180
|
+
<Columns3 className="mr-2 h-4 w-4" />
|
|
181
|
+
<span>{getTranslations("toolbar.columns", t)}</span>
|
|
182
|
+
</Button>
|
|
183
|
+
)}
|
|
184
|
+
{enableExport && onExport && (
|
|
185
|
+
<Button
|
|
186
|
+
variant="outline"
|
|
187
|
+
onClick={() => {
|
|
188
|
+
onExport("csv");
|
|
189
|
+
if (isMobile) setMobileMenuOpen(false);
|
|
190
|
+
}}
|
|
191
|
+
className={isMobile ? "w-full justify-start" : ""}
|
|
192
|
+
>
|
|
193
|
+
<Download className="mr-2 h-4 w-4" />
|
|
194
|
+
<span>{getTranslations("toolbar.export", t)}</span>
|
|
195
|
+
</Button>
|
|
196
|
+
)}
|
|
197
|
+
{onRefresh && (
|
|
198
|
+
<Button
|
|
199
|
+
variant="outline"
|
|
200
|
+
onClick={() => {
|
|
201
|
+
onRefresh();
|
|
202
|
+
if (isMobile) setMobileMenuOpen(false);
|
|
203
|
+
}}
|
|
204
|
+
className={isMobile ? "w-full justify-start" : ""}
|
|
205
|
+
>
|
|
206
|
+
<RefreshCw className="mr-2 h-4 w-4" />
|
|
207
|
+
<span>{getTranslations("toolbar.refresh", t)}</span>
|
|
208
|
+
</Button>
|
|
209
|
+
)}
|
|
210
|
+
{onReset && hasTableChanges() && (
|
|
211
|
+
<Button
|
|
212
|
+
variant="outline"
|
|
213
|
+
onClick={() => {
|
|
214
|
+
onReset();
|
|
215
|
+
if (isMobile) setMobileMenuOpen(false);
|
|
216
|
+
}}
|
|
217
|
+
className={isMobile ? "w-full justify-start" : ""}
|
|
218
|
+
>
|
|
219
|
+
<RotateCcw className="mr-2 h-4 w-4" />
|
|
220
|
+
<span>{getTranslations("toolbar.reset", t)}</span>
|
|
221
|
+
</Button>
|
|
222
|
+
)}
|
|
223
|
+
</>
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const renderTableActions = (isMobile = false) =>
|
|
227
|
+
tableActions?.map((action) => {
|
|
228
|
+
const disabled =
|
|
229
|
+
typeof action.disabled === "function"
|
|
230
|
+
? action.disabled(selectedRows)
|
|
231
|
+
: action.disabled;
|
|
232
|
+
|
|
233
|
+
const hidden =
|
|
234
|
+
typeof action.hidden === "function"
|
|
235
|
+
? action.hidden(selectedRows)
|
|
236
|
+
: action.hidden;
|
|
237
|
+
|
|
238
|
+
if (hidden) return null;
|
|
239
|
+
|
|
240
|
+
if (action.requiresSelection && selectedRows.length === 0) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const Icon = action.icon;
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<Button
|
|
248
|
+
key={action.id}
|
|
249
|
+
variant={action.variant}
|
|
250
|
+
disabled={disabled}
|
|
251
|
+
onClick={() => {
|
|
252
|
+
action.onClick?.(selectedRows);
|
|
253
|
+
if (isMobile) setMobileMenuOpen(false);
|
|
254
|
+
}}
|
|
255
|
+
className={isMobile ? "w-full justify-start" : action.className}
|
|
256
|
+
>
|
|
257
|
+
{Icon && <Icon className="mr-2 h-4 w-4" />}
|
|
258
|
+
{action.label}
|
|
259
|
+
</Button>
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const hasAnyEnabledFeature =
|
|
264
|
+
config.enableSearch ||
|
|
265
|
+
config.enableFiltering ||
|
|
266
|
+
config.enableColumnVisibility ||
|
|
267
|
+
enableExport ||
|
|
268
|
+
onRefresh ||
|
|
269
|
+
(tableActions && tableActions.length > 0);
|
|
270
|
+
|
|
271
|
+
if (!hasAnyEnabledFeature) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
return (
|
|
275
|
+
<div className="flex items-center gap-2 w-full">
|
|
276
|
+
{config.enableSearch && (
|
|
277
|
+
<Input
|
|
278
|
+
placeholder={getTranslations("toolbar.search", t)}
|
|
279
|
+
value={searchValue}
|
|
280
|
+
onChange={(event) => handleSearchChange(event.target.value)}
|
|
281
|
+
className="md:max-w-sm"
|
|
282
|
+
/>
|
|
283
|
+
)}
|
|
284
|
+
{selectedRows.length > 0 && (
|
|
285
|
+
<div className="text-sm text-muted-foreground">
|
|
286
|
+
{selectedRows.length} {getTranslations("toolbar.selected", t)}
|
|
287
|
+
</div>
|
|
288
|
+
)}
|
|
289
|
+
|
|
290
|
+
<ButtonGroup className="hidden ml-auto md:flex">
|
|
291
|
+
{renderTableButtons(false)}
|
|
292
|
+
</ButtonGroup>
|
|
293
|
+
<ButtonGroup className="hidden md:has-first:flex">
|
|
294
|
+
{renderTableActions(false)}
|
|
295
|
+
</ButtonGroup>
|
|
296
|
+
<Drawer open={mobileMenuOpen} onOpenChange={setMobileMenuOpen}>
|
|
297
|
+
<DrawerTrigger asChild>
|
|
298
|
+
<Button variant="outline" size="icon" className="md:hidden">
|
|
299
|
+
<Menu className="h-4 w-4" />
|
|
300
|
+
</Button>
|
|
301
|
+
</DrawerTrigger>
|
|
302
|
+
<DrawerContent className="p-2">
|
|
303
|
+
<DrawerHeader>
|
|
304
|
+
<DrawerTitle>{getTranslations("toolbar.actions", t)}</DrawerTitle>
|
|
305
|
+
</DrawerHeader>
|
|
306
|
+
<div className="flex flex-col gap-2 mt-4">
|
|
307
|
+
{renderTableButtons(true)}
|
|
308
|
+
{renderTableActions(true)}
|
|
309
|
+
</div>
|
|
310
|
+
</DrawerContent>
|
|
311
|
+
</Drawer>
|
|
312
|
+
</div>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { GenericObjectType } from "@rjsf/utils";
|
|
2
|
+
import type { ColumnDef } from "@tanstack/react-table";
|
|
3
|
+
import { MoreHorizontal, Pencil, Save, X } from "lucide-react";
|
|
4
|
+
import { useMemo, type RefObject } from "react";
|
|
5
|
+
import { Button } from "../../../components/button";
|
|
6
|
+
import { Checkbox } from "../../../components/checkbox";
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuItem,
|
|
11
|
+
DropdownMenuTrigger,
|
|
12
|
+
} from "../../../components/dropdown-menu";
|
|
13
|
+
import type {
|
|
14
|
+
CellProps,
|
|
15
|
+
ColumnConfig,
|
|
16
|
+
ExpandableColumnMeta,
|
|
17
|
+
JSONSchema,
|
|
18
|
+
MasterDataGridConfig,
|
|
19
|
+
MasterDataGridResources,
|
|
20
|
+
} from "../types";
|
|
21
|
+
import {
|
|
22
|
+
generateColumnsFromSchema,
|
|
23
|
+
mergeColumns,
|
|
24
|
+
} from "../utils/column-generator";
|
|
25
|
+
|
|
26
|
+
export interface UseColumnsProps<TData> {
|
|
27
|
+
config: MasterDataGridConfig<TData>;
|
|
28
|
+
configRef: RefObject<MasterDataGridConfig<TData>>;
|
|
29
|
+
schema?: JSONSchema | GenericObjectType;
|
|
30
|
+
customColumns?: ColumnConfig<TData>[];
|
|
31
|
+
enableRowSelection: boolean;
|
|
32
|
+
enableColumnVisibility: boolean;
|
|
33
|
+
editingRowsRef: RefObject<Record<string, Record<string, unknown>>>;
|
|
34
|
+
updateCellValue: (rowId: string, columnId: string, value: unknown) => void;
|
|
35
|
+
getRowId?: (row: TData, index: number) => string;
|
|
36
|
+
t?: MasterDataGridResources;
|
|
37
|
+
startEditingRow: (rowId: string, row: TData) => void;
|
|
38
|
+
cancelEditingRow: (rowId: string, row: TData) => void;
|
|
39
|
+
saveEditingRow: (rowId: string, row: TData) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useColumns<TData>({
|
|
43
|
+
config,
|
|
44
|
+
configRef,
|
|
45
|
+
schema,
|
|
46
|
+
customColumns,
|
|
47
|
+
enableRowSelection,
|
|
48
|
+
enableColumnVisibility,
|
|
49
|
+
editingRowsRef,
|
|
50
|
+
updateCellValue,
|
|
51
|
+
getRowId,
|
|
52
|
+
t,
|
|
53
|
+
startEditingRow,
|
|
54
|
+
cancelEditingRow,
|
|
55
|
+
saveEditingRow,
|
|
56
|
+
}: UseColumnsProps<TData>): ColumnDef<TData>[] {
|
|
57
|
+
return useMemo<ColumnDef<TData>[]>(() => {
|
|
58
|
+
const editingContext = config.editing?.enabled
|
|
59
|
+
? {
|
|
60
|
+
get editingRows() {
|
|
61
|
+
return editingRowsRef.current;
|
|
62
|
+
},
|
|
63
|
+
onCellUpdate: updateCellValue,
|
|
64
|
+
getRowId: getRowId || ((row: TData, index: number) => String(index)),
|
|
65
|
+
}
|
|
66
|
+
: undefined;
|
|
67
|
+
|
|
68
|
+
const generatedColumns = schema
|
|
69
|
+
? generateColumnsFromSchema<TData>(
|
|
70
|
+
schema,
|
|
71
|
+
configRef.current.localization,
|
|
72
|
+
t,
|
|
73
|
+
editingContext,
|
|
74
|
+
configRef.current.cellClassName,
|
|
75
|
+
configRef.current.dateOptions,
|
|
76
|
+
configRef.current.customRenderers,
|
|
77
|
+
configRef.current.editing?.errorDisplayMode,
|
|
78
|
+
enableColumnVisibility,
|
|
79
|
+
config.expansion?.expanderColumns
|
|
80
|
+
)
|
|
81
|
+
: [];
|
|
82
|
+
|
|
83
|
+
const mergeContext = editingContext
|
|
84
|
+
? {
|
|
85
|
+
get editingRows() {
|
|
86
|
+
return editingRowsRef.current;
|
|
87
|
+
},
|
|
88
|
+
getRowId: editingContext.getRowId,
|
|
89
|
+
}
|
|
90
|
+
: undefined;
|
|
91
|
+
|
|
92
|
+
const merged = mergeColumns<TData>(
|
|
93
|
+
generatedColumns,
|
|
94
|
+
customColumns,
|
|
95
|
+
mergeContext,
|
|
96
|
+
enableColumnVisibility,
|
|
97
|
+
t
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const mergedWithExpansion = merged.map((col) => {
|
|
101
|
+
const shouldExpandOnClick =
|
|
102
|
+
(col.meta as ExpandableColumnMeta)?.isExpanderColumn ||
|
|
103
|
+
customColumns?.find((c) => c.id === col.id)?.isExpanderColumn;
|
|
104
|
+
|
|
105
|
+
if (!shouldExpandOnClick || !configRef.current.expansion?.enabled) {
|
|
106
|
+
return col;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const originalCell = col.cell;
|
|
110
|
+
return {
|
|
111
|
+
...col,
|
|
112
|
+
cell: (props: CellProps<TData>) => {
|
|
113
|
+
const content =
|
|
114
|
+
typeof originalCell === "function"
|
|
115
|
+
? originalCell(props)
|
|
116
|
+
: originalCell;
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
onClick={(e) => {
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
props.row.toggleExpanded();
|
|
123
|
+
}}
|
|
124
|
+
className="cursor-pointer hover:bg-muted/50"
|
|
125
|
+
>
|
|
126
|
+
{content}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const finalColumns: ColumnDef<TData>[] = [];
|
|
134
|
+
|
|
135
|
+
if (enableRowSelection) {
|
|
136
|
+
finalColumns.push({
|
|
137
|
+
id: "select",
|
|
138
|
+
header: ({ table }) => (
|
|
139
|
+
<Checkbox
|
|
140
|
+
checked={table.getIsAllPageRowsSelected()}
|
|
141
|
+
onCheckedChange={(value) =>
|
|
142
|
+
table.toggleAllPageRowsSelected(!!value)
|
|
143
|
+
}
|
|
144
|
+
aria-label={t?.["select_all"]}
|
|
145
|
+
/>
|
|
146
|
+
),
|
|
147
|
+
cell: ({ row }) => (
|
|
148
|
+
<Checkbox
|
|
149
|
+
checked={row.getIsSelected()}
|
|
150
|
+
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
|
151
|
+
aria-label={t?.["select_row"]}
|
|
152
|
+
/>
|
|
153
|
+
),
|
|
154
|
+
enableSorting: false,
|
|
155
|
+
enableHiding: false,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
finalColumns.push(...mergedWithExpansion);
|
|
160
|
+
|
|
161
|
+
if (config.rowActions && config.rowActions.length > 0) {
|
|
162
|
+
finalColumns.push({
|
|
163
|
+
id: "actions",
|
|
164
|
+
header: t?.["actions"],
|
|
165
|
+
cell: ({ row }) => {
|
|
166
|
+
const rowActions = config.rowActions?.filter((action) => {
|
|
167
|
+
if (typeof action.hidden === "function") {
|
|
168
|
+
return !action.hidden(row.original);
|
|
169
|
+
}
|
|
170
|
+
return !action.hidden;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!rowActions || rowActions.length === 0) return null;
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<DropdownMenu>
|
|
177
|
+
<DropdownMenuTrigger asChild>
|
|
178
|
+
<Button
|
|
179
|
+
variant="ghost"
|
|
180
|
+
size="icon-xs"
|
|
181
|
+
className="w-full"
|
|
182
|
+
aria-label={t?.["open_menu"]}
|
|
183
|
+
>
|
|
184
|
+
<MoreHorizontal />
|
|
185
|
+
</Button>
|
|
186
|
+
</DropdownMenuTrigger>
|
|
187
|
+
<DropdownMenuContent align="end">
|
|
188
|
+
{rowActions.map((action) => {
|
|
189
|
+
const label =
|
|
190
|
+
typeof action.label === "function"
|
|
191
|
+
? action.label(row.original)
|
|
192
|
+
: action.label;
|
|
193
|
+
const disabled =
|
|
194
|
+
typeof action.disabled === "function"
|
|
195
|
+
? action.disabled(row.original)
|
|
196
|
+
: action.disabled;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<DropdownMenuItem
|
|
200
|
+
key={action.id}
|
|
201
|
+
onClick={(e) => action.onClick?.(row.original, e)}
|
|
202
|
+
disabled={disabled}
|
|
203
|
+
className={action.className}
|
|
204
|
+
>
|
|
205
|
+
{action.icon && <action.icon className="size-3.5" />}
|
|
206
|
+
{label}
|
|
207
|
+
</DropdownMenuItem>
|
|
208
|
+
);
|
|
209
|
+
})}
|
|
210
|
+
</DropdownMenuContent>
|
|
211
|
+
</DropdownMenu>
|
|
212
|
+
);
|
|
213
|
+
},
|
|
214
|
+
enableSorting: false,
|
|
215
|
+
enableHiding: false,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (config.editing?.enabled && config.editing.mode === "row") {
|
|
220
|
+
finalColumns.push({
|
|
221
|
+
id: "edit-actions",
|
|
222
|
+
header: t?.["edit"] || "Edit",
|
|
223
|
+
cell: ({ row }) => {
|
|
224
|
+
const rowId = getRowId
|
|
225
|
+
? getRowId(row.original, row.index)
|
|
226
|
+
: String(row.index);
|
|
227
|
+
const isEditing = !!editingRowsRef.current[rowId];
|
|
228
|
+
const isRowEditable =
|
|
229
|
+
!config.editing?.isRowEditable ||
|
|
230
|
+
config.editing.isRowEditable(row.original);
|
|
231
|
+
|
|
232
|
+
if (!isRowEditable) return null;
|
|
233
|
+
|
|
234
|
+
return isEditing ? (
|
|
235
|
+
<div className="flex gap-1">
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="sm"
|
|
239
|
+
onClick={() => saveEditingRow(rowId, row.original)}
|
|
240
|
+
className="h-7 px-2"
|
|
241
|
+
aria-label={t?.["save"]}
|
|
242
|
+
>
|
|
243
|
+
<Save className="size-3.5" />
|
|
244
|
+
</Button>
|
|
245
|
+
<Button
|
|
246
|
+
variant="ghost"
|
|
247
|
+
size="sm"
|
|
248
|
+
onClick={() => cancelEditingRow(rowId, row.original)}
|
|
249
|
+
className="h-7 px-2"
|
|
250
|
+
aria-label={t?.["cancel"]}
|
|
251
|
+
>
|
|
252
|
+
<X className="size-3.5" />
|
|
253
|
+
</Button>
|
|
254
|
+
</div>
|
|
255
|
+
) : (
|
|
256
|
+
<Button
|
|
257
|
+
variant="ghost"
|
|
258
|
+
size="sm"
|
|
259
|
+
onClick={() => startEditingRow(rowId, row.original)}
|
|
260
|
+
className="h-7 px-2"
|
|
261
|
+
aria-label={t?.["edit"]}
|
|
262
|
+
>
|
|
263
|
+
<Pencil className="size-3.5" />
|
|
264
|
+
</Button>
|
|
265
|
+
);
|
|
266
|
+
},
|
|
267
|
+
enableSorting: false,
|
|
268
|
+
enableHiding: false,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (config.columnOrder && config.columnOrder.length > 0) {
|
|
273
|
+
const orderedColumns: ColumnDef<TData>[] = [];
|
|
274
|
+
const columnMap = new Map(finalColumns.map((col) => [col.id, col]));
|
|
275
|
+
|
|
276
|
+
for (const colId of config.columnOrder) {
|
|
277
|
+
const col = columnMap.get(String(colId));
|
|
278
|
+
if (col) {
|
|
279
|
+
orderedColumns.push(col);
|
|
280
|
+
columnMap.delete(String(colId));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
orderedColumns.push(...Array.from(columnMap.values()));
|
|
284
|
+
|
|
285
|
+
return orderedColumns;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
!config.columnOrder &&
|
|
290
|
+
config.columnVisibility?.mode === "show" &&
|
|
291
|
+
config.columnVisibility.columns.length > 0
|
|
292
|
+
) {
|
|
293
|
+
const orderedColumns: ColumnDef<TData>[] = [];
|
|
294
|
+
const columnMap = new Map(finalColumns.map((col) => [col.id, col]));
|
|
295
|
+
|
|
296
|
+
for (const colId of config.columnVisibility.columns) {
|
|
297
|
+
const col = columnMap.get(String(colId));
|
|
298
|
+
if (col) {
|
|
299
|
+
orderedColumns.push(col);
|
|
300
|
+
columnMap.delete(String(colId));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
orderedColumns.push(...Array.from(columnMap.values()));
|
|
305
|
+
|
|
306
|
+
return orderedColumns;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return finalColumns;
|
|
310
|
+
}, [
|
|
311
|
+
schema,
|
|
312
|
+
customColumns,
|
|
313
|
+
enableRowSelection,
|
|
314
|
+
enableColumnVisibility,
|
|
315
|
+
config.expansion,
|
|
316
|
+
config.rowActions,
|
|
317
|
+
config.editing,
|
|
318
|
+
config.columnOrder,
|
|
319
|
+
config.columnVisibility,
|
|
320
|
+
config.cellClassName,
|
|
321
|
+
config.dateOptions,
|
|
322
|
+
config.customRenderers,
|
|
323
|
+
configRef,
|
|
324
|
+
editingRowsRef,
|
|
325
|
+
updateCellValue,
|
|
326
|
+
getRowId,
|
|
327
|
+
t,
|
|
328
|
+
startEditingRow,
|
|
329
|
+
cancelEditingRow,
|
|
330
|
+
saveEditingRow,
|
|
331
|
+
]);
|
|
332
|
+
}
|