@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,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { Banner } from "../banner/Banner.js";
|
|
4
|
+
import { Button } from "../button/Button.js";
|
|
5
|
+
import { Checkbox } from "../checkbox/Checkbox.js";
|
|
6
|
+
import { ErrorSummary } from "../error-summary/ErrorSummary.js";
|
|
7
|
+
import { Field } from "../field/Field.js";
|
|
8
|
+
import { FieldError } from "../field-error/FieldError.js";
|
|
9
|
+
import { FormSection } from "../form-section/FormSection.js";
|
|
10
|
+
import { Radio, RadioGroup } from "../radio/Radio.js";
|
|
11
|
+
import { Textarea } from "../textarea/Textarea.js";
|
|
12
|
+
// 1つ選ぶ質問の選択肢の上限(docs/components/choosing.md の「選ぶ部品の使い分け」)
|
|
13
|
+
const MAX_SINGLE_OPTIONS = 5;
|
|
14
|
+
const FAILED_MESSAGE = "回答を送信できませんでした。時間をおいてもう一度送信してください。";
|
|
15
|
+
// 必須の質問の案内は、操作に合わせて「入力」と「選択」を使い分ける(docs/writing/error-and-empty.md の「エラーと空の状態」)
|
|
16
|
+
function validate(question, answer) {
|
|
17
|
+
if (!question.required)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (question.type === "text")
|
|
20
|
+
return typeof answer === "string" && answer.trim() !== "" ? undefined : "回答を入力してください。";
|
|
21
|
+
if (question.type === "single")
|
|
22
|
+
return answer ? undefined : "選択肢を1つ選択してください。";
|
|
23
|
+
return Array.isArray(answer) && answer.length > 0 ? undefined : "選択肢を1つ以上選択してください。";
|
|
24
|
+
}
|
|
25
|
+
const emptyAnswer = (question) => (question.type === "multiple" ? [] : "");
|
|
26
|
+
export function QuestionForm({ sections, onSubmit, submitLabel, pendingLabel = "送信中", level = 2, className }) {
|
|
27
|
+
const prefix = useId();
|
|
28
|
+
const questions = sections.flatMap(section => section.questions);
|
|
29
|
+
const [answers, setAnswers] = useState(() => Object.fromEntries(questions.map(question => [question.id, emptyAnswer(question)])));
|
|
30
|
+
const [errors, setErrors] = useState({});
|
|
31
|
+
// 送信したときに作ったまとめの質問の id。直ったものは、描くときに外す
|
|
32
|
+
const [summary, setSummary] = useState([]);
|
|
33
|
+
const [submitting, setSubmitting] = useState(false);
|
|
34
|
+
const [failed, setFailed] = useState(false);
|
|
35
|
+
// Enter キーでの送信も含め、送信中の2回目を、描き直しを待たずに止める(FORM-011)
|
|
36
|
+
const submittingRef = useRef(false);
|
|
37
|
+
// すべての質問が必須なら、項目ごとに「(必須)」を付けず、フォームの先頭に1回だけ書く(docs/components.md の「操作と入力」)
|
|
38
|
+
const allRequired = questions.length > 0 && questions.every(question => question.required);
|
|
39
|
+
// 型では防げない、選択肢の多い「1つ選ぶ質問」を、描くたびではなく1回だけ知らせる(COMPONENTS-080)
|
|
40
|
+
const tooMany = questions.filter(question => question.type === "single" && question.options.length > MAX_SINGLE_OPTIONS).map(question => question.id).join(",");
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (tooMany)
|
|
43
|
+
console.warn(`QuestionForm: 1つ選ぶ質問の選択肢は${MAX_SINGLE_OPTIONS}個までにする(${tooMany})`);
|
|
44
|
+
}, [tooMany]);
|
|
45
|
+
const domId = (questionId) => `${prefix}-${questionId}`;
|
|
46
|
+
const answerOf = (question) => answers[question.id] ?? emptyAnswer(question);
|
|
47
|
+
const focusQuestion = (questionId) => document.getElementById(domId(questionId))?.focus();
|
|
48
|
+
// エラーの出ている質問だけ、答えを変えたときにも確かめ直し、直ったらすぐに消す(FORM-001、FORM-002)
|
|
49
|
+
const change = (question, answer) => {
|
|
50
|
+
setAnswers(current => ({ ...current, [question.id]: answer }));
|
|
51
|
+
if (errors[question.id])
|
|
52
|
+
setErrors(current => withError(current, question.id, validate(question, answer)));
|
|
53
|
+
};
|
|
54
|
+
// 質問から離れたときに、その質問を確かめる。グループの中の選択肢どうしの移動では確かめない
|
|
55
|
+
const leave = (question) => (event) => {
|
|
56
|
+
if (event.currentTarget.contains(event.relatedTarget))
|
|
57
|
+
return;
|
|
58
|
+
setErrors(current => withError(current, question.id, validate(question, answerOf(question))));
|
|
59
|
+
};
|
|
60
|
+
// 送信したときのエラーを出す。画面の並びで最初のエラーの質問へフォーカスを移し、2つ以上ならまとめを出す(docs/form/submit-errors.md)
|
|
61
|
+
const showSubmitErrors = (found) => {
|
|
62
|
+
const ids = questions.map(question => question.id).filter(id => found[id]);
|
|
63
|
+
setErrors(found);
|
|
64
|
+
setSummary(ids.length >= 2 ? ids : []);
|
|
65
|
+
if (ids.length > 0)
|
|
66
|
+
focusQuestion(ids[0]);
|
|
67
|
+
return ids.length > 0;
|
|
68
|
+
};
|
|
69
|
+
const submit = async (event) => {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
if (submittingRef.current)
|
|
72
|
+
return;
|
|
73
|
+
setFailed(false);
|
|
74
|
+
const found = {};
|
|
75
|
+
for (const question of questions) {
|
|
76
|
+
const error = validate(question, answerOf(question));
|
|
77
|
+
if (error)
|
|
78
|
+
found[question.id] = error;
|
|
79
|
+
}
|
|
80
|
+
if (showSubmitErrors(found))
|
|
81
|
+
return;
|
|
82
|
+
submittingRef.current = true;
|
|
83
|
+
setSubmitting(true);
|
|
84
|
+
try {
|
|
85
|
+
// 後から足された質問も含め、今の質問の一覧の順で答えを渡す
|
|
86
|
+
const serverErrors = await onSubmit(Object.fromEntries(questions.map(question => [question.id, answerOf(question)])));
|
|
87
|
+
if (serverErrors)
|
|
88
|
+
showSubmitErrors(serverErrors);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
setFailed(true);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
submittingRef.current = false;
|
|
95
|
+
setSubmitting(false);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// まとめには、まだ直っていない質問だけを残し、件数を合わせる。すべて直ったら消す
|
|
99
|
+
const labelOf = (id) => questions.find(question => question.id === id)?.label ?? id;
|
|
100
|
+
const summaryItems = summary.filter(id => errors[id]).map(id => ({ id: domId(id), label: labelOf(id), message: errors[id] }));
|
|
101
|
+
return (_jsx("form", { noValidate: true, onSubmit: submit, className: className, children: _jsxs("div", { className: "space-y-8", children: [(failed || summaryItems.length > 0 || allRequired) && (_jsxs("div", { className: "space-y-4", children: [failed && _jsx(Banner, { variant: "danger", children: FAILED_MESSAGE }), _jsx(ErrorSummary, { items: summaryItems, noun: "\u56DE\u7B54" }), allRequired && _jsx("p", { className: "text-sm leading-relaxed text-muted-foreground", children: "\u3059\u3079\u3066\u306E\u9805\u76EE\u304C\u5FC5\u9808\u3067\u3059\u3002" })] })), sections.map((section, index) => (_jsx(FormSection, { title: section.title, level: level, children: section.questions.map(question => (_jsx("div", { onBlur: leave(question), children: _jsx(QuestionInput, { question: question, id: domId(question.id), answer: answerOf(question), error: errors[question.id],
|
|
102
|
+
// すべて必須のときは、先頭の1文で伝え、項目ごとの「(必須)」を出さない
|
|
103
|
+
showRequired: !allRequired && Boolean(question.required), onChange: answer => change(question, answer) }) }, question.id))) }, index))), _jsx(Button, { type: "submit", variant: "primary", pending: submitting, pendingLabel: pendingLabel, children: submitLabel })] }) }));
|
|
104
|
+
}
|
|
105
|
+
function withError(errors, id, error) {
|
|
106
|
+
if (error)
|
|
107
|
+
return errors[id] === error ? errors : { ...errors, [id]: error };
|
|
108
|
+
if (!(id in errors))
|
|
109
|
+
return errors;
|
|
110
|
+
const { [id]: _removed, ...rest } = errors;
|
|
111
|
+
return rest;
|
|
112
|
+
}
|
|
113
|
+
function QuestionInput({ question, id, answer, error, showRequired, onChange }) {
|
|
114
|
+
const required = Boolean(question.required);
|
|
115
|
+
if (question.type === "text") {
|
|
116
|
+
return (_jsx(Field, { id: id, label: question.label, required: showRequired, error: error, children: _jsx(Textarea, { value: typeof answer === "string" ? answer : "", "aria-required": required || undefined, onChange: event => onChange(event.target.value) }) }));
|
|
117
|
+
}
|
|
118
|
+
if (question.type === "single") {
|
|
119
|
+
return (_jsx(RadioGroup, { legend: question.label, name: id, value: typeof answer === "string" ? answer : "", onChange: onChange, required: showRequired, error: error, children: question.options.map((option, index) => (_jsx(Radio, { id: index === 0 ? id : undefined, value: option.value, required: required || undefined, children: option.label }, option.value))) }));
|
|
120
|
+
}
|
|
121
|
+
const selected = Array.isArray(answer) ? answer : [];
|
|
122
|
+
const errorId = `${id}-error`;
|
|
123
|
+
// 複数選ぶ質問は、RadioGroup と同じく fieldset と legend で名前を付け、エラーはグループから指す。
|
|
124
|
+
// チェックボックスに required は付けない(付けると、すべてを選ぶ必要があるという意味になる)
|
|
125
|
+
return (_jsxs("fieldset", { className: "min-w-0", "aria-describedby": error ? errorId : undefined, children: [_jsxs("legend", { className: "mb-2 text-sm font-medium leading-tight text-foreground", children: [question.label, showRequired && _jsx("span", { className: "font-normal text-muted-foreground", children: "\uFF08\u5FC5\u9808\uFF09" })] }), _jsx("div", { children: question.options.map((option, index) => (_jsx(Checkbox, { id: index === 0 ? id : undefined, name: id, value: option.value, checked: selected.includes(option.value), "aria-invalid": error ? true : undefined, onChange: event => onChange(event.target.checked
|
|
126
|
+
? question.options.map(o => o.value).filter(v => v === option.value || selected.includes(v))
|
|
127
|
+
: selected.filter(v => v !== option.value)), children: option.label }, option.value))) }), _jsx(FieldError, { id: errorId, className: "*:mt-2", children: error })] }));
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./QuestionForm.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./QuestionForm.js";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { formatNumber } from "../../lib/number.js";
|
|
5
|
+
import { ChartFrame } from "../chart/ChartFrame.js";
|
|
6
|
+
import { ChartTooltip } from "../chart/ChartTooltip.js";
|
|
7
|
+
import { formatValue } from "../chart/format.js";
|
|
8
|
+
import { AXIS_FONT_SIZE, niceTicks, tickCount, truncate, valueRange } from "../chart/scale.js";
|
|
9
|
+
import { LineSwatch, SERIES_DASH, SERIES_STROKE, SeriesMarker, seriesIndex } from "../chart/series.js";
|
|
10
|
+
import { LABEL_GAP, SPACE_XS } from "../chart/spacing.js";
|
|
11
|
+
import { ChartTooltipContent, usePointerPick } from "../chart/useChartHover.js";
|
|
12
|
+
import { LABEL_MAX, TOP_LABEL_OFFSET, axisAngle, layoutRadar, nearestAxis, radarPath } from "./geometry.js";
|
|
13
|
+
// 複数の項目の値を、中心から伸ばした軸の上の多角形で比べる。軸は、項目(labels)ごとに1本ずつ、真上から時計回りに並べる。
|
|
14
|
+
// 系列は、色に加えて、折れ線と同じ線の種類と印の形で描き分ける(docs/chart/color.md の CHART-002)。
|
|
15
|
+
// 多角形は塗らない(CHART-023)。値のない項目(null)では線を切り、前後の頂点をつながない
|
|
16
|
+
export function RadarChart(props) {
|
|
17
|
+
useRadarWarning(props.labels, props.series);
|
|
18
|
+
return (_jsx(ChartFrame, { ...props, component: "RadarChart", swatch: i => _jsx(LineSwatch, { index: i }), children: size => _jsx(RadarPlot, { ...props, ...size }) }));
|
|
19
|
+
}
|
|
20
|
+
// 項目が3つより少ないと、多角形にならない。負の値は、中心より内側に描けない。どちらも開発時に1回だけ知らせる
|
|
21
|
+
function useRadarWarning(labels, series) {
|
|
22
|
+
const few = labels.length > 0 && labels.length < MIN_AXES;
|
|
23
|
+
const negative = valueRange(series)[0] < 0;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (few)
|
|
26
|
+
console.warn(`RadarChart: 項目は${MIN_AXES}つ以上にする。2つまでなら BarChart で比べる`);
|
|
27
|
+
}, [few]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (negative)
|
|
30
|
+
console.warn("RadarChart: 値は0以上にする。中心を0にして描くので、負の値は中心に描く");
|
|
31
|
+
}, [negative]);
|
|
32
|
+
}
|
|
33
|
+
const MIN_AXES = 3;
|
|
34
|
+
function RadarPlot({ labels, series, unit, width, height }) {
|
|
35
|
+
const area = layoutRadar(labels, width, height);
|
|
36
|
+
const { cx, cy, radius } = area;
|
|
37
|
+
const count = labels.length;
|
|
38
|
+
// 中心を0にする(CHART-003)。目盛りは、半径48pxに1つを目安にする
|
|
39
|
+
const ticks = niceTicks(0, Math.max(0, valueRange(series)[1]), tickCount(radius));
|
|
40
|
+
const top = ticks[ticks.length - 1];
|
|
41
|
+
const hover = usePointerPick((x, y) => nearestAxis(x, y, area, count));
|
|
42
|
+
const active = hover.index;
|
|
43
|
+
const at = (i, r) => {
|
|
44
|
+
const angle = axisAngle(i, count);
|
|
45
|
+
return { x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) };
|
|
46
|
+
};
|
|
47
|
+
const point = (i, value) => at(i, (Math.max(0, value) / top) * radius);
|
|
48
|
+
const ring = (r) => labels.map((_, i) => `${i === 0 ? "M" : "L"}${at(i, r).x} ${at(i, r).y}`).join("") + "Z";
|
|
49
|
+
return (_jsxs(_Fragment, { children: [_jsxs("svg", { "aria-hidden": "true", width: width, height: height, className: "block overflow-visible", children: [ticks.slice(1).map(tick => (_jsx("path", { d: ring((tick / top) * radius), fill: "none", strokeWidth: "1", className: "stroke-border" }, tick))), labels.map((_, i) => {
|
|
50
|
+
const end = at(i, radius);
|
|
51
|
+
return (_jsx("line", { x1: cx, y1: cy, x2: end.x, y2: end.y, strokeWidth: "1", className: i === active ? "stroke-muted-foreground" : "stroke-border" }, i));
|
|
52
|
+
}), ticks.slice(1).map(tick => (_jsx("text", { x: cx - LABEL_GAP, y: cy - (tick / top) * radius - SPACE_XS, textAnchor: "end", className: "fill-muted-foreground text-xs", children: formatNumber(tick) }, tick))), series.map((s, i) => (_jsxs("g", { children: [_jsx("path", { d: radarPath(s.values, point), fill: "none", strokeWidth: "2", strokeLinejoin: "round", strokeLinecap: "round", strokeDasharray: SERIES_DASH[seriesIndex(i)], className: SERIES_STROKE[seriesIndex(i)] }), s.values.map((value, j) => {
|
|
53
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
54
|
+
return null;
|
|
55
|
+
const p = point(j, value);
|
|
56
|
+
return _jsx(SeriesMarker, { index: i, x: p.x, y: p.y, size: j === active ? 10 : 8 }, j);
|
|
57
|
+
})] }, i))), _jsx(AxisLabels, { labels: labels, area: area, width: width, at: at }), _jsx("circle", { cx: cx, cy: cy, r: radius + LABEL_GAP + AXIS_FONT_SIZE, fill: "transparent", ...hover.handlers })] }), _jsx(ChartTooltip, { position: hover.position, onDismiss: hover.dismiss, children: active !== null && (_jsx(ChartTooltipContent, { label: labels[active] ?? "", rows: series.map((s, i) => ({ name: s.name, swatch: _jsx(LineSwatch, { index: i }), value: formatValue(s.values[active] ?? null, unit) })) })) })] }));
|
|
58
|
+
}
|
|
59
|
+
// 項目の名前。軸の先から LABEL_GAP だけ外に、軸の向きに合わせて置く。
|
|
60
|
+
// 右の軸は名前の左端を、左の軸は右端を、真上と真下の軸は中央を合わせる。上下の向きに合わせて、文字の高さの半分まで上下にずらす。
|
|
61
|
+
// 真上の軸(1つ目)の名前は、いちばん外の目盛りの値と重ならないように、その上に置く(TOP_LABEL_OFFSET)。
|
|
62
|
+
// 斜めにしない(CHART-006)。svg の幅に収まらない名前は「…」で切り詰める。全文はツールチップと値の表で読める
|
|
63
|
+
function AxisLabels({ labels, area, width, at, }) {
|
|
64
|
+
return (_jsx("g", { children: labels.map((label, i) => {
|
|
65
|
+
const angle = axisAngle(i, labels.length);
|
|
66
|
+
const cos = Math.cos(angle);
|
|
67
|
+
const { x, y } = i === 0 ? { x: area.cx, y: area.cy - area.radius - TOP_LABEL_OFFSET - AXIS_FONT_SIZE / 2 } : at(i, area.radius + LABEL_GAP);
|
|
68
|
+
const anchor = Math.abs(cos) < 0.1 ? "middle" : cos > 0 ? "start" : "end";
|
|
69
|
+
const room = anchor === "middle" ? Math.min(2 * x, 2 * (width - x)) : anchor === "start" ? width - x : x;
|
|
70
|
+
return (_jsx("text", { x: x, y: i === 0 ? y : y + (Math.sin(angle) * AXIS_FONT_SIZE) / 2, textAnchor: anchor, dominantBaseline: "middle", className: "fill-muted-foreground text-xs", children: truncate(label, Math.min(LABEL_MAX, room)) }, i));
|
|
71
|
+
}) }));
|
|
72
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChartSeries } from "../chart/types.js";
|
|
2
|
+
export declare const LABEL_MAX = 96;
|
|
3
|
+
/** 中心と半径。svg の中の座標 */
|
|
4
|
+
export interface RadarArea {
|
|
5
|
+
cx: number;
|
|
6
|
+
cy: number;
|
|
7
|
+
radius: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function axisAngle(index: number, count: number): number;
|
|
10
|
+
export declare const TOP_LABEL_OFFSET: number;
|
|
11
|
+
export declare function layoutRadar(labels: readonly string[], width: number, height: number): RadarArea;
|
|
12
|
+
export declare function nearestAxis(x: number, y: number, area: RadarArea, count: number): number | null;
|
|
13
|
+
export declare function radarPath(values: ChartSeries["values"], point: (i: number, value: number) => {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// レーダーチャートの形の計算(中心と半径、軸の向き、マウスに近い軸、多角形の線)。部品の中だけで使い、書き出さない
|
|
2
|
+
import { AXIS_FONT_SIZE, textWidth } from "../chart/scale.js";
|
|
3
|
+
import { LABEL_GAP, SPACE_XS } from "../chart/spacing.js";
|
|
4
|
+
// 項目の名前に使う幅の上限。項目の軸(CategoryAxis)と同じ96pxにする
|
|
5
|
+
export const LABEL_MAX = 96;
|
|
6
|
+
// 軸の向き(ラジアン)。1つ目の軸を真上に置き、時計回りに等しい角度で並べる
|
|
7
|
+
export function axisAngle(index, count) {
|
|
8
|
+
return -Math.PI / 2 + (2 * Math.PI * index) / Math.max(count, 1);
|
|
9
|
+
}
|
|
10
|
+
// 真上の軸の先から、名前の文字の下端までの高さ。真上の軸の先のすぐ上(SPACE_XS)には、いちばん外の目盛りの値を書くので、
|
|
11
|
+
// 名前はその上に、SPACE_XS だけ離して置く
|
|
12
|
+
export const TOP_LABEL_OFFSET = SPACE_XS + AXIS_FONT_SIZE + SPACE_XS;
|
|
13
|
+
// svg の大きさと項目の名前から、中心と半径を決める。
|
|
14
|
+
// 左右には、項目の名前(96pxまで)と LABEL_GAP を置ける分をあける。上には、いちばん外の目盛りの値と真上の軸の名前を、
|
|
15
|
+
// 下には、LABEL_GAP と名前の文字の高さをあける。
|
|
16
|
+
// 狭い幅でも図が小さくなりすぎないように、半径は幅の1/4より小さくしない。そのときは、左右の名前を切り詰める
|
|
17
|
+
export function layoutRadar(labels, width, height) {
|
|
18
|
+
const longest = Math.min(LABEL_MAX, Math.max(0, ...labels.map(label => textWidth(label))));
|
|
19
|
+
const top = TOP_LABEL_OFFSET + AXIS_FONT_SIZE;
|
|
20
|
+
const bottom = LABEL_GAP + AXIS_FONT_SIZE;
|
|
21
|
+
const byWidth = width / 2 - LABEL_GAP - longest;
|
|
22
|
+
const byHeight = (height - top - bottom) / 2;
|
|
23
|
+
const radius = Math.max(1, Math.min(byHeight, Math.max(byWidth, width / 4)));
|
|
24
|
+
return { cx: width / 2, cy: top + Math.max(byHeight, 1), radius };
|
|
25
|
+
}
|
|
26
|
+
// マウスの位置から、中心から見た向きがいちばん近い軸を選ぶ
|
|
27
|
+
export function nearestAxis(x, y, area, count) {
|
|
28
|
+
if (count === 0)
|
|
29
|
+
return null;
|
|
30
|
+
const angle = Math.atan2(y - area.cy, x - area.cx) + Math.PI / 2;
|
|
31
|
+
const step = (2 * Math.PI) / count;
|
|
32
|
+
return ((Math.round(angle / step) % count) + count) % count;
|
|
33
|
+
}
|
|
34
|
+
// 系列の多角形の d。値のない項目で線を切る。最後の頂点から最初の頂点へは、どちらにも値があるときだけ閉じる
|
|
35
|
+
export function radarPath(values, point) {
|
|
36
|
+
const count = values.length;
|
|
37
|
+
const present = (i) => typeof values[i] === "number" && Number.isFinite(values[i]);
|
|
38
|
+
if (count > 0 && values.every((_, i) => present(i))) {
|
|
39
|
+
return values.map((v, i) => `${i === 0 ? "M" : "L"}${point(i, v).x} ${point(i, v).y}`).join("") + "Z";
|
|
40
|
+
}
|
|
41
|
+
// 値のない項目の次から描き始め、ひと回りする。こうすると、最後の頂点から最初の頂点への線も、切らずにつなげる
|
|
42
|
+
const start = values.findIndex((_, i) => !present(i)) + 1;
|
|
43
|
+
let d = "";
|
|
44
|
+
let drawing = false;
|
|
45
|
+
for (let k = 0; k < count; k++) {
|
|
46
|
+
const i = (start + k) % count;
|
|
47
|
+
if (!present(i)) {
|
|
48
|
+
drawing = false;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const p = point(i, values[i]);
|
|
52
|
+
d += `${drawing ? "L" : "M"}${p.x} ${p.y}`;
|
|
53
|
+
drawing = true;
|
|
54
|
+
}
|
|
55
|
+
return d;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadarChart.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadarChart.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** 円形の進みの1つのリング */
|
|
2
|
+
export interface RadialChartItem {
|
|
3
|
+
/** リングの名前。凡例、ツールチップ、値の表の1列目に出す */
|
|
4
|
+
name: string;
|
|
5
|
+
/** 今の値。0以上にする。値のないリングは null にする */
|
|
6
|
+
value: number | null;
|
|
7
|
+
/** 目標(満点)の値。弧は value / max の割合まで塗る。省いたときは100 */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** このリングの値の単位。リングごとに単位が違うとき(「kcal」「分」)だけ渡す。省いたときは、部品の unit */
|
|
10
|
+
unit?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RadialChartProps {
|
|
13
|
+
/** グラフの名前。図の上に出し、図と値の表の名前にもする */
|
|
14
|
+
label: string;
|
|
15
|
+
/** グラフが伝える要点を、1〜2文で書く。「今月の目標の8割まで進みました。」のようにする */
|
|
16
|
+
description: string;
|
|
17
|
+
/** リング。外側から順に描く。3つまで */
|
|
18
|
+
items: readonly RadialChartItem[];
|
|
19
|
+
/**
|
|
20
|
+
* 形。full は円(円形の進み)、half は半円(ゲージ)。省いたときは full。
|
|
21
|
+
* どちらも、弧を今の値の割合まで塗る。ゲージにも針は描かない(docs/chart/drawing.md の CHART-025)
|
|
22
|
+
*/
|
|
23
|
+
shape?: "full" | "half";
|
|
24
|
+
/** 値の単位(「%」「点」「件」)。値の書き方は docs/writing/date-and-number.md の「日付、数値、単位」に従う */
|
|
25
|
+
unit?: string;
|
|
26
|
+
/** 値の名前。値の表の列の見出しと、ツールチップに出す。省いたときは「値」 */
|
|
27
|
+
valueLabel?: string;
|
|
28
|
+
/** 目標(max)の名前(「目標」「満点」)。リングが1つのときに数値の下に出し、値の表の列の見出しにもする。省いたときは「目標」 */
|
|
29
|
+
maxLabel?: string;
|
|
30
|
+
/** リングの名前の列の見出し。値の表の1列目の見出しにする。省いたときは「項目」 */
|
|
31
|
+
categoryLabel?: string;
|
|
32
|
+
/** 値が1つもないときの文。省いたときは「まだデータがありません。」 */
|
|
33
|
+
emptyMessage?: string;
|
|
34
|
+
/** 図の高さ(px)。省いたときは、full が240、half が160。幅は、置いた場所の幅に合わせる */
|
|
35
|
+
height?: number;
|
|
36
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function RadialChart({ items, shape, unit, valueLabel, maxLabel, categoryLabel, height, ...props }: RadialChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow } from "../table/Table.js";
|
|
5
|
+
import { ChartLayout } from "../chart/ChartFrame.js";
|
|
6
|
+
import { ChartTooltip } from "../chart/ChartTooltip.js";
|
|
7
|
+
import { formatValue } from "../chart/format.js";
|
|
8
|
+
import { Legend } from "../chart/Legend.js";
|
|
9
|
+
import { AXIS_FONT_SIZE, textWidth } from "../chart/scale.js";
|
|
10
|
+
import { SERIES_STROKE, seriesIndex } from "../chart/series.js";
|
|
11
|
+
import { RING_GAP, SPACE_XS } from "../chart/spacing.js";
|
|
12
|
+
import { ChartTooltipContent, usePointerPick } from "../chart/useChartHover.js";
|
|
13
|
+
// リングの数の上限(docs/chart/drawing.md の CHART-024)。内側のリングほど短くなり、4つ目からは弧の長さを見比べられない
|
|
14
|
+
const MAX_RINGS = 3;
|
|
15
|
+
// リングの太さ(px)。間隔ではなく形の値(docs/chart/size-and-spacing.md の「間隔」の表の外)
|
|
16
|
+
const RING_WIDTH = 16;
|
|
17
|
+
const isValue = (v) => typeof v === "number" && Number.isFinite(v);
|
|
18
|
+
const maxOf = (item) => item.max ?? 100;
|
|
19
|
+
// 目標に対する割合(%)。小数第1位までにする。値がないか、目標が0以下のときは null
|
|
20
|
+
function ratioOf(item) {
|
|
21
|
+
const max = maxOf(item);
|
|
22
|
+
if (!isValue(item.value) || !(max > 0))
|
|
23
|
+
return null;
|
|
24
|
+
return Math.round((item.value / max) * 1000) / 10;
|
|
25
|
+
}
|
|
26
|
+
// 弧を塗る割合(0〜1)。目標を超えたときは1周(半円では端まで)で止め、2周目は描かない。超えた量は文字の値で読む
|
|
27
|
+
function fillOf(item) {
|
|
28
|
+
const ratio = ratioOf(item);
|
|
29
|
+
return ratio === null ? 0 : Math.min(1, Math.max(0, ratio / 100));
|
|
30
|
+
}
|
|
31
|
+
// 開発時の知らせ。リングが多すぎるとき(CHART-024)と、負の値や0以下の目標を渡したとき
|
|
32
|
+
function useRadialWarning(items) {
|
|
33
|
+
const tooMany = items.length > MAX_RINGS;
|
|
34
|
+
const invalid = items.some(item => (isValue(item.value) && item.value < 0) || !(maxOf(item) > 0));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (tooMany)
|
|
37
|
+
console.warn(`RadialChart: リングは${MAX_RINGS}つまでにする。4つ以上は BarList か表で示す(docs/chart/drawing.md の CHART-024)`);
|
|
38
|
+
}, [tooMany]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (invalid)
|
|
41
|
+
console.warn("RadialChart: value は0以上、max は0より大きくする。上限や目標のない量は、円形の進みで描かない(docs/chart/drawing.md の CHART-026)");
|
|
42
|
+
}, [invalid]);
|
|
43
|
+
}
|
|
44
|
+
// 点数や目標に対する割合を、円の弧で示す。shape="half" で、半円のゲージにする。
|
|
45
|
+
// 弧は、真上(半円では左の端)から時計回りに、目標に対する割合まで塗る。リングは3つまで外側から重ね、系列の色(chart-1〜chart-3)で塗る。
|
|
46
|
+
// 色だけで見分けさせず、凡例とツールチップの見本で、何番目のリングかを形で示す(docs/chart/color.md の CHART-002)。
|
|
47
|
+
// リングが1つのときは、真ん中に数値と目標を書く。2つ以上のときは、凡例に名前と数値を並べる
|
|
48
|
+
export function RadialChart({ items, shape = "full", unit, valueLabel = "値", maxLabel = "目標", categoryLabel = "項目", height, ...props }) {
|
|
49
|
+
useRadialWarning(items);
|
|
50
|
+
const rings = items.slice(0, MAX_RINGS);
|
|
51
|
+
const ratioLabel = `${maxLabel}に対する割合`;
|
|
52
|
+
const unitOf = (item) => item.unit ?? unit;
|
|
53
|
+
const legend = rings.length > 1 ? (_jsx(Legend, { items: rings.map((item, i) => ({
|
|
54
|
+
name: item.name,
|
|
55
|
+
value: formatValue(item.value, unitOf(item)),
|
|
56
|
+
swatch: _jsx(RingSwatch, { index: i, count: rings.length, shape: shape }),
|
|
57
|
+
})) })) : undefined;
|
|
58
|
+
return (_jsx(ChartLayout, { ...props, component: "RadialChart", seriesNames: rings.map(item => item.name), empty: !items.some(item => isValue(item.value)), height: height ?? (shape === "half" ? 160 : 240), swatch: i => _jsx(RingSwatch, { index: i, count: rings.length, shape: shape }), legend: legend, maxSeries: Infinity, table: _jsxs(Table, { children: [_jsx("caption", { className: "sr-only", children: props.label }), _jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableHeaderCell, { children: categoryLabel }), _jsx(TableHeaderCell, { className: "text-right", children: valueLabel }), _jsx(TableHeaderCell, { className: "text-right", children: maxLabel }), _jsx(TableHeaderCell, { className: "text-right", children: ratioLabel })] }) }), _jsx(TableBody, { children: items.map((item, i) => (_jsxs(TableRow, { children: [_jsx(TableHeaderCell, { scope: "row", children: item.name }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(item.value, unitOf(item)) }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(maxOf(item), unitOf(item)) }), _jsx(TableCell, { className: "whitespace-nowrap text-right tabular-nums", children: formatValue(ratioOf(item), "%") })] }, i))) })] }), children: size => (_jsx(RadialPlot, { rings: rings, shape: shape, unitOf: unitOf, valueLabel: valueLabel, maxLabel: maxLabel, ratioLabel: ratioLabel, ...size })) }));
|
|
59
|
+
}
|
|
60
|
+
// 中心(cx, cy)から半径 r の円の上の、角度 angle(ラジアン。0 が右、時計回り)の点
|
|
61
|
+
function at(cx, cy, r, angle) {
|
|
62
|
+
return { x: cx + r * Math.cos(angle), y: cy + r * Math.sin(angle) };
|
|
63
|
+
}
|
|
64
|
+
// 角度 start から、時計回りに span(ラジアン)だけ進む弧の線。1周のときは、半周の弧を2つつないで円にする
|
|
65
|
+
function arcPath(cx, cy, r, start, span) {
|
|
66
|
+
if (span >= Math.PI * 2 - 1e-6) {
|
|
67
|
+
const a = at(cx, cy, r, start);
|
|
68
|
+
const b = at(cx, cy, r, start + Math.PI);
|
|
69
|
+
return `M${a.x} ${a.y}A${r} ${r} 0 1 1 ${b.x} ${b.y}A${r} ${r} 0 1 1 ${a.x} ${a.y}`;
|
|
70
|
+
}
|
|
71
|
+
const a = at(cx, cy, r, start);
|
|
72
|
+
const b = at(cx, cy, r, start + span);
|
|
73
|
+
return `M${a.x} ${a.y}A${r} ${r} 0 ${span > Math.PI ? 1 : 0} 1 ${b.x} ${b.y}`;
|
|
74
|
+
}
|
|
75
|
+
// 形ごとの、弧の始まりの角度と、目標まで塗ったときの角度の幅。円は真上から1周、半円は左の端から真上を通って右の端まで
|
|
76
|
+
function sweep(shape) {
|
|
77
|
+
return shape === "full" ? { start: -Math.PI / 2, total: Math.PI * 2 } : { start: Math.PI, total: Math.PI };
|
|
78
|
+
}
|
|
79
|
+
// 凡例とツールチップの見本。リングの数だけ同心の弧を細い線で描き、そのリングの位置の弧だけを系列の色で太く描く。
|
|
80
|
+
// 色を見分けられなくても、外から何番目のリングかが形で分かる
|
|
81
|
+
function RingSwatch({ index, count, shape }) {
|
|
82
|
+
const { start, total } = sweep(shape);
|
|
83
|
+
const cy = shape === "full" ? 8 : 12;
|
|
84
|
+
return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 16 16", className: "size-4 shrink-0", children: Array.from({ length: count }, (_, i) => {
|
|
85
|
+
const r = 7 - i * 2.5;
|
|
86
|
+
return i === index ? (_jsx("path", { d: arcPath(8, cy, r, start, total), fill: "none", strokeWidth: "2", className: SERIES_STROKE[seriesIndex(i)] }, i)) : (_jsx("path", { d: arcPath(8, cy, r, start, total), fill: "none", strokeWidth: "1", className: "stroke-muted-foreground" }, i));
|
|
87
|
+
}) }));
|
|
88
|
+
}
|
|
89
|
+
// 真ん中の数値の文字の大きさ(text-2xl)と、その下の目標の文字の大きさ(text-xs)
|
|
90
|
+
const VALUE_FONT_SIZE = 24;
|
|
91
|
+
function RadialPlot({ rings, shape, unitOf, valueLabel, maxLabel, ratioLabel, width, height }) {
|
|
92
|
+
const { start, total } = sweep(shape);
|
|
93
|
+
// 円は、幅と高さの小さいほうを直径にして真ん中に置く。半円は、幅の半分と高さの小さいほうを半径にし、平らな辺を下にそろえる
|
|
94
|
+
const outer = shape === "full" ? Math.min(width, height) / 2 : Math.min(width / 2, height);
|
|
95
|
+
const cx = width / 2;
|
|
96
|
+
const cy = shape === "full" ? height / 2 : (height + outer) / 2;
|
|
97
|
+
// リングの太さの中央の半径。外側から順に、リングどうしの間(XS)をあけて内側へ並べる
|
|
98
|
+
const radius = (i) => outer - RING_WIDTH / 2 - i * (RING_WIDTH + RING_GAP);
|
|
99
|
+
const inner = outer - rings.length * RING_WIDTH - (rings.length - 1) * RING_GAP;
|
|
100
|
+
// マウスの位置から、乗せているリングを決める。リングの太さに、隣との間の半分ずつを足した帯で判定する。半円では、平らな辺より下では出さない
|
|
101
|
+
const hover = usePointerPick((x, y) => {
|
|
102
|
+
if (shape === "half" && y > cy)
|
|
103
|
+
return null;
|
|
104
|
+
const d = Math.hypot(x - cx, y - cy);
|
|
105
|
+
const i = Math.floor((outer + RING_GAP / 2 - d) / (RING_WIDTH + RING_GAP));
|
|
106
|
+
return i >= 0 && i < rings.length ? i : null;
|
|
107
|
+
});
|
|
108
|
+
const active = hover.index;
|
|
109
|
+
const activeItem = active !== null ? rings[active] : undefined;
|
|
110
|
+
// リングが1つのときは、真ん中に数値と目標を書く。内側の円に収まらないときは書かない(値は値の表とツールチップで読める)
|
|
111
|
+
const single = rings.length === 1 ? rings[0] : undefined;
|
|
112
|
+
const valueText = single ? formatValue(single.value, unitOf(single)) : "";
|
|
113
|
+
const maxText = single ? `${maxLabel} ${formatValue(maxOf(single), unitOf(single))}` : "";
|
|
114
|
+
const room = shape === "full" ? inner * 2 * 0.8 : inner * 2 * 0.9;
|
|
115
|
+
const showCenter = single !== undefined &&
|
|
116
|
+
textWidth(valueText, VALUE_FONT_SIZE) <= room &&
|
|
117
|
+
textWidth(maxText) <= room &&
|
|
118
|
+
VALUE_FONT_SIZE + SPACE_XS + AXIS_FONT_SIZE <= (shape === "full" ? inner * 2 * 0.8 : inner * 0.9);
|
|
119
|
+
// 円では、数値と目標の2行の組を中心にそろえる。半円では、目標の行の下端を平らな辺にそろえる
|
|
120
|
+
const maxBaseline = shape === "full" ? cy + (VALUE_FONT_SIZE + SPACE_XS + AXIS_FONT_SIZE) / 2 : cy;
|
|
121
|
+
const valueBaseline = maxBaseline - AXIS_FONT_SIZE - SPACE_XS;
|
|
122
|
+
return (_jsxs(_Fragment, { children: [_jsxs("svg", { "aria-hidden": "true", width: width, height: height, className: "block overflow-visible", children: [rings.map((item, i) => {
|
|
123
|
+
const r = radius(i);
|
|
124
|
+
const fill = fillOf(item);
|
|
125
|
+
return (_jsxs("g", { children: [_jsx("path", { d: arcPath(cx, cy, r, start, total), fill: "none", strokeWidth: RING_WIDTH, className: "stroke-muted" }), fill > 0 && (_jsx("path", { d: arcPath(cx, cy, r, start, total * fill), fill: "none", strokeWidth: RING_WIDTH, className: SERIES_STROKE[seriesIndex(i)] }))] }, i));
|
|
126
|
+
}), active !== null && (_jsxs("g", { fill: "none", strokeWidth: "2", className: "stroke-foreground", children: [_jsx("path", { d: arcPath(cx, cy, radius(active) + RING_WIDTH / 2 + 1, start, total) }), _jsx("path", { d: arcPath(cx, cy, radius(active) - RING_WIDTH / 2 - 1, start, total) })] })), showCenter && (_jsxs(_Fragment, { children: [_jsx("text", { x: cx, y: valueBaseline, textAnchor: "middle", className: "fill-foreground text-2xl font-semibold tabular-nums", children: valueText }), _jsx("text", { x: cx, y: maxBaseline, textAnchor: "middle", className: "fill-muted-foreground text-xs tabular-nums", children: maxText })] })), _jsx("rect", { x: cx - outer - RING_GAP, y: cy - outer - RING_GAP, width: (outer + RING_GAP) * 2, height: shape === "full" ? (outer + RING_GAP) * 2 : outer + RING_GAP, fill: "transparent", ...hover.handlers })] }), _jsx(ChartTooltip, { position: hover.position, onDismiss: hover.dismiss, children: active !== null && activeItem && (_jsx(ChartTooltipContent, { label: activeItem.name, rows: [
|
|
127
|
+
{
|
|
128
|
+
name: valueLabel,
|
|
129
|
+
swatch: rings.length > 1 ? _jsx(RingSwatch, { index: active, count: rings.length, shape: shape }) : undefined,
|
|
130
|
+
value: formatValue(activeItem.value, unitOf(activeItem)),
|
|
131
|
+
},
|
|
132
|
+
{ name: maxLabel, value: formatValue(maxOf(activeItem), unitOf(activeItem)) },
|
|
133
|
+
{ name: ratioLabel, value: formatValue(ratioOf(activeItem), "%") },
|
|
134
|
+
] })) })] }));
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadialChart.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RadialChart.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type FieldsetHTMLAttributes, type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface RadioGroupProps extends Omit<FieldsetHTMLAttributes<HTMLFieldSetElement>, "onChange" | "defaultValue"> {
|
|
3
|
+
/** グループの名前。`<legend>` に書き、読み上げで何の選択かを伝える */
|
|
4
|
+
legend: string;
|
|
5
|
+
/** 送信するときの名前。子の Radio に配る */
|
|
6
|
+
name: string;
|
|
7
|
+
/** 選択中の Radio の value。渡すと、選択を使う側で持つ */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** 選択を使う側で持たないときの、初めの選択 */
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
/** Radio を選んだときに、その value で呼ぶ */
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
/** 必須の項目。`<legend>` の後ろに「必須」と書き、Radio に required を付ける */
|
|
14
|
+
required?: boolean;
|
|
15
|
+
/** どう直せばよいかを書いたエラー。ないときは省く */
|
|
16
|
+
error?: string;
|
|
17
|
+
/** Radio を並べる */
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function RadioGroup({ legend, name, value, defaultValue, onChange, required, error, children, className, "aria-describedby": describedBy, ...props }: RadioGroupProps): import("react").JSX.Element;
|
|
23
|
+
export interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "name" | "value" | "children"> {
|
|
24
|
+
/** 送信する値。グループの中で重ならない文字列にする */
|
|
25
|
+
value: string;
|
|
26
|
+
/** 選択肢の文言 */
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function Radio({ value, children, className, onChange, ...props }: RadioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useId } from "react";
|
|
3
|
+
import { FieldError } from "../field-error/FieldError.js";
|
|
4
|
+
import { cn } from "../../lib/cn.js";
|
|
5
|
+
import { inputFocus, inputInvalid, inputSurface } from "../input/inputStyle.js";
|
|
6
|
+
const RadioGroupContext = createContext(null);
|
|
7
|
+
// fieldset と legend でグループに名前を付け、name と選択を子の Radio に配る。
|
|
8
|
+
// 矢印キーでの移動はネイティブの振る舞いに任せる
|
|
9
|
+
export function RadioGroup({ legend, name, value, defaultValue, onChange, required, error, children, className, "aria-describedby": describedBy, ...props }) {
|
|
10
|
+
const errorId = useId();
|
|
11
|
+
return (_jsxs("fieldset", { className: cn("min-w-0", className), "aria-describedby": cn(describedBy, error && errorId) || undefined, ...props, children: [_jsxs("legend", { className: "mb-2 text-sm font-medium leading-tight text-foreground", children: [legend, required && _jsx("span", { className: "font-normal text-muted-foreground", children: "\uFF08\u5FC5\u9808\uFF09" })] }), _jsx(RadioGroupContext.Provider, { value: { name, value, defaultValue, onChange, required, invalid: Boolean(error) }, children: _jsx("div", { children: children }) }), _jsx(FieldError, { id: errorId, className: "*:mt-2", children: error })] }));
|
|
12
|
+
}
|
|
13
|
+
// ネイティブの <input type="radio"> の見た目だけを描き直す。
|
|
14
|
+
// label で丸と文言を包み、行の全体を押せる範囲にして、高さを44px以上にする
|
|
15
|
+
export function Radio({ value, children, className, onChange, ...props }) {
|
|
16
|
+
const group = useContext(RadioGroupContext);
|
|
17
|
+
const controlled = group?.value !== undefined;
|
|
18
|
+
return (_jsx("label", { className: cn("flex min-h-11 w-fit min-w-11 cursor-pointer items-center text-sm leading-tight text-foreground has-disabled:cursor-not-allowed has-disabled:opacity-50", className), children: _jsxs("span", { className: "flex items-start gap-2", children: [_jsx("span", { className: "flex h-lh shrink-0 items-center", children: _jsxs("span", { className: "relative flex size-5 shrink-0", children: [_jsx("input", { type: "radio", name: group?.name, value: value, required: group?.required, "aria-invalid": group?.invalid || undefined, checked: controlled ? group?.value === value : undefined, defaultChecked: !controlled && group?.defaultValue !== undefined ? group.defaultValue === value : undefined, onChange: e => {
|
|
19
|
+
group?.onChange?.(value);
|
|
20
|
+
onChange?.(e);
|
|
21
|
+
},
|
|
22
|
+
// 枠線、フォーカス、エラーは入力欄と同じ(inputStyle.ts)。無効のときは label の側で薄くするので、ここではカーソルだけを変える
|
|
23
|
+
className: cn("peer size-5 cursor-pointer appearance-none rounded-full checked:border-primary checked:bg-primary disabled:cursor-not-allowed", inputSurface, inputFocus, inputInvalid), ...props }), _jsx("span", { "aria-hidden": "true", className: "pointer-events-none absolute inset-0 m-auto size-2 rounded-full bg-primary-icon opacity-0 peer-checked:opacity-100" })] }) }), _jsx("span", { children: children })] }) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Radio.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Radio.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export interface ReplyLoaderProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "role" | "aria-live" | "aria-atomic"> {
|
|
3
|
+
/** 返答を待っている間(文がまだ出ていない間)は true にする。文が出始めたら、生成が終わったら、止めたら、失敗したら false にする */
|
|
4
|
+
pending: boolean;
|
|
5
|
+
/** 進行中の文言。見た目にも読み上げにも、この文言だけを出す。省いたときは「返答を生成しています」 */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ReplyLoader({ pending, label, className, ...props }: ReplyLoaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Spinner } from "../spinner/Spinner.js";
|
|
3
|
+
// 返答を待っている間に、メッセージの並びの末尾(返答が出る場所)で、スピナーと文言で進行中を示す。入力欄のそばには置かない(COMPONENTS-083)。
|
|
4
|
+
// 外側は、進行中でないときも置いておく role="status"(aria-live="polite")の領域にする。領域が後から DOM に入ると、
|
|
5
|
+
// 読み上げられないことがあるためである。進行中になったら文言を入れ、読み上げでは文言だけを1回伝える。
|
|
6
|
+
// 少しずつ増える返答の途中の文と、生成が終わった後の全文は、この部品では読ませない(全文は使う側のメッセージの領域で読む)
|
|
7
|
+
export function ReplyLoader({ pending, label = "返答を生成しています", className, ...props }) {
|
|
8
|
+
return (_jsx("div", { ...props, role: "status", "aria-live": "polite", "aria-atomic": "true", className: className, children: pending && (_jsxs("p", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [_jsx(Spinner, {}), _jsx("span", { className: "text-trim", children: label })] })) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ReplyLoader.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ReplyLoader.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** サンキー図の1つの流れ */
|
|
2
|
+
export interface SankeyLink {
|
|
3
|
+
/** 流れの元の項目の名前 */
|
|
4
|
+
source: string;
|
|
5
|
+
/** 流れの先の項目の名前 */
|
|
6
|
+
target: string;
|
|
7
|
+
/** 流れの量。0以上にする */
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SankeyChartProps {
|
|
11
|
+
/** グラフの名前。図の上に出し、図と値の表の名前にもする */
|
|
12
|
+
label: string;
|
|
13
|
+
/** グラフが伝える要点を、1〜2文で書く。「申し込みの半分は、検索から来ています。」のようにする */
|
|
14
|
+
description: string;
|
|
15
|
+
/**
|
|
16
|
+
* 流れ。項目は、名前で結びつける。項目の段(列)は、最初の元から数えた流れの数で決まり、同じ段の項目は、流れに初めて出た順に上から並べる。
|
|
17
|
+
* 1つの段の項目は5つまでにする(docs/chart/color.md の CHART-029)。流れを元の項目へ戻さない(docs/chart/drawing.md の CHART-028)
|
|
18
|
+
*/
|
|
19
|
+
links: readonly SankeyLink[];
|
|
20
|
+
/** 量の単位(「件」「万円」)。値の書き方は docs/writing/date-and-number.md の「日付、数値、単位」に従う */
|
|
21
|
+
unit?: string;
|
|
22
|
+
/** 量の名前(「申し込みの数」)。値の表の列の見出しと、ツールチップに出す。省いたときは「量」 */
|
|
23
|
+
valueLabel?: string;
|
|
24
|
+
/** 値の表の、流れの元の列の見出し。省いたときは「元」 */
|
|
25
|
+
sourceLabel?: string;
|
|
26
|
+
/** 値の表の、流れの先の列の見出し。省いたときは「先」 */
|
|
27
|
+
targetLabel?: string;
|
|
28
|
+
/** 値が1つもないときの文。省いたときは「まだデータがありません。」 */
|
|
29
|
+
emptyMessage?: string;
|
|
30
|
+
/** 図の高さ(px)。省いたときは240。幅は、置いた場所の幅に合わせる */
|
|
31
|
+
height?: number;
|
|
32
|
+
/** 外側の配置(余白と幅)だけに使う */
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function SankeyChart({ links, unit, valueLabel, sourceLabel, targetLabel, ...props }: SankeyChartProps): import("react").JSX.Element;
|