@knk1313/plain-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -2
- package/dist/components/accordion/Accordion.d.ts +27 -0
- package/dist/components/accordion/Accordion.js +18 -0
- package/dist/components/accordion/index.d.ts +1 -0
- package/dist/components/accordion/index.js +1 -0
- package/dist/components/agent-form/AgentForm.d.ts +40 -0
- package/dist/components/agent-form/AgentForm.js +100 -0
- package/dist/components/agent-form/index.d.ts +1 -0
- package/dist/components/agent-form/index.js +1 -0
- package/dist/components/agent-steps/AgentSteps.d.ts +21 -0
- package/dist/components/agent-steps/AgentSteps.js +42 -0
- package/dist/components/agent-steps/index.d.ts +1 -0
- package/dist/components/agent-steps/index.js +1 -0
- package/dist/components/agent-thinking/AgentThinking.d.ts +12 -0
- package/dist/components/agent-thinking/AgentThinking.js +18 -0
- package/dist/components/agent-thinking/index.d.ts +1 -0
- package/dist/components/agent-thinking/index.js +1 -0
- package/dist/components/area-chart/AreaChart.d.ts +10 -0
- package/dist/components/area-chart/AreaChart.js +83 -0
- package/dist/components/area-chart/index.d.ts +1 -0
- package/dist/components/area-chart/index.js +1 -0
- package/dist/components/auth-card/AuthCard.d.ts +14 -0
- package/dist/components/auth-card/AuthCard.js +9 -0
- package/dist/components/auth-card/PasswordInput.d.ts +13 -0
- package/dist/components/auth-card/PasswordInput.js +26 -0
- package/dist/components/auth-card/index.d.ts +2 -0
- package/dist/components/auth-card/index.js +2 -0
- package/dist/components/avatar/Avatar.d.ts +14 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/index.d.ts +1 -0
- package/dist/components/avatar/index.js +1 -0
- package/dist/components/badge/Badge.d.ts +9 -0
- package/dist/components/badge/Badge.js +15 -0
- package/dist/components/badge/index.d.ts +1 -0
- package/dist/components/badge/index.js +1 -0
- package/dist/components/banner/Banner.d.ts +9 -0
- package/dist/components/banner/Banner.js +36 -0
- package/dist/components/banner/index.d.ts +1 -0
- package/dist/components/banner/index.js +1 -0
- package/dist/components/bar-chart/BarChart.d.ts +3 -0
- package/dist/components/bar-chart/BarChart.js +47 -0
- package/dist/components/bar-chart/index.d.ts +1 -0
- package/dist/components/bar-chart/index.js +1 -0
- package/dist/components/bar-list/BarList.d.ts +26 -0
- package/dist/components/bar-list/BarList.js +24 -0
- package/dist/components/bar-list/index.d.ts +1 -0
- package/dist/components/bar-list/index.js +1 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb/Breadcrumb.js +9 -0
- package/dist/components/breadcrumb/index.d.ts +1 -0
- package/dist/components/breadcrumb/index.js +1 -0
- package/dist/components/button/Button.d.ts +24 -0
- package/dist/components/button/Button.js +31 -0
- package/dist/components/button/buttonStyle.d.ts +9 -0
- package/dist/components/button/buttonStyle.js +41 -0
- package/dist/components/button/index.d.ts +1 -0
- package/dist/components/button/index.js +1 -0
- package/dist/components/button-group/ButtonGroup.d.ts +18 -0
- package/dist/components/button-group/ButtonGroup.js +26 -0
- package/dist/components/button-group/index.d.ts +1 -0
- package/dist/components/button-group/index.js +1 -0
- package/dist/components/calendar/Calendar.d.ts +20 -0
- package/dist/components/calendar/Calendar.js +98 -0
- package/dist/components/calendar/index.d.ts +1 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/calendar-view/CalendarView.d.ts +34 -0
- package/dist/components/calendar-view/CalendarView.js +111 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/index.js +1 -0
- package/dist/components/card/Card.d.ts +6 -0
- package/dist/components/card/Card.js +6 -0
- package/dist/components/card/index.d.ts +1 -0
- package/dist/components/card/index.js +1 -0
- package/dist/components/carousel/Carousel.d.ts +18 -0
- package/dist/components/carousel/Carousel.js +58 -0
- package/dist/components/carousel/index.d.ts +1 -0
- package/dist/components/carousel/index.js +1 -0
- package/dist/components/chart/Axis.d.ts +51 -0
- package/dist/components/chart/Axis.js +127 -0
- package/dist/components/chart/ChartFrame.d.ts +79 -0
- package/dist/components/chart/ChartFrame.js +80 -0
- package/dist/components/chart/ChartTooltip.d.ts +12 -0
- package/dist/components/chart/ChartTooltip.js +57 -0
- package/dist/components/chart/Legend.d.ts +11 -0
- package/dist/components/chart/Legend.js +6 -0
- package/dist/components/chart/Sparkline.d.ts +5 -0
- package/dist/components/chart/Sparkline.js +20 -0
- package/dist/components/chart/format.d.ts +2 -0
- package/dist/components/chart/format.js +17 -0
- package/dist/components/chart/heatmap.d.ts +18 -0
- package/dist/components/chart/heatmap.js +47 -0
- package/dist/components/chart/index.d.ts +1 -0
- package/dist/components/chart/index.js +1 -0
- package/dist/components/chart/line.d.ts +1 -0
- package/dist/components/chart/line.js +15 -0
- package/dist/components/chart/scale.d.ts +15 -0
- package/dist/components/chart/scale.js +100 -0
- package/dist/components/chart/series.d.ts +44 -0
- package/dist/components/chart/series.js +86 -0
- package/dist/components/chart/spacing.d.ts +29 -0
- package/dist/components/chart/spacing.js +34 -0
- package/dist/components/chart/types.d.ts +29 -0
- package/dist/components/chart/types.js +2 -0
- package/dist/components/chart/useChartHover.d.ts +34 -0
- package/dist/components/chart/useChartHover.js +97 -0
- package/dist/components/checkbox/Checkbox.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.js +38 -0
- package/dist/components/checkbox/index.d.ts +1 -0
- package/dist/components/checkbox/index.js +1 -0
- package/dist/components/chip/Chip.d.ts +21 -0
- package/dist/components/chip/Chip.js +10 -0
- package/dist/components/chip/index.d.ts +1 -0
- package/dist/components/chip/index.js +1 -0
- package/dist/components/close-button/CloseButton.d.ts +14 -0
- package/dist/components/close-button/CloseButton.js +9 -0
- package/dist/components/close-button/index.d.ts +1 -0
- package/dist/components/close-button/index.js +1 -0
- package/dist/components/color-picker/ColorPicker.d.ts +21 -0
- package/dist/components/color-picker/ColorPicker.js +20 -0
- package/dist/components/color-picker/index.d.ts +1 -0
- package/dist/components/color-picker/index.js +1 -0
- package/dist/components/combo-chart/ComboChart.d.ts +12 -0
- package/dist/components/combo-chart/ComboChart.js +84 -0
- package/dist/components/combo-chart/index.d.ts +1 -0
- package/dist/components/combo-chart/index.js +1 -0
- package/dist/components/combobox/Combobox.d.ts +33 -0
- package/dist/components/combobox/Combobox.js +246 -0
- package/dist/components/combobox/index.d.ts +1 -0
- package/dist/components/combobox/index.js +1 -0
- package/dist/components/command-palette/CommandPalette.d.ts +36 -0
- package/dist/components/command-palette/CommandPalette.js +156 -0
- package/dist/components/command-palette/index.d.ts +1 -0
- package/dist/components/command-palette/index.js +1 -0
- package/dist/components/composer/Composer.d.ts +32 -0
- package/dist/components/composer/Composer.js +101 -0
- package/dist/components/composer/index.d.ts +1 -0
- package/dist/components/composer/index.js +1 -0
- package/dist/components/composer-attachments/ComposerAttachments.d.ts +25 -0
- package/dist/components/composer-attachments/ComposerAttachments.js +52 -0
- package/dist/components/composer-attachments/index.d.ts +1 -0
- package/dist/components/composer-attachments/index.js +1 -0
- package/dist/components/composer-panel/ComposerPanel.d.ts +26 -0
- package/dist/components/composer-panel/ComposerPanel.js +154 -0
- package/dist/components/composer-panel/index.d.ts +1 -0
- package/dist/components/composer-panel/index.js +1 -0
- package/dist/components/contribution-chart/ContributionChart.d.ts +25 -0
- package/dist/components/contribution-chart/ContributionChart.js +127 -0
- package/dist/components/contribution-chart/index.d.ts +1 -0
- package/dist/components/contribution-chart/index.js +1 -0
- package/dist/components/data-grid/DataGrid.d.ts +40 -0
- package/dist/components/data-grid/DataGrid.js +157 -0
- package/dist/components/data-grid/index.d.ts +1 -0
- package/dist/components/data-grid/index.js +1 -0
- package/dist/components/data-table/DataTable.d.ts +87 -0
- package/dist/components/data-table/DataTable.js +150 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/query.d.ts +54 -0
- package/dist/components/data-table/query.js +70 -0
- package/dist/components/date-picker/DatePicker.d.ts +25 -0
- package/dist/components/date-picker/DatePicker.js +154 -0
- package/dist/components/date-picker/index.d.ts +1 -0
- package/dist/components/date-picker/index.js +1 -0
- package/dist/components/dialog/ConfirmDialog.d.ts +25 -0
- package/dist/components/dialog/ConfirmDialog.js +69 -0
- package/dist/components/dialog/Dialog.d.ts +25 -0
- package/dist/components/dialog/Dialog.js +11 -0
- package/dist/components/dialog/DialogFrame.d.ts +22 -0
- package/dist/components/dialog/DialogFrame.js +21 -0
- package/dist/components/dialog/DiscardChangesDialog.d.ts +10 -0
- package/dist/components/dialog/DiscardChangesDialog.js +10 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/useDiscardOnClose.d.ts +20 -0
- package/dist/components/dialog/useDiscardOnClose.js +26 -0
- package/dist/components/dialog/useModalDialog.d.ts +20 -0
- package/dist/components/dialog/useModalDialog.js +85 -0
- package/dist/components/drawer/Drawer.d.ts +14 -0
- package/dist/components/drawer/Drawer.js +22 -0
- package/dist/components/drawer/index.d.ts +1 -0
- package/dist/components/drawer/index.js +1 -0
- package/dist/components/empty-state/EmptyState.d.ts +11 -0
- package/dist/components/empty-state/EmptyState.js +7 -0
- package/dist/components/empty-state/index.d.ts +1 -0
- package/dist/components/empty-state/index.js +1 -0
- package/dist/components/error-state/ErrorState.d.ts +8 -0
- package/dist/components/error-state/ErrorState.js +7 -0
- package/dist/components/error-state/index.d.ts +1 -0
- package/dist/components/error-state/index.js +1 -0
- package/dist/components/error-summary/ErrorSummary.d.ts +21 -0
- package/dist/components/error-summary/ErrorSummary.js +16 -0
- package/dist/components/error-summary/index.d.ts +1 -0
- package/dist/components/error-summary/index.js +1 -0
- package/dist/components/field/Field.d.ts +23 -0
- package/dist/components/field/Field.js +20 -0
- package/dist/components/field/index.d.ts +1 -0
- package/dist/components/field/index.js +1 -0
- package/dist/components/field-error/FieldError.d.ts +10 -0
- package/dist/components/field-error/FieldError.js +52 -0
- package/dist/components/field-error/index.d.ts +1 -0
- package/dist/components/field-error/index.js +1 -0
- package/dist/components/file-upload/FileUpload.d.ts +50 -0
- package/dist/components/file-upload/FileUpload.js +169 -0
- package/dist/components/file-upload/fileSize.d.ts +1 -0
- package/dist/components/file-upload/fileSize.js +13 -0
- package/dist/components/file-upload/index.d.ts +1 -0
- package/dist/components/file-upload/index.js +1 -0
- package/dist/components/form-section/FormSection.d.ts +16 -0
- package/dist/components/form-section/FormSection.js +14 -0
- package/dist/components/form-section/index.d.ts +1 -0
- package/dist/components/form-section/index.js +1 -0
- package/dist/components/form-steps/FormSteps.d.ts +18 -0
- package/dist/components/form-steps/FormSteps.js +26 -0
- package/dist/components/form-steps/index.d.ts +1 -0
- package/dist/components/form-steps/index.js +1 -0
- package/dist/components/funnel-chart/FunnelChart.d.ts +12 -0
- package/dist/components/funnel-chart/FunnelChart.js +69 -0
- package/dist/components/funnel-chart/index.d.ts +1 -0
- package/dist/components/funnel-chart/index.js +1 -0
- package/dist/components/header/Header.d.ts +14 -0
- package/dist/components/header/Header.js +31 -0
- package/dist/components/header/index.d.ts +1 -0
- package/dist/components/header/index.js +1 -0
- package/dist/components/heatmap-chart/HeatmapChart.d.ts +10 -0
- package/dist/components/heatmap-chart/HeatmapChart.js +76 -0
- package/dist/components/heatmap-chart/index.d.ts +1 -0
- package/dist/components/heatmap-chart/index.js +1 -0
- package/dist/components/image-error/ImageError.d.ts +11 -0
- package/dist/components/image-error/ImageError.js +16 -0
- package/dist/components/image-error/index.d.ts +1 -0
- package/dist/components/image-error/index.js +1 -0
- package/dist/components/image-loader/ImageLoader.d.ts +9 -0
- package/dist/components/image-loader/ImageLoader.js +10 -0
- package/dist/components/image-loader/index.d.ts +1 -0
- package/dist/components/image-loader/index.js +1 -0
- package/dist/components/index.d.ts +98 -0
- package/dist/components/index.js +97 -0
- package/dist/components/input/Input.d.ts +6 -0
- package/dist/components/input/Input.js +8 -0
- package/dist/components/input/index.d.ts +1 -0
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/inputStyle.d.ts +14 -0
- package/dist/components/input/inputStyle.js +35 -0
- package/dist/components/item-range/ItemRange.d.ts +11 -0
- package/dist/components/item-range/ItemRange.js +13 -0
- package/dist/components/item-range/index.d.ts +1 -0
- package/dist/components/item-range/index.js +1 -0
- package/dist/components/label/Label.d.ts +8 -0
- package/dist/components/label/Label.js +5 -0
- package/dist/components/label/index.d.ts +1 -0
- package/dist/components/label/index.js +1 -0
- package/dist/components/line-chart/LineChart.d.ts +10 -0
- package/dist/components/line-chart/LineChart.js +29 -0
- package/dist/components/line-chart/index.d.ts +1 -0
- package/dist/components/line-chart/index.js +1 -0
- package/dist/components/link-button/LinkButton.d.ts +29 -0
- package/dist/components/link-button/LinkButton.js +15 -0
- package/dist/components/link-button/index.d.ts +1 -0
- package/dist/components/link-button/index.js +1 -0
- package/dist/components/menu/Menu.d.ts +33 -0
- package/dist/components/menu/Menu.js +113 -0
- package/dist/components/menu/index.d.ts +1 -0
- package/dist/components/menu/index.js +1 -0
- package/dist/components/meter/Meter.d.ts +24 -0
- package/dist/components/meter/Meter.js +65 -0
- package/dist/components/meter/index.d.ts +1 -0
- package/dist/components/meter/index.js +1 -0
- package/dist/components/nav-group/NavGroup.d.ts +24 -0
- package/dist/components/nav-group/NavGroup.js +23 -0
- package/dist/components/nav-group/index.d.ts +1 -0
- package/dist/components/nav-group/index.js +1 -0
- package/dist/components/notification/Notification.d.ts +25 -0
- package/dist/components/notification/Notification.js +13 -0
- package/dist/components/notification/index.d.ts +1 -0
- package/dist/components/notification/index.js +1 -0
- package/dist/components/notification-center/NotificationCenter.d.ts +33 -0
- package/dist/components/notification-center/NotificationCenter.js +29 -0
- package/dist/components/notification-center/index.d.ts +1 -0
- package/dist/components/notification-center/index.js +1 -0
- package/dist/components/number-field/NumberField.d.ts +28 -0
- package/dist/components/number-field/NumberField.js +155 -0
- package/dist/components/number-field/index.d.ts +1 -0
- package/dist/components/number-field/index.js +1 -0
- package/dist/components/otp-input/OtpInput.d.ts +14 -0
- package/dist/components/otp-input/OtpInput.js +70 -0
- package/dist/components/otp-input/index.d.ts +1 -0
- package/dist/components/otp-input/index.js +1 -0
- package/dist/components/pagination/Pagination.d.ts +21 -0
- package/dist/components/pagination/Pagination.js +51 -0
- package/dist/components/pagination/index.d.ts +1 -0
- package/dist/components/pagination/index.js +1 -0
- package/dist/components/popover/Popover.d.ts +23 -0
- package/dist/components/popover/Popover.js +83 -0
- package/dist/components/popover/index.d.ts +1 -0
- package/dist/components/popover/index.js +1 -0
- package/dist/components/progress/Progress.d.ts +12 -0
- package/dist/components/progress/Progress.js +30 -0
- package/dist/components/progress/index.d.ts +1 -0
- package/dist/components/progress/index.js +1 -0
- package/dist/components/question-form/QuestionForm.d.ts +59 -0
- package/dist/components/question-form/QuestionForm.js +128 -0
- package/dist/components/question-form/index.d.ts +1 -0
- package/dist/components/question-form/index.js +1 -0
- package/dist/components/radar-chart/RadarChart.d.ts +3 -0
- package/dist/components/radar-chart/RadarChart.js +72 -0
- package/dist/components/radar-chart/geometry.d.ts +16 -0
- package/dist/components/radar-chart/geometry.js +56 -0
- package/dist/components/radar-chart/index.d.ts +1 -0
- package/dist/components/radar-chart/index.js +1 -0
- package/dist/components/radial-chart/RadialChart.d.ts +39 -0
- package/dist/components/radial-chart/RadialChart.js +135 -0
- package/dist/components/radial-chart/index.d.ts +1 -0
- package/dist/components/radial-chart/index.js +1 -0
- package/dist/components/radio/Radio.d.ts +31 -0
- package/dist/components/radio/Radio.js +24 -0
- package/dist/components/radio/index.d.ts +1 -0
- package/dist/components/radio/index.js +1 -0
- package/dist/components/reply-loader/ReplyLoader.d.ts +10 -0
- package/dist/components/reply-loader/ReplyLoader.js +9 -0
- package/dist/components/reply-loader/index.d.ts +1 -0
- package/dist/components/reply-loader/index.js +1 -0
- package/dist/components/sankey-chart/SankeyChart.d.ts +35 -0
- package/dist/components/sankey-chart/SankeyChart.js +218 -0
- package/dist/components/sankey-chart/index.d.ts +1 -0
- package/dist/components/sankey-chart/index.js +1 -0
- package/dist/components/scatter-chart/ScatterChart.d.ts +38 -0
- package/dist/components/scatter-chart/ScatterChart.js +69 -0
- package/dist/components/scatter-chart/index.d.ts +1 -0
- package/dist/components/scatter-chart/index.js +1 -0
- package/dist/components/search-field/SearchField.d.ts +17 -0
- package/dist/components/search-field/SearchField.js +92 -0
- package/dist/components/search-field/index.d.ts +1 -0
- package/dist/components/search-field/index.js +1 -0
- package/dist/components/segmented-control/SegmentedControl.d.ts +26 -0
- package/dist/components/segmented-control/SegmentedControl.js +38 -0
- package/dist/components/segmented-control/index.d.ts +1 -0
- package/dist/components/segmented-control/index.js +1 -0
- package/dist/components/select/Select.d.ts +11 -0
- package/dist/components/select/Select.js +30 -0
- package/dist/components/select/index.d.ts +1 -0
- package/dist/components/select/index.js +1 -0
- package/dist/components/separator/Separator.d.ts +14 -0
- package/dist/components/separator/Separator.js +12 -0
- package/dist/components/separator/index.d.ts +1 -0
- package/dist/components/separator/index.js +1 -0
- package/dist/components/settings-modal/SettingsModal.d.ts +35 -0
- package/dist/components/settings-modal/SettingsModal.js +120 -0
- package/dist/components/settings-modal/index.d.ts +1 -0
- package/dist/components/settings-modal/index.js +1 -0
- package/dist/components/sidebar/Sidebar.d.ts +30 -0
- package/dist/components/sidebar/Sidebar.js +30 -0
- package/dist/components/sidebar/index.d.ts +1 -0
- package/dist/components/sidebar/index.js +1 -0
- package/dist/components/skeleton/Skeleton.d.ts +6 -0
- package/dist/components/skeleton/Skeleton.js +6 -0
- package/dist/components/skeleton/index.d.ts +1 -0
- package/dist/components/skeleton/index.js +1 -0
- package/dist/components/skip-link/SkipLink.d.ts +8 -0
- package/dist/components/skip-link/SkipLink.js +10 -0
- package/dist/components/skip-link/index.d.ts +1 -0
- package/dist/components/skip-link/index.js +1 -0
- package/dist/components/slider/Slider.d.ts +19 -0
- package/dist/components/slider/Slider.js +49 -0
- package/dist/components/slider/index.d.ts +1 -0
- package/dist/components/slider/index.js +1 -0
- package/dist/components/spinner/Spinner.d.ts +5 -0
- package/dist/components/spinner/Spinner.js +7 -0
- package/dist/components/spinner/index.d.ts +1 -0
- package/dist/components/spinner/index.js +1 -0
- package/dist/components/stacked-bar/StackedBar.d.ts +29 -0
- package/dist/components/stacked-bar/StackedBar.js +77 -0
- package/dist/components/stacked-bar/index.d.ts +1 -0
- package/dist/components/stacked-bar/index.js +1 -0
- package/dist/components/stat-card/StatCard.d.ts +19 -0
- package/dist/components/stat-card/StatCard.js +32 -0
- package/dist/components/stat-card/index.d.ts +1 -0
- package/dist/components/stat-card/index.js +1 -0
- package/dist/components/switch/Switch.d.ts +10 -0
- package/dist/components/switch/Switch.js +22 -0
- package/dist/components/switch/index.d.ts +1 -0
- package/dist/components/switch/index.js +1 -0
- package/dist/components/table/SortableHeader.d.ts +12 -0
- package/dist/components/table/SortableHeader.js +11 -0
- package/dist/components/table/Table.d.ts +15 -0
- package/dist/components/table/Table.js +26 -0
- package/dist/components/table/align.d.ts +1 -0
- package/dist/components/table/align.js +5 -0
- package/dist/components/table/index.d.ts +4 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/tabs/Tabs.d.ts +38 -0
- package/dist/components/tabs/Tabs.js +137 -0
- package/dist/components/tabs/fitTabs.d.ts +18 -0
- package/dist/components/tabs/fitTabs.js +46 -0
- package/dist/components/tabs/index.d.ts +1 -0
- package/dist/components/tabs/index.js +1 -0
- package/dist/components/tag-group/TagGroup.d.ts +29 -0
- package/dist/components/tag-group/TagGroup.js +82 -0
- package/dist/components/tag-group/index.d.ts +1 -0
- package/dist/components/tag-group/index.js +1 -0
- package/dist/components/task-list/TaskList.d.ts +46 -0
- package/dist/components/task-list/TaskList.js +30 -0
- package/dist/components/task-list/index.d.ts +1 -0
- package/dist/components/task-list/index.js +1 -0
- package/dist/components/text-link/TextLink.d.ts +27 -0
- package/dist/components/text-link/TextLink.js +22 -0
- package/dist/components/text-link/index.d.ts +1 -0
- package/dist/components/text-link/index.js +1 -0
- package/dist/components/textarea/Textarea.d.ts +6 -0
- package/dist/components/textarea/Textarea.js +9 -0
- package/dist/components/textarea/index.d.ts +1 -0
- package/dist/components/textarea/index.js +1 -0
- package/dist/components/time-field/TimeField.d.ts +6 -0
- package/dist/components/time-field/TimeField.js +9 -0
- package/dist/components/time-field/index.d.ts +1 -0
- package/dist/components/time-field/index.js +1 -0
- package/dist/components/toast/Toast.d.ts +19 -0
- package/dist/components/toast/Toast.js +190 -0
- package/dist/components/toast/index.d.ts +1 -0
- package/dist/components/toast/index.js +1 -0
- package/dist/components/token-input/TokenInput.d.ts +27 -0
- package/dist/components/token-input/TokenInput.js +153 -0
- package/dist/components/token-input/index.d.ts +1 -0
- package/dist/components/token-input/index.js +1 -0
- package/dist/components/tooltip/Tooltip.d.ts +17 -0
- package/dist/components/tooltip/Tooltip.js +144 -0
- package/dist/components/tooltip/index.d.ts +1 -0
- package/dist/components/tooltip/index.js +1 -0
- package/dist/components/tree-view/TreeView.d.ts +29 -0
- package/dist/components/tree-view/TreeView.js +140 -0
- package/dist/components/tree-view/index.d.ts +1 -0
- package/dist/components/tree-view/index.js +1 -0
- package/dist/components/unsaved-changes/index.d.ts +1 -0
- package/dist/components/unsaved-changes/index.js +1 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.d.ts +12 -0
- package/dist/components/unsaved-changes/useUnsavedChanges.js +45 -0
- package/dist/components/usage-limit/UsageLimit.d.ts +15 -0
- package/dist/components/usage-limit/UsageLimit.js +21 -0
- package/dist/components/usage-limit/index.d.ts +1 -0
- package/dist/components/usage-limit/index.js +1 -0
- package/dist/components/web-search-results/WebSearchResults.d.ts +21 -0
- package/dist/components/web-search-results/WebSearchResults.js +17 -0
- package/dist/components/web-search-results/index.d.ts +1 -0
- package/dist/components/web-search-results/index.js +1 -0
- package/dist/lib/anchor.d.ts +21 -0
- package/dist/lib/anchor.js +50 -0
- package/dist/lib/cn.d.ts +1 -0
- package/dist/lib/cn.js +5 -0
- package/dist/lib/date.d.ts +77 -0
- package/dist/lib/date.js +165 -0
- package/dist/lib/icon-message.d.ts +16 -0
- package/dist/lib/icon-message.js +7 -0
- package/dist/lib/number.d.ts +1 -0
- package/dist/lib/number.js +5 -0
- package/dist/lib/slot.d.ts +8 -0
- package/dist/lib/slot.js +53 -0
- package/dist/lib/variant.d.ts +1 -0
- package/dist/lib/variant.js +1 -0
- package/docs/a11y.md +320 -0
- package/docs/chart/axis.md +82 -0
- package/docs/chart/color.md +120 -0
- package/docs/chart/drawing.md +283 -0
- package/docs/chart/reading.md +79 -0
- package/docs/chart/size-and-spacing.md +85 -0
- package/docs/chart.md +47 -0
- package/docs/color/contrast.md +80 -0
- package/docs/color/data-viz.md +66 -0
- package/docs/color/foundation.md +91 -0
- package/docs/color/neutral.md +88 -0
- package/docs/color/state.md +111 -0
- package/docs/color.md +22 -0
- package/docs/components/accordion.md +51 -0
- package/docs/components/agent-form.md +56 -0
- package/docs/components/agent-steps.md +75 -0
- package/docs/components/agent-thinking.md +70 -0
- package/docs/components/area-chart.md +55 -0
- package/docs/components/auth-card.md +126 -0
- package/docs/components/avatar.md +38 -0
- package/docs/components/badge.md +28 -0
- package/docs/components/banner.md +19 -0
- package/docs/components/bar-list.md +77 -0
- package/docs/components/button-group.md +74 -0
- package/docs/components/button.md +49 -0
- package/docs/components/calendar-view.md +106 -0
- package/docs/components/calendar.md +44 -0
- package/docs/components/carousel.md +81 -0
- package/docs/components/chart.md +45 -0
- package/docs/components/chat-message.md +199 -0
- package/docs/components/checkbox.md +27 -0
- package/docs/components/chip.md +34 -0
- package/docs/components/choosing.md +26 -0
- package/docs/components/close-button.md +17 -0
- package/docs/components/color-picker.md +52 -0
- package/docs/components/combo-chart.md +74 -0
- package/docs/components/combobox.md +60 -0
- package/docs/components/command-palette.md +151 -0
- package/docs/components/composer-attachments.md +116 -0
- package/docs/components/composer-panel.md +106 -0
- package/docs/components/composer.md +163 -0
- package/docs/components/contribution-chart.md +70 -0
- package/docs/components/data-grid.md +132 -0
- package/docs/components/data-table.md +165 -0
- package/docs/components/date-picker.md +120 -0
- package/docs/components/dialog.md +211 -0
- package/docs/components/drawer.md +38 -0
- package/docs/components/empty-state.md +17 -0
- package/docs/components/error-state.md +13 -0
- package/docs/components/error-summary.md +49 -0
- package/docs/components/field.md +84 -0
- package/docs/components/file-upload.md +161 -0
- package/docs/components/focus.md +25 -0
- package/docs/components/form-section.md +49 -0
- package/docs/components/form-steps.md +63 -0
- package/docs/components/funnel-chart.md +49 -0
- package/docs/components/heatmap-chart.md +64 -0
- package/docs/components/image-error.md +73 -0
- package/docs/components/image-loader.md +53 -0
- package/docs/components/input.md +21 -0
- package/docs/components/item-range.md +10 -0
- package/docs/components/link-button.md +16 -0
- package/docs/components/menu.md +115 -0
- package/docs/components/meter.md +83 -0
- package/docs/components/nav-group.md +33 -0
- package/docs/components/notification-center.md +100 -0
- package/docs/components/notification.md +127 -0
- package/docs/components/number-field.md +128 -0
- package/docs/components/otp-input.md +86 -0
- package/docs/components/pagination.md +29 -0
- package/docs/components/popover.md +43 -0
- package/docs/components/progress.md +25 -0
- package/docs/components/prohibitions.md +58 -0
- package/docs/components/props.md +20 -0
- package/docs/components/question-form.md +125 -0
- package/docs/components/radar-chart.md +61 -0
- package/docs/components/radial-chart.md +74 -0
- package/docs/components/radio.md +24 -0
- package/docs/components/reply-loader.md +80 -0
- package/docs/components/sankey-chart.md +71 -0
- package/docs/components/scatter-chart.md +61 -0
- package/docs/components/search-field.md +44 -0
- package/docs/components/segmented-control.md +35 -0
- package/docs/components/select.md +28 -0
- package/docs/components/separator.md +23 -0
- package/docs/components/settings-modal.md +128 -0
- package/docs/components/sidebar.md +145 -0
- package/docs/components/skeleton.md +27 -0
- package/docs/components/skip-link.md +17 -0
- package/docs/components/slider.md +82 -0
- package/docs/components/spinner.md +8 -0
- package/docs/components/stacked-bar.md +66 -0
- package/docs/components/stat-card.md +78 -0
- package/docs/components/switch.md +61 -0
- package/docs/components/table.md +43 -0
- package/docs/components/tabs.md +104 -0
- package/docs/components/tag-group.md +115 -0
- package/docs/components/task-list.md +99 -0
- package/docs/components/text-link.md +17 -0
- package/docs/components/textarea.md +27 -0
- package/docs/components/time-field.md +97 -0
- package/docs/components/toast.md +73 -0
- package/docs/components/token-input.md +135 -0
- package/docs/components/tooltip.md +41 -0
- package/docs/components/tree-view.md +71 -0
- package/docs/components/usage-limit.md +47 -0
- package/docs/components/web-search-results.md +60 -0
- package/docs/components.md +234 -0
- package/docs/design.md +31 -0
- package/docs/form/clearing-errors.md +28 -0
- package/docs/form/error-announcement.md +69 -0
- package/docs/form/long-forms.md +103 -0
- package/docs/form/placeholder.md +40 -0
- package/docs/form/submit-errors.md +102 -0
- package/docs/form/submitting.md +72 -0
- package/docs/form/unsaved-changes.md +146 -0
- package/docs/form/validation-timing.md +44 -0
- package/docs/form.md +39 -0
- package/docs/glossary.md +169 -0
- package/docs/icon.md +245 -0
- package/docs/interaction/before.md +64 -0
- package/docs/interaction/motion.md +38 -0
- package/docs/interaction/pending.md +38 -0
- package/docs/interaction/permissions.md +133 -0
- package/docs/interaction/result.md +38 -0
- package/docs/interaction/states.md +159 -0
- package/docs/interaction.md +31 -0
- package/docs/layout/alignment.md +145 -0
- package/docs/layout/hit-area.md +58 -0
- package/docs/layout/mobile.md +200 -0
- package/docs/layout/responsive.md +73 -0
- package/docs/layout/scroll.md +51 -0
- package/docs/layout/surface.md +110 -0
- package/docs/layout.md +31 -0
- package/docs/list/board.md +85 -0
- package/docs/list/paging.md +146 -0
- package/docs/list/search.md +98 -0
- package/docs/list/toolbar.md +91 -0
- package/docs/list.md +39 -0
- package/docs/log.md +94 -0
- package/docs/manual.md +152 -0
- package/docs/navigation/header-and-transition.md +82 -0
- package/docs/navigation/location.md +68 -0
- package/docs/navigation/menu-items.md +152 -0
- package/docs/navigation/menu-structure.md +68 -0
- package/docs/navigation.md +23 -0
- package/docs/rules.md +246 -0
- package/docs/scenario.md +218 -0
- package/docs/spacing/placement.md +219 -0
- package/docs/spacing/radius.md +45 -0
- package/docs/spacing/scale.md +91 -0
- package/docs/spacing.md +17 -0
- package/docs/typography.md +233 -0
- package/docs/writing/date-and-number.md +25 -0
- package/docs/writing/error-and-empty.md +58 -0
- package/docs/writing/label-and-button.md +124 -0
- package/docs/writing/tone.md +156 -0
- package/docs/writing.md +27 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +3 -0
- package/package.json +115 -4
- package/scripts/lint/colors.mjs +103 -0
- package/scripts/lint/deps.mjs +33 -0
- package/scripts/lint/icons.mjs +177 -0
- package/scripts/lint/interaction.mjs +163 -0
- package/scripts/lint/layout.mjs +103 -0
- package/scripts/lint/markup.mjs +271 -0
- package/scripts/lint/shared.mjs +340 -0
- package/scripts/lint/spacing.mjs +70 -0
- package/scripts/lint/typography.mjs +141 -0
- package/scripts/lint/writing.mjs +107 -0
- package/scripts/lint.mjs +166 -0
- package/scripts/plain-ui-lint.mjs +33 -0
- package/tokens/tokens.css +482 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { cn } from "../../lib/cn.js";
|
|
5
|
+
import { Input } from "../input/Input.js";
|
|
6
|
+
import { Table, TableBody, TableHead, TableHeaderCell, TableRow } from "../table/Table.js";
|
|
7
|
+
import { headerAlign } from "../table/align.js";
|
|
8
|
+
const cellKey = ({ row, col }) => `${row}-${col}`;
|
|
9
|
+
// セル。編集していないときの今のセルは、フォーカスの輪を内側に描いて示す(隣のセルの線に重ねない)
|
|
10
|
+
const cellClass = "align-middle font-normal text-foreground outline-none focus:ring-2 focus:ring-inset focus:ring-ring";
|
|
11
|
+
// 文字のセルは44pxの高さ(表のセルの高さは最小の高さになる)にし、編集を始めたときの入力欄(Input、44px)と行の高さをそろえる。
|
|
12
|
+
// 余白は片方だけを付ける(cn はクラスの競合を解かない)
|
|
13
|
+
const cellViewClass = "h-11 px-4 py-2 leading-tight";
|
|
14
|
+
const cellEditClass = "p-0";
|
|
15
|
+
// 見出しの行は、枠の中で縦にスクロールしても上端に残す。固定した見出しのセルは、下の行が透けないように見出しの面(bg-muted)を塗る。
|
|
16
|
+
// border-collapse の線は固定したセルと一緒に動かないため、行の区切りの線は ::after で見出しのセルの下端に描く
|
|
17
|
+
const stickyHeaderClass = "sticky top-0 bg-muted after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border";
|
|
18
|
+
// 表計算のようにセルを編集する表(WAI-ARIA APG の Data Grid パターン)。
|
|
19
|
+
// ネイティブの表に role="grid" を付け、セルの移動は roving tabindex で受け持つ。
|
|
20
|
+
// 値は使う側が rows と onChange で持つ。今のセルと、編集中の値だけを部品の中に持つ
|
|
21
|
+
export function DataGrid({ columns, rows, onChange, className, ...props }) {
|
|
22
|
+
const baseId = useId();
|
|
23
|
+
// 今のセルと、編集中の入力欄。どちらも同時に1つだけなので、描いた要素を ref で受け取る
|
|
24
|
+
const currentCellRef = useRef(null);
|
|
25
|
+
const inputRef = useRef(null);
|
|
26
|
+
const [active, setActive] = useState({ row: 0, col: 0 });
|
|
27
|
+
const [editing, setEditing] = useState(null);
|
|
28
|
+
// blur と Enter が続けて起きても、1回だけ確定する。state は描き直すまで古い値のままなので、ref でも持つ
|
|
29
|
+
const editingRef = useRef(null);
|
|
30
|
+
// 描いた後に、今のセルへフォーカスを移すかどうか(矢印キー、編集の確定と取り消しのとき)
|
|
31
|
+
const focusCell = useRef(false);
|
|
32
|
+
const composingRef = useRef(false);
|
|
33
|
+
// 行や列が減っても、今のセルを表の中に保つ
|
|
34
|
+
const current = {
|
|
35
|
+
row: Math.max(0, Math.min(active.row, rows.length - 1)),
|
|
36
|
+
col: Math.max(0, Math.min(active.col, columns.length - 1)),
|
|
37
|
+
};
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!focusCell.current)
|
|
40
|
+
return;
|
|
41
|
+
focusCell.current = false;
|
|
42
|
+
currentCellRef.current?.focus();
|
|
43
|
+
});
|
|
44
|
+
// 編集を始めたら、入力欄へフォーカスを移し、文字の末尾に入力の位置を置く(値を消さない)
|
|
45
|
+
const editingKey = editing ? cellKey(editing) : null;
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!editingKey)
|
|
48
|
+
return;
|
|
49
|
+
const input = inputRef.current;
|
|
50
|
+
if (!input)
|
|
51
|
+
return;
|
|
52
|
+
input.focus();
|
|
53
|
+
input.setSelectionRange(input.value.length, input.value.length);
|
|
54
|
+
}, [editingKey]);
|
|
55
|
+
function startEdit(position) {
|
|
56
|
+
const column = columns[position.col];
|
|
57
|
+
const row = rows[position.row];
|
|
58
|
+
if (!column || !row || column.readOnly)
|
|
59
|
+
return;
|
|
60
|
+
const next = { ...position, draft: row[column.key] ?? "" };
|
|
61
|
+
editingRef.current = next;
|
|
62
|
+
setEditing(next);
|
|
63
|
+
}
|
|
64
|
+
// 編集を終える。commit なら、値が変わったときだけ onChange で知らせる
|
|
65
|
+
function finishEdit(commit, returnFocus) {
|
|
66
|
+
const edit = editingRef.current;
|
|
67
|
+
if (!edit)
|
|
68
|
+
return;
|
|
69
|
+
editingRef.current = null;
|
|
70
|
+
composingRef.current = false;
|
|
71
|
+
const column = columns[edit.col];
|
|
72
|
+
const row = rows[edit.row];
|
|
73
|
+
if (commit && column && row && edit.draft !== (row[column.key] ?? ""))
|
|
74
|
+
onChange(row.id, column.key, edit.draft);
|
|
75
|
+
setEditing(null);
|
|
76
|
+
if (returnFocus)
|
|
77
|
+
focusCell.current = true;
|
|
78
|
+
}
|
|
79
|
+
// from はキーを押したセル。state の今のセルではなく、フォーカスのあるセルから移る
|
|
80
|
+
function onCellKeyDown(from, event) {
|
|
81
|
+
// 編集中の入力欄のキーは、入力欄の側で受ける
|
|
82
|
+
if (event.target !== event.currentTarget)
|
|
83
|
+
return;
|
|
84
|
+
if (event.key === "Enter" || event.key === "F2") {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
startEdit(from);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const lastRow = rows.length - 1;
|
|
90
|
+
const lastCol = columns.length - 1;
|
|
91
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
92
|
+
// 端では止まる(反対の端へは回らない。APG の Data Grid と同じ)
|
|
93
|
+
const next = {
|
|
94
|
+
ArrowLeft: () => ({ row: from.row, col: Math.max(0, from.col - 1) }),
|
|
95
|
+
ArrowRight: () => ({ row: from.row, col: Math.min(lastCol, from.col + 1) }),
|
|
96
|
+
ArrowUp: () => ({ row: Math.max(0, from.row - 1), col: from.col }),
|
|
97
|
+
ArrowDown: () => ({ row: Math.min(lastRow, from.row + 1), col: from.col }),
|
|
98
|
+
// Ctrl(Mac では Command)を押しながらなら、表の最初と最後のセルへ移る
|
|
99
|
+
Home: () => (ctrl ? { row: 0, col: 0 } : { row: from.row, col: 0 }),
|
|
100
|
+
End: () => (ctrl ? { row: lastRow, col: lastCol } : { row: from.row, col: lastCol }),
|
|
101
|
+
}[event.key];
|
|
102
|
+
if (!next)
|
|
103
|
+
return;
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
const target = next();
|
|
106
|
+
if (target.row === from.row && target.col === from.col)
|
|
107
|
+
return;
|
|
108
|
+
focusCell.current = true;
|
|
109
|
+
setActive(target);
|
|
110
|
+
}
|
|
111
|
+
function onInputKeyDown(event) {
|
|
112
|
+
// かな漢字の変換を確定する Enter と Esc では、編集を終えない
|
|
113
|
+
if (event.nativeEvent.isComposing || composingRef.current)
|
|
114
|
+
return;
|
|
115
|
+
if (event.key === "Enter") {
|
|
116
|
+
// フォームの中に置いても、送信しない
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
finishEdit(true, true);
|
|
119
|
+
}
|
|
120
|
+
else if (event.key === "Escape") {
|
|
121
|
+
// ダイアログの中に置いても、ダイアログを閉じずに編集だけを取り消す
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
event.stopPropagation();
|
|
124
|
+
finishEdit(false, true);
|
|
125
|
+
}
|
|
126
|
+
// Tab と Shift+Tab は止めない。blur で確定し、フォーカスは表の外の次(前)の要素へ移る
|
|
127
|
+
}
|
|
128
|
+
const colHeaderId = (col) => `${baseId}-col-${col}`;
|
|
129
|
+
const rowHeaderId = (row) => `${baseId}-row-${row}`;
|
|
130
|
+
return (_jsx("div", { className: cn("w-full overflow-auto scroll-pt-9", className), children: _jsxs(Table, { role: "grid", ...props, children: [_jsx(TableHead, { children: _jsx(TableRow, { children: columns.map((column, col) => (_jsx(TableHeaderCell, { id: colHeaderId(col), className: cn(stickyHeaderClass, column.className), children: column.label }, column.key))) }) }), _jsx(TableBody, { children: rows.map((row, rowIndex) => (_jsx(TableRow, { children: columns.map((column, col) => {
|
|
131
|
+
const position = { row: rowIndex, col };
|
|
132
|
+
const isCurrent = rowIndex === current.row && col === current.col;
|
|
133
|
+
const isEditing = editing !== null && editing.row === rowIndex && editing.col === col;
|
|
134
|
+
// 最初の列は行の見出しにし、ほかの列へ移ったときも、どの行かを読み上げで伝える
|
|
135
|
+
const Cell = col === 0 ? "th" : "td";
|
|
136
|
+
return (_jsx(Cell, { id: col === 0 ? rowHeaderId(rowIndex) : undefined, scope: col === 0 ? "row" : undefined, ref: isCurrent ? currentCellRef : undefined,
|
|
137
|
+
// roving tabindex:Tabキーで止まるのは今のセルだけ。編集中は入力欄に止まり、セルには止まらない
|
|
138
|
+
tabIndex: isCurrent && !isEditing ? 0 : -1, "aria-readonly": column.readOnly || undefined, onFocus: event => {
|
|
139
|
+
if (event.target === event.currentTarget && !isCurrent)
|
|
140
|
+
setActive(position);
|
|
141
|
+
}, onKeyDown: event => onCellKeyDown(position, event), onDoubleClick: () => {
|
|
142
|
+
if (!isEditing)
|
|
143
|
+
startEdit(position);
|
|
144
|
+
}, className: cn(cellClass, isEditing ? cellEditClass : cellViewClass, headerAlign(column.className), column.className), children: isEditing ? (_jsx(Input, { ref: inputRef, value: editing.draft, inputMode: column.inputMode,
|
|
145
|
+
// 入力欄の既定の幅(20文字分)で列を広げない。幅はセルに合わせる
|
|
146
|
+
size: 1, "aria-labelledby": col === 0 ? colHeaderId(col) : `${colHeaderId(col)} ${rowHeaderId(rowIndex)}`, onChange: event => {
|
|
147
|
+
const edit = editingRef.current;
|
|
148
|
+
if (!edit)
|
|
149
|
+
return;
|
|
150
|
+
const next = { ...edit, draft: event.target.value };
|
|
151
|
+
editingRef.current = next;
|
|
152
|
+
setEditing(next);
|
|
153
|
+
}, onKeyDown: onInputKeyDown, onCompositionStart: () => (composingRef.current = true), onCompositionEnd: () => (composingRef.current = false),
|
|
154
|
+
// Tab で表の外へ出たときと、別のセルを押したときは確定する(表計算と同じ)
|
|
155
|
+
onBlur: () => finishEdit(true, false) })) : (row[column.key]) }, column.key));
|
|
156
|
+
}) }, row.id))) })] }) }));
|
|
157
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./DataGrid.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./DataGrid.js";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type PaginationLinkProps } from "../pagination/Pagination.js";
|
|
3
|
+
import { type DataTableFilter, type DataTableSort } from "./query.js";
|
|
4
|
+
export interface DataTableColumn<T> {
|
|
5
|
+
/** 列を見分けるキー。並べ替えのできる列では、クエリの `sort` に書く値になる */
|
|
6
|
+
key: string;
|
|
7
|
+
/** 列の見出し */
|
|
8
|
+
header: string;
|
|
9
|
+
/** セルの中身 */
|
|
10
|
+
cell: (row: T) => ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* 並べ替えのできる列に渡す、768px未満の並び順の選択に出す文言(「更新日が古い順」「更新日が新しい順」)。
|
|
13
|
+
* 渡した列だけ、見出しを並べ替えのボタンにする
|
|
14
|
+
*/
|
|
15
|
+
sort?: {
|
|
16
|
+
asc: string;
|
|
17
|
+
desc: string;
|
|
18
|
+
};
|
|
19
|
+
/** 揃え(text-right)、折り返し(whitespace-nowrap、min-w-48)、隠す列の条件(hidden @3xl:table-cell)だけに使う。見出しとセルの両方に付く */
|
|
20
|
+
className?: string;
|
|
21
|
+
/** 縦並びの一覧にも出す。先頭の列はタイトルとしていつも出すので、2列目からのうち、状態と判断に要る列にだけ付ける */
|
|
22
|
+
list?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** 選んでいる行。まとめての操作に渡す */
|
|
25
|
+
export interface DataTableSelection {
|
|
26
|
+
/** 選んだ行の rowKey。all が true のときは、今のページの行の rowKey */
|
|
27
|
+
ids: string[];
|
|
28
|
+
/** 今の検索と絞り込みに一致するすべての項目を選んでいる。true のときは、ids ではなく条件で操作する */
|
|
29
|
+
all: boolean;
|
|
30
|
+
/** 選んでいる件数。確認のダイアログのタイトルに書く */
|
|
31
|
+
count: number;
|
|
32
|
+
/** 選択を外す。まとめての操作を終えた後に呼ぶ */
|
|
33
|
+
clear: () => void;
|
|
34
|
+
}
|
|
35
|
+
type SelectionProps<T> = {
|
|
36
|
+
/** まとめての操作のボタン。1件でも選ぶと、検索と絞り込みの場所に出す */
|
|
37
|
+
bulkActions: (selection: DataTableSelection) => ReactNode;
|
|
38
|
+
/** 行のチェックボックスの名前に使う、行のタイトル(「「週次の定例の議事録」を選ぶ」) */
|
|
39
|
+
rowLabel: (row: T) => string;
|
|
40
|
+
} | {
|
|
41
|
+
bulkActions?: undefined;
|
|
42
|
+
rowLabel?: undefined;
|
|
43
|
+
};
|
|
44
|
+
export type DataTableStatus = "ready" | "loading" | "error";
|
|
45
|
+
export type DataTableProps<T> = SelectionProps<T> & {
|
|
46
|
+
/** 一覧の項目の名前(「ドキュメント」)。表の名前(「ドキュメントの一覧」)、検索欄の名前、0件の文言に使う */
|
|
47
|
+
itemName: string;
|
|
48
|
+
columns: DataTableColumn<T>[];
|
|
49
|
+
/** 絞り込みの項目。3つまでは検索欄の隣に、4つ以上はポップオーバーにまとめる */
|
|
50
|
+
filters?: DataTableFilter[];
|
|
51
|
+
/** 並べ替えの初めの列と向き */
|
|
52
|
+
defaultSort: DataTableSort;
|
|
53
|
+
/** 検索欄を置く。省いたときは置く */
|
|
54
|
+
searchable?: boolean;
|
|
55
|
+
/** 今のURLのクエリ。表示するたびに、ここから状態を読む */
|
|
56
|
+
searchParams: URLSearchParams;
|
|
57
|
+
/** 状態を変えたときに、新しいクエリで呼ぶ。replace が true のとき(検索)は、履歴に足さずに今のURLを置き換える */
|
|
58
|
+
onNavigate: (next: URLSearchParams, options: {
|
|
59
|
+
replace: boolean;
|
|
60
|
+
}) => void;
|
|
61
|
+
/** ページ送りのリンクの先を、クエリから作る。省いたときは `?<クエリ>` */
|
|
62
|
+
href?: (next: URLSearchParams) => string;
|
|
63
|
+
/** ページ送りをルーターのリンクで描くときに渡す(Pagination の renderLink) */
|
|
64
|
+
renderLink?: (props: PaginationLinkProps) => ReactNode;
|
|
65
|
+
/** 今のページの行。検索、絞り込み、並べ替え、ページ分けは、使う側が readDataTableQuery で読んだ状態で済ませておく */
|
|
66
|
+
rows: T[];
|
|
67
|
+
/** 今の検索と絞り込みに一致する、全体の件数 */
|
|
68
|
+
total: number;
|
|
69
|
+
/** 行を見分けるキー */
|
|
70
|
+
rowKey: (row: T) => string;
|
|
71
|
+
/** 取得の状態。省いたときは ready */
|
|
72
|
+
status?: DataTableStatus;
|
|
73
|
+
/** 取得に失敗したときの「もう一度読み込む」 */
|
|
74
|
+
onRetry: () => void;
|
|
75
|
+
/** データがまだないときの空の状態。検索や絞り込みで0件のときは、部品が「絞り込みを解除する」を出す */
|
|
76
|
+
empty: {
|
|
77
|
+
message: string;
|
|
78
|
+
actionLabel: string;
|
|
79
|
+
onAction: () => void;
|
|
80
|
+
};
|
|
81
|
+
/** 行ごとの操作のボタン。表では末尾の列に、縦並びの一覧では項目の下に並べる */
|
|
82
|
+
rowActions?: (row: T) => ReactNode;
|
|
83
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
84
|
+
className?: string;
|
|
85
|
+
};
|
|
86
|
+
export declare function DataTable<T>(props: DataTableProps<T>): import("react").JSX.Element;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { Button } from "../button/Button.js";
|
|
5
|
+
import { Checkbox } from "../checkbox/Checkbox.js";
|
|
6
|
+
import { Chip } from "../chip/Chip.js";
|
|
7
|
+
import { EmptyState } from "../empty-state/EmptyState.js";
|
|
8
|
+
import { ErrorState } from "../error-state/ErrorState.js";
|
|
9
|
+
import { ItemRange } from "../item-range/ItemRange.js";
|
|
10
|
+
import { Label } from "../label/Label.js";
|
|
11
|
+
import { Pagination } from "../pagination/Pagination.js";
|
|
12
|
+
import { Popover } from "../popover/Popover.js";
|
|
13
|
+
import { SearchField } from "../search-field/SearchField.js";
|
|
14
|
+
import { Select } from "../select/Select.js";
|
|
15
|
+
import { Skeleton } from "../skeleton/Skeleton.js";
|
|
16
|
+
import { SortableHeader } from "../table/SortableHeader.js";
|
|
17
|
+
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from "../table/Table.js";
|
|
18
|
+
import { cn } from "../../lib/cn.js";
|
|
19
|
+
import { formatNumber } from "../../lib/number.js";
|
|
20
|
+
import { PER_PAGE_OPTIONS, hasConditions, isReservedKey, readDataTableQuery, writeDataTableQuery, } from "./query.js";
|
|
21
|
+
// 表にする幅。行ごとの操作のボタンを持つ表は、広い幅を条件にする(docs/layout/mobile.md)。
|
|
22
|
+
// クラス名を組み立てず、そのまま書く(Tailwind がクラスを読み取れるように)
|
|
23
|
+
const layouts = {
|
|
24
|
+
plain: { table: "hidden @2xl:block", list: "@2xl:hidden" },
|
|
25
|
+
actions: { table: "hidden @3xl:block", list: "@3xl:hidden" },
|
|
26
|
+
};
|
|
27
|
+
const SKELETON_ROWS = [0, 1, 2, 3, 4];
|
|
28
|
+
const FOCUSABLE = "input:not(:disabled), select:not(:disabled), button:not(:disabled)";
|
|
29
|
+
const toDirection = (sort, key) => sort.key !== key ? "none" : sort.order === "asc" ? "ascending" : "descending";
|
|
30
|
+
// 読んで比べる・行ごとに操作する表。Table に、検索、絞り込み、並べ替え、複数選択とまとめての操作、件数と範囲、ページ送りを組み合わせる(docs/list.md)。
|
|
31
|
+
// 状態はURLのクエリだけに持ち、部品はURLに触らない。読むクエリは searchParams で受け取り、変えたクエリは onNavigate で知らせる。
|
|
32
|
+
// データの取得、検索、並べ替えはしない。使う側が、同じ readDataTableQuery で読んだ状態で取得した今のページの行を rows で渡す。
|
|
33
|
+
// 置き場所の幅が足りないときは、同じ行を縦並びの一覧で見せる(docs/layout/mobile.md)。幅は、部品の外側の @container で測る
|
|
34
|
+
export function DataTable(props) {
|
|
35
|
+
const { itemName, columns, filters = [], defaultSort, searchable = true, searchParams, onNavigate, href = defaultHref, renderLink, rows, total, rowKey, status = "ready", onRetry, empty, rowActions, bulkActions, rowLabel, className, } = props;
|
|
36
|
+
const config = { columns, filters, defaultSort };
|
|
37
|
+
const query = readDataTableQuery(searchParams, config);
|
|
38
|
+
// 選択を外す・フォーカスを移す時機の目印。データテーブルの持つ状態だけを並べた文字列にする
|
|
39
|
+
const queryKey = writeDataTableQuery(new URLSearchParams(), query, config).toString();
|
|
40
|
+
const filterKeys = filters.map(f => f.key).join(",");
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const reserved = filterKeys.split(",").filter(key => key !== "" && isReservedKey(key));
|
|
43
|
+
if (reserved.length > 0)
|
|
44
|
+
console.warn(`DataTable: 絞り込みのキー ${reserved.join("、")} は、検索、並べ替え、ページのクエリとぶつかる。別の名前にする`);
|
|
45
|
+
}, [filterKeys]);
|
|
46
|
+
const navigate = (patch, replace = false) => {
|
|
47
|
+
// 検索、絞り込み、並べ替え、1ページの件数を変えたときは、1ページ目に戻す(docs/list/paging.md の LIST-004)
|
|
48
|
+
const next = { ...query, page: 1, ...patch };
|
|
49
|
+
onNavigate(writeDataTableQuery(searchParams, next, config), { replace });
|
|
50
|
+
};
|
|
51
|
+
// 選択はURLに持たない。ページと条件が変わったら外す(LIST-010)。選んだ時の queryKey と今の queryKey が違えば、選んでいないとして読む
|
|
52
|
+
const [selectionState, setSelectionState] = useState({ key: queryKey, ids: [], all: false });
|
|
53
|
+
const pageIds = status === "ready" ? rows.map(rowKey) : [];
|
|
54
|
+
const current = selectionState.key === queryKey ? selectionState : { key: queryKey, ids: [], all: false };
|
|
55
|
+
// 読み込み直して消えた行は、選んだままにしない
|
|
56
|
+
const selectedIds = current.all ? pageIds : current.ids.filter(id => pageIds.includes(id));
|
|
57
|
+
const selectedCount = current.all ? total : selectedIds.length;
|
|
58
|
+
const selecting = bulkActions !== undefined && selectedCount > 0;
|
|
59
|
+
const pageSelected = pageIds.length > 0 && pageIds.every(id => selectedIds.includes(id));
|
|
60
|
+
const setSelection = (ids, all = false) => setSelectionState({ key: queryKey, ids, all });
|
|
61
|
+
const toggleRow = (id) => setSelection(selectedIds.includes(id) ? selectedIds.filter(i => i !== id) : [...selectedIds, id]);
|
|
62
|
+
const togglePage = () => setSelection(pageSelected ? [] : pageIds);
|
|
63
|
+
const toolbarRef = useRef(null);
|
|
64
|
+
const chipsRef = useRef(null);
|
|
65
|
+
const pendingFocus = useRef(null);
|
|
66
|
+
// 押した要素が消えた後に、フォーカスを残すところへ移す。URLを変えたときは、新しいクエリで描き直されるまで待つ
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const pending = pendingFocus.current;
|
|
69
|
+
if (!pending || pending.waitFor === queryKey)
|
|
70
|
+
return;
|
|
71
|
+
pendingFocus.current = null;
|
|
72
|
+
const visible = (el) => el.checkVisibility?.() ?? true;
|
|
73
|
+
const chips = [...(chipsRef.current?.querySelectorAll("button") ?? [])];
|
|
74
|
+
const chip = typeof pending.target === "object" && chips.length > 0 ? chips[Math.min(pending.target.chip, chips.length - 1)] : undefined;
|
|
75
|
+
const fallback = [...(toolbarRef.current?.querySelectorAll(FOCUSABLE) ?? [])].find(visible);
|
|
76
|
+
(chip ?? fallback)?.focus();
|
|
77
|
+
});
|
|
78
|
+
const clearSelection = () => {
|
|
79
|
+
pendingFocus.current = { target: "toolbar" };
|
|
80
|
+
setSelection([]);
|
|
81
|
+
};
|
|
82
|
+
const selection = { ids: selectedIds, all: current.all, count: selectedCount, clear: () => setSelection([]) };
|
|
83
|
+
const setFilter = (key, value) => {
|
|
84
|
+
const next = { ...query.filters };
|
|
85
|
+
if (value === "")
|
|
86
|
+
delete next[key];
|
|
87
|
+
else
|
|
88
|
+
next[key] = value;
|
|
89
|
+
navigate({ filters: next });
|
|
90
|
+
};
|
|
91
|
+
const activeFilters = filters.flatMap(f => {
|
|
92
|
+
const option = f.options.find(o => o.value === query.filters[f.key]);
|
|
93
|
+
return option ? [{ key: f.key, text: `${f.label}:${option.label}` }] : [];
|
|
94
|
+
});
|
|
95
|
+
const removeFilter = (key, index) => {
|
|
96
|
+
pendingFocus.current = { target: { chip: index }, waitFor: queryKey };
|
|
97
|
+
setFilter(key, "");
|
|
98
|
+
};
|
|
99
|
+
const clearConditions = () => {
|
|
100
|
+
pendingFocus.current = { target: "toolbar", waitFor: queryKey };
|
|
101
|
+
navigate({ q: "", filters: {} });
|
|
102
|
+
};
|
|
103
|
+
const sortBy = (key) => {
|
|
104
|
+
// 今の列なら向きを替え、ほかの列なら昇順から始める
|
|
105
|
+
const order = query.sort.key === key && query.sort.order === "asc" ? "desc" : "asc";
|
|
106
|
+
navigate({ sort: { key, order } });
|
|
107
|
+
};
|
|
108
|
+
const sortOptions = columns.flatMap(c => c.sort ? [{ value: `${c.key}:asc`, label: c.sort.asc }, { value: `${c.key}:desc`, label: c.sort.desc }] : []);
|
|
109
|
+
const layout = layouts[rowActions ? "actions" : "plain"];
|
|
110
|
+
const ready = status === "ready";
|
|
111
|
+
const filtered = hasConditions(query);
|
|
112
|
+
const showResults = ready && total > 0;
|
|
113
|
+
const pageCount = Math.ceil(total / query.perPage);
|
|
114
|
+
const [first, ...rest] = columns;
|
|
115
|
+
const listColumns = rest.filter(c => c.list);
|
|
116
|
+
return (_jsxs("div", { className: cn("@container space-y-4", className), children: [_jsxs("div", { ref: toolbarRef, className: "flex flex-wrap items-center gap-2", children: [bulkActions && (_jsx("p", { role: "status", className: "text-sm empty:sr-only", children: selecting ? `${formatNumber(selectedCount)}件を選択中` : "" })), selecting ? (_jsxs(_Fragment, { children: [bulkActions(selection), pageSelected && !current.all && total > pageIds.length && (_jsx(Button, { variant: "muted", size: "sm", onClick: () => setSelection(pageIds, true), children: `すべての${formatNumber(total)}件を選ぶ` })), _jsx(Button, { variant: "muted", size: "sm", onClick: clearSelection, children: "\u9078\u629E\u3092\u89E3\u9664\u3059\u308B" })] })) : (_jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2 @3xl:flex-wrap", children: [searchable && (_jsx(SearchField, { "aria-label": `${itemName}を検索`, value: query.q, onChange: q => navigate({ q }, true), className: "min-w-0 flex-1 @2xl:w-80 @2xl:flex-none" })), filters.length > 0 && _jsx(Filters, { filters: filters, values: query.filters, onChange: setFilter })] }))] }), !selecting && activeFilters.length > 0 && (_jsxs("ul", { ref: chipsRef, className: "flex flex-wrap items-center gap-2", "aria-label": "\u304B\u3051\u3066\u3044\u308B\u7D5E\u308A\u8FBC\u307F", children: [activeFilters.map((f, index) => (_jsx("li", { className: "flex min-w-0", children: _jsx(Chip, { onRemove: () => removeFilter(f.key, index), removeLabel: `「${f.text}」の絞り込みを外す`, children: f.text }) }, f.key))), activeFilters.length >= 2 && (_jsx("li", { className: "flex", children: _jsx(Button, { variant: "muted", size: "sm", onClick: () => {
|
|
117
|
+
pendingFocus.current = { target: "toolbar", waitFor: queryKey };
|
|
118
|
+
navigate({ filters: {} });
|
|
119
|
+
}, children: "\u3059\u3079\u3066\u89E3\u9664" }) }))] })), showResults && (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx(ItemRange, { total: total, page: query.page, pageSize: query.perPage }), sortOptions.length > 0 && (_jsxs("label", { className: cn("flex items-center gap-2 text-sm text-foreground", layout.list), children: ["\u4E26\u3073\u9806", _jsx(Select, { value: `${query.sort.key}:${query.sort.order}`, onChange: e => {
|
|
120
|
+
const value = e.target.value;
|
|
121
|
+
const at = value.lastIndexOf(":");
|
|
122
|
+
navigate({ sort: { key: value.slice(0, at), order: value.slice(at + 1) } });
|
|
123
|
+
}, children: sortOptions.map(o => (_jsx("option", { value: o.value, children: o.label }, o.value))) })] }))] })), _jsx("div", { "aria-busy": status === "loading", children: status === "error" ? (_jsx(ErrorState, { onRetry: onRetry })) : ready && total === 0 ? (
|
|
124
|
+
// 取得は成功して0件のとき。条件をかけているなら、条件を外す操作を置く(docs/writing/error-and-empty.md の「エラーと空の状態」)
|
|
125
|
+
filtered ? (_jsx(EmptyState, { message: `条件に一致する${itemName}がありません。`, actionLabel: "\u7D5E\u308A\u8FBC\u307F\u3092\u89E3\u9664\u3059\u308B", onAction: clearConditions })) : (_jsx(EmptyState, { ...empty }))) : (_jsxs(_Fragment, { children: [_jsx("div", { className: layout.table, children: _jsxs(Table, { "aria-label": `${itemName}の一覧`, children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [bulkActions && (_jsx(TableHeaderCell, { className: "w-px", children: _jsx(Checkbox, { "aria-label": "\u3053\u306E\u30DA\u30FC\u30B8\u306E\u3059\u3079\u3066\u3092\u9078\u3076", checked: pageSelected, indeterminate: !pageSelected && selectedIds.length > 0, disabled: !ready, onChange: togglePage }) })), columns.map(c => c.sort ? (_jsx(SortableHeader, { direction: toDirection(query.sort, c.key), onSort: () => sortBy(c.key), className: c.className, children: c.header }, c.key)) : (_jsx(TableHeaderCell, { className: c.className, children: c.header }, c.key))), rowActions && (_jsx(TableHeaderCell, { children: _jsx("span", { className: "sr-only", children: "\u64CD\u4F5C" }) }))] }) }), _jsx(TableBody, { children: ready
|
|
126
|
+
? rows.map(row => {
|
|
127
|
+
const id = rowKey(row);
|
|
128
|
+
return (_jsxs(TableRow, { children: [bulkActions && (_jsx(TableCell, { children: _jsx(Checkbox, { "aria-label": `「${rowLabel(row)}」を選ぶ`, checked: selectedIds.includes(id), onChange: () => toggleRow(id) }) })), columns.map(c => (_jsx(TableCell, { className: c.className, children: c.cell(row) }, c.key))), rowActions && (_jsx(TableCell, { className: "whitespace-nowrap", children: _jsx("div", { className: "flex items-center justify-end gap-2", children: rowActions(row) }) }))] }, id));
|
|
129
|
+
})
|
|
130
|
+
: // 読み込み中は、読み込んだ後と同じ列で行の形を保つ(docs/components/skeleton.md)
|
|
131
|
+
SKELETON_ROWS.map(i => (_jsxs(TableRow, { children: [bulkActions && _jsx(TableCell, { children: _jsx(Skeleton, { className: "size-5" }) }), columns.map(c => (_jsx(TableCell, { className: c.className, children: _jsx(Skeleton, { className: "h-4 w-24" }) }, c.key))), rowActions && _jsx(TableCell, { children: _jsx(Skeleton, { className: "ml-auto h-8 w-24" }) })] }, i))) })] }) }), _jsxs("div", { className: cn("space-y-2", layout.list), children: [bulkActions && ready && (_jsx(Checkbox, { checked: pageSelected, indeterminate: !pageSelected && selectedIds.length > 0, onChange: togglePage, children: "\u3053\u306E\u30DA\u30FC\u30B8\u306E\u3059\u3079\u3066\u3092\u9078\u3076" })), _jsx("ul", { "aria-label": `${itemName}の一覧`, className: "divide-y border-y", children: ready
|
|
132
|
+
? rows.map(row => {
|
|
133
|
+
const id = rowKey(row);
|
|
134
|
+
return (_jsxs("li", { className: "flex items-start gap-2 py-2", children: [bulkActions && (_jsx("div", { className: "flex h-6 shrink-0 items-center", children: _jsx(Checkbox, { "aria-label": `「${rowLabel(row)}」を選ぶ`, checked: selectedIds.includes(id), onChange: () => toggleRow(id) }) })), _jsxs("div", { className: "min-w-0 flex-1 space-y-1", children: [_jsx("div", { className: "leading-normal", children: first?.cell(row) }), listColumns.length > 0 && (_jsx("div", { className: "flex flex-wrap items-center gap-2 text-sm text-muted-foreground", children: listColumns.map(c => (_jsx("span", { className: "whitespace-nowrap", children: c.cell(row) }, c.key))) })), rowActions && _jsx("div", { className: "flex flex-wrap items-center gap-2 pt-1", children: rowActions(row) })] })] }, id));
|
|
135
|
+
})
|
|
136
|
+
: SKELETON_ROWS.map(i => (_jsxs("li", { className: "space-y-2 py-2", children: [_jsx(Skeleton, { className: "h-4 w-48" }), _jsx(Skeleton, { className: "h-4 w-24" })] }, i))) })] })] })) }), showResults && (_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [_jsx(Pagination, { page: query.page, pageCount: pageCount, href: page => href(writeDataTableQuery(searchParams, { ...query, page }, config)), renderLink: renderLink }), total > PER_PAGE_OPTIONS[0] && (_jsxs("label", { className: "ml-auto flex items-center gap-2 text-sm text-foreground", children: ["\u8868\u793A\u4EF6\u6570", _jsx(Select, { value: String(query.perPage), onChange: e => navigate({ perPage: Number(e.target.value) }), children: PER_PAGE_OPTIONS.map(n => (_jsxs("option", { value: n, children: [n, "\u4EF6"] }, n))) })] }))] }))] }));
|
|
137
|
+
}
|
|
138
|
+
function defaultHref(next) {
|
|
139
|
+
return `?${next.toString()}`;
|
|
140
|
+
}
|
|
141
|
+
// 絞り込みの項目。3つまでは検索欄の隣に選択を並べ、4つ以上は「絞り込み」のポップオーバーにまとめる。
|
|
142
|
+
// 3つまでのときも、置き場所が768px未満で横に並びきらないときは、ポップオーバーにまとめる(docs/list/search.md の「絞り込み」)。
|
|
143
|
+
// どちらも、選んだ時点でクエリを変える。かけている絞り込みは、一覧の上のチップで示す
|
|
144
|
+
function Filters({ filters, values, onChange }) {
|
|
145
|
+
const id = useId();
|
|
146
|
+
const popover = (_jsx(Popover, { label: "\u7D5E\u308A\u8FBC\u307F", children: _jsx("div", { className: "space-y-4", children: filters.map(f => (_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: `${id}-${f.key}`, children: f.label }), _jsxs(Select, { id: `${id}-${f.key}`, value: values[f.key] ?? "", onChange: e => onChange(f.key, e.target.value), children: [_jsx("option", { value: "", children: "\u3059\u3079\u3066" }), f.options.map(o => (_jsx("option", { value: o.value, children: o.label }, o.value)))] })] }, f.key))) }) }));
|
|
147
|
+
if (filters.length > 3)
|
|
148
|
+
return popover;
|
|
149
|
+
return (_jsxs(_Fragment, { children: [filters.map(f => (_jsxs(Select, { "aria-label": f.label, value: values[f.key] ?? "", onChange: e => onChange(f.key, e.target.value), className: "hidden @3xl:block", children: [_jsxs("option", { value: "", children: [f.label, "\uFF1A\u3059\u3079\u3066"] }), f.options.map(o => (_jsxs("option", { value: o.value, children: [f.label, "\uFF1A", o.label] }, o.value)))] }, f.key))), _jsx("div", { className: "flex @3xl:hidden", children: popover })] }));
|
|
150
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type SortOrder = "asc" | "desc";
|
|
2
|
+
/** 1ページの件数の選択肢。画面ごとに変えない(docs/list/paging.md の LIST-009) */
|
|
3
|
+
export declare const PER_PAGE_OPTIONS: readonly [25, 50, 100];
|
|
4
|
+
export type PerPage = (typeof PER_PAGE_OPTIONS)[number];
|
|
5
|
+
export interface DataTableFilterOption {
|
|
6
|
+
/** クエリに書く値(`status=shared` の `shared`) */
|
|
7
|
+
value: string;
|
|
8
|
+
/** 画面に出す文言(「共有中」) */
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DataTableFilter {
|
|
12
|
+
/** クエリのキー(`status`)。`q`、`sort`、`order`、`page`、`per_page` は使えない */
|
|
13
|
+
key: string;
|
|
14
|
+
/** 絞り込みの項目の名前(「状態」)。チップでは「状態:共有中」のように書く */
|
|
15
|
+
label: string;
|
|
16
|
+
options: DataTableFilterOption[];
|
|
17
|
+
}
|
|
18
|
+
export interface DataTableSort {
|
|
19
|
+
/** 並べ替える列の key */
|
|
20
|
+
key: string;
|
|
21
|
+
order: SortOrder;
|
|
22
|
+
}
|
|
23
|
+
/** 状態を読むのに要る設定。DataTable に渡す columns、filters、defaultSort と同じものを渡す */
|
|
24
|
+
export interface DataTableQueryConfig {
|
|
25
|
+
/** 並べ替えのできる列は、sort を持つ */
|
|
26
|
+
columns: readonly {
|
|
27
|
+
key: string;
|
|
28
|
+
sort?: unknown;
|
|
29
|
+
}[];
|
|
30
|
+
filters?: readonly DataTableFilter[];
|
|
31
|
+
/** 並べ替えの初めの列と向き。クエリに書かない */
|
|
32
|
+
defaultSort: DataTableSort;
|
|
33
|
+
}
|
|
34
|
+
export interface DataTableQuery {
|
|
35
|
+
/** 検索の語。なければ空の文字列 */
|
|
36
|
+
q: string;
|
|
37
|
+
/** かけている絞り込み。かけていない項目のキーは持たない */
|
|
38
|
+
filters: Record<string, string>;
|
|
39
|
+
sort: DataTableSort;
|
|
40
|
+
/** 今のページ。1から数える */
|
|
41
|
+
page: number;
|
|
42
|
+
perPage: PerPage;
|
|
43
|
+
}
|
|
44
|
+
/** URLのクエリから状態を読む。知らない値(並べ替えられない列、選択肢にない絞り込み、25・50・100以外の件数)は、初めの値として読む */
|
|
45
|
+
export declare function readDataTableQuery(searchParams: URLSearchParams, config: DataTableQueryConfig): DataTableQuery;
|
|
46
|
+
/**
|
|
47
|
+
* 状態をURLのクエリに書く。初めの値(1ページ目、初めの並べ替え、絞り込みなし、50件)は書かない。
|
|
48
|
+
* データテーブルが持たないキー(`tab` など)は、base から引き継ぐ
|
|
49
|
+
*/
|
|
50
|
+
export declare function writeDataTableQuery(base: URLSearchParams, query: DataTableQuery, config: DataTableQueryConfig): URLSearchParams;
|
|
51
|
+
/** 検索か絞り込みを、1つでもかけているか */
|
|
52
|
+
export declare function hasConditions(query: DataTableQuery): boolean;
|
|
53
|
+
/** 絞り込みのキーが、データテーブルの持つクエリのキーとぶつかるか */
|
|
54
|
+
export declare function isReservedKey(key: string): boolean;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// データテーブルの状態(検索、絞り込み、並べ替え、ページ、1ページの件数)と、URLのクエリの読み書き(docs/list/paging.md の「一覧の状態とURL」)。
|
|
2
|
+
// URLそのものには触らない。読むのは使う側から渡された URLSearchParams で、書いた結果も URLSearchParams で返す。
|
|
3
|
+
// 使う側は、同じ関数でクエリを読み、データの取得に使う。部品と使う側が、同じ読み方で同じ状態を見るためである
|
|
4
|
+
/** 1ページの件数の選択肢。画面ごとに変えない(docs/list/paging.md の LIST-009) */
|
|
5
|
+
export const PER_PAGE_OPTIONS = [25, 50, 100];
|
|
6
|
+
const DEFAULT_PER_PAGE = 50;
|
|
7
|
+
const RESERVED = ["q", "sort", "order", "page", "per_page"];
|
|
8
|
+
function sortable(config) {
|
|
9
|
+
return config.columns.filter(c => c.sort !== undefined).map(c => c.key);
|
|
10
|
+
}
|
|
11
|
+
/** URLのクエリから状態を読む。知らない値(並べ替えられない列、選択肢にない絞り込み、25・50・100以外の件数)は、初めの値として読む */
|
|
12
|
+
export function readDataTableQuery(searchParams, config) {
|
|
13
|
+
const filters = {};
|
|
14
|
+
for (const filter of config.filters ?? []) {
|
|
15
|
+
const value = searchParams.get(filter.key);
|
|
16
|
+
if (value !== null && filter.options.some(o => o.value === value))
|
|
17
|
+
filters[filter.key] = value;
|
|
18
|
+
}
|
|
19
|
+
const sortKey = searchParams.get("sort");
|
|
20
|
+
const order = searchParams.get("order");
|
|
21
|
+
const sort = {
|
|
22
|
+
key: sortKey !== null && sortable(config).includes(sortKey) ? sortKey : config.defaultSort.key,
|
|
23
|
+
order: order === "asc" || order === "desc" ? order : config.defaultSort.order,
|
|
24
|
+
};
|
|
25
|
+
const page = Number(searchParams.get("page"));
|
|
26
|
+
const perPage = Number(searchParams.get("per_page"));
|
|
27
|
+
return {
|
|
28
|
+
q: searchParams.get("q") ?? "",
|
|
29
|
+
filters,
|
|
30
|
+
sort,
|
|
31
|
+
page: Number.isInteger(page) && page >= 1 ? page : 1,
|
|
32
|
+
perPage: PER_PAGE_OPTIONS.includes(perPage) ? perPage : DEFAULT_PER_PAGE,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 状態をURLのクエリに書く。初めの値(1ページ目、初めの並べ替え、絞り込みなし、50件)は書かない。
|
|
37
|
+
* データテーブルが持たないキー(`tab` など)は、base から引き継ぐ
|
|
38
|
+
*/
|
|
39
|
+
export function writeDataTableQuery(base, query, config) {
|
|
40
|
+
const filterKeys = (config.filters ?? []).map(f => f.key);
|
|
41
|
+
const next = new URLSearchParams();
|
|
42
|
+
for (const [key, value] of base) {
|
|
43
|
+
if (!RESERVED.includes(key) && !filterKeys.includes(key))
|
|
44
|
+
next.append(key, value);
|
|
45
|
+
}
|
|
46
|
+
if (query.q !== "")
|
|
47
|
+
next.set("q", query.q);
|
|
48
|
+
for (const key of filterKeys) {
|
|
49
|
+
const value = query.filters[key];
|
|
50
|
+
if (value !== undefined)
|
|
51
|
+
next.set(key, value);
|
|
52
|
+
}
|
|
53
|
+
if (query.sort.key !== config.defaultSort.key || query.sort.order !== config.defaultSort.order) {
|
|
54
|
+
next.set("sort", query.sort.key);
|
|
55
|
+
next.set("order", query.sort.order);
|
|
56
|
+
}
|
|
57
|
+
if (query.page > 1)
|
|
58
|
+
next.set("page", String(query.page));
|
|
59
|
+
if (query.perPage !== DEFAULT_PER_PAGE)
|
|
60
|
+
next.set("per_page", String(query.perPage));
|
|
61
|
+
return next;
|
|
62
|
+
}
|
|
63
|
+
/** 検索か絞り込みを、1つでもかけているか */
|
|
64
|
+
export function hasConditions(query) {
|
|
65
|
+
return query.q !== "" || Object.keys(query.filters).length > 0;
|
|
66
|
+
}
|
|
67
|
+
/** 絞り込みのキーが、データテーブルの持つクエリのキーとぶつかるか */
|
|
68
|
+
export function isReservedKey(key) {
|
|
69
|
+
return RESERVED.includes(key);
|
|
70
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type InputHTMLAttributes } from "react";
|
|
2
|
+
import { type WeekStart } from "../calendar/Calendar.js";
|
|
3
|
+
type NativeInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue" | "onChange" | "onBlur" | "min" | "max" | "className" | "list" | "children">;
|
|
4
|
+
export interface DatePickerProps extends NativeInputProps {
|
|
5
|
+
/** 選んだ日。まだ選んでいないときと、打ち込んだ文字が日付として読めないときは null。時刻は見ない */
|
|
6
|
+
value: Date | null;
|
|
7
|
+
/**
|
|
8
|
+
* 打ち込んだ文字が変わったときと、カレンダーで日を選んだときに呼ぶ。選択は使う側で持つ。
|
|
9
|
+
* 読めない文字や、選べる範囲の外の日付のときは、date を null にし、error にどう直せばよいかの文を渡す。
|
|
10
|
+
* 空にしたときは、date も error もない。エラーを出す時機は使う側で決める(docs/form/validation-timing.md)
|
|
11
|
+
*/
|
|
12
|
+
onChange: (date: Date | null, error?: string) => void;
|
|
13
|
+
/** 入力欄、カレンダーを開くボタン、開いたカレンダーのどれからも、フォーカスが外へ出たときに呼ぶ。入力を確かめる時機に使う */
|
|
14
|
+
onBlur?: () => void;
|
|
15
|
+
/** 選べる最初の日。これより前の日付は、カレンダーで押せず、打ち込むとエラーになる */
|
|
16
|
+
min?: Date;
|
|
17
|
+
/** 選べる最後の日。これより後の日付は、カレンダーで押せず、打ち込むとエラーになる */
|
|
18
|
+
max?: Date;
|
|
19
|
+
/** カレンダーの週の始まりの曜日。0 が日曜、1 が月曜。省いたときは日曜。アプリの中で混ぜない */
|
|
20
|
+
weekStartsOn?: WeekStart;
|
|
21
|
+
/** 外側の配置(余白と幅)だけに使う。入力欄ではなく、ボタンを含む外側の枠に付く */
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function DatePicker({ value, onChange, onBlur, min, max, weekStartsOn, className, name, disabled, autoComplete, onCompositionStart, onCompositionEnd, style, ...props }: DatePickerProps): import("react").JSX.Element;
|
|
25
|
+
export {};
|