@recursica/mui-adapter 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/mui-adapter.cjs +74 -1
- package/dist/mui-adapter.cjs.map +1 -1
- package/dist/mui-adapter.css +1 -1
- package/dist/mui-adapter.js +6651 -201
- package/dist/mui-adapter.js.map +1 -1
- package/dist/src/components/Accordion/Accordion.d.ts +63 -2
- package/dist/src/components/AssistiveElement/AssistiveElement.d.ts +9 -2
- package/dist/src/components/Autocomplete/Autocomplete.d.ts +17 -0
- package/dist/src/components/Autocomplete/index.d.ts +1 -0
- package/dist/src/components/Avatar/Avatar.d.ts +14 -2
- package/dist/src/components/Badge/Badge.d.ts +13 -3
- package/dist/src/components/Breadcrumb/Breadcrumb.d.ts +10 -3
- package/dist/src/components/Button/Button.d.ts +1 -1
- package/dist/src/components/Card/Card.d.ts +40 -3
- package/dist/src/components/Checkbox/Checkbox.d.ts +15 -2
- package/dist/src/components/Checkbox/CheckboxGroup.d.ts +16 -0
- package/dist/src/components/Checkbox/index.d.ts +5 -1
- package/dist/src/components/Chip/Chip.d.ts +18 -2
- package/dist/src/components/Dropdown/Dropdown.d.ts +23 -3
- package/dist/src/components/FormControlLayout/FormControlLayout.d.ts +10 -2
- package/dist/src/components/FormControlWrapper/FormControlWrapper.d.ts +24 -2
- package/dist/src/components/HoverCard/HoverCard.d.ts +55 -3
- package/dist/src/components/Label/Label.d.ts +13 -2
- package/dist/src/components/Link/Link.d.ts +1 -1
- package/dist/src/components/Menu/Menu.d.ts +99 -3
- package/dist/src/components/Modal/Modal.d.ts +36 -2
- package/dist/src/components/NumberInput/NumberInput.d.ts +14 -2
- package/dist/src/components/Pagination/Pagination.d.ts +44 -2
- package/dist/src/components/Pagination/Pagination.icons.d.ts +8 -0
- package/dist/src/components/Panel/Panel.d.ts +65 -3
- package/dist/src/components/Radio/Radio.d.ts +13 -3
- package/dist/src/components/Radio/RadioGroup.d.ts +13 -0
- package/dist/src/components/ReadOnlyField/ReadOnlyBooleanField.d.ts +5 -0
- package/dist/src/components/ReadOnlyField/ReadOnlyField.d.ts +7 -2
- package/dist/src/components/ReadOnlyField/ReadOnlySwitchField.d.ts +5 -0
- package/dist/src/components/ReadOnlyField/ReadOnlyTextField.d.ts +8 -0
- package/dist/src/components/ReadOnlyField/WithReadOnlyWrapper.d.ts +28 -0
- package/dist/src/components/ReadOnlyField/index.d.ts +1 -0
- package/dist/src/components/SegmentedControl/SegmentedControl.d.ts +31 -3
- package/dist/src/components/Slider/Slider.d.ts +28 -2
- package/dist/src/components/Stepper/Stepper.d.ts +21 -2
- package/dist/src/components/Switch/Switch.d.ts +10 -3
- package/dist/src/components/Switch/SwitchGroup.d.ts +13 -0
- package/dist/src/components/Tabs/Tabs.d.ts +35 -3
- package/dist/src/components/Text/Text.d.ts +1 -1
- package/dist/src/components/TextArea/TextArea.d.ts +18 -2
- package/dist/src/components/TextField/TextField.d.ts +16 -2
- package/dist/src/components/Timeline/Timeline.d.ts +14 -2
- package/dist/src/components/Timeline/TimelineItem.d.ts +29 -0
- package/dist/src/components/Title/Title.d.ts +1 -1
- package/dist/src/components/Toast/Toast.d.ts +25 -2
- package/dist/src/components/Tooltip/Tooltip.d.ts +42 -3
- package/dist/src/components/Typography/Typography.d.ts +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/package.json +12 -2
- package/src/GlobalExemptions.modules.css +13 -0
- package/src/components/Accordion/Accordion.module.css +295 -0
- package/src/components/Accordion/Accordion.stories.tsx +149 -21
- package/src/components/Accordion/Accordion.tsx +264 -4
- package/src/components/AssistiveElement/AssistiveElement.module.css +111 -0
- package/src/components/AssistiveElement/AssistiveElement.stories.tsx +76 -19
- package/src/components/AssistiveElement/AssistiveElement.tsx +85 -4
- package/src/components/Autocomplete/Autocomplete.module.css +325 -0
- package/src/components/Autocomplete/Autocomplete.stories.tsx +196 -0
- package/src/components/Autocomplete/Autocomplete.tsx +201 -0
- package/src/components/Autocomplete/index.ts +1 -0
- package/src/components/Avatar/Avatar.module.css +344 -0
- package/src/components/Avatar/Avatar.stories.tsx +94 -22
- package/src/components/Avatar/Avatar.tsx +110 -5
- package/src/components/Badge/Badge.module.css +127 -0
- package/src/components/Badge/Badge.stories.tsx +65 -22
- package/src/components/Badge/Badge.tsx +70 -5
- package/src/components/Breadcrumb/Breadcrumb.module.css +26 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +57 -22
- package/src/components/Breadcrumb/Breadcrumb.tsx +62 -5
- package/src/components/Button/Button.module.css +113 -20
- package/src/components/Button/Button.stories.tsx +3 -0
- package/src/components/Button/Button.tsx +10 -3
- package/src/components/Card/Card.module.css +118 -0
- package/src/components/Card/Card.stories.tsx +117 -19
- package/src/components/Card/Card.tsx +179 -4
- package/src/components/Checkbox/Checkbox.module.css +232 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +81 -19
- package/src/components/Checkbox/Checkbox.tsx +146 -4
- package/src/components/Checkbox/CheckboxGroup.tsx +117 -0
- package/src/components/Checkbox/index.ts +6 -1
- package/src/components/Chip/Chip.module.css +236 -0
- package/src/components/Chip/Chip.stories.tsx +101 -21
- package/src/components/Chip/Chip.tsx +138 -5
- package/src/components/DatePicker/DatePicker.module.css +42 -0
- package/src/components/DatePicker/DatePicker.tsx +1 -0
- package/src/components/Dropdown/Dropdown.module.css +296 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +80 -21
- package/src/components/Dropdown/Dropdown.tsx +182 -5
- package/src/components/FileInput/FileInput.module.css +47 -0
- package/src/components/FileInput/FileInput.tsx +1 -0
- package/src/components/FileUpload/FileUpload.module.css +40 -0
- package/src/components/FileUpload/FileUpload.tsx +1 -0
- package/src/components/FormControlLayout/FormControlLayout.module.css +92 -0
- package/src/components/FormControlLayout/FormControlLayout.stories.tsx +74 -19
- package/src/components/FormControlLayout/FormControlLayout.tsx +58 -4
- package/src/components/FormControlWrapper/FormControlWrapper.module.css +96 -0
- package/src/components/FormControlWrapper/FormControlWrapper.stories.tsx +122 -19
- package/src/components/FormControlWrapper/FormControlWrapper.tsx +145 -6
- package/src/components/HoverCard/HoverCard.module.css +91 -0
- package/src/components/HoverCard/HoverCard.stories.tsx +158 -21
- package/src/components/HoverCard/HoverCard.tsx +150 -4
- package/src/components/Label/Label.module.css +136 -0
- package/src/components/Label/Label.stories.tsx +98 -17
- package/src/components/Label/Label.tsx +88 -4
- package/src/components/Link/Link.module.css +8 -0
- package/src/components/Menu/Menu.module.css +287 -0
- package/src/components/Menu/Menu.stories.tsx +307 -21
- package/src/components/Menu/Menu.tsx +318 -4
- package/src/components/Modal/Modal.module.css +172 -0
- package/src/components/Modal/Modal.stories.tsx +66 -22
- package/src/components/Modal/Modal.tsx +216 -3
- package/src/components/NumberInput/NumberInput.module.css +281 -0
- package/src/components/NumberInput/NumberInput.stories.tsx +83 -20
- package/src/components/NumberInput/NumberInput.tsx +148 -5
- package/src/components/Pagination/Pagination.icons.tsx +66 -0
- package/src/components/Pagination/Pagination.module.css +307 -0
- package/src/components/Pagination/Pagination.stories.tsx +42 -21
- package/src/components/Pagination/Pagination.tsx +193 -4
- package/src/components/Panel/Panel.module.css +206 -0
- package/src/components/Panel/Panel.stories.tsx +214 -22
- package/src/components/Panel/Panel.tsx +153 -4
- package/src/components/Radio/Radio.module.css +220 -0
- package/src/components/Radio/Radio.stories.tsx +77 -19
- package/src/components/Radio/Radio.tsx +178 -4
- package/src/components/Radio/RadioGroup.tsx +111 -0
- package/src/components/ReadOnlyField/ReadOnlyBooleanField.tsx +21 -0
- package/src/components/ReadOnlyField/ReadOnlyField.module.css +54 -0
- package/src/components/ReadOnlyField/ReadOnlyField.stories.tsx +175 -16
- package/src/components/ReadOnlyField/ReadOnlyField.tsx +109 -4
- package/src/components/ReadOnlyField/ReadOnlySwitchField.tsx +21 -0
- package/src/components/ReadOnlyField/ReadOnlyTextField.tsx +48 -0
- package/src/components/ReadOnlyField/WithReadOnlyWrapper.tsx +93 -0
- package/src/components/ReadOnlyField/index.ts +1 -0
- package/src/components/SegmentedControl/SegmentedControl.module.css +203 -0
- package/src/components/SegmentedControl/SegmentedControl.stories.tsx +102 -20
- package/src/components/SegmentedControl/SegmentedControl.tsx +110 -5
- package/src/components/Slider/Slider.module.css +542 -0
- package/src/components/Slider/Slider.stories.tsx +157 -19
- package/src/components/Slider/Slider.tsx +282 -4
- package/src/components/Stepper/Stepper.module.css +410 -0
- package/src/components/Stepper/Stepper.stories.tsx +132 -19
- package/src/components/Stepper/Stepper.tsx +145 -5
- package/src/components/Switch/Switch.module.css +238 -0
- package/src/components/Switch/Switch.stories.tsx +98 -19
- package/src/components/Switch/Switch.tsx +153 -5
- package/src/components/Switch/SwitchGroup.tsx +111 -0
- package/src/components/Tabs/Tabs.module.css +422 -0
- package/src/components/Tabs/Tabs.stories.tsx +138 -19
- package/src/components/Tabs/Tabs.tsx +103 -5
- package/src/components/TextArea/TextArea.module.css +160 -0
- package/src/components/TextArea/TextArea.stories.tsx +80 -21
- package/src/components/TextArea/TextArea.tsx +156 -5
- package/src/components/TextField/TextField.module.css +266 -0
- package/src/components/TextField/TextField.stories.tsx +168 -15
- package/src/components/TextField/TextField.tsx +171 -5
- package/src/components/TimePicker/TimePicker.module.css +41 -0
- package/src/components/TimePicker/TimePicker.tsx +1 -0
- package/src/components/Timeline/Timeline.module.css +367 -0
- package/src/components/Timeline/Timeline.stories.tsx +114 -21
- package/src/components/Timeline/Timeline.tsx +80 -4
- package/src/components/Timeline/TimelineItem.tsx +101 -0
- package/src/components/Toast/Toast.module.css +170 -0
- package/src/components/Toast/Toast.stories.tsx +54 -22
- package/src/components/Toast/Toast.tsx +90 -4
- package/src/components/Tooltip/Tooltip.module.css +90 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +152 -22
- package/src/components/Tooltip/Tooltip.tsx +114 -4
- package/src/components/TransferList/TransferList.module.css +38 -0
- package/src/components/TransferList/TransferList.tsx +1 -0
- package/src/components/index.ts +1 -0
|
@@ -1,35 +1,173 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { Slider } from "./Slider";
|
|
3
|
-
import {
|
|
3
|
+
import { formControlArgTypes } from "../../../.storybook/commonArgTypes";
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof Slider> = {
|
|
6
|
-
title: "UI-Kit
|
|
6
|
+
title: "UI-Kit/Slider",
|
|
7
7
|
component: Slider,
|
|
8
8
|
tags: ["autodocs"],
|
|
9
9
|
parameters: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
docs: {
|
|
11
|
+
description: {
|
|
12
|
+
component: `
|
|
13
|
+
The \`Slider\` component wraps Mantine's Slider to support a premium design system, a bidirectional input state,
|
|
14
|
+
custom min/max labels, step indicators, and strict states like error, disabled, and read-only.
|
|
15
|
+
|
|
16
|
+
### Architecture
|
|
17
|
+
The component uses Recursica's unified \`FormControlWrapper\` and \`<WithReadOnlyWrapper>\` to render consistent form layouts (stacked, side-by-side) and read-only representations.
|
|
18
|
+
All visual properties map perfectly to token values inside \`Slider.module.css\`.
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
...formControlArgTypes,
|
|
25
|
+
disabled: {
|
|
26
|
+
control: "boolean",
|
|
27
|
+
description: "Disables both the slider track and the text input field.",
|
|
28
|
+
},
|
|
29
|
+
error: {
|
|
30
|
+
control: "text",
|
|
31
|
+
description:
|
|
32
|
+
"Places the slider in an error state with custom border/icon highlights.",
|
|
33
|
+
},
|
|
34
|
+
required: {
|
|
35
|
+
control: "boolean",
|
|
36
|
+
},
|
|
37
|
+
label: {
|
|
38
|
+
control: "text",
|
|
39
|
+
description: "Outer form control label.",
|
|
40
|
+
},
|
|
41
|
+
assistiveText: {
|
|
42
|
+
control: "text",
|
|
43
|
+
description: "Assistive text rendered below or beside the component.",
|
|
44
|
+
},
|
|
45
|
+
readOnly: {
|
|
46
|
+
control: "boolean",
|
|
47
|
+
description: "Puts the component in static read-only mode.",
|
|
48
|
+
},
|
|
49
|
+
showInput: {
|
|
50
|
+
control: "boolean",
|
|
51
|
+
description: "Controls whether the numeric input box is visible.",
|
|
52
|
+
},
|
|
53
|
+
showMinMaxLabels: {
|
|
54
|
+
control: "boolean",
|
|
55
|
+
description: "Toggles rendering of min/max labels below the track.",
|
|
26
56
|
},
|
|
27
57
|
},
|
|
28
58
|
};
|
|
29
59
|
|
|
30
60
|
export default meta;
|
|
61
|
+
|
|
31
62
|
type Story = StoryObj<typeof Slider>;
|
|
32
63
|
|
|
33
64
|
export const Default: Story = {
|
|
34
|
-
|
|
65
|
+
args: {
|
|
66
|
+
label: "Auditory Threshold",
|
|
67
|
+
assistiveText: "Specify the maximum decibel frequency boundary.",
|
|
68
|
+
defaultValue: 40,
|
|
69
|
+
min: 0,
|
|
70
|
+
max: 100,
|
|
71
|
+
step: 1,
|
|
72
|
+
showMinMaxLabels: true,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const WithInputField: Story = {
|
|
77
|
+
args: {
|
|
78
|
+
...Default.args,
|
|
79
|
+
showInput: true,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const SideBySideLayout: Story = {
|
|
84
|
+
args: {
|
|
85
|
+
...Default.args,
|
|
86
|
+
formLayout: "side-by-side",
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const Disabled: Story = {
|
|
91
|
+
args: {
|
|
92
|
+
label: "Decommissioned Server Node",
|
|
93
|
+
assistiveText: "Modifications to this environment are frozen.",
|
|
94
|
+
defaultValue: 35,
|
|
95
|
+
disabled: true,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const ErrorState: Story = {
|
|
100
|
+
args: {
|
|
101
|
+
label: "Core Temperature Alert",
|
|
102
|
+
assistiveText:
|
|
103
|
+
"Severe core degradation across the hypervisor socket cluster.",
|
|
104
|
+
defaultValue: 85,
|
|
105
|
+
error: "Thermal overload threshold exceeded.",
|
|
106
|
+
required: true,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const StaticReadOnly: Story = {
|
|
111
|
+
args: {
|
|
112
|
+
label: "System Calibration Metrics",
|
|
113
|
+
assistiveText:
|
|
114
|
+
"Frozen baseline calibrations derived during initial staging.",
|
|
115
|
+
value: 65,
|
|
116
|
+
readOnly: true,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const EditableReadOnly: Story = {
|
|
121
|
+
args: {
|
|
122
|
+
label: "Adaptive Node Output",
|
|
123
|
+
assistiveText:
|
|
124
|
+
"Click edit to unlock bidirectional input parameter boundaries.",
|
|
125
|
+
defaultValue: 15,
|
|
126
|
+
readOnly: true,
|
|
127
|
+
labelWithEditIcon: true,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const WithMarks: Story = {
|
|
132
|
+
args: {
|
|
133
|
+
label: "Interactive Marks Map",
|
|
134
|
+
defaultValue: 50,
|
|
135
|
+
min: 0,
|
|
136
|
+
max: 100,
|
|
137
|
+
step: 10,
|
|
138
|
+
marks: [
|
|
139
|
+
{ value: 0, label: "0%" },
|
|
140
|
+
{ value: 25, label: "25%" },
|
|
141
|
+
{ value: 50, label: "50%" },
|
|
142
|
+
{ value: 75, label: "75%" },
|
|
143
|
+
{ value: 100, label: "100%" },
|
|
144
|
+
],
|
|
145
|
+
showMinMaxLabels: false,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const FormLayouts: Story = {
|
|
150
|
+
render: () => (
|
|
151
|
+
<div
|
|
152
|
+
style={{
|
|
153
|
+
display: "flex",
|
|
154
|
+
flexDirection: "column",
|
|
155
|
+
gap: "2.5rem",
|
|
156
|
+
maxWidth: 600,
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
<Slider
|
|
160
|
+
label="Stacked Layout"
|
|
161
|
+
assistiveText="This is the standard top-to-bottom stacked form layout."
|
|
162
|
+
defaultValue={40}
|
|
163
|
+
formLayout="stacked"
|
|
164
|
+
/>
|
|
165
|
+
<Slider
|
|
166
|
+
label="Side-by-Side Layout"
|
|
167
|
+
assistiveText="This is the side-by-side layout aligning label beside control."
|
|
168
|
+
defaultValue={60}
|
|
169
|
+
formLayout="side-by-side"
|
|
170
|
+
/>
|
|
171
|
+
</div>
|
|
172
|
+
),
|
|
35
173
|
};
|
|
@@ -1,7 +1,285 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { forwardRef, useState, useEffect } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Slider as MuiSlider,
|
|
4
|
+
type SliderProps as MuiSliderProps,
|
|
5
|
+
type InputWrapperProps,
|
|
6
|
+
} from "@mui/material";
|
|
7
|
+
import { type ReadOnlyControlProps } from "@recursica/adapter-common";
|
|
8
|
+
import {
|
|
9
|
+
filterStylingProps,
|
|
10
|
+
type RecursicaOverStyled,
|
|
11
|
+
} from "../../utils/filterStylingProps";
|
|
12
|
+
import { type RecursicaFormControlWrapperProps } from "../FormControlWrapper/FormControlWrapper";
|
|
13
|
+
import { WithReadOnlyWrapper } from "../ReadOnlyField/WithReadOnlyWrapper";
|
|
2
14
|
|
|
3
|
-
|
|
15
|
+
import styles from "./Slider.module.css";
|
|
4
16
|
|
|
5
|
-
export
|
|
6
|
-
|
|
17
|
+
export interface RecursicaSliderProps
|
|
18
|
+
extends Omit<
|
|
19
|
+
Omit<MuiSliderProps, "size" | "color">,
|
|
20
|
+
"variant" | "radius" | "wrapperProps" | "classNames" | "styles" | "label"
|
|
21
|
+
>,
|
|
22
|
+
Omit<
|
|
23
|
+
RecursicaFormControlWrapperProps,
|
|
24
|
+
"controlMaxWidth" | "controlMinWidth"
|
|
25
|
+
>,
|
|
26
|
+
Pick<InputWrapperProps, "error" | "required" | "withAsterisk">,
|
|
27
|
+
ReadOnlyControlProps {
|
|
28
|
+
/** The form control label displayed above or beside the slider track. */
|
|
29
|
+
label?: React.ReactNode;
|
|
30
|
+
/** Floating tooltip shown above the thumb when dragging. Replaces Mui's `label`. */
|
|
31
|
+
tooltipLabel?: MuiSliderProps["label"];
|
|
32
|
+
/** An optional icon rendered to the left of the slider track. */
|
|
33
|
+
icon?: React.ReactNode;
|
|
34
|
+
/** Whether to render a numeric input field side-by-side or stacked with the track. Defaults to false. */
|
|
35
|
+
showInput?: boolean;
|
|
36
|
+
/** Whether to render min and max labels below the track. Defaults to true. */
|
|
37
|
+
showMinMaxLabels?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type SliderProps = RecursicaOverStyled<RecursicaSliderProps>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Custom Read-Only visual representation of the Slider value.
|
|
44
|
+
* Utilizes component-specific read-only typography variables.
|
|
45
|
+
*/
|
|
46
|
+
const SliderReadOnlyValue: React.FC<{ value: number }> = ({ value }) => {
|
|
47
|
+
return <div className={styles.readOnlyValue}>{value}</div>;
|
|
7
48
|
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Recursica Slider component wrapping Mui's Slider.
|
|
52
|
+
*
|
|
53
|
+
* Implements a bidirectional text input field next to the slider track, responsive layouts,
|
|
54
|
+
* custom typography-bound min/max labels, an optional leading icon, and an explicit read-only layout.
|
|
55
|
+
*/
|
|
56
|
+
export const Slider = forwardRef<HTMLDivElement, SliderProps>(
|
|
57
|
+
function Slider(props, ref) {
|
|
58
|
+
const {
|
|
59
|
+
overStyled = false,
|
|
60
|
+
formLayout = "stacked",
|
|
61
|
+
|
|
62
|
+
// Label & Wrapper Maps
|
|
63
|
+
labelSize,
|
|
64
|
+
labelAlignment,
|
|
65
|
+
labelOptionalText,
|
|
66
|
+
labelWithEditIcon,
|
|
67
|
+
labelActionArea,
|
|
68
|
+
onLabelEditClick,
|
|
69
|
+
|
|
70
|
+
label,
|
|
71
|
+
tooltipLabel,
|
|
72
|
+
assistiveText,
|
|
73
|
+
assistiveWithIcon,
|
|
74
|
+
error,
|
|
75
|
+
required,
|
|
76
|
+
withAsterisk,
|
|
77
|
+
id,
|
|
78
|
+
className,
|
|
79
|
+
style,
|
|
80
|
+
disabled,
|
|
81
|
+
readOnly,
|
|
82
|
+
readOnlyComponent,
|
|
83
|
+
emptyValueComponent,
|
|
84
|
+
value,
|
|
85
|
+
defaultValue,
|
|
86
|
+
icon,
|
|
87
|
+
showInput = false,
|
|
88
|
+
showMinMaxLabels = true,
|
|
89
|
+
min = 0,
|
|
90
|
+
max = 100,
|
|
91
|
+
step = 1,
|
|
92
|
+
onChange,
|
|
93
|
+
onChangeEnd,
|
|
94
|
+
...rest
|
|
95
|
+
} = props;
|
|
96
|
+
|
|
97
|
+
// Bidirectional state linking the slider track value to the input field string representation
|
|
98
|
+
const [internalValue, setInternalValue] = useState<number>(() => {
|
|
99
|
+
if (value !== undefined) return value;
|
|
100
|
+
if (defaultValue !== undefined) return defaultValue;
|
|
101
|
+
return min;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const resolvedValue = value !== undefined ? value : internalValue;
|
|
105
|
+
const [inputValue, setInputValue] = useState<string>(
|
|
106
|
+
resolvedValue.toString(),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Synchronize text input whenever the slider value changes
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
setInputValue(resolvedValue.toString());
|
|
112
|
+
}, [resolvedValue]);
|
|
113
|
+
|
|
114
|
+
const handleValueChange = (e: Event, val: number | number[]) => {
|
|
115
|
+
const singleVal = Array.isArray(val) ? val[0] : val;
|
|
116
|
+
if (value === undefined) {
|
|
117
|
+
setInternalValue(singleVal);
|
|
118
|
+
}
|
|
119
|
+
onChange?.(singleVal as any);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
123
|
+
const valStr = e.target.value;
|
|
124
|
+
setInputValue(valStr);
|
|
125
|
+
|
|
126
|
+
const parsed = parseFloat(valStr);
|
|
127
|
+
if (!isNaN(parsed)) {
|
|
128
|
+
// Clamp input value to bounds
|
|
129
|
+
const clamped = Math.max(min, Math.min(max, parsed));
|
|
130
|
+
handleValueChange(null as any, clamped);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const handleInputBlur = () => {
|
|
135
|
+
setInputValue(resolvedValue.toString());
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const sanitizedProps = filterStylingProps(rest, overStyled);
|
|
139
|
+
const restRecord = sanitizedProps as Record<string, unknown>;
|
|
140
|
+
|
|
141
|
+
// Delete prohibited sizing hooks from bypassing variables natively
|
|
142
|
+
delete restRecord["size"];
|
|
143
|
+
delete restRecord["color"];
|
|
144
|
+
delete restRecord["wrapperProps"];
|
|
145
|
+
|
|
146
|
+
// Securely map core native blocks down ensuring nested CSS modules map precisely
|
|
147
|
+
const mergedClassNames: Partial<Record<string, string>> = {
|
|
148
|
+
root: styles.sliderRoot,
|
|
149
|
+
rail: styles.sliderTrack,
|
|
150
|
+
track: styles.sliderBar,
|
|
151
|
+
thumb: styles.sliderThumb,
|
|
152
|
+
mark: styles.sliderMark,
|
|
153
|
+
markLabel: styles.sliderMarkLabel,
|
|
154
|
+
valueLabel: styles.sliderTooltip,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const classNamesProp = restRecord.classNames;
|
|
158
|
+
if (
|
|
159
|
+
classNamesProp &&
|
|
160
|
+
typeof classNamesProp === "object" &&
|
|
161
|
+
!Array.isArray(classNamesProp)
|
|
162
|
+
) {
|
|
163
|
+
const o = classNamesProp as Partial<Record<string, string>>;
|
|
164
|
+
mergedClassNames.root = o.root
|
|
165
|
+
? `${styles.sliderRoot} ${o.root}`
|
|
166
|
+
: styles.sliderRoot;
|
|
167
|
+
mergedClassNames.rail = o.track
|
|
168
|
+
? `${styles.sliderTrack} ${o.track}`
|
|
169
|
+
: styles.sliderTrack;
|
|
170
|
+
mergedClassNames.track = o.bar
|
|
171
|
+
? `${styles.sliderBar} ${o.bar}`
|
|
172
|
+
: styles.sliderBar;
|
|
173
|
+
mergedClassNames.thumb = o.thumb
|
|
174
|
+
? `${styles.sliderThumb} ${o.thumb}`
|
|
175
|
+
: styles.sliderThumb;
|
|
176
|
+
mergedClassNames.mark = o.mark
|
|
177
|
+
? `${styles.sliderMark} ${o.mark}`
|
|
178
|
+
: styles.sliderMark;
|
|
179
|
+
mergedClassNames.markLabel = o.markLabel
|
|
180
|
+
? `${styles.sliderMarkLabel} ${o.markLabel}`
|
|
181
|
+
: styles.sliderMarkLabel;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const wrapperClass = className
|
|
185
|
+
? `${styles.layoutOverride} ${className}`
|
|
186
|
+
: styles.layoutOverride;
|
|
187
|
+
|
|
188
|
+
const leadingIcon = icon ? (
|
|
189
|
+
<span className={styles.iconWrapper} aria-hidden>
|
|
190
|
+
{icon}
|
|
191
|
+
</span>
|
|
192
|
+
) : null;
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<WithReadOnlyWrapper
|
|
196
|
+
ref={ref}
|
|
197
|
+
className={wrapperClass}
|
|
198
|
+
style={style as React.CSSProperties}
|
|
199
|
+
controlMaxWidth={undefined}
|
|
200
|
+
controlMinWidth={undefined}
|
|
201
|
+
overStyled={overStyled as true}
|
|
202
|
+
formLayout={formLayout}
|
|
203
|
+
labelSize={labelSize}
|
|
204
|
+
labelAlignment={labelAlignment}
|
|
205
|
+
labelOptionalText={labelOptionalText}
|
|
206
|
+
labelWithEditIcon={labelWithEditIcon}
|
|
207
|
+
labelActionArea={labelActionArea}
|
|
208
|
+
onLabelEditClick={onLabelEditClick}
|
|
209
|
+
label={label}
|
|
210
|
+
assistiveText={assistiveText}
|
|
211
|
+
assistiveWithIcon={assistiveWithIcon}
|
|
212
|
+
error={error}
|
|
213
|
+
required={required}
|
|
214
|
+
withAsterisk={withAsterisk}
|
|
215
|
+
id={id}
|
|
216
|
+
readOnly={readOnly}
|
|
217
|
+
readOnlyComponent={readOnlyComponent || SliderReadOnlyValue}
|
|
218
|
+
emptyValueComponent={emptyValueComponent}
|
|
219
|
+
readOnlyType="text"
|
|
220
|
+
readOnlyValue={resolvedValue}
|
|
221
|
+
readOnlyNativeProps={{ value: resolvedValue }}
|
|
222
|
+
activeComponent={
|
|
223
|
+
<div
|
|
224
|
+
className={styles.sliderContainer}
|
|
225
|
+
data-form-layout={formLayout}
|
|
226
|
+
data-disabled={disabled ? "true" : undefined}
|
|
227
|
+
data-error={error ? "true" : undefined}
|
|
228
|
+
>
|
|
229
|
+
{leadingIcon}
|
|
230
|
+
|
|
231
|
+
{showMinMaxLabels && (
|
|
232
|
+
<span className={styles.minMaxGuide}>{min}</span>
|
|
233
|
+
)}
|
|
234
|
+
|
|
235
|
+
<div className={styles.sliderTrackWrapper}>
|
|
236
|
+
<MuiSlider
|
|
237
|
+
classes={mergedClassNames}
|
|
238
|
+
disabled={disabled}
|
|
239
|
+
value={resolvedValue}
|
|
240
|
+
onChange={handleValueChange}
|
|
241
|
+
onChangeCommitted={onChangeEnd as any}
|
|
242
|
+
min={min}
|
|
243
|
+
max={max}
|
|
244
|
+
step={step}
|
|
245
|
+
valueLabelDisplay={tooltipLabel === null ? "off" : "auto"}
|
|
246
|
+
valueLabelFormat={
|
|
247
|
+
typeof tooltipLabel === "function"
|
|
248
|
+
? (tooltipLabel as any)
|
|
249
|
+
: undefined
|
|
250
|
+
}
|
|
251
|
+
{...(sanitizedProps as unknown as MuiSliderProps)}
|
|
252
|
+
/>
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<div className={styles.rightGuideContainer}>
|
|
256
|
+
{!showInput && (
|
|
257
|
+
<span className={styles.currentValue}>{resolvedValue}</span>
|
|
258
|
+
)}
|
|
259
|
+
{showMinMaxLabels && (
|
|
260
|
+
<span className={styles.minMaxGuide}>{max}</span>
|
|
261
|
+
)}
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
{showInput && (
|
|
265
|
+
<input
|
|
266
|
+
type="number"
|
|
267
|
+
className={styles.inputField}
|
|
268
|
+
value={inputValue}
|
|
269
|
+
onChange={handleInputChange}
|
|
270
|
+
onBlur={handleInputBlur}
|
|
271
|
+
min={min}
|
|
272
|
+
max={max}
|
|
273
|
+
step={step}
|
|
274
|
+
disabled={disabled}
|
|
275
|
+
data-error={error ? "true" : undefined}
|
|
276
|
+
/>
|
|
277
|
+
)}
|
|
278
|
+
</div>
|
|
279
|
+
}
|
|
280
|
+
/>
|
|
281
|
+
);
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
Slider.displayName = "Slider";
|