@blockle/blocks 0.14.3 → 0.15.2
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 +4 -4
- package/dist/index.mjs +4 -4
- package/dist/momotaro.chunk.d.ts +8 -7
- package/dist/styles/components/form/Input/Input.cjs +2 -2
- package/dist/styles/components/form/Input/Input.mjs +2 -2
- package/dist/styles/components/form/Slider/Slider.cjs +76 -31
- package/dist/styles/components/form/Slider/Slider.mjs +77 -32
- package/dist/styles/components/form/Slider/slider.css.cjs +1 -0
- package/dist/styles/components/form/Slider/slider.css.mjs +1 -0
- package/dist/styles/lib/css/utils/cssUtils.cjs +5 -0
- package/dist/styles/lib/css/utils/cssUtils.mjs +6 -0
- package/dist/styles/themes/momotaro/components/dialog.css.cjs +11 -11
- package/dist/styles/themes/momotaro/components/dialog.css.mjs +11 -11
- package/dist/styles/themes/momotaro/components/slider.css.cjs +26 -2
- package/dist/styles/themes/momotaro/components/slider.css.mjs +26 -2
- package/dist/styles/themes/momotaro/tokens.css.cjs +11 -10
- package/dist/styles/themes/momotaro/tokens.css.mjs +11 -10
- package/package.json +16 -15
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,8 @@ const reactDom = require("react-dom");
|
|
|
21
21
|
const styles_components_overlay_Dialog_Dialog_cjs = require("./styles/components/overlay/Dialog/Dialog.cjs");
|
|
22
22
|
const styles_components_typography_Heading_Heading_cjs = require("./styles/components/typography/Heading/Heading.cjs");
|
|
23
23
|
const styles_components_typography_Text_Text_cjs = require("./styles/components/typography/Text/Text.cjs");
|
|
24
|
-
const Progress = react.forwardRef(function Progress2({
|
|
24
|
+
const Progress = react.forwardRef(function Progress2({ className, indeterminate, max = 100, value = 0, ...restProps }, ref) {
|
|
25
|
+
const progress = value / max * 100;
|
|
25
26
|
const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles(
|
|
26
27
|
"progress",
|
|
27
28
|
{
|
|
@@ -31,10 +32,9 @@ const Progress = react.forwardRef(function Progress2({ value, max = 100, classNa
|
|
|
31
32
|
);
|
|
32
33
|
const barClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles(
|
|
33
34
|
"progress",
|
|
34
|
-
{ bar: true, variants: { indeterminate
|
|
35
|
+
{ bar: true, variants: { indeterminate } },
|
|
35
36
|
false
|
|
36
37
|
);
|
|
37
|
-
const progress = value === void 0 ? 0 : value / max * 100;
|
|
38
38
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
39
39
|
styles_components_display_Divider_Divider_cjs.Box,
|
|
40
40
|
{
|
|
@@ -53,7 +53,7 @@ const Progress = react.forwardRef(function Progress2({ value, max = 100, classNa
|
|
|
53
53
|
backgroundColor: "currentColor",
|
|
54
54
|
inlineSize: "full",
|
|
55
55
|
blockSize: "full",
|
|
56
|
-
style: { transform:
|
|
56
|
+
style: { transform: indeterminate ? void 0 : `translateX(-${100 - progress}%)` }
|
|
57
57
|
}
|
|
58
58
|
)
|
|
59
59
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,8 @@ import { useIsomorphicLayoutEffect, hasAnimationDuration, useKeyboard, useClickO
|
|
|
23
23
|
import { Dialog, usePreventBodyScroll } from "./styles/components/overlay/Dialog/Dialog.mjs";
|
|
24
24
|
import { Heading } from "./styles/components/typography/Heading/Heading.mjs";
|
|
25
25
|
import { Text } from "./styles/components/typography/Text/Text.mjs";
|
|
26
|
-
const Progress = forwardRef(function Progress2({
|
|
26
|
+
const Progress = forwardRef(function Progress2({ className, indeterminate, max = 100, value = 0, ...restProps }, ref) {
|
|
27
|
+
const progress = value / max * 100;
|
|
27
28
|
const containerClassName = useComponentStyles(
|
|
28
29
|
"progress",
|
|
29
30
|
{
|
|
@@ -33,10 +34,9 @@ const Progress = forwardRef(function Progress2({ value, max = 100, className, ..
|
|
|
33
34
|
);
|
|
34
35
|
const barClassName = useComponentStyles(
|
|
35
36
|
"progress",
|
|
36
|
-
{ bar: true, variants: { indeterminate
|
|
37
|
+
{ bar: true, variants: { indeterminate } },
|
|
37
38
|
false
|
|
38
39
|
);
|
|
39
|
-
const progress = value === void 0 ? 0 : value / max * 100;
|
|
40
40
|
return /* @__PURE__ */ jsx(
|
|
41
41
|
Box,
|
|
42
42
|
{
|
|
@@ -55,7 +55,7 @@ const Progress = forwardRef(function Progress2({ value, max = 100, className, ..
|
|
|
55
55
|
backgroundColor: "currentColor",
|
|
56
56
|
inlineSize: "full",
|
|
57
57
|
blockSize: "full",
|
|
58
|
-
style: { transform:
|
|
58
|
+
style: { transform: indeterminate ? void 0 : `translateX(-${100 - progress}%)` }
|
|
59
59
|
}
|
|
60
60
|
)
|
|
61
61
|
}
|
package/dist/momotaro.chunk.d.ts
CHANGED
|
@@ -394,6 +394,7 @@ type SliderTheme = {
|
|
|
394
394
|
variants: {
|
|
395
395
|
size: 'small' | 'medium' | 'large';
|
|
396
396
|
colorScheme: 'primary' | 'secondary';
|
|
397
|
+
disabled: boolean;
|
|
397
398
|
};
|
|
398
399
|
};
|
|
399
400
|
type TooltipTheme = {
|
|
@@ -608,14 +609,14 @@ declare const Divider: React.FC<DividerProps>;
|
|
|
608
609
|
|
|
609
610
|
type ProgressProps = {
|
|
610
611
|
/**
|
|
611
|
-
* The value of the progress bar, between 0 and 100.
|
|
612
|
-
* If undefined, the progress bar will be indeterminate.
|
|
612
|
+
* The value of the progress bar, between 0 and max=100.
|
|
613
613
|
*/
|
|
614
|
-
|
|
615
|
-
max?: number;
|
|
614
|
+
'aria-labelledby'?: string;
|
|
616
615
|
className?: string;
|
|
616
|
+
indeterminate?: boolean;
|
|
617
|
+
max?: number;
|
|
617
618
|
style?: React.CSSProperties;
|
|
618
|
-
|
|
619
|
+
value?: number;
|
|
619
620
|
};
|
|
620
621
|
declare const Progress: react.ForwardRefExoticComponent<ProgressProps & react.RefAttributes<HTMLProgressElement>>;
|
|
621
622
|
|
|
@@ -677,7 +678,6 @@ type InputProps = {
|
|
|
677
678
|
type?: OptionalLiteral<'email' | 'number' | 'password' | 'tel' | 'text' | 'url'>;
|
|
678
679
|
startSlot?: React.ReactNode;
|
|
679
680
|
endSlot?: React.ReactNode;
|
|
680
|
-
label: string;
|
|
681
681
|
} & Omit<HTMLElementProps<HTMLInputElement>, 'type'>;
|
|
682
682
|
declare const Input: react.ForwardRefExoticComponent<{
|
|
683
683
|
className?: string;
|
|
@@ -685,7 +685,6 @@ declare const Input: react.ForwardRefExoticComponent<{
|
|
|
685
685
|
type?: OptionalLiteral<"email" | "number" | "password" | "tel" | "text" | "url">;
|
|
686
686
|
startSlot?: React.ReactNode;
|
|
687
687
|
endSlot?: React.ReactNode;
|
|
688
|
-
label: string;
|
|
689
688
|
} & Omit<HTMLElementProps<HTMLInputElement>, "type"> & react.RefAttributes<HTMLInputElement>>;
|
|
690
689
|
|
|
691
690
|
type LabelProps = {
|
|
@@ -740,6 +739,8 @@ type SliderProps = {
|
|
|
740
739
|
'aria-label'?: string;
|
|
741
740
|
size: SliderTheme['variants']['size'];
|
|
742
741
|
colorScheme: SliderTheme['variants']['colorScheme'];
|
|
742
|
+
disabled?: boolean;
|
|
743
|
+
precision?: number;
|
|
743
744
|
};
|
|
744
745
|
declare const Slider: react__default.FC<SliderProps>;
|
|
745
746
|
|
|
@@ -3,7 +3,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const react = require("react");
|
|
4
4
|
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
5
|
const styles_components_form_Input_input_css_cjs = require("./input.css.cjs");
|
|
6
|
-
const Input = react.forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot,
|
|
6
|
+
const Input = react.forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, placeholder, ...restProps }, ref) {
|
|
7
7
|
const id = react.useId();
|
|
8
8
|
const containerClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("input", { container: true }, false);
|
|
9
9
|
const inputClassName = styles_components_display_Divider_Divider_cjs.useComponentStyles("input", { input: true });
|
|
@@ -16,7 +16,7 @@ const Input = react.forwardRef(function Input2({ className, name, type = "text",
|
|
|
16
16
|
ref,
|
|
17
17
|
name,
|
|
18
18
|
type,
|
|
19
|
-
placeholder
|
|
19
|
+
placeholder,
|
|
20
20
|
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Input_input_css_cjs.input, inputClassName),
|
|
21
21
|
...restProps
|
|
22
22
|
}
|
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef, useId } from "react";
|
|
3
3
|
import { useComponentStyles, Box, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
4
|
import { input } from "./input.css.mjs";
|
|
5
|
-
const Input = forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot,
|
|
5
|
+
const Input = forwardRef(function Input2({ className, name, type = "text", startSlot, endSlot, placeholder, ...restProps }, ref) {
|
|
6
6
|
const id = useId();
|
|
7
7
|
const containerClassName = useComponentStyles("input", { container: true }, false);
|
|
8
8
|
const inputClassName = useComponentStyles("input", { input: true });
|
|
@@ -15,7 +15,7 @@ const Input = forwardRef(function Input2({ className, name, type = "text", start
|
|
|
15
15
|
ref,
|
|
16
16
|
name,
|
|
17
17
|
type,
|
|
18
|
-
placeholder
|
|
18
|
+
placeholder,
|
|
19
19
|
className: classnames(input, inputClassName),
|
|
20
20
|
...restProps
|
|
21
21
|
}
|
|
@@ -3,6 +3,43 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const react = require("react");
|
|
4
4
|
const styles_components_display_Divider_Divider_cjs = require("../../display/Divider/Divider.cjs");
|
|
5
5
|
const styles_components_form_Slider_slider_css_cjs = require("./slider.css.cjs");
|
|
6
|
+
function useControlledValue({
|
|
7
|
+
defaultValue,
|
|
8
|
+
value,
|
|
9
|
+
onChange,
|
|
10
|
+
transformValue
|
|
11
|
+
}) {
|
|
12
|
+
const [internValue, setInternValue] = react.useState(defaultValue);
|
|
13
|
+
const currentValue = (onChange ? value : internValue) ?? defaultValue;
|
|
14
|
+
const setValue = react.useCallback(
|
|
15
|
+
function setValue2(value2) {
|
|
16
|
+
const nextValue = transformValue ? transformValue(value2) : value2;
|
|
17
|
+
if (onChange) {
|
|
18
|
+
onChange(nextValue);
|
|
19
|
+
} else {
|
|
20
|
+
setInternValue(nextValue);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[onChange, transformValue]
|
|
24
|
+
);
|
|
25
|
+
if (process.env.NODE_ENV !== "production") {
|
|
26
|
+
react.useEffect(() => {
|
|
27
|
+
if (onChange && value === void 0) {
|
|
28
|
+
console.error("Slider is in controlled mode but no value is provided");
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
}
|
|
32
|
+
return [currentValue, setValue];
|
|
33
|
+
}
|
|
34
|
+
function roundToPrecision(value, precision) {
|
|
35
|
+
const factor = 10 ** precision;
|
|
36
|
+
return Math.round(value * factor) / factor;
|
|
37
|
+
}
|
|
38
|
+
function getBoundValue(newValue, min, max, step) {
|
|
39
|
+
let value = Math.round(newValue / step) * step;
|
|
40
|
+
value = Math.max(min, Math.min(max, value));
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
6
43
|
function getProgress(event, rect) {
|
|
7
44
|
const { clientX, clientY } = event;
|
|
8
45
|
const { width, height, left, top } = rect;
|
|
@@ -44,11 +81,18 @@ function usePointerProgress({ container, orientation, onChange }) {
|
|
|
44
81
|
};
|
|
45
82
|
}, [container, onChange, orientation]);
|
|
46
83
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
const usableKeys = /* @__PURE__ */ new Set([
|
|
85
|
+
"ArrowLeft",
|
|
86
|
+
"ArrowRight",
|
|
87
|
+
"ArrowUp",
|
|
88
|
+
"ArrowDown",
|
|
89
|
+
"Home",
|
|
90
|
+
"End",
|
|
91
|
+
"PageUp",
|
|
92
|
+
"PageDown",
|
|
93
|
+
"Home",
|
|
94
|
+
"End"
|
|
95
|
+
]);
|
|
52
96
|
const Slider = ({
|
|
53
97
|
min = 0,
|
|
54
98
|
max = 100,
|
|
@@ -60,26 +104,24 @@ const Slider = ({
|
|
|
60
104
|
name,
|
|
61
105
|
size,
|
|
62
106
|
colorScheme,
|
|
107
|
+
disabled,
|
|
108
|
+
precision = 2,
|
|
63
109
|
...restProps
|
|
64
110
|
}) => {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
111
|
+
const baseClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", {
|
|
112
|
+
base: true,
|
|
113
|
+
variants: { size, colorScheme, disabled }
|
|
114
|
+
});
|
|
69
115
|
const trackClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { track: true }, false);
|
|
70
116
|
const filledTrackClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { filledTrack: true }, false);
|
|
71
117
|
const thumbClass = styles_components_display_Divider_Divider_cjs.useComponentStyles("slider", { thumb: true }, false);
|
|
72
118
|
const containerRef = react.useRef(null);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (onChange && internValue !== value) {
|
|
80
|
-
onChange(internValue);
|
|
81
|
-
}
|
|
82
|
-
}, [internValue, onChange, value]);
|
|
119
|
+
const [currentValue, setValue] = useControlledValue({
|
|
120
|
+
defaultValue,
|
|
121
|
+
value,
|
|
122
|
+
onChange,
|
|
123
|
+
transformValue: (value2) => roundToPrecision(getBoundValue(value2, min, max, step), precision)
|
|
124
|
+
});
|
|
83
125
|
usePointerProgress({
|
|
84
126
|
container: containerRef,
|
|
85
127
|
orientation,
|
|
@@ -87,29 +129,32 @@ const Slider = ({
|
|
|
87
129
|
if (orientation === "vertical") {
|
|
88
130
|
progress = 1 - progress;
|
|
89
131
|
}
|
|
90
|
-
|
|
132
|
+
setValue(max * progress);
|
|
91
133
|
}
|
|
92
134
|
});
|
|
93
135
|
const onKeyDown = react.useCallback(
|
|
94
136
|
(event) => {
|
|
137
|
+
if (!usableKeys.has(event.key)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
95
140
|
event.preventDefault();
|
|
96
141
|
event.stopPropagation();
|
|
97
142
|
const specialKey = ["PageUp", "PageDown"];
|
|
98
143
|
const stepModifier = event.shiftKey || specialKey.includes(event.key) ? (max - min) / 10 : step;
|
|
99
144
|
if (event.key === "ArrowLeft" || event.key === "ArrowDown" || event.key === "PageDown") {
|
|
100
|
-
return
|
|
145
|
+
return setValue(currentValue - stepModifier);
|
|
101
146
|
}
|
|
102
147
|
if (event.key === "ArrowRight" || event.key === "ArrowUp" || event.key === "PageUp") {
|
|
103
|
-
return
|
|
148
|
+
return setValue(currentValue + stepModifier);
|
|
104
149
|
}
|
|
105
150
|
if (event.key === "Home") {
|
|
106
|
-
return
|
|
151
|
+
return setValue(min);
|
|
107
152
|
}
|
|
108
153
|
if (event.key === "End") {
|
|
109
|
-
return
|
|
154
|
+
return setValue(max);
|
|
110
155
|
}
|
|
111
156
|
},
|
|
112
|
-
[max, min, step]
|
|
157
|
+
[max, min, step, setValue, currentValue]
|
|
113
158
|
);
|
|
114
159
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
115
160
|
"div",
|
|
@@ -126,28 +171,28 @@ const Slider = ({
|
|
|
126
171
|
{
|
|
127
172
|
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Slider_slider_css_cjs.filledTrack, filledTrackClass),
|
|
128
173
|
style: {
|
|
129
|
-
inlineSize: `${
|
|
174
|
+
inlineSize: `${currentValue / max * 100}%`
|
|
130
175
|
}
|
|
131
176
|
}
|
|
132
177
|
) }),
|
|
133
178
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
134
|
-
"
|
|
179
|
+
"button",
|
|
135
180
|
{
|
|
181
|
+
type: "button",
|
|
136
182
|
className: styles_components_display_Divider_Divider_cjs.classnames(styles_components_form_Slider_slider_css_cjs.thumb, thumbClass),
|
|
137
|
-
tabIndex: 0,
|
|
138
183
|
role: "slider",
|
|
139
184
|
"aria-valuemin": min,
|
|
140
185
|
"aria-valuemax": max,
|
|
141
|
-
"aria-valuenow":
|
|
186
|
+
"aria-valuenow": currentValue,
|
|
142
187
|
"aria-orientation": orientation,
|
|
143
188
|
style: {
|
|
144
|
-
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${
|
|
189
|
+
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${currentValue / max * 100}%`
|
|
145
190
|
},
|
|
146
191
|
onKeyDown,
|
|
147
192
|
...restProps
|
|
148
193
|
}
|
|
149
194
|
),
|
|
150
|
-
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value:
|
|
195
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", disabled, name, value: currentValue })
|
|
151
196
|
]
|
|
152
197
|
}
|
|
153
198
|
);
|
|
@@ -1,7 +1,44 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useState, useCallback, useEffect, useRef } from "react";
|
|
3
3
|
import { useComponentStyles, classnames } from "../../display/Divider/Divider.mjs";
|
|
4
4
|
import { containerVertical, container, track, filledTrack, thumb } from "./slider.css.mjs";
|
|
5
|
+
function useControlledValue({
|
|
6
|
+
defaultValue,
|
|
7
|
+
value,
|
|
8
|
+
onChange,
|
|
9
|
+
transformValue
|
|
10
|
+
}) {
|
|
11
|
+
const [internValue, setInternValue] = useState(defaultValue);
|
|
12
|
+
const currentValue = (onChange ? value : internValue) ?? defaultValue;
|
|
13
|
+
const setValue = useCallback(
|
|
14
|
+
function setValue2(value2) {
|
|
15
|
+
const nextValue = transformValue ? transformValue(value2) : value2;
|
|
16
|
+
if (onChange) {
|
|
17
|
+
onChange(nextValue);
|
|
18
|
+
} else {
|
|
19
|
+
setInternValue(nextValue);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
[onChange, transformValue]
|
|
23
|
+
);
|
|
24
|
+
if (process.env.NODE_ENV !== "production") {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (onChange && value === void 0) {
|
|
27
|
+
console.error("Slider is in controlled mode but no value is provided");
|
|
28
|
+
}
|
|
29
|
+
}, []);
|
|
30
|
+
}
|
|
31
|
+
return [currentValue, setValue];
|
|
32
|
+
}
|
|
33
|
+
function roundToPrecision(value, precision) {
|
|
34
|
+
const factor = 10 ** precision;
|
|
35
|
+
return Math.round(value * factor) / factor;
|
|
36
|
+
}
|
|
37
|
+
function getBoundValue(newValue, min, max, step) {
|
|
38
|
+
let value = Math.round(newValue / step) * step;
|
|
39
|
+
value = Math.max(min, Math.min(max, value));
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
5
42
|
function getProgress(event, rect) {
|
|
6
43
|
const { clientX, clientY } = event;
|
|
7
44
|
const { width, height, left, top } = rect;
|
|
@@ -43,11 +80,18 @@ function usePointerProgress({ container: container2, orientation, onChange }) {
|
|
|
43
80
|
};
|
|
44
81
|
}, [container2, onChange, orientation]);
|
|
45
82
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
83
|
+
const usableKeys = /* @__PURE__ */ new Set([
|
|
84
|
+
"ArrowLeft",
|
|
85
|
+
"ArrowRight",
|
|
86
|
+
"ArrowUp",
|
|
87
|
+
"ArrowDown",
|
|
88
|
+
"Home",
|
|
89
|
+
"End",
|
|
90
|
+
"PageUp",
|
|
91
|
+
"PageDown",
|
|
92
|
+
"Home",
|
|
93
|
+
"End"
|
|
94
|
+
]);
|
|
51
95
|
const Slider = ({
|
|
52
96
|
min = 0,
|
|
53
97
|
max = 100,
|
|
@@ -59,26 +103,24 @@ const Slider = ({
|
|
|
59
103
|
name,
|
|
60
104
|
size,
|
|
61
105
|
colorScheme,
|
|
106
|
+
disabled,
|
|
107
|
+
precision = 2,
|
|
62
108
|
...restProps
|
|
63
109
|
}) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
110
|
+
const baseClass = useComponentStyles("slider", {
|
|
111
|
+
base: true,
|
|
112
|
+
variants: { size, colorScheme, disabled }
|
|
113
|
+
});
|
|
68
114
|
const trackClass = useComponentStyles("slider", { track: true }, false);
|
|
69
115
|
const filledTrackClass = useComponentStyles("slider", { filledTrack: true }, false);
|
|
70
116
|
const thumbClass = useComponentStyles("slider", { thumb: true }, false);
|
|
71
117
|
const containerRef = useRef(null);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (onChange && internValue !== value) {
|
|
79
|
-
onChange(internValue);
|
|
80
|
-
}
|
|
81
|
-
}, [internValue, onChange, value]);
|
|
118
|
+
const [currentValue, setValue] = useControlledValue({
|
|
119
|
+
defaultValue,
|
|
120
|
+
value,
|
|
121
|
+
onChange,
|
|
122
|
+
transformValue: (value2) => roundToPrecision(getBoundValue(value2, min, max, step), precision)
|
|
123
|
+
});
|
|
82
124
|
usePointerProgress({
|
|
83
125
|
container: containerRef,
|
|
84
126
|
orientation,
|
|
@@ -86,29 +128,32 @@ const Slider = ({
|
|
|
86
128
|
if (orientation === "vertical") {
|
|
87
129
|
progress = 1 - progress;
|
|
88
130
|
}
|
|
89
|
-
|
|
131
|
+
setValue(max * progress);
|
|
90
132
|
}
|
|
91
133
|
});
|
|
92
134
|
const onKeyDown = useCallback(
|
|
93
135
|
(event) => {
|
|
136
|
+
if (!usableKeys.has(event.key)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
94
139
|
event.preventDefault();
|
|
95
140
|
event.stopPropagation();
|
|
96
141
|
const specialKey = ["PageUp", "PageDown"];
|
|
97
142
|
const stepModifier = event.shiftKey || specialKey.includes(event.key) ? (max - min) / 10 : step;
|
|
98
143
|
if (event.key === "ArrowLeft" || event.key === "ArrowDown" || event.key === "PageDown") {
|
|
99
|
-
return
|
|
144
|
+
return setValue(currentValue - stepModifier);
|
|
100
145
|
}
|
|
101
146
|
if (event.key === "ArrowRight" || event.key === "ArrowUp" || event.key === "PageUp") {
|
|
102
|
-
return
|
|
147
|
+
return setValue(currentValue + stepModifier);
|
|
103
148
|
}
|
|
104
149
|
if (event.key === "Home") {
|
|
105
|
-
return
|
|
150
|
+
return setValue(min);
|
|
106
151
|
}
|
|
107
152
|
if (event.key === "End") {
|
|
108
|
-
return
|
|
153
|
+
return setValue(max);
|
|
109
154
|
}
|
|
110
155
|
},
|
|
111
|
-
[max, min, step]
|
|
156
|
+
[max, min, step, setValue, currentValue]
|
|
112
157
|
);
|
|
113
158
|
return /* @__PURE__ */ jsxs(
|
|
114
159
|
"div",
|
|
@@ -125,28 +170,28 @@ const Slider = ({
|
|
|
125
170
|
{
|
|
126
171
|
className: classnames(filledTrack, filledTrackClass),
|
|
127
172
|
style: {
|
|
128
|
-
inlineSize: `${
|
|
173
|
+
inlineSize: `${currentValue / max * 100}%`
|
|
129
174
|
}
|
|
130
175
|
}
|
|
131
176
|
) }),
|
|
132
177
|
/* @__PURE__ */ jsx(
|
|
133
|
-
"
|
|
178
|
+
"button",
|
|
134
179
|
{
|
|
180
|
+
type: "button",
|
|
135
181
|
className: classnames(thumb, thumbClass),
|
|
136
|
-
tabIndex: 0,
|
|
137
182
|
role: "slider",
|
|
138
183
|
"aria-valuemin": min,
|
|
139
184
|
"aria-valuemax": max,
|
|
140
|
-
"aria-valuenow":
|
|
185
|
+
"aria-valuenow": currentValue,
|
|
141
186
|
"aria-orientation": orientation,
|
|
142
187
|
style: {
|
|
143
|
-
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${
|
|
188
|
+
[orientation === "horizontal" ? "insetInlineStart" : "insetInlineEnd"]: `${currentValue / max * 100}%`
|
|
144
189
|
},
|
|
145
190
|
onKeyDown,
|
|
146
191
|
...restProps
|
|
147
192
|
}
|
|
148
193
|
),
|
|
149
|
-
/* @__PURE__ */ jsx("input", { type: "hidden", name, value:
|
|
194
|
+
/* @__PURE__ */ jsx("input", { type: "hidden", disabled, name, value: currentValue })
|
|
150
195
|
]
|
|
151
196
|
}
|
|
152
197
|
);
|
|
@@ -22,10 +22,18 @@ const dialog = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("dialo
|
|
|
22
22
|
selectors: {
|
|
23
23
|
"&[open]": {
|
|
24
24
|
transform: "translate(0, 0)",
|
|
25
|
-
opacity: 1
|
|
25
|
+
opacity: 1,
|
|
26
|
+
// @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
|
|
27
|
+
"@starting-style": {
|
|
28
|
+
transform: "translate(0, -120px)",
|
|
29
|
+
opacity: 0
|
|
30
|
+
}
|
|
26
31
|
},
|
|
27
32
|
"&[open]::backdrop": {
|
|
28
|
-
opacity: 1
|
|
33
|
+
opacity: 1,
|
|
34
|
+
"@starting-style": {
|
|
35
|
+
opacity: 0
|
|
36
|
+
}
|
|
29
37
|
}
|
|
30
38
|
},
|
|
31
39
|
// Apply the animation only if the user has not requested reduced motion
|
|
@@ -37,19 +45,11 @@ const dialog = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("dialo
|
|
|
37
45
|
transitionBehavior: "allow-discrete",
|
|
38
46
|
transitionProperty: "opacity, transform, overlay, display",
|
|
39
47
|
transitionDuration: "240ms, 160ms, 240ms, 240ms",
|
|
40
|
-
// @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
|
|
41
|
-
"@starting-style": {
|
|
42
|
-
transform: "translate(0, -120px)",
|
|
43
|
-
opacity: 0
|
|
44
|
-
},
|
|
45
48
|
"::backdrop": {
|
|
46
49
|
opacity: 0,
|
|
47
50
|
transitionBehavior: "allow-discrete",
|
|
48
51
|
transitionProperty: "opacity, overlay, display",
|
|
49
|
-
transitionDuration: "160ms, 240ms, 240ms"
|
|
50
|
-
"@starting-style": {
|
|
51
|
-
opacity: 0
|
|
52
|
-
}
|
|
52
|
+
transitionDuration: "160ms, 240ms, 240ms"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -21,10 +21,18 @@ const dialog = makeComponentTheme("dialog", {
|
|
|
21
21
|
selectors: {
|
|
22
22
|
"&[open]": {
|
|
23
23
|
transform: "translate(0, 0)",
|
|
24
|
-
opacity: 1
|
|
24
|
+
opacity: 1,
|
|
25
|
+
// @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
|
|
26
|
+
"@starting-style": {
|
|
27
|
+
transform: "translate(0, -120px)",
|
|
28
|
+
opacity: 0
|
|
29
|
+
}
|
|
25
30
|
},
|
|
26
31
|
"&[open]::backdrop": {
|
|
27
|
-
opacity: 1
|
|
32
|
+
opacity: 1,
|
|
33
|
+
"@starting-style": {
|
|
34
|
+
opacity: 0
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
},
|
|
30
38
|
// Apply the animation only if the user has not requested reduced motion
|
|
@@ -36,19 +44,11 @@ const dialog = makeComponentTheme("dialog", {
|
|
|
36
44
|
transitionBehavior: "allow-discrete",
|
|
37
45
|
transitionProperty: "opacity, transform, overlay, display",
|
|
38
46
|
transitionDuration: "240ms, 160ms, 240ms, 240ms",
|
|
39
|
-
// @ts-expect-error - Vanilla Extract does not support @starting-style (yet)
|
|
40
|
-
"@starting-style": {
|
|
41
|
-
transform: "translate(0, -120px)",
|
|
42
|
-
opacity: 0
|
|
43
|
-
},
|
|
44
47
|
"::backdrop": {
|
|
45
48
|
opacity: 0,
|
|
46
49
|
transitionBehavior: "allow-discrete",
|
|
47
50
|
transitionProperty: "opacity, overlay, display",
|
|
48
|
-
transitionDuration: "160ms, 240ms, 240ms"
|
|
49
|
-
"@starting-style": {
|
|
50
|
-
opacity: 0
|
|
51
|
-
}
|
|
51
|
+
transitionDuration: "160ms, 240ms, 240ms"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -9,6 +9,7 @@ fileScope.setFileScope("src/themes/momotaro/components/slider.css.ts", "@blockle
|
|
|
9
9
|
const trackBackground = css.createVar("trackBackground");
|
|
10
10
|
const filledTrackBackground = css.createVar("filledTrackBackground");
|
|
11
11
|
const thumbBackground = css.createVar("thumbBackground");
|
|
12
|
+
const thumbActive = css.createVar("thumbActive");
|
|
12
13
|
const slider = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("slider", {
|
|
13
14
|
base: styles_lib_css_style_style_cjs.style({
|
|
14
15
|
blockSize: "20px"
|
|
@@ -25,7 +26,22 @@ const slider = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("slide
|
|
|
25
26
|
backgroundColor: thumbBackground,
|
|
26
27
|
borderRadius: "50%",
|
|
27
28
|
height: "16px",
|
|
28
|
-
width: "16px"
|
|
29
|
+
width: "16px",
|
|
30
|
+
boxShadow: `0 0 0 0px color-mix(in srgb, ${styles_lib_theme_vars_css_cjs.vars.color.primaryLight}, transparent 0%)`,
|
|
31
|
+
vars: {
|
|
32
|
+
[thumbActive]: `0 0 0 8px color-mix(in srgb, ${styles_lib_theme_vars_css_cjs.vars.color.primaryLight}, transparent 20%)`
|
|
33
|
+
},
|
|
34
|
+
":hover": {
|
|
35
|
+
boxShadow: thumbActive
|
|
36
|
+
},
|
|
37
|
+
":focus-visible": {
|
|
38
|
+
boxShadow: thumbActive
|
|
39
|
+
},
|
|
40
|
+
"@media": {
|
|
41
|
+
"(prefers-reduced-motion: no-preference)": {
|
|
42
|
+
transition: "box-shadow 0.2s"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
29
45
|
}, styles_themes_momotaro_components_helpers_css_cjs.focusable]),
|
|
30
46
|
variants: {
|
|
31
47
|
size: {
|
|
@@ -54,7 +70,15 @@ const slider = styles_lib_theme_makeComponentTheme_cjs.makeComponentTheme("slide
|
|
|
54
70
|
[thumbBackground]: styles_lib_theme_vars_css_cjs.vars.color.secondary
|
|
55
71
|
}
|
|
56
72
|
})
|
|
57
|
-
}
|
|
73
|
+
},
|
|
74
|
+
disabled: styles_lib_css_style_style_cjs.style({
|
|
75
|
+
pointerEvents: "none",
|
|
76
|
+
vars: {
|
|
77
|
+
[trackBackground]: "#c0c0c0",
|
|
78
|
+
[filledTrackBackground]: "#ccc",
|
|
79
|
+
[thumbBackground]: "#c0c0c0"
|
|
80
|
+
}
|
|
81
|
+
})
|
|
58
82
|
},
|
|
59
83
|
defaultVariants: {
|
|
60
84
|
size: "medium",
|
|
@@ -8,6 +8,7 @@ setFileScope("src/themes/momotaro/components/slider.css.ts", "@blockle/blocks");
|
|
|
8
8
|
const trackBackground = createVar("trackBackground");
|
|
9
9
|
const filledTrackBackground = createVar("filledTrackBackground");
|
|
10
10
|
const thumbBackground = createVar("thumbBackground");
|
|
11
|
+
const thumbActive = createVar("thumbActive");
|
|
11
12
|
const slider = makeComponentTheme("slider", {
|
|
12
13
|
base: style({
|
|
13
14
|
blockSize: "20px"
|
|
@@ -24,7 +25,22 @@ const slider = makeComponentTheme("slider", {
|
|
|
24
25
|
backgroundColor: thumbBackground,
|
|
25
26
|
borderRadius: "50%",
|
|
26
27
|
height: "16px",
|
|
27
|
-
width: "16px"
|
|
28
|
+
width: "16px",
|
|
29
|
+
boxShadow: `0 0 0 0px color-mix(in srgb, ${vars.color.primaryLight}, transparent 0%)`,
|
|
30
|
+
vars: {
|
|
31
|
+
[thumbActive]: `0 0 0 8px color-mix(in srgb, ${vars.color.primaryLight}, transparent 20%)`
|
|
32
|
+
},
|
|
33
|
+
":hover": {
|
|
34
|
+
boxShadow: thumbActive
|
|
35
|
+
},
|
|
36
|
+
":focus-visible": {
|
|
37
|
+
boxShadow: thumbActive
|
|
38
|
+
},
|
|
39
|
+
"@media": {
|
|
40
|
+
"(prefers-reduced-motion: no-preference)": {
|
|
41
|
+
transition: "box-shadow 0.2s"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
28
44
|
}, focusable]),
|
|
29
45
|
variants: {
|
|
30
46
|
size: {
|
|
@@ -53,7 +69,15 @@ const slider = makeComponentTheme("slider", {
|
|
|
53
69
|
[thumbBackground]: vars.color.secondary
|
|
54
70
|
}
|
|
55
71
|
})
|
|
56
|
-
}
|
|
72
|
+
},
|
|
73
|
+
disabled: style({
|
|
74
|
+
pointerEvents: "none",
|
|
75
|
+
vars: {
|
|
76
|
+
[trackBackground]: "#c0c0c0",
|
|
77
|
+
[filledTrackBackground]: "#ccc",
|
|
78
|
+
[thumbBackground]: "#c0c0c0"
|
|
79
|
+
}
|
|
80
|
+
})
|
|
57
81
|
},
|
|
58
82
|
defaultVariants: {
|
|
59
83
|
size: "medium",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
|
+
const styles_lib_css_utils_cssUtils_cjs = require("../../lib/css/utils/cssUtils.cjs");
|
|
3
4
|
fileScope.setFileScope("src/themes/momotaro/tokens.css.ts", "@blockle/blocks");
|
|
4
5
|
const tokens = {
|
|
5
6
|
border: {
|
|
@@ -60,11 +61,11 @@ const tokens = {
|
|
|
60
61
|
secondary: '"Rubik", sans-serif'
|
|
61
62
|
},
|
|
62
63
|
fontSize: {
|
|
63
|
-
xsmall:
|
|
64
|
-
small:
|
|
65
|
-
medium:
|
|
66
|
-
large:
|
|
67
|
-
xlarge:
|
|
64
|
+
xsmall: styles_lib_css_utils_cssUtils_cjs.rem(12),
|
|
65
|
+
small: styles_lib_css_utils_cssUtils_cjs.rem(14),
|
|
66
|
+
medium: styles_lib_css_utils_cssUtils_cjs.rem(16),
|
|
67
|
+
large: styles_lib_css_utils_cssUtils_cjs.rem(20),
|
|
68
|
+
xlarge: styles_lib_css_utils_cssUtils_cjs.rem(24)
|
|
68
69
|
},
|
|
69
70
|
fontWeight: {
|
|
70
71
|
regular: 400,
|
|
@@ -72,11 +73,11 @@ const tokens = {
|
|
|
72
73
|
strong: 700
|
|
73
74
|
},
|
|
74
75
|
lineHeight: {
|
|
75
|
-
xsmall:
|
|
76
|
-
small:
|
|
77
|
-
medium:
|
|
78
|
-
large:
|
|
79
|
-
xlarge:
|
|
76
|
+
xsmall: styles_lib_css_utils_cssUtils_cjs.rem(16),
|
|
77
|
+
small: styles_lib_css_utils_cssUtils_cjs.rem(20),
|
|
78
|
+
medium: styles_lib_css_utils_cssUtils_cjs.rem(24),
|
|
79
|
+
large: styles_lib_css_utils_cssUtils_cjs.rem(28),
|
|
80
|
+
xlarge: styles_lib_css_utils_cssUtils_cjs.rem(32)
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
|
+
import { rem } from "../../lib/css/utils/cssUtils.mjs";
|
|
2
3
|
setFileScope("src/themes/momotaro/tokens.css.ts", "@blockle/blocks");
|
|
3
4
|
const tokens = {
|
|
4
5
|
border: {
|
|
@@ -59,11 +60,11 @@ const tokens = {
|
|
|
59
60
|
secondary: '"Rubik", sans-serif'
|
|
60
61
|
},
|
|
61
62
|
fontSize: {
|
|
62
|
-
xsmall:
|
|
63
|
-
small:
|
|
64
|
-
medium:
|
|
65
|
-
large:
|
|
66
|
-
xlarge:
|
|
63
|
+
xsmall: rem(12),
|
|
64
|
+
small: rem(14),
|
|
65
|
+
medium: rem(16),
|
|
66
|
+
large: rem(20),
|
|
67
|
+
xlarge: rem(24)
|
|
67
68
|
},
|
|
68
69
|
fontWeight: {
|
|
69
70
|
regular: 400,
|
|
@@ -71,11 +72,11 @@ const tokens = {
|
|
|
71
72
|
strong: 700
|
|
72
73
|
},
|
|
73
74
|
lineHeight: {
|
|
74
|
-
xsmall:
|
|
75
|
-
small:
|
|
76
|
-
medium:
|
|
77
|
-
large:
|
|
78
|
-
xlarge:
|
|
75
|
+
xsmall: rem(16),
|
|
76
|
+
small: rem(20),
|
|
77
|
+
medium: rem(24),
|
|
78
|
+
large: rem(28),
|
|
79
|
+
xlarge: rem(32)
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockle/blocks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Blocks design system",
|
|
5
5
|
"repository": "git@github.com:Blockle/blocks.git",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"./src/lib/theme/globalTheme.ts",
|
|
10
10
|
"dist/side-effects/**"
|
|
11
11
|
],
|
|
12
|
+
"type": "module",
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
14
15
|
"types": {
|
|
@@ -47,14 +48,14 @@
|
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "crackle package && node ./temp-use-client-fix.js",
|
|
49
50
|
"build-storybook": "storybook build",
|
|
51
|
+
"changeset": "changeset",
|
|
50
52
|
"coverage": "vitest run --coverage",
|
|
51
53
|
"fix": "crackle fix",
|
|
52
54
|
"lint": "eslint .",
|
|
53
55
|
"release": "npm run ts && npm run test && npm run build && changeset publish",
|
|
54
56
|
"storybook": "storybook dev -p 6006 --no-open",
|
|
55
57
|
"test": "vitest --silent # ignore warnings till js-dom can parse new css features",
|
|
56
|
-
"ts": "tsc --noemit --project ./tsconfig.json"
|
|
57
|
-
"changeset": "changeset"
|
|
58
|
+
"ts": "tsc --noemit --project ./tsconfig.json"
|
|
58
59
|
},
|
|
59
60
|
"resolutions": {
|
|
60
61
|
"string-width": "^4.2.2"
|
|
@@ -64,19 +65,19 @@
|
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@changesets/cli": "^2.27.5",
|
|
67
|
-
"@chromatic-com/storybook": "^
|
|
68
|
-
"@crackle/cli": "^0.15.
|
|
68
|
+
"@chromatic-com/storybook": "^2.0.2",
|
|
69
|
+
"@crackle/cli": "^0.15.5",
|
|
69
70
|
"@crackle/core": "^0.33.3",
|
|
70
|
-
"@storybook/addon-a11y": "^8.
|
|
71
|
+
"@storybook/addon-a11y": "^8.3.0",
|
|
71
72
|
"@storybook/addon-coverage": "^1.0.4",
|
|
72
|
-
"@storybook/addon-essentials": "^8.
|
|
73
|
-
"@storybook/addon-interactions": "^8.
|
|
74
|
-
"@storybook/addon-links": "^8.
|
|
75
|
-
"@storybook/blocks": "^8.
|
|
76
|
-
"@storybook/preview-api": "^8.
|
|
77
|
-
"@storybook/react": "^8.
|
|
78
|
-
"@storybook/react-vite": "^8.
|
|
79
|
-
"@storybook/test": "^8.
|
|
73
|
+
"@storybook/addon-essentials": "^8.3.0",
|
|
74
|
+
"@storybook/addon-interactions": "^8.3.0",
|
|
75
|
+
"@storybook/addon-links": "^8.3.0",
|
|
76
|
+
"@storybook/blocks": "^8.3.0",
|
|
77
|
+
"@storybook/preview-api": "^8.3.0",
|
|
78
|
+
"@storybook/react": "^8.3.0",
|
|
79
|
+
"@storybook/react-vite": "^8.3.0",
|
|
80
|
+
"@storybook/test": "^8.3.0",
|
|
80
81
|
"@testing-library/jest-dom": "^6.4.5",
|
|
81
82
|
"@testing-library/react": "^16.0.0",
|
|
82
83
|
"@types/eslint": "^8.56.12",
|
|
@@ -104,7 +105,7 @@
|
|
|
104
105
|
"prop-types": "^15.8.1",
|
|
105
106
|
"react": "^18.3.1",
|
|
106
107
|
"react-dom": "^18.3.1",
|
|
107
|
-
"storybook": "^8.
|
|
108
|
+
"storybook": "^8.3.0",
|
|
108
109
|
"typescript": "^5.4.5",
|
|
109
110
|
"vitest": "^2.0.5"
|
|
110
111
|
},
|