UNPKG

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