@central-ui/react 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +49 -0
- package/README.md +1 -1
- package/dist/components/accordion/index.d.ts +7 -6
- package/dist/components/accordion/index.js +13 -10
- package/dist/components/autocomplete/index.d.ts +22 -33
- package/dist/components/autocomplete/index.js +90 -73
- package/dist/components/avatar/index.d.ts +1 -2
- package/dist/components/avatar/index.js +6 -6
- package/dist/components/badge/index.d.ts +0 -1
- package/dist/components/badge/index.js +2 -2
- package/dist/components/banner/index.d.ts +1 -1
- package/dist/components/banner/index.js +24 -26
- package/dist/components/barchart/index.d.ts +106 -0
- package/dist/components/barchart/index.js +122 -0
- package/dist/components/breadcrumb/index.d.ts +0 -1
- package/dist/components/breadcrumb/index.js +6 -7
- package/dist/components/button/index.d.ts +3 -4
- package/dist/components/button/index.js +11 -12
- package/dist/components/card/index.d.ts +0 -1
- package/dist/components/card/index.js +0 -1
- package/dist/components/checkbox/index.d.ts +13 -11
- package/dist/components/checkbox/index.js +59 -39
- package/dist/components/chip/index.d.ts +1 -1
- package/dist/components/chip/index.js +2 -3
- package/dist/components/combobox/index.d.ts +32 -44
- package/dist/components/combobox/index.js +112 -88
- package/dist/components/datepicker/index.d.ts +54 -55
- package/dist/components/datepicker/index.js +105 -100
- package/dist/components/dialog/index.d.ts +17 -30
- package/dist/components/dialog/index.js +25 -26
- package/dist/components/divider/index.d.ts +0 -1
- package/dist/components/divider/index.js +0 -1
- package/dist/components/donutchart/index.d.ts +100 -0
- package/dist/components/donutchart/index.js +178 -0
- package/dist/components/drawer/index.d.ts +15 -24
- package/dist/components/drawer/index.js +45 -47
- package/dist/components/empty/index.d.ts +1 -2
- package/dist/components/empty/index.js +2 -4
- package/dist/components/fileupload/index.d.ts +4 -9
- package/dist/components/fileupload/index.js +27 -39
- package/dist/components/form/index.d.ts +0 -1
- package/dist/components/form/index.js +0 -1
- package/dist/components/horizontalbarchart/index.d.ts +120 -0
- package/dist/components/horizontalbarchart/index.js +193 -0
- package/dist/components/input/index.d.ts +23 -23
- package/dist/components/input/index.js +86 -115
- package/dist/components/linechart/index.d.ts +114 -0
- package/dist/components/linechart/index.js +139 -0
- package/dist/components/menu/index.d.ts +14 -16
- package/dist/components/menu/index.js +56 -53
- package/dist/components/metric/index.d.ts +0 -1
- package/dist/components/metric/index.js +0 -1
- package/dist/components/numberinput/index.d.ts +16 -23
- package/dist/components/numberinput/index.js +55 -68
- package/dist/components/otpinput/index.d.ts +14 -9
- package/dist/components/otpinput/index.js +32 -25
- package/dist/components/page/index.d.ts +0 -1
- package/dist/components/page/index.js +2 -4
- package/dist/components/passwordinput/index.d.ts +16 -13
- package/dist/components/passwordinput/index.js +47 -56
- package/dist/components/popover/index.d.ts +21 -19
- package/dist/components/popover/index.js +40 -21
- package/dist/components/radio/index.d.ts +13 -9
- package/dist/components/radio/index.js +80 -71
- package/dist/components/ratinginput/index.d.ts +15 -10
- package/dist/components/ratinginput/index.js +38 -18
- package/dist/components/select/index.d.ts +29 -32
- package/dist/components/select/index.js +79 -50
- package/dist/components/skeleton/index.d.ts +0 -1
- package/dist/components/skeleton/index.js +0 -1
- package/dist/components/slider/index.d.ts +14 -9
- package/dist/components/slider/index.js +75 -74
- package/dist/components/spinner/index.d.ts +2 -3
- package/dist/components/spinner/index.js +2 -3
- package/dist/components/splitter/index.d.ts +1 -2
- package/dist/components/splitter/index.js +6 -7
- package/dist/components/stepper/index.d.ts +8 -20
- package/dist/components/stepper/index.js +15 -16
- package/dist/components/switch/index.d.ts +12 -10
- package/dist/components/switch/index.js +52 -36
- package/dist/components/table/index.d.ts +3 -3
- package/dist/components/table/index.js +17 -16
- package/dist/components/tabs/index.d.ts +3 -4
- package/dist/components/tabs/index.js +6 -7
- package/dist/components/textarea/index.d.ts +16 -13
- package/dist/components/textarea/index.js +46 -55
- package/dist/components/textlink/index.d.ts +3 -1
- package/dist/components/textlink/index.js +4 -1
- package/dist/components/toast/index.d.ts +8 -14
- package/dist/components/toast/index.js +54 -54
- package/dist/components/toggle/index.d.ts +5 -6
- package/dist/components/toggle/index.js +19 -26
- package/dist/components/tooltip/index.d.ts +11 -13
- package/dist/components/tooltip/index.js +14 -11
- package/dist/components/tour/index.d.ts +154 -0
- package/dist/components/tour/index.js +280 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -1
- package/dist/types/Icon.d.ts +10 -0
- package/dist/types/Icon.js +1 -0
- package/dist/types/Style.d.ts +0 -1
- package/dist/types/Style.js +0 -1
- package/dist/types/Tone.d.ts +0 -1
- package/dist/types/Tone.js +0 -1
- package/dist/types/Validation.d.ts +12 -0
- package/dist/types/Validation.js +1 -0
- package/dist/utils/ArkStateToDataAttributes.d.ts +0 -1
- package/dist/utils/ArkStateToDataAttributes.js +3 -2
- package/dist/utils/Tone.d.ts +0 -1
- package/dist/utils/Tone.js +1 -2
- package/dist/utils/Validation.d.ts +14 -0
- package/dist/utils/Validation.js +23 -0
- package/dist/utils/asChild.d.ts +41 -0
- package/dist/utils/asChild.js +15 -0
- package/dist/utils/icons.d.ts +24 -0
- package/dist/utils/icons.js +160 -0
- package/dist/utils/useForwardClickToInput.d.ts +0 -1
- package/dist/utils/useForwardClickToInput.js +4 -3
- package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts +0 -1
- package/dist/utils/virtualization/useVirtualizedAutocomplete.js +0 -1
- package/dist/utils/virtualization/useVirtualizedCombobox.d.ts +0 -1
- package/dist/utils/virtualization/useVirtualizedCombobox.js +0 -1
- package/dist/utils/virtualization/useVirtualizedTable.d.ts +0 -1
- package/dist/utils/virtualization/useVirtualizedTable.js +0 -1
- package/package.json +12 -11
- package/src/presets/shopify-polaris/shopify-polaris-autocomplete.css +15 -6
- package/src/presets/shopify-polaris/shopify-polaris-badge.css +1 -1
- package/src/presets/shopify-polaris/shopify-polaris-barchart.css +64 -0
- package/src/presets/shopify-polaris/shopify-polaris-checkbox.css +2 -2
- package/src/presets/shopify-polaris/shopify-polaris-chip.css +3 -3
- package/src/presets/shopify-polaris/shopify-polaris-combobox.css +19 -10
- package/src/presets/shopify-polaris/shopify-polaris-datepicker.css +20 -11
- package/src/presets/shopify-polaris/shopify-polaris-dialog.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-donutchart.css +172 -0
- package/src/presets/shopify-polaris/shopify-polaris-drawer.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-fileupload.css +1 -1
- package/src/presets/shopify-polaris/shopify-polaris-horizontalbarchart.css +60 -0
- package/src/presets/shopify-polaris/shopify-polaris-input.css +14 -5
- package/src/presets/shopify-polaris/shopify-polaris-linechart.css +68 -0
- package/src/presets/shopify-polaris/shopify-polaris-menu.css +47 -6
- package/src/presets/shopify-polaris/shopify-polaris-numberinput.css +16 -7
- package/src/presets/shopify-polaris/shopify-polaris-otpinput.css +3 -3
- package/src/presets/shopify-polaris/shopify-polaris-passwordinput.css +14 -5
- package/src/presets/shopify-polaris/shopify-polaris-popover.css +29 -0
- package/src/presets/shopify-polaris/shopify-polaris-radio.css +2 -2
- package/src/presets/shopify-polaris/shopify-polaris-ratinginput.css +2 -2
- package/src/presets/shopify-polaris/shopify-polaris-select.css +15 -6
- package/src/presets/shopify-polaris/shopify-polaris-slider.css +2 -2
- package/src/presets/shopify-polaris/shopify-polaris-stepper.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-switch.css +2 -2
- package/src/presets/shopify-polaris/shopify-polaris-textarea.css +13 -4
- package/src/presets/shopify-polaris/shopify-polaris-toast.css +43 -0
- package/src/presets/shopify-polaris/shopify-polaris-tooltip.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris.css +5 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-autocomplete.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-barchart.css +64 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-checkbox.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-combobox.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-datepicker.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-dialog.css +9 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-donutchart.css +172 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-drawer.css +9 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-fileupload.css +1 -1
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-horizontalbarchart.css +60 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-input.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-linechart.css +68 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-menu.css +9 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-numberinput.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-otpinput.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-passwordinput.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-popover.css +22 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-radio.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-ratinginput.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-slider.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-stepper.css +9 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-switch.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-textarea.css +2 -2
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-tooltip.css +9 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy.css +4 -0
- package/dist/components/accordion/index.d.ts.map +0 -1
- package/dist/components/accordion/index.js.map +0 -1
- package/dist/components/autocomplete/index.d.ts.map +0 -1
- package/dist/components/autocomplete/index.js.map +0 -1
- package/dist/components/avatar/index.d.ts.map +0 -1
- package/dist/components/avatar/index.js.map +0 -1
- package/dist/components/badge/index.d.ts.map +0 -1
- package/dist/components/badge/index.js.map +0 -1
- package/dist/components/banner/index.d.ts.map +0 -1
- package/dist/components/banner/index.js.map +0 -1
- package/dist/components/breadcrumb/index.d.ts.map +0 -1
- package/dist/components/breadcrumb/index.js.map +0 -1
- package/dist/components/button/index.d.ts.map +0 -1
- package/dist/components/button/index.js.map +0 -1
- package/dist/components/card/index.d.ts.map +0 -1
- package/dist/components/card/index.js.map +0 -1
- package/dist/components/checkbox/index.d.ts.map +0 -1
- package/dist/components/checkbox/index.js.map +0 -1
- package/dist/components/chip/index.d.ts.map +0 -1
- package/dist/components/chip/index.js.map +0 -1
- package/dist/components/combobox/index.d.ts.map +0 -1
- package/dist/components/combobox/index.js.map +0 -1
- package/dist/components/datepicker/index.d.ts.map +0 -1
- package/dist/components/datepicker/index.js.map +0 -1
- package/dist/components/dialog/index.d.ts.map +0 -1
- package/dist/components/dialog/index.js.map +0 -1
- package/dist/components/divider/index.d.ts.map +0 -1
- package/dist/components/divider/index.js.map +0 -1
- package/dist/components/drawer/index.d.ts.map +0 -1
- package/dist/components/drawer/index.js.map +0 -1
- package/dist/components/empty/index.d.ts.map +0 -1
- package/dist/components/empty/index.js.map +0 -1
- package/dist/components/fileupload/index.d.ts.map +0 -1
- package/dist/components/fileupload/index.js.map +0 -1
- package/dist/components/form/index.d.ts.map +0 -1
- package/dist/components/form/index.js.map +0 -1
- package/dist/components/input/index.d.ts.map +0 -1
- package/dist/components/input/index.js.map +0 -1
- package/dist/components/menu/index.d.ts.map +0 -1
- package/dist/components/menu/index.js.map +0 -1
- package/dist/components/metric/index.d.ts.map +0 -1
- package/dist/components/metric/index.js.map +0 -1
- package/dist/components/numberinput/index.d.ts.map +0 -1
- package/dist/components/numberinput/index.js.map +0 -1
- package/dist/components/otpinput/index.d.ts.map +0 -1
- package/dist/components/otpinput/index.js.map +0 -1
- package/dist/components/page/index.d.ts.map +0 -1
- package/dist/components/page/index.js.map +0 -1
- package/dist/components/passwordinput/index.d.ts.map +0 -1
- package/dist/components/passwordinput/index.js.map +0 -1
- package/dist/components/popover/index.d.ts.map +0 -1
- package/dist/components/popover/index.js.map +0 -1
- package/dist/components/radio/index.d.ts.map +0 -1
- package/dist/components/radio/index.js.map +0 -1
- package/dist/components/ratinginput/index.d.ts.map +0 -1
- package/dist/components/ratinginput/index.js.map +0 -1
- package/dist/components/select/index.d.ts.map +0 -1
- package/dist/components/select/index.js.map +0 -1
- package/dist/components/skeleton/index.d.ts.map +0 -1
- package/dist/components/skeleton/index.js.map +0 -1
- package/dist/components/slider/index.d.ts.map +0 -1
- package/dist/components/slider/index.js.map +0 -1
- package/dist/components/spinner/index.d.ts.map +0 -1
- package/dist/components/spinner/index.js.map +0 -1
- package/dist/components/splitter/index.d.ts.map +0 -1
- package/dist/components/splitter/index.js.map +0 -1
- package/dist/components/stepper/index.d.ts.map +0 -1
- package/dist/components/stepper/index.js.map +0 -1
- package/dist/components/switch/index.d.ts.map +0 -1
- package/dist/components/switch/index.js.map +0 -1
- package/dist/components/table/index.d.ts.map +0 -1
- package/dist/components/table/index.js.map +0 -1
- package/dist/components/tabs/index.d.ts.map +0 -1
- package/dist/components/tabs/index.js.map +0 -1
- package/dist/components/textarea/index.d.ts.map +0 -1
- package/dist/components/textarea/index.js.map +0 -1
- package/dist/components/textlink/index.d.ts.map +0 -1
- package/dist/components/textlink/index.js.map +0 -1
- package/dist/components/toast/index.d.ts.map +0 -1
- package/dist/components/toast/index.js.map +0 -1
- package/dist/components/toggle/index.d.ts.map +0 -1
- package/dist/components/toggle/index.js.map +0 -1
- package/dist/components/tooltip/index.d.ts.map +0 -1
- package/dist/components/tooltip/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/Style.d.ts.map +0 -1
- package/dist/types/Style.js.map +0 -1
- package/dist/types/Tone.d.ts.map +0 -1
- package/dist/types/Tone.js.map +0 -1
- package/dist/utils/ArkStateToDataAttributes.d.ts.map +0 -1
- package/dist/utils/ArkStateToDataAttributes.js.map +0 -1
- package/dist/utils/Tone.d.ts.map +0 -1
- package/dist/utils/Tone.js.map +0 -1
- package/dist/utils/useForwardClickToInput.d.ts.map +0 -1
- package/dist/utils/useForwardClickToInput.js.map +0 -1
- package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts.map +0 -1
- package/dist/utils/virtualization/useVirtualizedAutocomplete.js.map +0 -1
- package/dist/utils/virtualization/useVirtualizedCombobox.d.ts.map +0 -1
- package/dist/utils/virtualization/useVirtualizedCombobox.js.map +0 -1
- package/dist/utils/virtualization/useVirtualizedTable.d.ts.map +0 -1
- package/dist/utils/virtualization/useVirtualizedTable.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { asChildStyleAttributes } from "../../utils/asChild.js";
|
|
2
3
|
import { FileUpload as ArkFileUpload, useFileUpload, useFileUploadContext, } from '@ark-ui/react/file-upload';
|
|
3
|
-
import { File as FileIcon, Upload, X } from
|
|
4
|
-
import { cloneElement, createContext, useContext
|
|
4
|
+
import { File as FileIcon, Upload, X } from "../../utils/icons.js";
|
|
5
|
+
import { cloneElement, createContext, useContext } from 'react';
|
|
5
6
|
import { twMerge } from 'tailwind-merge';
|
|
6
7
|
import { arkStateToDataAttributes } from "../../utils/ArkStateToDataAttributes.js";
|
|
7
8
|
/**
|
|
8
|
-
* Root manages accepted/rejected files, validation, and picker behavior. Dropzone/
|
|
9
|
+
* Root manages accepted/rejected files, validation, and picker behavior. Dropzone/PickerButton open the picker; do not add a second file input. FileList supplies entries; pass each entry file and status to File. FileThumbnail chooses image preview versus fallback automatically.
|
|
9
10
|
*
|
|
10
11
|
* @example Complete composition
|
|
11
12
|
* import { FileUpload } from '@central-ui/react'
|
|
@@ -19,7 +20,7 @@ import { arkStateToDataAttributes } from "../../utils/ArkStateToDataAttributes.j
|
|
|
19
20
|
* <FileUpload.UploadIcon />
|
|
20
21
|
* <FileUpload.Title>Drop an image here</FileUpload.Title>
|
|
21
22
|
* <FileUpload.Description>PNG or JPG up to 10 MB.</FileUpload.Description>
|
|
22
|
-
* <FileUpload.
|
|
23
|
+
* <FileUpload.PickerButton>Browse image</FileUpload.PickerButton>
|
|
23
24
|
* <FileUpload.FileList>
|
|
24
25
|
* {({ file, status }) => (
|
|
25
26
|
* <FileUpload.File file={file} status={status}>
|
|
@@ -50,8 +51,8 @@ import { arkStateToDataAttributes } from "../../utils/ArkStateToDataAttributes.j
|
|
|
50
51
|
* </FileUpload.Root>
|
|
51
52
|
*/
|
|
52
53
|
export function Root({ children, ...props }) {
|
|
53
|
-
const
|
|
54
|
-
return (_jsx(ArkFileUpload.RootProvider, { value:
|
|
54
|
+
const fileUpload = useFileUpload(props);
|
|
55
|
+
return (_jsx(ArkFileUpload.RootProvider, { value: fileUpload, asChild: true, children: _jsx(_Fragment, { children: children }) }));
|
|
55
56
|
}
|
|
56
57
|
export function Container({ disableStyle, className, ...props }) {
|
|
57
58
|
return (_jsx("div", { "data-component": "fileupload-container", "data-style-disabled": disableStyle ? '' : undefined, className: className, ...props }));
|
|
@@ -62,16 +63,17 @@ export function Label({ disableStyle, className, ...props }) {
|
|
|
62
63
|
export function Dropzone({ disableStyle, children, className, ...props }) {
|
|
63
64
|
return (_jsxs(ArkFileUpload.Dropzone, { ...props, "data-component": "fileupload-dropzone", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: [children, _jsx(ArkFileUpload.HiddenInput, {})] }));
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
/** Opens the file picker. Pass asChild to give this behavior to your own button, like an "Upload" Button; it keeps the state data attributes but none of this part's styling. */
|
|
67
|
+
export function PickerButton({ asChild, disableStyle, ...props }) {
|
|
68
|
+
const styleAttributes = asChildStyleAttributes({ asChild, component: 'fileupload-pickerbutton', disableStyle });
|
|
69
|
+
return _jsx(ArkFileUpload.Trigger, { ...props, asChild: asChild, ...styleAttributes });
|
|
67
70
|
}
|
|
68
71
|
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
69
72
|
export function UploadIcon({ disableStyle, children = _jsx(Upload, {}), className, ...props }) {
|
|
70
|
-
const
|
|
73
|
+
const fileUpload = useFileUploadContext();
|
|
71
74
|
return cloneElement(children, {
|
|
72
|
-
...children.props,
|
|
73
75
|
...props,
|
|
74
|
-
...arkStateToDataAttributes(
|
|
76
|
+
...arkStateToDataAttributes(fileUpload),
|
|
75
77
|
...useFileStatusAttributes(),
|
|
76
78
|
...{
|
|
77
79
|
'data-component': 'fileupload-uploadicon',
|
|
@@ -82,26 +84,20 @@ export function UploadIcon({ disableStyle, children = _jsx(Upload, {}), classNam
|
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
export function Title({ disableStyle, className, ...props }) {
|
|
85
|
-
const
|
|
86
|
-
return (_jsx("p", { ...props, ...arkStateToDataAttributes(
|
|
87
|
+
const fileUpload = useFileUploadContext();
|
|
88
|
+
return (_jsx("p", { ...props, ...arkStateToDataAttributes(fileUpload), ...useFileStatusAttributes(), "data-component": "fileupload-title", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
87
89
|
}
|
|
88
90
|
export function Description({ disableStyle, className, ...props }) {
|
|
89
|
-
const
|
|
90
|
-
return (_jsx("p", { ...props, ...arkStateToDataAttributes(
|
|
91
|
+
const fileUpload = useFileUploadContext();
|
|
92
|
+
return (_jsx("p", { ...props, ...arkStateToDataAttributes(fileUpload), ...useFileStatusAttributes(), "data-component": "fileupload-description", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
91
93
|
}
|
|
92
94
|
// Keep Ark's accepted and rejected arrays native; only merge their presentation.
|
|
93
95
|
export function FileList({ disableStyle, children, className, style, onClick, ...props }) {
|
|
94
|
-
const
|
|
96
|
+
const fileUpload = useFileUploadContext();
|
|
97
|
+
// One list of accepted and rejected files, each knowing its status
|
|
95
98
|
const entries = [
|
|
96
|
-
...
|
|
97
|
-
|
|
98
|
-
status: 'accepted',
|
|
99
|
-
errors: [],
|
|
100
|
-
})),
|
|
101
|
-
...upload.rejectedFiles.map((rejection) => ({
|
|
102
|
-
...rejection,
|
|
103
|
-
status: 'rejected',
|
|
104
|
-
})),
|
|
99
|
+
...fileUpload.acceptedFiles.map((file) => ({ file, status: 'accepted', errors: [] })),
|
|
100
|
+
...fileUpload.rejectedFiles.map((rejection) => ({ ...rejection, status: 'rejected' })),
|
|
105
101
|
];
|
|
106
102
|
return (_jsx("ul", { ...props, style: { ...style, cursor: 'default' }, onClick: (event) => {
|
|
107
103
|
// Clicks anywhere in the file list must not open the surrounding Dropzone.
|
|
@@ -111,7 +107,7 @@ export function FileList({ disableStyle, children, className, style, onClick, ..
|
|
|
111
107
|
}
|
|
112
108
|
export function File({ disableStyle, status, className, children, ...props }) {
|
|
113
109
|
const entry = useContext(FileStatusContext);
|
|
114
|
-
return (_jsx(ArkFileUpload.ItemGroup, { type: status, asChild: true, children: _jsx(
|
|
110
|
+
return (_jsx(ArkFileUpload.ItemGroup, { type: status, asChild: true, children: _jsx(_Fragment, { children: _jsx(FileStatusContext.Provider, { value: { status, errors: entry.errors }, children: _jsx(ArkFileUpload.Item, { ...props, "data-status": status, "data-component": "fileupload-file", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: children }) }) }) }));
|
|
115
111
|
}
|
|
116
112
|
/** Reads the surrounding File automatically. Omit children to keep the supplied text; override only for custom presentation. */
|
|
117
113
|
export function FileErrorText({ disableStyle, children, className, ...props }) {
|
|
@@ -130,11 +126,10 @@ export function FileThumbnail({ disableStyle, children, className, ...props }) {
|
|
|
130
126
|
}
|
|
131
127
|
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
132
128
|
export function FileThumbnailIcon({ disableStyle, children = _jsx(FileIcon, {}), className, ...props }) {
|
|
133
|
-
const
|
|
129
|
+
const fileUpload = useFileUploadContext();
|
|
134
130
|
return cloneElement(children, {
|
|
135
|
-
...children.props,
|
|
136
131
|
...props,
|
|
137
|
-
...arkStateToDataAttributes(
|
|
132
|
+
...arkStateToDataAttributes(fileUpload),
|
|
138
133
|
...useFileStatusAttributes(),
|
|
139
134
|
...{
|
|
140
135
|
'data-component': 'fileupload-filethumbnailicon',
|
|
@@ -152,22 +147,16 @@ export function FileName({ disableStyle, className, ...props }) {
|
|
|
152
147
|
export function FileSize({ disableStyle, className, ...props }) {
|
|
153
148
|
return (_jsx(ArkFileUpload.ItemSizeText, { ...props, ...useFileStatusAttributes(), "data-component": "fileupload-filesize", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
154
149
|
}
|
|
155
|
-
/** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
|
|
156
|
-
export function FileRemoveHandler({ children, ...props }) {
|
|
157
|
-
const attributes = useFileStatusAttributes();
|
|
158
|
-
return (_jsx(ArkFileUpload.ItemDeleteTrigger, { ...props, ...attributes, asChild: true, children: children }));
|
|
159
|
-
}
|
|
160
150
|
/** Removes the surrounding file automatically, including rejected entries. No extra removal click handler needed. */
|
|
161
151
|
export function FileRemoveButton({ disableStyle, children, className, ...props }) {
|
|
162
152
|
return (_jsx(ArkFileUpload.ItemDeleteTrigger, { ...props, ...useFileStatusAttributes(), asChild: false, "data-component": "fileupload-fileremovebutton", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: children }));
|
|
163
153
|
}
|
|
164
154
|
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
165
155
|
export function FileRemoveButtonIcon({ disableStyle, children = _jsx(X, {}), className, ...props }) {
|
|
166
|
-
const
|
|
156
|
+
const fileUpload = useFileUploadContext();
|
|
167
157
|
return cloneElement(children, {
|
|
168
|
-
...children.props,
|
|
169
158
|
...props,
|
|
170
|
-
...arkStateToDataAttributes(
|
|
159
|
+
...arkStateToDataAttributes(fileUpload),
|
|
171
160
|
...useFileStatusAttributes(),
|
|
172
161
|
...{
|
|
173
162
|
'data-component': 'fileupload-fileremovebuttonicon',
|
|
@@ -178,8 +167,7 @@ export function FileRemoveButtonIcon({ disableStyle, children = _jsx(X, {}), cla
|
|
|
178
167
|
});
|
|
179
168
|
}
|
|
180
169
|
// Each rendered row shares rejection details with its parts, without mirroring upload state.
|
|
181
|
-
const FileStatusContext = createContext({ errors: [] });
|
|
170
|
+
const FileStatusContext = /* @__PURE__ */ createContext({ errors: [] });
|
|
182
171
|
function useFileStatusAttributes() {
|
|
183
172
|
return { 'data-status': useContext(FileStatusContext).status };
|
|
184
173
|
}
|
|
185
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -32,4 +32,3 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
32
32
|
export function Form({ disableStyle, className, ...props }) {
|
|
33
33
|
return (_jsx("form", { "data-component": "form-form", "data-style-disabled": disableStyle ? '' : undefined, className: className, ...props }));
|
|
34
34
|
}
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import { BarChart as RechartsBarChart } from 'recharts';
|
|
3
|
+
import type { BarProps as RechartsBarProps, TooltipProps as RechartsTooltipProps, XAxisProps as RechartsXAxisProps } from 'recharts';
|
|
4
|
+
import type { StyleProps } from '../../types/Style.ts';
|
|
5
|
+
/** Every record needs a unique `label` (the category) and a numeric `value` (the bar length). Extra fields are kept for the tooltip. */
|
|
6
|
+
type Datum = {
|
|
7
|
+
label: string;
|
|
8
|
+
value: number;
|
|
9
|
+
};
|
|
10
|
+
export type RootProps<Data extends Datum = Datum> = Pick<ComponentProps<typeof RechartsBarChart>, 'accessibilityLayer' | 'desc'> & {
|
|
11
|
+
/** Rows are drawn top to bottom in this order, so sort the records before passing them (e.g. largest first). */
|
|
12
|
+
data: readonly Data[];
|
|
13
|
+
'aria-label': string;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a record's `label` into display text.
|
|
17
|
+
* Used by the category names and the tooltip label, so both always read the same.
|
|
18
|
+
* Use it to shorten long names or to join fields (e.g. `'United States · Iowa'`).
|
|
19
|
+
* @default (label) => label
|
|
20
|
+
*/
|
|
21
|
+
labelToString?: (label: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a record's `value` into display text.
|
|
24
|
+
* Used by the value at each bar's end, the X axis ticks, and the tooltip value, so all read the same.
|
|
25
|
+
* Use it for currency, percentages, or units (e.g. `53700` → `'$53.7K'`).
|
|
26
|
+
* @default (value) => value.toLocaleString()
|
|
27
|
+
*/
|
|
28
|
+
valueToString?: (value: number) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the X axis may place ticks at fractional values. Only matters when the XAxis part is rendered.
|
|
31
|
+
* Keep it `false` for counts (sessions, orders) so the axis never shows `0.5 sessions`.
|
|
32
|
+
* Set it to `true` for continuous measures where fractions are meaningful, such as ratings.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
allowDecimals?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Where each category name sits.
|
|
38
|
+
* - `'top'`: above its bar, left-aligned. Bars keep the full width, so long names and long bars both fit. The usual choice for dashboards.
|
|
39
|
+
* - `'left'`: in a column left of the bars, like a classic axis. Use it when names are short and rows should line up as a table.
|
|
40
|
+
* @default 'top'
|
|
41
|
+
*/
|
|
42
|
+
labelPosition?: 'top' | 'left';
|
|
43
|
+
};
|
|
44
|
+
/** Provides the chart data, formatting, and accessibility settings to its parts. Renders no element. */
|
|
45
|
+
export declare function Root<Data extends Datum>({ children, labelToString, valueToString, allowDecimals, labelPosition, ...chart }: RootProps<Data>): import("react").JSX.Element;
|
|
46
|
+
export type ContainerProps = Pick<ComponentProps<typeof RechartsBarChart>, 'children' | 'height' | 'className' | 'style' | 'id' | 'margin' | 'ref' | 'tabIndex'> & {
|
|
47
|
+
/**
|
|
48
|
+
* A horizontal line through the hovered row.
|
|
49
|
+
* Off by default: the hovered bar already dims, so a guide adds little here.
|
|
50
|
+
* Turn it on for many thin rows, where it helps the eye follow a row to its value. Style it through `data-component="horizontalbarchart-hoverguide"`.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
hoverGuide?: LineSwitch;
|
|
54
|
+
};
|
|
55
|
+
/** On/off only: style it through its data-component in a preset, so each export keeps one className. */
|
|
56
|
+
type LineSwitch = boolean;
|
|
57
|
+
/** Recharts supplies its own responsive container, so no extra wrapper is needed. */
|
|
58
|
+
export declare function Container({ height, className, style, children, hoverGuide, ...props }: ContainerProps): import("react").JSX.Element;
|
|
59
|
+
export type XAxisProps = Pick<RechartsXAxisProps, 'tickSize'> & {
|
|
60
|
+
/** Classes for the tick labels, e.g. `fill-neutral-500`. Keep the font size at 12px: Recharts measures labels at that size to skip overlapping ones. */
|
|
61
|
+
className?: string;
|
|
62
|
+
/** Space between the labels and the plot area, in pixels. */
|
|
63
|
+
labelGap?: number;
|
|
64
|
+
/** The line along the axis. Hidden by default. */
|
|
65
|
+
axisLine?: LineSwitch;
|
|
66
|
+
/** The small marks at each tick. Hidden by default. */
|
|
67
|
+
tickLine?: LineSwitch;
|
|
68
|
+
};
|
|
69
|
+
/** Shows the value ticks along the bottom. Optional: without it the scale still exists, just unlabeled. Renders no element. */
|
|
70
|
+
export declare function XAxis({ className, axisLine, tickLine, tickSize, labelGap, }: XAxisProps): null;
|
|
71
|
+
export type GridProps = {
|
|
72
|
+
/** Classes for every grid line, e.g. `stroke-neutral-200 [stroke-dasharray:4_4]`. */
|
|
73
|
+
className?: string;
|
|
74
|
+
};
|
|
75
|
+
/** Vertical lines only, one per X value tick, marking milestones along the bars. */
|
|
76
|
+
export declare function Grid({ className }: GridProps): import("react").JSX.Element;
|
|
77
|
+
export type BarsProps = Pick<RechartsBarProps, 'radius' | 'hide' | 'name'> & {
|
|
78
|
+
/**
|
|
79
|
+
* Classes for every bar. Colors come only from here or from a preset; there is no built-in color.
|
|
80
|
+
* Target hover with `data-active:` (e.g. `fill-sky-500 data-active:opacity-80`).
|
|
81
|
+
*/
|
|
82
|
+
className?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the bar under the pointer gets `data-active`. Pass false to turn the hover state off.
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
activeBar?: boolean;
|
|
88
|
+
/** Optional BarLabel and BarValue parts, drawn on every bar. */
|
|
89
|
+
children?: ReactNode;
|
|
90
|
+
};
|
|
91
|
+
export declare function Bars({ className, activeBar, children, ...props }: BarsProps): import("react").JSX.Element;
|
|
92
|
+
export type BarLabelProps = {
|
|
93
|
+
/** Classes for the category names, e.g. `fill-neutral-500`. Target the placement with `data-[position=top]:` or `data-[position=left]:`. */
|
|
94
|
+
className?: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Each bar's category name, formatted by `labelToString` on Root and placed by Root's `labelPosition`.
|
|
98
|
+
* Recharts draws it as a LabelList inside the bar; omit it for bars without names.
|
|
99
|
+
*/
|
|
100
|
+
export declare function BarLabel({ className }: BarLabelProps): import("react").JSX.Element | null;
|
|
101
|
+
export type BarValueProps = {
|
|
102
|
+
/** Classes for the value printed past each bar's end, e.g. `fill-neutral-500`. */
|
|
103
|
+
className?: string;
|
|
104
|
+
};
|
|
105
|
+
/** Each bar's value, formatted by `valueToString` on Root and printed past the bar's end. Recharts draws it as a LabelList inside the bar. */
|
|
106
|
+
export declare function BarValue({ className }: BarValueProps): import("react").JSX.Element;
|
|
107
|
+
export type TooltipProps<Data extends Datum = Datum> = Pick<RechartsTooltipProps<number, string>, 'offset' | 'allowEscapeViewBox' | 'portal'> & {
|
|
108
|
+
/** Receives the hovered record and returns the popup. */
|
|
109
|
+
children: (datum: Data) => ReactNode;
|
|
110
|
+
};
|
|
111
|
+
/** Renders no element: hands its popup to the Container. For extra fields, specify the record type: Tooltip<(typeof data)[number]>. */
|
|
112
|
+
export declare function Tooltip<Data extends Datum = Datum>({ children, offset, allowEscapeViewBox, portal, }: TooltipProps<Data>): null;
|
|
113
|
+
export declare function TooltipPopup({ disableStyle, className, ...props }: ComponentProps<'div'> & StyleProps): import("react").JSX.Element;
|
|
114
|
+
export declare function TooltipTitle({ disableStyle, className, ...props }: ComponentProps<'p'> & StyleProps): import("react").JSX.Element;
|
|
115
|
+
/** Shows the hovered record's label, formatted by `labelToString` on Root. */
|
|
116
|
+
export declare function TooltipLabel({ disableStyle, className, ...props }: Omit<ComponentProps<'p'>, 'children'> & StyleProps): import("react").JSX.Element;
|
|
117
|
+
/** Shows the hovered record's value, formatted by `valueToString` on Root. */
|
|
118
|
+
export declare function TooltipValue({ disableStyle, className, ...props }: Omit<ComponentProps<'p'>, 'children'> & StyleProps): import("react").JSX.Element;
|
|
119
|
+
export declare function TooltipColorIndicator({ disableStyle, className, ...props }: ComponentProps<'span'> & StyleProps): import("react").JSX.Element;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useLayoutEffect, useState } from 'react';
|
|
3
|
+
import { twMerge } from 'tailwind-merge';
|
|
4
|
+
import { Bar as RechartsBar, BarChart as RechartsBarChart, CartesianGrid as RechartsGrid, LabelList as RechartsLabelList, Rectangle as RechartsRectangle, Text as RechartsText, Tooltip as RechartsTooltip, XAxis as RechartsXAxis, YAxis as RechartsYAxis, usePlotArea, } from 'recharts';
|
|
5
|
+
// Recharts measures labels at this size; colors come from className or a preset.
|
|
6
|
+
const textSize = { fontSize: 12 };
|
|
7
|
+
const ChartContext = /* @__PURE__ */ createContext(null);
|
|
8
|
+
/** Provides the chart data, formatting, and accessibility settings to its parts. Renders no element. */
|
|
9
|
+
export function Root({ children, labelToString = (label) => label, valueToString = (value) => value.toLocaleString(), allowDecimals = false, labelPosition = 'top', ...chart }) {
|
|
10
|
+
return (_jsx(ChartContext.Provider, { value: {
|
|
11
|
+
...chart,
|
|
12
|
+
labelToString,
|
|
13
|
+
valueToString,
|
|
14
|
+
allowDecimals,
|
|
15
|
+
labelPosition,
|
|
16
|
+
}, children: children }));
|
|
17
|
+
}
|
|
18
|
+
function useChart(part) {
|
|
19
|
+
const chart = useContext(ChartContext);
|
|
20
|
+
if (!chart)
|
|
21
|
+
throw new Error(`HorizontalBarChart.${part} must be inside HorizontalBarChart.Root`);
|
|
22
|
+
return chart;
|
|
23
|
+
}
|
|
24
|
+
const lineProps = (line, part) =>
|
|
25
|
+
// Recharts forwards data attributes at runtime; its types omit them.
|
|
26
|
+
(line && { 'data-component': part });
|
|
27
|
+
/** Lets optional parts hand their settings to the Container, which owns the axes and the single Recharts tooltip. */
|
|
28
|
+
const SlotsContext = /* @__PURE__ */ createContext(null);
|
|
29
|
+
/** Recharts supplies its own responsive container, so no extra wrapper is needed. */
|
|
30
|
+
export function Container({ height = 300, className, style, children, hoverGuide = false, ...props }) {
|
|
31
|
+
const chart = useChart('Container');
|
|
32
|
+
const [tooltip, setTooltip] = useState(null);
|
|
33
|
+
const [xAxis, setXAxis] = useState(null);
|
|
34
|
+
const [label, setLabel] = useState(null);
|
|
35
|
+
const [slots] = useState(() => ({
|
|
36
|
+
setTooltip,
|
|
37
|
+
setXAxis,
|
|
38
|
+
setLabel,
|
|
39
|
+
}));
|
|
40
|
+
const labelsOnTop = chart.labelPosition === 'top';
|
|
41
|
+
const { className: xTickClassName, labelGap = 8, axisLine = false, tickLine = false, tickSize, } = xAxis ?? {};
|
|
42
|
+
return (_jsxs(RechartsBarChart
|
|
43
|
+
// Top room for the first name; right room for the value printed past each bar's end.
|
|
44
|
+
, {
|
|
45
|
+
// Top room for the first name; right room for the value printed past each bar's end.
|
|
46
|
+
margin: { top: labelsOnTop ? 20 : 12, right: 56, bottom: 0, left: 0 }, ...props, data: chart.data, accessibilityLayer: chart.accessibilityLayer, desc: chart.desc, title: chart['aria-label'], className: twMerge('min-w-0 w-full', className), style: { ...style, background: 'transparent' }, height: height, width: "100%", responsive: true, layout: "vertical",
|
|
47
|
+
// Recharts applies this gap on both sides of a bar. With names on top, 12px a side
|
|
48
|
+
// always leaves 24px between bars for a name, however many rows there are.
|
|
49
|
+
barCategoryGap: labelsOnTop ? 12 : '20%', children: [_jsx(RechartsXAxis, { height: "auto", tickSize: tickSize, axisLine: lineProps(axisLine, 'horizontalbarchart-xaxis-line'), tickLine: lineProps(tickLine, 'horizontalbarchart-xaxis-tickline'), hide: !xAxis, tickMargin: labelGap, tickFormatter: chart.valueToString, allowDecimals: chart.allowDecimals, fontSize: 12, tick: {
|
|
50
|
+
className: xTickClassName,
|
|
51
|
+
'data-component': 'horizontalbarchart-xaxis-ticklabel',
|
|
52
|
+
}, dataKey: "value", type: "number", label: false, angle: 0,
|
|
53
|
+
// Always include zero so bars have a baseline, and never collapse the range when every value is 0.
|
|
54
|
+
domain: ([minimum, maximum]) => [
|
|
55
|
+
Math.min(0, minimum),
|
|
56
|
+
Math.max(Math.min(0, minimum) + 1, maximum, 0),
|
|
57
|
+
], interval: "preserveStartEnd", minTickGap: 8 }), _jsx(RechartsYAxis
|
|
58
|
+
// Names sit on the left only when a BarLabel part is rendered.
|
|
59
|
+
, {
|
|
60
|
+
// Names sit on the left only when a BarLabel part is rendered.
|
|
61
|
+
hide: labelsOnTop || !label, axisLine: false, tickLine: false, width: "auto", tickMargin: 8, tickFormatter: chart.labelToString, fontSize: 12, tick: {
|
|
62
|
+
className: label?.className,
|
|
63
|
+
'data-component': 'horizontalbarchart-label',
|
|
64
|
+
'data-position': 'left',
|
|
65
|
+
}, dataKey: "label", type: "category", label: false, angle: 0, interval: 0 }), _jsx(SlotsContext.Provider, { value: slots, children: children }), _jsx(RechartsTooltip, { offset: 12, ...tooltip?.props,
|
|
66
|
+
// Native popup slide, timed to match the hover guide's transition.
|
|
67
|
+
animationDuration: 200, animationEasing: "ease-out", shared: true, cursor: hoverGuide && _jsx(HoverGuide, {}), content: (state) => {
|
|
68
|
+
if (!tooltip || !state.active || !state.payload.length)
|
|
69
|
+
return null;
|
|
70
|
+
// Recharts types the payload as unknown; payload[0] is always the hovered record.
|
|
71
|
+
const datum = state.payload[0].payload;
|
|
72
|
+
return (_jsx(TooltipContext.Provider, { value: datum, children: tooltip.render(datum) }));
|
|
73
|
+
} })] }));
|
|
74
|
+
}
|
|
75
|
+
function useSlots(part) {
|
|
76
|
+
const slots = useContext(SlotsContext);
|
|
77
|
+
if (!slots)
|
|
78
|
+
throw new Error(`HorizontalBarChart.${part} must be inside HorizontalBarChart.Container`);
|
|
79
|
+
return slots;
|
|
80
|
+
}
|
|
81
|
+
/** Shows the value ticks along the bottom. Optional: without it the scale still exists, just unlabeled. Renders no element. */
|
|
82
|
+
export function XAxis({ className, axisLine, tickLine, tickSize, labelGap, }) {
|
|
83
|
+
const slots = useSlots('XAxis');
|
|
84
|
+
useLayoutEffect(() => {
|
|
85
|
+
slots.setXAxis({ className, axisLine, tickLine, tickSize, labelGap });
|
|
86
|
+
return () => slots.setXAxis(null);
|
|
87
|
+
}, [slots.setXAxis, className, axisLine, tickLine, tickSize, labelGap]);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
/** Vertical lines only, one per X value tick, marking milestones along the bars. */
|
|
91
|
+
export function Grid({ className }) {
|
|
92
|
+
return (_jsx(RechartsGrid, { horizontal: false,
|
|
93
|
+
// Recharts' native line slot: each line gets the class and a data-component hook.
|
|
94
|
+
vertical: {
|
|
95
|
+
className,
|
|
96
|
+
'data-component': 'horizontalbarchart-gridline',
|
|
97
|
+
}, fill: "none" }));
|
|
98
|
+
}
|
|
99
|
+
export function Bars({ className, activeBar = true, children, ...props }) {
|
|
100
|
+
return (_jsx(RechartsBar, { radius: 2, ...props, activeBar: activeBar,
|
|
101
|
+
// Recharts' native shape slot renders each bar ourselves, so className and data attributes land on the drawn element.
|
|
102
|
+
shape: (bar) => (_jsx(RechartsRectangle, { ...bar, className: className, "data-component": "horizontalbarchart-bar", "data-index": bar.index, "data-active": bar.isActive ? '' : undefined })), dataKey: "value",
|
|
103
|
+
// Bars stretch to fill each row, but a few rows never become blocks.
|
|
104
|
+
maxBarSize: 80,
|
|
105
|
+
// Zero rows still get a thin, hoverable sliver at the baseline.
|
|
106
|
+
minPointSize: 2, isAnimationActive: false, children: children }));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Each bar's category name, formatted by `labelToString` on Root and placed by Root's `labelPosition`.
|
|
110
|
+
* Recharts draws it as a LabelList inside the bar; omit it for bars without names.
|
|
111
|
+
*/
|
|
112
|
+
export function BarLabel({ className }) {
|
|
113
|
+
const chart = useChart('BarLabel');
|
|
114
|
+
const slots = useSlots('BarLabel');
|
|
115
|
+
// Names on the left are the Container's category axis, so it needs to know they exist and their classes.
|
|
116
|
+
useLayoutEffect(() => {
|
|
117
|
+
slots.setLabel({ className });
|
|
118
|
+
return () => slots.setLabel(null);
|
|
119
|
+
}, [slots.setLabel, className]);
|
|
120
|
+
if (chart.labelPosition !== 'top')
|
|
121
|
+
return null;
|
|
122
|
+
return (_jsx(RechartsLabelList, { dataKey: "label", content: (label) => _jsx(NameAboveBar, { ...label, className: className }) }));
|
|
123
|
+
}
|
|
124
|
+
/** Each bar's value, formatted by `valueToString` on Root and printed past the bar's end. Recharts draws it as a LabelList inside the bar. */
|
|
125
|
+
export function BarValue({ className }) {
|
|
126
|
+
const chart = useChart('BarValue');
|
|
127
|
+
return (_jsx(RechartsLabelList, { dataKey: "value", position: "right", offset: 8, formatter: (value) => chart.valueToString(Number(value)), className: className, ...{ 'data-component': 'horizontalbarchart-value' }, ...textSize }));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Recharts sizes a bar's label to the bar itself, so short bars would wrap long names.
|
|
131
|
+
* Through LabelList's `content` slot, the name gets the plot's full width and one line instead,
|
|
132
|
+
* and Recharts' Text truncates it with an ellipsis only when it reaches the chart's edge.
|
|
133
|
+
*/
|
|
134
|
+
// viewBox is the bar's own rectangle, which Recharts passes to every label.
|
|
135
|
+
function NameAboveBar({ viewBox, value, className, }) {
|
|
136
|
+
const chart = useChart('Bars');
|
|
137
|
+
const plotArea = usePlotArea();
|
|
138
|
+
if (!plotArea || !viewBox || !('x' in viewBox))
|
|
139
|
+
return null;
|
|
140
|
+
return (_jsx(RechartsText
|
|
141
|
+
// 6px above the bar's top-left corner, whatever the bar's thickness.
|
|
142
|
+
, {
|
|
143
|
+
// 6px above the bar's top-left corner, whatever the bar's thickness.
|
|
144
|
+
x: viewBox.x, y: (viewBox.y ?? 0) - 6,
|
|
145
|
+
// Names may run past the plot into the right margin reserved for values.
|
|
146
|
+
width: plotArea.width + 48, maxLines: 1, textAnchor: "start", verticalAnchor: "end", className: className, "data-component": "horizontalbarchart-label", "data-position": "top", ...textSize, children: chart.labelToString(String(value ?? '')) }));
|
|
147
|
+
}
|
|
148
|
+
const TooltipContext = /* @__PURE__ */ createContext(null);
|
|
149
|
+
/** Renders no element: hands its popup to the Container. For extra fields, specify the record type: Tooltip<(typeof data)[number]>. */
|
|
150
|
+
export function Tooltip({ children, offset, allowEscapeViewBox, portal, }) {
|
|
151
|
+
const slots = useSlots('Tooltip');
|
|
152
|
+
useLayoutEffect(() => {
|
|
153
|
+
slots.setTooltip({
|
|
154
|
+
render: children,
|
|
155
|
+
props: { offset, allowEscapeViewBox, portal },
|
|
156
|
+
});
|
|
157
|
+
return () => slots.setTooltip(null);
|
|
158
|
+
}, [slots.setTooltip, children, offset, allowEscapeViewBox, portal]);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
/** Recharts gives the cursor the row's whole rectangle; only its center line is drawn. */
|
|
162
|
+
function HoverGuide({ x = 0, y = 0, width = 0, height = 0, }) {
|
|
163
|
+
return (_jsx("line", { "data-component": "horizontalbarchart-hoverguide",
|
|
164
|
+
// Draw at y=0 and move with a transform, so CSS can slide it between rows (Recharts' cursor has no animation of its own).
|
|
165
|
+
x1: x, x2: x + width, y1: 0, y2: 0,
|
|
166
|
+
// The slide between points is built in.
|
|
167
|
+
className: "transition-transform duration-200 ease-out motion-reduce:transition-none", style: { transform: `translateY(${y + height / 2}px)` }, pointerEvents: "none" }));
|
|
168
|
+
}
|
|
169
|
+
export function TooltipPopup({ disableStyle, className, ...props }) {
|
|
170
|
+
return (_jsx("div", { ...props, "data-component": "horizontalbarchart-tooltip", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
171
|
+
}
|
|
172
|
+
export function TooltipTitle({ disableStyle, className, ...props }) {
|
|
173
|
+
return (_jsx("p", { ...props, "data-component": "horizontalbarchart-tooltiptitle", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
174
|
+
}
|
|
175
|
+
/** Shows the hovered record's label, formatted by `labelToString` on Root. */
|
|
176
|
+
export function TooltipLabel({ disableStyle, className, ...props }) {
|
|
177
|
+
const chart = useChart('TooltipLabel');
|
|
178
|
+
const datum = useContext(TooltipContext);
|
|
179
|
+
if (!datum)
|
|
180
|
+
throw new Error('HorizontalBarChart.TooltipLabel must be inside HorizontalBarChart.Tooltip');
|
|
181
|
+
return (_jsx("p", { ...props, "data-component": "horizontalbarchart-tooltiplabel", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: chart.labelToString(datum.label) }));
|
|
182
|
+
}
|
|
183
|
+
/** Shows the hovered record's value, formatted by `valueToString` on Root. */
|
|
184
|
+
export function TooltipValue({ disableStyle, className, ...props }) {
|
|
185
|
+
const chart = useChart('TooltipValue');
|
|
186
|
+
const datum = useContext(TooltipContext);
|
|
187
|
+
if (!datum)
|
|
188
|
+
throw new Error('HorizontalBarChart.TooltipValue must be inside HorizontalBarChart.Tooltip');
|
|
189
|
+
return (_jsx("p", { ...props, "data-component": "horizontalbarchart-tooltipvalue", "data-style-disabled": disableStyle ? '' : undefined, className: className, children: chart.valueToString(datum.value) }));
|
|
190
|
+
}
|
|
191
|
+
export function TooltipColorIndicator({ disableStyle, className, ...props }) {
|
|
192
|
+
return (_jsx("span", { "aria-hidden": "true", ...props, "data-component": "horizontalbarchart-tooltipcolorindicator", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
193
|
+
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import type { StyleProps } from '../../types/Style.ts';
|
|
2
|
+
import type { SVGIconProps } from '../../types/Icon.ts';
|
|
2
3
|
import { Input as BaseInput } from '@base-ui/react/input';
|
|
3
|
-
import type {
|
|
4
|
+
import type { ValidationProps } from '../../types/Validation.ts';
|
|
4
5
|
import type { ComponentProps, ReactElement, ReactNode } from 'react';
|
|
5
|
-
|
|
6
|
+
import type { ValidationMessageChildren } from '../../utils/Validation.ts';
|
|
7
|
+
export type RootProps = Pick<BaseInput.Props, 'id' | 'name' | 'form' | 'value' | 'defaultValue' | 'onValueChange' | 'disabled' | 'readOnly' | 'required' | 'type'> & ValidationProps & {
|
|
6
8
|
children?: ReactNode;
|
|
7
|
-
/** Choose the visual tone. This does not validate data or show/hide feedback messages. */
|
|
8
|
-
/** Choose the visual tone. This does not validate data or show/hide feedback messages. */
|
|
9
|
-
tone?: 'neutral' | 'valid' | 'invalid';
|
|
10
9
|
};
|
|
11
10
|
/**
|
|
12
|
-
* Keep configuration such as value, name
|
|
11
|
+
* Keep configuration such as value, name and validation on Root. Input is the editable control; InputGroup and Container organize it. Optional addon controls already have their own behavior where named, such as clearing.
|
|
13
12
|
*
|
|
14
13
|
* @example Complete composition
|
|
15
14
|
* import { Input } from '@central-ui/react'
|
|
@@ -46,40 +45,41 @@ export type RootProps = Pick<BaseInput.Props, 'id' | 'name' | 'form' | 'value' |
|
|
|
46
45
|
* )
|
|
47
46
|
* }
|
|
48
47
|
*/
|
|
49
|
-
export declare function Root({ children, id,
|
|
50
|
-
export type InputProps = Omit<BaseInput.Props,
|
|
48
|
+
export declare function Root({ children, id, validation, value, defaultValue, onValueChange, disabled, readOnly, required, ...coreProps }: RootProps): import("react").JSX.Element;
|
|
49
|
+
export type InputProps = Omit<BaseInput.Props, 'id' | 'name' | 'form' | 'value' | 'defaultValue' | 'onValueChange' | 'disabled' | 'readOnly' | 'required' | 'type' | 'className' | 'render'> & {
|
|
51
50
|
className?: string;
|
|
52
51
|
} & StyleProps;
|
|
53
|
-
export declare const Input: import("react").ForwardRefExoticComponent<Omit<
|
|
54
|
-
className?: string;
|
|
55
|
-
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
52
|
+
export declare const Input: import("react").ForwardRefExoticComponent<Omit<InputProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
56
53
|
export declare const InputGroup: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
57
54
|
export declare const Container: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
58
55
|
/** Labels the associated control automatically. Supply the visible text; do not wire a second label association. */
|
|
59
56
|
export declare const Label: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "htmlFor"> & StyleProps, "ref"> & import("react").RefAttributes<HTMLLabelElement>>;
|
|
60
57
|
export declare const Description: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export declare const
|
|
58
|
+
type MessageProps = Omit<ComponentProps<'div'>, 'children'> & StyleProps & {
|
|
59
|
+
children?: ValidationMessageChildren;
|
|
60
|
+
};
|
|
61
|
+
/** Shows itself only while Root's validation is `'error'`: with no children it shows the message from `['error', message]`, a function children formats that message, and other children replace it. */
|
|
62
|
+
export declare const Error: import("react").ForwardRefExoticComponent<Omit<MessageProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
63
|
+
/** Shows itself only while Root's validation is `'success'`: with no children it shows the message from `['success', message]`, a function children formats that message, and other children replace it. */
|
|
64
|
+
export declare const Success: import("react").ForwardRefExoticComponent<Omit<MessageProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
65
|
+
export declare const Addon: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & StyleProps & {
|
|
66
66
|
/** Choose the preset appearance; this does not add action behavior. */
|
|
67
67
|
variant?: "normal" | "emphasized";
|
|
68
|
-
}
|
|
68
|
+
}, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
69
69
|
export declare const AddonText: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLSpanElement> & import("react").HTMLAttributes<HTMLSpanElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLSpanElement>>;
|
|
70
70
|
/** Supply the decorative icon as a child. Its classes are preserved; interaction belongs to the surrounding control. */
|
|
71
|
-
export declare function AddonIcon(
|
|
71
|
+
export declare function AddonIcon(props: Omit<ComponentProps<'svg'>, 'children'> & StyleProps & {
|
|
72
72
|
/** Supply the decorative icon; the wrapper forwards the relevant state and preserves its classes. */
|
|
73
73
|
children: ReactElement<ComponentProps<'svg'>>;
|
|
74
|
-
})
|
|
74
|
+
}): import("react").JSX.Element;
|
|
75
75
|
export declare const AddonButton: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
76
76
|
/** Built-in icon; no children needed. Use it inside its matching control. */
|
|
77
|
-
export declare const AddonLoadingIcon: import("react").ForwardRefExoticComponent<Omit<Omit<
|
|
77
|
+
export declare const AddonLoadingIcon: import("react").ForwardRefExoticComponent<Omit<Omit<SVGIconProps, "children"> & StyleProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
78
78
|
/** Clears the control automatically; no clearing click handler needed. Supply the clear icon and an accessible name. */
|
|
79
79
|
export declare const AddonClearButton: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
80
80
|
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
81
|
-
export declare function AddonClearButtonIcon({
|
|
81
|
+
export declare function AddonClearButtonIcon({ children, ...props }: Omit<ComponentProps<'svg'>, 'children'> & StyleProps & {
|
|
82
82
|
/** Omit for the supplied default icon; pass a child only to replace it. */
|
|
83
83
|
children?: ReactElement<ComponentProps<'svg'>>;
|
|
84
|
-
})
|
|
85
|
-
|
|
84
|
+
}): import("react").JSX.Element;
|
|
85
|
+
export {};
|