@knk1313/plain-ui 0.0.0-stage → 0.2.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 +86 -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 +183 -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/publish.md +26 -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 +117 -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
- package/tokens/tokens.values.json +234 -0
|
@@ -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 {};
|
|
@@ -0,0 +1,154 @@
|
|
|
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 { CalendarIcon } from "lucide-react";
|
|
5
|
+
import { Button } from "../button/Button.js";
|
|
6
|
+
import { Calendar } from "../calendar/Calendar.js";
|
|
7
|
+
import { placeBelowAnchor } from "../../lib/anchor.js";
|
|
8
|
+
import { cn } from "../../lib/cn.js";
|
|
9
|
+
import { daysInMonth, formatDate, formatMonth, isDayInRange, parseDate, toDateValue } from "../../lib/date.js";
|
|
10
|
+
// 打ち込んだ文字を確かめる。空なら日付もエラーもなく、読めて範囲の中なら日付を、そうでなければエラーの文を返す
|
|
11
|
+
function readText(text, min, max) {
|
|
12
|
+
if (text.trim() === "")
|
|
13
|
+
return { date: null };
|
|
14
|
+
const parsed = parseDate(text);
|
|
15
|
+
if ("error" in parsed) {
|
|
16
|
+
if (parsed.error === "day")
|
|
17
|
+
return { date: null, error: `${formatMonth(parsed.month)}は${daysInMonth(parsed.month)}日までです。` };
|
|
18
|
+
// 入力例は今日の日付で書く。決まった年の例は、年が変わると古く見える
|
|
19
|
+
const today = new Date();
|
|
20
|
+
const example = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
|
|
21
|
+
return { date: null, error: `日付は、${example} のように、年、月、日の順に入力してください。` };
|
|
22
|
+
}
|
|
23
|
+
if (isDayInRange(parsed.date, min, max))
|
|
24
|
+
return { date: parsed.date };
|
|
25
|
+
if (min && max)
|
|
26
|
+
return { date: null, error: `${formatDate(min)}から${formatDate(max)}までの日付を入力してください。` };
|
|
27
|
+
if (min)
|
|
28
|
+
return { date: null, error: `${formatDate(min)}以降の日付を入力してください。` };
|
|
29
|
+
return { date: null, error: `${formatDate(max)}以前の日付を入力してください。` };
|
|
30
|
+
}
|
|
31
|
+
// 日付の入力欄。日付を打ち込むか、右端のボタンで開くカレンダー(Calendar)から選ぶ。
|
|
32
|
+
// カレンダーは Popover API(popover="auto")で最前面の層に出し、フォーカスの移し方と戻し方は Popover と同じ形で自作する
|
|
33
|
+
// (docs/components/date-picker.md の「日付ピッカーの作り方」)。選択は使う側が value と onChange で持ち、
|
|
34
|
+
// 打ち込んでいる途中の文字だけを部品の中に持つ
|
|
35
|
+
export function DatePicker({ value, onChange, onBlur, min, max, weekStartsOn, className, name, disabled, autoComplete = "off", onCompositionStart, onCompositionEnd, style, ...props }) {
|
|
36
|
+
const id = useId();
|
|
37
|
+
const buttonId = `${id}-button`;
|
|
38
|
+
const popoverId = `${id}-calendar`;
|
|
39
|
+
// anchor-name に使える形にする(useId の値には、名前に使えない文字が入る)
|
|
40
|
+
const anchorName = `--date-picker-${id.replace(/[^A-Za-z0-9_-]/g, "")}`;
|
|
41
|
+
const rootRef = useRef(null);
|
|
42
|
+
const popoverRef = useRef(null);
|
|
43
|
+
const composingRef = useRef(false);
|
|
44
|
+
const [open, setOpen] = useState(false);
|
|
45
|
+
// 入力欄の文字。選んだ日は「2026年12月1日」の形で書く(docs/writing/date-and-number.md の「日付の書き方を混ぜない」)
|
|
46
|
+
const [text, setText] = useState(value ? formatDate(value) : "");
|
|
47
|
+
// 最後に知らせた日付。親から戻ってきた値で、打ち込んでいる途中の文字を書き換えないために使う
|
|
48
|
+
const valueKey = value ? toDateValue(value) : "";
|
|
49
|
+
const sentRef = useRef(valueKey);
|
|
50
|
+
const [prevKey, setPrevKey] = useState(valueKey);
|
|
51
|
+
if (valueKey !== prevKey) {
|
|
52
|
+
setPrevKey(valueKey);
|
|
53
|
+
// 外から値が変わったとき(保存した値の読み込み、フォームの取り消しなど)だけ、文字をその日付にそろえる
|
|
54
|
+
if (valueKey !== sentRef.current) {
|
|
55
|
+
sentRef.current = valueKey;
|
|
56
|
+
setText(value ? formatDate(value) : "");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 名前のないまま描いたときに、1回だけ知らせる(Combobox と同じ形)
|
|
60
|
+
const unlabeled = !props["aria-label"] && !props["aria-labelledby"] && !props.id;
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (unlabeled)
|
|
63
|
+
console.warn("DatePicker: aria-label か aria-labelledby で名前を付けるか、Field で包む");
|
|
64
|
+
}, [unlabeled]);
|
|
65
|
+
// カレンダーは開いている間だけ描く。開くたびに、選んだ日(なければ今日)の月から始め、Tab キーで止まる日へフォーカスを移す
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!open)
|
|
68
|
+
return;
|
|
69
|
+
const popover = popoverRef.current;
|
|
70
|
+
if (!popover)
|
|
71
|
+
return;
|
|
72
|
+
// anchor positioning に対応しないブラウザでだけ、中身の大きさが決まった後に置き直し、画面の端から8pxの内側に収める
|
|
73
|
+
placeBelowAnchor(popover, rootRef.current, { edge: 8 });
|
|
74
|
+
popover.querySelector('[role="grid"] button[tabindex="0"]')?.focus();
|
|
75
|
+
}, [open]);
|
|
76
|
+
function emit(nextText) {
|
|
77
|
+
const { date, error } = readText(nextText, min, max);
|
|
78
|
+
sentRef.current = date ? toDateValue(date) : "";
|
|
79
|
+
onChange(date, error);
|
|
80
|
+
}
|
|
81
|
+
function choose(date) {
|
|
82
|
+
setText(formatDate(date));
|
|
83
|
+
sentRef.current = toDateValue(date);
|
|
84
|
+
onChange(date);
|
|
85
|
+
// 閉じる前にフォーカスが中にあるので、閉じるとカレンダーを開くボタンへ戻る(handleBeforeToggle)
|
|
86
|
+
popoverRef.current?.hidePopover();
|
|
87
|
+
}
|
|
88
|
+
function handleBlur(e) {
|
|
89
|
+
// 部品の中(入力欄、ボタン、カレンダー)でフォーカスが移っただけなら、離れたとみなさない
|
|
90
|
+
if (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget))
|
|
91
|
+
return;
|
|
92
|
+
// 読めた日付は、決まった書き方(2026年12月1日)に書き直す。読めない文字は、直せるようにそのまま残す
|
|
93
|
+
const { date } = readText(text, min, max);
|
|
94
|
+
if (date)
|
|
95
|
+
setText(formatDate(date));
|
|
96
|
+
onBlur?.();
|
|
97
|
+
}
|
|
98
|
+
function handleBeforeToggle(e) {
|
|
99
|
+
if (e.target !== e.currentTarget)
|
|
100
|
+
return;
|
|
101
|
+
const popover = e.currentTarget;
|
|
102
|
+
const trigger = popover.ownerDocument.getElementById(buttonId);
|
|
103
|
+
if (e.newState === "open") {
|
|
104
|
+
// anchor positioning に対応しないブラウザでだけ、入力欄の枠の位置から計算して置く(lib/anchor.ts)
|
|
105
|
+
placeBelowAnchor(popover, rootRef.current);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// 閉じる直前に、フォーカスが中にあるか、どこにもない(外の何もない所を押した)ときだけ、開いたボタンへ戻す(Popover と同じ)。
|
|
109
|
+
// 外の別の入力欄やボタンを押して閉じたときは、移った先に残す
|
|
110
|
+
const active = popover.ownerDocument.activeElement;
|
|
111
|
+
if (!active || active === popover.ownerDocument.body || popover.contains(active))
|
|
112
|
+
trigger?.focus();
|
|
113
|
+
}
|
|
114
|
+
function handleToggle(e) {
|
|
115
|
+
if (e.target !== e.currentTarget)
|
|
116
|
+
return;
|
|
117
|
+
setOpen(e.newState === "open");
|
|
118
|
+
}
|
|
119
|
+
function handlePopoverKeyDown(e) {
|
|
120
|
+
// Esc キーで閉じる。Dialog の中に置いたときも、1回目の Esc キーではカレンダーだけを閉じる
|
|
121
|
+
if (e.key !== "Escape" || e.defaultPrevented)
|
|
122
|
+
return;
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
popoverRef.current?.hidePopover();
|
|
126
|
+
}
|
|
127
|
+
return (_jsxs("div", { ref: rootRef, onBlur: handleBlur,
|
|
128
|
+
// anchor positioning で、カレンダーを入力欄の枠に結ぶ
|
|
129
|
+
style: { anchorName },
|
|
130
|
+
// 枠は Input と同じ見た目にし、SearchField と同じく、入力欄とボタンを1つの枠に収める。
|
|
131
|
+
// ボタンの見た目(32px)は、枠の内側(42px)の上下と同じくらいの隙間で右端に置く
|
|
132
|
+
className: cn("flex min-h-11 w-full items-center gap-2 rounded-md border border-input bg-background pl-4 pr-1 text-foreground has-[input:focus-visible]:ring-2 has-[input:focus-visible]:ring-ring has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50 has-aria-invalid:border-danger-icon", className), children: [_jsx("input", { type: "text", value: text, disabled: disabled, autoComplete: autoComplete, onChange: e => {
|
|
133
|
+
const next = e.target.value;
|
|
134
|
+
setText(next);
|
|
135
|
+
// 変換中の読みでは確かめず、確定してから確かめる
|
|
136
|
+
if (!composingRef.current)
|
|
137
|
+
emit(next);
|
|
138
|
+
}, onCompositionStart: e => {
|
|
139
|
+
composingRef.current = true;
|
|
140
|
+
onCompositionStart?.(e);
|
|
141
|
+
}, onCompositionEnd: e => {
|
|
142
|
+
composingRef.current = false;
|
|
143
|
+
emit(e.currentTarget.value);
|
|
144
|
+
onCompositionEnd?.(e);
|
|
145
|
+
}, style: style, className: "min-w-0 flex-1 self-stretch bg-transparent py-2 text-base outline-none disabled:cursor-not-allowed", ...props }), name && _jsx("input", { type: "hidden", name: name, value: valueKey, disabled: disabled }), _jsx(Button, { id: buttonId, variant: "ghost", size: "icon-sm", "aria-label": "\u30AB\u30EC\u30F3\u30C0\u30FC\u304B\u3089\u9078\u3076", "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": popoverId,
|
|
146
|
+
// 押せないときは開かない。Button は disabled を aria-disabled で描き、押しても何もしない
|
|
147
|
+
popoverTarget: disabled ? undefined : popoverId, disabled: disabled,
|
|
148
|
+
// 押したときに入力欄からフォーカスを外さない。押したボタンにフォーカスを移さないブラウザ(Safari)で、
|
|
149
|
+
// 開く前に部品から離れたとみなして onBlur を呼ばないようにする。開くとフォーカスはカレンダーの日へ移る
|
|
150
|
+
onMouseDown: e => e.preventDefault(), className: "shrink-0", children: _jsx(CalendarIcon, { "aria-hidden": "true", className: "size-4 text-icon" }) }), _jsx("div", { ref: popoverRef, id: popoverId, popover: "auto", role: "dialog", "aria-labelledby": buttonId, onBeforeToggle: handleBeforeToggle, onToggle: handleToggle, onKeyDown: handlePopoverKeyDown, style: { positionAnchor: anchorName },
|
|
151
|
+
// 手前の層に出るので z- は付けない。面は Popover にそろえる。内側の余白は、日どうしの間と同じSにし、390pxの画面にも収める。
|
|
152
|
+
// anchor positioning では、入力欄の枠の真下・左端そろえに置く。下に入らなければ上に出し、横に入らなければ枠の中央にそろえる
|
|
153
|
+
className: "inset-auto mx-0 my-1 rounded-lg border bg-popover p-2 text-popover-foreground shadow-md [position-area:block-end_span-inline-end] [position-try-fallbacks:flip-block,block-end,block-start]", children: open && _jsx(Calendar, { value: value, onChange: choose, min: min, max: max, weekStartsOn: weekStartsOn }) })] }));
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./DatePicker.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./DatePicker.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ConfirmDialogProps {
|
|
2
|
+
/** 開いているか。開閉は使う側で持つ */
|
|
3
|
+
open: boolean;
|
|
4
|
+
/** Escキー、キャンセル、実行が終わったときに閉じる。open を false にする */
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
/** 対象と操作(例:このドキュメントを完全に削除しますか?) */
|
|
7
|
+
title: string;
|
|
8
|
+
/** 操作の結果。元に戻せないなら、そのことを書く */
|
|
9
|
+
description: string;
|
|
10
|
+
/** 実行のボタンの文言(例:完全に削除する) */
|
|
11
|
+
confirmLabel: string;
|
|
12
|
+
/** 処理中の実行のボタンの文言(例:削除中)。省いたときは「処理中」 */
|
|
13
|
+
pendingLabel?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 実行のボタンの色。既定の値はなく、必ず渡す(色の選び忘れを型で防ぐ)。
|
|
16
|
+
* 取り消せない操作は danger、あとから取り消せる操作は primary にする
|
|
17
|
+
*/
|
|
18
|
+
confirmVariant: "primary" | "danger";
|
|
19
|
+
/**
|
|
20
|
+
* 実行のボタンを押したとき。Promise を返すと、終わるまでダイアログを開いたまま実行のボタンを処理中にし、
|
|
21
|
+
* 解決したら閉じる。reject したら閉じずに、Error の message をダイアログの中に出す
|
|
22
|
+
*/
|
|
23
|
+
onConfirm: () => void | Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
export declare function ConfirmDialog({ open, onClose, title, description, confirmLabel, pendingLabel, confirmVariant, onConfirm, }: ConfirmDialogProps): import("react").JSX.Element;
|