@webiny/admin-ui 0.0.0-unstable.7be00a75a9 → 0.0.0-unstable.7c2def32a7
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/Accordion/Accordion.d.ts +7 -6
- package/Accordion/Accordion.stories.d.ts +1 -1
- package/Accordion/Accordion.stories.js.map +1 -1
- package/Accordion/components/AccordionContent.js +4 -1
- package/Accordion/components/AccordionContent.js.map +1 -1
- package/Accordion/components/AccordionItem.d.ts +8 -6
- package/Accordion/components/AccordionItem.js.map +1 -1
- package/Accordion/components/AccordionItemAction.d.ts +7 -6
- package/Accordion/components/AccordionItemDragHandle.d.ts +2 -1
- package/Accordion/components/AccordionItemDragHandle.js +2 -1
- package/Accordion/components/AccordionItemDragHandle.js.map +1 -1
- package/Accordion/components/AccordionItemIcon.d.ts +7 -6
- package/Accordion/components/AccordionItemSeparator.d.ts +7 -6
- package/Accordion/components/AccordionTrigger.js +4 -2
- package/Accordion/components/AccordionTrigger.js.map +1 -1
- package/Alert/Alert.d.ts +21 -19
- package/Alert/Alert.stories.d.ts +1 -1
- package/Alert/Alert.stories.js.map +1 -1
- package/AutoComplete/AutoComplete.d.ts +7 -6
- package/AutoComplete/AutoComplete.stories.d.ts +1 -1
- package/AutoComplete/AutoComplete.stories.js.map +1 -1
- package/AutoComplete/primitives/AutoCompletePrimitive.d.ts +13 -6
- package/AutoComplete/primitives/AutoCompletePrimitive.js +1 -0
- package/AutoComplete/primitives/AutoCompletePrimitive.js.map +1 -1
- package/AutoComplete/primitives/AutoCompletePrimitive.stories.d.ts +1 -1
- package/AutoComplete/primitives/AutoCompletePrimitive.stories.js.map +1 -1
- package/Avatar/Avatar.d.ts +9 -8
- package/Avatar/Avatar.stories.d.ts +1 -1
- package/Avatar/Avatar.stories.js.map +1 -1
- package/Avatar/components/AvatarFallback.d.ts +7 -6
- package/Avatar/components/AvatarImage.d.ts +7 -6
- package/BetaBadge/BetaBadge.d.ts +6 -0
- package/BetaBadge/BetaBadge.js +7 -0
- package/BetaBadge/BetaBadge.js.map +1 -0
- package/Breadcrumbs/Breadcrumbs.d.ts +54 -0
- package/Breadcrumbs/Breadcrumbs.js +66 -0
- package/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/Breadcrumbs/Breadcrumbs.stories.d.ts +9 -0
- package/Breadcrumbs/Breadcrumbs.stories.js +71 -0
- package/Breadcrumbs/Breadcrumbs.stories.js.map +1 -0
- package/Breadcrumbs/index.d.ts +1 -0
- package/Breadcrumbs/index.js +1 -0
- package/Button/Button.d.ts +10 -9
- package/Button/Button.js +7 -0
- package/Button/Button.js.map +1 -1
- package/Button/Button.mdx +13 -0
- package/Button/Button.stories.d.ts +2 -1
- package/Button/Button.stories.js +9 -2
- package/Button/Button.stories.js.map +1 -1
- package/Button/CopyButton.d.ts +7 -6
- package/Button/IconButton.d.ts +10 -9
- package/Button/IconButton.stories.d.ts +1 -1
- package/Button/IconButton.stories.js.map +1 -1
- package/Calendar/Calendar.d.ts +7 -6
- package/Calendar/calendarClassNames.js +1 -1
- package/Calendar/calendarClassNames.js.map +1 -1
- package/Card/Card.d.ts +8 -22
- package/Card/Card.stories.d.ts +1 -1
- package/Card/Card.stories.js.map +1 -1
- package/Card/components/CancelAction.d.ts +8 -6
- package/Card/components/CardContent.d.ts +6 -6
- package/Card/components/CardTitle.d.ts +2 -2
- package/Card/components/ConfirmAction.d.ts +8 -6
- package/Card/components/Icon.d.ts +7 -6
- package/Checkbox/Checkbox.d.ts +7 -6
- package/Checkbox/Checkbox.stories.d.ts +1 -1
- package/Checkbox/Checkbox.stories.js.map +1 -1
- package/Checkbox/primitives/CheckboxPrimitive.d.ts +17 -12
- package/Checkbox/primitives/CheckboxPrimitive.stories.d.ts +1 -1
- package/Checkbox/primitives/CheckboxPrimitive.stories.js.map +1 -1
- package/CheckboxGroup/CheckboxGroup.d.ts +7 -6
- package/CheckboxGroup/CheckboxGroup.stories.d.ts +1 -1
- package/CheckboxGroup/CheckboxGroup.stories.js.map +1 -1
- package/CheckboxGroup/primitives/CheckboxGroupPrimitive.d.ts +20 -12
- package/CheckboxGroup/primitives/CheckboxGroupPrimitive.stories.d.ts +1 -1
- package/CheckboxGroup/primitives/CheckboxGroupPrimitive.stories.js.map +1 -1
- package/CodeEditor/CodeEditor.d.ts +7 -6
- package/CodeEditor/CodeEditor.stories.d.ts +1 -1
- package/CodeEditor/CodeEditor.stories.js.map +1 -1
- package/CodeEditor/CodeEditorPrimitive.d.ts +7 -6
- package/CodeEditor/CodeEditorPrimitive.js +3 -1
- package/CodeEditor/CodeEditorPrimitive.js.map +1 -1
- package/CodeEditor/CodeEditorPrimitive.stories.d.ts +1 -1
- package/CodeEditor/CodeEditorPrimitive.stories.js.map +1 -1
- package/ColorPicker/ColorPicker.d.ts +7 -6
- package/ColorPicker/ColorPicker.stories.d.ts +1 -1
- package/ColorPicker/ColorPicker.stories.js.map +1 -1
- package/ColorPicker/primitives/ColorPickerPrimitive.d.ts +7 -6
- package/ColorPicker/primitives/ColorPickerPrimitive.stories.d.ts +1 -1
- package/ColorPicker/primitives/ColorPickerPrimitive.stories.js.map +1 -1
- package/Command/Command.d.ts +10 -8
- package/Command/components/List.d.ts +1 -1
- package/Command/components/List.js +9 -5
- package/Command/components/List.js.map +1 -1
- package/DataList/DataListModal.d.ts +6 -3
- package/DataTable/DataTable.d.ts +23 -12
- package/DataTable/DataTable.js +18 -7
- package/DataTable/DataTable.js.map +1 -1
- package/DataTable/DataTable.stories.d.ts +1 -1
- package/DataTable/DataTable.stories.js.map +1 -1
- package/DataTable/components/ColumnsVisibility.d.ts +5 -4
- package/DataTable/components/ColumnsVisibility.js +7 -3
- package/DataTable/components/ColumnsVisibility.js.map +1 -1
- package/DatePicker/DatePicker.d.ts +11 -7
- package/DatePicker/DatePicker.js +10 -2
- package/DatePicker/DatePicker.js.map +1 -1
- package/DatePicker/DatePicker.stories.d.ts +11 -1
- package/DatePicker/DatePicker.stories.js +44 -1
- package/DatePicker/DatePicker.stories.js.map +1 -1
- package/DatePicker/primitives/BirthdayPicker.d.ts +13 -0
- package/DatePicker/primitives/BirthdayPicker.js +355 -0
- package/DatePicker/primitives/BirthdayPicker.js.map +1 -0
- package/DatePicker/primitives/BirthdayPickerCell.d.ts +14 -0
- package/DatePicker/primitives/BirthdayPickerCell.js +19 -0
- package/DatePicker/primitives/BirthdayPickerCell.js.map +1 -0
- package/DatePicker/primitives/BirthdayPickerSegments.d.ts +9 -0
- package/DatePicker/primitives/BirthdayPickerSegments.js +43 -0
- package/DatePicker/primitives/BirthdayPickerSegments.js.map +1 -0
- package/DatePicker/primitives/DateOnlyPicker.js +2 -2
- package/DatePicker/primitives/DateOnlyPicker.js.map +1 -1
- package/DatePicker/primitives/DatePickerPrimitive.d.ts +7 -6
- package/DatePicker/primitives/DatePickerPrimitive.js +3 -0
- package/DatePicker/primitives/DatePickerPrimitive.js.map +1 -1
- package/DatePicker/primitives/DateRangePicker.js +3 -3
- package/DatePicker/primitives/DateRangePicker.js.map +1 -1
- package/DatePicker/primitives/DateTimePicker.d.ts +1 -1
- package/DatePicker/primitives/DateTimePicker.js +26 -18
- package/DatePicker/primitives/DateTimePicker.js.map +1 -1
- package/DatePicker/primitives/MultipleDatesPicker.js +3 -3
- package/DatePicker/primitives/MultipleDatesPicker.js.map +1 -1
- package/DatePicker/primitives/components/DatePickerTrigger.js +2 -2
- package/DatePicker/primitives/components/DatePickerTrigger.js.map +1 -1
- package/DatePicker/utils/birthdayHelpers.d.ts +77 -0
- package/DatePicker/utils/birthdayHelpers.js +145 -0
- package/DatePicker/utils/birthdayHelpers.js.map +1 -0
- package/DatePicker/utils/birthdayHelpers.test.d.ts +1 -0
- package/DatePicker/utils/birthdayHelpers.test.js +394 -0
- package/DatePicker/utils/birthdayHelpers.test.js.map +1 -0
- package/DatePicker/utils/dateHelpers.d.ts +6 -1
- package/DatePicker/utils/dateHelpers.js +13 -5
- package/DatePicker/utils/dateHelpers.js.map +1 -1
- package/DatePicker/utils/dateHelpers.test.d.ts +1 -0
- package/DatePicker/utils/dateHelpers.test.js +32 -0
- package/DatePicker/utils/dateHelpers.test.js.map +1 -0
- package/DatePicker/utils/index.d.ts +1 -0
- package/DatePicker/utils/index.js +1 -0
- package/DatePicker/utils/timezoneHelpers.d.ts +3 -0
- package/DatePicker/utils/timezoneHelpers.js +32 -0
- package/DatePicker/utils/timezoneHelpers.js.map +1 -0
- package/DatePicker/utils/types.d.ts +15 -2
- package/Dialog/Dialog.d.ts +8 -22
- package/Dialog/Dialog.stories.d.ts +1 -1
- package/Dialog/Dialog.stories.js.map +1 -1
- package/Dialog/components/CancelAction.d.ts +8 -6
- package/Dialog/components/ConfirmAction.d.ts +8 -6
- package/Dialog/components/DialogContent.d.ts +1 -1
- package/Dialog/components/DialogFooter.d.ts +1 -1
- package/Dialog/components/DialogTitle.d.ts +1 -1
- package/Dialog/components/Icon.d.ts +7 -6
- package/DragCursor/DragCursor.d.ts +7 -0
- package/DragCursor/DragCursor.js +21 -0
- package/DragCursor/DragCursor.js.map +1 -0
- package/DragCursor/DragCursor.stories.d.ts +10 -0
- package/DragCursor/DragCursor.stories.js +97 -0
- package/DragCursor/DragCursor.stories.js.map +1 -0
- package/DragCursor/index.d.ts +1 -0
- package/DragCursor/index.js +1 -0
- package/Drawer/Drawer.d.ts +18 -28
- package/Drawer/Drawer.js +2 -1
- package/Drawer/Drawer.js.map +1 -1
- package/Drawer/Drawer.stories.d.ts +2 -1
- package/Drawer/Drawer.stories.js +21 -2
- package/Drawer/Drawer.stories.js.map +1 -1
- package/Drawer/components/CancelButton.d.ts +8 -6
- package/Drawer/components/ConfirmButton.d.ts +8 -6
- package/Drawer/components/DrawerContent.d.ts +1 -1
- package/Drawer/components/DrawerHeader.d.ts +2 -2
- package/Drawer/components/DrawerHeader.js +11 -8
- package/Drawer/components/DrawerHeader.js.map +1 -1
- package/Drawer/components/Icon.d.ts +7 -6
- package/Drawer/components/Icon.js +3 -4
- package/Drawer/components/Icon.js.map +1 -1
- package/DropdownMenu/DropdownMenu.stories.d.ts +1 -1
- package/DropdownMenu/DropdownMenu.stories.js.map +1 -1
- package/DropdownMenu/components/DropdownMenuItem.d.ts +8 -2
- package/DropdownMenu/components/DropdownMenuItem.js +11 -3
- package/DropdownMenu/components/DropdownMenuItem.js.map +1 -1
- package/DropdownMenu/components/DropdownMenuLink.d.ts +9 -8
- package/DropdownMenu/components/DropdownMenuSeparator.d.ts +7 -6
- package/EditableTitle/EditableTitle.d.ts +67 -0
- package/EditableTitle/EditableTitle.js +73 -0
- package/EditableTitle/EditableTitle.js.map +1 -0
- package/EditableTitle/index.d.ts +1 -0
- package/EditableTitle/index.js +1 -0
- package/EmptyState/EmptyState.d.ts +43 -0
- package/EmptyState/EmptyState.js +93 -0
- package/EmptyState/EmptyState.js.map +1 -0
- package/EmptyState/EmptyState.stories.d.ts +13 -0
- package/EmptyState/EmptyState.stories.js +136 -0
- package/EmptyState/EmptyState.stories.js.map +1 -0
- package/EmptyState/illustrations/ContentIllustration.d.ts +2 -0
- package/EmptyState/illustrations/ContentIllustration.js +100 -0
- package/EmptyState/illustrations/ContentIllustration.js.map +1 -0
- package/EmptyState/illustrations/LayoutIllustration.d.ts +2 -0
- package/EmptyState/illustrations/LayoutIllustration.js +93 -0
- package/EmptyState/illustrations/LayoutIllustration.js.map +1 -0
- package/EmptyState/illustrations/ListingIllustration.d.ts +2 -0
- package/EmptyState/illustrations/ListingIllustration.js +92 -0
- package/EmptyState/illustrations/ListingIllustration.js.map +1 -0
- package/EmptyState/illustrations/SelectIllustration.d.ts +2 -0
- package/EmptyState/illustrations/SelectIllustration.js +100 -0
- package/EmptyState/illustrations/SelectIllustration.js.map +1 -0
- package/EmptyState/illustrations/TableIllustration.d.ts +2 -0
- package/EmptyState/illustrations/TableIllustration.js +233 -0
- package/EmptyState/illustrations/TableIllustration.js.map +1 -0
- package/EmptyState/illustrations/UploadIllustration.d.ts +2 -0
- package/EmptyState/illustrations/UploadIllustration.js +77 -0
- package/EmptyState/illustrations/UploadIllustration.js.map +1 -0
- package/EmptyState/illustrations/index.d.ts +6 -0
- package/EmptyState/illustrations/index.js +6 -0
- package/EmptyState/index.d.ts +1 -0
- package/EmptyState/index.js +1 -0
- package/FilePicker/FilePicker.d.ts +19 -18
- package/FilePicker/FilePicker.stories.d.ts +7 -1
- package/FilePicker/FilePicker.stories.js +24 -1
- package/FilePicker/FilePicker.stories.js.map +1 -1
- package/FilePicker/primitives/FilePickerPrimitive.d.ts +20 -19
- package/FilePicker/primitives/FilePickerPrimitive.stories.d.ts +1 -1
- package/FilePicker/primitives/FilePickerPrimitive.stories.js.map +1 -1
- package/FilePicker/primitives/components/Trigger.d.ts +1 -1
- package/FilePicker/primitives/components/previews/ImagePreview/ImagePreview.d.ts +19 -7
- package/FilePicker/primitives/components/previews/ImagePreview/ImagePreview.js +15 -6
- package/FilePicker/primitives/components/previews/ImagePreview/ImagePreview.js.map +1 -1
- package/FilePicker/primitives/components/previews/ItemActions.js +1 -1
- package/FilePicker/primitives/components/previews/ItemActions.js.map +1 -1
- package/FilePicker/primitives/components/previews/ItemDescription.js +1 -1
- package/FilePicker/primitives/components/previews/ItemDescription.js.map +1 -1
- package/FilePicker/primitives/components/previews/RichItemPreview/FileType.d.ts +5 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/FileType.js +45 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/FileType.js.map +1 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/Placeholder.d.ts +5 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/Placeholder.js +14 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/Placeholder.js.map +1 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemPreview.d.ts +12 -6
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemPreview.js +54 -12
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemPreview.js.map +1 -1
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemThumbnail.d.ts +11 -1
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemThumbnail.js +8 -61
- package/FilePicker/primitives/components/previews/RichItemPreview/RichItemThumbnail.js.map +1 -1
- package/FilePicker/primitives/components/previews/RichItemPreview/Thumbnail.d.ts +11 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/Thumbnail.js +24 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/Thumbnail.js.map +1 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/ThumbnailActions.d.ts +10 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/ThumbnailActions.js +46 -0
- package/FilePicker/primitives/components/previews/RichItemPreview/ThumbnailActions.js.map +1 -0
- package/FilePicker/primitives/components/previews/TextOnlyPreview/TextOnlyPreview.d.ts +7 -6
- package/FilePicker/primitives/components/previews/TruncatedFileName.d.ts +7 -0
- package/FilePicker/primitives/components/previews/TruncatedFileName.js +20 -0
- package/FilePicker/primitives/components/previews/TruncatedFileName.js.map +1 -0
- package/FilePicker/primitives/components/previews/fileName.d.ts +4 -0
- package/FilePicker/primitives/components/previews/fileName.js +26 -0
- package/FilePicker/primitives/components/previews/fileName.js.map +1 -0
- package/FilePicker/primitives/components/previews/index.d.ts +1 -0
- package/FilePicker/primitives/components/previews/index.js +1 -0
- package/FilePicker/primitives/components/previews/variants.d.ts +1 -1
- package/FillViewport/FillViewport.d.ts +63 -0
- package/FillViewport/FillViewport.js +67 -0
- package/FillViewport/FillViewport.js.map +1 -0
- package/FillViewport/index.d.ts +1 -0
- package/FillViewport/index.js +1 -0
- package/FormComponent/Description.d.ts +7 -6
- package/FormComponent/ErrorMessage.d.ts +7 -6
- package/FormComponent/Label.d.ts +7 -6
- package/FormComponent/Note.d.ts +7 -6
- package/Grid/Grid.d.ts +25 -23
- package/Grid/Grid.js.map +1 -1
- package/Grid/Grid.stories.d.ts +1 -1
- package/Grid/Grid.stories.js.map +1 -1
- package/HeaderBar/HeaderBar.d.ts +7 -6
- package/HeaderBar/HeaderBar.stories.d.ts +1 -1
- package/HeaderBar/HeaderBar.stories.js.map +1 -1
- package/Heading/Heading.d.ts +8 -7
- package/Heading/Heading.stories.d.ts +1 -1
- package/Heading/Heading.stories.js.map +1 -1
- package/Icon/Icon.d.ts +9 -8
- package/Icon/Icon.stories.d.ts +1 -1
- package/Icon/Icon.stories.js.map +1 -1
- package/IconPicker/IconPicker.d.ts +7 -6
- package/IconPicker/IconPicker.stories.d.ts +1 -1
- package/IconPicker/IconPicker.stories.js.map +1 -1
- package/IconPicker/primitives/IconPickerPrimitive.d.ts +1 -1
- package/IconPicker/primitives/IconPickerPrimitive.js +1 -2
- package/IconPicker/primitives/IconPickerPrimitive.js.map +1 -1
- package/IconPicker/primitives/IconPickerPrimitive.stories.d.ts +1 -1
- package/IconPicker/primitives/IconPickerPrimitive.stories.js.map +1 -1
- package/IconPicker/primitives/components/IconPickerTrigger.d.ts +1 -1
- package/ImageEditor/AspectRatioPreview.d.ts +16 -0
- package/ImageEditor/AspectRatioPreview.js +26 -0
- package/ImageEditor/AspectRatioPreview.js.map +1 -0
- package/ImageEditor/CropHotspotEditor.d.ts +22 -0
- package/ImageEditor/CropHotspotEditor.js +402 -0
- package/ImageEditor/CropHotspotEditor.js.map +1 -0
- package/ImageEditor/ImageEditor.d.ts +18 -0
- package/ImageEditor/ImageEditor.js +151 -0
- package/ImageEditor/ImageEditor.js.map +1 -0
- package/ImageEditor/ImageEditor.stories.d.ts +6 -0
- package/ImageEditor/ImageEditor.stories.js +42 -0
- package/ImageEditor/ImageEditor.stories.js.map +1 -0
- package/ImageEditor/MetaFields.d.ts +12 -0
- package/ImageEditor/MetaFields.js +20 -0
- package/ImageEditor/MetaFields.js.map +1 -0
- package/ImageEditor/SectionLabel.d.ts +8 -0
- package/ImageEditor/SectionLabel.js +7 -0
- package/ImageEditor/SectionLabel.js.map +1 -0
- package/ImageEditor/geometry.d.ts +46 -0
- package/ImageEditor/geometry.js +126 -0
- package/ImageEditor/geometry.js.map +1 -0
- package/ImageEditor/index.d.ts +3 -0
- package/ImageEditor/index.js +3 -0
- package/ImageEditor/types.d.ts +52 -0
- package/ImageEditor/types.js +35 -0
- package/ImageEditor/types.js.map +1 -0
- package/Input/Input.d.ts +7 -6
- package/Input/Input.stories.d.ts +1 -1
- package/Input/Input.stories.js.map +1 -1
- package/Input/InputPrimitive.d.ts +9 -8
- package/Input/InputPrimitive.stories.d.ts +1 -1
- package/Input/InputPrimitive.stories.js.map +1 -1
- package/Label/Label.d.ts +8 -7
- package/Label/Label.stories.d.ts +1 -1
- package/Label/Label.stories.js.map +1 -1
- package/Label/components/LabelValue.d.ts +1 -1
- package/Link/Link.d.ts +3 -3
- package/Link/Link.js +1 -1
- package/Link/Link.js.map +1 -1
- package/Link/Link.stories.d.ts +1 -1
- package/Link/Link.stories.js.map +1 -1
- package/List/List.d.ts +8 -7
- package/List/List.stories.d.ts +1 -1
- package/List/List.stories.js.map +1 -1
- package/List/components/ListItem.d.ts +7 -6
- package/List/components/ListItemAction.d.ts +7 -6
- package/List/components/ListItemHandle.d.ts +7 -6
- package/List/components/ListItemIcon.d.ts +7 -6
- package/List/components/ListItemSeparator.d.ts +7 -6
- package/Loader/Loader.d.ts +9 -8
- package/Loader/Loader.stories.d.ts +1 -1
- package/Loader/Loader.stories.js.map +1 -1
- package/Loader/OverlayLoader.d.ts +7 -6
- package/Loader/OverlayLoader.stories.d.ts +1 -1
- package/Loader/OverlayLoader.stories.js.map +1 -1
- package/Markdown/Markdown.d.ts +47 -0
- package/Markdown/Markdown.js +17 -0
- package/Markdown/Markdown.js.map +1 -0
- package/Markdown/index.d.ts +1 -0
- package/Markdown/index.js +1 -0
- package/MultiAutoComplete/MultiAutoComplete.d.ts +7 -6
- package/MultiAutoComplete/MultiAutoComplete.stories.d.ts +1 -1
- package/MultiAutoComplete/MultiAutoComplete.stories.js.map +1 -1
- package/MultiAutoComplete/primitives/MultiAutoCompletePrimitive.d.ts +13 -6
- package/MultiAutoComplete/primitives/MultiAutoCompletePrimitive.js +1 -0
- package/MultiAutoComplete/primitives/MultiAutoCompletePrimitive.js.map +1 -1
- package/MultiAutoComplete/primitives/MultiAutoCompletePrimitive.stories.d.ts +1 -1
- package/MultiAutoComplete/primitives/MultiAutoCompletePrimitive.stories.js.map +1 -1
- package/MultiAutoComplete/primitives/presenters/MultiAutoCompletePresenterWithFreeInput.d.ts +3 -3
- package/MultiAutoComplete/primitives/useMultiAutoComplete.d.ts +3 -3
- package/MultiFilePicker/MultiFilePicker.d.ts +19 -18
- package/MultiFilePicker/MultiFilePicker.stories.d.ts +1 -1
- package/MultiFilePicker/MultiFilePicker.stories.js.map +1 -1
- package/MultiFilePicker/primitives/MultiFilePickerPrimitive.d.ts +19 -18
- package/MultiFilePicker/primitives/MultiFilePickerPrimitive.stories.d.ts +1 -1
- package/MultiFilePicker/primitives/MultiFilePickerPrimitive.stories.js.map +1 -1
- package/MultiSelect/MultiSelect.d.ts +7 -6
- package/MultiSelect/MultiSelect.stories.d.ts +1 -1
- package/MultiSelect/MultiSelect.stories.js.map +1 -1
- package/MultiSelect/primitives/MultiSelectPrimitive.d.ts +10 -6
- package/MultiSelect/primitives/MultiSelectPrimitive.js +12 -5
- package/MultiSelect/primitives/MultiSelectPrimitive.js.map +1 -1
- package/Popover/Popover.d.ts +7 -6
- package/Popover/Popover.stories.d.ts +8 -1
- package/Popover/Popover.stories.js +24 -1
- package/Popover/Popover.stories.js.map +1 -1
- package/Popover/primitives/PopoverPrimitive.d.ts +7 -7
- package/Popover/primitives/components/PopoverContent.js +6 -1
- package/Popover/primitives/components/PopoverContent.js.map +1 -1
- package/ProgressBar/ProgressBar.d.ts +7 -6
- package/ProgressBar/ProgressBar.stories.d.ts +1 -1
- package/ProgressBar/ProgressBar.stories.js.map +1 -1
- package/RadioGroup/RadioGroup.d.ts +7 -6
- package/RadioGroup/RadioGroup.stories.d.ts +1 -1
- package/RadioGroup/RadioGroup.stories.js.map +1 -1
- package/RadioGroup/primitives/Radio.d.ts +7 -6
- package/RadioGroup/primitives/RadioGroupPrimitive.d.ts +5 -1
- package/RadioGroup/primitives/RadioGroupPrimitive.stories.d.ts +1 -1
- package/RadioGroup/primitives/RadioGroupPrimitive.stories.js.map +1 -1
- package/RangeSlider/RangeSlider.d.ts +7 -6
- package/RangeSlider/RangeSlider.stories.d.ts +1 -1
- package/RangeSlider/RangeSlider.stories.js.map +1 -1
- package/RangeSlider/primitives/RangeSliderPrimitive.stories.d.ts +1 -1
- package/RangeSlider/primitives/RangeSliderPrimitive.stories.js.map +1 -1
- package/ScrollArea/ScrollArea.d.ts +16 -2
- package/ScrollArea/ScrollArea.js +25 -11
- package/ScrollArea/ScrollArea.js.map +1 -1
- package/ScrollArea/ScrollArea.stories.d.ts +1 -1
- package/ScrollArea/ScrollArea.stories.js.map +1 -1
- package/SegmentedControl/SegmentedControl.d.ts +11 -6
- package/SegmentedControl/SegmentedControl.js +6 -2
- package/SegmentedControl/SegmentedControl.js.map +1 -1
- package/SegmentedControl/SegmentedControl.stories.d.ts +5 -1
- package/SegmentedControl/SegmentedControl.stories.js +100 -2
- package/SegmentedControl/SegmentedControl.stories.js.map +1 -1
- package/SegmentedControl/SegmentedControlTab.d.ts +10 -0
- package/SegmentedControl/SegmentedControlTab.js +21 -0
- package/SegmentedControl/SegmentedControlTab.js.map +1 -0
- package/SegmentedControl/SegmentedControlTabs.d.ts +14 -0
- package/SegmentedControl/SegmentedControlTabs.js +71 -0
- package/SegmentedControl/SegmentedControlTabs.js.map +1 -0
- package/SegmentedControl/SegmentedControlTabsContext.d.ts +19 -0
- package/SegmentedControl/SegmentedControlTabsContext.js +11 -0
- package/SegmentedControl/SegmentedControlTabsContext.js.map +1 -0
- package/SegmentedControl/index.d.ts +2 -0
- package/SegmentedControl/index.js +2 -0
- package/SegmentedControl/primitives/SegmentedControlPrimitive.d.ts +6 -2
- package/SegmentedControl/primitives/SegmentedControlPrimitive.js +4 -3
- package/SegmentedControl/primitives/SegmentedControlPrimitive.js.map +1 -1
- package/SegmentedControl/primitives/SegmentedControlPrimitive.stories.d.ts +2 -1
- package/SegmentedControl/primitives/SegmentedControlPrimitive.stories.js +8 -1
- package/SegmentedControl/primitives/SegmentedControlPrimitive.stories.js.map +1 -1
- package/Select/Select.d.ts +7 -6
- package/Select/Select.stories.d.ts +1 -1
- package/Select/Select.stories.js.map +1 -1
- package/Select/primitives/SelectPrimitive.stories.d.ts +1 -1
- package/Select/primitives/SelectPrimitive.stories.js.map +1 -1
- package/Select/primitives/components/SelectContent.js +4 -6
- package/Select/primitives/components/SelectContent.js.map +1 -1
- package/Select/primitives/components/SelectTrigger.d.ts +2 -2
- package/Separator/Separator.d.ts +9 -8
- package/Separator/Separator.stories.d.ts +1 -1
- package/Separator/Separator.stories.js.map +1 -1
- package/Sidebar/Sidebar.d.ts +9 -6
- package/Sidebar/Sidebar.stories.d.ts +1 -1
- package/Sidebar/Sidebar.stories.js.map +1 -1
- package/Sidebar/components/SidebarContent.js +1 -1
- package/Sidebar/components/SidebarContent.js.map +1 -1
- package/Sidebar/components/SidebarIcon.d.ts +7 -6
- package/Sidebar/components/SidebarProvider.d.ts +4 -4
- package/Sidebar/components/SidebarRoot.js +1 -1
- package/Sidebar/components/SidebarRoot.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuGroup.d.ts +9 -8
- package/Sidebar/components/items/SidebarMenuItem.d.ts +13 -9
- package/Sidebar/components/items/SidebarMenuItem.js +3 -1
- package/Sidebar/components/items/SidebarMenuItem.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuItemBadge.d.ts +6 -0
- package/Sidebar/components/items/SidebarMenuItemBadge.js +7 -0
- package/Sidebar/components/items/SidebarMenuItemBadge.js.map +1 -0
- package/Sidebar/components/items/SidebarMenuItemIcon.d.ts +7 -6
- package/Sidebar/components/items/SidebarMenuLink.d.ts +12 -9
- package/Sidebar/components/items/SidebarMenuLink.js +3 -1
- package/Sidebar/components/items/SidebarMenuLink.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuProvider.d.ts +4 -4
- package/Sidebar/components/items/SidebarMenuRootButton.d.ts +1 -1
- package/Sidebar/components/items/SidebarMenuRootButton.js +8 -3
- package/Sidebar/components/items/SidebarMenuRootButton.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuRootItem.d.ts +9 -7
- package/Sidebar/components/items/SidebarMenuSubButton.d.ts +1 -1
- package/Sidebar/components/items/SidebarMenuSubButton.js +14 -6
- package/Sidebar/components/items/SidebarMenuSubButton.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuSubItem.js +3 -3
- package/Sidebar/components/items/SidebarMenuSubItem.js.map +1 -1
- package/Sidebar/components/items/SidebarMenuSubItemIndentation.js +2 -1
- package/Sidebar/components/items/SidebarMenuSubItemIndentation.js.map +1 -1
- package/Skeleton/Skeleton.d.ts +9 -7
- package/Skeleton/Skeleton.js +10 -4
- package/Skeleton/Skeleton.js.map +1 -1
- package/Skeleton/Skeleton.stories.d.ts +3 -1
- package/Skeleton/Skeleton.stories.js +28 -2
- package/Skeleton/Skeleton.stories.js.map +1 -1
- package/Slider/Slider.d.ts +7 -6
- package/Slider/Slider.stories.d.ts +1 -1
- package/Slider/Slider.stories.js.map +1 -1
- package/Slider/primitives/SliderPrimitive.stories.d.ts +1 -1
- package/Slider/primitives/SliderPrimitive.stories.js.map +1 -1
- package/SteppedProgress/SteppedProgress.d.ts +7 -6
- package/SteppedProgress/SteppedProgress.stories.d.ts +1 -1
- package/SteppedProgress/SteppedProgress.stories.js.map +1 -1
- package/SteppedProgress/SteppedProgressItem.d.ts +7 -6
- package/Switch/Switch.d.ts +10 -9
- package/Switch/Switch.js +21 -7
- package/Switch/Switch.js.map +1 -1
- package/Switch/Switch.stories.d.ts +1 -1
- package/Switch/Switch.stories.js.map +1 -1
- package/Switch/domains/SwitchItemDto.d.ts +1 -1
- package/Switch/primitives/SwitchPrimitive.d.ts +10 -6
- package/Switch/primitives/SwitchPrimitive.js +4 -3
- package/Switch/primitives/SwitchPrimitive.js.map +1 -1
- package/Switch/primitives/SwitchPrimitive.stories.d.ts +1 -1
- package/Switch/primitives/SwitchPrimitive.stories.js.map +1 -1
- package/Table/Table.d.ts +12 -10
- package/Table/components/Direction.d.ts +1 -1
- package/Tabs/Tabs.d.ts +14 -7
- package/Tabs/Tabs.js +32 -11
- package/Tabs/Tabs.js.map +1 -1
- package/Tabs/Tabs.mdx +27 -0
- package/Tabs/Tabs.stories.d.ts +2 -1
- package/Tabs/Tabs.stories.js +19 -1
- package/Tabs/Tabs.stories.js.map +1 -1
- package/Tabs/components/Content.d.ts +1 -1
- package/Tabs/components/List.d.ts +2 -2
- package/Tabs/components/Tab.d.ts +7 -6
- package/Tabs/components/Trigger.d.ts +3 -2
- package/Tabs/components/Trigger.js +8 -3
- package/Tabs/components/Trigger.js.map +1 -1
- package/Tag/Tag.d.ts +8 -7
- package/Tag/Tag.stories.d.ts +1 -1
- package/Tag/Tag.stories.js.map +1 -1
- package/Tags/Tags.d.ts +7 -6
- package/Tags/Tags.stories.d.ts +1 -1
- package/Tags/Tags.stories.js.map +1 -1
- package/Tags/primitives/TagsPrimitive.d.ts +7 -6
- package/Tags/primitives/TagsPrimitive.stories.d.ts +1 -1
- package/Tags/primitives/TagsPrimitive.stories.js.map +1 -1
- package/Text/Text.d.ts +8 -7
- package/Text/Text.stories.d.ts +1 -1
- package/Text/Text.stories.js.map +1 -1
- package/Textarea/Textarea.d.ts +7 -6
- package/Textarea/Textarea.stories.d.ts +1 -1
- package/Textarea/Textarea.stories.js.map +1 -1
- package/Textarea/TextareaPrimitive.d.ts +9 -8
- package/Textarea/TextareaPrimitive.stories.d.ts +1 -1
- package/Textarea/TextareaPrimitive.stories.js.map +1 -1
- package/TimeAgo/TimeAgo.stories.d.ts +1 -1
- package/TimeAgo/TimeAgo.stories.js.map +1 -1
- package/TimeAgo/getElapsedSeconds.js +3 -3
- package/TimeAgo/getElapsedSeconds.js.map +1 -1
- package/Toast/Toast.d.ts +7 -6
- package/Toast/components/ToastActions.d.ts +7 -6
- package/Toast/components/ToastDescription.d.ts +7 -6
- package/Toast/components/ToastTitle.d.ts +7 -6
- package/Toast/useToast.stories.d.ts +1 -1
- package/Toast/useToast.stories.js.map +1 -1
- package/Toggle/Toggle.d.ts +7 -6
- package/Toggle/Toggle.stories.d.ts +1 -1
- package/Toggle/Toggle.stories.js.map +1 -1
- package/Toggle/primitives/TogglePrimitive.d.ts +13 -9
- package/Toggle/primitives/TogglePrimitive.stories.d.ts +1 -1
- package/Toggle/primitives/TogglePrimitive.stories.js.map +1 -1
- package/ToggleGroup/ToggleGroup.d.ts +7 -6
- package/ToggleGroup/ToggleGroup.stories.d.ts +1 -1
- package/ToggleGroup/ToggleGroup.stories.js.map +1 -1
- package/ToggleGroup/domains/ToggleGroupItem.d.ts +3 -0
- package/ToggleGroup/domains/ToggleGroupItem.js +6 -1
- package/ToggleGroup/domains/ToggleGroupItem.js.map +1 -1
- package/ToggleGroup/domains/ToggleGroupItemFormatted.d.ts +1 -0
- package/ToggleGroup/domains/ToggleGroupItemFormatter.js +2 -1
- package/ToggleGroup/domains/ToggleGroupItemFormatter.js.map +1 -1
- package/ToggleGroup/domains/ToggleGroupItemParams.d.ts +1 -0
- package/ToggleGroup/primitives/ToggleGroupPrimitive.d.ts +13 -9
- package/ToggleGroup/primitives/ToggleGroupPrimitive.js +12 -3
- package/ToggleGroup/primitives/ToggleGroupPrimitive.js.map +1 -1
- package/ToggleGroup/primitives/ToggleGroupPrimitive.stories.d.ts +1 -1
- package/ToggleGroup/primitives/ToggleGroupPrimitive.stories.js.map +1 -1
- package/Tooltip/Tooltip.d.ts +7 -6
- package/Tooltip/Tooltip.stories.d.ts +1 -1
- package/Tooltip/Tooltip.stories.js.map +1 -1
- package/Tree/Tree.d.ts +7 -6
- package/Tree/Tree.stories.d.ts +1 -1
- package/Tree/Tree.stories.js.map +1 -1
- package/Tree/components/Item.d.ts +7 -6
- package/Tree/components/ItemCollapseTrigger.d.ts +7 -6
- package/Tree/components/ItemContent.d.ts +8 -6
- package/Tree/components/ItemDragHandle.d.ts +7 -6
- package/Tree/components/ItemIcon.d.ts +7 -6
- package/Tree/components/ItemPlaceholder.d.ts +7 -6
- package/Tree/components/ItemSubIndentation.d.ts +7 -6
- package/Tree/useTree.js +6 -2
- package/Tree/useTree.js.map +1 -1
- package/Widget/Widget.d.ts +8 -22
- package/Widget/Widget.stories.d.ts +1 -1
- package/Widget/Widget.stories.js.map +1 -1
- package/Widget/components/Icon.d.ts +7 -6
- package/Widget/components/WidgetAction.d.ts +8 -6
- package/Widget/components/WidgetContent.d.ts +5 -5
- package/exports/admin/ui.d.ts +3 -0
- package/exports/admin/ui.js +3 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useEscapeScrollLock.d.ts +13 -0
- package/hooks/useEscapeScrollLock.js +21 -0
- package/hooks/useEscapeScrollLock.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/package.json +33 -35
- package/theme.css +52 -0
- package/utils.js +53 -34
- package/utils.js.map +1 -1
package/DataTable/DataTable.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { ColumnSort, OnChangeFn, Row,
|
|
2
|
+
import type { ColumnSort, ColumnVisibilityState, OnChangeFn, Row, RowData, SortingState } from "@tanstack/react-table";
|
|
3
|
+
declare const features: {
|
|
4
|
+
columnResizingFeature: import("@tanstack/table-core").TableFeature;
|
|
5
|
+
columnSizingFeature: import("@tanstack/table-core").TableFeature;
|
|
6
|
+
columnVisibilityFeature: import("@tanstack/table-core").TableFeature;
|
|
7
|
+
rowSelectionFeature: import("@tanstack/table-core").TableFeature;
|
|
8
|
+
rowSortingFeature: import("@tanstack/table-core").TableFeature;
|
|
9
|
+
sortedRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
10
|
+
coreRowModel: (table: import("@tanstack/table-core").Table<any, any>) => () => import("@tanstack/table-core").RowModel<any, any>;
|
|
11
|
+
};
|
|
12
|
+
type Features = typeof features;
|
|
3
13
|
interface DataTableColumn<T> {
|
|
4
14
|
header?: string | number | React.JSX.Element;
|
|
5
15
|
cell?: (row: T) => string | number | React.JSX.Element | null;
|
|
@@ -18,13 +28,13 @@ type DataTableDefaultData = {
|
|
|
18
28
|
id: string;
|
|
19
29
|
$selectable?: boolean;
|
|
20
30
|
};
|
|
21
|
-
type DataTableRow<T> = Row<DataTableDefaultData & T>;
|
|
31
|
+
type DataTableRow<T extends RowData> = Row<Features, DataTableDefaultData & T>;
|
|
22
32
|
type DataTableSorting = SortingState;
|
|
23
33
|
type DataTableColumnSort = ColumnSort;
|
|
24
34
|
type OnDataTableSortingChange = OnChangeFn<DataTableSorting>;
|
|
25
|
-
type DataTableColumnVisibility =
|
|
35
|
+
type DataTableColumnVisibility = ColumnVisibilityState;
|
|
26
36
|
type OnDataTableColumnVisibilityChange = OnChangeFn<DataTableColumnVisibility>;
|
|
27
|
-
interface DataTableProps<TEntry> {
|
|
37
|
+
interface DataTableProps<TEntry extends RowData> {
|
|
28
38
|
/**
|
|
29
39
|
* Show or hide borders.
|
|
30
40
|
*/
|
|
@@ -52,7 +62,7 @@ interface DataTableProps<TEntry> {
|
|
|
52
62
|
/**
|
|
53
63
|
* Callback that is called to determine if the row is selectable.
|
|
54
64
|
*/
|
|
55
|
-
isRowSelectable?: (row: Row<TEntry>) => boolean;
|
|
65
|
+
isRowSelectable?: (row: Row<Features, TEntry>) => boolean;
|
|
56
66
|
/**
|
|
57
67
|
* Render the skeleton state while data are loading.
|
|
58
68
|
*/
|
|
@@ -86,23 +96,24 @@ interface DataTableProps<TEntry> {
|
|
|
86
96
|
*/
|
|
87
97
|
stickyHeader?: boolean;
|
|
88
98
|
}
|
|
89
|
-
declare const
|
|
90
|
-
|
|
99
|
+
declare const DecoratableDataTable: <T extends Record<string, any> & DataTableDefaultData>({ bordered, canSelectAllRows, columnVisibility, columns: initialColumns, data: initialData, initialSorting, isRowSelectable, loading, onColumnVisibilityChange, onSelectRow, onSortingChange, onToggleRow, selectedRows, sorting, stickyHeader }: DataTableProps<T>) => React.JSX.Element;
|
|
100
|
+
declare const DataTable: typeof DecoratableDataTable & {
|
|
101
|
+
original: typeof DecoratableDataTable;
|
|
91
102
|
originalName: string;
|
|
92
103
|
displayName: string;
|
|
93
104
|
} & {
|
|
94
|
-
original:
|
|
95
|
-
original:
|
|
105
|
+
original: typeof DecoratableDataTable & {
|
|
106
|
+
original: typeof DecoratableDataTable;
|
|
96
107
|
originalName: string;
|
|
97
108
|
displayName: string;
|
|
98
109
|
};
|
|
99
110
|
originalName: string;
|
|
100
111
|
displayName: string;
|
|
101
112
|
} & {
|
|
102
|
-
createDecorator: (decorator: import("@webiny/react-composition/types.js").ComponentDecorator<
|
|
103
|
-
original:
|
|
113
|
+
createDecorator: (decorator: import("@webiny/react-composition/types.js").ComponentDecorator<typeof DecoratableDataTable & {
|
|
114
|
+
original: typeof DecoratableDataTable;
|
|
104
115
|
originalName: string;
|
|
105
116
|
displayName: string;
|
|
106
117
|
}>) => (props: unknown) => React.JSX.Element;
|
|
107
118
|
};
|
|
108
|
-
export { DataTable, type DataTableProps, type DataTableColumn, type DataTableColumns, type DataTableDefaultData, type DataTableRow, type DataTableSorting, type DataTableColumnSort, type OnDataTableSortingChange, type DataTableColumnVisibility, type OnDataTableColumnVisibilityChange };
|
|
119
|
+
export { DataTable, type Features, type DataTableProps, type DataTableColumn, type DataTableColumns, type DataTableDefaultData, type DataTableRow, type DataTableSorting, type DataTableColumnSort, type OnDataTableSortingChange, type DataTableColumnVisibility, type OnDataTableColumnVisibilityChange };
|
package/DataTable/DataTable.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import react, { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { flexRender,
|
|
2
|
+
import { columnResizingFeature, columnSizingFeature, columnVisibilityFeature, createCoreRowModel, createSortedRowModel, flexRender, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
3
3
|
import { CheckboxPrimitive } from "../Checkbox/index.js";
|
|
4
4
|
import { Skeleton } from "../Skeleton/index.js";
|
|
5
5
|
import { Table } from "../Table/index.js";
|
|
6
6
|
import { ColumnSorter, ColumnsVisibility } from "./components/index.js";
|
|
7
7
|
import { cn, makeDecoratable } from "../utils.js";
|
|
8
|
+
const features = tableFeatures({
|
|
9
|
+
columnResizingFeature: columnResizingFeature,
|
|
10
|
+
columnSizingFeature: columnSizingFeature,
|
|
11
|
+
columnVisibilityFeature: columnVisibilityFeature,
|
|
12
|
+
rowSelectionFeature: rowSelectionFeature,
|
|
13
|
+
rowSortingFeature: rowSortingFeature,
|
|
14
|
+
sortedRowModel: createSortedRowModel(),
|
|
15
|
+
coreRowModel: createCoreRowModel()
|
|
16
|
+
});
|
|
8
17
|
const defineColumns = (columns, options)=>{
|
|
9
18
|
const { canSelectAllRows, onSelectRow, onToggleRow, loading } = options;
|
|
10
19
|
return useMemo(()=>{
|
|
@@ -158,7 +167,8 @@ const DecoratableDataTable = ({ bordered, canSelectAllRows = true, columnVisibil
|
|
|
158
167
|
onToggleRow,
|
|
159
168
|
loading
|
|
160
169
|
});
|
|
161
|
-
const table =
|
|
170
|
+
const table = useTable({
|
|
171
|
+
features: features,
|
|
162
172
|
columnResizeMode: "onChange",
|
|
163
173
|
columns,
|
|
164
174
|
data,
|
|
@@ -167,8 +177,6 @@ const DecoratableDataTable = ({ bordered, canSelectAllRows = true, columnVisibil
|
|
|
167
177
|
enableRowSelection: isRowSelectable,
|
|
168
178
|
enableSorting: !!onSortingChange,
|
|
169
179
|
enableSortingRemoval: false,
|
|
170
|
-
getCoreRowModel: getCoreRowModel(),
|
|
171
|
-
getSortedRowModel: getSortedRowModel(),
|
|
172
180
|
manualSorting: true,
|
|
173
181
|
onColumnVisibilityChange,
|
|
174
182
|
onRowSelectionChange,
|
|
@@ -181,9 +189,12 @@ const DecoratableDataTable = ({ bordered, canSelectAllRows = true, columnVisibil
|
|
|
181
189
|
});
|
|
182
190
|
const getColumnWidth = useCallback((column)=>{
|
|
183
191
|
if (!column.getCanResize()) return column.getSize();
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
|
|
192
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
193
|
+
const fixedTotal = visibleColumns.filter((col)=>!col.getCanResize()).reduce((total, col)=>total + col.getSize(), 0);
|
|
194
|
+
const resizableTotal = visibleColumns.filter((col)=>col.getCanResize()).reduce((total, col)=>total + col.getSize(), 0);
|
|
195
|
+
if (0 === resizableTotal) return column.getSize();
|
|
196
|
+
const available = Math.max(tableWidth - fixedTotal, 0);
|
|
197
|
+
return Math.ceil(column.getSize() * available / resizableTotal);
|
|
187
198
|
}, [
|
|
188
199
|
table,
|
|
189
200
|
tableWidth
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTable/DataTable.js","sources":["../../src/DataTable/DataTable.tsx"],"sourcesContent":["import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type {\n Cell,\n Column,\n ColumnDef,\n ColumnSort,\n OnChangeFn,\n Row,\n RowSelectionState,\n SortingState,\n VisibilityState\n} from \"@tanstack/react-table\";\nimport {\n flexRender,\n getCoreRowModel,\n getSortedRowModel,\n useReactTable\n} from \"@tanstack/react-table\";\nimport { CheckboxPrimitive } from \"~/Checkbox/index.js\";\nimport { Skeleton } from \"~/Skeleton/index.js\";\nimport { Table } from \"~/Table/index.js\";\nimport { ColumnSorter, ColumnsVisibility } from \"./components/index.js\";\nimport { cn, makeDecoratable } from \"~/utils.js\";\n\ninterface DataTableColumn<T> {\n /*\n * Column header component.\n */\n header?: string | number | React.JSX.Element;\n /*\n * Cell renderer, receives the full row and returns the value to render inside the cell.\n */\n cell?: (row: T) => string | number | React.JSX.Element | null;\n /*\n * Column size.\n */\n size?: number;\n /*\n * Should truncate?\n */\n truncate?: boolean;\n /*\n * Column class names.\n */\n className?: string;\n /*\n * Enable column sorting.\n */\n enableSorting?: boolean;\n /*\n * Enable column resizing.\n */\n enableResizing?: boolean;\n /*\n * Enable column visibility toggling.\n */\n enableHiding?: boolean;\n /*\n * Accessor key for the column data path.\n */\n accessorKey?: string;\n}\n\ntype DataTableColumns<T> = {\n [P in keyof T]?: DataTableColumn<T>;\n};\n\ntype DataTableDefaultData = {\n id: string;\n /*\n * Define if a specific row can be selected.\n */\n $selectable?: boolean;\n};\n\ntype DataTableRow<T> = Row<DataTableDefaultData & T>;\n\ntype DataTableSorting = SortingState;\n\ntype DataTableColumnSort = ColumnSort;\n\ntype OnDataTableSortingChange = OnChangeFn<DataTableSorting>;\n\ntype DataTableColumnVisibility = VisibilityState;\n\ntype OnDataTableColumnVisibilityChange = OnChangeFn<DataTableColumnVisibility>;\n\ninterface DataTableProps<TEntry> {\n /**\n * Show or hide borders.\n */\n bordered?: boolean;\n /**\n * Controls whether \"select all\" action is allowed.\n */\n canSelectAllRows?: boolean;\n /**\n * Columns definition.\n */\n columns: DataTableColumns<TEntry>;\n /**\n * The column visibility state.\n */\n columnVisibility?: DataTableColumnVisibility;\n /**\n * Callback that receives current column visibility state.\n */\n onColumnVisibilityChange?: OnDataTableColumnVisibilityChange;\n /**\n * Data to display into DataTable body.\n */\n data: TEntry[];\n /**\n * Callback that is called to determine if the row is selectable.\n */\n isRowSelectable?: (row: Row<TEntry>) => boolean;\n /**\n * Render the skeleton state while data are loading.\n */\n loading?: boolean;\n /**\n * Callback that receives the selected rows.\n */\n onSelectRow?: (rows: TEntry[]) => void;\n /**\n * Callback that receives the toggled row.\n */\n onToggleRow?: (row: TEntry) => void;\n /**\n * Callback that receives current sorting state.\n */\n onSortingChange?: OnDataTableSortingChange;\n /**\n * Selected rows.\n */\n selectedRows?: TEntry[];\n /**\n * Sorting state.\n */\n sorting?: DataTableSorting;\n /**\n * Initial sorting state.\n */\n initialSorting?: DataTableSorting;\n /**\n * Enable sticky header.\n */\n stickyHeader?: boolean;\n}\n\ninterface DefineColumnsOptions<TEntry> {\n canSelectAllRows: boolean;\n onSelectRow?: DataTableProps<TEntry>[\"onSelectRow\"];\n onToggleRow: DataTableProps<TEntry>[\"onToggleRow\"];\n loading: DataTableProps<TEntry>[\"loading\"];\n}\n\nconst defineColumns = <T,>(\n columns: DataTableProps<T>[\"columns\"],\n options: DefineColumnsOptions<T>\n): ColumnDef<T>[] => {\n const { canSelectAllRows, onSelectRow, onToggleRow, loading } = options;\n\n return useMemo(() => {\n const columnsList = Object.keys(columns).map(key => ({\n id: key,\n ...columns[key as keyof typeof columns]\n }));\n\n const defaults: ColumnDef<T>[] = columnsList.map(column => {\n const {\n accessorKey,\n cell,\n className,\n enableHiding = true,\n enableResizing = true,\n enableSorting = false,\n header,\n truncate = true,\n id,\n size = 100\n } = column;\n\n return {\n id,\n accessorKey: accessorKey || id,\n header: () => header,\n cell: props => {\n if (cell && typeof cell === \"function\") {\n return cell(props.row.original);\n } else {\n // Automatically convert any cell value to a string for rendering,\n // ensuring the table displays values correctly. This aligns with React's\n // rendering, which expects JSX, strings or null.\n // https://github.com/TanStack/table/issues/1042\n return props.getValue() ? String(props.getValue()) : null;\n }\n },\n enableSorting,\n meta: {\n className,\n truncate\n },\n enableResizing,\n size,\n enableHiding\n };\n });\n\n let columnsDefs = defaults;\n const firstColumn = defaults[0];\n const isSelectable = onToggleRow || onSelectRow;\n\n if (isSelectable && firstColumn) {\n columnsDefs = [\n {\n ...firstColumn,\n accessorKey: firstColumn.id as string,\n header: props => {\n if (!props) {\n return null;\n }\n\n return (\n <div className={\"flex items-center gap-xl\"}>\n <CheckboxPrimitive\n indeterminate={props.table.getIsSomeRowsSelected()}\n checked={props.table.getIsAllRowsSelected()}\n onChange={props.table.toggleAllPageRowsSelected}\n aria-label=\"Select all\"\n disabled={!canSelectAllRows}\n onClick={e => e.stopPropagation()}\n />\n {firstColumn.header\n ? React.createElement(firstColumn.header, props)\n : null}\n </div>\n );\n },\n cell: props => {\n if (!props) {\n return null;\n }\n return (\n <div className={\"flex items-center gap-xl\"}>\n <CheckboxPrimitive\n checked={props.row.getIsSelected()}\n onChange={value => props.row.toggleSelected(!!value)}\n disabled={!props.row.getCanSelect()}\n aria-label=\"Select row\"\n className={cn(!props.row.getCanSelect() ? \"invisible\" : \"\")}\n />\n {firstColumn.cell\n ? React.createElement(firstColumn.cell, props)\n : null}\n </div>\n );\n }\n },\n ...defaults.slice(1)\n ];\n }\n\n return columnsDefs.map(column => {\n if (loading) {\n return {\n ...column,\n cell: () => <Skeleton type={\"text\"} size={\"md\"} />\n };\n }\n\n return column;\n });\n }, [columns, onSelectRow, onToggleRow, loading]);\n};\n\nconst typedMemo: <T>(component: T) => T = memo;\n\ninterface TableCellProps<T> {\n cell: Cell<T, unknown>;\n getColumnWidth: (column: Column<T>) => number;\n}\n\nconst TableCell = <T,>({ cell, getColumnWidth }: TableCellProps<T>) => {\n const width = getColumnWidth(cell.column);\n\n return (\n <Table.Cell {...cell.column.columnDef.meta} style={{ width, maxWidth: width }}>\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </Table.Cell>\n );\n};\n\nconst MemoTableCell = typedMemo(TableCell);\n\ninterface TableRowProps<T> {\n selected: boolean;\n cells: Cell<T, unknown>[];\n getColumnWidth: (column: Column<T>) => number;\n}\n\nconst TableRow = <T,>({ selected, cells, getColumnWidth }: TableRowProps<T>) => {\n return (\n <Table.Row selected={selected}>\n {cells.map(cell => (\n <MemoTableCell<T> key={cell.id} cell={cell} getColumnWidth={getColumnWidth} />\n ))}\n </Table.Row>\n );\n};\n\nconst MemoTableRow = typedMemo(TableRow);\n\n/**\n * Empty array must be defined outside the React component so it does not force rerendering of the DataTable\n */\nconst emptyArray = Array(10).fill({});\n\nconst DecoratableDataTable = <T extends Record<string, any> & DataTableDefaultData>({\n bordered,\n canSelectAllRows = true,\n columnVisibility,\n columns: initialColumns,\n data: initialData,\n initialSorting,\n isRowSelectable,\n loading,\n onColumnVisibilityChange,\n onSelectRow,\n onSortingChange,\n onToggleRow,\n selectedRows = [],\n sorting,\n stickyHeader\n}: DataTableProps<T>) => {\n const tableRef = useRef<HTMLDivElement>(null);\n const [tableWidth, setTableWidth] = useState(1);\n\n const data = loading ? emptyArray : initialData;\n\n useEffect(() => {\n const updateElementWidth = () => {\n if (tableRef.current) {\n const width = tableRef.current.clientWidth;\n setTableWidth(width);\n }\n };\n\n updateElementWidth();\n\n window.addEventListener(\"resize\", updateElementWidth);\n\n return () => {\n window.removeEventListener(\"resize\", updateElementWidth);\n };\n }, [tableRef.current]);\n\n const rowSelection = useMemo(() => {\n return selectedRows.reduce<RowSelectionState>((acc, item) => {\n const recordIndex = data.findIndex(rec => rec.id === item.id);\n return { ...acc, [recordIndex]: true };\n }, {});\n }, [selectedRows, data]);\n\n const onRowSelectionChange: OnChangeFn<RowSelectionState> = updater => {\n const newSelection = typeof updater === \"function\" ? updater(rowSelection) : updater;\n\n /**\n * `@tanstack/react-table` isn't telling us what row was selected or deselected. It simply gives us\n * the new selection state (an object with row indexes that are currently selected).\n *\n * To figure out what row was toggled, we need to calculate the difference between the old selection\n * and the new selection. What we're doing here is:\n * - find all items that were present in the previous selection, but are no longer present in the new selection\n * - find all items that are present in the new selection, but were not present in the previous selection\n */\n const toggledRows = [\n ...Object.keys(rowSelection).filter(x => !(x in newSelection)),\n ...Object.keys(newSelection).filter(x => !(x in rowSelection))\n ];\n\n // If the difference is only 1 item, and `onToggleRow` is available, execute that.\n if (toggledRows.length === 1 && typeof onToggleRow === \"function\") {\n onToggleRow(data[parseInt(toggledRows[0])]);\n return;\n } else if (typeof onSelectRow === \"function\") {\n const selection = Object.keys(newSelection).map(key => data[parseInt(key)]);\n onSelectRow(selection);\n }\n };\n\n const tableSorting = useMemo(() => {\n if (!Array.isArray(sorting) || !sorting.length) {\n return initialSorting;\n }\n return sorting;\n }, [sorting]);\n\n const columns = defineColumns(initialColumns, {\n canSelectAllRows,\n onSelectRow,\n onToggleRow,\n loading\n });\n\n const table = useReactTable<T>({\n columnResizeMode: \"onChange\",\n columns,\n data,\n enableColumnResizing: true,\n enableHiding: !!onColumnVisibilityChange,\n enableRowSelection: isRowSelectable,\n enableSorting: !!onSortingChange,\n enableSortingRemoval: false,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n manualSorting: true,\n onColumnVisibilityChange,\n onRowSelectionChange,\n onSortingChange,\n state: {\n columnVisibility,\n rowSelection,\n sorting: tableSorting\n }\n });\n\n const getColumnWidth = useCallback(\n (column: Column<T>): number => {\n if (!column.getCanResize()) {\n return column.getSize();\n }\n\n const tableSize = table.getTotalSize();\n const columnSize = column.getSize();\n\n return Math.ceil((columnSize * tableWidth) / tableSize);\n },\n [table, tableWidth]\n );\n\n /**\n * Had to memoize the rows to avoid browser freeze.\n */\n const tableRows = useMemo(() => {\n return table.getRowModel().rows;\n }, [table, data, columns]);\n\n return (\n <div ref={tableRef}>\n <Table bordered={bordered} sticky={stickyHeader}>\n <Table.Header sticky={stickyHeader}>\n {table.getHeaderGroups().map(headerGroup => (\n <Table.Row key={headerGroup.id}>\n {headerGroup.headers.map((header, index) => {\n const isLastCell = index === headerGroup.headers.length - 1;\n const width = getColumnWidth(header.column);\n\n return (\n <Table.Head\n key={header.id}\n {...header.column.columnDef.meta}\n colSpan={header.colSpan}\n style={{ width, maxWidth: width }}\n >\n {header.isPlaceholder ? null : (\n <ColumnSorter\n onClick={header.column.getToggleSortingHandler()}\n sortable={header.column.getCanSort()}\n >\n <div\n className={cn({\n \"w-full overflow-hidden whitespace-nowrap\": true,\n truncate: !isLastCell\n })}\n >\n {flexRender(\n header.column.columnDef.header,\n header.getContext()\n )}\n </div>\n <Table.Direction\n direction={header.column.getIsSorted() || null}\n />\n {isLastCell && (\n <div className={\"h-md\"}>\n <ColumnsVisibility\n columns={table.getAllColumns()}\n />\n </div>\n )}\n </ColumnSorter>\n )}\n {header.column.getCanResize() && (\n <Table.Resizer\n onMouseDown={header.getResizeHandler()}\n onTouchStart={header.getResizeHandler()}\n isResizing={header.column.getIsResizing()}\n />\n )}\n </Table.Head>\n );\n })}\n </Table.Row>\n ))}\n </Table.Header>\n <Table.Body>\n {tableRows.map(row => {\n const id = row.original.id || row.id;\n return (\n <MemoTableRow<T>\n key={id}\n cells={row.getVisibleCells()}\n selected={row.getIsSelected()}\n getColumnWidth={getColumnWidth}\n />\n );\n })}\n </Table.Body>\n </Table>\n </div>\n );\n};\n\nconst DataTable = makeDecoratable(\"DataTable\", DecoratableDataTable);\n\nexport {\n DataTable,\n type DataTableProps,\n type DataTableColumn,\n type DataTableColumns,\n type DataTableDefaultData,\n type DataTableRow,\n type DataTableSorting,\n type DataTableColumnSort,\n type OnDataTableSortingChange,\n type DataTableColumnVisibility,\n type OnDataTableColumnVisibilityChange\n};\n"],"names":["defineColumns","columns","options","canSelectAllRows","onSelectRow","onToggleRow","loading","useMemo","columnsList","Object","key","defaults","column","accessorKey","cell","className","enableHiding","enableResizing","enableSorting","header","truncate","id","size","props","String","columnsDefs","firstColumn","isSelectable","CheckboxPrimitive","e","React","value","cn","Skeleton","typedMemo","memo","TableCell","getColumnWidth","width","Table","flexRender","MemoTableCell","TableRow","selected","cells","MemoTableRow","emptyArray","Array","DecoratableDataTable","bordered","columnVisibility","initialColumns","initialData","initialSorting","isRowSelectable","onColumnVisibilityChange","onSortingChange","selectedRows","sorting","stickyHeader","tableRef","useRef","tableWidth","setTableWidth","useState","data","useEffect","updateElementWidth","window","rowSelection","acc","item","recordIndex","rec","onRowSelectionChange","updater","newSelection","toggledRows","x","parseInt","selection","tableSorting","table","useReactTable","getCoreRowModel","getSortedRowModel","useCallback","tableSize","columnSize","Math","tableRows","headerGroup","index","isLastCell","ColumnSorter","ColumnsVisibility","row","DataTable","makeDecoratable"],"mappings":";;;;;;;AA6JA,MAAMA,gBAAgB,CAClBC,SACAC;IAEA,MAAM,EAAEC,gBAAgB,EAAEC,WAAW,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGJ;IAEhE,OAAOK,QAAQ;QACX,MAAMC,cAAcC,OAAO,IAAI,CAACR,SAAS,GAAG,CAACS,CAAAA,M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AK3D,qBAIZ,oBAACoB,MAAM,IAAI,QACNmD,UAAU,GAAG,CAACM,CAAAA;QACX,MAAM3E,KAAK2E,IAAI,QAAQ,CAAC,EAAE,IAAIA,IAAI,EAAE;QACpC,OAAO,WAAP,GACI,oBAACnD,cAAYA;YACT,KAAKxB;YACL,OAAO2E,IAAI,eAAe;YAC1B,UAAUA,IAAI,aAAa;YAC3B,gBAAgB3D;;IAG5B;AAKpB;AAEA,MAAM4D,YAAYC,gBAAgB,aAAalD"}
|
|
1
|
+
{"version":3,"file":"DataTable/DataTable.js","sources":["../../src/DataTable/DataTable.tsx"],"sourcesContent":["import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type {\n Cell,\n Column,\n ColumnDef,\n ColumnSort,\n ColumnVisibilityState,\n OnChangeFn,\n Row,\n RowData,\n RowSelectionState,\n SortingState\n} from \"@tanstack/react-table\";\nimport {\n columnResizingFeature,\n columnSizingFeature,\n columnVisibilityFeature,\n createCoreRowModel,\n createSortedRowModel,\n flexRender,\n rowSelectionFeature,\n rowSortingFeature,\n tableFeatures,\n useTable\n} from \"@tanstack/react-table\";\nimport { CheckboxPrimitive } from \"~/Checkbox/index.js\";\nimport { Skeleton } from \"~/Skeleton/index.js\";\nimport { Table } from \"~/Table/index.js\";\nimport { ColumnSorter, ColumnsVisibility } from \"./components/index.js\";\nimport { cn, makeDecoratable } from \"~/utils.js\";\n\nconst features = tableFeatures({\n columnResizingFeature,\n columnSizingFeature,\n columnVisibilityFeature,\n rowSelectionFeature,\n rowSortingFeature,\n sortedRowModel: createSortedRowModel(),\n coreRowModel: createCoreRowModel()\n});\n\ntype Features = typeof features;\n\ninterface DataTableColumn<T> {\n /*\n * Column header component.\n */\n header?: string | number | React.JSX.Element;\n /*\n * Cell renderer, receives the full row and returns the value to render inside the cell.\n */\n cell?: (row: T) => string | number | React.JSX.Element | null;\n /*\n * Column size.\n */\n size?: number;\n /*\n * Should truncate?\n */\n truncate?: boolean;\n /*\n * Column class names.\n */\n className?: string;\n /*\n * Enable column sorting.\n */\n enableSorting?: boolean;\n /*\n * Enable column resizing.\n */\n enableResizing?: boolean;\n /*\n * Enable column visibility toggling.\n */\n enableHiding?: boolean;\n /*\n * Accessor key for the column data path.\n */\n accessorKey?: string;\n}\n\ntype DataTableColumns<T> = {\n [P in keyof T]?: DataTableColumn<T>;\n};\n\ntype DataTableDefaultData = {\n id: string;\n /*\n * Define if a specific row can be selected.\n */\n $selectable?: boolean;\n};\n\ntype DataTableRow<T extends RowData> = Row<Features, DataTableDefaultData & T>;\n\ntype DataTableSorting = SortingState;\n\ntype DataTableColumnSort = ColumnSort;\n\ntype OnDataTableSortingChange = OnChangeFn<DataTableSorting>;\n\ntype DataTableColumnVisibility = ColumnVisibilityState;\n\ntype OnDataTableColumnVisibilityChange = OnChangeFn<DataTableColumnVisibility>;\n\ninterface DataTableProps<TEntry extends RowData> {\n /**\n * Show or hide borders.\n */\n bordered?: boolean;\n /**\n * Controls whether \"select all\" action is allowed.\n */\n canSelectAllRows?: boolean;\n /**\n * Columns definition.\n */\n columns: DataTableColumns<TEntry>;\n /**\n * The column visibility state.\n */\n columnVisibility?: DataTableColumnVisibility;\n /**\n * Callback that receives current column visibility state.\n */\n onColumnVisibilityChange?: OnDataTableColumnVisibilityChange;\n /**\n * Data to display into DataTable body.\n */\n data: TEntry[];\n /**\n * Callback that is called to determine if the row is selectable.\n */\n isRowSelectable?: (row: Row<Features, TEntry>) => boolean;\n /**\n * Render the skeleton state while data are loading.\n */\n loading?: boolean;\n /**\n * Callback that receives the selected rows.\n */\n onSelectRow?: (rows: TEntry[]) => void;\n /**\n * Callback that receives the toggled row.\n */\n onToggleRow?: (row: TEntry) => void;\n /**\n * Callback that receives current sorting state.\n */\n onSortingChange?: OnDataTableSortingChange;\n /**\n * Selected rows.\n */\n selectedRows?: TEntry[];\n /**\n * Sorting state.\n */\n sorting?: DataTableSorting;\n /**\n * Initial sorting state.\n */\n initialSorting?: DataTableSorting;\n /**\n * Enable sticky header.\n */\n stickyHeader?: boolean;\n}\n\ninterface DefineColumnsOptions<TEntry extends RowData> {\n canSelectAllRows: boolean;\n onSelectRow?: DataTableProps<TEntry>[\"onSelectRow\"];\n onToggleRow: DataTableProps<TEntry>[\"onToggleRow\"];\n loading: DataTableProps<TEntry>[\"loading\"];\n}\n\nconst defineColumns = <T extends RowData>(\n columns: DataTableProps<T>[\"columns\"],\n options: DefineColumnsOptions<T>\n): ColumnDef<Features, T>[] => {\n const { canSelectAllRows, onSelectRow, onToggleRow, loading } = options;\n\n return useMemo(() => {\n const columnsList = Object.keys(columns).map(key => ({\n id: key,\n ...columns[key as keyof typeof columns]\n }));\n\n const defaults: ColumnDef<Features, T>[] = columnsList.map(column => {\n const {\n accessorKey,\n cell,\n className,\n enableHiding = true,\n enableResizing = true,\n enableSorting = false,\n header,\n truncate = true,\n id,\n size = 100\n } = column;\n\n return {\n id,\n accessorKey: accessorKey || id,\n header: () => header,\n cell: props => {\n if (cell && typeof cell === \"function\") {\n return cell(props.row.original);\n } else {\n // Automatically convert any cell value to a string for rendering,\n // ensuring the table displays values correctly. This aligns with React's\n // rendering, which expects JSX, strings or null.\n // https://github.com/TanStack/table/issues/1042\n return props.getValue() ? String(props.getValue()) : null;\n }\n },\n enableSorting,\n meta: {\n className,\n truncate\n },\n enableResizing,\n size,\n enableHiding\n };\n });\n\n let columnsDefs = defaults;\n const firstColumn = defaults[0];\n const isSelectable = onToggleRow || onSelectRow;\n\n if (isSelectable && firstColumn) {\n columnsDefs = [\n {\n ...firstColumn,\n accessorKey: firstColumn.id as string,\n header: props => {\n if (!props) {\n return null;\n }\n\n return (\n <div className={\"flex items-center gap-xl\"}>\n <CheckboxPrimitive\n indeterminate={props.table.getIsSomeRowsSelected()}\n checked={props.table.getIsAllRowsSelected()}\n onChange={props.table.toggleAllPageRowsSelected}\n aria-label=\"Select all\"\n disabled={!canSelectAllRows}\n onClick={e => e.stopPropagation()}\n />\n {firstColumn.header\n ? React.createElement(firstColumn.header, props)\n : null}\n </div>\n );\n },\n cell: props => {\n if (!props) {\n return null;\n }\n return (\n <div className={\"flex items-center gap-xl\"}>\n <CheckboxPrimitive\n checked={props.row.getIsSelected()}\n onChange={value => props.row.toggleSelected(!!value)}\n disabled={!props.row.getCanSelect()}\n aria-label=\"Select row\"\n className={cn(!props.row.getCanSelect() ? \"invisible\" : \"\")}\n />\n {firstColumn.cell\n ? React.createElement(firstColumn.cell, props)\n : null}\n </div>\n );\n }\n },\n ...defaults.slice(1)\n ];\n }\n\n return columnsDefs.map(column => {\n if (loading) {\n return {\n ...column,\n cell: () => <Skeleton type={\"text\"} size={\"md\"} />\n };\n }\n\n return column;\n });\n }, [columns, onSelectRow, onToggleRow, loading]);\n};\n\nconst typedMemo: <T>(component: T) => T = memo;\n\ninterface TableCellProps<T extends RowData> {\n cell: Cell<Features, T, unknown>;\n getColumnWidth: (column: Column<Features, T>) => number;\n}\n\nconst TableCell = <T extends RowData>({ cell, getColumnWidth }: TableCellProps<T>) => {\n const width = getColumnWidth(cell.column);\n\n return (\n <Table.Cell {...cell.column.columnDef.meta} style={{ width, maxWidth: width }}>\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </Table.Cell>\n );\n};\n\nconst MemoTableCell = typedMemo(TableCell);\n\ninterface TableRowProps<T extends RowData> {\n selected: boolean;\n cells: Cell<Features, T, unknown>[];\n getColumnWidth: (column: Column<Features, T>) => number;\n}\n\nconst TableRow = <T extends RowData>({ selected, cells, getColumnWidth }: TableRowProps<T>) => {\n return (\n <Table.Row selected={selected}>\n {cells.map(cell => (\n <MemoTableCell<T> key={cell.id} cell={cell} getColumnWidth={getColumnWidth} />\n ))}\n </Table.Row>\n );\n};\n\nconst MemoTableRow = typedMemo(TableRow);\n\n/**\n * Empty array must be defined outside the React component so it does not force rerendering of the DataTable\n */\nconst emptyArray = Array(10).fill({});\n\nconst DecoratableDataTable = <T extends Record<string, any> & DataTableDefaultData>({\n bordered,\n canSelectAllRows = true,\n columnVisibility,\n columns: initialColumns,\n data: initialData,\n initialSorting,\n isRowSelectable,\n loading,\n onColumnVisibilityChange,\n onSelectRow,\n onSortingChange,\n onToggleRow,\n selectedRows = [],\n sorting,\n stickyHeader\n}: DataTableProps<T>) => {\n const tableRef = useRef<HTMLDivElement>(null);\n const [tableWidth, setTableWidth] = useState(1);\n\n const data = loading ? emptyArray : initialData;\n\n useEffect(() => {\n const updateElementWidth = () => {\n if (tableRef.current) {\n const width = tableRef.current.clientWidth;\n setTableWidth(width);\n }\n };\n\n updateElementWidth();\n\n window.addEventListener(\"resize\", updateElementWidth);\n\n return () => {\n window.removeEventListener(\"resize\", updateElementWidth);\n };\n }, [tableRef.current]);\n\n const rowSelection = useMemo(() => {\n return selectedRows.reduce<RowSelectionState>((acc, item) => {\n const recordIndex = data.findIndex(rec => rec.id === item.id);\n return { ...acc, [recordIndex]: true };\n }, {});\n }, [selectedRows, data]);\n\n const onRowSelectionChange: OnChangeFn<RowSelectionState> = updater => {\n const newSelection = typeof updater === \"function\" ? updater(rowSelection) : updater;\n\n /**\n * `@tanstack/react-table` isn't telling us what row was selected or deselected. It simply gives us\n * the new selection state (an object with row indexes that are currently selected).\n *\n * To figure out what row was toggled, we need to calculate the difference between the old selection\n * and the new selection. What we're doing here is:\n * - find all items that were present in the previous selection, but are no longer present in the new selection\n * - find all items that are present in the new selection, but were not present in the previous selection\n */\n const toggledRows = [\n ...Object.keys(rowSelection).filter(x => !(x in newSelection)),\n ...Object.keys(newSelection).filter(x => !(x in rowSelection))\n ];\n\n // If the difference is only 1 item, and `onToggleRow` is available, execute that.\n if (toggledRows.length === 1 && typeof onToggleRow === \"function\") {\n onToggleRow(data[parseInt(toggledRows[0])]);\n return;\n } else if (typeof onSelectRow === \"function\") {\n const selection = Object.keys(newSelection).map(key => data[parseInt(key)]);\n onSelectRow(selection);\n }\n };\n\n const tableSorting = useMemo(() => {\n if (!Array.isArray(sorting) || !sorting.length) {\n return initialSorting;\n }\n return sorting;\n }, [sorting]);\n\n const columns = defineColumns(initialColumns, {\n canSelectAllRows,\n onSelectRow,\n onToggleRow,\n loading\n });\n\n const table = useTable<typeof features, T>({\n features,\n columnResizeMode: \"onChange\",\n columns,\n data,\n enableColumnResizing: true,\n enableHiding: !!onColumnVisibilityChange,\n enableRowSelection: isRowSelectable,\n enableSorting: !!onSortingChange,\n enableSortingRemoval: false,\n manualSorting: true,\n onColumnVisibilityChange,\n onRowSelectionChange,\n onSortingChange,\n state: {\n columnVisibility,\n rowSelection,\n sorting: tableSorting\n }\n });\n\n const getColumnWidth = useCallback(\n (column: Column<Features, T>): number => {\n // Non-resizable columns (e.g. row-selection, actions) keep their fixed size.\n if (!column.getCanResize()) {\n return column.getSize();\n }\n\n /**\n * Resizable columns share the space left after the fixed columns, proportionally to\n * their own size. This makes the table always fill the full container width — even when\n * columns are hidden — so trailing content (e.g. the columns-visibility cog) stays\n * flush right instead of drifting left as columns are removed.\n */\n const visibleColumns = table.getVisibleLeafColumns();\n const fixedTotal = visibleColumns\n .filter(col => !col.getCanResize())\n .reduce((total, col) => total + col.getSize(), 0);\n const resizableTotal = visibleColumns\n .filter(col => col.getCanResize())\n .reduce((total, col) => total + col.getSize(), 0);\n\n if (resizableTotal === 0) {\n return column.getSize();\n }\n\n const available = Math.max(tableWidth - fixedTotal, 0);\n\n return Math.ceil((column.getSize() * available) / resizableTotal);\n },\n [table, tableWidth]\n );\n\n /**\n * Had to memoize the rows to avoid browser freeze.\n */\n const tableRows = useMemo(() => {\n return table.getRowModel().rows;\n }, [table, data, columns]);\n\n return (\n <div ref={tableRef}>\n <Table bordered={bordered} sticky={stickyHeader}>\n <Table.Header sticky={stickyHeader}>\n {table.getHeaderGroups().map(headerGroup => (\n <Table.Row key={headerGroup.id}>\n {headerGroup.headers.map((header, index) => {\n const isLastCell = index === headerGroup.headers.length - 1;\n const width = getColumnWidth(header.column);\n\n return (\n <Table.Head\n key={header.id}\n {...header.column.columnDef.meta}\n colSpan={header.colSpan}\n style={{ width, maxWidth: width }}\n >\n {header.isPlaceholder ? null : (\n <ColumnSorter\n onClick={header.column.getToggleSortingHandler()}\n sortable={header.column.getCanSort()}\n >\n <div\n className={cn({\n \"w-full overflow-hidden whitespace-nowrap\": true,\n truncate: !isLastCell\n })}\n >\n {flexRender(\n header.column.columnDef.header,\n header.getContext()\n )}\n </div>\n <Table.Direction\n direction={header.column.getIsSorted() || null}\n />\n {isLastCell && (\n <div className={\"h-md\"}>\n <ColumnsVisibility\n columns={table.getAllColumns()}\n />\n </div>\n )}\n </ColumnSorter>\n )}\n {header.column.getCanResize() && (\n <Table.Resizer\n onMouseDown={header.getResizeHandler()}\n onTouchStart={header.getResizeHandler()}\n isResizing={header.column.getIsResizing()}\n />\n )}\n </Table.Head>\n );\n })}\n </Table.Row>\n ))}\n </Table.Header>\n <Table.Body>\n {tableRows.map(row => {\n const id = row.original.id || row.id;\n return (\n <MemoTableRow<T>\n key={id}\n cells={row.getVisibleCells()}\n selected={row.getIsSelected()}\n getColumnWidth={getColumnWidth}\n />\n );\n })}\n </Table.Body>\n </Table>\n </div>\n );\n};\n\nconst DataTable = makeDecoratable(\"DataTable\", DecoratableDataTable);\n\nexport {\n DataTable,\n type Features,\n type DataTableProps,\n type DataTableColumn,\n type DataTableColumns,\n type DataTableDefaultData,\n type DataTableRow,\n type DataTableSorting,\n type DataTableColumnSort,\n type OnDataTableSortingChange,\n type DataTableColumnVisibility,\n type OnDataTableColumnVisibilityChange\n};\n"],"names":["features","tableFeatures","columnResizingFeature","columnSizingFeature","columnVisibilityFeature","rowSelectionFeature","rowSortingFeature","createSortedRowModel","createCoreRowModel","defineColumns","columns","options","canSelectAllRows","onSelectRow","onToggleRow","loading","useMemo","columnsList","Object","key","defaults","column","accessorKey","cell","className","enableHiding","enableResizing","enableSorting","header","truncate","id","size","props","String","columnsDefs","firstColumn","isSelectable","CheckboxPrimitive","e","React","value","cn","Skeleton","typedMemo","memo","TableCell","getColumnWidth","width","Table","flexRender","MemoTableCell","TableRow","selected","cells","MemoTableRow","emptyArray","Array","DecoratableDataTable","bordered","columnVisibility","initialColumns","initialData","initialSorting","isRowSelectable","onColumnVisibilityChange","onSortingChange","selectedRows","sorting","stickyHeader","tableRef","useRef","tableWidth","setTableWidth","useState","data","useEffect","updateElementWidth","window","rowSelection","acc","item","recordIndex","rec","onRowSelectionChange","updater","newSelection","toggledRows","x","parseInt","selection","tableSorting","table","useTable","useCallback","visibleColumns","fixedTotal","col","total","resizableTotal","available","Math","tableRows","headerGroup","index","isLastCell","ColumnSorter","ColumnsVisibility","row","DataTable","makeDecoratable"],"mappings":";;;;;;;AA+BA,MAAMA,WAAWC,cAAc;IAC3BC,uBAAqBA;IACrBC,qBAAmBA;IACnBC,yBAAuBA;IACvBC,qBAAmBA;IACnBC,mBAAiBA;IACjB,gBAAgBC;IAChB,cAAcC;AAClB;AAyIA,MAAMC,gBAAgB,CAClBC,SACAC;IAEA,MAAM,EAAEC,gBAAgB,EAAEC,WAAW,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGJ;IAEhE,OAAOK,QAAQ;QACX,MAAMC,cAAcC,OAAO,IAAI,CAACR,SAAS,GAAG,CAACS,CAAAA,MAAQ;gBACjD,IAAIA;gBACJ,GAAGT,OAAO,CAACS,IAA4B;YAC3C;QAEA,MAAMC,WAAqCH,YAAY,GAAG,CAACI,CAAAA;YACvD,MAAM,EACFC,WAAW,EACXC,IAAI,EACJC,SAAS,EACTC,eAAe,IAAI,EACnBC,iBAAiB,IAAI,EACrBC,gBAAgB,KAAK,EACrBC,MAAM,EACNC,WAAW,IAAI,EACfC,EAAE,EACFC,OAAO,GAAG,EACb,GAAGV;YAEJ,OAAO;gBACHS;gBACA,aAAaR,eAAeQ;gBAC5B,QAAQ,IAAMF;gBACd,MAAMI,CAAAA;oBACF,IAAIT,QAAQ,AAAgB,cAAhB,OAAOA,MACf,OAAOA,KAAKS,MAAM,GAAG,CAAC,QAAQ;oBAM9B,OAAOA,MAAM,QAAQ,KAAKC,OAAOD,MAAM,QAAQ,MAA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AKxB;YACL,OAAO6E,IAAI,eAAe;YAC1B,UAAUA,IAAI,aAAa;YAC3B,gBAAgB7D;;IAG5B;AAKpB;AAEA,MAAM8D,YAAYC,gBAAgB,aAAapD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import type { DataTableDefaultData } from "./DataTable.js";
|
|
3
3
|
import { DataTable } from "./DataTable.js";
|
|
4
4
|
declare const meta: Meta<typeof DataTable>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTable/DataTable.stories.js","sources":["../../src/DataTable/DataTable.stories.tsx"],"sourcesContent":["import React, { useState, useEffect } from \"react\";\nimport type { Meta, StoryObj } from \"@storybook/react-webpack5\";\nimport type { DataTableColumns, DataTableDefaultData, DataTableSorting } from \"./DataTable.js\";\nimport { DataTable } from \"./DataTable.js\";\nimport { Avatar } from \"~/Avatar/index.js\";\nimport { Text } from \"~/Text/index.js\";\n\nconst meta: Meta<typeof DataTable> = {\n title: \"Components/DataTable\",\n component: DataTable,\n parameters: {\n layout: \"padded\"\n }\n};\n\nexport default meta;\ntype Story<T extends Record<string, any> & DataTableDefaultData> = StoryObj<typeof DataTable<T>>;\n\n// Declare the data structure.\ninterface Entry {\n id: string;\n name: string;\n createdBy: string;\n lastModified: string;\n status: string;\n}\n\n// Define the columns structure for the table.\nconst columns: DataTableColumns<Entry> = {\n name: {\n header: \"Title\"\n },\n createdBy: {\n header: \"Author\"\n },\n lastModified: {\n header: \"Last Modified\"\n },\n status: {\n header: \"Status\"\n }\n};\n\n// Define the data to display.\nconst data = [\n {\n id: \"entry-1\",\n name: \"Getting Started Guide\",\n createdBy: \"John Doe\",\n lastModified: \"1 hour ago\",\n status: \"Published\"\n },\n {\n id: \"entry-2\",\n name: \"User Documentation\",\n createdBy: \"Jane Smith\",\n lastModified: \"3 days ago\",\n status: \"Draft\"\n },\n {\n id: \"entry-3\",\n name: \"API Reference\",\n createdBy: \"John Doe\",\n lastModified: \"1 week ago\",\n status: \"Published\"\n }\n];\n\nexport const Default: Story<Entry> = {\n args: {\n data,\n columns\n }\n};\n\nexport const Bordered: Story<Entry> = {\n args: {\n ...Default.args,\n bordered: true\n }\n};\n\nexport const WithStickyHeader: Story<Entry> = {\n args: {\n ...Default.args,\n stickyHeader: true\n }\n};\n\nexport const WithSelectableRows: Story<Entry> = {\n args: Default.args,\n render: args => {\n const [selectedRows, setSelectedRows] = useState<Entry[]>([]);\n\n return (\n <DataTable\n {...args}\n selectedRows={selectedRows}\n onSelectRow={rows => setSelectedRows(rows)}\n />\n );\n }\n};\n\nexport const WithLoading: Story<Entry> = {\n args: {\n columns\n },\n render: ({ columns }) => {\n const [loading, setLoading] = useState(true);\n const [tableData, setTableData] = useState<Entry[]>([]);\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setTableData(data); // your predefined data\n setLoading(false);\n }, 5000);\n\n return () => clearTimeout(timer);\n }, []);\n\n return <DataTable columns={columns} data={tableData} loading={loading} />;\n }\n};\n\nexport const WithLongColumnContent: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n header: \"Name - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\"\n }\n },\n data: data.map(entry => ({\n ...entry,\n name: `${entry.name} - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla facilisi. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`\n }))\n }\n};\n\nexport const WithCustomCellRenderer: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n cell: (entry: Entry) => {\n return (\n <div className={\"flex items-center gap-sm-extra\"}>\n <Avatar\n image={\n <Avatar.Image\n src=\"https://github.com/webiny-bot.png\"\n alt=\"@webiny\"\n />\n }\n fallback={<Avatar.Fallback>{entry.name.charAt(0)}</Avatar.Fallback>}\n size={\"xl\"}\n />\n <div>\n <Text className={\"text-neutral-primary font-semibold\"} as={\"div\"}>\n {entry.name}\n </Text>\n <Text\n size={\"sm\"}\n className={\"text-neutral-strong\"}\n as={\"div\"}\n >{`Last updated: ${entry.lastModified}`}</Text>\n </div>\n </div>\n );\n }\n }\n }\n }\n};\n\nexport const WithCustomColumnSize: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n size: 200\n }\n }\n }\n};\n\nexport const WithCustomColumnClassName: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n lastModified: {\n ...columns.lastModified,\n className: \"bg-primary-subtle\"\n },\n status: {\n ...columns.status,\n className: \"text-right\"\n }\n }\n }\n};\n\nexport const WithSorting: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n enableSorting: true\n },\n lastModified: {\n ...columns.lastModified,\n enableSorting: true\n }\n },\n sorting: [\n {\n id: \"lastModified\",\n desc: true\n }\n ]\n },\n render: ({ sorting: argsSorting = [], ...args }) => {\n const [sorting, setSorting] = useState<DataTableSorting>(argsSorting);\n return <DataTable {...args} sorting={sorting} onSortingChange={setSorting} />;\n }\n};\n\n// Add a Documentation story\nexport const Documentation: Story<Entry> = {\n args: {\n bordered: true,\n stickyHeader: true,\n columns: {\n name: {\n header: \"Title\",\n enableSorting: true\n },\n createdBy: {\n header: \"Author\"\n },\n lastModified: {\n header: \"Last Modified\",\n enableSorting: true\n },\n status: {\n header: \"Status\"\n }\n },\n data: [\n {\n id: \"entry-1\",\n name: \"Getting Started Guide\",\n createdBy: \"John Doe\",\n lastModified: \"1 hour ago\",\n status: \"Published\"\n },\n {\n id: \"entry-2\",\n name: \"User Documentation\",\n createdBy: \"Jane Smith\",\n lastModified: \"3 days ago\",\n status: \"Draft\"\n },\n {\n id: \"entry-3\",\n name: \"API Reference\",\n createdBy: \"John Doe\",\n lastModified: \"1 week ago\",\n status: \"Published\"\n }\n ]\n },\n render: args => {\n const [selectedRows, setSelectedRows] = useState<Entry[]>([]);\n const [sorting, setSorting] = useState<DataTableSorting>([]);\n\n return (\n <DataTable\n {...args}\n selectedRows={selectedRows}\n onSelectRow={rows => setSelectedRows(rows)}\n sorting={sorting}\n onSortingChange={setSorting}\n />\n );\n },\n parameters: {\n docs: {\n description: {\n story: \"This example shows a DataTable with selectable rows, sorting, and a sticky header.\"\n }\n }\n },\n argTypes: {\n bordered: {\n description: \"Show or hide borders.\",\n control: \"boolean\",\n defaultValue: true\n },\n stickyHeader: {\n description: \"Enable sticky header.\",\n control: \"boolean\",\n defaultValue: true\n },\n columns: {\n description: \"Columns definition. Please refer to the code example for details.\",\n control: false\n },\n data: {\n description:\n \"Data to display into DataTable body. Please refer to the code example for details.\",\n control: false\n }\n }\n};\n"],"names":["meta","DataTable","columns","data","Default","Bordered","WithStickyHeader","WithSelectableRows","args","selectedRows","setSelectedRows","useState","rows","WithLoading","loading","setLoading","tableData","setTableData","useEffect","timer","setTimeout","clearTimeout","WithLongColumnContent","entry","WithCustomCellRenderer","Avatar","Text","WithCustomColumnSize","WithCustomColumnClassName","WithSorting","argsSorting","sorting","setSorting","Documentation"],"mappings":";;;;AAOA,MAAMA,OAA+B;IACjC,OAAO;IACP,WAAWC;IACX,YAAY;QACR,QAAQ;IACZ;AACJ;AAEA,0BAAeD;AAaf,MAAME,4BAAmC;IACrC,MAAM;QACF,QAAQ;IACZ;IACA,WAAW;QACP,QAAQ;IACZ;IACA,cAAc;QACV,QAAQ;IACZ;IACA,QAAQ;QACJ,QAAQ;IACZ;AACJ;AAGA,MAAMC,OAAO;IACT;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;IACA;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;IACA;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;CACH;AAEM,MAAMC,UA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AGrB,SAA2BmB;QACzD,OAAO,WAAP,GAAO,oBAAC7B,WAASA;YAAE,GAAGO,IAAI;YAAE,SAASuB;YAAS,iBAAiBC;;IACnE;AACJ;AAGO,MAAMC,gBAA8B;IACvC,MAAM;QACF,UAAU;QACV,cAAc;QACd,SAAS;YACL,MAAM;gBACF,QAAQ;gBACR,eAAe;YACnB;YACA,WAAW;gBACP,QAAQ;YACZ;YACA,cAAc;gBACV,QAAQ;gBACR,eAAe;YACnB;YACA,QAAQ;gBACJ,QAAQ;YACZ;QACJ;QACA,MAAM;YACF;gBACI,IAAI;gBACJ,MAAM;gBACN,WAAW;gBACX,cAAc;gBACd,QAAQ;YACZ;YACA;gBACI,IAAI;gBACJ,MAAM;gBACN,WAAW;gBACX,cAAc;gBACd,QAAQ;YACZ;YACA;gBACI,IAAI;gBACJ,MAAM;gBACN,WAAW;gBACX,cAAc;gBACd,QAAQ;YACZ;SACH;IACL;IACA,QAAQzB,CAAAA;QACJ,MAAM,CAACC,cAAcC,gBAAgB,GAAGC,SAAkB,EAAE;QAC5D,MAAM,CAACoB,SAASC,WAAW,GAAGrB,SAA2B,EAAE;QAE3D,OAAO,WAAP,GACI,oBAACV,WAASA;YACL,GAAGO,IAAI;YACR,cAAcC;YACd,aAAaG,CAAAA,OAAQF,gBAAgBE;YACrC,SAASmB;YACT,iBAAiBC;;IAG7B;IACA,YAAY;QACR,MAAM;YACF,aAAa;gBACT,OAAO;YACX;QACJ;IACJ;IACA,UAAU;QACN,UAAU;YACN,aAAa;YACb,SAAS;YACT,cAAc;QAClB;QACA,cAAc;YACV,aAAa;YACb,SAAS;YACT,cAAc;QAClB;QACA,SAAS;YACL,aAAa;YACb,SAAS;QACb;QACA,MAAM;YACF,aACI;YACJ,SAAS;QACb;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"DataTable/DataTable.stories.js","sources":["../../src/DataTable/DataTable.stories.tsx"],"sourcesContent":["import React, { useState, useEffect } from \"react\";\nimport type { Meta, StoryObj } from \"@storybook/react\";\nimport type { DataTableColumns, DataTableDefaultData, DataTableSorting } from \"./DataTable.js\";\nimport { DataTable } from \"./DataTable.js\";\nimport { Avatar } from \"~/Avatar/index.js\";\nimport { Text } from \"~/Text/index.js\";\n\nconst meta: Meta<typeof DataTable> = {\n title: \"Components/DataTable\",\n component: DataTable,\n parameters: {\n layout: \"padded\"\n }\n};\n\nexport default meta;\ntype Story<T extends Record<string, any> & DataTableDefaultData> = StoryObj<typeof DataTable<T>>;\n\n// Declare the data structure.\ninterface Entry {\n id: string;\n name: string;\n createdBy: string;\n lastModified: string;\n status: string;\n}\n\n// Define the columns structure for the table.\nconst columns: DataTableColumns<Entry> = {\n name: {\n header: \"Title\"\n },\n createdBy: {\n header: \"Author\"\n },\n lastModified: {\n header: \"Last Modified\"\n },\n status: {\n header: \"Status\"\n }\n};\n\n// Define the data to display.\nconst data = [\n {\n id: \"entry-1\",\n name: \"Getting Started Guide\",\n createdBy: \"John Doe\",\n lastModified: \"1 hour ago\",\n status: \"Published\"\n },\n {\n id: \"entry-2\",\n name: \"User Documentation\",\n createdBy: \"Jane Smith\",\n lastModified: \"3 days ago\",\n status: \"Draft\"\n },\n {\n id: \"entry-3\",\n name: \"API Reference\",\n createdBy: \"John Doe\",\n lastModified: \"1 week ago\",\n status: \"Published\"\n }\n];\n\nexport const Default: Story<Entry> = {\n args: {\n data,\n columns\n }\n};\n\nexport const Bordered: Story<Entry> = {\n args: {\n ...Default.args,\n bordered: true\n }\n};\n\nexport const WithStickyHeader: Story<Entry> = {\n args: {\n ...Default.args,\n stickyHeader: true\n }\n};\n\nexport const WithSelectableRows: Story<Entry> = {\n args: Default.args,\n render: args => {\n const [selectedRows, setSelectedRows] = useState<Entry[]>([]);\n\n return (\n <DataTable\n {...args}\n selectedRows={selectedRows}\n onSelectRow={rows => setSelectedRows(rows)}\n />\n );\n }\n};\n\nexport const WithLoading: Story<Entry> = {\n args: {\n columns\n },\n render: ({ columns }) => {\n const [loading, setLoading] = useState(true);\n const [tableData, setTableData] = useState<Entry[]>([]);\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setTableData(data); // your predefined data\n setLoading(false);\n }, 5000);\n\n return () => clearTimeout(timer);\n }, []);\n\n return <DataTable columns={columns} data={tableData} loading={loading} />;\n }\n};\n\nexport const WithLongColumnContent: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n header: \"Name - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\"\n }\n },\n data: data.map(entry => ({\n ...entry,\n name: `${entry.name} - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla facilisi. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`\n }))\n }\n};\n\nexport const WithCustomCellRenderer: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n cell: (entry: Entry) => {\n return (\n <div className={\"flex items-center gap-sm-extra\"}>\n <Avatar\n image={\n <Avatar.Image\n src=\"https://github.com/webiny-bot.png\"\n alt=\"@webiny\"\n />\n }\n fallback={<Avatar.Fallback>{entry.name.charAt(0)}</Avatar.Fallback>}\n size={\"xl\"}\n />\n <div>\n <Text className={\"text-neutral-primary font-semibold\"} as={\"div\"}>\n {entry.name}\n </Text>\n <Text\n size={\"sm\"}\n className={\"text-neutral-strong\"}\n as={\"div\"}\n >{`Last updated: ${entry.lastModified}`}</Text>\n </div>\n </div>\n );\n }\n }\n }\n }\n};\n\nexport const WithCustomColumnSize: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n size: 200\n }\n }\n }\n};\n\nexport const WithCustomColumnClassName: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n lastModified: {\n ...columns.lastModified,\n className: \"bg-primary-subtle\"\n },\n status: {\n ...columns.status,\n className: \"text-right\"\n }\n }\n }\n};\n\nexport const WithSorting: Story<Entry> = {\n args: {\n ...Default.args,\n columns: {\n ...columns,\n name: {\n ...columns.name,\n enableSorting: true\n },\n lastModified: {\n ...columns.lastModified,\n enableSorting: true\n }\n },\n sorting: [\n {\n id: \"lastModified\",\n desc: true\n }\n ]\n },\n render: ({ sorting: argsSorting = [], ...args }) => {\n const [sorting, setSorting] = useState<DataTableSorting>(argsSorting);\n return <DataTable {...args} sorting={sorting} onSortingChange={setSorting} />;\n }\n};\n\n// Add a Documentation story\nexport const Documentation: Story<Entry> = {\n args: {\n bordered: true,\n stickyHeader: true,\n columns: {\n name: {\n header: \"Title\",\n enableSorting: true\n },\n createdBy: {\n header: \"Author\"\n },\n lastModified: {\n header: \"Last Modified\",\n enableSorting: true\n },\n status: {\n header: \"Status\"\n }\n },\n data: [\n {\n id: \"entry-1\",\n name: \"Getting Started Guide\",\n createdBy: \"John Doe\",\n lastModified: \"1 hour ago\",\n status: \"Published\"\n },\n {\n id: \"entry-2\",\n name: \"User Documentation\",\n createdBy: \"Jane Smith\",\n lastModified: \"3 days ago\",\n status: \"Draft\"\n },\n {\n id: \"entry-3\",\n name: \"API Reference\",\n createdBy: \"John Doe\",\n lastModified: \"1 week ago\",\n status: \"Published\"\n }\n ]\n },\n render: args => {\n const [selectedRows, setSelectedRows] = useState<Entry[]>([]);\n const [sorting, setSorting] = useState<DataTableSorting>([]);\n\n return (\n <DataTable\n {...args}\n selectedRows={selectedRows}\n onSelectRow={rows => setSelectedRows(rows)}\n sorting={sorting}\n onSortingChange={setSorting}\n />\n );\n },\n parameters: {\n docs: {\n description: {\n story: \"This example shows a DataTable with selectable rows, sorting, and a sticky header.\"\n }\n }\n },\n argTypes: {\n bordered: {\n description: \"Show or hide borders.\",\n control: \"boolean\",\n defaultValue: true\n },\n stickyHeader: {\n description: \"Enable sticky header.\",\n control: \"boolean\",\n defaultValue: true\n },\n columns: {\n description: \"Columns definition. Please refer to the code example for details.\",\n control: false\n },\n data: {\n description:\n \"Data to display into DataTable body. Please refer to the code example for details.\",\n control: false\n }\n }\n};\n"],"names":["meta","DataTable","columns","data","Default","Bordered","WithStickyHeader","WithSelectableRows","args","selectedRows","setSelectedRows","useState","rows","WithLoading","loading","setLoading","tableData","setTableData","useEffect","timer","setTimeout","clearTimeout","WithLongColumnContent","entry","WithCustomCellRenderer","Avatar","Text","WithCustomColumnSize","WithCustomColumnClassName","WithSorting","argsSorting","sorting","setSorting","Documentation"],"mappings":";;;;AAOA,MAAMA,OAA+B;IACjC,OAAO;IACP,WAAWC;IACX,YAAY;QACR,QAAQ;IACZ;AACJ;AAEA,0BAAeD;AAaf,MAAME,4BAAmC;IACrC,MAAM;QACF,QAAQ;IACZ;IACA,WAAW;QACP,QAAQ;IACZ;IACA,cAAc;QACV,QAAQ;IACZ;IACA,QAAQ;QACJ,QAAQ;IACZ;AACJ;AAGA,MAAMC,OAAO;IACT;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;IACA;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;IACA;QACI,IAAI;QACJ,MAAM;QACN,WAAW;QACX,cAAc;QACd,QAAQ;IACZ;CACH;AAEM,MAAMC,UAAwB;IACjC,MAAM;QACFD,MAAAA;QACAD,SAAAA;IACJ;AACJ;AAEO,MAAMG,WAAyB;IAClC,MAAM;QACF,GAAGD,QAAQ,IAAI;QACf,UAAU;IACd;AACJ;AAEO,MAAME,mBAAiC;IAC1C,MAAM;QACF,GAAGF,QAAQ,IAAI;QACf,cAAc;IAClB;AACJ;AAEO,MAAMG,qBAAmC;IAC5C,MAAMH,QAAQ,IAAI;IAClB,QAAQI,CAAAA;QACJ,MAAM,CAACC,cAAcC,gBAAgB,GAAGC,SAAkB,EAAE;QAE5D,OAAO,WAAP,GACI,oBAACV,WAASA;YACL,GAAGO,IAAI;YACR,cAAcC;YACd,aAAaG,CAAAA,OAAQF,gBAAgBE;;IAGjD;AACJ;AAEO,MAAMC,cAA4B;IACrC,MAAM;QACFX,SAAA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I,IAAI;gBACJ,MAAM;gBACN,WAAW;gBACX,cAAc;gBACd,QAAQ;YACZ;SACH;IACL;IACA,QAAQzB,CAAAA;QACJ,MAAM,CAACC,cAAcC,gBAAgB,GAAGC,SAAkB,EAAE;QAC5D,MAAM,CAACoB,SAASC,WAAW,GAAGrB,SAA2B,EAAE;QAE3D,OAAO,WAAP,GACI,oBAACV,WAASA;YACL,GAAGO,IAAI;YACR,cAAcC;YACd,aAAaG,CAAAA,OAAQF,gBAAgBE;YACrC,SAASmB;YACT,iBAAiBC;;IAG7B;IACA,YAAY;QACR,MAAM;YACF,aAAa;gBACT,OAAO;YACX;QACJ;IACJ;IACA,UAAU;QACN,UAAU;YACN,aAAa;YACb,SAAS;YACT,cAAc;QAClB;QACA,cAAc;YACV,aAAa;YACb,SAAS;YACT,cAAc;QAClB;QACA,SAAS;YACL,aAAa;YACb,SAAS;QACb;QACA,MAAM;YACF,aACI;YACJ,SAAS;QACb;IACJ;AACJ"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { Column } from "@tanstack/react-table";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type { Column, RowData } from "@tanstack/react-table";
|
|
3
|
+
import type { Features } from "../DataTable.js";
|
|
4
|
+
interface ColumnsVisibilityProps<T extends RowData> {
|
|
5
|
+
columns: Column<Features, T>[];
|
|
5
6
|
}
|
|
6
|
-
export declare const ColumnsVisibility: <T>(props: ColumnsVisibilityProps<T>) => React.JSX.Element | null;
|
|
7
|
+
export declare const ColumnsVisibility: <T extends RowData>(props: ColumnsVisibilityProps<T>) => React.JSX.Element | null;
|
|
7
8
|
export {};
|
|
@@ -7,14 +7,17 @@ const ColumnsVisibility = (props)=>{
|
|
|
7
7
|
const getHeaderName = useCallback((column)=>{
|
|
8
8
|
const { header } = column.columnDef;
|
|
9
9
|
if ("string" == typeof header) return header;
|
|
10
|
-
if ("function" == typeof header)
|
|
10
|
+
if ("function" == typeof header) {
|
|
11
|
+
const flatHeader = column.table.getFlatHeaders().find((h)=>h.column.id === column.id);
|
|
12
|
+
if (flatHeader) return header(flatHeader.getContext());
|
|
13
|
+
}
|
|
11
14
|
return column.id;
|
|
12
15
|
}, []);
|
|
13
16
|
const options = useMemo(()=>props.columns.filter((column)=>column.getCanHide()).map((column)=>({
|
|
14
17
|
id: column.id,
|
|
15
18
|
header: getHeaderName(column),
|
|
16
|
-
onChange: column.toggleVisibility,
|
|
17
|
-
getValue: column.getIsVisible
|
|
19
|
+
onChange: (value)=>column.toggleVisibility(value),
|
|
20
|
+
getValue: ()=>column.getIsVisible()
|
|
18
21
|
})), [
|
|
19
22
|
props.columns
|
|
20
23
|
]);
|
|
@@ -29,6 +32,7 @@ const ColumnsVisibility = (props)=>{
|
|
|
29
32
|
text: "Display columns"
|
|
30
33
|
}), options.map((option)=>/*#__PURE__*/ react.createElement(DropdownMenu.Item, {
|
|
31
34
|
key: option.id,
|
|
35
|
+
preventClose: true,
|
|
32
36
|
text: /*#__PURE__*/ react.createElement(Checkbox, {
|
|
33
37
|
label: option.header,
|
|
34
38
|
onChange: option.onChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTable/components/ColumnsVisibility.js","sources":["../../../src/DataTable/components/ColumnsVisibility.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from \"react\";\nimport { ReactComponent as SettingsIcon } from \"@webiny/icons/settings.svg\";\nimport type { Column } from \"@tanstack/react-table\";\nimport { IconButton } from \"~/Button/index.js\";\nimport { Checkbox } from \"~/Checkbox/index.js\";\nimport { DropdownMenu } from \"~/DropdownMenu/index.js\";\n\ninterface ColumnsVisibilityProps<T> {\n columns: Column<T>[];\n}\n\ninterface Option {\n id: string;\n header: string;\n onChange: (value?: boolean | undefined) => void;\n getValue: () => boolean;\n}\n\nexport const ColumnsVisibility = <T
|
|
1
|
+
{"version":3,"file":"DataTable/components/ColumnsVisibility.js","sources":["../../../src/DataTable/components/ColumnsVisibility.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from \"react\";\nimport { ReactComponent as SettingsIcon } from \"@webiny/icons/settings.svg\";\nimport type { Column, RowData } from \"@tanstack/react-table\";\nimport { IconButton } from \"~/Button/index.js\";\nimport { Checkbox } from \"~/Checkbox/index.js\";\nimport { DropdownMenu } from \"~/DropdownMenu/index.js\";\nimport type { Features } from \"../DataTable.js\";\n\ninterface ColumnsVisibilityProps<T extends RowData> {\n columns: Column<Features, T>[];\n}\n\ninterface Option {\n id: string;\n header: string;\n onChange: (value?: boolean | undefined) => void;\n getValue: () => boolean;\n}\n\nexport const ColumnsVisibility = <T extends RowData>(props: ColumnsVisibilityProps<T>) => {\n const getHeaderName = useCallback((column: Column<Features, T>) => {\n const { header } = column.columnDef;\n\n if (typeof header === \"string\") {\n return header;\n }\n\n if (typeof header === \"function\") {\n const flatHeader = column.table.getFlatHeaders().find(h => h.column.id === column.id);\n\n if (flatHeader) {\n return header(flatHeader.getContext());\n }\n }\n\n return column.id;\n }, []);\n\n const options: Option[] = useMemo(() => {\n return props.columns\n .filter(column => column.getCanHide())\n .map(column => {\n return {\n id: column.id,\n header: getHeaderName(column),\n onChange: (value?: boolean) => column.toggleVisibility(value),\n getValue: () => column.getIsVisible()\n };\n });\n }, [props.columns]);\n\n if (options.length === 0) {\n return null;\n }\n\n return (\n <DropdownMenu\n trigger={<IconButton icon={<SettingsIcon />} variant={\"ghost\"} size={\"xs\"} />}\n >\n <DropdownMenu.Label text={\"Display columns\"} />\n {options.map(option => {\n return (\n <DropdownMenu.Item\n key={option.id}\n preventClose\n text={\n <Checkbox\n label={option.header}\n onChange={option.onChange}\n checked={option.getValue()}\n />\n }\n />\n );\n })}\n </DropdownMenu>\n );\n};\n"],"names":["ColumnsVisibility","props","getHeaderName","useCallback","column","header","flatHeader","h","options","useMemo","value","DropdownMenu","IconButton","SettingsIcon","option","Checkbox"],"mappings":";;;;;AAmBO,MAAMA,oBAAoB,CAAoBC;IACjD,MAAMC,gBAAgBC,YAAY,CAACC;QAC/B,MAAM,EAAEC,MAAM,EAAE,GAAGD,OAAO,SAAS;QAEnC,IAAI,AAAkB,YAAlB,OAAOC,QACP,OAAOA;QAGX,IAAI,AAAkB,cAAlB,OAAOA,QAAuB;YAC9B,MAAMC,aAAaF,OAAO,KAAK,CAAC,cAAc,GAAG,IAAI,CAACG,CAAAA,IAAKA,EAAE,MAAM,CAAC,EAAE,KAAKH,OAAO,EAAE;YAEpF,IAAIE,YACA,OAAOD,OAAOC,WAAW,UAAU;QAE3C;QAEA,OAAOF,OAAO,EAAE;IACpB,GAAG,EAAE;IAEL,MAAMI,UAAoBC,QAAQ,IACvBR,MAAM,OAAO,CACf,MAAM,CAACG,CAAAA,SAAUA,OAAO,UAAU,IAClC,GAAG,CAACA,CAAAA,SACM;gBACH,IAAIA,OAAO,EAAE;gBACb,QAAQF,cAAcE;gBACtB,UAAU,CAACM,QAAoBN,OAAO,gBAAgB,CAACM;gBACvD,UAAU,IAAMN,OAAO,YAAY;YACvC,KAET;QAACH,MAAM,OAAO;KAAC;IAElB,IAAIO,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAO;IAGX,OAAO,WAAP,GACI,oBAACG,cAAYA;QACT,uBAAS,oBAACC,YAAUA;YAAC,oBAAM,oBAACC,gBAAYA;YAAK,SAAS;YAAS,MAAM;;qBAErE,oBAACF,aAAa,KAAK;QAAC,MAAM;QACzBH,QAAQ,GAAG,CAACM,CAAAA,SACF,WAAP,GACI,oBAACH,aAAa,IAAI;YACd,KAAKG,OAAO,EAAE;YACd;YACA,oBACI,oBAACC,UAAQA;gBACL,OAAOD,OAAO,MAAM;gBACpB,UAAUA,OAAO,QAAQ;gBACzB,SAASA,OAAO,QAAQ;;;AAQxD"}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { DatePickerPrimitiveProps } from "./primitives/index.js";
|
|
3
3
|
import type { FormComponentProps } from "../FormComponent/index.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
interface DatePickerOwnProps {
|
|
5
|
+
showTimezone?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type DatePickerProps = DatePickerPrimitiveProps & FormComponentProps & DatePickerOwnProps;
|
|
8
|
+
declare const DecoratableDatePicker: ({ label, description, note, hint, required, disabled, validation, showTimezone, ...props }: DatePickerProps) => React.JSX.Element;
|
|
9
|
+
declare const DatePicker: typeof DecoratableDatePicker & {
|
|
10
|
+
original: typeof DecoratableDatePicker;
|
|
7
11
|
originalName: string;
|
|
8
12
|
displayName: string;
|
|
9
13
|
} & {
|
|
10
|
-
original:
|
|
11
|
-
original:
|
|
14
|
+
original: typeof DecoratableDatePicker & {
|
|
15
|
+
original: typeof DecoratableDatePicker;
|
|
12
16
|
originalName: string;
|
|
13
17
|
displayName: string;
|
|
14
18
|
};
|
|
15
19
|
originalName: string;
|
|
16
20
|
displayName: string;
|
|
17
21
|
} & {
|
|
18
|
-
createDecorator: (decorator: import("@webiny/react-composition/types.js").ComponentDecorator<
|
|
19
|
-
original:
|
|
22
|
+
createDecorator: (decorator: import("@webiny/react-composition/types.js").ComponentDecorator<typeof DecoratableDatePicker & {
|
|
23
|
+
original: typeof DecoratableDatePicker;
|
|
20
24
|
originalName: string;
|
|
21
25
|
displayName: string;
|
|
22
26
|
}>) => (props: unknown) => React.JSX.Element;
|
package/DatePicker/DatePicker.js
CHANGED
|
@@ -2,7 +2,15 @@ import react, { useMemo } from "react";
|
|
|
2
2
|
import { makeDecoratable } from "../utils.js";
|
|
3
3
|
import { DatePickerPrimitive } from "./primitives/index.js";
|
|
4
4
|
import { FormComponentDescription, FormComponentErrorMessage, FormComponentLabel, FormComponentNote } from "../FormComponent/index.js";
|
|
5
|
-
|
|
5
|
+
import { Text } from "../Text/index.js";
|
|
6
|
+
const TimezoneLabel = ()=>{
|
|
7
|
+
const timezone = useMemo(()=>Intl.DateTimeFormat().resolvedOptions().timeZone, []);
|
|
8
|
+
return /*#__PURE__*/ react.createElement(Text, {
|
|
9
|
+
size: "sm",
|
|
10
|
+
className: "text-neutral-strong mt-xxs"
|
|
11
|
+
}, "Timezone: ", timezone);
|
|
12
|
+
};
|
|
13
|
+
const DecoratableDatePicker = ({ label, description, note, hint, required, disabled, validation, showTimezone = false, ...props })=>{
|
|
6
14
|
const { isValid: validationIsValid, message: validationMessage } = validation || {};
|
|
7
15
|
const invalid = useMemo(()=>false === validationIsValid, [
|
|
8
16
|
validationIsValid
|
|
@@ -22,7 +30,7 @@ const DecoratableDatePicker = ({ label, description, note, hint, required, disab
|
|
|
22
30
|
...props,
|
|
23
31
|
disabled: disabled,
|
|
24
32
|
invalid: invalid
|
|
25
|
-
}), /*#__PURE__*/ react.createElement(FormComponentErrorMessage, {
|
|
33
|
+
}), showTimezone && /*#__PURE__*/ react.createElement(TimezoneLabel, null), /*#__PURE__*/ react.createElement(FormComponentErrorMessage, {
|
|
26
34
|
text: validationMessage,
|
|
27
35
|
invalid: invalid,
|
|
28
36
|
disabled: disabled
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker/DatePicker.js","sources":["../../src/DatePicker/DatePicker.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { makeDecoratable } from \"~/utils.js\";\nimport type { DatePickerPrimitiveProps } from \"./primitives/index.js\";\nimport { DatePickerPrimitive } from \"./primitives/index.js\";\nimport type { FormComponentProps } from \"~/FormComponent/index.js\";\nimport {\n FormComponentDescription,\n FormComponentErrorMessage,\n FormComponentLabel,\n FormComponentNote\n} from \"~/FormComponent/index.js\";\n\ntype DatePickerProps = DatePickerPrimitiveProps & FormComponentProps;\n\nconst DecoratableDatePicker = ({\n label,\n description,\n note,\n hint,\n required,\n disabled,\n validation,\n ...props\n}: DatePickerProps) => {\n const { isValid: validationIsValid, message: validationMessage } = validation || {};\n const invalid = useMemo(() => validationIsValid === false, [validationIsValid]);\n\n return (\n <div className=\"w-full\">\n <FormComponentLabel\n text={label}\n hint={hint}\n required={required}\n disabled={disabled}\n invalid={invalid}\n />\n <FormComponentDescription text={description} disabled={disabled} />\n <DatePickerPrimitive\n {...(props as DatePickerPrimitiveProps)}\n disabled={disabled}\n invalid={invalid}\n />\n <FormComponentErrorMessage\n text={validationMessage}\n invalid={invalid}\n disabled={disabled}\n />\n <FormComponentNote text={note} disabled={disabled} />\n </div>\n );\n};\n\nconst DatePicker = makeDecoratable(\"DatePicker\", DecoratableDatePicker);\n\nexport { DatePicker, type DatePickerProps };\n"],"names":["DecoratableDatePicker","label","description","note","hint","required","disabled","validation","props","validationIsValid","validationMessage","invalid","
|
|
1
|
+
{"version":3,"file":"DatePicker/DatePicker.js","sources":["../../src/DatePicker/DatePicker.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { makeDecoratable } from \"~/utils.js\";\nimport type { DatePickerPrimitiveProps } from \"./primitives/index.js\";\nimport { DatePickerPrimitive } from \"./primitives/index.js\";\nimport type { FormComponentProps } from \"~/FormComponent/index.js\";\nimport {\n FormComponentDescription,\n FormComponentErrorMessage,\n FormComponentLabel,\n FormComponentNote\n} from \"~/FormComponent/index.js\";\nimport { Text } from \"~/Text/index.js\";\n\ninterface DatePickerOwnProps {\n showTimezone?: boolean;\n}\n\ntype DatePickerProps = DatePickerPrimitiveProps & FormComponentProps & DatePickerOwnProps;\n\nconst TimezoneLabel = () => {\n const timezone = useMemo(() => Intl.DateTimeFormat().resolvedOptions().timeZone, []);\n return (\n <Text size={\"sm\"} className={\"text-neutral-strong mt-xxs\"}>\n Timezone: {timezone}\n </Text>\n );\n};\n\nconst DecoratableDatePicker = ({\n label,\n description,\n note,\n hint,\n required,\n disabled,\n validation,\n showTimezone = false,\n ...props\n}: DatePickerProps) => {\n const { isValid: validationIsValid, message: validationMessage } = validation || {};\n const invalid = useMemo(() => validationIsValid === false, [validationIsValid]);\n\n return (\n <div className=\"w-full\">\n <FormComponentLabel\n text={label}\n hint={hint}\n required={required}\n disabled={disabled}\n invalid={invalid}\n />\n <FormComponentDescription text={description} disabled={disabled} />\n <DatePickerPrimitive\n {...(props as DatePickerPrimitiveProps)}\n disabled={disabled}\n invalid={invalid}\n />\n {showTimezone && <TimezoneLabel />}\n <FormComponentErrorMessage\n text={validationMessage}\n invalid={invalid}\n disabled={disabled}\n />\n <FormComponentNote text={note} disabled={disabled} />\n </div>\n );\n};\n\nconst DatePicker = makeDecoratable(\"DatePicker\", DecoratableDatePicker);\n\nexport { DatePicker, type DatePickerProps };\n"],"names":["TimezoneLabel","timezone","useMemo","Intl","Text","DecoratableDatePicker","label","description","note","hint","required","disabled","validation","showTimezone","props","validationIsValid","validationMessage","invalid","FormComponentLabel","FormComponentDescription","DatePickerPrimitive","FormComponentErrorMessage","FormComponentNote","DatePicker","makeDecoratable"],"mappings":";;;;;AAmBA,MAAMA,gBAAgB;IAClB,MAAMC,WAAWC,QAAQ,IAAMC,KAAK,cAAc,GAAG,eAAe,GAAG,QAAQ,EAAE,EAAE;IACnF,OAAO,WAAP,GACI,oBAACC,MAAIA;QAAC,MAAM;QAAM,WAAW;OAA8B,cAC5CH;AAGvB;AAEA,MAAMI,wBAAwB,CAAC,EAC3BC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,IAAI,EACJC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACVC,eAAe,KAAK,EACpB,GAAGC,OACW;IACd,MAAM,EAAE,SAASC,iBAAiB,EAAE,SAASC,iBAAiB,EAAE,GAAGJ,cAAc,CAAC;IAClF,MAAMK,UAAUf,QAAQ,IAAMa,AAAsB,UAAtBA,mBAA6B;QAACA;KAAkB;IAE9E,OAAO,WAAP,GACI,oBAAC;QAAI,WAAU;qBACX,oBAACG,oBAAkBA;QACf,MAAMZ;QACN,MAAMG;QACN,UAAUC;QACV,UAAUC;QACV,SAASM;sBAEb,oBAACE,0BAAwBA;QAAC,MAAMZ;QAAa,UAAUI;sBACvD,oBAACS,qBAAmBA;QACf,GAAIN,KAAK;QACV,UAAUH;QACV,SAASM;QAEZJ,gBAAgB,WAAhBA,GAAgB,oBAACb,eAAaA,OAAAA,WAAAA,GAC/B,oBAACqB,2BAAyBA;QACtB,MAAML;QACN,SAASC;QACT,UAAUN;sBAEd,oBAACW,mBAAiBA;QAAC,MAAMd;QAAM,UAAUG;;AAGrD;AAEA,MAAMY,aAAaC,gBAAgB,cAAcnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { DatePicker } from "./DatePicker.js";
|
|
3
3
|
declare const meta: Meta<typeof DatePicker>;
|
|
4
4
|
export default meta;
|
|
@@ -12,6 +12,16 @@ export declare const WithErrors: Story;
|
|
|
12
12
|
export declare const Disabled: Story;
|
|
13
13
|
export declare const FullExample: Story;
|
|
14
14
|
export declare const WithPresets: Story;
|
|
15
|
+
/**
|
|
16
|
+
* Picks a date one step at a time: a day, then a month, then a year (newest first). Built for
|
|
17
|
+
* dates far in the past, like a date of birth. The value is a `YYYY-MM-DD` string.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TypeBirthday: Story;
|
|
20
|
+
/**
|
|
21
|
+
* With `minDate` and `maxDate`, years run from the latest allowed one down to the earliest,
|
|
22
|
+
* and days and months that can't make an allowed date are dimmed. Here: 18 to 100 years old.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TypeBirthdayWithLimits: Story;
|
|
15
25
|
export declare const TypeTime: Story;
|
|
16
26
|
export declare const TypeDateTimeLocal: Story;
|
|
17
27
|
export declare const TypeDateTimeTz: Story;
|
|
@@ -12,6 +12,7 @@ const meta = {
|
|
|
12
12
|
control: "select",
|
|
13
13
|
options: [
|
|
14
14
|
"date",
|
|
15
|
+
"birthday",
|
|
15
16
|
"time",
|
|
16
17
|
"dateTimeLocal",
|
|
17
18
|
"dateTimeTz",
|
|
@@ -144,6 +145,48 @@ const WithPresets = {
|
|
|
144
145
|
description: "Choose a date or use a preset."
|
|
145
146
|
}
|
|
146
147
|
};
|
|
148
|
+
const TypeBirthday = {
|
|
149
|
+
render: (args)=>{
|
|
150
|
+
const [value, setValue] = useState("1990-02-09");
|
|
151
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
152
|
+
className: "flex flex-col gap-md max-w-[480px]"
|
|
153
|
+
}, /*#__PURE__*/ react.createElement(DatePicker, {
|
|
154
|
+
...args,
|
|
155
|
+
type: "birthday",
|
|
156
|
+
value: value,
|
|
157
|
+
onChange: setValue
|
|
158
|
+
}), /*#__PURE__*/ react.createElement("span", {
|
|
159
|
+
className: "text-sm text-neutral-muted"
|
|
160
|
+
}, "Value: ", value ?? "(empty)"));
|
|
161
|
+
},
|
|
162
|
+
args: {
|
|
163
|
+
label: "Date of birth"
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const TypeBirthdayWithLimits = {
|
|
167
|
+
render: (args)=>{
|
|
168
|
+
const [value, setValue] = useState();
|
|
169
|
+
const today = new Date();
|
|
170
|
+
const [minDate] = useState(()=>new Date(today.getFullYear() - 100, today.getMonth(), today.getDate()));
|
|
171
|
+
const [maxDate] = useState(()=>new Date(today.getFullYear() - 18, today.getMonth(), today.getDate()));
|
|
172
|
+
return /*#__PURE__*/ react.createElement("div", {
|
|
173
|
+
className: "flex flex-col gap-md max-w-[480px]"
|
|
174
|
+
}, /*#__PURE__*/ react.createElement(DatePicker, {
|
|
175
|
+
...args,
|
|
176
|
+
type: "birthday",
|
|
177
|
+
value: value,
|
|
178
|
+
onChange: setValue,
|
|
179
|
+
minDate: minDate,
|
|
180
|
+
maxDate: maxDate
|
|
181
|
+
}), /*#__PURE__*/ react.createElement("span", {
|
|
182
|
+
className: "text-sm text-neutral-muted"
|
|
183
|
+
}, "Value: ", value ?? "(empty)"));
|
|
184
|
+
},
|
|
185
|
+
args: {
|
|
186
|
+
label: "Date of birth",
|
|
187
|
+
description: "You must be 18 or older."
|
|
188
|
+
}
|
|
189
|
+
};
|
|
147
190
|
const TypeTime = {
|
|
148
191
|
render: (args)=>{
|
|
149
192
|
const [value, setValue] = useState();
|
|
@@ -399,6 +442,6 @@ const Documentation = {
|
|
|
399
442
|
}
|
|
400
443
|
};
|
|
401
444
|
export default DatePicker_stories;
|
|
402
|
-
export { Default, Disabled, Documentation, FullExample, TypeDateRange, TypeDateTimeLocal, TypeDateTimeTz, TypeMonth, TypeMultipleDates, TypeMultipleMonths, TypeMultipleYears, TypeTime, TypeWeek, TypeYear, WithDescription, WithErrors, WithLabel, WithLabelRequired, WithNotes, WithPresets };
|
|
445
|
+
export { Default, Disabled, Documentation, FullExample, TypeBirthday, TypeBirthdayWithLimits, TypeDateRange, TypeDateTimeLocal, TypeDateTimeTz, TypeMonth, TypeMultipleDates, TypeMultipleMonths, TypeMultipleYears, TypeTime, TypeWeek, TypeYear, WithDescription, WithErrors, WithLabel, WithLabelRequired, WithNotes, WithPresets };
|
|
403
446
|
|
|
404
447
|
//# sourceMappingURL=DatePicker.stories.js.map
|