UNPKG

7.23 kBTypeScriptView Raw
1import { Simplify } from '@mui/types';
2import * as React from 'react';
3import { PolymorphicProps, SlotComponentProps, SlotComponentPropsWithSlotState } from '../utils';
4import { UseSliderHiddenInputProps, UseSliderParameters, UseSliderRootSlotProps, UseSliderThumbSlotProps } from '../useSlider';
5export type SliderOwnerState = Simplify<SliderOwnProps & {
6 disabled: boolean;
7 focusedThumbIndex: number;
8 activeThumbIndex: number;
9 isRtl: boolean;
10 max: number;
11 min: number;
12 dragging: boolean;
13 marked: boolean;
14 orientation: 'horizontal' | 'vertical';
15 scale: (value: number) => number;
16 step: number | null;
17 track: 'normal' | false | 'inverted';
18 valueLabelFormat: string | ((value: number, index: number) => React.ReactNode);
19}>;
20export interface SliderRootSlotPropsOverrides {
21}
22export interface SliderTrackSlotPropsOverrides {
23}
24export interface SliderRailSlotPropsOverrides {
25}
26export interface SliderThumbSlotPropsOverrides {
27}
28export interface SliderMarkSlotPropsOverrides {
29}
30export interface SliderMarkLabelSlotPropsOverrides {
31}
32export interface SliderValueLabelSlotPropsOverrides {
33}
34export interface SliderInputSlotPropsOverrides {
35}
36export interface SliderThumbSlotState {
37 focused: boolean;
38 active: boolean;
39 index: number;
40}
41export interface SliderOwnProps extends Omit<UseSliderParameters, 'ref'> {
42 /**
43 * The label of the slider.
44 */
45 'aria-label'?: string;
46 /**
47 * A string value that provides a user-friendly name for the current value of the slider.
48 */
49 'aria-valuetext'?: string;
50 /**
51 * Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider.
52 * This is important for screen reader users.
53 * @param {number} index The thumb label's index to format.
54 * @returns {string}
55 */
56 getAriaLabel?: (index: number) => string;
57 /**
58 * Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.
59 * This is important for screen reader users.
60 * @param {number} value The thumb label's value to format.
61 * @param {number} index The thumb label's index to format.
62 * @returns {string}
63 */
64 getAriaValueText?: (value: number, index: number) => string;
65 /**
66 * The props used for each slot inside the Slider.
67 * @default {}
68 */
69 slotProps?: {
70 root?: SlotComponentProps<'span', SliderRootSlotPropsOverrides, SliderOwnerState>;
71 track?: SlotComponentProps<'span', SliderTrackSlotPropsOverrides, SliderOwnerState>;
72 rail?: SlotComponentProps<'span', SliderRailSlotPropsOverrides, SliderOwnerState>;
73 thumb?: SlotComponentPropsWithSlotState<'span', SliderThumbSlotPropsOverrides, SliderOwnerState, SliderThumbSlotState>;
74 mark?: SlotComponentProps<'span', SliderMarkSlotPropsOverrides, SliderOwnerState>;
75 markLabel?: SlotComponentProps<'span', SliderMarkLabelSlotPropsOverrides, SliderOwnerState>;
76 valueLabel?: SlotComponentProps<React.ElementType, SliderValueLabelSlotPropsOverrides, SliderOwnerState>;
77 input?: SlotComponentProps<'input', SliderInputSlotPropsOverrides, SliderOwnerState>;
78 };
79 /**
80 * The components used for each slot inside the Slider.
81 * Either a string to use a HTML element or a component.
82 * @default {}
83 */
84 slots?: SliderSlots;
85 /**
86 * The track presentation:
87 *
88 * - `normal` the track will render a bar representing the slider value.
89 * - `inverted` the track will render a bar representing the remaining slider value.
90 * - `false` the track will render without a bar.
91 * @default 'normal'
92 */
93 track?: 'normal' | false | 'inverted';
94 /**
95 * The format function the value label's value.
96 *
97 * When a function is provided, it should have the following signature:
98 *
99 * - {number} value The value label's value to format
100 * - {number} index The value label's index to format
101 * @param {any} x
102 * @returns {any}
103 * @default function Identity(x) {
104 * return x;
105 * }
106 */
107 valueLabelFormat?: string | ((value: number, index: number) => React.ReactNode);
108}
109export interface SliderSlots {
110 /**
111 * The component that renders the root.
112 * @default 'span'
113 */
114 root?: React.ElementType;
115 /**
116 * The component that renders the track.
117 * @default 'span'
118 */
119 track?: React.ElementType;
120 /**
121 * The component that renders the rail.
122 * @default 'span'
123 */
124 rail?: React.ElementType;
125 /**
126 * The component that renders the thumb.
127 * @default 'span'
128 */
129 thumb?: React.ElementType;
130 /**
131 * The component that renders the mark.
132 * @default 'span'
133 */
134 mark?: React.ElementType;
135 /**
136 * The component that renders the mark label.
137 * @default 'span'
138 */
139 markLabel?: React.ElementType;
140 /**
141 * The component that renders the value label.
142 */
143 valueLabel?: React.ElementType;
144 /**
145 * The component that renders the input.
146 * @default 'input'
147 */
148 input?: React.ElementType;
149}
150export interface SliderTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'span'> {
151 props: SliderOwnProps & AdditionalProps;
152 defaultComponent: RootComponentType;
153}
154export type SliderProps<RootComponentType extends React.ElementType = SliderTypeMap['defaultComponent']> = PolymorphicProps<SliderTypeMap<{}, RootComponentType>, RootComponentType>;
155export type SliderRootSlotProps = UseSliderRootSlotProps & {
156 children: React.ReactNode;
157 className: string;
158 ownerState: SliderOwnerState;
159};
160export type SliderTrackSlotProps = {
161 className?: string;
162 ownerState: SliderOwnerState;
163 style: React.CSSProperties;
164};
165export type SliderRailSlotProps = {
166 className?: string;
167 ownerState: SliderOwnerState;
168};
169export type SliderThumbSlotProps = UseSliderThumbSlotProps & {
170 'data-index': number;
171 children: React.ReactNode;
172 className?: string;
173 ownerState: SliderOwnerState;
174 style: React.CSSProperties;
175};
176export type SliderMarkSlotProps = {
177 'data-index': number;
178 className?: string;
179 markActive?: boolean;
180 ownerState: SliderOwnerState;
181 style: React.CSSProperties;
182};
183export type SliderMarkLabelSlotProps = {
184 'aria-hidden': boolean;
185 'data-index': number;
186 className?: string;
187 markLabelActive?: boolean;
188 ownerState: SliderOwnerState;
189 style: React.CSSProperties;
190};
191export type SliderValueLabelSlotProps = {
192 children: React.ReactNode;
193 className?: string;
194 disabled?: boolean;
195 index?: number;
196 open?: boolean;
197 ownerState: SliderOwnerState;
198 valueLabel?: string | React.ReactNode;
199 valueLabelFormat?: string | ((value: number, index: number) => React.ReactNode);
200};
201export type SliderInputSlotProps = UseSliderHiddenInputProps & {
202 'aria-label': React.AriaAttributes['aria-label'];
203 'aria-valuenow': React.AriaAttributes['aria-valuenow'];
204 'aria-valuetext': React.AriaAttributes['aria-valuetext'];
205 'data-index': number;
206 ownerState: SliderOwnerState;
207 style: React.CSSProperties;
208 value: number;
209};
210
\No newline at end of file