@blockle/blocks 0.9.0 → 0.10.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/dist/index.cjs +3 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +4 -1
- package/dist/momotaro.chunk.d.ts +303 -267
- package/dist/reset.css.cjs +1 -1
- package/dist/reset.css.mjs +1 -1
- package/dist/styles/components/display/Divider/Divider.cjs +3 -3
- package/dist/styles/components/display/Divider/Divider.mjs +3 -3
- package/dist/styles/components/display/Divider/divider.css.cjs +1 -1
- package/dist/styles/components/display/Divider/divider.css.mjs +1 -1
- package/dist/styles/components/form/Button/Button.css.cjs +1 -1
- package/dist/styles/components/form/Button/Button.css.mjs +1 -1
- package/dist/styles/components/form/Checkbox/checkbox.css.cjs +1 -1
- package/dist/styles/components/form/Checkbox/checkbox.css.mjs +1 -1
- package/dist/styles/components/form/Input/input.css.cjs +1 -1
- package/dist/styles/components/form/Input/input.css.mjs +1 -1
- package/dist/styles/components/form/Radio/radio.css.cjs +1 -1
- package/dist/styles/components/form/Radio/radio.css.mjs +1 -1
- package/dist/styles/components/form/Select/select.css.cjs +1 -1
- package/dist/styles/components/form/Select/select.css.mjs +1 -1
- package/dist/styles/components/form/Slider/Slider.cjs +155 -0
- package/dist/styles/components/form/Slider/Slider.mjs +156 -0
- package/dist/styles/components/form/Slider/slider.css.cjs +73 -0
- package/dist/styles/components/form/Slider/slider.css.mjs +74 -0
- package/dist/styles/components/form/Switch/switch.css.cjs +1 -1
- package/dist/styles/components/form/Switch/switch.css.mjs +1 -1
- package/dist/styles/components/other/BlocksProvider/BlocksProvider.cjs +21 -1
- package/dist/styles/components/other/BlocksProvider/BlocksProvider.mjs +21 -1
- package/dist/styles/components/overlay/Dialog/Dialog.cjs +9 -0
- package/dist/styles/components/overlay/Dialog/Dialog.mjs +12 -3
- package/dist/styles/components/overlay/Dialog/dialog.css.cjs +1 -1
- package/dist/styles/components/overlay/Dialog/dialog.css.mjs +1 -1
- package/dist/styles/components/typography/Heading/heading.css.cjs +1 -1
- package/dist/styles/components/typography/Heading/heading.css.mjs +1 -1
- package/dist/styles/components/typography/Text/text.css.cjs +1 -1
- package/dist/styles/components/typography/Text/text.css.mjs +1 -1
- package/dist/styles/lib/css/atoms/sprinkles.css.cjs +1 -1
- package/dist/styles/lib/css/atoms/sprinkles.css.mjs +1 -1
- package/dist/styles/lib/css/layers/layers.css.cjs +1 -1
- package/dist/styles/lib/css/layers/layers.css.mjs +1 -1
- package/dist/styles/lib/theme/vars.css.cjs +1 -1
- package/dist/styles/lib/theme/vars.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/button.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/button.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/checkbox.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/checkbox.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/dialog.css.cjs +9 -8
- package/dist/styles/themes/momotaro/components/dialog.css.mjs +9 -8
- package/dist/styles/themes/momotaro/components/divider.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/divider.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/dropdown.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/dropdown.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/helpers.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/helpers.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/index.cjs +3 -1
- package/dist/styles/themes/momotaro/components/index.mjs +3 -1
- package/dist/styles/themes/momotaro/components/input.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/input.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/label.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/label.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/link.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/link.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/progress.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/progress.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/radio.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/radio.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/select.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/select.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/slider.css.cjs +65 -0
- package/dist/styles/themes/momotaro/components/slider.css.mjs +66 -0
- package/dist/styles/themes/momotaro/components/spinner.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/spinner.css.mjs +1 -1
- package/dist/styles/themes/momotaro/components/switch.css.cjs +1 -1
- package/dist/styles/themes/momotaro/components/switch.css.mjs +1 -1
- package/dist/styles/themes/momotaro/momotaro.css.cjs +1 -1
- package/dist/styles/themes/momotaro/momotaro.css.mjs +1 -1
- package/dist/styles/themes/momotaro/tokens.css.cjs +3 -3
- package/dist/styles/themes/momotaro/tokens.css.mjs +3 -3
- package/package.json +28 -28
package/dist/reset.css.cjs
CHANGED
package/dist/reset.css.mjs
CHANGED
|
@@ -6,11 +6,11 @@ const styles_lib_utils_atomProps_cjs = require("../../../lib/utils/atom-props.cj
|
|
|
6
6
|
const styles_lib_css_atoms_sprinkles_css_cjs = require("../../../lib/css/atoms/sprinkles.css.cjs");
|
|
7
7
|
const BlocksProviderContext = react.createContext(null);
|
|
8
8
|
const useTheme = () => {
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
9
|
+
const context = react.useContext(BlocksProviderContext);
|
|
10
|
+
if (!context) {
|
|
11
11
|
throw new Error("useTheme must be used within a BlocksProvider");
|
|
12
12
|
}
|
|
13
|
-
return theme;
|
|
13
|
+
return context.theme;
|
|
14
14
|
};
|
|
15
15
|
function useComponentStyles(name, props, useDefaultVariants = true) {
|
|
16
16
|
const { components } = useTheme();
|
|
@@ -5,11 +5,11 @@ import { getAtomsAndProps } from "../../../lib/utils/atom-props.mjs";
|
|
|
5
5
|
import { atoms } from "../../../lib/css/atoms/sprinkles.css.mjs";
|
|
6
6
|
const BlocksProviderContext = createContext(null);
|
|
7
7
|
const useTheme = () => {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
8
|
+
const context = useContext(BlocksProviderContext);
|
|
9
|
+
if (!context) {
|
|
10
10
|
throw new Error("useTheme must be used within a BlocksProvider");
|
|
11
11
|
}
|
|
12
|
-
return theme;
|
|
12
|
+
return context.theme;
|
|
13
13
|
};
|
|
14
14
|
function useComponentStyles(name, props, useDefaultVariants = true) {
|
|
15
15
|
const { components } = useTheme();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/display/Divider/divider.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/display/Divider/divider.css.ts", "@blockle/blocks");
|
|
6
6
|
const divider = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/display/Divider/divider.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/display/Divider/divider.css.ts", "@blockle/blocks");
|
|
5
5
|
const divider = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Button/Button.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Button/Button.css.ts", "@blockle/blocks");
|
|
6
6
|
const buttonReset = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Button/Button.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Button/Button.css.ts", "@blockle/blocks");
|
|
5
5
|
const buttonReset = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Checkbox/checkbox.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Checkbox/checkbox.css.ts", "@blockle/blocks");
|
|
6
6
|
const container = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Checkbox/checkbox.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Checkbox/checkbox.css.ts", "@blockle/blocks");
|
|
5
5
|
const container = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Input/input.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Input/input.css.ts", "@blockle/blocks");
|
|
6
6
|
const input = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Input/input.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Input/input.css.ts", "@blockle/blocks");
|
|
5
5
|
const input = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Radio/radio.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Radio/radio.css.ts", "@blockle/blocks");
|
|
6
6
|
const container = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Radio/radio.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Radio/radio.css.ts", "@blockle/blocks");
|
|
5
5
|
const container = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Select/select.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Select/select.css.ts", "@blockle/blocks");
|
|
6
6
|
const wrapper = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Select/select.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Select/select.css.ts", "@blockle/blocks");
|
|
5
5
|
const wrapper = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const react = require("react");
|
|
4
|
+
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
|
+
const styles_components_form_Slider_slider_css_cjs = require("./slider.css.cjs");
|
|
6
|
+
function getProgress(event, rect) {
|
|
7
|
+
const { clientX, clientY } = event;
|
|
8
|
+
const { width, height, left, top } = rect;
|
|
9
|
+
const x = (clientX - left) / width;
|
|
10
|
+
const y = (clientY - top) / height;
|
|
11
|
+
return [x, y];
|
|
12
|
+
}
|
|
13
|
+
function usePointerProgress({ container, orientation, onChange }) {
|
|
14
|
+
react.useEffect(() => {
|
|
15
|
+
const element = container.current;
|
|
16
|
+
function pointerdown(event) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
event.stopPropagation();
|
|
19
|
+
if (!element) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const containerRect = element.getBoundingClientRect();
|
|
23
|
+
const axisIndex = orientation === "horizontal" ? 0 : 1;
|
|
24
|
+
const progress = getProgress(event, containerRect);
|
|
25
|
+
onChange(progress[axisIndex]);
|
|
26
|
+
const pointermove = (event2) => {
|
|
27
|
+
event2.preventDefault();
|
|
28
|
+
const progress2 = getProgress(event2, containerRect);
|
|
29
|
+
onChange(progress2[axisIndex]);
|
|
30
|
+
};
|
|
31
|
+
const pointerup = () => {
|
|
32
|
+
document.removeEventListener("pointermove", pointermove);
|
|
33
|
+
document.removeEventListener("pointerup", pointerup);
|
|
34
|
+
};
|
|
35
|
+
document.addEventListener("pointermove", pointermove);
|
|
36
|
+
document.addEventListener("pointerup", pointerup);
|
|
37
|
+
}
|
|
38
|
+
if (!element) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
element.addEventListener("pointerdown", pointerdown);
|
|
42
|
+
return () => {
|
|
43
|
+
element.removeEventListener("pointerdown", pointerdown);
|
|
44
|
+
};
|
|
45
|
+
}, [container, onChange, orientation]);
|
|
46
|
+
}
|
|
47
|
+
function getBoundValue(newValue, min, max, step) {
|
|
48
|
+
let value = Math.round(newValue / step) * step;
|
|
49
|
+
value = Math.max(min, Math.min(max, value));
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
const Slider = ({
|
|
53
|
+
min = 0,
|
|
54
|
+
max = 100,
|
|
55
|
+
step = 1,
|
|
56
|
+
orientation = "horizontal",
|
|
57
|
+
defaultValue = 0,
|
|
58
|
+
onChange,
|
|
59
|
+
value,
|
|
60
|
+
name,
|
|
61
|
+
size,
|
|
62
|
+
colorScheme,
|
|
63
|
+
...restProps
|
|
64
|
+
}) => {
|
|
65
|
+
const [internValue, setInternValue] = react.useState(
|
|
66
|
+
getBoundValue(value ?? defaultValue, min, max, step)
|
|
67
|
+
);
|
|
68
|
+
const baseClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { base: true, variants: { size, colorScheme } });
|
|
69
|
+
const trackClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { track: true }, false);
|
|
70
|
+
const filledTrackClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { filledTrack: true }, false);
|
|
71
|
+
const thumbClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { thumb: true }, false);
|
|
72
|
+
const containerRef = react.useRef(null);
|
|
73
|
+
react.useEffect(() => {
|
|
74
|
+
if (value !== void 0) {
|
|
75
|
+
setInternValue(getBoundValue(value, min, max, step));
|
|
76
|
+
}
|
|
77
|
+
}, [value, min, max, step]);
|
|
78
|
+
react.useEffect(() => {
|
|
79
|
+
if (onChange && internValue !== value) {
|
|
80
|
+
onChange(internValue);
|
|
81
|
+
}
|
|
82
|
+
}, [internValue, onChange, value]);
|
|
83
|
+
usePointerProgress({
|
|
84
|
+
container: containerRef,
|
|
85
|
+
orientation,
|
|
86
|
+
onChange(progress) {
|
|
87
|
+
if (orientation === "vertical") {
|
|
88
|
+
progress = 1 - progress;
|
|
89
|
+
}
|
|
90
|
+
setInternValue(getBoundValue(max * progress, min, max, step));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const onKeyDown = react.useCallback(
|
|
94
|
+
(event) => {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
const specialKey = ["PageUp", "PageDown"];
|
|
98
|
+
const stepModifier = event.shiftKey || specialKey.includes(event.key) ? (max - min) / 10 : step;
|
|
99
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowDown" || event.key === "PageDown") {
|
|
100
|
+
return setInternValue((value2) => getBoundValue(value2 - stepModifier, min, max, step));
|
|
101
|
+
}
|
|
102
|
+
if (event.key === "ArrowRight" || event.key === "ArrowUp" || event.key === "PageUp") {
|
|
103
|
+
return setInternValue((value2) => getBoundValue(value2 + stepModifier, min, max, step));
|
|
104
|
+
}
|
|
105
|
+
if (event.key === "Home") {
|
|
106
|
+
return setInternValue(min);
|
|
107
|
+
}
|
|
108
|
+
if (event.key === "End") {
|
|
109
|
+
return setInternValue(max);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[max, min, step]
|
|
113
|
+
);
|
|
114
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
ref: containerRef,
|
|
118
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(
|
|
119
|
+
styles_components_form_Slider_slider_css_cjs.container,
|
|
120
|
+
orientation === "vertical" ? styles_components_form_Slider_slider_css_cjs.containerVertical : "",
|
|
121
|
+
baseClass
|
|
122
|
+
),
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Slider_slider_css_cjs.track, trackClass), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Slider_slider_css_cjs.filledTrack, filledTrackClass),
|
|
128
|
+
style: {
|
|
129
|
+
inlineSize: `${internValue / max * 100}%`
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
) }),
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
134
|
+
"div",
|
|
135
|
+
{
|
|
136
|
+
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Slider_slider_css_cjs.thumb, thumbClass),
|
|
137
|
+
tabIndex: 0,
|
|
138
|
+
role: "slider",
|
|
139
|
+
"aria-valuemin": min,
|
|
140
|
+
"aria-valuemax": max,
|
|
141
|
+
"aria-valuenow": internValue,
|
|
142
|
+
"aria-orientation": orientation,
|
|
143
|
+
style: {
|
|
144
|
+
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${internValue / max * 100}%`
|
|
145
|
+
},
|
|
146
|
+
onKeyDown,
|
|
147
|
+
...restProps
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value: internValue })
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
exports.Slider = Slider;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, useRef, useCallback } from "react";
|
|
3
|
+
import { useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
|
+
import { containerVertical, container, track, filledTrack, thumb } from "./slider.css.mjs";
|
|
5
|
+
function getProgress(event, rect) {
|
|
6
|
+
const { clientX, clientY } = event;
|
|
7
|
+
const { width, height, left, top } = rect;
|
|
8
|
+
const x = (clientX - left) / width;
|
|
9
|
+
const y = (clientY - top) / height;
|
|
10
|
+
return [x, y];
|
|
11
|
+
}
|
|
12
|
+
function usePointerProgress({ container: container2, orientation, onChange }) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const element = container2.current;
|
|
15
|
+
function pointerdown(event) {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
event.stopPropagation();
|
|
18
|
+
if (!element) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const containerRect = element.getBoundingClientRect();
|
|
22
|
+
const axisIndex = orientation === "horizontal" ? 0 : 1;
|
|
23
|
+
const progress = getProgress(event, containerRect);
|
|
24
|
+
onChange(progress[axisIndex]);
|
|
25
|
+
const pointermove = (event2) => {
|
|
26
|
+
event2.preventDefault();
|
|
27
|
+
const progress2 = getProgress(event2, containerRect);
|
|
28
|
+
onChange(progress2[axisIndex]);
|
|
29
|
+
};
|
|
30
|
+
const pointerup = () => {
|
|
31
|
+
document.removeEventListener("pointermove", pointermove);
|
|
32
|
+
document.removeEventListener("pointerup", pointerup);
|
|
33
|
+
};
|
|
34
|
+
document.addEventListener("pointermove", pointermove);
|
|
35
|
+
document.addEventListener("pointerup", pointerup);
|
|
36
|
+
}
|
|
37
|
+
if (!element) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
element.addEventListener("pointerdown", pointerdown);
|
|
41
|
+
return () => {
|
|
42
|
+
element.removeEventListener("pointerdown", pointerdown);
|
|
43
|
+
};
|
|
44
|
+
}, [container2, onChange, orientation]);
|
|
45
|
+
}
|
|
46
|
+
function getBoundValue(newValue, min, max, step) {
|
|
47
|
+
let value = Math.round(newValue / step) * step;
|
|
48
|
+
value = Math.max(min, Math.min(max, value));
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
const Slider = ({
|
|
52
|
+
min = 0,
|
|
53
|
+
max = 100,
|
|
54
|
+
step = 1,
|
|
55
|
+
orientation = "horizontal",
|
|
56
|
+
defaultValue = 0,
|
|
57
|
+
onChange,
|
|
58
|
+
value,
|
|
59
|
+
name,
|
|
60
|
+
size,
|
|
61
|
+
colorScheme,
|
|
62
|
+
...restProps
|
|
63
|
+
}) => {
|
|
64
|
+
const [internValue, setInternValue] = useState(
|
|
65
|
+
getBoundValue(value ?? defaultValue, min, max, step)
|
|
66
|
+
);
|
|
67
|
+
const baseClass = useComponentStyles("slider", { base: true, variants: { size, colorScheme } });
|
|
68
|
+
const trackClass = useComponentStyles("slider", { track: true }, false);
|
|
69
|
+
const filledTrackClass = useComponentStyles("slider", { filledTrack: true }, false);
|
|
70
|
+
const thumbClass = useComponentStyles("slider", { thumb: true }, false);
|
|
71
|
+
const containerRef = useRef(null);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (value !== void 0) {
|
|
74
|
+
setInternValue(getBoundValue(value, min, max, step));
|
|
75
|
+
}
|
|
76
|
+
}, [value, min, max, step]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (onChange && internValue !== value) {
|
|
79
|
+
onChange(internValue);
|
|
80
|
+
}
|
|
81
|
+
}, [internValue, onChange, value]);
|
|
82
|
+
usePointerProgress({
|
|
83
|
+
container: containerRef,
|
|
84
|
+
orientation,
|
|
85
|
+
onChange(progress) {
|
|
86
|
+
if (orientation === "vertical") {
|
|
87
|
+
progress = 1 - progress;
|
|
88
|
+
}
|
|
89
|
+
setInternValue(getBoundValue(max * progress, min, max, step));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const onKeyDown = useCallback(
|
|
93
|
+
(event) => {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
const specialKey = ["PageUp", "PageDown"];
|
|
97
|
+
const stepModifier = event.shiftKey || specialKey.includes(event.key) ? (max - min) / 10 : step;
|
|
98
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowDown" || event.key === "PageDown") {
|
|
99
|
+
return setInternValue((value2) => getBoundValue(value2 - stepModifier, min, max, step));
|
|
100
|
+
}
|
|
101
|
+
if (event.key === "ArrowRight" || event.key === "ArrowUp" || event.key === "PageUp") {
|
|
102
|
+
return setInternValue((value2) => getBoundValue(value2 + stepModifier, min, max, step));
|
|
103
|
+
}
|
|
104
|
+
if (event.key === "Home") {
|
|
105
|
+
return setInternValue(min);
|
|
106
|
+
}
|
|
107
|
+
if (event.key === "End") {
|
|
108
|
+
return setInternValue(max);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[max, min, step]
|
|
112
|
+
);
|
|
113
|
+
return /* @__PURE__ */ jsxs(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
ref: containerRef,
|
|
117
|
+
className: classnames(
|
|
118
|
+
container,
|
|
119
|
+
orientation === "vertical" ? containerVertical : "",
|
|
120
|
+
baseClass
|
|
121
|
+
),
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsx("div", { className: classnames(track, trackClass), children: /* @__PURE__ */ jsx(
|
|
124
|
+
"div",
|
|
125
|
+
{
|
|
126
|
+
className: classnames(filledTrack, filledTrackClass),
|
|
127
|
+
style: {
|
|
128
|
+
inlineSize: `${internValue / max * 100}%`
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
) }),
|
|
132
|
+
/* @__PURE__ */ jsx(
|
|
133
|
+
"div",
|
|
134
|
+
{
|
|
135
|
+
className: classnames(thumb, thumbClass),
|
|
136
|
+
tabIndex: 0,
|
|
137
|
+
role: "slider",
|
|
138
|
+
"aria-valuemin": min,
|
|
139
|
+
"aria-valuemax": max,
|
|
140
|
+
"aria-valuenow": internValue,
|
|
141
|
+
"aria-orientation": orientation,
|
|
142
|
+
style: {
|
|
143
|
+
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${internValue / max * 100}%`
|
|
144
|
+
},
|
|
145
|
+
onKeyDown,
|
|
146
|
+
...restProps
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ jsx("input", { type: "hidden", name, value: internValue })
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
export {
|
|
155
|
+
Slider
|
|
156
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
|
+
const css = require("@vanilla-extract/css");
|
|
4
|
+
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Slider/slider.css.ts", "@blockle/blocks");
|
|
6
|
+
const container = css.style({
|
|
7
|
+
"@layer": {
|
|
8
|
+
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
9
|
+
position: "relative",
|
|
10
|
+
writingMode: "horizontal-tb"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}, "container");
|
|
14
|
+
const containerVertical = css.style({
|
|
15
|
+
"@layer": {
|
|
16
|
+
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
17
|
+
writingMode: "vertical-lr"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}, "containerVertical");
|
|
21
|
+
const track = css.style({
|
|
22
|
+
"@layer": {
|
|
23
|
+
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
24
|
+
cursor: "pointer",
|
|
25
|
+
position: "absolute",
|
|
26
|
+
inlineSize: "100%",
|
|
27
|
+
insetBlockStart: "50%",
|
|
28
|
+
transform: "translateY(-50%)",
|
|
29
|
+
selectors: {
|
|
30
|
+
[`${containerVertical} &`]: {
|
|
31
|
+
transform: "translateX(-50%)"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, "track");
|
|
37
|
+
const filledTrack = css.style({
|
|
38
|
+
"@layer": {
|
|
39
|
+
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
40
|
+
position: "absolute",
|
|
41
|
+
blockSize: "100%",
|
|
42
|
+
borderRadius: "inherit",
|
|
43
|
+
selectors: {
|
|
44
|
+
[`${containerVertical} &`]: {
|
|
45
|
+
insetInlineEnd: "0%"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, "filledTrack");
|
|
51
|
+
const thumb = css.style({
|
|
52
|
+
"@layer": {
|
|
53
|
+
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
54
|
+
cursor: "pointer",
|
|
55
|
+
position: "absolute",
|
|
56
|
+
blockSize: "100%",
|
|
57
|
+
insetBlockStart: "50%",
|
|
58
|
+
transform: "translate(-50%, -50%)",
|
|
59
|
+
touchAction: "none",
|
|
60
|
+
selectors: {
|
|
61
|
+
[`${containerVertical} &`]: {
|
|
62
|
+
transform: "translate(-50%, 50%)"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, "thumb");
|
|
68
|
+
fileScope.endFileScope();
|
|
69
|
+
exports.container = container;
|
|
70
|
+
exports.containerVertical = containerVertical;
|
|
71
|
+
exports.filledTrack = filledTrack;
|
|
72
|
+
exports.thumb = thumb;
|
|
73
|
+
exports.track = track;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
|
+
import { style } from "@vanilla-extract/css";
|
|
3
|
+
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
+
setFileScope("src/components/form/Slider/slider.css.ts", "@blockle/blocks");
|
|
5
|
+
const container = style({
|
|
6
|
+
"@layer": {
|
|
7
|
+
[blocksLayer]: {
|
|
8
|
+
position: "relative",
|
|
9
|
+
writingMode: "horizontal-tb"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}, "container");
|
|
13
|
+
const containerVertical = style({
|
|
14
|
+
"@layer": {
|
|
15
|
+
[blocksLayer]: {
|
|
16
|
+
writingMode: "vertical-lr"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, "containerVertical");
|
|
20
|
+
const track = style({
|
|
21
|
+
"@layer": {
|
|
22
|
+
[blocksLayer]: {
|
|
23
|
+
cursor: "pointer",
|
|
24
|
+
position: "absolute",
|
|
25
|
+
inlineSize: "100%",
|
|
26
|
+
insetBlockStart: "50%",
|
|
27
|
+
transform: "translateY(-50%)",
|
|
28
|
+
selectors: {
|
|
29
|
+
[`${containerVertical} &`]: {
|
|
30
|
+
transform: "translateX(-50%)"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, "track");
|
|
36
|
+
const filledTrack = style({
|
|
37
|
+
"@layer": {
|
|
38
|
+
[blocksLayer]: {
|
|
39
|
+
position: "absolute",
|
|
40
|
+
blockSize: "100%",
|
|
41
|
+
borderRadius: "inherit",
|
|
42
|
+
selectors: {
|
|
43
|
+
[`${containerVertical} &`]: {
|
|
44
|
+
insetInlineEnd: "0%"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, "filledTrack");
|
|
50
|
+
const thumb = style({
|
|
51
|
+
"@layer": {
|
|
52
|
+
[blocksLayer]: {
|
|
53
|
+
cursor: "pointer",
|
|
54
|
+
position: "absolute",
|
|
55
|
+
blockSize: "100%",
|
|
56
|
+
insetBlockStart: "50%",
|
|
57
|
+
transform: "translate(-50%, -50%)",
|
|
58
|
+
touchAction: "none",
|
|
59
|
+
selectors: {
|
|
60
|
+
[`${containerVertical} &`]: {
|
|
61
|
+
transform: "translate(-50%, 50%)"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, "thumb");
|
|
67
|
+
endFileScope();
|
|
68
|
+
export {
|
|
69
|
+
container,
|
|
70
|
+
containerVertical,
|
|
71
|
+
filledTrack,
|
|
72
|
+
thumb,
|
|
73
|
+
track
|
|
74
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
3
|
const css = require("@vanilla-extract/css");
|
|
4
4
|
const styles_lib_css_layers_layers_css_cjs = require("../../../lib/css/layers/layers.css.cjs");
|
|
5
|
-
fileScope.setFileScope("src/components/form/Switch/switch.css.ts", "blocks");
|
|
5
|
+
fileScope.setFileScope("src/components/form/Switch/switch.css.ts", "@blockle/blocks");
|
|
6
6
|
const container = css.style({
|
|
7
7
|
"@layer": {
|
|
8
8
|
[styles_lib_css_layers_layers_css_cjs.blocksLayer]: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
2
|
import { style } from "@vanilla-extract/css";
|
|
3
3
|
import { blocksLayer } from "../../../lib/css/layers/layers.css.mjs";
|
|
4
|
-
setFileScope("src/components/form/Switch/switch.css.ts", "blocks");
|
|
4
|
+
setFileScope("src/components/form/Switch/switch.css.ts", "@blockle/blocks");
|
|
5
5
|
const container = style({
|
|
6
6
|
"@layer": {
|
|
7
7
|
[blocksLayer]: {
|