@blockle/blocks 0.19.1 → 0.20.0-alpha1
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/dist/components/accessibility/VisuallyHidden/VisuallyHidden.cjs +19 -0
- package/dist/components/accessibility/VisuallyHidden/VisuallyHidden.mjs +20 -0
- package/dist/components/accessibility/VisuallyHidden/index.cjs +1 -0
- package/dist/components/accessibility/VisuallyHidden/index.mjs +1 -0
- package/dist/{styles/components/Accessibility → components/accessibility}/VisuallyHidden/visually-hidden.css.cjs +1 -1
- package/dist/{styles/components/Accessibility → components/accessibility}/VisuallyHidden/visually-hidden.css.mjs +1 -1
- package/dist/components/display/Divider/Divider.cjs +25 -0
- package/dist/components/display/Divider/Divider.mjs +26 -0
- package/dist/{styles/components → components}/display/Divider/divider.css.cjs +2 -2
- package/dist/components/display/Divider/index.cjs +1 -0
- package/dist/components/display/Divider/index.mjs +1 -0
- package/dist/components/feedback/Progress/Progress.cjs +53 -0
- package/dist/components/feedback/Progress/Progress.mjs +54 -0
- package/dist/components/feedback/Progress/index.cjs +1 -0
- package/dist/components/feedback/Progress/index.mjs +1 -0
- package/dist/components/feedback/Spinner/Spinner.cjs +25 -0
- package/dist/components/feedback/Spinner/Spinner.mjs +26 -0
- package/dist/components/feedback/Spinner/index.cjs +1 -0
- package/dist/components/feedback/Spinner/index.mjs +1 -0
- package/dist/components/form/Button/Button.cjs +58 -0
- package/dist/{styles/components → components}/form/Button/Button.css.cjs +2 -2
- package/dist/{styles/components → components}/form/Button/Button.mjs +13 -11
- package/dist/components/form/Button/index.cjs +1 -0
- package/dist/components/form/Button/index.mjs +1 -0
- package/dist/components/form/Checkbox/Checkbox.cjs +78 -0
- package/dist/components/form/Checkbox/Checkbox.mjs +79 -0
- package/dist/{styles/components → components}/form/Checkbox/checkbox.css.cjs +3 -3
- package/dist/components/form/Checkbox/index.cjs +1 -0
- package/dist/components/form/Checkbox/index.mjs +1 -0
- package/dist/components/form/Input/Input.cjs +50 -0
- package/dist/components/form/Input/Input.mjs +51 -0
- package/dist/components/form/Input/index.cjs +1 -0
- package/dist/components/form/Input/index.mjs +1 -0
- package/dist/{styles/components → components}/form/Input/input.css.cjs +2 -2
- package/dist/components/form/Label/Label.cjs +29 -0
- package/dist/components/form/Label/Label.mjs +30 -0
- package/dist/components/form/Label/index.cjs +1 -0
- package/dist/components/form/Label/index.mjs +1 -0
- package/dist/components/form/Radio/Radio.cjs +47 -0
- package/dist/components/form/Radio/Radio.mjs +48 -0
- package/dist/components/form/Radio/RadioGroup.cjs +1 -0
- package/dist/components/form/Radio/RadioGroup.mjs +1 -0
- package/dist/components/form/Radio/index.cjs +1 -0
- package/dist/components/form/Radio/index.mjs +1 -0
- package/dist/{styles/components → components}/form/Radio/radio.css.cjs +3 -3
- package/dist/components/form/Select/Select.cjs +64 -0
- package/dist/{styles/components → components}/form/Select/Select.mjs +23 -6
- package/dist/components/form/Select/index.cjs +1 -0
- package/dist/components/form/Select/index.mjs +1 -0
- package/dist/{styles/components → components}/form/Select/select.css.cjs +4 -4
- package/dist/components/form/Slider/Slider.cjs +139 -0
- package/dist/components/form/Slider/Slider.mjs +142 -0
- package/dist/components/form/Slider/index.cjs +1 -0
- package/dist/components/form/Slider/index.mjs +1 -0
- package/dist/{styles/components → components}/form/Slider/slider.css.cjs +6 -6
- package/dist/components/form/Slider/usePointerProgress.cjs +44 -0
- package/dist/components/form/Slider/usePointerProgress.mjs +45 -0
- package/dist/{styles/components → components}/form/Switch/Switch.cjs +10 -8
- package/dist/{styles/components → components}/form/Switch/Switch.mjs +9 -5
- package/dist/components/form/Switch/index.cjs +1 -0
- package/dist/components/form/Switch/index.mjs +1 -0
- package/dist/{styles/components → components}/form/Switch/switch.css.cjs +3 -3
- package/dist/components/layout/Box/Box.cjs +27 -0
- package/dist/components/layout/Box/Box.mjs +28 -0
- package/dist/components/layout/Box/index.cjs +1 -0
- package/dist/components/layout/Box/index.mjs +1 -0
- package/dist/components/layout/Inline/Inline.cjs +29 -0
- package/dist/components/layout/Inline/Inline.mjs +30 -0
- package/dist/components/layout/Inline/index.cjs +1 -0
- package/dist/components/layout/Inline/index.mjs +1 -0
- package/dist/components/layout/Stack/Stack.cjs +29 -0
- package/dist/components/layout/Stack/Stack.mjs +30 -0
- package/dist/components/layout/Stack/index.cjs +1 -0
- package/dist/components/layout/Stack/index.mjs +1 -0
- package/dist/components/navigation/Link/Link.cjs +31 -0
- package/dist/components/navigation/Link/Link.mjs +32 -0
- package/dist/components/navigation/Link/index.cjs +1 -0
- package/dist/components/navigation/Link/index.mjs +1 -0
- package/dist/components/other/BlocksProvider/BlocksProvider.cjs +36 -0
- package/dist/{styles/components → components}/other/BlocksProvider/BlocksProvider.mjs +12 -5
- package/dist/components/other/BlocksProvider/context.cjs +4 -0
- package/dist/components/other/BlocksProvider/context.mjs +7 -0
- package/dist/components/other/BlocksProvider/index.cjs +1 -0
- package/dist/components/other/BlocksProvider/index.mjs +1 -0
- package/dist/components/other/Portal/Portal.cjs +7 -0
- package/dist/components/other/Portal/Portal.mjs +8 -0
- package/dist/components/other/Portal/index.cjs +1 -0
- package/dist/components/other/Portal/index.mjs +1 -0
- package/dist/components/overlay/Dialog/Dialog.cjs +77 -0
- package/dist/components/overlay/Dialog/Dialog.mjs +80 -0
- package/dist/{styles/components → components}/overlay/Dialog/dialog.css.cjs +2 -2
- package/dist/components/overlay/Dialog/dialogHelper.cjs +20 -0
- package/dist/components/overlay/Dialog/dialogHelper.mjs +21 -0
- package/dist/components/overlay/Dialog/index.cjs +1 -0
- package/dist/components/overlay/Dialog/index.mjs +1 -0
- package/dist/components/overlay/Popover/Popover.cjs +111 -0
- package/dist/components/overlay/Popover/Popover.mjs +112 -0
- package/dist/components/overlay/Popover/popover-utils.cjs +61 -0
- package/dist/components/overlay/Popover/popover-utils.mjs +62 -0
- package/dist/components/overlay/Tooltip/Tooltip.cjs +71 -0
- package/dist/components/overlay/Tooltip/Tooltip.mjs +74 -0
- package/dist/components/overlay/Tooltip/index.cjs +1 -0
- package/dist/components/overlay/Tooltip/index.mjs +1 -0
- package/dist/components/typography/Heading/Heading.cjs +23 -0
- package/dist/components/typography/Heading/Heading.mjs +24 -0
- package/dist/{styles/components → components}/typography/Heading/heading.css.cjs +2 -2
- package/dist/components/typography/Heading/index.cjs +1 -0
- package/dist/components/typography/Heading/index.mjs +1 -0
- package/dist/components/typography/Text/Text.cjs +20 -0
- package/dist/{styles/components → components}/typography/Text/Text.mjs +2 -2
- package/dist/components/typography/Text/index.cjs +1 -0
- package/dist/components/typography/Text/index.mjs +1 -0
- package/dist/{styles/components → components}/typography/Text/text.css.cjs +2 -2
- package/dist/hooks/useClickOutside/useClickOutside.cjs +22 -0
- package/dist/hooks/useClickOutside/useClickOutside.mjs +23 -0
- package/dist/hooks/useControlledValue/useControlledValue.cjs +31 -0
- package/dist/hooks/useControlledValue/useControlledValue.mjs +32 -0
- package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect/index.mjs +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +4 -0
- package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +7 -0
- package/dist/hooks/useKeyboard/index.cjs +1 -0
- package/dist/hooks/useKeyboard/index.mjs +1 -0
- package/dist/hooks/useKeyboard/useKeyboard.cjs +19 -0
- package/dist/hooks/useKeyboard/useKeyboard.mjs +22 -0
- package/dist/hooks/useLayer/index.cjs +1 -0
- package/dist/hooks/useLayer/index.mjs +1 -0
- package/dist/hooks/useLayer/useLayer.cjs +25 -0
- package/dist/hooks/useLayer/useLayer.mjs +26 -0
- package/dist/hooks/usePreventBodyScroll/index.cjs +1 -0
- package/dist/hooks/usePreventBodyScroll/index.mjs +1 -0
- package/dist/hooks/usePreventBodyScroll/usePreventBodyScroll.cjs +29 -0
- package/dist/hooks/usePreventBodyScroll/usePreventBodyScroll.mjs +30 -0
- package/dist/hooks/useRestoreFocus/index.cjs +1 -0
- package/dist/hooks/useRestoreFocus/index.mjs +1 -0
- package/dist/hooks/useRestoreFocus/useRestoreFocus.cjs +17 -0
- package/dist/hooks/useRestoreFocus/useRestoreFocus.mjs +18 -0
- package/dist/hooks/useRootAriaHidden/index.cjs +1 -0
- package/dist/hooks/useRootAriaHidden/index.mjs +1 -0
- package/dist/hooks/useRootAriaHidden/useRootAriaHidden.cjs +11 -0
- package/dist/hooks/useRootAriaHidden/useRootAriaHidden.mjs +12 -0
- package/dist/hooks/useVisibilityState/index.cjs +1 -0
- package/dist/hooks/useVisibilityState/index.mjs +1 -0
- package/dist/hooks/useVisibilityState/useVisibilityState.cjs +15 -0
- package/dist/hooks/useVisibilityState/useVisibilityState.mjs +16 -0
- package/dist/index.cjs +71 -444
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +37 -415
- package/dist/lib/asChildRenderer/createAsChildTemplate.cjs +72 -0
- package/dist/lib/asChildRenderer/createAsChildTemplate.mjs +73 -0
- package/dist/{styles/lib → lib}/css/atoms/atomicProperties.cjs +28 -22
- package/dist/{styles/lib → lib}/css/atoms/atomicProperties.mjs +7 -1
- package/dist/{styles/lib → lib}/css/atoms/sprinkles.css.cjs +8 -8
- package/dist/lib/css/flexbox/flexbox.cjs +16 -0
- package/dist/lib/css/flexbox/flexbox.mjs +17 -0
- package/dist/{styles/lib → lib}/css/style/style.cjs +3 -3
- package/dist/lib/react/mergeProps.cjs +42 -0
- package/dist/lib/react/mergeProps.mjs +43 -0
- package/dist/lib/react/refs.cjs +16 -0
- package/dist/lib/react/refs.mjs +17 -0
- package/dist/lib/theme/makeTheme.cjs +12 -0
- package/dist/lib/theme/store/theme.cjs +92 -0
- package/dist/lib/theme/store/theme.mjs +93 -0
- package/dist/lib/theme/vars.css.cjs +9 -0
- package/dist/{styles/lib → lib}/utils/atom-props.cjs +2 -2
- package/dist/lib/utils/classnames.cjs +6 -0
- package/dist/lib/utils/classnames.mjs +7 -0
- package/dist/lib/utils/dom.cjs +12 -0
- package/dist/lib/utils/dom.mjs +13 -0
- package/dist/lib/utils/math.cjs +12 -0
- package/dist/lib/utils/math.mjs +13 -0
- package/dist/momotaro.chunk.d.ts +40 -56
- package/dist/reset.cjs +2 -2
- package/dist/reset.mjs +2 -2
- package/dist/{styles/themes → themes}/momotaro/components/button.css.cjs +23 -23
- package/dist/themes/momotaro/components/checkbox.css.cjs +59 -0
- package/dist/{styles/themes → themes}/momotaro/components/dialog.css.cjs +4 -4
- package/dist/{styles/themes → themes}/momotaro/components/divider.css.cjs +2 -2
- package/dist/{styles/themes → themes}/momotaro/components/helpers.css.cjs +3 -3
- package/dist/themes/momotaro/components/index.cjs +34 -0
- package/dist/{styles/themes → themes}/momotaro/components/input.css.cjs +9 -9
- package/dist/{styles/themes → themes}/momotaro/components/label.css.cjs +7 -7
- package/dist/{styles/themes → themes}/momotaro/components/link.css.cjs +7 -7
- package/dist/{styles/themes → themes}/momotaro/components/popover.css.cjs +4 -4
- package/dist/{styles/themes → themes}/momotaro/components/progress.css.cjs +7 -7
- package/dist/themes/momotaro/components/radio.css.cjs +60 -0
- package/dist/themes/momotaro/components/select.css.cjs +44 -0
- package/dist/themes/momotaro/components/slider.css.cjs +89 -0
- package/dist/{styles/themes → themes}/momotaro/components/spinner.css.cjs +2 -2
- package/dist/{styles/themes → themes}/momotaro/components/switch.css.cjs +10 -10
- package/dist/{styles/themes → themes}/momotaro/components/tooltip.css.cjs +6 -6
- package/dist/themes/momotaro/momotaro.css.cjs +13 -0
- package/dist/{styles/themes → themes}/momotaro/tokens.css.cjs +11 -11
- package/dist/themes/momotaro.cjs +2 -2
- package/dist/themes/momotaro.mjs +1 -1
- package/package.json +5 -15
- package/dist/styles/components/Accessibility/VisuallyHidden/VisuallyHidden.cjs +0 -16
- package/dist/styles/components/Accessibility/VisuallyHidden/VisuallyHidden.mjs +0 -17
- package/dist/styles/components/display/Divider/Divider.cjs +0 -239
- package/dist/styles/components/display/Divider/Divider.mjs +0 -240
- package/dist/styles/components/form/Button/Button.cjs +0 -56
- package/dist/styles/components/form/Checkbox/Checkbox.cjs +0 -84
- package/dist/styles/components/form/Checkbox/Checkbox.mjs +0 -85
- package/dist/styles/components/form/Input/Input.cjs +0 -37
- package/dist/styles/components/form/Input/Input.mjs +0 -38
- package/dist/styles/components/form/Radio/Radio.cjs +0 -23
- package/dist/styles/components/form/Radio/Radio.mjs +0 -24
- package/dist/styles/components/form/Select/Select.cjs +0 -47
- package/dist/styles/components/form/Slider/Slider.cjs +0 -205
- package/dist/styles/components/form/Slider/Slider.mjs +0 -206
- package/dist/styles/components/other/BlocksProvider/BlocksProvider.cjs +0 -31
- package/dist/styles/components/overlay/Dialog/Dialog.cjs +0 -172
- package/dist/styles/components/overlay/Dialog/Dialog.mjs +0 -173
- package/dist/styles/components/typography/Heading/Heading.cjs +0 -15
- package/dist/styles/components/typography/Heading/Heading.mjs +0 -16
- package/dist/styles/components/typography/Text/Text.cjs +0 -20
- package/dist/styles/lib/theme/makeTheme.cjs +0 -12
- package/dist/styles/lib/theme/vars.css.cjs +0 -9
- package/dist/styles/themes/momotaro/components/checkbox.css.cjs +0 -59
- package/dist/styles/themes/momotaro/components/index.cjs +0 -34
- package/dist/styles/themes/momotaro/components/radio.css.cjs +0 -60
- package/dist/styles/themes/momotaro/components/select.css.cjs +0 -44
- package/dist/styles/themes/momotaro/components/slider.css.cjs +0 -89
- package/dist/styles/themes/momotaro/momotaro.css.cjs +0 -13
- /package/dist/{styles/components → components}/display/Divider/divider.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Button/Button.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Checkbox/checkbox.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Input/input.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Radio/radio.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Select/select.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Slider/slider.css.mjs +0 -0
- /package/dist/{styles/components → components}/form/Switch/switch.css.mjs +0 -0
- /package/dist/{styles/components → components}/overlay/Dialog/dialog.css.mjs +0 -0
- /package/dist/{styles/components → components}/typography/Heading/heading.css.mjs +0 -0
- /package/dist/{styles/components → components}/typography/Text/text.css.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/atoms.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/atoms.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/breakpoints.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/breakpoints.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/index.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/index.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/atoms/sprinkles.css.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/layers/layers.css.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/layers/layers.css.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/reset/reset.css.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/reset/reset.css.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/style/style.mjs +0 -0
- /package/dist/{styles/lib → lib}/css/utils/cssUtils.cjs +0 -0
- /package/dist/{styles/lib → lib}/css/utils/cssUtils.mjs +0 -0
- /package/dist/{styles/lib → lib}/theme/makeComponentTheme.cjs +0 -0
- /package/dist/{styles/lib → lib}/theme/makeComponentTheme.mjs +0 -0
- /package/dist/{styles/lib → lib}/theme/makeTheme.mjs +0 -0
- /package/dist/{styles/lib → lib}/theme/makeVanillaTheme.cjs +0 -0
- /package/dist/{styles/lib → lib}/theme/makeVanillaTheme.mjs +0 -0
- /package/dist/{styles/lib → lib}/theme/tokens.cjs +0 -0
- /package/dist/{styles/lib → lib}/theme/tokens.mjs +0 -0
- /package/dist/{styles/lib → lib}/theme/vars.css.mjs +0 -0
- /package/dist/{styles/lib → lib}/utils/atom-props.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/button.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/checkbox.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/dialog.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/divider.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/helpers.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/index.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/input.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/label.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/link.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/popover.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/progress.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/radio.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/select.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/slider.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/spinner.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/switch.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/tooltip.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/transitions.cjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/components/transitions.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/index.cjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/index.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/momotaro.css.mjs +0 -0
- /package/dist/{styles/themes → themes}/momotaro/tokens.css.mjs +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,416 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { Button
|
|
15
|
-
import { Checkbox
|
|
16
|
-
import { Input } from "./
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const progress = value / max * 100;
|
|
37
|
-
const containerClassName = useComponentStyles(
|
|
38
|
-
"progress",
|
|
39
|
-
{
|
|
40
|
-
base: true
|
|
41
|
-
},
|
|
42
|
-
false
|
|
43
|
-
);
|
|
44
|
-
const barClassName = useComponentStyles(
|
|
45
|
-
"progress",
|
|
46
|
-
{ bar: true, variants: { indeterminate } },
|
|
47
|
-
false
|
|
48
|
-
);
|
|
49
|
-
return /* @__PURE__ */ jsx(
|
|
50
|
-
Box,
|
|
51
|
-
{
|
|
52
|
-
ref,
|
|
53
|
-
className: classnames(containerClassName, className),
|
|
54
|
-
overflow: "hidden",
|
|
55
|
-
role: "progressbar",
|
|
56
|
-
"aria-valuenow": value,
|
|
57
|
-
"aria-valuemin": 0,
|
|
58
|
-
"aria-valuemax": max,
|
|
59
|
-
...restProps,
|
|
60
|
-
children: /* @__PURE__ */ jsx(
|
|
61
|
-
Box,
|
|
62
|
-
{
|
|
63
|
-
className: barClassName,
|
|
64
|
-
backgroundColor: "currentColor",
|
|
65
|
-
inlineSize: "full",
|
|
66
|
-
blockSize: "full",
|
|
67
|
-
style: { transform: indeterminate ? void 0 : `translateX(-${100 - progress}%)` }
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
const justifyContentMap = {
|
|
74
|
-
left: "flex-start",
|
|
75
|
-
right: "flex-end",
|
|
76
|
-
center: "center",
|
|
77
|
-
between: "space-between",
|
|
78
|
-
around: "space-around"
|
|
79
|
-
};
|
|
80
|
-
const alignItemsMap = {
|
|
81
|
-
left: "flex-start",
|
|
82
|
-
right: "flex-end",
|
|
83
|
-
center: "center",
|
|
84
|
-
stretch: "stretch"
|
|
85
|
-
};
|
|
86
|
-
const Inline = ({
|
|
87
|
-
alignX,
|
|
88
|
-
alignY,
|
|
89
|
-
tag: Tag = "div",
|
|
90
|
-
children,
|
|
91
|
-
display = "flex",
|
|
92
|
-
spacing,
|
|
93
|
-
...props
|
|
94
|
-
}) => {
|
|
95
|
-
return /* @__PURE__ */ jsx(
|
|
96
|
-
Box,
|
|
97
|
-
{
|
|
98
|
-
asChild: true,
|
|
99
|
-
display,
|
|
100
|
-
gap: spacing,
|
|
101
|
-
flexDirection: "row",
|
|
102
|
-
justifyContent: alignX ? justifyContentMap[alignX] : void 0,
|
|
103
|
-
alignItems: alignY ? alignItemsMap[alignY] : void 0,
|
|
104
|
-
flexWrap: "wrap",
|
|
105
|
-
...props,
|
|
106
|
-
children: /* @__PURE__ */ jsx(Tag, { children })
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
const Stack = ({
|
|
111
|
-
tag: Tag = "div",
|
|
112
|
-
display = "flex",
|
|
113
|
-
children,
|
|
114
|
-
spacing,
|
|
115
|
-
alignX,
|
|
116
|
-
...restProps
|
|
117
|
-
}) => {
|
|
118
|
-
if (process.env.NODE_ENV === "development" && restProps.start !== void 0 && Tag !== "ol") {
|
|
119
|
-
console.warn('Stack: "start" prop is only valid with tag="ol"');
|
|
120
|
-
}
|
|
121
|
-
return /* @__PURE__ */ jsx(
|
|
122
|
-
Box,
|
|
123
|
-
{
|
|
124
|
-
asChild: true,
|
|
125
|
-
display,
|
|
126
|
-
gap: spacing,
|
|
127
|
-
flexDirection: "column",
|
|
128
|
-
alignItems: alignX ? alignItemsMap[alignX] : void 0,
|
|
129
|
-
...restProps,
|
|
130
|
-
children: /* @__PURE__ */ jsx(Tag, { children })
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
const { Template, Slot } = createAsChildTemplate("a");
|
|
135
|
-
const Link = ({
|
|
136
|
-
asChild,
|
|
137
|
-
children,
|
|
138
|
-
className,
|
|
139
|
-
ref,
|
|
140
|
-
underline,
|
|
141
|
-
variant,
|
|
142
|
-
...restProps
|
|
143
|
-
}) => {
|
|
144
|
-
const linkClassName = useComponentStyles("link", {
|
|
145
|
-
base: true,
|
|
146
|
-
variants: { variant, underline }
|
|
147
|
-
});
|
|
148
|
-
return /* @__PURE__ */ jsx(
|
|
149
|
-
Template,
|
|
150
|
-
{
|
|
151
|
-
asChild,
|
|
152
|
-
ref,
|
|
153
|
-
className: classnames(className, linkClassName),
|
|
154
|
-
...restProps,
|
|
155
|
-
children: /* @__PURE__ */ jsx(Slot, { children })
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
const Portal = ({ children, container }) => {
|
|
160
|
-
const context = useTheme();
|
|
161
|
-
return createPortal(
|
|
162
|
-
/* @__PURE__ */ jsx(BlocksProvider, { theme: context, children }),
|
|
163
|
-
container || document.body
|
|
164
|
-
);
|
|
165
|
-
};
|
|
166
|
-
const useLayer = () => {
|
|
167
|
-
const layerRef = useRef(null);
|
|
168
|
-
useEffect(
|
|
169
|
-
() => () => {
|
|
170
|
-
if (layerRef.current) {
|
|
171
|
-
layerRef.current.remove();
|
|
172
|
-
layerRef.current = null;
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
[]
|
|
176
|
-
);
|
|
177
|
-
function getLayer() {
|
|
178
|
-
if (!layerRef.current) {
|
|
179
|
-
const div = document.createElement("div");
|
|
180
|
-
div.dataset.layer = "blocks";
|
|
181
|
-
layerRef.current = div;
|
|
182
|
-
document.body.append(layerRef.current);
|
|
183
|
-
}
|
|
184
|
-
return layerRef.current;
|
|
185
|
-
}
|
|
186
|
-
return getLayer;
|
|
187
|
-
};
|
|
188
|
-
const useVisibilityState = (open) => {
|
|
189
|
-
const [visible, setVisible] = useState(open);
|
|
190
|
-
const hide = useCallback(() => {
|
|
191
|
-
setVisible(false);
|
|
192
|
-
}, []);
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
if (open) {
|
|
195
|
-
setVisible(true);
|
|
196
|
-
}
|
|
197
|
-
}, [open]);
|
|
198
|
-
return [visible, hide];
|
|
199
|
-
};
|
|
200
|
-
function getPopoverPosition(align, anchorRef, popoverRef) {
|
|
201
|
-
if (!anchorRef.current || !popoverRef.current) {
|
|
202
|
-
return [0, 0];
|
|
203
|
-
}
|
|
204
|
-
popoverRef.current.style.transform = "none";
|
|
205
|
-
popoverRef.current.style.transitionDuration = "0s";
|
|
206
|
-
const anchorRect = anchorRef.current.getBoundingClientRect();
|
|
207
|
-
const popoverRect = popoverRef.current.getBoundingClientRect();
|
|
208
|
-
let popoverStyles = getComputedStyle(popoverRef.current);
|
|
209
|
-
const top = popoverStyles.getPropertyValue("top");
|
|
210
|
-
const left = popoverStyles.getPropertyValue("left");
|
|
211
|
-
popoverRef.current.style.left = "0";
|
|
212
|
-
popoverRef.current.style.top = "0";
|
|
213
|
-
popoverStyles = getComputedStyle(popoverRef.current);
|
|
214
|
-
const marginTop = Number.parseFloat(popoverStyles.getPropertyValue("margin-top"));
|
|
215
|
-
const marginRight = Number.parseFloat(popoverStyles.getPropertyValue("margin-right"));
|
|
216
|
-
const marginBottom = Number.parseFloat(popoverStyles.getPropertyValue("margin-bottom"));
|
|
217
|
-
const marginLeft = Number.parseFloat(popoverStyles.getPropertyValue("margin-left"));
|
|
218
|
-
const marginY = marginTop + marginBottom;
|
|
219
|
-
const marginX = marginRight + marginLeft;
|
|
220
|
-
const docHeight = document.documentElement.clientHeight;
|
|
221
|
-
const docWidth = document.documentElement.clientWidth;
|
|
222
|
-
const docScrollTop = document.documentElement.scrollTop;
|
|
223
|
-
const docScrollLeft = document.documentElement.scrollLeft;
|
|
224
|
-
const anchorLeft = anchorRect.left + docScrollLeft;
|
|
225
|
-
const anchorTop = anchorRect.top + docScrollTop;
|
|
226
|
-
const topPosition = anchorRect.top - (popoverRect.height + marginTop);
|
|
227
|
-
const rightPosition = anchorRect.left + anchorRect.width + popoverRect.width;
|
|
228
|
-
const bottomPosition = anchorRect.top + anchorRect.height + popoverRect.height;
|
|
229
|
-
const leftPosition = anchorRect.left - popoverRect.width;
|
|
230
|
-
const offsetX = anchorLeft - marginLeft - (popoverRect.width - anchorRect.width) / 2;
|
|
231
|
-
const offsetY = anchorTop - marginTop - (popoverRect.height - anchorRect.height) / 2;
|
|
232
|
-
popoverRef.current.style.transform = "";
|
|
233
|
-
popoverRef.current.style.transitionDuration = "";
|
|
234
|
-
popoverRef.current.style.top = top;
|
|
235
|
-
popoverRef.current.style.left = left;
|
|
236
|
-
switch (align) {
|
|
237
|
-
case "top": {
|
|
238
|
-
return topPosition > 0 ? [offsetX, anchorTop - popoverRect.height - marginY] : [offsetX, anchorTop + anchorRect.height];
|
|
239
|
-
}
|
|
240
|
-
case "bottom": {
|
|
241
|
-
return bottomPosition < docHeight || topPosition < 0 ? [offsetX, anchorTop + anchorRect.height] : [offsetX, anchorTop - popoverRect.height - marginY];
|
|
242
|
-
}
|
|
243
|
-
case "left": {
|
|
244
|
-
return leftPosition > docWidth || leftPosition > 0 ? [anchorLeft - popoverRect.width - marginX, offsetY] : [anchorLeft + anchorRect.width, offsetY];
|
|
245
|
-
}
|
|
246
|
-
case "right": {
|
|
247
|
-
return rightPosition < docWidth || leftPosition < 0 ? [anchorLeft + anchorRect.width, offsetY] : [anchorLeft - popoverRect.width - marginX, offsetY];
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const Popover = ({
|
|
252
|
-
align = "bottom",
|
|
253
|
-
anchorElement,
|
|
254
|
-
children,
|
|
255
|
-
className,
|
|
256
|
-
onRequestClose,
|
|
257
|
-
open,
|
|
258
|
-
repositionOnScroll,
|
|
259
|
-
style: style2,
|
|
260
|
-
...restProps
|
|
261
|
-
}) => {
|
|
262
|
-
const layer = useLayer();
|
|
263
|
-
const [visible, hide] = useVisibilityState(open);
|
|
264
|
-
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
265
|
-
const popoverRef = useRef(null);
|
|
266
|
-
const containerClassName = useComponentStyles("popover", { base: true }, false);
|
|
267
|
-
useLayoutEffect(() => {
|
|
268
|
-
if (!visible) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
const position2 = getPopoverPosition(align, anchorElement, popoverRef);
|
|
272
|
-
setPosition({ x: position2[0], y: position2[1] });
|
|
273
|
-
}, [align, anchorElement, visible]);
|
|
274
|
-
useEffect(() => {
|
|
275
|
-
if (!open || !repositionOnScroll) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
function handleResize() {
|
|
279
|
-
const position2 = getPopoverPosition(align, anchorElement, popoverRef);
|
|
280
|
-
setPosition({ x: position2[0], y: position2[1] });
|
|
281
|
-
}
|
|
282
|
-
window.addEventListener("resize", handleResize);
|
|
283
|
-
window.addEventListener("scroll", handleResize);
|
|
284
|
-
return () => {
|
|
285
|
-
window.removeEventListener("resize", handleResize);
|
|
286
|
-
window.removeEventListener("scroll", handleResize);
|
|
287
|
-
};
|
|
288
|
-
}, [align, anchorElement, open, repositionOnScroll]);
|
|
289
|
-
useIsomorphicLayoutEffect(() => {
|
|
290
|
-
var _a;
|
|
291
|
-
if (!open) {
|
|
292
|
-
(_a = popoverRef.current) == null ? void 0 : _a.removeAttribute("data-open");
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
let timer = requestAnimationFrame(() => {
|
|
296
|
-
timer = requestAnimationFrame(() => {
|
|
297
|
-
var _a2;
|
|
298
|
-
(_a2 = popoverRef.current) == null ? void 0 : _a2.setAttribute("data-open", "");
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
return () => {
|
|
302
|
-
cancelAnimationFrame(timer);
|
|
303
|
-
};
|
|
304
|
-
}, [open, visible]);
|
|
305
|
-
const onAnimationEnd = useCallback(() => {
|
|
306
|
-
if (!open) {
|
|
307
|
-
hide();
|
|
308
|
-
}
|
|
309
|
-
}, [hide, open]);
|
|
310
|
-
useEffect(() => {
|
|
311
|
-
if (open) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (!hasAnimationDuration(popoverRef.current)) {
|
|
315
|
-
hide();
|
|
316
|
-
}
|
|
317
|
-
}, [hide, open]);
|
|
318
|
-
useKeyboard("Escape", onRequestClose, { enabled: visible });
|
|
319
|
-
useClickOutside(popoverRef, onRequestClose, { enabled: visible });
|
|
320
|
-
if (!visible) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
const dataOpen = typeof window === "undefined" && open ? "" : void 0;
|
|
324
|
-
return /* @__PURE__ */ jsx(Portal, { container: layer(), children: /* @__PURE__ */ jsx(
|
|
325
|
-
Box,
|
|
326
|
-
{
|
|
327
|
-
ref: popoverRef,
|
|
328
|
-
"data-open": dataOpen,
|
|
329
|
-
onAnimationEnd,
|
|
330
|
-
onTransitionEnd: onAnimationEnd,
|
|
331
|
-
className: classnames(containerClassName, className),
|
|
332
|
-
position: "absolute",
|
|
333
|
-
style: {
|
|
334
|
-
...style2,
|
|
335
|
-
left: position.x,
|
|
336
|
-
top: position.y
|
|
337
|
-
},
|
|
338
|
-
...restProps,
|
|
339
|
-
children
|
|
340
|
-
}
|
|
341
|
-
) });
|
|
342
|
-
};
|
|
343
|
-
const Tooltip = ({
|
|
344
|
-
align = "top",
|
|
345
|
-
children,
|
|
346
|
-
label,
|
|
347
|
-
colorScheme
|
|
348
|
-
}) => {
|
|
349
|
-
const id = useId();
|
|
350
|
-
const ref = useRef(null);
|
|
351
|
-
const [open, setOpen] = useState(false);
|
|
352
|
-
const tooltipClassName = useComponentStyles("tooltip", {
|
|
353
|
-
base: true,
|
|
354
|
-
variants: { colorScheme }
|
|
355
|
-
});
|
|
356
|
-
useEffect(() => {
|
|
357
|
-
const element = ref.current;
|
|
358
|
-
if (!element) {
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
function onEnter() {
|
|
362
|
-
setOpen(true);
|
|
363
|
-
}
|
|
364
|
-
function onLeave() {
|
|
365
|
-
setOpen(false);
|
|
366
|
-
}
|
|
367
|
-
element.addEventListener("mouseenter", onEnter);
|
|
368
|
-
element.addEventListener("mouseleave", onLeave);
|
|
369
|
-
element.addEventListener("focusin", onEnter);
|
|
370
|
-
element.addEventListener("focusout", onLeave);
|
|
371
|
-
return () => {
|
|
372
|
-
element.removeEventListener("mouseenter", onEnter);
|
|
373
|
-
element.removeEventListener("mouseleave", onLeave);
|
|
374
|
-
element.removeEventListener("focusin", onEnter);
|
|
375
|
-
element.removeEventListener("focusout", onLeave);
|
|
376
|
-
};
|
|
377
|
-
}, [ref, setOpen]);
|
|
378
|
-
if (Children.count(children) !== 1) {
|
|
379
|
-
throw new Error("Tooltip component can only have one child");
|
|
380
|
-
}
|
|
381
|
-
const child = Children.toArray(children)[0];
|
|
382
|
-
if (!isValidElement(child)) {
|
|
383
|
-
return null;
|
|
384
|
-
}
|
|
385
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
386
|
-
cloneElement(child, {
|
|
387
|
-
ref: composeRefs(ref, child.ref),
|
|
388
|
-
["aria-describedby"]: open ? id : void 0
|
|
389
|
-
}),
|
|
390
|
-
/* @__PURE__ */ jsx(
|
|
391
|
-
Popover,
|
|
392
|
-
{
|
|
393
|
-
id,
|
|
394
|
-
role: "tooltip",
|
|
395
|
-
anchorElement: ref,
|
|
396
|
-
open,
|
|
397
|
-
onRequestClose: () => {
|
|
398
|
-
setOpen(false);
|
|
399
|
-
},
|
|
400
|
-
align,
|
|
401
|
-
className: tooltipClassName,
|
|
402
|
-
children: label
|
|
403
|
-
}
|
|
404
|
-
)
|
|
405
|
-
] });
|
|
406
|
-
};
|
|
407
|
-
const useRootAriaHidden = (hidden) => {
|
|
408
|
-
const context = useContext(BlocksProviderContext);
|
|
409
|
-
if (!context) {
|
|
410
|
-
throw new Error("useRootAriaHidden must be used within a BlocksProvider");
|
|
411
|
-
}
|
|
412
|
-
context.setAriaHidden(hidden);
|
|
413
|
-
};
|
|
1
|
+
import { minMediaQuery } from "./lib/css/atoms/breakpoints.mjs";
|
|
2
|
+
import { style } from "./lib/css/style/style.mjs";
|
|
3
|
+
import { makeComponentTheme } from "./lib/theme/makeComponentTheme.mjs";
|
|
4
|
+
import { makeTheme } from "./lib/theme/makeTheme.mjs";
|
|
5
|
+
import { vars } from "./lib/theme/vars.css.mjs";
|
|
6
|
+
import { createAsChildTemplate } from "./lib/asChildRenderer/createAsChildTemplate.mjs";
|
|
7
|
+
import { getTheme, setTheme } from "./lib/theme/store/theme.mjs";
|
|
8
|
+
import { classnames } from "./lib/utils/classnames.mjs";
|
|
9
|
+
import { atoms } from "./lib/css/atoms/sprinkles.css.mjs";
|
|
10
|
+
import { VisuallyHidden } from "./components/accessibility/VisuallyHidden/VisuallyHidden.mjs";
|
|
11
|
+
import { Divider } from "./components/display/Divider/Divider.mjs";
|
|
12
|
+
import { Progress } from "./components/feedback/Progress/Progress.mjs";
|
|
13
|
+
import { Spinner } from "./components/feedback/Spinner/Spinner.mjs";
|
|
14
|
+
import { Button } from "./components/form/Button/Button.mjs";
|
|
15
|
+
import { Checkbox } from "./components/form/Checkbox/Checkbox.mjs";
|
|
16
|
+
import { Input } from "./components/form/Input/Input.mjs";
|
|
17
|
+
import { Label } from "./components/form/Label/Label.mjs";
|
|
18
|
+
import { Radio } from "./components/form/Radio/Radio.mjs";
|
|
19
|
+
import { Select } from "./components/form/Select/Select.mjs";
|
|
20
|
+
import { Slider } from "./components/form/Slider/Slider.mjs";
|
|
21
|
+
import { Switch } from "./components/form/Switch/Switch.mjs";
|
|
22
|
+
import { Box } from "./components/layout/Box/Box.mjs";
|
|
23
|
+
import { Inline } from "./components/layout/Inline/Inline.mjs";
|
|
24
|
+
import { Stack } from "./components/layout/Stack/Stack.mjs";
|
|
25
|
+
import { Link } from "./components/navigation/Link/Link.mjs";
|
|
26
|
+
import { BlocksProvider } from "./components/other/BlocksProvider/BlocksProvider.mjs";
|
|
27
|
+
import { Portal } from "./components/other/Portal/Portal.mjs";
|
|
28
|
+
import { Dialog } from "./components/overlay/Dialog/Dialog.mjs";
|
|
29
|
+
import { Tooltip } from "./components/overlay/Tooltip/Tooltip.mjs";
|
|
30
|
+
import { Heading } from "./components/typography/Heading/Heading.mjs";
|
|
31
|
+
import { Text } from "./components/typography/Text/Text.mjs";
|
|
32
|
+
import { useIsomorphicLayoutEffect } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
33
|
+
import { useKeyboard } from "./hooks/useKeyboard/useKeyboard.mjs";
|
|
34
|
+
import { usePreventBodyScroll } from "./hooks/usePreventBodyScroll/usePreventBodyScroll.mjs";
|
|
35
|
+
import { useRootAriaHidden } from "./hooks/useRootAriaHidden/useRootAriaHidden.mjs";
|
|
414
36
|
export {
|
|
415
37
|
BlocksProvider,
|
|
416
38
|
Box,
|
|
@@ -437,12 +59,12 @@ export {
|
|
|
437
59
|
atoms,
|
|
438
60
|
classnames,
|
|
439
61
|
createAsChildTemplate,
|
|
62
|
+
getTheme,
|
|
440
63
|
makeComponentTheme,
|
|
441
64
|
makeTheme,
|
|
442
65
|
minMediaQuery,
|
|
66
|
+
setTheme,
|
|
443
67
|
style,
|
|
444
|
-
useComponentStyleDefaultProps,
|
|
445
|
-
useComponentStyles,
|
|
446
68
|
useIsomorphicLayoutEffect,
|
|
447
69
|
useKeyboard,
|
|
448
70
|
usePreventBodyScroll,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const lib_react_mergeProps_cjs = require("../react/mergeProps.cjs");
|
|
5
|
+
function createAsChildTemplate(defaultElement) {
|
|
6
|
+
const Tag = defaultElement;
|
|
7
|
+
const Template = ({
|
|
8
|
+
asChild,
|
|
9
|
+
children,
|
|
10
|
+
ref,
|
|
11
|
+
...rootProps
|
|
12
|
+
}) => {
|
|
13
|
+
if (!asChild) {
|
|
14
|
+
const tagProps = { ref, ...rootProps };
|
|
15
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...tagProps, children });
|
|
16
|
+
}
|
|
17
|
+
const childrenArray = react.Children.toArray(children);
|
|
18
|
+
const slotIndex = childrenArray.findIndex((child) => {
|
|
19
|
+
if (!react.isValidElement(child)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return child.type === Slot;
|
|
23
|
+
});
|
|
24
|
+
const slot = childrenArray[slotIndex];
|
|
25
|
+
if (!slot) {
|
|
26
|
+
if (process.env.NODE_ENV !== "production") {
|
|
27
|
+
console.error("Template: No Slot provided");
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (!isValidElementWithChildren(slot)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!react.isValidElement(slot.props.children)) {
|
|
35
|
+
if (process.env.NODE_ENV !== "production") {
|
|
36
|
+
if (react.Children.toArray(slot.props.children).length === 0) {
|
|
37
|
+
console.error("When using asChild, at least one child is required");
|
|
38
|
+
} else {
|
|
39
|
+
console.error("When using asChild, only one child is allowed");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (!isValidElementWithChildren(slot.props.children)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const nextChildren = [...childrenArray];
|
|
48
|
+
if (nextChildren.length === 1 && !slot.props.children.props.children) {
|
|
49
|
+
return react.cloneElement(
|
|
50
|
+
slot.props.children,
|
|
51
|
+
lib_react_mergeProps_cjs.mergeProps(rootProps, slot.props.children.props)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
nextChildren[slotIndex] = slot.props.children.props.children;
|
|
55
|
+
return react.cloneElement(
|
|
56
|
+
slot.props.children,
|
|
57
|
+
lib_react_mergeProps_cjs.mergeProps(rootProps, slot.props.children.props),
|
|
58
|
+
nextChildren
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
Template,
|
|
63
|
+
Slot
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function isValidElementWithChildren(child) {
|
|
67
|
+
return react.isValidElement(child) && !!child.props;
|
|
68
|
+
}
|
|
69
|
+
const Slot = ({ children }) => {
|
|
70
|
+
return children;
|
|
71
|
+
};
|
|
72
|
+
exports.createAsChildTemplate = createAsChildTemplate;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Children, isValidElement, cloneElement } from "react";
|
|
3
|
+
import { mergeProps } from "../react/mergeProps.mjs";
|
|
4
|
+
function createAsChildTemplate(defaultElement) {
|
|
5
|
+
const Tag = defaultElement;
|
|
6
|
+
const Template = ({
|
|
7
|
+
asChild,
|
|
8
|
+
children,
|
|
9
|
+
ref,
|
|
10
|
+
...rootProps
|
|
11
|
+
}) => {
|
|
12
|
+
if (!asChild) {
|
|
13
|
+
const tagProps = { ref, ...rootProps };
|
|
14
|
+
return /* @__PURE__ */ jsx(Tag, { ...tagProps, children });
|
|
15
|
+
}
|
|
16
|
+
const childrenArray = Children.toArray(children);
|
|
17
|
+
const slotIndex = childrenArray.findIndex((child) => {
|
|
18
|
+
if (!isValidElement(child)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return child.type === Slot;
|
|
22
|
+
});
|
|
23
|
+
const slot = childrenArray[slotIndex];
|
|
24
|
+
if (!slot) {
|
|
25
|
+
if (process.env.NODE_ENV !== "production") {
|
|
26
|
+
console.error("Template: No Slot provided");
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (!isValidElementWithChildren(slot)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!isValidElement(slot.props.children)) {
|
|
34
|
+
if (process.env.NODE_ENV !== "production") {
|
|
35
|
+
if (Children.toArray(slot.props.children).length === 0) {
|
|
36
|
+
console.error("When using asChild, at least one child is required");
|
|
37
|
+
} else {
|
|
38
|
+
console.error("When using asChild, only one child is allowed");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (!isValidElementWithChildren(slot.props.children)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const nextChildren = [...childrenArray];
|
|
47
|
+
if (nextChildren.length === 1 && !slot.props.children.props.children) {
|
|
48
|
+
return cloneElement(
|
|
49
|
+
slot.props.children,
|
|
50
|
+
mergeProps(rootProps, slot.props.children.props)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
nextChildren[slotIndex] = slot.props.children.props.children;
|
|
54
|
+
return cloneElement(
|
|
55
|
+
slot.props.children,
|
|
56
|
+
mergeProps(rootProps, slot.props.children.props),
|
|
57
|
+
nextChildren
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
Template,
|
|
62
|
+
Slot
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function isValidElementWithChildren(child) {
|
|
66
|
+
return isValidElement(child) && !!child.props;
|
|
67
|
+
}
|
|
68
|
+
const Slot = ({ children }) => {
|
|
69
|
+
return children;
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
createAsChildTemplate
|
|
73
|
+
};
|