@torpor/ui 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -7
- package/dist/Accordion/Accordion.torp +42 -165
- package/dist/Accordion/AccordionContent.torp +6 -6
- package/dist/Accordion/AccordionHeader.torp +7 -11
- package/dist/Accordion/AccordionItem.torp +24 -24
- package/dist/Accordion/AccordionTrigger.torp +17 -8
- package/dist/Accordion/AccordionTypes.ts +1 -1
- package/dist/Accordion/index.d.ts +23 -25
- package/dist/Accordion/index.js +6 -22
- package/dist/Breadcrumb/Breadcrumb.torp +12 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +6 -6
- package/dist/Breadcrumb/BreadcrumbList.torp +21 -0
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +4 -4
- package/dist/Breadcrumb/index.d.ts +39 -15
- package/dist/Breadcrumb/index.js +5 -14
- package/dist/Calendar/Calendar.torp +163 -156
- package/dist/Calendar/CalendarDay.torp +91 -45
- package/dist/Calendar/CalendarDayHeader.torp +36 -0
- package/dist/Calendar/CalendarGrid.torp +104 -0
- package/dist/Calendar/CalendarGridHeader.torp +43 -0
- package/dist/Calendar/CalendarHeader.torp +48 -0
- package/dist/Calendar/CalendarHeaderTrigger.torp +54 -0
- package/dist/Calendar/CalendarTypes.ts +24 -3
- package/dist/Calendar/buildDays.ts +54 -0
- package/dist/Calendar/index.d.ts +191 -5
- package/dist/Calendar/index.js +8 -10
- package/dist/Carousel/Carousel.torp +180 -0
- package/dist/Carousel/CarouselIndicators.torp +65 -0
- package/dist/Carousel/CarouselNext.torp +43 -0
- package/dist/Carousel/CarouselPrevious.torp +44 -0
- package/dist/Carousel/CarouselSlide.torp +57 -0
- package/dist/Carousel/CarouselTypes.ts +28 -0
- package/dist/Carousel/index.d.ts +147 -0
- package/dist/Carousel/index.js +6 -0
- package/dist/Charts/BarChart.torp +55 -144
- package/dist/Charts/Chart.torp +120 -0
- package/dist/Charts/ChartBars.torp +78 -0
- package/dist/Charts/ChartColumns.torp +66 -0
- package/dist/Charts/ChartGrid.torp +54 -0
- package/dist/Charts/ChartLines.torp +60 -0
- package/dist/Charts/ChartTypes.ts +25 -0
- package/dist/Charts/ChartXAxis.torp +83 -0
- package/dist/Charts/ChartYAxis.torp +105 -0
- package/dist/Charts/ColumnChart.torp +70 -0
- package/dist/Charts/GridLines.torp +4 -4
- package/dist/Charts/LineChart.torp +55 -178
- package/dist/Charts/PieChart.torp +14 -20
- package/dist/Charts/ScatterChart.torp +45 -38
- package/dist/Charts/SparkLine.torp +16 -19
- package/dist/Charts/XAxis.torp +11 -11
- package/dist/Charts/YAxis.torp +8 -8
- package/dist/Charts/index.d.ts +328 -79
- package/dist/Charts/index.js +17 -34
- package/dist/ColorPicker/ColorPalette.torp +154 -0
- package/dist/ColorPicker/ColorPicker.torp +157 -0
- package/dist/ColorPicker/index.d.ts +85 -0
- package/dist/ColorPicker/index.js +3 -0
- package/dist/ComboBox/ComboBox.torp +205 -0
- package/dist/ComboBox/ComboBoxContent.torp +112 -0
- package/dist/ComboBox/ComboBoxInput.torp +145 -0
- package/dist/ComboBox/ComboBoxTrigger.torp +49 -0
- package/dist/ComboBox/ComboBoxTypes.ts +39 -0
- package/dist/ComboBox/index.d.ts +152 -0
- package/dist/ComboBox/index.js +6 -0
- package/dist/CommandPalette/CommandPalette.torp +220 -0
- package/dist/CommandPalette/CommandTypes.ts +14 -0
- package/dist/CommandPalette/index.d.ts +45 -0
- package/dist/CommandPalette/index.js +2 -0
- package/dist/Contextual/Contextual.torp +32 -50
- package/dist/Contextual/ContextualContent.torp +29 -73
- package/dist/Contextual/ContextualHover.torp +112 -0
- package/dist/Contextual/ContextualTrigger.torp +31 -42
- package/dist/Contextual/ContextualTypes.ts +4 -17
- package/dist/Contextual/index.d.ts +44 -27
- package/dist/Contextual/index.js +5 -14
- package/dist/DataGrid/DataGrid.torp +496 -0
- package/dist/DataGrid/DataGridTypes.ts +25 -0
- package/dist/DataGrid/index.d.ts +90 -0
- package/dist/DataGrid/index.js +3 -0
- package/dist/DataGrid/sortRows.ts +32 -0
- package/dist/DatePicker/DatePicker.torp +222 -0
- package/dist/DatePicker/DatePickerHeader.torp +20 -0
- package/dist/DatePicker/index.d.ts +55 -0
- package/dist/DatePicker/index.js +2 -0
- package/dist/DateRangePicker/DateRangePicker.torp +311 -0
- package/dist/DateRangePicker/DateRangePickerDay.torp +137 -0
- package/dist/DateRangePicker/DateRangePickerTypes.ts +21 -0
- package/dist/DateRangePicker/index.d.ts +76 -0
- package/dist/DateRangePicker/index.js +3 -0
- package/dist/Dialog/Dialog.torp +24 -17
- package/dist/Dialog/DialogBody.torp +5 -9
- package/dist/Dialog/DialogButton.torp +12 -12
- package/dist/Dialog/DialogFooter.torp +3 -7
- package/dist/Dialog/DialogHeader.torp +6 -10
- package/dist/Dialog/index.d.ts +27 -27
- package/dist/Dialog/index.js +6 -22
- package/dist/Disclosure/Disclosure.torp +18 -18
- package/dist/Disclosure/DisclosureContent.torp +5 -6
- package/dist/Disclosure/DisclosureHeader.torp +7 -11
- package/dist/Disclosure/DisclosureTrigger.torp +4 -5
- package/dist/Disclosure/index.d.ts +14 -16
- package/dist/Disclosure/index.js +5 -18
- package/dist/Drawer/Drawer.torp +19 -49
- package/dist/Drawer/DrawerContent.torp +67 -13
- package/dist/Drawer/DrawerOverlay.torp +4 -4
- package/dist/Drawer/DrawerTrigger.torp +16 -4
- package/dist/Drawer/DrawerTypes.ts +3 -0
- package/dist/Drawer/index.d.ts +16 -20
- package/dist/Drawer/index.js +5 -18
- package/dist/FocusGroup/FocusGroup.torp +70 -0
- package/dist/FocusGroup/FocusGroupButton.torp +59 -0
- package/dist/FocusGroup/FocusGroupTypes.ts +14 -0
- package/dist/FocusGroup/index.d.ts +44 -0
- package/dist/FocusGroup/index.js +3 -0
- package/dist/Form/CheckBox.torp +27 -18
- package/dist/Form/Field.torp +17 -17
- package/dist/Form/File.torp +31 -22
- package/dist/Form/FileDrop.torp +187 -0
- package/dist/Form/Form.torp +24 -22
- package/dist/Form/FormTypes.ts +2 -0
- package/dist/Form/FormValues.torp +37 -0
- package/dist/Form/Hidden.torp +4 -12
- package/dist/Form/Input.torp +38 -32
- package/dist/Form/Label.torp +3 -3
- package/dist/Form/Message.torp +13 -5
- package/dist/Form/MessageSummary.torp +5 -4
- package/dist/Form/Option.torp +11 -7
- package/dist/Form/Select.torp +32 -28
- package/dist/Form/TextArea.torp +35 -31
- package/dist/Form/Toggle.torp +109 -0
- package/dist/Form/index.d.ts +178 -79
- package/dist/Form/index.js +16 -50
- package/dist/ListBox/ListBox.torp +253 -150
- package/dist/ListBox/ListBoxItem.torp +54 -30
- package/dist/ListBox/ListBoxSeparator.torp +5 -2
- package/dist/ListBox/ListBoxTypes.ts +23 -5
- package/dist/ListBox/LoadedListBoxItems.torp +41 -0
- package/dist/ListBox/index.d.ts +56 -17
- package/dist/ListBox/index.js +4 -14
- package/dist/MaskedInput/MaskedInput.torp +143 -0
- package/dist/MaskedInput/index.d.ts +52 -0
- package/dist/MaskedInput/index.js +2 -0
- package/dist/Menu/Menu.torp +86 -71
- package/dist/Menu/MenuButton.torp +17 -10
- package/dist/Menu/MenuCheck.torp +22 -18
- package/dist/Menu/MenuGroup.torp +4 -4
- package/dist/Menu/MenuIndicator.torp +5 -13
- package/dist/Menu/MenuPopout.torp +20 -50
- package/dist/Menu/MenuPopoutContent.torp +15 -66
- package/dist/Menu/MenuPopoutTrigger.torp +19 -100
- package/dist/Menu/MenuRadio.torp +25 -26
- package/dist/Menu/MenuRadioGroup.torp +25 -68
- package/dist/Menu/MenuSeparator.torp +3 -2
- package/dist/Menu/MenuTypes.ts +9 -19
- package/dist/Menu/index.d.ts +45 -51
- package/dist/Menu/index.js +12 -46
- package/dist/MenuBar/MenuBar.torp +31 -83
- package/dist/MenuBar/MenuBarItem.torp +33 -51
- package/dist/MenuBar/MenuBarItemContent.torp +15 -101
- package/dist/MenuBar/MenuBarItemTrigger.torp +20 -55
- package/dist/MenuBar/MenuBarTypes.ts +11 -10
- package/dist/MenuBar/index.d.ts +17 -19
- package/dist/MenuBar/index.js +5 -18
- package/dist/Modal/Modal.torp +22 -47
- package/dist/Modal/ModalContent.torp +21 -44
- package/dist/Modal/ModalOverlay.torp +4 -4
- package/dist/Modal/ModalTrigger.torp +16 -32
- package/dist/Modal/ModalTypes.ts +5 -16
- package/dist/Modal/index.d.ts +17 -29
- package/dist/Modal/index.js +29 -28
- package/dist/Modal/index.js.map +1 -1
- package/dist/Modal/showPrompt.ts +2 -2
- package/dist/NavMenu/NavMenu.torp +22 -111
- package/dist/NavMenu/NavMenuButton.torp +7 -8
- package/dist/NavMenu/NavMenuElement.torp +6 -7
- package/dist/NavMenu/NavMenuGroup.torp +5 -5
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -8
- package/dist/NavMenu/NavMenuLink.torp +7 -10
- package/dist/NavMenu/NavMenuPopout.torp +15 -60
- package/dist/NavMenu/NavMenuPopoutContent.torp +14 -73
- package/dist/NavMenu/NavMenuPopoutTrigger.torp +17 -99
- package/dist/NavMenu/NavMenuSeparator.torp +3 -7
- package/dist/NavMenu/NavMenuTypes.ts +4 -14
- package/dist/NavMenu/index.d.ts +40 -44
- package/dist/NavMenu/index.js +11 -42
- package/dist/Notification/Notification.torp +12 -24
- package/dist/Notification/NotificationClose.torp +6 -3
- package/dist/Notification/NotificationContainer.torp +3 -7
- package/dist/Notification/NotificationContent.torp +3 -7
- package/dist/Notification/NotificationTypes.ts +1 -1
- package/dist/Notification/index.d.ts +15 -12
- package/dist/Notification/index.js +22 -32
- package/dist/Notification/index.js.map +1 -1
- package/dist/NumberInput/NumberInput.torp +255 -0
- package/dist/NumberInput/index.d.ts +44 -0
- package/dist/NumberInput/index.js +2 -0
- package/dist/Pagination/Pagination.torp +41 -34
- package/dist/Pagination/PaginationItem.torp +50 -13
- package/dist/Pagination/PaginationTypes.ts +3 -6
- package/dist/Pagination/buildPages.ts +9 -5
- package/dist/Pagination/index.d.ts +19 -9
- package/dist/Pagination/index.js +3 -40
- package/dist/Popover/Popover.torp +32 -50
- package/dist/Popover/PopoverContent.torp +27 -76
- package/dist/Popover/PopoverHover.torp +90 -0
- package/dist/Popover/PopoverTrigger.torp +17 -40
- package/dist/Popover/PopoverTypes.ts +4 -17
- package/dist/Popover/index.d.ts +40 -25
- package/dist/Popover/index.js +18 -18
- package/dist/Popover/index.js.map +1 -1
- package/dist/Progress/Progress.torp +88 -0
- package/dist/Progress/index.d.ts +37 -0
- package/dist/Progress/index.js +2 -0
- package/dist/Rating/Rating.torp +225 -0
- package/dist/Rating/index.d.ts +44 -0
- package/dist/Rating/index.js +2 -0
- package/dist/SegmentedControl/SegmentedControl.torp +233 -0
- package/dist/SegmentedControl/SegmentedControlTypes.ts +26 -0
- package/dist/SegmentedControl/SegmentedItem.torp +78 -0
- package/dist/SegmentedControl/index.d.ts +74 -0
- package/dist/SegmentedControl/index.js +3 -0
- package/dist/SelectBox/SelectBox.torp +107 -53
- package/dist/SelectBox/SelectBoxContent.torp +45 -19
- package/dist/SelectBox/SelectBoxTrigger.torp +108 -8
- package/dist/SelectBox/SelectBoxTypes.ts +26 -11
- package/dist/SelectBox/index.d.ts +39 -54
- package/dist/SelectBox/index.js +5 -18
- package/dist/Slider/Slider.torp +248 -0
- package/dist/Slider/index.d.ts +45 -0
- package/dist/Slider/index.js +2 -0
- package/dist/Splitter/Splitter.torp +156 -0
- package/dist/Splitter/SplitterHandle.torp +161 -0
- package/dist/Splitter/SplitterPane.torp +63 -0
- package/dist/Splitter/SplitterTypes.ts +31 -0
- package/dist/Splitter/index.d.ts +103 -0
- package/dist/Splitter/index.js +4 -0
- package/dist/Stepper/Stepper.torp +146 -0
- package/dist/Stepper/StepperMarker.torp +24 -0
- package/dist/Stepper/StepperNext.torp +44 -0
- package/dist/Stepper/StepperPrevious.torp +44 -0
- package/dist/Stepper/StepperStep.torp +90 -0
- package/dist/Stepper/StepperTypes.ts +30 -0
- package/dist/Stepper/index.d.ts +149 -0
- package/dist/Stepper/index.js +6 -0
- package/dist/TabGroup/TabContent.torp +6 -6
- package/dist/TabGroup/TabGroup.torp +97 -113
- package/dist/TabGroup/TabGroupTypes.ts +1 -1
- package/dist/TabGroup/TabHeader.torp +23 -19
- package/dist/TabGroup/TabList.torp +8 -21
- package/dist/TabGroup/TabTrigger.torp +6 -7
- package/dist/TabGroup/index.d.ts +26 -26
- package/dist/TabGroup/index.js +6 -22
- package/dist/TagInput/TagInput.torp +378 -0
- package/dist/TagInput/index.d.ts +48 -0
- package/dist/TagInput/index.js +2 -0
- package/dist/TimePicker/TimePicker.torp +462 -0
- package/dist/TimePicker/index.d.ts +53 -0
- package/dist/TimePicker/index.js +2 -0
- package/dist/ToolBar/ToolBar.torp +29 -110
- package/dist/ToolBar/ToolBarButton.torp +7 -8
- package/dist/ToolBar/ToolBarElement.torp +7 -11
- package/dist/ToolBar/ToolBarPopout.torp +16 -68
- package/dist/ToolBar/ToolBarPopoutContent.torp +15 -73
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +19 -110
- package/dist/ToolBar/ToolBarSeparator.torp +3 -7
- package/dist/ToolBar/ToolBarTypes.ts +7 -14
- package/dist/ToolBar/index.d.ts +30 -32
- package/dist/ToolBar/index.js +8 -30
- package/dist/Tree/Tree.torp +395 -0
- package/dist/Tree/TreeItem.torp +176 -0
- package/dist/Tree/TreeItemChildren.torp +60 -0
- package/dist/Tree/TreeItemContent.torp +46 -0
- package/dist/Tree/TreeItemLabel.torp +94 -0
- package/dist/Tree/TreeItemTrigger.torp +78 -0
- package/dist/Tree/TreeLoadedChildren.torp +122 -0
- package/dist/Tree/TreeTypes.ts +63 -0
- package/dist/Tree/index.d.ts +262 -0
- package/dist/Tree/index.js +7 -0
- package/dist/icons/ChevronDoubleLeft.torp +19 -0
- package/dist/icons/ChevronDoubleRight.torp +19 -0
- package/dist/icons/index.d.ts +61 -1
- package/dist/icons/index.js +17 -58
- package/dist/loader-DEeG5vFY.js +44 -0
- package/dist/loader-DEeG5vFY.js.map +1 -0
- package/dist/motion/index.d.ts +12 -8
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +72 -88
- package/dist/motion/index.js.map +1 -1
- package/dist/mount/draggable.ts +63 -0
- package/dist/mount/dropTarget.ts +108 -0
- package/dist/mount/hoverTrigger.ts +1 -1
- package/dist/utils/$handle.ts +23 -0
- package/dist/utils/LoadedItems.torp +47 -0
- package/dist/utils/PopoutClickTrigger.torp +99 -0
- package/dist/utils/PopoutTypes.ts +59 -12
- package/dist/utils/SubmenuPopout.torp +89 -0
- package/dist/utils/SubmenuPopoutContent.torp +87 -0
- package/dist/utils/SubmenuPopoutTrigger.torp +160 -0
- package/dist/utils/chartColors.ts +13 -13
- package/dist/utils/chartLayout.ts +143 -0
- package/dist/utils/colorUtils.ts +103 -0
- package/dist/utils/createItemGroup.ts +152 -0
- package/dist/utils/dateUtils.ts +8 -7
- package/dist/utils/documentEvents.ts +4 -4
- package/dist/utils/dragState.ts +86 -0
- package/dist/utils/focusGroup.ts +204 -0
- package/dist/utils/focusItem.ts +44 -0
- package/dist/utils/formField.ts +70 -0
- package/dist/utils/hoverOpen.ts +50 -0
- package/dist/utils/hoverReveal.ts +194 -0
- package/dist/utils/loader.ts +113 -0
- package/dist/utils/maskUtils.ts +98 -0
- package/dist/utils/popoutContent.ts +137 -0
- package/dist/utils/reorderList.ts +52 -0
- package/package.json +97 -22
- package/dist/Accordion/index.js.map +0 -1
- package/dist/Breadcrumb/index.js.map +0 -1
- package/dist/Calendar/index.js.map +0 -1
- package/dist/Charts/index.js.map +0 -1
- package/dist/Contextual/index.js.map +0 -1
- package/dist/Dialog/index.js.map +0 -1
- package/dist/Disclosure/index.js.map +0 -1
- package/dist/Drawer/index.js.map +0 -1
- package/dist/Form/index.js.map +0 -1
- package/dist/ListBox/index.js.map +0 -1
- package/dist/Menu/index.js.map +0 -1
- package/dist/MenuBar/index.js.map +0 -1
- package/dist/NavMenu/index.js.map +0 -1
- package/dist/Pagination/index.js.map +0 -1
- package/dist/SelectBox/SelectBoxInput.torp +0 -95
- package/dist/SelectBox/index.js.map +0 -1
- package/dist/TabGroup/index.js.map +0 -1
- package/dist/ToolBar/index.js.map +0 -1
- package/dist/icons/index.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/metafile-esm.json +0 -1
- package/dist/motion/fade.ts +0 -16
- package/dist/motion/grow.ts +0 -23
- package/dist/motion/measure.ts +0 -28
- package/dist/motion/slide.ts +0 -45
- package/dist/mount/index.d.ts +0 -2
- package/dist/utils/index.d.ts +0 -2
package/dist/Charts/index.d.ts
CHANGED
|
@@ -5,23 +5,41 @@ interface BarChartProps {
|
|
|
5
5
|
/** An ID for the root element */
|
|
6
6
|
id?: string;
|
|
7
7
|
/** Classes for the root element */
|
|
8
|
-
class?: ClassValue
|
|
8
|
+
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
|
-
style?: StyleValue
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
showHLines?: boolean
|
|
22
|
-
showVLines?: boolean
|
|
10
|
+
style?: StyleValue;
|
|
11
|
+
/** An ARIA label describing the chart for screen readers */
|
|
12
|
+
ariaLabel?: string;
|
|
13
|
+
series: DataSeries[];
|
|
14
|
+
height?: number;
|
|
15
|
+
width?: number;
|
|
16
|
+
xLabel?: string;
|
|
17
|
+
yLabel?: string;
|
|
18
|
+
maxValue?: number;
|
|
19
|
+
stepCount?: number;
|
|
20
|
+
stepValue?: number;
|
|
21
|
+
showHLines?: boolean;
|
|
22
|
+
showVLines?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* A bar chart: one thick horizontal bar per series, drawn from the left
|
|
27
|
+
* edge towards its first value, with category labels down the side and the
|
|
28
|
+
* value scale along the bottom.
|
|
29
|
+
*
|
|
30
|
+
* This is a preset over the layered chart components:
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* <Chart>
|
|
34
|
+
* <ChartYAxis />
|
|
35
|
+
* <ChartGrid />
|
|
36
|
+
* <ChartXAxis />
|
|
37
|
+
* <ChartBars />
|
|
38
|
+
* </Chart>
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* For a vertical column per value, use ColumnChart instead.
|
|
42
|
+
*/
|
|
25
43
|
declare function BarChart(
|
|
26
44
|
$parent: ParentNode,
|
|
27
45
|
$anchor: Node | null,
|
|
@@ -32,15 +50,222 @@ declare function BarChart(
|
|
|
32
50
|
|
|
33
51
|
|
|
34
52
|
|
|
53
|
+
interface ChartProps {
|
|
54
|
+
/** An ID for the root element */
|
|
55
|
+
id?: string;
|
|
56
|
+
/** Classes for the root element */
|
|
57
|
+
class?: ClassValue;
|
|
58
|
+
/** Styles for the root element */
|
|
59
|
+
style?: StyleValue;
|
|
60
|
+
/** An ARIA label describing the chart for screen readers */
|
|
61
|
+
ariaLabel?: string;
|
|
62
|
+
/** The series that layers draw from (layers reference them by index) */
|
|
63
|
+
series: DataSeries[];
|
|
64
|
+
/** Fixed height in pixels (default 200) */
|
|
65
|
+
height?: number;
|
|
66
|
+
/** Fixed width in pixels (default: fills the container, minimum 400) */
|
|
67
|
+
width?: number;
|
|
68
|
+
/** Label under the x axis */
|
|
69
|
+
xLabel?: string;
|
|
70
|
+
/** Label beside the y axis */
|
|
71
|
+
yLabel?: string;
|
|
72
|
+
/** The value at the top of the value axis, instead of the series' maximum */
|
|
73
|
+
maxValue?: number;
|
|
74
|
+
/** The number of steps between 0 and the maximum value (default 2) */
|
|
75
|
+
stepCount?: number;
|
|
76
|
+
/** The size of each step, instead of being calculated */
|
|
77
|
+
stepValue?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A container for layered chart components. It measures its text, works out
|
|
82
|
+
* the plot geometry and provides it to whatever axes, grid lines and marks
|
|
83
|
+
* are slotted inside:
|
|
84
|
+
*
|
|
85
|
+
* ```
|
|
86
|
+
* <Chart ariaLabel="Revenue" series={revenue}>
|
|
87
|
+
* <ChartYAxis side="right" />
|
|
88
|
+
* <ChartGrid />
|
|
89
|
+
* <ChartXAxis />
|
|
90
|
+
* <ChartColumns />
|
|
91
|
+
* <ChartLines seriesIndex={1} showPoints />
|
|
92
|
+
* </Chart>
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* Layers can be mixed freely -- columns with a line overlaid, an axis on
|
|
96
|
+
* either side, only a y axis with no x axis -- so a preset like LineChart is
|
|
97
|
+
* just one such combination.
|
|
98
|
+
*
|
|
99
|
+
* See also the ready-made presets: BarChart, ColumnChart, LineChart,
|
|
100
|
+
* ScatterChart.
|
|
101
|
+
*/
|
|
102
|
+
declare function Chart(
|
|
103
|
+
$parent: ParentNode,
|
|
104
|
+
$anchor: Node | null,
|
|
105
|
+
$props: ChartProps | undefined,
|
|
106
|
+
$context?: Record<PropertyKey, any>,
|
|
107
|
+
$slots?: Record<string, SlotRender>,
|
|
108
|
+
): void;
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Horizontal bar marks for a Chart: one thick horizontal bar per series,
|
|
114
|
+
* drawn from the left edge of the plot towards its value.
|
|
115
|
+
*
|
|
116
|
+
* For a column per value grouped under each label, use ChartColumns --
|
|
117
|
+
* those run vertically.
|
|
118
|
+
*/
|
|
119
|
+
declare function ChartBars(
|
|
120
|
+
$parent: ParentNode,
|
|
121
|
+
$anchor: Node | null,
|
|
122
|
+
$props?: ChartBarsProps,
|
|
123
|
+
$context?: Record<PropertyKey, any>,
|
|
124
|
+
$slots?: Record<string, SlotRender>,
|
|
125
|
+
): void;
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Vertical column marks for a Chart: every value in the chosen series is
|
|
131
|
+
* drawn as a vertical column, grouped under its label.
|
|
132
|
+
*
|
|
133
|
+
* For one thick bar per series, use ChartBars -- those run horizontally.
|
|
134
|
+
*/
|
|
135
|
+
declare function ChartColumns(
|
|
136
|
+
$parent: ParentNode,
|
|
137
|
+
$anchor: Node | null,
|
|
138
|
+
$props?: ChartColumnsProps,
|
|
139
|
+
$context?: Record<PropertyKey, any>,
|
|
140
|
+
$slots?: Record<string, SlotRender>,
|
|
141
|
+
): void;
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Grid lines for a Chart: horizontal lines at each value step and/or
|
|
147
|
+
* vertical lines through each category slot.
|
|
148
|
+
*/
|
|
149
|
+
declare function ChartGrid(
|
|
150
|
+
$parent: ParentNode,
|
|
151
|
+
$anchor: Node | null,
|
|
152
|
+
$props?: ChartGridProps,
|
|
153
|
+
$context?: Record<PropertyKey, any>,
|
|
154
|
+
$slots?: Record<string, SlotRender>,
|
|
155
|
+
): void;
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Line marks for a Chart: draws the chosen series as a connected line
|
|
161
|
+
* across the category slots.
|
|
162
|
+
*
|
|
163
|
+
* Add alongside ChartColumns or ChartBars for overlaid layers -- or use two
|
|
164
|
+
* ChartLines with different `seriesIndex` to compare series.
|
|
165
|
+
*/
|
|
166
|
+
declare function ChartLines(
|
|
167
|
+
$parent: ParentNode,
|
|
168
|
+
$anchor: Node | null,
|
|
169
|
+
$props?: ChartLinesProps,
|
|
170
|
+
$context?: Record<PropertyKey, any>,
|
|
171
|
+
$slots?: Record<string, SlotRender>,
|
|
172
|
+
): void;
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The x axis for a chart. For vertical marks (columns, lines) it runs along
|
|
178
|
+
* the bottom with each series' label centered under its slot; for
|
|
179
|
+
* horizontal marks (bars) it becomes the value scale, with a tick for each
|
|
180
|
+
* step along the bottom.
|
|
181
|
+
*/
|
|
182
|
+
declare function ChartXAxis(
|
|
183
|
+
$parent: ParentNode,
|
|
184
|
+
$anchor: Node | null,
|
|
185
|
+
$props?: ChartXAxisProps,
|
|
186
|
+
$context?: Record<PropertyKey, any>,
|
|
187
|
+
$slots?: Record<string, SlotRender>,
|
|
188
|
+
): void;
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The y axis for a chart. For vertical marks (columns, lines) it is the
|
|
194
|
+
* value scale -- a line down the `side` edge with a tick for each step
|
|
195
|
+
* between 0 and the maximum value. For horizontal marks (bars) it carries
|
|
196
|
+
* the category labels, one per band down the left.
|
|
197
|
+
*
|
|
198
|
+
* Drawing it on either side does not change the plot geometry; overlaying
|
|
199
|
+
* an axis is purely presentational.
|
|
200
|
+
*/
|
|
201
|
+
declare function ChartYAxis(
|
|
202
|
+
$parent: ParentNode,
|
|
203
|
+
$anchor: Node | null,
|
|
204
|
+
$props?: ChartYAxisProps,
|
|
205
|
+
$context?: Record<PropertyKey, any>,
|
|
206
|
+
$slots?: Record<string, SlotRender>,
|
|
207
|
+
): void;
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
interface ColumnChartProps {
|
|
212
|
+
/** An ID for the root element */
|
|
213
|
+
id?: string;
|
|
214
|
+
/** Classes for the root element */
|
|
215
|
+
class?: ClassValue;
|
|
216
|
+
/** Styles for the root element */
|
|
217
|
+
style?: StyleValue;
|
|
218
|
+
/** An ARIA label describing the chart for screen readers */
|
|
219
|
+
ariaLabel?: string;
|
|
220
|
+
series: DataSeries[];
|
|
221
|
+
height?: number;
|
|
222
|
+
width?: number;
|
|
223
|
+
xLabel?: string;
|
|
224
|
+
yLabel?: string;
|
|
225
|
+
maxValue?: number;
|
|
226
|
+
stepCount?: number;
|
|
227
|
+
stepValue?: number;
|
|
228
|
+
showHLines?: boolean;
|
|
229
|
+
showVLines?: boolean;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* A column chart: each value in each series is drawn as a vertical column,
|
|
234
|
+
* grouped under the series' label along the bottom axis.
|
|
235
|
+
*
|
|
236
|
+
* This is a preset over the layered chart components:
|
|
237
|
+
*
|
|
238
|
+
* ```
|
|
239
|
+
* <Chart>
|
|
240
|
+
* <ChartValueAxis />
|
|
241
|
+
* <ChartGrid />
|
|
242
|
+
* <ChartXAxis />
|
|
243
|
+
* <ChartColumns />
|
|
244
|
+
* </Chart>
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* Compose those directly to customize -- e.g. the value axis on the right,
|
|
248
|
+
* or a line overlaid with ChartLines.
|
|
249
|
+
*/
|
|
250
|
+
declare function ColumnChart(
|
|
251
|
+
$parent: ParentNode,
|
|
252
|
+
$anchor: Node | null,
|
|
253
|
+
$props: ColumnChartProps,
|
|
254
|
+
$context?: Record<PropertyKey, any>,
|
|
255
|
+
$slots?: Record<string, SlotRender>,
|
|
256
|
+
): void;
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
35
260
|
interface GridLinesProps {
|
|
36
261
|
/** An ID for the root element */
|
|
37
262
|
id?: string;
|
|
38
263
|
/** Classes for the root element */
|
|
39
|
-
class?: ClassValue
|
|
264
|
+
class?: ClassValue;
|
|
40
265
|
/** Styles for the root element */
|
|
41
|
-
style?: StyleValue
|
|
42
|
-
showHLines?: boolean
|
|
43
|
-
showVLines?: boolean
|
|
266
|
+
style?: StyleValue;
|
|
267
|
+
showHLines?: boolean;
|
|
268
|
+
showVLines?: boolean;
|
|
44
269
|
width: number;
|
|
45
270
|
labels: string[];
|
|
46
271
|
xStepValue: number;
|
|
@@ -68,24 +293,42 @@ interface LineChartProps {
|
|
|
68
293
|
/** An ID for the root element */
|
|
69
294
|
id?: string;
|
|
70
295
|
/** Classes for the root element */
|
|
71
|
-
class?: ClassValue
|
|
296
|
+
class?: ClassValue;
|
|
72
297
|
/** Styles for the root element */
|
|
73
|
-
style?: StyleValue
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
showHLines?: boolean
|
|
86
|
-
showVLines?: boolean
|
|
298
|
+
style?: StyleValue;
|
|
299
|
+
/** An ARIA label describing the chart for screen readers */
|
|
300
|
+
ariaLabel?: string;
|
|
301
|
+
series: DataSeries[];
|
|
302
|
+
height?: number;
|
|
303
|
+
width?: number;
|
|
304
|
+
xLabel?: string;
|
|
305
|
+
yLabel?: string;
|
|
306
|
+
maxValue?: number;
|
|
307
|
+
stepCount?: number;
|
|
308
|
+
stepValue?: number;
|
|
309
|
+
showPoints?: boolean;
|
|
310
|
+
showHLines?: boolean;
|
|
311
|
+
showVLines?: boolean;
|
|
87
312
|
}
|
|
88
313
|
|
|
314
|
+
/**
|
|
315
|
+
* A line chart: each series drawn as a connected line across the category
|
|
316
|
+
* slots.
|
|
317
|
+
*
|
|
318
|
+
* This is a preset over the layered chart components:
|
|
319
|
+
*
|
|
320
|
+
* ```
|
|
321
|
+
* <Chart>
|
|
322
|
+
* <ChartValueAxis />
|
|
323
|
+
* <ChartGrid />
|
|
324
|
+
* <ChartXAxis />
|
|
325
|
+
* <ChartLines seriesIndex={0} />
|
|
326
|
+
* </Chart>
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* Compose those directly for overlaid layers (columns plus a line, multiple
|
|
330
|
+
* separately-indexed lines etc).
|
|
331
|
+
*/
|
|
89
332
|
declare function LineChart(
|
|
90
333
|
$parent: ParentNode,
|
|
91
334
|
$anchor: Node | null,
|
|
@@ -100,13 +343,15 @@ interface PieChartProps {
|
|
|
100
343
|
/** An ID for the root element */
|
|
101
344
|
id?: string;
|
|
102
345
|
/** Classes for the root element */
|
|
103
|
-
class?: ClassValue
|
|
346
|
+
class?: ClassValue;
|
|
104
347
|
/** Styles for the root element */
|
|
105
|
-
style?: StyleValue
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
348
|
+
style?: StyleValue;
|
|
349
|
+
/** An ARIA label describing the chart for screen readers */
|
|
350
|
+
ariaLabel?: string;
|
|
351
|
+
data: PieData[];
|
|
352
|
+
size?: number;
|
|
353
|
+
radius?: number;
|
|
354
|
+
cutout?: number;
|
|
110
355
|
}
|
|
111
356
|
|
|
112
357
|
declare function PieChart(
|
|
@@ -123,22 +368,24 @@ interface ScatterChartProps {
|
|
|
123
368
|
/** An ID for the root element */
|
|
124
369
|
id?: string;
|
|
125
370
|
/** Classes for the root element */
|
|
126
|
-
class?: ClassValue
|
|
371
|
+
class?: ClassValue;
|
|
127
372
|
/** Styles for the root element */
|
|
128
|
-
style?: StyleValue
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
373
|
+
style?: StyleValue;
|
|
374
|
+
/** An ARIA label describing the chart for screen readers */
|
|
375
|
+
ariaLabel?: string;
|
|
376
|
+
series: DataSeries[];
|
|
377
|
+
height?: number;
|
|
378
|
+
width?: number;
|
|
379
|
+
xLabel?: string;
|
|
380
|
+
yLabel?: string;
|
|
381
|
+
xStepCount?: number;
|
|
382
|
+
xStepValue?: number;
|
|
383
|
+
yStepCount?: number;
|
|
384
|
+
yStepValue?: number;
|
|
385
|
+
hideXAxis?: boolean;
|
|
386
|
+
hideYAxis?: boolean;
|
|
387
|
+
showHLines?: boolean;
|
|
388
|
+
showVLines?: boolean;
|
|
142
389
|
}
|
|
143
390
|
|
|
144
391
|
declare function ScatterChart(
|
|
@@ -155,13 +402,15 @@ interface SparkLineProps {
|
|
|
155
402
|
/** An ID for the root element */
|
|
156
403
|
id?: string;
|
|
157
404
|
/** Classes for the root element */
|
|
158
|
-
class?: ClassValue
|
|
405
|
+
class?: ClassValue;
|
|
159
406
|
/** Styles for the root element */
|
|
160
|
-
style?: StyleValue
|
|
407
|
+
style?: StyleValue;
|
|
408
|
+
/** An ARIA label describing the chart for screen readers */
|
|
409
|
+
ariaLabel?: string;
|
|
161
410
|
data: number[];
|
|
162
|
-
color?: string
|
|
163
|
-
height?: number
|
|
164
|
-
width?: number
|
|
411
|
+
color?: string;
|
|
412
|
+
height?: number;
|
|
413
|
+
width?: number;
|
|
165
414
|
}
|
|
166
415
|
|
|
167
416
|
declare function SparkLine(
|
|
@@ -175,17 +424,17 @@ declare function SparkLine(
|
|
|
175
424
|
|
|
176
425
|
|
|
177
426
|
interface XAxisProps {
|
|
178
|
-
showAxis: boolean
|
|
179
|
-
height: number
|
|
180
|
-
width: number
|
|
181
|
-
itemWidth: number
|
|
182
|
-
textHeight: number
|
|
183
|
-
xLabel: string
|
|
184
|
-
labels: string[]
|
|
185
|
-
stepLabels:number[]
|
|
186
|
-
stepValue: number
|
|
187
|
-
chartLeft: number
|
|
188
|
-
chartBottom: number
|
|
427
|
+
showAxis: boolean;
|
|
428
|
+
height: number;
|
|
429
|
+
width: number;
|
|
430
|
+
itemWidth: number;
|
|
431
|
+
textHeight: number;
|
|
432
|
+
xLabel: string;
|
|
433
|
+
labels: string[];
|
|
434
|
+
stepLabels: number[];
|
|
435
|
+
stepValue: number;
|
|
436
|
+
chartLeft: number;
|
|
437
|
+
chartBottom: number;
|
|
189
438
|
}
|
|
190
439
|
|
|
191
440
|
declare function XAxis(
|
|
@@ -199,14 +448,14 @@ declare function XAxis(
|
|
|
199
448
|
|
|
200
449
|
|
|
201
450
|
interface YAxisProps {
|
|
202
|
-
showAxis: boolean
|
|
203
|
-
valueHeight: number
|
|
204
|
-
textHeight: number
|
|
205
|
-
yLabel: string
|
|
206
|
-
stepLabels: number[]
|
|
207
|
-
stepValue: number
|
|
208
|
-
chartLeft: number
|
|
209
|
-
chartBottom: number
|
|
451
|
+
showAxis: boolean;
|
|
452
|
+
valueHeight: number;
|
|
453
|
+
textHeight: number;
|
|
454
|
+
yLabel: string;
|
|
455
|
+
stepLabels: number[];
|
|
456
|
+
stepValue: number;
|
|
457
|
+
chartLeft: number;
|
|
458
|
+
chartBottom: number;
|
|
210
459
|
}
|
|
211
460
|
|
|
212
461
|
declare function YAxis(
|
|
@@ -217,4 +466,4 @@ declare function YAxis(
|
|
|
217
466
|
$slots?: Record<string, SlotRender>,
|
|
218
467
|
): void;
|
|
219
468
|
|
|
220
|
-
export { BarChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
|
|
469
|
+
export { BarChart, Chart, ChartBars, ChartColumns, ChartGrid, ChartLines, ChartXAxis, ChartYAxis, ColumnChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
|
package/dist/Charts/index.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// src/Charts/XAxis.torp
|
|
20
|
-
import XAxis_default from "./XAxis.torp";
|
|
21
|
-
|
|
22
|
-
// src/Charts/YAxis.torp
|
|
23
|
-
import YAxis_default from "./YAxis.torp";
|
|
24
|
-
export {
|
|
25
|
-
BarChart_default as BarChart,
|
|
26
|
-
GridLines_default as GridLines,
|
|
27
|
-
LineChart_default as LineChart,
|
|
28
|
-
PieChart_default as PieChart,
|
|
29
|
-
ScatterChart_default as ScatterChart,
|
|
30
|
-
SparkLine_default as SparkLine,
|
|
31
|
-
XAxis_default as XAxis,
|
|
32
|
-
YAxis_default as YAxis
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import BarChart from "./BarChart.torp";
|
|
2
|
+
import Chart from "./Chart.torp";
|
|
3
|
+
import ChartBars from "./ChartBars.torp";
|
|
4
|
+
import ChartColumns from "./ChartColumns.torp";
|
|
5
|
+
import ChartGrid from "./ChartGrid.torp";
|
|
6
|
+
import ChartLines from "./ChartLines.torp";
|
|
7
|
+
import ChartXAxis from "./ChartXAxis.torp";
|
|
8
|
+
import ChartYAxis from "./ChartYAxis.torp";
|
|
9
|
+
import ColumnChart from "./ColumnChart.torp";
|
|
10
|
+
import GridLines from "./GridLines.torp";
|
|
11
|
+
import LineChart from "./LineChart.torp";
|
|
12
|
+
import PieChart from "./PieChart.torp";
|
|
13
|
+
import ScatterChart from "./ScatterChart.torp";
|
|
14
|
+
import SparkLine from "./SparkLine.torp";
|
|
15
|
+
import XAxis from "./XAxis.torp";
|
|
16
|
+
import YAxis from "./YAxis.torp";
|
|
17
|
+
export { BarChart, Chart, ChartBars, ChartColumns, ChartGrid, ChartLines, ChartXAxis, ChartYAxis, ColumnChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import {
|
|
3
|
+
type FieldContext,
|
|
4
|
+
FieldContextName,
|
|
5
|
+
type FormContext,
|
|
6
|
+
FormContextName,
|
|
7
|
+
} from "../Form/FormTypes";
|
|
8
|
+
import FormValues from "../Form/FormValues.torp";
|
|
9
|
+
import { createFocusGroup, type FocusItemState } from "../utils/focusGroup";
|
|
10
|
+
import { defaultPalette, parseHex } from "../utils/colorUtils";
|
|
11
|
+
import createFormField from "../utils/formField";
|
|
12
|
+
|
|
13
|
+
interface ColorPaletteProps {
|
|
14
|
+
/** An ID for the root element */
|
|
15
|
+
id?: string;
|
|
16
|
+
/** Classes for the root element */
|
|
17
|
+
class?: ClassValue;
|
|
18
|
+
/** Styles for the root element */
|
|
19
|
+
style?: StyleValue;
|
|
20
|
+
/** The selected color as "#rrggbb"; undefined if nothing is selected */
|
|
21
|
+
value?: Bindable<string | undefined>;
|
|
22
|
+
/** The colors to offer (default: a built-in gray + hue palette) */
|
|
23
|
+
colors?: string[];
|
|
24
|
+
/** If set to true, the user cannot interact with this palette */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** An accessible name for the palette */
|
|
27
|
+
ariaLabel?: string;
|
|
28
|
+
/** The name of the component's form data field */
|
|
29
|
+
name?: string;
|
|
30
|
+
/** Raised when a color has been selected or deselected */
|
|
31
|
+
onchange?: (value: string | undefined) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A grid of color swatches that behaves like a radio group: one swatch can
|
|
36
|
+
* be selected, clicking it again deselects, and the arrow keys move through
|
|
37
|
+
* the swatches selecting as they go.
|
|
38
|
+
*
|
|
39
|
+
* Use ColorPicker instead when arbitrary hex values should be enterable
|
|
40
|
+
* alongside the palette.
|
|
41
|
+
*/
|
|
42
|
+
export default function ColorPalette($props: ColorPaletteProps | undefined) {
|
|
43
|
+
let root: HTMLElement;
|
|
44
|
+
|
|
45
|
+
// Wire up the enclosing Form and Field, if any
|
|
46
|
+
const form = createFormField(
|
|
47
|
+
$props?.name,
|
|
48
|
+
$context[FormContextName] as FormContext | undefined,
|
|
49
|
+
$context[FieldContextName] as FieldContext | undefined,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function getDisabled(): boolean {
|
|
53
|
+
return $props?.disabled === true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getColors(): string[] {
|
|
57
|
+
return $props?.colors ?? defaultPalette;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let $state = $watch({
|
|
61
|
+
value: undefined as string | undefined,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
$bind($state, $props, "value");
|
|
65
|
+
|
|
66
|
+
const group = createFocusGroup<FocusItemState>();
|
|
67
|
+
|
|
68
|
+
function normalized(color: string | undefined | null): string {
|
|
69
|
+
return parseHex(color) ?? "";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isSelected(color: string): boolean {
|
|
73
|
+
return $state.value !== undefined && normalized($state.value) === normalized(color);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function select(color: string) {
|
|
77
|
+
if (getDisabled()) return;
|
|
78
|
+
const next = normalized(color);
|
|
79
|
+
// Selecting the current swatch clears it, like Rating's allowClear
|
|
80
|
+
$state.value = isSelected(color) ? undefined : next || undefined;
|
|
81
|
+
form.handleInput();
|
|
82
|
+
$props?.onchange?.($state.value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function handleKey(index: number, e: KeyboardEvent) {
|
|
86
|
+
if (getDisabled()) return;
|
|
87
|
+
switch (e.key) {
|
|
88
|
+
case "Enter":
|
|
89
|
+
case " ": {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
select(getColors()[index]);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
const before = group.getFocusIndex();
|
|
96
|
+
group.handleGroupKey(index, e);
|
|
97
|
+
const after = group.getFocusIndex();
|
|
98
|
+
if (after !== before && after >= 0) {
|
|
99
|
+
group.handleItemFocus(after);
|
|
100
|
+
select(getColors()[after]);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Only blur when focus leaves the whole palette
|
|
108
|
+
function handleFocusOut(e: FocusEvent) {
|
|
109
|
+
if (!root.contains(e.relatedTarget as Node | null)) {
|
|
110
|
+
form.handleBlur();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@render {
|
|
115
|
+
<div
|
|
116
|
+
{$props?.id}
|
|
117
|
+
class={["torp-color-palette", $props?.class]}
|
|
118
|
+
{$props?.style}
|
|
119
|
+
role="radiogroup"
|
|
120
|
+
aria-label={$props?.ariaLabel}
|
|
121
|
+
aria-disabled={getDisabled() ? "true" : undefined}
|
|
122
|
+
data-valid={form.valid ? "valid" : "invalid"}
|
|
123
|
+
aria-describedby={form.messageId}
|
|
124
|
+
onfocusout={handleFocusOut}
|
|
125
|
+
&ref={root}
|
|
126
|
+
>
|
|
127
|
+
@for (let [i, color] of getColors().entries()) {
|
|
128
|
+
@key = color
|
|
129
|
+
<button
|
|
130
|
+
type="button"
|
|
131
|
+
class="torp-color-palette-swatch"
|
|
132
|
+
role="radio"
|
|
133
|
+
tabindex={group.isTabStop(i) ? 0 : -1}
|
|
134
|
+
aria-checked={isSelected(color) ? "true" : "false"}
|
|
135
|
+
aria-label={normalized(color)}
|
|
136
|
+
aria-disabled={getDisabled() ? "true" : undefined}
|
|
137
|
+
data-color={color}
|
|
138
|
+
data-selected={isSelected(color) ? "selected" : undefined}
|
|
139
|
+
disabled={getDisabled()}
|
|
140
|
+
style={`background-color:${color}`}
|
|
141
|
+
onclick={() => select(color)}
|
|
142
|
+
onkeydown={(e: KeyboardEvent) => handleKey(i, e)}
|
|
143
|
+
onmount={(el: HTMLElement) => {
|
|
144
|
+
const item: FocusItemState = { setFocused: () => el.focus() };
|
|
145
|
+
group.registerItem(item);
|
|
146
|
+
return () => group.removeItem(item.index!);
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
}
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<FormValues name={form.name} value={$state.value} />
|
|
153
|
+
}
|
|
154
|
+
}
|