@react5/ui 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/package.json +38 -38
- package/packages/app/README.md +50 -50
- package/packages/app/eslint.config.js +28 -28
- package/packages/app/index.html +13 -13
- package/packages/app/jest.config.js +12 -12
- package/packages/app/package.json +36 -36
- package/packages/app/src/App.css +5 -5
- package/packages/app/src/App.tsx +35 -35
- package/packages/app/src/i18n/config.ts +21 -21
- package/packages/app/src/i18n/en/translation.json +4 -4
- package/packages/app/src/i18n/fr/translation.json +4 -4
- package/packages/app/src/i18n/index.ts +3 -3
- package/packages/app/src/main.tsx +16 -16
- package/packages/app/src/styles/1-reset.scss +72 -72
- package/packages/app/src/styles/2-colors.scss +11 -11
- package/packages/app/src/vite-env.d.ts +1 -1
- package/packages/app/tsconfig.app.json +26 -26
- package/packages/app/tsconfig.json +7 -7
- package/packages/app/tsconfig.node.json +24 -24
- package/packages/app/vite.config.ts +7 -7
- package/packages/lib/.babelrc +9 -9
- package/packages/lib/.storybook/main.js +50 -50
- package/packages/lib/.storybook/preview.js +13 -13
- package/packages/lib/declaration.d.ts +9 -9
- package/packages/lib/dist/esm/index.esm.scss +1326 -1326
- package/packages/lib/dist/index.scss +1326 -1326
- package/packages/lib/dist/types/hooks/use-form.d.ts +1 -1
- package/packages/lib/dist/types/hooks/use-form.d.ts.map +1 -1
- package/packages/lib/jest.config.js +19 -19
- package/packages/lib/package.json +110 -110
- package/packages/lib/plop/component/index.js +43 -43
- package/packages/lib/plop/index.js +3 -3
- package/packages/lib/plop/templates/component/component.hbs +19 -19
- package/packages/lib/plop/templates/component/index.hbs +1 -1
- package/packages/lib/plop/templates/component/stories.hbs +17 -17
- package/packages/lib/plop/templates/component/style.hbs +1 -1
- package/packages/lib/plop/templates/component/test.hbs +11 -11
- package/packages/lib/plopfile.js +1 -1
- package/packages/lib/rollup.config.mjs +64 -64
- package/packages/lib/src/components/Accordion/Accordion.scss +67 -67
- package/packages/lib/src/components/Accordion/Accordion.tsx +36 -36
- package/packages/lib/src/components/Button/Button.scss +42 -42
- package/packages/lib/src/components/Button/Button.stories.tsx +26 -26
- package/packages/lib/src/components/Button/Button.tsx +40 -40
- package/packages/lib/src/components/Button/index.tsx +1 -1
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.scss +3 -3
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.stories.tsx +17 -17
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.test.tsx +11 -11
- package/packages/lib/src/components/ButtonsGroup/ButtonsGroup.tsx +17 -17
- package/packages/lib/src/components/ButtonsGroup/index.tsx +1 -1
- package/packages/lib/src/components/CheckBox/CheckBox.scss +63 -63
- package/packages/lib/src/components/CheckBox/CheckBox.stories.tsx +22 -22
- package/packages/lib/src/components/CheckBox/CheckBox.tsx +42 -42
- package/packages/lib/src/components/CheckBox/index.tsx +1 -1
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.scss +6 -6
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.stories.tsx +17 -17
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.test.tsx +11 -11
- package/packages/lib/src/components/DialogPrompt/DialogPrompt.tsx +41 -41
- package/packages/lib/src/components/DialogPrompt/index.tsx +1 -1
- package/packages/lib/src/components/Divider/Divider.scss +22 -22
- package/packages/lib/src/components/Divider/Divider.tsx +20 -20
- package/packages/lib/src/components/DropDown/DropDown.scss +70 -70
- package/packages/lib/src/components/DropDown/DropDown.stories.tsx +45 -45
- package/packages/lib/src/components/DropDown/DropDown.tsx +61 -61
- package/packages/lib/src/components/DropDown/index.tsx +1 -1
- package/packages/lib/src/components/Form/Form.scss +3 -3
- package/packages/lib/src/components/Form/Form.stories.tsx +20 -20
- package/packages/lib/src/components/Form/Form.tsx +25 -25
- package/packages/lib/src/components/FormButtons/FormButtons.scss +5 -5
- package/packages/lib/src/components/FormButtons/FormButtons.tsx +18 -18
- package/packages/lib/src/components/IconButton/IconButton.scss +64 -64
- package/packages/lib/src/components/IconButton/IconButton.tsx +44 -44
- package/packages/lib/src/components/MenuItem/MenuItem.scss +13 -13
- package/packages/lib/src/components/MenuItem/MenuItem.tsx +36 -36
- package/packages/lib/src/components/Modal/Modal.scss +71 -71
- package/packages/lib/src/components/Modal/Modal.tsx +60 -60
- package/packages/lib/src/components/Navbar/Navbar.scss +52 -52
- package/packages/lib/src/components/Navbar/Navbar.stories.tsx +25 -25
- package/packages/lib/src/components/Navbar/Navbar.tsx +38 -38
- package/packages/lib/src/components/NavbarLink/NavbarLink.scss +15 -15
- package/packages/lib/src/components/NavbarLink/NavbarLink.tsx +34 -34
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.scss +156 -156
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.stories.tsx +24 -24
- package/packages/lib/src/components/NavbarMenu/NavbarMenu.tsx +72 -72
- package/packages/lib/src/components/Panel/Panel.scss +4 -4
- package/packages/lib/src/components/Panel/Panel.stories.tsx +17 -17
- package/packages/lib/src/components/Panel/Panel.test.tsx +11 -11
- package/packages/lib/src/components/Panel/Panel.tsx +18 -18
- package/packages/lib/src/components/Panel/index.tsx +1 -1
- package/packages/lib/src/components/Paper/Paper.scss +5 -5
- package/packages/lib/src/components/Paper/Paper.stories.tsx +18 -18
- package/packages/lib/src/components/Paper/Paper.tsx +18 -18
- package/packages/lib/src/components/Paper/index.tsx +1 -1
- package/packages/lib/src/components/RangeSlider/RangeSlider.scss +83 -83
- package/packages/lib/src/components/RangeSlider/RangeSlider.stories.tsx +24 -24
- package/packages/lib/src/components/RangeSlider/RangeSlider.tsx +150 -150
- package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.scss +72 -72
- package/packages/lib/src/components/ResponsiveBar/ResponsiveBar.tsx +38 -38
- package/packages/lib/src/components/ScrollView/ScrollView.scss +20 -20
- package/packages/lib/src/components/ScrollView/ScrollView.stories.tsx +17 -17
- package/packages/lib/src/components/ScrollView/ScrollView.test.tsx +11 -11
- package/packages/lib/src/components/ScrollView/ScrollView.tsx +19 -19
- package/packages/lib/src/components/ScrollView/index.tsx +1 -1
- package/packages/lib/src/components/Section/Section.scss +17 -17
- package/packages/lib/src/components/Section/Section.tsx +26 -26
- package/packages/lib/src/components/SelectField/SelectField.scss +33 -33
- package/packages/lib/src/components/SelectField/SelectField.stories.tsx +14 -14
- package/packages/lib/src/components/SelectField/SelectField.tsx +53 -53
- package/packages/lib/src/components/SelectField/index.tsx +1 -1
- package/packages/lib/src/components/Spacer/Spacer.scss +2 -2
- package/packages/lib/src/components/Spacer/Spacer.tsx +6 -6
- package/packages/lib/src/components/StackPanel/StackPanel.scss +8 -8
- package/packages/lib/src/components/StackPanel/StackPanel.stories.tsx +17 -17
- package/packages/lib/src/components/StackPanel/StackPanel.test.tsx +11 -11
- package/packages/lib/src/components/StackPanel/StackPanel.tsx +31 -31
- package/packages/lib/src/components/StackPanel/index.tsx +1 -1
- package/packages/lib/src/components/Submenu/Submenu.scss +55 -55
- package/packages/lib/src/components/Submenu/Submenu.stories.tsx +45 -45
- package/packages/lib/src/components/Submenu/Submenu.tsx +59 -59
- package/packages/lib/src/components/Submenu/index.tsx +1 -1
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.scss +75 -75
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.stories.tsx +17 -17
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.test.tsx +11 -11
- package/packages/lib/src/components/SuccessCongratulation/SuccessCongratulation.tsx +63 -63
- package/packages/lib/src/components/SuccessCongratulation/index.tsx +1 -1
- package/packages/lib/src/components/TextArea/TextArea.scss +33 -33
- package/packages/lib/src/components/TextArea/TextArea.stories.tsx +14 -14
- package/packages/lib/src/components/TextArea/TextArea.tsx +49 -49
- package/packages/lib/src/components/TextArea/index.tsx +1 -1
- package/packages/lib/src/components/TextField/TextField.scss +48 -48
- package/packages/lib/src/components/TextField/TextField.stories.tsx +14 -14
- package/packages/lib/src/components/TextField/TextField.tsx +86 -86
- package/packages/lib/src/components/TextField/index.tsx +1 -1
- package/packages/lib/src/components/TitleEdit/TitleEdit.scss +17 -17
- package/packages/lib/src/components/TitleEdit/TitleEdit.tsx +69 -69
- package/packages/lib/src/components/Toast/Toast.scss +32 -32
- package/packages/lib/src/components/Toast/Toast.tsx +29 -29
- package/packages/lib/src/components/ToggleButton/ToggleButton.scss +47 -47
- package/packages/lib/src/components/ToggleButton/ToggleButton.stories.tsx +22 -22
- package/packages/lib/src/components/ToggleButton/ToggleButton.tsx +41 -41
- package/packages/lib/src/components/ToggleButton/index.tsx +1 -1
- package/packages/lib/src/components/Toolbar/Toolbar.scss +16 -16
- package/packages/lib/src/components/Toolbar/Toolbar.stories.tsx +17 -17
- package/packages/lib/src/components/Toolbar/Toolbar.test.tsx +11 -11
- package/packages/lib/src/components/Toolbar/Toolbar.tsx +20 -20
- package/packages/lib/src/components/Toolbar/index.tsx +1 -1
- package/packages/lib/src/components/Typography/Typography.scss +51 -51
- package/packages/lib/src/components/Typography/Typography.stories.tsx +18 -18
- package/packages/lib/src/components/Typography/Typography.tsx +19 -19
- package/packages/lib/src/components/index.tsx +33 -33
- package/packages/lib/src/hooks/index.tsx +3 -3
- package/packages/lib/src/hooks/use-click-outside.tsx +19 -19
- package/packages/lib/src/hooks/use-form.tsx +107 -107
- package/packages/lib/src/hooks/use-keys-enteresc.tsx +25 -25
- package/packages/lib/src/hooks/use-set-startup-focus.tsx +8 -8
- package/packages/lib/src/i18n/config.ts +8 -8
- package/packages/lib/src/i18n/en/translation.json +11 -11
- package/packages/lib/src/i18n/fr/translation.json +11 -11
- package/packages/lib/src/i18n/index.ts +11 -11
- package/packages/lib/src/index.tsx +7 -7
- package/packages/lib/src/stories/Intrduction.mdx +175 -175
- package/packages/lib/src/stories/assets/github.svg +3 -3
- package/packages/lib/src/styles/1-color-vars.scss +50 -50
- package/packages/lib/src/styles/2-font-variables.scss +2 -2
- package/packages/lib/src/styles/variables.scss +1 -1
- package/packages/lib/src/test/i18n.ts +17 -17
- package/packages/lib/src/utils/bem.ts +4 -4
- package/packages/lib/src/utils/formatError.ts +5 -5
- package/packages/lib/src/utils/index.ts +1 -1
- package/packages/lib/src/utils/interfaces.ts +5 -5
- package/packages/lib/tsconfig.json +25 -25
- package/packages/lib/vite.config.js +18 -18
- package/packages/ui-test/package-lock.json +97 -97
- package/packages/ui-test/package.json +19 -19
- package/packages/ui-test/playwright.config.ts +80 -80
- package/packages/ui-test/tests/example.spec.ts +18 -18
- package/packages/ui-test/tests-examples/demo-todo-app.spec.ts +437 -437
- package/packages/lib/dist/esm/index.esm.js.map +0 -1
- package/packages/lib/dist/index.js.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import clsx from "clsx";
|
|
2
|
-
import "./Paper.scss";
|
|
3
|
-
import type { ReactNode } from "react";
|
|
4
|
-
import { bem } from '../../utils/bem';
|
|
5
|
-
|
|
6
|
-
export interface IPaperProps {
|
|
7
|
-
className?: string;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const b = bem("paper");
|
|
12
|
-
export const Paper = ({children, className}: IPaperProps) => {
|
|
13
|
-
return (<div className={clsx(b(), className)}>
|
|
14
|
-
{children}
|
|
15
|
-
</div>)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default Paper
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import "./Paper.scss";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { bem } from '../../utils/bem';
|
|
5
|
+
|
|
6
|
+
export interface IPaperProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const b = bem("paper");
|
|
12
|
+
export const Paper = ({children, className}: IPaperProps) => {
|
|
13
|
+
return (<div className={clsx(b(), className)}>
|
|
14
|
+
{children}
|
|
15
|
+
</div>)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Paper
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Paper"
|
|
1
|
+
export * from "./Paper"
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
.r5ui-range-slider {
|
|
2
|
-
display: flex;
|
|
3
|
-
width: 100%;
|
|
4
|
-
padding: 0 1em;
|
|
5
|
-
align-items: center;
|
|
6
|
-
flex-direction: column;
|
|
7
|
-
|
|
8
|
-
&__track {
|
|
9
|
-
position: relative;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 6px;
|
|
12
|
-
background-color: $primary_border_color;
|
|
13
|
-
border-radius: 3px;
|
|
14
|
-
cursor: pointer;
|
|
15
|
-
margin: 0 10px;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
&__range {
|
|
19
|
-
position: absolute;
|
|
20
|
-
height: 100%;
|
|
21
|
-
background-color: $primary_bg_color_highlight;
|
|
22
|
-
border-radius: 3px;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
&__thumb {
|
|
26
|
-
position: absolute;
|
|
27
|
-
top: 200%;
|
|
28
|
-
transform: translate(-50%, 0);
|
|
29
|
-
width: 20px;
|
|
30
|
-
height: 20px;
|
|
31
|
-
background-color: $secondary_color;
|
|
32
|
-
border-radius: 3px;
|
|
33
|
-
border: $border_size solid $primary_border_color;
|
|
34
|
-
cursor: pointer;
|
|
35
|
-
|
|
36
|
-
&::before {
|
|
37
|
-
content: '';
|
|
38
|
-
position: absolute;
|
|
39
|
-
top: -7px; // Position the tip above the rectangle
|
|
40
|
-
left: 50%;
|
|
41
|
-
transform: translateX(-50%);
|
|
42
|
-
border-left: 7px solid transparent;
|
|
43
|
-
border-right: 7px solid transparent;
|
|
44
|
-
border-bottom: 7px solid $secondary_color;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
&:hover {
|
|
48
|
-
background-color: $primary_text_color_highlight;
|
|
49
|
-
&::before {
|
|
50
|
-
border-bottom-color: $primary_text_color_highlight;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
&--min {
|
|
55
|
-
z-index: 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
&--max {
|
|
59
|
-
z-index: 2;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
&__values {
|
|
64
|
-
display: flex;
|
|
65
|
-
justify-content: space-between;
|
|
66
|
-
width: 100%;
|
|
67
|
-
margin-top: 25px;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
&__value-field {
|
|
71
|
-
width: 8em;
|
|
72
|
-
margin: 0 4px;
|
|
73
|
-
}
|
|
74
|
-
&__value {
|
|
75
|
-
display: flex;
|
|
76
|
-
flex-direction: row;
|
|
77
|
-
font-size: 1rem;
|
|
78
|
-
color: $primary_text_color;
|
|
79
|
-
align-items: center;
|
|
80
|
-
}
|
|
81
|
-
&__pick-button {
|
|
82
|
-
margin-right: 0;
|
|
83
|
-
}
|
|
1
|
+
.r5ui-range-slider {
|
|
2
|
+
display: flex;
|
|
3
|
+
width: 100%;
|
|
4
|
+
padding: 0 1em;
|
|
5
|
+
align-items: center;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
|
|
8
|
+
&__track {
|
|
9
|
+
position: relative;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 6px;
|
|
12
|
+
background-color: $primary_border_color;
|
|
13
|
+
border-radius: 3px;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
margin: 0 10px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__range {
|
|
19
|
+
position: absolute;
|
|
20
|
+
height: 100%;
|
|
21
|
+
background-color: $primary_bg_color_highlight;
|
|
22
|
+
border-radius: 3px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__thumb {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 200%;
|
|
28
|
+
transform: translate(-50%, 0);
|
|
29
|
+
width: 20px;
|
|
30
|
+
height: 20px;
|
|
31
|
+
background-color: $secondary_color;
|
|
32
|
+
border-radius: 3px;
|
|
33
|
+
border: $border_size solid $primary_border_color;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
|
|
36
|
+
&::before {
|
|
37
|
+
content: '';
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: -7px; // Position the tip above the rectangle
|
|
40
|
+
left: 50%;
|
|
41
|
+
transform: translateX(-50%);
|
|
42
|
+
border-left: 7px solid transparent;
|
|
43
|
+
border-right: 7px solid transparent;
|
|
44
|
+
border-bottom: 7px solid $secondary_color;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&:hover {
|
|
48
|
+
background-color: $primary_text_color_highlight;
|
|
49
|
+
&::before {
|
|
50
|
+
border-bottom-color: $primary_text_color_highlight;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&--min {
|
|
55
|
+
z-index: 1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&--max {
|
|
59
|
+
z-index: 2;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&__values {
|
|
64
|
+
display: flex;
|
|
65
|
+
justify-content: space-between;
|
|
66
|
+
width: 100%;
|
|
67
|
+
margin-top: 25px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&__value-field {
|
|
71
|
+
width: 8em;
|
|
72
|
+
margin: 0 4px;
|
|
73
|
+
}
|
|
74
|
+
&__value {
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: row;
|
|
77
|
+
font-size: 1rem;
|
|
78
|
+
color: $primary_text_color;
|
|
79
|
+
align-items: center;
|
|
80
|
+
}
|
|
81
|
+
&__pick-button {
|
|
82
|
+
margin-right: 0;
|
|
83
|
+
}
|
|
84
84
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
|
|
3
|
-
import { RangeSlider } from './RangeSlider';
|
|
4
|
-
|
|
5
|
-
const meta: Meta<typeof RangeSlider> = {
|
|
6
|
-
component: RangeSlider,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default meta;
|
|
10
|
-
type Story = StoryObj<typeof RangeSlider>;
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
|
14
|
-
* See https://storybook.js.org/docs/react/api/csf
|
|
15
|
-
* to learn how to use render functions.
|
|
16
|
-
*/
|
|
17
|
-
const menuItems = [{ to: '/about', title: 'About' }];
|
|
18
|
-
export const Primary: Story = {
|
|
19
|
-
render: () => (
|
|
20
|
-
<div style={{ backgroundColor: '#ccc' }}>
|
|
21
|
-
<RangeSlider onChange={(v) => console.log(v)}></RangeSlider>
|
|
22
|
-
</div>
|
|
23
|
-
),
|
|
24
|
-
};
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
|
|
3
|
+
import { RangeSlider } from './RangeSlider';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof RangeSlider> = {
|
|
6
|
+
component: RangeSlider,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
type Story = StoryObj<typeof RangeSlider>;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
|
|
14
|
+
* See https://storybook.js.org/docs/react/api/csf
|
|
15
|
+
* to learn how to use render functions.
|
|
16
|
+
*/
|
|
17
|
+
const menuItems = [{ to: '/about', title: 'About' }];
|
|
18
|
+
export const Primary: Story = {
|
|
19
|
+
render: () => (
|
|
20
|
+
<div style={{ backgroundColor: '#ccc' }}>
|
|
21
|
+
<RangeSlider onChange={(v) => console.log(v)}></RangeSlider>
|
|
22
|
+
</div>
|
|
23
|
+
),
|
|
24
|
+
};
|
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import './RangeSlider.scss';
|
|
3
|
-
import '@react5/time-span/packages/lib/dist/index.css'
|
|
4
|
-
import { bem } from '../../utils/bem';
|
|
5
|
-
import clsx from 'clsx';
|
|
6
|
-
import { FaArrowRightFromBracket, FaArrowRightToBracket } from "react-icons/fa6"
|
|
7
|
-
import { IconButton } from '../IconButton';
|
|
8
|
-
import { TimeSpanInput } from '@react5/time-span';
|
|
9
|
-
|
|
10
|
-
interface RangeSliderProps {
|
|
11
|
-
min?: number;
|
|
12
|
-
max?: number;
|
|
13
|
-
step?: number;
|
|
14
|
-
from?: number;
|
|
15
|
-
to?: number;
|
|
16
|
-
pickFromLabel?: string;
|
|
17
|
-
pickToLabel?: string;
|
|
18
|
-
onPickTo?: () => void;
|
|
19
|
-
onPickFrom?: () => void;
|
|
20
|
-
onChange?: (from: number, to: number) => void;
|
|
21
|
-
}
|
|
22
|
-
const b = bem("range-slider")
|
|
23
|
-
export const RangeSlider: React.FC<RangeSliderProps> = ({ min = 0, max = 1 * 60 * 60, step = 1,
|
|
24
|
-
from = min, to = max, onChange, onPickFrom, onPickTo, pickFromLabel, pickToLabel }) => {
|
|
25
|
-
const [fromValue, setFromValue] = useState<number>(from);
|
|
26
|
-
const [toValue, setToValue] = useState<number>(to);
|
|
27
|
-
const trackRef = useRef<HTMLDivElement>(null);
|
|
28
|
-
const activeThumb = useRef<'min' | 'max' | null>(null);
|
|
29
|
-
const moveCallback = useCallback(
|
|
30
|
-
(x: number) => {
|
|
31
|
-
handleMove(x);
|
|
32
|
-
},
|
|
33
|
-
[],
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
const getPercentage = (value: number) => ((value - min) / (max - min)) * 100;
|
|
37
|
-
|
|
38
|
-
const handleMove = (clientX: number) => {
|
|
39
|
-
if (!trackRef.current || !activeThumb.current) return;
|
|
40
|
-
|
|
41
|
-
const trackRect = trackRef.current.getBoundingClientRect();
|
|
42
|
-
const position = clientX - trackRect.left;
|
|
43
|
-
const newPercentage = Math.min(Math.max(position / trackRect.width, 0), 1);
|
|
44
|
-
const newValue = Math.round((min + newPercentage * (max - min)) / step) * step;
|
|
45
|
-
|
|
46
|
-
if (activeThumb.current === 'min') {
|
|
47
|
-
if (newValue < toValue) {
|
|
48
|
-
setFromValue(newValue);
|
|
49
|
-
}
|
|
50
|
-
} else if (activeThumb.current === 'max') {
|
|
51
|
-
if (newValue > fromValue) {
|
|
52
|
-
setToValue(newValue);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const handleMouseUp = () => {
|
|
58
|
-
if (onChange) {
|
|
59
|
-
onChange(fromValue, toValue);
|
|
60
|
-
}
|
|
61
|
-
activeThumb.current = null;
|
|
62
|
-
document.removeEventListener('mousemove', handleMouseMove);
|
|
63
|
-
//document.removeEventListener('mouseup', handleMouseUp);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const handleMouseMove = (e: MouseEvent) => {
|
|
67
|
-
moveCallback(e.clientX);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const handleMouseDown = (thumb: 'min' | 'max') => (e: React.MouseEvent) => {
|
|
71
|
-
activeThumb.current = thumb;
|
|
72
|
-
handleMove(e.clientX);
|
|
73
|
-
document.addEventListener('mousemove', handleMouseMove);
|
|
74
|
-
//document.addEventListener('mouseup', handleMouseUp);
|
|
75
|
-
};
|
|
76
|
-
const handleFromValueChange = (v: number) => {
|
|
77
|
-
setFromValue(v);
|
|
78
|
-
onChange && onChange(v, toValue)
|
|
79
|
-
}
|
|
80
|
-
const handleToValueChange = (v: number) => {
|
|
81
|
-
setToValue(v)
|
|
82
|
-
onChange && onChange(fromValue, v)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
setFromValue(from);
|
|
87
|
-
setToValue(to);
|
|
88
|
-
}, [from, to]);
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<div className={b()}>
|
|
92
|
-
<div ref={trackRef} className={b("track")}>
|
|
93
|
-
<div
|
|
94
|
-
className={b("range")}
|
|
95
|
-
style={{
|
|
96
|
-
left: `${getPercentage(fromValue)}%`,
|
|
97
|
-
right: `${100 - getPercentage(toValue)}%`,
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
<div
|
|
101
|
-
className={clsx(b("thumb"), b("thumb", "min"))}
|
|
102
|
-
style={{ left: `${getPercentage(fromValue)}%` }}
|
|
103
|
-
onMouseDown={handleMouseDown('min')}
|
|
104
|
-
onMouseUp={handleMouseUp}
|
|
105
|
-
/>
|
|
106
|
-
<div
|
|
107
|
-
className={clsx(b("thumb"), b("thumb", "max"))}
|
|
108
|
-
style={{ left: `${getPercentage(toValue)}%` }}
|
|
109
|
-
onMouseDown={handleMouseDown('max')}
|
|
110
|
-
onMouseUp={handleMouseUp}
|
|
111
|
-
/>
|
|
112
|
-
</div>
|
|
113
|
-
<div className={b("values")}>
|
|
114
|
-
<span className={b("value")}>
|
|
115
|
-
<TimeSpanInput
|
|
116
|
-
className={b("value-field")}
|
|
117
|
-
step={step || 2}
|
|
118
|
-
value={fromValue}
|
|
119
|
-
onChange={handleFromValueChange}
|
|
120
|
-
/>
|
|
121
|
-
<IconButton
|
|
122
|
-
className={b("pick-button")}
|
|
123
|
-
variant='round-outlined'
|
|
124
|
-
title={pickFromLabel}
|
|
125
|
-
onClick={onPickFrom}
|
|
126
|
-
>
|
|
127
|
-
<FaArrowRightFromBracket/>
|
|
128
|
-
</IconButton>
|
|
129
|
-
</span>
|
|
130
|
-
<span className={b("value")}>
|
|
131
|
-
<IconButton
|
|
132
|
-
className={b("pick-button")}
|
|
133
|
-
variant='round-outlined'
|
|
134
|
-
title={pickToLabel}
|
|
135
|
-
onClick={onPickTo}
|
|
136
|
-
>
|
|
137
|
-
<FaArrowRightToBracket/>
|
|
138
|
-
</IconButton>
|
|
139
|
-
<TimeSpanInput
|
|
140
|
-
className={b("value-field")}
|
|
141
|
-
step={step || 2}
|
|
142
|
-
value={toValue}
|
|
143
|
-
onChange={handleToValueChange}
|
|
144
|
-
/>
|
|
145
|
-
</span>
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
);
|
|
149
|
-
};
|
|
150
|
-
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import './RangeSlider.scss';
|
|
3
|
+
import '@react5/time-span/packages/lib/dist/index.css'
|
|
4
|
+
import { bem } from '../../utils/bem';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
import { FaArrowRightFromBracket, FaArrowRightToBracket } from "react-icons/fa6"
|
|
7
|
+
import { IconButton } from '../IconButton';
|
|
8
|
+
import { TimeSpanInput } from '@react5/time-span';
|
|
9
|
+
|
|
10
|
+
interface RangeSliderProps {
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
step?: number;
|
|
14
|
+
from?: number;
|
|
15
|
+
to?: number;
|
|
16
|
+
pickFromLabel?: string;
|
|
17
|
+
pickToLabel?: string;
|
|
18
|
+
onPickTo?: () => void;
|
|
19
|
+
onPickFrom?: () => void;
|
|
20
|
+
onChange?: (from: number, to: number) => void;
|
|
21
|
+
}
|
|
22
|
+
const b = bem("range-slider")
|
|
23
|
+
export const RangeSlider: React.FC<RangeSliderProps> = ({ min = 0, max = 1 * 60 * 60, step = 1,
|
|
24
|
+
from = min, to = max, onChange, onPickFrom, onPickTo, pickFromLabel, pickToLabel }) => {
|
|
25
|
+
const [fromValue, setFromValue] = useState<number>(from);
|
|
26
|
+
const [toValue, setToValue] = useState<number>(to);
|
|
27
|
+
const trackRef = useRef<HTMLDivElement>(null);
|
|
28
|
+
const activeThumb = useRef<'min' | 'max' | null>(null);
|
|
29
|
+
const moveCallback = useCallback(
|
|
30
|
+
(x: number) => {
|
|
31
|
+
handleMove(x);
|
|
32
|
+
},
|
|
33
|
+
[],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const getPercentage = (value: number) => ((value - min) / (max - min)) * 100;
|
|
37
|
+
|
|
38
|
+
const handleMove = (clientX: number) => {
|
|
39
|
+
if (!trackRef.current || !activeThumb.current) return;
|
|
40
|
+
|
|
41
|
+
const trackRect = trackRef.current.getBoundingClientRect();
|
|
42
|
+
const position = clientX - trackRect.left;
|
|
43
|
+
const newPercentage = Math.min(Math.max(position / trackRect.width, 0), 1);
|
|
44
|
+
const newValue = Math.round((min + newPercentage * (max - min)) / step) * step;
|
|
45
|
+
|
|
46
|
+
if (activeThumb.current === 'min') {
|
|
47
|
+
if (newValue < toValue) {
|
|
48
|
+
setFromValue(newValue);
|
|
49
|
+
}
|
|
50
|
+
} else if (activeThumb.current === 'max') {
|
|
51
|
+
if (newValue > fromValue) {
|
|
52
|
+
setToValue(newValue);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleMouseUp = () => {
|
|
58
|
+
if (onChange) {
|
|
59
|
+
onChange(fromValue, toValue);
|
|
60
|
+
}
|
|
61
|
+
activeThumb.current = null;
|
|
62
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
63
|
+
//document.removeEventListener('mouseup', handleMouseUp);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
67
|
+
moveCallback(e.clientX);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleMouseDown = (thumb: 'min' | 'max') => (e: React.MouseEvent) => {
|
|
71
|
+
activeThumb.current = thumb;
|
|
72
|
+
handleMove(e.clientX);
|
|
73
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
74
|
+
//document.addEventListener('mouseup', handleMouseUp);
|
|
75
|
+
};
|
|
76
|
+
const handleFromValueChange = (v: number) => {
|
|
77
|
+
setFromValue(v);
|
|
78
|
+
onChange && onChange(v, toValue)
|
|
79
|
+
}
|
|
80
|
+
const handleToValueChange = (v: number) => {
|
|
81
|
+
setToValue(v)
|
|
82
|
+
onChange && onChange(fromValue, v)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
setFromValue(from);
|
|
87
|
+
setToValue(to);
|
|
88
|
+
}, [from, to]);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div className={b()}>
|
|
92
|
+
<div ref={trackRef} className={b("track")}>
|
|
93
|
+
<div
|
|
94
|
+
className={b("range")}
|
|
95
|
+
style={{
|
|
96
|
+
left: `${getPercentage(fromValue)}%`,
|
|
97
|
+
right: `${100 - getPercentage(toValue)}%`,
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
<div
|
|
101
|
+
className={clsx(b("thumb"), b("thumb", "min"))}
|
|
102
|
+
style={{ left: `${getPercentage(fromValue)}%` }}
|
|
103
|
+
onMouseDown={handleMouseDown('min')}
|
|
104
|
+
onMouseUp={handleMouseUp}
|
|
105
|
+
/>
|
|
106
|
+
<div
|
|
107
|
+
className={clsx(b("thumb"), b("thumb", "max"))}
|
|
108
|
+
style={{ left: `${getPercentage(toValue)}%` }}
|
|
109
|
+
onMouseDown={handleMouseDown('max')}
|
|
110
|
+
onMouseUp={handleMouseUp}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
<div className={b("values")}>
|
|
114
|
+
<span className={b("value")}>
|
|
115
|
+
<TimeSpanInput
|
|
116
|
+
className={b("value-field")}
|
|
117
|
+
step={step || 2}
|
|
118
|
+
value={fromValue}
|
|
119
|
+
onChange={handleFromValueChange}
|
|
120
|
+
/>
|
|
121
|
+
<IconButton
|
|
122
|
+
className={b("pick-button")}
|
|
123
|
+
variant='round-outlined'
|
|
124
|
+
title={pickFromLabel}
|
|
125
|
+
onClick={onPickFrom}
|
|
126
|
+
>
|
|
127
|
+
<FaArrowRightFromBracket/>
|
|
128
|
+
</IconButton>
|
|
129
|
+
</span>
|
|
130
|
+
<span className={b("value")}>
|
|
131
|
+
<IconButton
|
|
132
|
+
className={b("pick-button")}
|
|
133
|
+
variant='round-outlined'
|
|
134
|
+
title={pickToLabel}
|
|
135
|
+
onClick={onPickTo}
|
|
136
|
+
>
|
|
137
|
+
<FaArrowRightToBracket/>
|
|
138
|
+
</IconButton>
|
|
139
|
+
<TimeSpanInput
|
|
140
|
+
className={b("value-field")}
|
|
141
|
+
step={step || 2}
|
|
142
|
+
value={toValue}
|
|
143
|
+
onChange={handleToValueChange}
|
|
144
|
+
/>
|
|
145
|
+
</span>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
151
|
export default RangeSlider;
|