UNPKG

11.5 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { Mark } from './useSlider.types';
5import { SlotComponentProps } from '../utils/types';
6import { Theme } from '../styles';
7import { OverrideProps, OverridableComponent } from '../OverridableComponent';
8import SliderValueLabelComponent from './SliderValueLabel';
9import { SliderClasses } from './sliderClasses';
10
11export interface SliderPropsColorOverrides {}
12
13export interface SliderPropsSizeOverrides {}
14
15export interface SliderComponentsPropsOverrides {}
16
17export interface SliderOwnerState extends SliderProps {
18 dragging: boolean;
19 marked: boolean;
20 focusedThumbIndex: number;
21}
22
23export interface SliderOwnProps {
24 /**
25 * The label of the slider.
26 */
27 'aria-label'?: string;
28 /**
29 * The id of the element containing a label for the slider.
30 */
31 'aria-labelledby'?: string;
32 /**
33 * A string value that provides a user-friendly name for the current value of the slider.
34 */
35 'aria-valuetext'?: string;
36 /**
37 * The color of the component.
38 * It supports both default and custom theme colors, which can be added as shown in the
39 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
40 * @default 'primary'
41 */
42 color?: OverridableStringUnion<
43 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
44 SliderPropsColorOverrides
45 >;
46 /**
47 * The components used for each slot inside.
48 *
49 * @deprecated use the `slots` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
50 *
51 * @default {}
52 */
53 components?: {
54 Root?: React.ElementType;
55 Track?: React.ElementType;
56 Rail?: React.ElementType;
57 Thumb?: React.ElementType;
58 Mark?: React.ElementType;
59 MarkLabel?: React.ElementType;
60 ValueLabel?: React.ElementType;
61 Input?: React.ElementType;
62 };
63 /**
64 * The extra props for the slot components.
65 * You can override the existing props or add new ones.
66 *
67 * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
68 *
69 * @default {}
70 */
71 componentsProps?: {
72 root?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
73 track?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
74 rail?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
75 thumb?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
76 mark?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
77 markLabel?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
78 valueLabel?: SlotComponentProps<
79 typeof SliderValueLabelComponent,
80 SliderComponentsPropsOverrides,
81 SliderOwnerState
82 >;
83 input?: SlotComponentProps<'input', SliderComponentsPropsOverrides, SliderOwnerState>;
84 };
85 /**
86 * Override or extend the styles applied to the component.
87 */
88 classes?: Partial<SliderClasses>;
89 /**
90 * @ignore
91 */
92 className?: string;
93 /**
94 * The default value. Use when the component is not controlled.
95 */
96 defaultValue?: number | number[];
97 /**
98 * If `true`, the component is disabled.
99 * @default false
100 */
101 disabled?: boolean;
102 /**
103 * If `true`, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
104 * @default false
105 */
106 disableSwap?: boolean;
107 /**
108 * Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider.
109 * This is important for screen reader users.
110 * @param {number} index The thumb label's index to format.
111 * @returns {string}
112 */
113 getAriaLabel?: (index: number) => string;
114 /**
115 * Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.
116 * This is important for screen reader users.
117 * @param {number} value The thumb label's value to format.
118 * @param {number} index The thumb label's index to format.
119 * @returns {string}
120 */
121 getAriaValueText?: (value: number, index: number) => string;
122 /**
123 * Marks indicate predetermined values to which the user can move the slider.
124 * If `true` the marks are spaced according the value of the `step` prop.
125 * If an array, it should contain objects with `value` and an optional `label` keys.
126 * @default false
127 */
128 marks?: boolean | Mark[];
129 /**
130 * The maximum allowed value of the slider.
131 * Should not be equal to min.
132 * @default 100
133 */
134 max?: number;
135 /**
136 * The minimum allowed value of the slider.
137 * Should not be equal to max.
138 * @default 0
139 */
140 min?: number;
141 /**
142 * Name attribute of the hidden `input` element.
143 */
144 name?: string;
145 /**
146 * Callback function that is fired when the slider's value changed.
147 *
148 * @param {Event} event The event source of the callback.
149 * You can pull out the new value by accessing `event.target.value` (any).
150 * **Warning**: This is a generic event not a change event.
151 * @param {number | number[]} value The new value.
152 * @param {number} activeThumb Index of the currently moved thumb.
153 */
154 onChange?: (event: Event, value: number | number[], activeThumb: number) => void;
155 /**
156 * Callback function that is fired when the `mouseup` is triggered.
157 *
158 * @param {React.SyntheticEvent | Event} event The event source of the callback. **Warning**: This is a generic event not a change event.
159 * @param {number | number[]} value The new value.
160 */
161 onChangeCommitted?: (event: React.SyntheticEvent | Event, value: number | number[]) => void;
162 /**
163 * The component orientation.
164 * @default 'horizontal'
165 */
166 orientation?: 'horizontal' | 'vertical';
167 /**
168 * A transformation function, to change the scale of the slider.
169 * @param {any} x
170 * @returns {any}
171 * @default function Identity(x) {
172 * return x;
173 * }
174 */
175 scale?: (value: number) => number;
176 /**
177 * The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
178 * @default 10
179 */
180 shiftStep?: number;
181 /**
182 * The size of the slider.
183 * @default 'medium'
184 */
185 size?: OverridableStringUnion<'small' | 'medium', SliderPropsSizeOverrides>;
186 /**
187 * The props used for each slot inside the Slider.
188 * @default {}
189 */
190 slotProps?: {
191 root?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
192 track?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
193 rail?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
194 thumb?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
195 mark?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
196 markLabel?: SlotComponentProps<'span', SliderComponentsPropsOverrides, SliderOwnerState>;
197 valueLabel?: SlotComponentProps<
198 typeof SliderValueLabelComponent,
199 SliderComponentsPropsOverrides,
200 SliderOwnerState
201 >;
202 input?: SlotComponentProps<'input', SliderComponentsPropsOverrides, SliderOwnerState>;
203 };
204 /**
205 * The components used for each slot inside the Slider.
206 * Either a string to use a HTML element or a component.
207 * @default {}
208 */
209 slots?: {
210 root?: React.ElementType;
211 track?: React.ElementType;
212 rail?: React.ElementType;
213 thumb?: React.ElementType;
214 mark?: React.ElementType;
215 markLabel?: React.ElementType;
216 valueLabel?: React.ElementType;
217 input?: React.ElementType;
218 };
219 /**
220 * The granularity with which the slider can step through values. (A "discrete" slider.)
221 * The `min` prop serves as the origin for the valid values.
222 * We recommend (max - min) to be evenly divisible by the step.
223 *
224 * When step is `null`, the thumb can only be slid onto marks provided with the `marks` prop.
225 * @default 1
226 */
227 step?: number | null;
228 /**
229 * The system prop that allows defining system overrides as well as additional CSS styles.
230 */
231 sx?: SxProps<Theme>;
232 /**
233 * Tab index attribute of the hidden `input` element.
234 */
235 tabIndex?: number;
236 /**
237 * The track presentation:
238 *
239 * - `normal` the track will render a bar representing the slider value.
240 * - `inverted` the track will render a bar representing the remaining slider value.
241 * - `false` the track will render without a bar.
242 * @default 'normal'
243 */
244 track?: 'normal' | false | 'inverted';
245 /**
246 * The value of the slider.
247 * For ranged sliders, provide an array with two values.
248 */
249 value?: number | number[];
250 /**
251 * Controls when the value label is displayed:
252 *
253 * - `auto` the value label will display when the thumb is hovered or focused.
254 * - `on` will display persistently.
255 * - `off` will never display.
256 * @default 'off'
257 */
258 valueLabelDisplay?: 'on' | 'auto' | 'off';
259 /**
260 * The format function the value label's value.
261 *
262 * When a function is provided, it should have the following signature:
263 *
264 * - {number} value The value label's value to format
265 * - {number} index The value label's index to format
266 * @param {any} x
267 * @returns {any}
268 * @default function Identity(x) {
269 * return x;
270 * }
271 */
272 valueLabelFormat?: string | ((value: number, index: number) => React.ReactNode);
273}
274
275export interface SliderTypeMap<
276 RootComponent extends React.ElementType = 'span',
277 AdditionalProps = {},
278> {
279 props: AdditionalProps & SliderOwnProps;
280 defaultComponent: RootComponent;
281}
282
283export interface SliderValueLabelProps extends React.HTMLAttributes<HTMLSpanElement> {
284 children: React.ReactElement<unknown>;
285 index: number;
286 open: boolean;
287 value: React.ReactNode;
288}
289
290type SliderRootProps = NonNullable<SliderTypeMap['props']['componentsProps']>['root'];
291type SliderMarkProps = NonNullable<SliderTypeMap['props']['componentsProps']>['mark'];
292type SliderMarkLabelProps = NonNullable<SliderTypeMap['props']['componentsProps']>['markLabel'];
293type SliderRailProps = NonNullable<SliderTypeMap['props']['componentsProps']>['rail'];
294type SliderTrackProps = NonNullable<SliderTypeMap['props']['componentsProps']>['track'];
295type SliderThumbProps = NonNullable<SliderTypeMap['props']['componentsProps']>['thumb'];
296
297export declare const SliderRoot: React.FC<SliderRootProps>;
298export declare const SliderMark: React.FC<SliderMarkProps>;
299export declare const SliderMarkLabel: React.FC<SliderMarkLabelProps>;
300export declare const SliderRail: React.FC<SliderRailProps>;
301export declare const SliderTrack: React.FC<SliderTrackProps>;
302export declare const SliderThumb: React.FC<SliderThumbProps>;
303export declare const SliderValueLabel: React.FC<SliderValueLabelProps>;
304
305/**
306 *
307 * Demos:
308 *
309 * - [Slider](https://mui.com/material-ui/react-slider/)
310 *
311 * API:
312 *
313 * - [Slider API](https://mui.com/material-ui/api/slider/)
314 */
315declare const Slider: OverridableComponent<SliderTypeMap>;
316
317export type SliderProps<
318 RootComponent extends React.ElementType = SliderTypeMap['defaultComponent'],
319 AdditionalProps = {},
320> = OverrideProps<SliderTypeMap<RootComponent, AdditionalProps>, RootComponent> & {
321 component?: React.ElementType;
322};
323
324export default Slider;
325
\No newline at end of file