reshaped 3.6.0-canary.0 → 3.6.0-canary.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/CHANGELOG.md +21 -2
- package/dist/bundle.css +1 -1
- package/dist/bundle.d.ts +1 -1
- package/dist/bundle.js +11 -11
- package/dist/components/Accordion/AccordionControlled.js +1 -1
- package/dist/components/Accordion/AccordionTrigger.js +1 -1
- package/dist/components/ActionBar/ActionBar.js +1 -1
- package/dist/components/Actionable/Actionable.js +1 -1
- package/dist/components/Autocomplete/tests/Autocomplete.stories.js +1 -0
- package/dist/components/Avatar/Avatar.js +1 -1
- package/dist/components/Badge/Badge.js +1 -1
- package/dist/components/Badge/BadgeContainer.js +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/components/Button/Button.js +1 -1
- package/dist/components/Button/ButtonGroup.js +1 -1
- package/dist/components/Calendar/CalendarDate.js +1 -1
- package/dist/components/Card/Card.d.ts +1 -1
- package/dist/components/Card/Card.js +1 -1
- package/dist/components/Card/tests/Card.stories.d.ts +1 -1
- package/dist/components/Card/tests/Card.test.stories.d.ts +1 -1
- package/dist/components/Carousel/Carousel.js +4 -3
- package/dist/components/Carousel/CarouselControl.js +1 -1
- package/dist/components/Checkbox/Checkbox.js +1 -1
- package/dist/components/Checkbox/Checkbox.module.css +1 -1
- package/dist/components/Container/Container.js +1 -1
- package/dist/components/Dismissible/Dismissible.js +1 -1
- package/dist/components/Divider/Divider.js +1 -1
- package/dist/components/DropdownMenu/DropdownMenu.js +1 -1
- package/dist/components/FileUpload/FileUpload.js +1 -1
- package/dist/components/Flyout/Flyout.types.d.ts +3 -2
- package/dist/components/Flyout/FlyoutContent.js +14 -11
- package/dist/components/Flyout/tests/Flyout.stories.d.ts +4 -0
- package/dist/components/Flyout/tests/Flyout.stories.js +20 -4
- package/dist/components/Flyout/useFlyout.js +13 -9
- package/dist/components/Flyout/utilities/calculatePosition.d.ts +1 -1
- package/dist/components/Flyout/utilities/calculatePosition.js +1 -1
- package/dist/components/Flyout/utilities/flyout.js +4 -4
- package/dist/components/FormControl/FormControl.context.d.ts +0 -2
- package/dist/components/Grid/Grid.js +1 -1
- package/dist/components/Hidden/Hidden.js +1 -1
- package/dist/components/Hotkey/Hotkey.js +1 -1
- package/dist/components/Icon/Icon.js +1 -1
- package/dist/components/Image/Image.js +1 -1
- package/dist/components/Link/Link.js +1 -1
- package/dist/components/Loader/Loader.js +1 -1
- package/dist/components/MenuItem/MenuItem.js +1 -1
- package/dist/components/Modal/Modal.js +2 -2
- package/dist/components/Modal/Modal.module.css +1 -1
- package/dist/components/NumberField/NumberFieldControlled.js +1 -1
- package/dist/components/Overlay/Overlay.js +3 -3
- package/dist/components/Overlay/Overlay.module.css +1 -1
- package/dist/components/Overlay/Overlay.types.d.ts +1 -0
- package/dist/components/PinField/PinFieldControlled.js +1 -1
- package/dist/components/Popover/Popover.js +3 -3
- package/dist/components/Popover/Popover.module.css +1 -1
- package/dist/components/Popover/Popover.types.d.ts +1 -0
- package/dist/components/Popover/tests/Popover.stories.d.ts +46 -7
- package/dist/components/Popover/tests/Popover.stories.js +209 -85
- package/dist/components/Progress/Progress.js +1 -1
- package/dist/components/ProgressIndicator/ProgressIndicator.js +1 -1
- package/dist/components/Radio/Radio.js +1 -1
- package/dist/components/Radio/Radio.module.css +1 -1
- package/dist/components/Reshaped/Reshaped.js +1 -1
- package/dist/components/Resizable/Resizable.js +1 -1
- package/dist/components/Scrim/Scrim.js +1 -1
- package/dist/components/ScrollArea/ScrollArea.js +8 -11
- package/dist/components/ScrollArea/ScrollArea.module.css +1 -1
- package/dist/components/ScrollArea/tests/ScrollArea.stories.d.ts +13 -4
- package/dist/components/ScrollArea/tests/ScrollArea.stories.js +129 -30
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/Skeleton/Skeleton.js +1 -1
- package/dist/components/Slider/Slider.types.d.ts +34 -7
- package/dist/components/Slider/SliderControlled.js +32 -20
- package/dist/components/Slider/SliderThumb.js +4 -4
- package/dist/components/Slider/SliderUncontrolled.js +3 -2
- package/dist/components/Slider/tests/Slider.stories.d.ts +38 -8
- package/dist/components/Slider/tests/Slider.stories.js +268 -54
- package/dist/components/Stepper/Stepper.js +1 -1
- package/dist/components/Switch/Switch.js +1 -1
- package/dist/components/Table/Table.js +6 -3
- package/dist/components/Table/Table.module.css +1 -1
- package/dist/components/Tabs/TabsItem.js +1 -1
- package/dist/components/Tabs/TabsList.js +3 -34
- package/dist/components/Tabs/TabsPanel.js +1 -1
- package/dist/components/Text/Text.js +1 -1
- package/dist/components/TextArea/TextArea.js +1 -1
- package/dist/components/TextField/TextField.js +1 -1
- package/dist/components/Theme/Theme.js +1 -1
- package/dist/components/Timeline/Timeline.js +1 -1
- package/dist/components/Toast/ToastContainer.js +1 -1
- package/dist/components/Toast/ToastRegion.js +1 -1
- package/dist/components/View/View.js +1 -1
- package/dist/components/_private/Aligner/Aligner.js +1 -1
- package/dist/components/_private/Expandable/Expandable.js +1 -1
- package/dist/components/_private/HiddenInput/HiddenInput.js +1 -1
- package/dist/hooks/_private/useFadeSide.d.ts +5 -0
- package/dist/hooks/_private/useFadeSide.js +47 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/styles/align/index.js +1 -1
- package/dist/styles/aspectRatio/index.js +1 -1
- package/dist/styles/bleed/index.js +1 -1
- package/dist/styles/border/index.js +1 -1
- package/dist/styles/height/index.js +1 -1
- package/dist/styles/inset/index.js +1 -1
- package/dist/styles/justify/index.js +1 -1
- package/dist/styles/maxHeight/index.js +1 -1
- package/dist/styles/maxWidth/index.js +1 -1
- package/dist/styles/minHeight/index.js +1 -1
- package/dist/styles/minWidth/index.js +1 -1
- package/dist/styles/padding/index.js +1 -1
- package/dist/styles/position/index.js +1 -1
- package/dist/styles/radius/index.js +1 -1
- package/dist/styles/textAlign/index.js +1 -1
- package/dist/styles/width/index.js +1 -1
- package/dist/utilities/dom/event.d.ts +7 -0
- package/dist/utilities/dom/event.js +11 -0
- package/dist/utilities/dom/find.d.ts +1 -1
- package/dist/utilities/dom/find.js +2 -2
- package/dist/utilities/dom/index.d.ts +1 -0
- package/dist/utilities/dom/index.js +1 -0
- package/dist/utilities/helpers.d.ts +1 -15
- package/dist/utilities/helpers.js +11 -133
- package/dist/utilities/props.d.ts +13 -0
- package/dist/utilities/props.js +83 -0
- package/package.json +25 -26
- package/dist/components/Popover/tests/Popover.test.stories.d.ts +0 -39
- package/dist/components/Popover/tests/Popover.test.stories.js +0 -167
- package/dist/components/ScrollArea/tests/ScrollArea.test.stories.d.ts +0 -23
- package/dist/components/ScrollArea/tests/ScrollArea.test.stories.js +0 -66
- package/dist/components/Slider/tests/Slider.test.stories.d.ts +0 -38
- package/dist/components/Slider/tests/Slider.test.stories.js +0 -150
@@ -1,4 +1,5 @@
|
|
1
1
|
import React from "react";
|
2
|
+
import { userEvent, expect, waitFor, fn } from "@storybook/test";
|
2
3
|
import { Example } from "../../../utilities/storybook/index.js";
|
3
4
|
import ScrollArea from "../index.js";
|
4
5
|
import View from "../../View/index.js";
|
@@ -16,10 +17,10 @@ export default {
|
|
16
17
|
},
|
17
18
|
},
|
18
19
|
};
|
19
|
-
export const
|
20
|
-
name: "
|
20
|
+
export const base = {
|
21
|
+
name: "base",
|
21
22
|
render: () => (<Example>
|
22
|
-
<Example.Item title="vertical">
|
23
|
+
<Example.Item title="vertical scroll">
|
23
24
|
<ScrollArea height="100px" scrollbarDisplay="visible">
|
24
25
|
<View backgroundColor="elevation-base" padding={4}>
|
25
26
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
@@ -33,7 +34,7 @@ export const direction = {
|
|
33
34
|
</ScrollArea>
|
34
35
|
</Example.Item>
|
35
36
|
|
36
|
-
<Example.Item title="horizontal">
|
37
|
+
<Example.Item title="horizontal scroll">
|
37
38
|
<ScrollArea height="100px" scrollbarDisplay="visible">
|
38
39
|
<View backgroundColor="elevation-base" padding={4} width="150%" height="100px">
|
39
40
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
@@ -42,7 +43,7 @@ export const direction = {
|
|
42
43
|
</ScrollArea>
|
43
44
|
</Example.Item>
|
44
45
|
|
45
|
-
<Example.Item title="horizontal
|
46
|
+
<Example.Item title="horizontal and vertical scroll">
|
46
47
|
<ScrollArea height="100px" scrollbarDisplay="visible">
|
47
48
|
<View backgroundColor="elevation-base" padding={4} width="150%">
|
48
49
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
@@ -57,12 +58,12 @@ export const direction = {
|
|
57
58
|
</Example.Item>
|
58
59
|
</Example>),
|
59
60
|
};
|
60
|
-
export const
|
61
|
+
export const scrollbarDisplay = {
|
61
62
|
name: "scrollbarDisplay",
|
62
63
|
render: () => (<Example>
|
63
|
-
<Example.Item title="
|
64
|
+
<Example.Item title="scrollbarDisplay: hover">
|
64
65
|
<ScrollArea height="100px">
|
65
|
-
<View backgroundColor="elevation-base" padding={4}>
|
66
|
+
<View backgroundColor="elevation-base" padding={4} width="150%">
|
66
67
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
67
68
|
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
68
69
|
printer took a galley of type and scrambled it to make a type specimen book. It has
|
@@ -74,9 +75,9 @@ export const visibility = {
|
|
74
75
|
</ScrollArea>
|
75
76
|
</Example.Item>
|
76
77
|
|
77
|
-
<Example.Item title="
|
78
|
+
<Example.Item title="scrollbarDisplay: hidden">
|
78
79
|
<ScrollArea height="100px" scrollbarDisplay="hidden">
|
79
|
-
<View backgroundColor="elevation-base" padding={4}>
|
80
|
+
<View backgroundColor="elevation-base" padding={4} width="150%">
|
80
81
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
81
82
|
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
82
83
|
printer took a galley of type and scrambled it to make a type specimen book. It has
|
@@ -88,9 +89,9 @@ export const visibility = {
|
|
88
89
|
</ScrollArea>
|
89
90
|
</Example.Item>
|
90
91
|
|
91
|
-
<Example.Item title="
|
92
|
+
<Example.Item title="scrollbarDisplay: visible">
|
92
93
|
<ScrollArea height="100px" scrollbarDisplay="visible">
|
93
|
-
<View backgroundColor="elevation-base" padding={4}>
|
94
|
+
<View backgroundColor="elevation-base" padding={4} width="150%">
|
94
95
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
95
96
|
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
96
97
|
printer took a galley of type and scrambled it to make a type specimen book. It has
|
@@ -103,26 +104,129 @@ export const visibility = {
|
|
103
104
|
</Example.Item>
|
104
105
|
</Example>),
|
105
106
|
};
|
106
|
-
export const
|
107
|
-
name: "
|
107
|
+
export const height = {
|
108
|
+
name: "height, maxHeight",
|
108
109
|
render: () => (<Example>
|
109
|
-
<Example.Item title="
|
110
|
-
<ScrollArea height="
|
111
|
-
<View padding={4}
|
112
|
-
|
113
|
-
|
110
|
+
<Example.Item title="height: 80px">
|
111
|
+
<ScrollArea height="80px">
|
112
|
+
<View backgroundColor="elevation-base" padding={4}>
|
113
|
+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
114
|
+
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
115
|
+
printer took a galley of type and scrambled it to make a type specimen book. It has
|
116
|
+
survived not only five centuries, but also the leap into electronic typesetting,
|
117
|
+
remaining essentially unchanged. It was popularised in the 1960s with the release of
|
118
|
+
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
|
119
|
+
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
|
120
|
+
</View>
|
121
|
+
</ScrollArea>
|
122
|
+
</Example.Item>
|
123
|
+
|
124
|
+
<Example.Item title="responsive height: s 80px, m: 120px">
|
125
|
+
<ScrollArea height={{ s: "80px", m: "120px" }}>
|
126
|
+
<View backgroundColor="elevation-base" padding={4}>
|
127
|
+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
128
|
+
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
129
|
+
printer took a galley of type and scrambled it to make a type specimen book. It has
|
130
|
+
survived not only five centuries, but also the leap into electronic typesetting,
|
131
|
+
remaining essentially unchanged. It was popularised in the 1960s with the release of
|
132
|
+
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
|
133
|
+
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
|
134
|
+
</View>
|
135
|
+
</ScrollArea>
|
136
|
+
</Example.Item>
|
137
|
+
|
138
|
+
<Example.Item title="maxHeight: 80px">
|
139
|
+
<ScrollArea maxHeight="80px">
|
140
|
+
<View backgroundColor="elevation-base" padding={4}>
|
141
|
+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
142
|
+
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
143
|
+
printer took a galley of type and scrambled it to make a type specimen book. It has
|
144
|
+
survived not only five centuries, but also the leap into electronic typesetting,
|
145
|
+
remaining essentially unchanged. It was popularised in the 1960s with the release of
|
146
|
+
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
|
147
|
+
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
|
148
|
+
</View>
|
149
|
+
</ScrollArea>
|
150
|
+
</Example.Item>
|
151
|
+
|
152
|
+
<Example.Item title="responsive max height: s 80px, m: 200px">
|
153
|
+
<ScrollArea maxHeight={{ s: "80px", m: "200px" }}>
|
154
|
+
<View backgroundColor="elevation-base" padding={4}>
|
155
|
+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
156
|
+
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
157
|
+
printer took a galley of type and scrambled it to make a type specimen book. It has
|
158
|
+
survived not only five centuries, but also the leap into electronic typesetting,
|
159
|
+
remaining essentially unchanged. It was popularised in the 1960s with the release of
|
160
|
+
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
|
161
|
+
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
|
162
|
+
</View>
|
163
|
+
</ScrollArea>
|
164
|
+
</Example.Item>
|
165
|
+
</Example>),
|
166
|
+
};
|
167
|
+
export const onScroll = {
|
168
|
+
name: "ref, onScroll",
|
169
|
+
args: {
|
170
|
+
handleScroll: fn(),
|
171
|
+
},
|
172
|
+
render: (args) => {
|
173
|
+
const ref = React.useRef(null);
|
174
|
+
return (<View gap={4}>
|
175
|
+
<View.Item>
|
176
|
+
<Button onClick={() => ref.current?.scrollBy({ top: 50, left: 50 })}>Scroll</Button>
|
177
|
+
</View.Item>
|
178
|
+
<ScrollArea height="100px" ref={ref} scrollbarDisplay="visible" onScroll={args.handleScroll}>
|
179
|
+
<View backgroundColor="neutral-faded" padding={4} width="1000px" height="200px">
|
180
|
+
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
|
181
|
+
has been the industry's standard dummy text ever since the 1500s, when an unknown
|
182
|
+
printer took a galley of type and scrambled it to make a type specimen book. It has
|
183
|
+
survived not only five centuries, but also the leap into electronic typesetting,
|
184
|
+
remaining essentially unchanged. It was popularised in the 1960s with the release of
|
185
|
+
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
|
186
|
+
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
|
187
|
+
</View>
|
188
|
+
</ScrollArea>
|
189
|
+
</View>);
|
190
|
+
},
|
191
|
+
play: async ({ canvas, args }) => {
|
192
|
+
const trigger = canvas.getAllByRole("button")[0];
|
193
|
+
await userEvent.click(trigger);
|
194
|
+
await waitFor(() => {
|
195
|
+
expect(args.handleScroll).toHaveBeenCalledTimes(1);
|
196
|
+
// x value is flaky, so only testing y here
|
197
|
+
expect(args.handleScroll).toHaveBeenCalledWith(expect.objectContaining({ y: 0.5 }));
|
198
|
+
});
|
199
|
+
},
|
200
|
+
};
|
201
|
+
export const className = {
|
202
|
+
name: "className, attributes",
|
203
|
+
render: () => (<div data-testid="root">
|
204
|
+
<ScrollArea className="test-classname" attributes={{ id: "test-id" }}>
|
205
|
+
Content
|
206
|
+
</ScrollArea>
|
207
|
+
</div>),
|
208
|
+
play: async ({ canvas }) => {
|
209
|
+
const root = canvas.getByTestId("root").firstChild;
|
210
|
+
expect(root).toHaveClass("test-classname");
|
211
|
+
expect(root).toHaveAttribute("id", "test-id");
|
212
|
+
},
|
213
|
+
};
|
214
|
+
export const testNested = {
|
215
|
+
name: "test: nested",
|
216
|
+
render: () => (<ScrollArea height="100px" scrollbarDisplay="visible">
|
217
|
+
<View padding={4} paddingInline={16}>
|
218
|
+
<ScrollArea height="200px" scrollbarDisplay="visible">
|
219
|
+
{Array(20)
|
114
220
|
.fill("")
|
115
221
|
.map((_, index) => {
|
116
222
|
return <div key={index}>Item {index + 1}</div>;
|
117
223
|
})}
|
118
|
-
</ScrollArea>
|
119
|
-
</View>
|
120
224
|
</ScrollArea>
|
121
|
-
</
|
122
|
-
</
|
225
|
+
</View>
|
226
|
+
</ScrollArea>),
|
123
227
|
};
|
124
|
-
export const
|
125
|
-
name: "
|
228
|
+
export const testDynamicHeight = {
|
229
|
+
name: "test: dynamic height change",
|
126
230
|
render: () => {
|
127
231
|
const [count, setCount] = React.useState(10);
|
128
232
|
return (<View gap={4}>
|
@@ -137,9 +241,4 @@ export const dynamicHeight = {
|
|
137
241
|
</ScrollArea>
|
138
242
|
</View>);
|
139
243
|
},
|
140
|
-
// TODO: After Using play(), Storybook makes the scroll lag, but not when triggered manually in the browser
|
141
|
-
// play: async ({ canvas }) => {
|
142
|
-
// const trigger = canvas.getAllByRole("button")[0];
|
143
|
-
// await userEvent.click(trigger);
|
144
|
-
// },
|
145
244
|
};
|
@@ -6,7 +6,7 @@ import { useFormControl } from "../FormControl/index.js";
|
|
6
6
|
import Actionable from "../Actionable/index.js";
|
7
7
|
import Text from "../Text/index.js";
|
8
8
|
import IconArrow from "../../icons/ChevronVertical.js";
|
9
|
-
import { classNames, responsiveClassNames, responsivePropDependency } from "../../utilities/
|
9
|
+
import { classNames, responsiveClassNames, responsivePropDependency } from "../../utilities/props.js";
|
10
10
|
import useElementId from "../../hooks/useElementId.js";
|
11
11
|
import s from "./Select.module.css";
|
12
12
|
const Select = (props) => {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { classNames } from "../../utilities/
|
2
|
+
import { classNames } from "../../utilities/props.js";
|
3
3
|
import View from "../View/index.js";
|
4
4
|
import s from "./Skeleton.module.css";
|
5
5
|
const Skeleton = (props) => {
|
@@ -4,23 +4,49 @@ export type SingleChangeArgs = {
|
|
4
4
|
minValue?: never;
|
5
5
|
maxValue?: never;
|
6
6
|
name: string;
|
7
|
+
minName?: never;
|
8
|
+
maxName?: never;
|
7
9
|
};
|
8
10
|
export type RangeChangeArgs = {
|
9
11
|
value?: never;
|
10
12
|
minValue: number;
|
11
13
|
maxValue: number;
|
12
14
|
name: string;
|
15
|
+
minName?: never;
|
16
|
+
maxName?: never;
|
13
17
|
};
|
14
|
-
type
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
export type NameRangeChangeArgs = {
|
19
|
+
value?: never;
|
20
|
+
minValue: number;
|
21
|
+
maxValue: number;
|
22
|
+
name?: never;
|
23
|
+
minName: string;
|
24
|
+
maxName: string;
|
18
25
|
};
|
19
26
|
type SingleSelectionProps = {
|
20
27
|
range?: false;
|
28
|
+
name: string;
|
29
|
+
minName?: never;
|
30
|
+
maxName?: never;
|
21
31
|
onChange?: (args: SingleChangeArgs) => void;
|
22
32
|
onChangeCommit?: (args: SingleChangeArgs) => void;
|
23
33
|
};
|
34
|
+
type RangeSelectionProps = {
|
35
|
+
range: true;
|
36
|
+
name: string;
|
37
|
+
minName?: never;
|
38
|
+
maxName?: never;
|
39
|
+
onChange?: (args: RangeChangeArgs) => void;
|
40
|
+
onChangeCommit?: (args: RangeChangeArgs) => void;
|
41
|
+
};
|
42
|
+
type NameRangeSelectionProps = {
|
43
|
+
range: true;
|
44
|
+
name?: never;
|
45
|
+
minName: string;
|
46
|
+
maxName: string;
|
47
|
+
onChange?: (args: RangeChangeArgs) => void;
|
48
|
+
onChangeCommit?: (args: RangeChangeArgs) => void;
|
49
|
+
};
|
24
50
|
type ControlledSingleProps = {
|
25
51
|
value: number;
|
26
52
|
defaultValue?: never;
|
@@ -42,7 +68,6 @@ type UncontrolledRangeProps = {
|
|
42
68
|
defaultMaxValue?: number;
|
43
69
|
};
|
44
70
|
type BaseProps = {
|
45
|
-
name: string;
|
46
71
|
step?: number;
|
47
72
|
disabled?: boolean;
|
48
73
|
min?: number;
|
@@ -54,8 +79,8 @@ type BaseProps = {
|
|
54
79
|
className?: G.ClassName;
|
55
80
|
attributes?: G.Attributes<"div">;
|
56
81
|
};
|
57
|
-
export type ControlledProps = BaseProps & ((ControlledSingleProps & SingleSelectionProps) | (ControlledRangeProps & RangeSelectionProps));
|
58
|
-
export type UncontrolledProps = BaseProps & ((UncontrolledSingleProps & SingleSelectionProps) | (UncontrolledRangeProps & RangeSelectionProps));
|
82
|
+
export type ControlledProps = BaseProps & ((ControlledSingleProps & SingleSelectionProps) | (ControlledRangeProps & (RangeSelectionProps | NameRangeSelectionProps)));
|
83
|
+
export type UncontrolledProps = BaseProps & ((UncontrolledSingleProps & SingleSelectionProps) | (UncontrolledRangeProps & (RangeSelectionProps | NameRangeSelectionProps)));
|
59
84
|
export type Props = ControlledProps | UncontrolledProps;
|
60
85
|
export type DefaultProps = {
|
61
86
|
min: number;
|
@@ -70,6 +95,7 @@ export type ThumbProps = {
|
|
70
95
|
position: number;
|
71
96
|
onChange: (value: number, options?: {
|
72
97
|
commit?: boolean;
|
98
|
+
native?: boolean;
|
73
99
|
}) => void;
|
74
100
|
onDragStart: (e: React.TouchEvent | React.MouseEvent) => void;
|
75
101
|
max: number;
|
@@ -78,5 +104,6 @@ export type ThumbProps = {
|
|
78
104
|
orientation: NonNullable<BaseProps["orientation"]>;
|
79
105
|
renderValue?: BaseProps["renderValue"];
|
80
106
|
tooltipRef: React.RefObject<HTMLDivElement | null>;
|
107
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
81
108
|
};
|
82
109
|
export {};
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use client";
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
3
3
|
import React from "react";
|
4
|
-
import { classNames } from "../../utilities/
|
5
|
-
import { enableUserSelect, disableUserSelect } from "../../utilities/dom/index.js";
|
4
|
+
import { classNames } from "../../utilities/props.js";
|
5
|
+
import { enableUserSelect, disableUserSelect, triggerChangeEvent } from "../../utilities/dom/index.js";
|
6
6
|
import { disableScroll, enableScroll } from "../../utilities/scroll/index.js";
|
7
7
|
import useRTL from "../../hooks/useRTL.js";
|
8
8
|
import useElementId from "../../hooks/useElementId.js";
|
@@ -19,11 +19,15 @@ const SliderControlled = (props) => {
|
|
19
19
|
const vertical = orientation === "vertical";
|
20
20
|
const minValue = range && props.minValue !== undefined ? applyStepToValue(props.minValue, step) : undefined;
|
21
21
|
const maxValue = applyStepToValue(range ? props.maxValue : props.value, step);
|
22
|
+
const minName = props.minName ?? props.name;
|
23
|
+
const maxName = props.maxName ?? props.name;
|
22
24
|
const barRef = React.useRef(null);
|
23
25
|
const minRef = React.useRef(null);
|
24
26
|
const maxRef = React.useRef(null);
|
25
27
|
const minTooltipRef = React.useRef(null);
|
26
28
|
const maxTooltipRef = React.useRef(null);
|
29
|
+
const minInputRef = React.useRef(null);
|
30
|
+
const maxInputRef = React.useRef(null);
|
27
31
|
const [draggingId, setDraggingId] = React.useState(null);
|
28
32
|
const [rtl] = useRTL();
|
29
33
|
const formControl = useFormControl();
|
@@ -68,7 +72,7 @@ const SliderControlled = (props) => {
|
|
68
72
|
const tooltipLeftSide = thumbRect && draggingRect && thumbRect.left - draggingRect.width / 2;
|
69
73
|
const tooltipRightSide = thumbRect && draggingRect && thumbRect.left + draggingRect.width / 2;
|
70
74
|
// Crosses the left slider boundary
|
71
|
-
if (tooltipLeftSide && barLeftSide && tooltipLeftSide < barLeftSide
|
75
|
+
if (tooltipLeftSide && barLeftSide && tooltipLeftSide < barLeftSide) {
|
72
76
|
nextTooltipOffset = draggingRect.width / 2 - 8;
|
73
77
|
}
|
74
78
|
// Crosses the right slider boundary
|
@@ -80,30 +84,38 @@ const SliderControlled = (props) => {
|
|
80
84
|
tooltipEl.style.setProperty("--rs-slider-tooltip-offset", `${nextTooltipOffset || 0}px`);
|
81
85
|
}
|
82
86
|
}, [minId, vertical]);
|
83
|
-
const handleMinChange = React.useCallback((value, options) => {
|
87
|
+
const handleMinChange = React.useCallback((value, options = {}) => {
|
84
88
|
if (!range)
|
85
89
|
return;
|
86
|
-
const
|
90
|
+
const args = { minValue: value, maxValue, name, minName, maxName };
|
87
91
|
// Manually controlled resolving of single/range handlers
|
88
92
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
89
93
|
// @ts-ignore
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
if (options.commit)
|
95
|
+
onChangeCommitRef.current?.(args);
|
96
|
+
// Manually controlled resolving of single/range handlers
|
97
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
98
|
+
// @ts-ignore
|
99
|
+
if (options.native)
|
100
|
+
onChangeRef.current?.(args);
|
101
|
+
triggerChangeEvent(minInputRef.current, value.toString());
|
102
|
+
}, [maxValue, name, minName, maxName, range, onChangeCommitRef, onChangeRef]);
|
103
|
+
const handleMaxChange = React.useCallback((value, options = {}) => {
|
104
|
+
const args = range
|
105
|
+
? { minValue: minValue, maxValue: value, name, minName, maxName }
|
106
|
+
: { value, name };
|
107
|
+
// Manually controlled resolving of single/range handlers
|
108
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
109
|
+
// @ts-ignore
|
110
|
+
if (options.commit)
|
111
|
+
onChangeCommitRef.current?.(args);
|
102
112
|
// Manually controlled resolving of single/range handlers
|
103
113
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
104
114
|
// @ts-ignore
|
105
|
-
|
106
|
-
|
115
|
+
if (options.native)
|
116
|
+
onChangeRef.current?.(args);
|
117
|
+
triggerChangeEvent(maxInputRef.current, value.toString());
|
118
|
+
}, [minValue, name, minName, maxName, range, onChangeRef, onChangeCommitRef]);
|
107
119
|
const handleMouseDown = ({ nativeEvent }) => {
|
108
120
|
if (disabled)
|
109
121
|
return;
|
@@ -213,7 +225,7 @@ const SliderControlled = (props) => {
|
|
213
225
|
_jsxs("div", { ...attributes, className: rootClassNames, onMouseDown: handleMouseDown, onTouchStart: handleMouseDown, children: [_jsx("div", { className: s.bar, ref: barRef, children: _jsx("div", { className: s.selection, style: {
|
214
226
|
"--rs-slider-selection-start": `${minPercentPosition || 0}%`,
|
215
227
|
"--rs-slider-selection-size": `${maxPercentPosition - (minPercentPosition || 0)}%`,
|
216
|
-
} }) }), _jsxs("div", { className: s.thumbs, children: [minValue !== undefined && minPercentPosition !== undefined && (_jsx(SliderThumb, { id: minId, active: minId === draggingId, name:
|
228
|
+
} }) }), _jsxs("div", { className: s.thumbs, children: [minValue !== undefined && minPercentPosition !== undefined && (_jsx(SliderThumb, { id: minId, active: minId === draggingId, name: minName, disabled: disabled, onChange: handleMinChange, value: minValue, onDragStart: handleMinDragStart, position: minPercentPosition, max: max, min: min, ref: minRef, tooltipRef: minTooltipRef, inputRef: minInputRef, renderValue: renderValue, step: step, orientation: orientation })), _jsx(SliderThumb, { id: maxId, active: maxId === draggingId, name: maxName, disabled: disabled, onChange: handleMaxChange, value: maxValue, onDragStart: handleMaxDragStart, position: maxPercentPosition, max: max, min: min, ref: maxRef, tooltipRef: maxTooltipRef, inputRef: maxInputRef, renderValue: renderValue, step: step, orientation: orientation })] })] }));
|
217
229
|
};
|
218
230
|
SliderControlled.displayName = "SliderControlled";
|
219
231
|
export default SliderControlled;
|
@@ -1,21 +1,21 @@
|
|
1
1
|
"use client";
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
3
3
|
import React from "react";
|
4
|
-
import { classNames } from "../../utilities/
|
4
|
+
import { classNames } from "../../utilities/props.js";
|
5
5
|
import Theme from "../Theme/index.js";
|
6
6
|
import Text from "../Text/index.js";
|
7
7
|
import { getPrecision } from "./Slider.utilities.js";
|
8
8
|
import s from "./Slider.module.css";
|
9
9
|
const SliderThumb = React.forwardRef((props, ref) => {
|
10
|
-
const { name, value, disabled, active, position, max, min, step, onChange, onDragStart, renderValue, tooltipRef, orientation, } = props;
|
10
|
+
const { name, value, disabled, active, position, max, min, step, onChange, onDragStart, renderValue, tooltipRef, inputRef, orientation, } = props;
|
11
11
|
const id = React.useId();
|
12
12
|
const thumbClassNames = classNames(s.thumb, active && s["thumb--active"]);
|
13
13
|
const precision = getPrecision(step);
|
14
14
|
const tooltipValue = renderValue ? renderValue({ value }) : value.toFixed(precision);
|
15
15
|
const handleChange = (e) => {
|
16
|
-
onChange(+e.target.value);
|
16
|
+
onChange(+e.target.value, { native: true });
|
17
17
|
};
|
18
|
-
return (_jsxs(_Fragment, { children: [_jsx("input", { className: s.input, type: "range", name: name, value: value, onChange: handleChange, disabled: disabled, max: max, min: min, step: step, "aria-labelledby": id, "aria-orientation": orientation }), _jsx("div", { ref: ref, className: thumbClassNames, onMouseDown: onDragStart, onTouchStart: onDragStart, style: { "--ts-slider-thumb-position": `${position}%` }, id: id, "aria-hidden": "true", children: renderValue !== false && (_jsx(Theme, { colorMode: "inverted", children: _jsx(Text, { variant: "caption-1", weight: "medium", className: s.tooltip, attributes: { ref: tooltipRef }, children: tooltipValue }) })) })] }));
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { className: s.input, type: "range", name: name, value: value, onChange: handleChange, disabled: disabled, max: max, min: min, step: step, "aria-labelledby": id, "aria-orientation": orientation, ref: inputRef }), _jsx("div", { ref: ref, className: thumbClassNames, onMouseDown: onDragStart, onTouchStart: onDragStart, style: { "--ts-slider-thumb-position": `${position}%` }, id: id, "aria-hidden": "true", children: renderValue !== false && (_jsx(Theme, { colorMode: "inverted", children: _jsx(Text, { variant: "caption-1", weight: "medium", className: s.tooltip, attributes: { ref: tooltipRef }, children: tooltipValue }) })) })] }));
|
19
19
|
});
|
20
20
|
SliderThumb.displayName = "SliderThumb";
|
21
21
|
export default SliderThumb;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
3
3
|
import React from "react";
|
4
4
|
import SliderControlled from "./SliderControlled.js";
|
5
|
+
const normalizeValue = (value, min, max) => Math.min(Math.max(value, min), max);
|
5
6
|
const SliderUncontrolled = (props) => {
|
6
7
|
const { min, max, onChange, range } = props;
|
7
8
|
const defaultMinValue = ("defaultMinValue" in props && props.defaultMinValue !== undefined && props.defaultMinValue) ||
|
@@ -10,8 +11,8 @@ const SliderUncontrolled = (props) => {
|
|
10
11
|
const defaultMaxValue = ("defaultMaxValue" in props && props.defaultMaxValue !== undefined && props.defaultMaxValue) ||
|
11
12
|
("defaultValue" in props && props.defaultValue !== undefined && props.defaultValue) ||
|
12
13
|
(range ? max : min);
|
13
|
-
const [minValue, setMinValue] = React.useState(defaultMinValue);
|
14
|
-
const [maxValue, setMaxValue] = React.useState(defaultMaxValue);
|
14
|
+
const [minValue, setMinValue] = React.useState(normalizeValue(defaultMinValue, min, max));
|
15
|
+
const [maxValue, setMaxValue] = React.useState(normalizeValue(defaultMaxValue, min, max));
|
15
16
|
const handleSingleChange = (args) => {
|
16
17
|
if (range)
|
17
18
|
return;
|
@@ -1,6 +1,9 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { StoryObj } from "@storybook/react";
|
3
|
+
import { Mock } from "@storybook/test";
|
1
4
|
declare const _default: {
|
2
5
|
title: string;
|
3
|
-
component:
|
6
|
+
component: React.FC<import("./..").SliderProps>;
|
4
7
|
parameters: {
|
5
8
|
iframe: {
|
6
9
|
url: string;
|
@@ -8,10 +11,37 @@ declare const _default: {
|
|
8
11
|
};
|
9
12
|
};
|
10
13
|
export default _default;
|
11
|
-
export declare const base:
|
12
|
-
export declare const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
export declare const
|
17
|
-
export declare const
|
14
|
+
export declare const base: StoryObj;
|
15
|
+
export declare const orientation: {
|
16
|
+
name: string;
|
17
|
+
render: () => React.JSX.Element;
|
18
|
+
};
|
19
|
+
export declare const minMax: StoryObj;
|
20
|
+
export declare const step: StoryObj;
|
21
|
+
export declare const disabled: StoryObj;
|
22
|
+
export declare const renderValue: StoryObj;
|
23
|
+
export declare const defaultValue: StoryObj<{
|
24
|
+
handleChange: Mock;
|
25
|
+
handleChangeCommit: Mock;
|
26
|
+
}>;
|
27
|
+
export declare const value: StoryObj<{
|
28
|
+
handleChange: Mock;
|
29
|
+
handleChangeCommit: Mock;
|
30
|
+
}>;
|
31
|
+
export declare const rangeDefaultValue: StoryObj<{
|
32
|
+
handleChange: Mock;
|
33
|
+
handleChangeCommit: Mock;
|
34
|
+
}>;
|
35
|
+
export declare const rangeValue: StoryObj<{
|
36
|
+
handleChange: Mock;
|
37
|
+
handleChangeCommit: Mock;
|
38
|
+
}>;
|
39
|
+
export declare const className: StoryObj;
|
40
|
+
export declare const testForm: StoryObj<{
|
41
|
+
handleFormChange: Mock;
|
42
|
+
handleFormInit: Mock;
|
43
|
+
}>;
|
44
|
+
export declare const testSwipe: {
|
45
|
+
name: string;
|
46
|
+
render: () => React.JSX.Element;
|
47
|
+
};
|