torch-glare 2.5.6 → 2.6.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/README.md +4 -3
- package/dist/bin/index.js +9 -24
- package/dist/bin/index.js.map +1 -1
- package/dist/src/commands/add.d.ts +2 -2
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +4 -70
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/hook.d.ts +5 -4
- package/dist/src/commands/hook.d.ts.map +1 -1
- package/dist/src/commands/hook.js +7 -75
- package/dist/src/commands/hook.js.map +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/layout.d.ts +5 -4
- package/dist/src/commands/layout.d.ts.map +1 -1
- package/dist/src/commands/layout.js +7 -75
- package/dist/src/commands/layout.js.map +1 -1
- package/dist/src/commands/provider.d.ts +5 -4
- package/dist/src/commands/provider.d.ts.map +1 -1
- package/dist/src/commands/provider.js +7 -75
- package/dist/src/commands/provider.js.map +1 -1
- package/dist/src/commands/update.d.ts.map +1 -1
- package/dist/src/commands/update.js +78 -43
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/utils.d.ts +5 -4
- package/dist/src/commands/utils.d.ts.map +1 -1
- package/dist/src/commands/utils.js +7 -80
- package/dist/src/commands/utils.js.map +1 -1
- package/dist/src/shared/addFromRegistry.d.ts +16 -0
- package/dist/src/shared/addFromRegistry.d.ts.map +1 -0
- package/dist/src/shared/addFromRegistry.js +88 -0
- package/dist/src/shared/addFromRegistry.js.map +1 -0
- package/dist/src/shared/getInstallCommand.d.ts.map +1 -1
- package/dist/src/shared/getInstallCommand.js +5 -0
- package/dist/src/shared/getInstallCommand.js.map +1 -1
- package/dist/src/shared/installDependencies.d.ts +0 -10
- package/dist/src/shared/installDependencies.d.ts.map +1 -1
- package/dist/src/shared/installDependencies.js +0 -17
- package/dist/src/shared/installDependencies.js.map +1 -1
- package/dist/src/shared/installFromPlan.d.ts +7 -5
- package/dist/src/shared/installFromPlan.d.ts.map +1 -1
- package/dist/src/shared/installFromPlan.js +103 -36
- package/dist/src/shared/installFromPlan.js.map +1 -1
- package/dist/src/shared/loadRegistry.d.ts +12 -3
- package/dist/src/shared/loadRegistry.d.ts.map +1 -1
- package/dist/src/shared/loadRegistry.js +19 -20
- package/dist/src/shared/loadRegistry.js.map +1 -1
- package/dist/src/shared/registryClient.d.ts +19 -0
- package/dist/src/shared/registryClient.d.ts.map +1 -0
- package/dist/src/shared/registryClient.js +128 -0
- package/dist/src/shared/registryClient.js.map +1 -0
- package/dist/src/shared/resolveEntry.d.ts +10 -7
- package/dist/src/shared/resolveEntry.d.ts.map +1 -1
- package/dist/src/shared/resolveEntry.js +18 -13
- package/dist/src/shared/resolveEntry.js.map +1 -1
- package/dist/src/shared/suggestOtherCommand.d.ts +7 -1
- package/dist/src/shared/suggestOtherCommand.d.ts.map +1 -1
- package/dist/src/shared/suggestOtherCommand.js +29 -23
- package/dist/src/shared/suggestOtherCommand.js.map +1 -1
- package/dist/src/types/main.d.ts +31 -2
- package/dist/src/types/main.d.ts.map +1 -1
- package/package.json +6 -11
- package/apps/lib/components/ActionButton.tsx +0 -93
- package/apps/lib/components/ActionsGroup.tsx +0 -27
- package/apps/lib/components/AlertDialog.tsx +0 -204
- package/apps/lib/components/Avatar.tsx +0 -46
- package/apps/lib/components/Badge.tsx +0 -250
- package/apps/lib/components/BadgeField.tsx +0 -403
- package/apps/lib/components/Breadcrumb.tsx +0 -280
- package/apps/lib/components/Button.tsx +0 -325
- package/apps/lib/components/ButtonGroup.tsx +0 -190
- package/apps/lib/components/Calendar.tsx +0 -115
- package/apps/lib/components/Card.tsx +0 -95
- package/apps/lib/components/Checkbox.tsx +0 -42
- package/apps/lib/components/ColorPicker.tsx +0 -441
- package/apps/lib/components/ConclusionHeader.tsx +0 -148
- package/apps/lib/components/ContextMenu.tsx +0 -571
- package/apps/lib/components/CountBadge.tsx +0 -52
- package/apps/lib/components/DataTable.tsx +0 -213
- package/apps/lib/components/DataViews/badge.ts +0 -49
- package/apps/lib/components/DataViews/cell.tsx +0 -324
- package/apps/lib/components/DataViews/context.ts +0 -144
- package/apps/lib/components/DataViews/data-views.tsx +0 -395
- package/apps/lib/components/DataViews/filters/children.tsx +0 -98
- package/apps/lib/components/DataViews/filters/custom.tsx +0 -34
- package/apps/lib/components/DataViews/filters/filters.tsx +0 -157
- package/apps/lib/components/DataViews/filters/index.ts +0 -4
- package/apps/lib/components/DataViews/filters/labelled.tsx +0 -20
- package/apps/lib/components/DataViews/filters/presets.tsx +0 -65
- package/apps/lib/components/DataViews/filters/sync.tsx +0 -35
- package/apps/lib/components/DataViews/filters/values.ts +0 -173
- package/apps/lib/components/DataViews/header.tsx +0 -220
- package/apps/lib/components/DataViews/hooks/index.ts +0 -5
- package/apps/lib/components/DataViews/hooks/useActiveRow.ts +0 -22
- package/apps/lib/components/DataViews/hooks/useControllable.ts +0 -52
- package/apps/lib/components/DataViews/index.ts +0 -88
- package/apps/lib/components/DataViews/panel/columns.tsx +0 -153
- package/apps/lib/components/DataViews/panel/controls.tsx +0 -106
- package/apps/lib/components/DataViews/panel/index.ts +0 -3
- package/apps/lib/components/DataViews/panel/panel.tsx +0 -164
- package/apps/lib/components/DataViews/panel/saved-views.tsx +0 -67
- package/apps/lib/components/DataViews/panel/section.tsx +0 -81
- package/apps/lib/components/DataViews/panel/sort.tsx +0 -42
- package/apps/lib/components/DataViews/panel/tab.tsx +0 -31
- package/apps/lib/components/DataViews/slots.ts +0 -72
- package/apps/lib/components/DataViews/states.tsx +0 -73
- package/apps/lib/components/DataViews/types.ts +0 -510
- package/apps/lib/components/DataViews/views/board-view.tsx +0 -381
- package/apps/lib/components/DataViews/views/card-rows.tsx +0 -36
- package/apps/lib/components/DataViews/views/inbox-view.tsx +0 -260
- package/apps/lib/components/DataViews/views/pane-views.tsx +0 -196
- package/apps/lib/components/DataViews/views/table-view.tsx +0 -493
- package/apps/lib/components/DataViews/views/tree-view.tsx +0 -367
- package/apps/lib/components/DatePicker.tsx +0 -232
- package/apps/lib/components/Dialog.tsx +0 -116
- package/apps/lib/components/Divider.tsx +0 -28
- package/apps/lib/components/Drawer.tsx +0 -451
- package/apps/lib/components/DropdownMenu.tsx +0 -554
- package/apps/lib/components/FieldHint.tsx +0 -69
- package/apps/lib/components/Form.tsx +0 -182
- package/apps/lib/components/FormBuilder/context.ts +0 -85
- package/apps/lib/components/FormBuilder/field-kind.ts +0 -28
- package/apps/lib/components/FormBuilder/fields/ChoiceFields.tsx +0 -60
- package/apps/lib/components/FormBuilder/fields/ColorField.tsx +0 -59
- package/apps/lib/components/FormBuilder/fields/CustomField.tsx +0 -11
- package/apps/lib/components/FormBuilder/fields/DateField.tsx +0 -32
- package/apps/lib/components/FormBuilder/fields/FieldArray.tsx +0 -74
- package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +0 -168
- package/apps/lib/components/FormBuilder/fields/FileField.tsx +0 -39
- package/apps/lib/components/FormBuilder/fields/OptionListFields.tsx +0 -132
- package/apps/lib/components/FormBuilder/fields/OtpField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +0 -109
- package/apps/lib/components/FormBuilder/fields/RichTextEditorField.tsx +0 -31
- package/apps/lib/components/FormBuilder/fields/SelectField.tsx +0 -114
- package/apps/lib/components/FormBuilder/fields/SignatureField.tsx +0 -157
- package/apps/lib/components/FormBuilder/fields/SliderField.tsx +0 -67
- package/apps/lib/components/FormBuilder/fields/SwitchBoxField.tsx +0 -41
- package/apps/lib/components/FormBuilder/fields/TableField.tsx +0 -336
- package/apps/lib/components/FormBuilder/fields/TextField.tsx +0 -213
- package/apps/lib/components/FormBuilder/fields/TreeSelectField.tsx +0 -43
- package/apps/lib/components/FormBuilder/fields/countries.ts +0 -303
- package/apps/lib/components/FormBuilder/fields/index.ts +0 -25
- package/apps/lib/components/FormBuilder/form-builder.tsx +0 -198
- package/apps/lib/components/FormBuilder/index.ts +0 -31
- package/apps/lib/components/FormBuilder/numberFormat.ts +0 -16
- package/apps/lib/components/FormBuilder/submit.tsx +0 -67
- package/apps/lib/components/FormBuilder/types.ts +0 -316
- package/apps/lib/components/FormRenderer/FormDrawer.tsx +0 -250
- package/apps/lib/components/FormRenderer/detail.tsx +0 -256
- package/apps/lib/components/FormRenderer/form-renderer.tsx +0 -358
- package/apps/lib/components/FormRenderer/header.tsx +0 -88
- package/apps/lib/components/FormRenderer/index.ts +0 -17
- package/apps/lib/components/FormRenderer/notch-action.tsx +0 -64
- package/apps/lib/components/FormRenderer/section.tsx +0 -39
- package/apps/lib/components/FormRenderer/stepper.tsx +0 -393
- package/apps/lib/components/FormRenderer/types.ts +0 -115
- package/apps/lib/components/FormSummary.tsx +0 -282
- package/apps/lib/components/HeaderBar.tsx +0 -117
- package/apps/lib/components/ImageAttachment.tsx +0 -209
- package/apps/lib/components/InnerLabelField.tsx +0 -154
- package/apps/lib/components/Input.tsx +0 -224
- package/apps/lib/components/InputField.tsx +0 -147
- package/apps/lib/components/InputOTP.tsx +0 -84
- package/apps/lib/components/Label.tsx +0 -129
- package/apps/lib/components/LabelField.tsx +0 -76
- package/apps/lib/components/LabeledCheckBox.tsx +0 -51
- package/apps/lib/components/LabeledRadio.tsx +0 -51
- package/apps/lib/components/LinkButton.tsx +0 -94
- package/apps/lib/components/LoginButton.tsx +0 -51
- package/apps/lib/components/PasswordLevel.tsx +0 -58
- package/apps/lib/components/Popover.tsx +0 -312
- package/apps/lib/components/ProfileMenu.tsx +0 -85
- package/apps/lib/components/Radio.tsx +0 -59
- package/apps/lib/components/RadioCard.tsx +0 -50
- package/apps/lib/components/ScrollArea.tsx +0 -54
- package/apps/lib/components/SearchField.tsx +0 -62
- package/apps/lib/components/SearchableSelect.tsx +0 -318
- package/apps/lib/components/SearchableTable.tsx +0 -344
- package/apps/lib/components/SearchableTree.tsx +0 -485
- package/apps/lib/components/SearchableTreeDialog.tsx +0 -502
- package/apps/lib/components/SectionBlock.tsx +0 -168
- package/apps/lib/components/Select.tsx +0 -347
- package/apps/lib/components/SimpleSelect.tsx +0 -225
- package/apps/lib/components/Skeleton.tsx +0 -12
- package/apps/lib/components/SlideDatePicker.tsx +0 -255
- package/apps/lib/components/SpinLoading.tsx +0 -174
- package/apps/lib/components/Stepper.tsx +0 -480
- package/apps/lib/components/Switch.tsx +0 -82
- package/apps/lib/components/TabFormItem.tsx +0 -153
- package/apps/lib/components/TabSwitch.tsx +0 -172
- package/apps/lib/components/Table.tsx +0 -597
- package/apps/lib/components/TextEditor/ChartBlockTool.ts +0 -676
- package/apps/lib/components/TextEditor/RichTextField.tsx +0 -46
- package/apps/lib/components/TextEditor/TableDnDWrapper.ts +0 -462
- package/apps/lib/components/TextEditor/TextEditor.tsx +0 -1164
- package/apps/lib/components/TextEditor/TextEditorToolbar.tsx +0 -429
- package/apps/lib/components/TextEditor/editor-tools/AlignmentTune.ts +0 -70
- package/apps/lib/components/TextEditor/editor-tools/ColorInlineTool.ts +0 -50
- package/apps/lib/components/TextEditor/editor-tools/StrikethroughInlineTool.ts +0 -48
- package/apps/lib/components/TextEditor/editor-tools/inlineFormat.ts +0 -98
- package/apps/lib/components/TextEditor/editorjs.d.ts +0 -60
- package/apps/lib/components/TextEditor/index.ts +0 -7
- package/apps/lib/components/TextEditor/markdownParser.ts +0 -346
- package/apps/lib/components/Textarea.tsx +0 -117
- package/apps/lib/components/Timeline.tsx +0 -263
- package/apps/lib/components/Toast.tsx +0 -87
- package/apps/lib/components/Toggle.tsx +0 -125
- package/apps/lib/components/ToggleButton.tsx +0 -140
- package/apps/lib/components/Tooltip.tsx +0 -116
- package/apps/lib/components/TransparentLabel.tsx +0 -71
- package/apps/lib/components/TreeDropDown.tsx +0 -115
- package/apps/lib/components/TreeFolder/TreeFolder.tsx +0 -380
- package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +0 -75
- package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +0 -354
- package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +0 -60
- package/apps/lib/components/TreeFolder/icons.tsx +0 -60
- package/apps/lib/components/TreeFolder/index.ts +0 -24
- package/apps/lib/components/TreeFolder/treeFolderUtils.ts +0 -109
- package/apps/lib/components/TreeFolder/types.ts +0 -77
- package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +0 -118
- package/apps/lib/hooks/useActiveTreeItem.ts +0 -61
- package/apps/lib/hooks/useClickOutside.ts +0 -27
- package/apps/lib/hooks/useDragDrop.tsx +0 -365
- package/apps/lib/hooks/useHtmlDir.ts +0 -31
- package/apps/lib/hooks/useInfiniteScroll.ts +0 -108
- package/apps/lib/hooks/useIsMobile.ts +0 -21
- package/apps/lib/hooks/useResize.ts +0 -67
- package/apps/lib/hooks/useTagSelection.ts +0 -300
- package/apps/lib/layouts/CNLayout.tsx +0 -372
- package/apps/lib/layouts/DataViewCard.tsx +0 -62
- package/apps/lib/layouts/FieldSection.tsx +0 -91
- package/apps/lib/layouts/TreeSubLayout.tsx +0 -173
- package/apps/lib/providers/ThemeProvider.tsx +0 -84
- package/apps/lib/registry.json +0 -1217
- package/apps/lib/tsconfig.json +0 -9
- package/apps/lib/tsconfig.tsbuildinfo +0 -1
- package/apps/lib/utils/cn.ts +0 -6
- package/apps/lib/utils/color.ts +0 -175
- package/apps/lib/utils/dataViews/path.ts +0 -67
- package/apps/lib/utils/dataViews/query.ts +0 -73
- package/apps/lib/utils/dataViews/types.ts +0 -187
- package/apps/lib/utils/dateFormat.ts +0 -108
- package/apps/lib/utils/resize.ts +0 -31
- package/apps/lib/utils/scroller.ts +0 -26
- package/apps/lib/utils/types.ts +0 -16
- package/docs/BLOCKS.md +0 -129
- package/docs/CHANGELOG-1.1.16.md +0 -108
- package/docs/Cover.png +0 -0
- package/docs/README.md +0 -215
- package/docs/components/action-button.md +0 -638
- package/docs/components/actions-group.md +0 -708
- package/docs/components/alert-dialog.md +0 -920
- package/docs/components/avatar.md +0 -709
- package/docs/components/badge-field.md +0 -738
- package/docs/components/badge.md +0 -301
- package/docs/components/breadcrumb.md +0 -930
- package/docs/components/button-group.md +0 -650
- package/docs/components/button.md +0 -639
- package/docs/components/calendar.md +0 -555
- package/docs/components/card.md +0 -622
- package/docs/components/chart-block-tool.md +0 -129
- package/docs/components/checkbox.md +0 -699
- package/docs/components/cn-layout.md +0 -854
- package/docs/components/color-picker.md +0 -101
- package/docs/components/conclusion-header.md +0 -80
- package/docs/components/context-menu.md +0 -483
- package/docs/components/count-badge.md +0 -560
- package/docs/components/data-table.md +0 -854
- package/docs/components/data-views/backend-response.md +0 -324
- package/docs/components/data-views/examples/a11y-rtl.md +0 -250
- package/docs/components/data-views/examples/api-orders-route.md +0 -130
- package/docs/components/data-views/examples/fields.md +0 -362
- package/docs/components/data-views/examples/filters.md +0 -307
- package/docs/components/data-views/examples/inbox-routing.md +0 -218
- package/docs/components/data-views/examples/index.md +0 -29
- package/docs/components/data-views/examples/overview.md +0 -244
- package/docs/components/data-views/examples/panel.md +0 -212
- package/docs/components/data-views/examples/scale.md +0 -231
- package/docs/components/data-views/examples/server-side.md +0 -210
- package/docs/components/data-views/examples/state.md +0 -250
- package/docs/components/data-views/examples/tree-custom.md +0 -388
- package/docs/components/data-views/examples/view-registry.md +0 -313
- package/docs/components/data-views/examples/views.md +0 -534
- package/docs/components/data-views/guide.md +0 -405
- package/docs/components/data-views/index.md +0 -1521
- package/docs/components/data-views/migration.md +0 -81
- package/docs/components/date-picker.md +0 -857
- package/docs/components/dialog.md +0 -929
- package/docs/components/divider.md +0 -766
- package/docs/components/drawer.md +0 -654
- package/docs/components/dropdown-menu.md +0 -668
- package/docs/components/field-hint.md +0 -898
- package/docs/components/field-section.md +0 -781
- package/docs/components/form-builder.md +0 -284
- package/docs/components/form-renderer.md +0 -396
- package/docs/components/form-summary.md +0 -138
- package/docs/components/form.md +0 -785
- package/docs/components/header-bar.md +0 -188
- package/docs/components/image-attachment.md +0 -906
- package/docs/components/inner-label-field.md +0 -819
- package/docs/components/input-field.md +0 -623
- package/docs/components/input-otp.md +0 -756
- package/docs/components/input.md +0 -634
- package/docs/components/label-field.md +0 -770
- package/docs/components/label.md +0 -761
- package/docs/components/labeled-check-box.md +0 -642
- package/docs/components/labeled-radio.md +0 -796
- package/docs/components/link-button.md +0 -685
- package/docs/components/login-button.md +0 -872
- package/docs/components/password-level.md +0 -803
- package/docs/components/popover.md +0 -649
- package/docs/components/profile-menu.md +0 -656
- package/docs/components/radio-card.md +0 -801
- package/docs/components/radio.md +0 -735
- package/docs/components/scroll-area.md +0 -691
- package/docs/components/search-field.md +0 -702
- package/docs/components/searchable-select.md +0 -368
- package/docs/components/searchable-table.md +0 -438
- package/docs/components/searchable-tree-dialog.md +0 -190
- package/docs/components/searchable-tree.md +0 -200
- package/docs/components/section-block.md +0 -483
- package/docs/components/select.md +0 -709
- package/docs/components/simple-select.md +0 -741
- package/docs/components/skeleton.md +0 -706
- package/docs/components/slide-date-picker.md +0 -837
- package/docs/components/spin-loading.md +0 -696
- package/docs/components/stepper.md +0 -316
- package/docs/components/switch.md +0 -770
- package/docs/components/tab-form-item.md +0 -773
- package/docs/components/tab-switch.md +0 -170
- package/docs/components/table-dnd-wrapper.md +0 -107
- package/docs/components/table.md +0 -1088
- package/docs/components/text-editor.md +0 -735
- package/docs/components/textarea.md +0 -681
- package/docs/components/timeline.md +0 -254
- package/docs/components/toast.md +0 -773
- package/docs/components/toggle-button.md +0 -643
- package/docs/components/toggle.md +0 -882
- package/docs/components/tooltip.md +0 -513
- package/docs/components/transparent-label.md +0 -721
- package/docs/components/tree-drop-down.md +0 -740
- package/docs/components/tree-folder.md +0 -110
- package/docs/components/tree-sub-layout.md +0 -707
- package/docs/explanation/architecture.md +0 -54
- package/docs/explanation/design-system.md +0 -52
- package/docs/how-to/form-and-list-recipes.md +0 -386
- package/docs/how-to/forms-with-form-builder.md +0 -472
- package/docs/how-to/guides.md +0 -1027
- package/docs/migration/changelog.md +0 -60
- package/docs/migration/form-builder-2.5.2.md +0 -113
- package/docs/reference/cli.md +0 -112
- package/docs/reference/components.md +0 -572
- package/docs/reference/hooks.md +0 -1523
- package/docs/reference/providers.md +0 -866
- package/docs/reference/tailwind-plugins.md +0 -942
- package/docs/reference/theme.md +0 -85
- package/docs/reference/types.md +0 -1016
- package/docs/reference/utilities.md +0 -726
- package/docs/tutorials/building-first-form.md +0 -846
- package/docs/tutorials/component-composition.md +0 -882
- package/docs/tutorials/getting-started.md +0 -302
- package/docs/tutorials/theming-basics.md +0 -785
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { CSS } from "@dnd-kit/utilities";
|
|
5
|
-
import {
|
|
6
|
-
ColumnDef,
|
|
7
|
-
flexRender,
|
|
8
|
-
getCoreRowModel,
|
|
9
|
-
getSortedRowModel,
|
|
10
|
-
Row,
|
|
11
|
-
SortingState,
|
|
12
|
-
useReactTable,
|
|
13
|
-
getPaginationRowModel,
|
|
14
|
-
getFilteredRowModel,
|
|
15
|
-
} from "@tanstack/react-table";
|
|
16
|
-
import {
|
|
17
|
-
DndContext,
|
|
18
|
-
closestCenter,
|
|
19
|
-
KeyboardSensor,
|
|
20
|
-
PointerSensor,
|
|
21
|
-
useSensor,
|
|
22
|
-
useSensors,
|
|
23
|
-
DragEndEvent,
|
|
24
|
-
} from "@dnd-kit/core";
|
|
25
|
-
import {
|
|
26
|
-
arrayMove,
|
|
27
|
-
SortableContext,
|
|
28
|
-
sortableKeyboardCoordinates,
|
|
29
|
-
useSortable,
|
|
30
|
-
verticalListSortingStrategy,
|
|
31
|
-
} from "@dnd-kit/sortable";
|
|
32
|
-
|
|
33
|
-
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./Table";
|
|
34
|
-
import { Checkbox } from "./Checkbox";
|
|
35
|
-
|
|
36
|
-
interface DataTableProps<TData extends { id: string | number }, TValue> {
|
|
37
|
-
columns: ColumnDef<TData, TValue>[];
|
|
38
|
-
data: TData[];
|
|
39
|
-
theme?: "dark" | "light" | "default";
|
|
40
|
-
onRowReorder?: (newData: TData[]) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function DataTable<TData extends { id: string | number }, TValue>({
|
|
44
|
-
columns,
|
|
45
|
-
data,
|
|
46
|
-
theme = "default",
|
|
47
|
-
onRowReorder,
|
|
48
|
-
}: DataTableProps<TData, TValue>) {
|
|
49
|
-
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
50
|
-
const [items, setItems] = React.useState<TData[]>(data);
|
|
51
|
-
const [rowSelection, setRowSelection] = React.useState({});
|
|
52
|
-
|
|
53
|
-
const sensors = useSensors(
|
|
54
|
-
useSensor(PointerSensor),
|
|
55
|
-
useSensor(KeyboardSensor, {
|
|
56
|
-
coordinateGetter: sortableKeyboardCoordinates,
|
|
57
|
-
}),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const table = useReactTable({
|
|
61
|
-
data: items,
|
|
62
|
-
columns,
|
|
63
|
-
getCoreRowModel: getCoreRowModel(),
|
|
64
|
-
getSortedRowModel: getSortedRowModel(),
|
|
65
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
66
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
67
|
-
onSortingChange: setSorting,
|
|
68
|
-
onRowSelectionChange: setRowSelection,
|
|
69
|
-
enableRowSelection: true,
|
|
70
|
-
enableMultiRowSelection: true,
|
|
71
|
-
state: {
|
|
72
|
-
sorting,
|
|
73
|
-
rowSelection,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const handleDragEnd = (event: DragEndEvent) => {
|
|
78
|
-
const { active, over } = event;
|
|
79
|
-
|
|
80
|
-
if (over && active.id !== over.id) {
|
|
81
|
-
const oldIndex = items.findIndex((item: TData) => item.id === active.id);
|
|
82
|
-
const newIndex = items.findIndex((item: TData) => item.id === over.id);
|
|
83
|
-
|
|
84
|
-
const newItems = arrayMove(items, oldIndex, newIndex);
|
|
85
|
-
setItems(newItems);
|
|
86
|
-
|
|
87
|
-
// Update row selection to maintain correct mapping after reorder
|
|
88
|
-
const newRowSelection: Record<string, boolean> = {};
|
|
89
|
-
Object.keys(rowSelection).forEach((rowIndex) => {
|
|
90
|
-
const oldRowIndex = parseInt(rowIndex);
|
|
91
|
-
const row = table.getRowModel().rows[oldRowIndex];
|
|
92
|
-
if (row) {
|
|
93
|
-
const newRowIndex = newItems.findIndex((item: TData) => item.id === row.original.id);
|
|
94
|
-
if (newRowIndex !== -1) {
|
|
95
|
-
newRowSelection[newRowIndex.toString()] = true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
setRowSelection(newRowSelection);
|
|
100
|
-
|
|
101
|
-
onRowReorder?.(newItems);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
|
|
107
|
-
<Table theme={theme}>
|
|
108
|
-
<TableHeader>
|
|
109
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
110
|
-
<TableRow key={headerGroup.id}>
|
|
111
|
-
<TableHead isDummy></TableHead>
|
|
112
|
-
<TableHead isDummy>
|
|
113
|
-
<Checkbox
|
|
114
|
-
checked={table.getIsAllRowsSelected()}
|
|
115
|
-
onCheckedChange={(checked) => {
|
|
116
|
-
table.toggleAllRowsSelected(!!checked);
|
|
117
|
-
}}
|
|
118
|
-
/>
|
|
119
|
-
</TableHead>
|
|
120
|
-
{headerGroup.headers.map((header) => {
|
|
121
|
-
const sortHandler = header.column.getToggleSortingHandler();
|
|
122
|
-
return (
|
|
123
|
-
<TableHead
|
|
124
|
-
key={header.id}
|
|
125
|
-
onSort={sortHandler ? () => sortHandler({}) : undefined}
|
|
126
|
-
sortType={header.column.getIsSorted() as "asc" | "desc" | undefined}
|
|
127
|
-
>
|
|
128
|
-
{header.isPlaceholder
|
|
129
|
-
? null
|
|
130
|
-
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
131
|
-
</TableHead>
|
|
132
|
-
);
|
|
133
|
-
})}
|
|
134
|
-
</TableRow>
|
|
135
|
-
))}
|
|
136
|
-
</TableHeader>
|
|
137
|
-
<TableBody>
|
|
138
|
-
{table.getRowModel().rows?.length ? (
|
|
139
|
-
<SortableContext
|
|
140
|
-
items={table.getRowModel().rows.map((row) => row.original)}
|
|
141
|
-
strategy={verticalListSortingStrategy}
|
|
142
|
-
>
|
|
143
|
-
{table.getRowModel().rows.map((row, i) => (
|
|
144
|
-
<SortableRow
|
|
145
|
-
key={i + "row"}
|
|
146
|
-
row={row}
|
|
147
|
-
state={row.getIsSelected() ? "selected" : undefined}
|
|
148
|
-
>
|
|
149
|
-
<TableCell isDummy>
|
|
150
|
-
<Checkbox
|
|
151
|
-
checked={row.getIsSelected()}
|
|
152
|
-
onCheckedChange={(checked) => {
|
|
153
|
-
row.toggleSelected(!!checked);
|
|
154
|
-
}}
|
|
155
|
-
/>
|
|
156
|
-
</TableCell>
|
|
157
|
-
{row.getVisibleCells().map((cell) => (
|
|
158
|
-
<TableCell key={cell.id}>
|
|
159
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
160
|
-
</TableCell>
|
|
161
|
-
))}
|
|
162
|
-
<TableCell isDummy className="w-full"></TableCell>
|
|
163
|
-
</SortableRow>
|
|
164
|
-
))}
|
|
165
|
-
</SortableContext>
|
|
166
|
-
) : (
|
|
167
|
-
<TableRow>
|
|
168
|
-
<TableCell colSpan={columns.length} className="h-24 text-center">
|
|
169
|
-
No results.
|
|
170
|
-
</TableCell>
|
|
171
|
-
</TableRow>
|
|
172
|
-
)}
|
|
173
|
-
</TableBody>
|
|
174
|
-
</Table>
|
|
175
|
-
</DndContext>
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
interface SortableRowProps<TData extends { id: string | number }> {
|
|
180
|
-
row: Row<TData>;
|
|
181
|
-
children: React.ReactNode;
|
|
182
|
-
state?: "delete" | "update" | "add" | "selected" | "open";
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function SortableRow<TData extends { id: string | number }>({
|
|
186
|
-
row,
|
|
187
|
-
children,
|
|
188
|
-
state,
|
|
189
|
-
}: SortableRowProps<TData>) {
|
|
190
|
-
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
191
|
-
id: row.original.id,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const style = {
|
|
195
|
-
transform: CSS.Transform.toString(transform),
|
|
196
|
-
transition,
|
|
197
|
-
opacity: isDragging ? 0.5 : 1,
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
return (
|
|
201
|
-
<TableRow ref={setNodeRef} style={style} state={state}>
|
|
202
|
-
<TableCell
|
|
203
|
-
{...attributes}
|
|
204
|
-
{...listeners}
|
|
205
|
-
className="cursor-grab active:cursor-grabbing"
|
|
206
|
-
isDummy
|
|
207
|
-
>
|
|
208
|
-
<i className="ri-draggable text-[18px]" />
|
|
209
|
-
</TableCell>
|
|
210
|
-
{children}
|
|
211
|
-
</TableRow>
|
|
212
|
-
);
|
|
213
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { BadgeVariant } from "../../utils/dataViews/types";
|
|
2
|
-
|
|
3
|
-
type TorchBadgeColor =
|
|
4
|
-
"gray" | "slate" | "red" | "orange" | "yellow" | "green" | "ocean" | "blue" | "purple" | "rose";
|
|
5
|
-
|
|
6
|
-
type TorchBadgeStyle = "solid" | "subtle";
|
|
7
|
-
|
|
8
|
-
export type ResolvedBadgeProps = {
|
|
9
|
-
color: TorchBadgeColor;
|
|
10
|
-
badgeStyle: TorchBadgeStyle;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Map the DataViews `BadgeVariant` set onto Glare `Badge` props.
|
|
15
|
-
* Defaults to `subtle` style (glare's native default — colored dot + subtle bg).
|
|
16
|
-
* The legacy "Light" / "navy" / "bluePurple" variants explicitly request solid
|
|
17
|
-
* fills, kept distinct for backwards compat with the data-views examples.
|
|
18
|
-
*/
|
|
19
|
-
export function resolveBadgeVariant(variant?: BadgeVariant): ResolvedBadgeProps {
|
|
20
|
-
switch (variant) {
|
|
21
|
-
case "green":
|
|
22
|
-
return { color: "green", badgeStyle: "subtle" };
|
|
23
|
-
case "greenLight":
|
|
24
|
-
return { color: "green", badgeStyle: "subtle" };
|
|
25
|
-
case "cocktailGreen":
|
|
26
|
-
return { color: "green", badgeStyle: "solid" };
|
|
27
|
-
case "yellow":
|
|
28
|
-
return { color: "yellow", badgeStyle: "subtle" };
|
|
29
|
-
case "redOrange":
|
|
30
|
-
return { color: "orange", badgeStyle: "subtle" };
|
|
31
|
-
case "redLight":
|
|
32
|
-
return { color: "red", badgeStyle: "subtle" };
|
|
33
|
-
case "rose":
|
|
34
|
-
return { color: "rose", badgeStyle: "subtle" };
|
|
35
|
-
case "purple":
|
|
36
|
-
return { color: "purple", badgeStyle: "subtle" };
|
|
37
|
-
case "bluePurple":
|
|
38
|
-
return { color: "purple", badgeStyle: "solid" };
|
|
39
|
-
case "blue":
|
|
40
|
-
return { color: "blue", badgeStyle: "subtle" };
|
|
41
|
-
case "navy":
|
|
42
|
-
return { color: "blue", badgeStyle: "solid" };
|
|
43
|
-
case "highlight":
|
|
44
|
-
return { color: "yellow", badgeStyle: "subtle" };
|
|
45
|
-
case "gray":
|
|
46
|
-
default:
|
|
47
|
-
return { color: "gray", badgeStyle: "subtle" };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { cn } from "../../utils/cn";
|
|
5
|
-
import { getByPath } from "../../utils/dataViews/path";
|
|
6
|
-
import type { CurrencyOptions, FieldConfig, Row } from "../../utils/dataViews/types";
|
|
7
|
-
import { Avatar, AvatarFallback, AvatarImage } from "../Avatar";
|
|
8
|
-
import { Badge } from "../Badge";
|
|
9
|
-
import { resolveBadgeVariant } from "./badge";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Paints one field of one row.
|
|
13
|
-
*
|
|
14
|
-
* This is the whole of DataViews' relationship with your data: read the value at `field.path` and
|
|
15
|
-
* turn it into pixels. Every view — table cell, board card, inbox row, tree node — goes through
|
|
16
|
-
* here, so a field looks the same wherever it appears and there is one place to add a type.
|
|
17
|
-
*
|
|
18
|
-
* `field.render` wins over `field.type`, so anything not covered below is a one-line escape hatch
|
|
19
|
-
* rather than a reason to extend `FieldType`.
|
|
20
|
-
*/
|
|
21
|
-
export function Cell({
|
|
22
|
-
field,
|
|
23
|
-
row,
|
|
24
|
-
className,
|
|
25
|
-
}: {
|
|
26
|
-
field: FieldConfig;
|
|
27
|
-
row: Row;
|
|
28
|
-
className?: string;
|
|
29
|
-
}) {
|
|
30
|
-
const value = getByPath(row, field.path);
|
|
31
|
-
|
|
32
|
-
if (field.render) return <>{field.render(value, row)}</>;
|
|
33
|
-
|
|
34
|
-
const type = field.type ?? "text";
|
|
35
|
-
if (type === "hidden") return null;
|
|
36
|
-
|
|
37
|
-
// `boolean` and `progress-bar` render something meaningful for a missing value — false, and an
|
|
38
|
-
// empty bar — so they are the two types that never show the placeholder.
|
|
39
|
-
if (isBlank(value) && type !== "boolean" && type !== "progress-bar") {
|
|
40
|
-
return className ? <span className={className}>{NULL_PLACEHOLDER}</span> : NULL_PLACEHOLDER;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const content = paint(type, field, row, value);
|
|
44
|
-
if (content === null) return null;
|
|
45
|
-
return className ? <span className={className}>{content}</span> : <>{content}</>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const NULL_PLACEHOLDER = <span className="text-content-presentation-global-tertiary">-</span>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* An empty array counts as blank. It has to: `String([])` is `""`, so without this an `image`
|
|
52
|
-
* field handed `[]` renders `<img src="">`, which the browser resolves to the current page and
|
|
53
|
-
* re-downloads it. `badge-array` checks `Array.isArray` before this ever applies.
|
|
54
|
-
*/
|
|
55
|
-
function isBlank(value: unknown) {
|
|
56
|
-
if (Array.isArray(value)) return value.length === 0;
|
|
57
|
-
return value === undefined || value === null || value === "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ─── Formatting helpers ───────────────────────────────────────────────────────
|
|
61
|
-
|
|
62
|
-
function formatWithToken(d: Date, token: string): string {
|
|
63
|
-
const pad = (n: number) => String(n).padStart(2, "0");
|
|
64
|
-
return token
|
|
65
|
-
.replace(/YYYY/g, String(d.getFullYear()))
|
|
66
|
-
.replace(/MM/g, pad(d.getMonth() + 1))
|
|
67
|
-
.replace(/DD/g, pad(d.getDate()))
|
|
68
|
-
.replace(/HH/g, pad(d.getHours()))
|
|
69
|
-
.replace(/mm/g, pad(d.getMinutes()))
|
|
70
|
-
.replace(/ss/g, pad(d.getSeconds()));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function toInitials(s: string): string {
|
|
74
|
-
if (!s) return "?";
|
|
75
|
-
const parts = String(s).trim().split(/\s+/).slice(0, 2);
|
|
76
|
-
return parts.map((p) => p[0]?.toUpperCase() ?? "").join("") || "?";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function IconNode({ icon }: { icon: string }) {
|
|
80
|
-
if (/^ri-/.test(icon)) return <i className={icon} />;
|
|
81
|
-
return <span aria-hidden>{icon}</span>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ─── The type switch ──────────────────────────────────────────────────────────
|
|
85
|
-
|
|
86
|
-
function paint(
|
|
87
|
-
type: NonNullable<FieldConfig["type"]>,
|
|
88
|
-
field: FieldConfig,
|
|
89
|
-
row: Row,
|
|
90
|
-
value: unknown,
|
|
91
|
-
): React.ReactNode {
|
|
92
|
-
switch (type) {
|
|
93
|
-
case "number": {
|
|
94
|
-
return (
|
|
95
|
-
<span className="font-mono text-content-presentation-global-primary">
|
|
96
|
-
{typeof value === "number" ? value.toLocaleString() : String(value)}
|
|
97
|
-
</span>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
case "date":
|
|
102
|
-
return <span className="text-content-presentation-global-primary">{String(value)}</span>;
|
|
103
|
-
|
|
104
|
-
case "date-format": {
|
|
105
|
-
const opts = field.dateFormat;
|
|
106
|
-
let formatted = String(value);
|
|
107
|
-
try {
|
|
108
|
-
const d = value instanceof Date ? value : new Date(value as string | number);
|
|
109
|
-
if (!Number.isNaN(d.getTime())) {
|
|
110
|
-
if (typeof opts === "object" && opts) {
|
|
111
|
-
formatted = new Intl.DateTimeFormat(undefined, opts).format(d);
|
|
112
|
-
} else if (typeof opts === "string") {
|
|
113
|
-
formatted = formatWithToken(d, opts);
|
|
114
|
-
} else {
|
|
115
|
-
formatted = new Intl.DateTimeFormat(undefined, {
|
|
116
|
-
year: "numeric",
|
|
117
|
-
month: "short",
|
|
118
|
-
day: "numeric",
|
|
119
|
-
}).format(d);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} catch {
|
|
123
|
-
/* fall through to the raw string */
|
|
124
|
-
}
|
|
125
|
-
return <span className="text-content-presentation-global-primary">{formatted}</span>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
case "boolean": {
|
|
129
|
-
const isTrue = !!value;
|
|
130
|
-
const variant = isTrue ? (field.trueVariant ?? "green") : (field.falseVariant ?? "gray");
|
|
131
|
-
return (
|
|
132
|
-
<Badge
|
|
133
|
-
{...resolveBadgeVariant(variant)}
|
|
134
|
-
label={isTrue ? (field.trueLabel ?? "Yes") : (field.falseLabel ?? "No")}
|
|
135
|
-
size="S"
|
|
136
|
-
/>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
case "enum-badge": {
|
|
141
|
-
const key = String(value);
|
|
142
|
-
const variant = field.variants?.[key] ?? field.defaultVariant ?? "gray";
|
|
143
|
-
return <Badge {...resolveBadgeVariant(variant)} label={key} size="S" />;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
case "badge-array": {
|
|
147
|
-
const badgeProps = resolveBadgeVariant(field.variant ?? "blue");
|
|
148
|
-
if (!Array.isArray(value)) {
|
|
149
|
-
return <Badge {...badgeProps} label={String(value)} size="XS" />;
|
|
150
|
-
}
|
|
151
|
-
const limit = field.limit ?? value.length;
|
|
152
|
-
const head = value.slice(0, limit);
|
|
153
|
-
const overflow = value.length - head.length;
|
|
154
|
-
return (
|
|
155
|
-
<div className="flex flex-wrap gap-1">
|
|
156
|
-
{/* Keyed by position, not by value — a badge-array is free to repeat one. */}
|
|
157
|
-
{head.map((v, i) => (
|
|
158
|
-
<Badge key={i} {...badgeProps} label={String(v)} size="XS" />
|
|
159
|
-
))}
|
|
160
|
-
{overflow > 0 && (
|
|
161
|
-
<Badge {...resolveBadgeVariant("gray")} label={`+${overflow}`} size="XS" />
|
|
162
|
-
)}
|
|
163
|
-
</div>
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
case "currency": {
|
|
168
|
-
const num = Number(value);
|
|
169
|
-
if (Number.isNaN(num)) {
|
|
170
|
-
return <span className="text-content-presentation-global-primary">{String(value)}</span>;
|
|
171
|
-
}
|
|
172
|
-
const opts: CurrencyOptions =
|
|
173
|
-
typeof field.currency === "string" ? { code: field.currency } : (field.currency ?? {});
|
|
174
|
-
const plain = () =>
|
|
175
|
-
`${opts.symbol ?? "$"}${num.toLocaleString(opts.locale, {
|
|
176
|
-
minimumFractionDigits: opts.decimals,
|
|
177
|
-
maximumFractionDigits: opts.decimals,
|
|
178
|
-
})}`;
|
|
179
|
-
|
|
180
|
-
let formatted: string;
|
|
181
|
-
if (opts.code) {
|
|
182
|
-
try {
|
|
183
|
-
formatted = new Intl.NumberFormat(opts.locale, {
|
|
184
|
-
style: "currency",
|
|
185
|
-
currency: opts.code,
|
|
186
|
-
minimumFractionDigits: opts.decimals,
|
|
187
|
-
maximumFractionDigits: opts.decimals,
|
|
188
|
-
}).format(num);
|
|
189
|
-
} catch {
|
|
190
|
-
formatted = plain();
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
formatted = plain();
|
|
194
|
-
}
|
|
195
|
-
return <span className="font-semibold text-green-600">{formatted}</span>;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
case "number-format": {
|
|
199
|
-
const num = Number(value);
|
|
200
|
-
if (Number.isNaN(num)) {
|
|
201
|
-
return <span className="text-content-presentation-global-primary">{String(value)}</span>;
|
|
202
|
-
}
|
|
203
|
-
return (
|
|
204
|
-
<span className="font-mono text-content-presentation-global-primary">
|
|
205
|
-
{new Intl.NumberFormat(undefined, field.format).format(num)}
|
|
206
|
-
</span>
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
case "progress-bar": {
|
|
211
|
-
const raw = Number(value);
|
|
212
|
-
const num = Number.isFinite(raw) ? raw : 0;
|
|
213
|
-
const pct = Math.max(0, Math.min(100, num));
|
|
214
|
-
// Thresholds are percentages of the bar, not values: below `warn` is red, at or above `ok`
|
|
215
|
-
// is green, and everything between is amber.
|
|
216
|
-
const [warn, ok] = field.thresholds ?? [40, 70];
|
|
217
|
-
const color = num >= ok ? "bg-green-500" : num >= warn ? "bg-yellow-500" : "bg-red-500";
|
|
218
|
-
return (
|
|
219
|
-
<div className="flex min-w-[120px] items-center gap-2">
|
|
220
|
-
<div className="bg-background-presentation-form-field-primary h-2 flex-1 overflow-hidden rounded-full">
|
|
221
|
-
<div className={cn("h-full transition-all", color)} style={{ width: `${pct}%` }} />
|
|
222
|
-
</div>
|
|
223
|
-
<span className="text-content-presentation-global-primary w-10 text-right text-xs font-medium tabular-nums">
|
|
224
|
-
{Math.round(num)}%
|
|
225
|
-
</span>
|
|
226
|
-
</div>
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
case "star-rating": {
|
|
231
|
-
const num = Number(value);
|
|
232
|
-
const max = field.max ?? 5;
|
|
233
|
-
const filled = Math.max(0, Math.min(max, Math.floor(num)));
|
|
234
|
-
return (
|
|
235
|
-
<div className="flex items-center gap-2">
|
|
236
|
-
<div className="flex">
|
|
237
|
-
{Array.from({ length: max }).map((_, i) => (
|
|
238
|
-
<span key={i} className={i < filled ? "text-yellow-500" : "text-gray-300"} aria-hidden>
|
|
239
|
-
★
|
|
240
|
-
</span>
|
|
241
|
-
))}
|
|
242
|
-
</div>
|
|
243
|
-
<span className="text-sm font-semibold tabular-nums">
|
|
244
|
-
{Number.isFinite(num) ? num : "-"}
|
|
245
|
-
</span>
|
|
246
|
-
</div>
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
case "icon-text": {
|
|
251
|
-
const icon = field.icon ?? "";
|
|
252
|
-
const after = field.iconPosition === "after";
|
|
253
|
-
return (
|
|
254
|
-
<span className="text-content-presentation-global-primary inline-flex items-center gap-1.5">
|
|
255
|
-
{!after && icon && <IconNode icon={icon} />}
|
|
256
|
-
<span>{String(value)}</span>
|
|
257
|
-
{after && icon && <IconNode icon={icon} />}
|
|
258
|
-
</span>
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
case "two-line": {
|
|
263
|
-
const secondary = field.secondaryPath != null ? getByPath(row, field.secondaryPath) : null;
|
|
264
|
-
return (
|
|
265
|
-
<div className="leading-tight">
|
|
266
|
-
<div className="text-content-presentation-global-primary font-semibold">
|
|
267
|
-
{String(value)}
|
|
268
|
-
</div>
|
|
269
|
-
{secondary != null && (
|
|
270
|
-
<div className="text-content-presentation-global-secondary text-xs">
|
|
271
|
-
{String(secondary)}
|
|
272
|
-
</div>
|
|
273
|
-
)}
|
|
274
|
-
</div>
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
case "avatar": {
|
|
279
|
-
const src = typeof value === "string" ? value : null;
|
|
280
|
-
// Without a `fallbackPath` there is no name to derive initials from — falling back to the
|
|
281
|
-
// image URL would spell them out of "ht".
|
|
282
|
-
const fallbackSource = field.fallbackPath != null ? getByPath(row, field.fallbackPath) : null;
|
|
283
|
-
const initials = toInitials(String(fallbackSource ?? "?"));
|
|
284
|
-
return (
|
|
285
|
-
<Avatar>
|
|
286
|
-
{src && <AvatarImage src={src} alt={initials} />}
|
|
287
|
-
<AvatarFallback>{initials}</AvatarFallback>
|
|
288
|
-
</Avatar>
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
case "link": {
|
|
293
|
-
const v = String(value);
|
|
294
|
-
let href = v;
|
|
295
|
-
if (field.linkType === "mailto" && !v.startsWith("mailto:")) href = `mailto:${v}`;
|
|
296
|
-
else if (field.linkType === "tel" && !v.startsWith("tel:")) href = `tel:${v}`;
|
|
297
|
-
return (
|
|
298
|
-
<a
|
|
299
|
-
href={href}
|
|
300
|
-
target={field.linkType === "url" ? "_blank" : undefined}
|
|
301
|
-
rel={field.linkType === "url" ? "noopener noreferrer" : undefined}
|
|
302
|
-
className="text-blue-600 hover:underline"
|
|
303
|
-
onClick={(e) => e.stopPropagation()}
|
|
304
|
-
>
|
|
305
|
-
{v}
|
|
306
|
-
</a>
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
case "image":
|
|
311
|
-
return (
|
|
312
|
-
// eslint-disable-next-line @next/next/no-img-element -- the src is arbitrary consumer data
|
|
313
|
-
<img
|
|
314
|
-
src={String(value)}
|
|
315
|
-
alt=""
|
|
316
|
-
className="border-border-presentation-global-primary h-10 w-10 rounded border object-cover"
|
|
317
|
-
/>
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
case "text":
|
|
321
|
-
default:
|
|
322
|
-
return <span className="text-content-presentation-global-primary">{String(value)}</span>;
|
|
323
|
-
}
|
|
324
|
-
}
|