UNPKG

4.47 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent2, Intent } from "../../common";
3import { IntentProps, Props } from "../../common/props";
4export interface ISliderBaseProps extends Props, IntentProps {
5 /**
6 * Whether the slider is non-interactive.
7 *
8 * @default false
9 */
10 disabled?: boolean;
11 /**
12 * Increment between successive labels. Must be greater than zero.
13 *
14 * @default inferred (if labelStepSize is undefined)
15 */
16 labelStepSize?: number;
17 /**
18 * Array of specific values for the label placement. This prop is mutually exclusive with
19 * `labelStepSize`.
20 */
21 labelValues?: number[];
22 /**
23 * Number of decimal places to use when rendering label value. Default value is the number of
24 * decimals used in the `stepSize` prop. This prop has _no effect_ if you supply a custom
25 * `labelRenderer` callback.
26 *
27 * @default inferred from stepSize
28 */
29 labelPrecision?: number;
30 /**
31 * Maximum value of the slider.
32 *
33 * @default 10
34 */
35 max?: number;
36 /**
37 * Minimum value of the slider.
38 *
39 * @default 0
40 */
41 min?: number;
42 /**
43 * Whether a solid bar should be rendered on the track between current and initial values,
44 * or between handles for `RangeSlider`.
45 *
46 * @default true
47 */
48 showTrackFill?: boolean;
49 /**
50 * Increment between successive values; amount by which the handle moves. Must be greater than zero.
51 *
52 * @default 1
53 */
54 stepSize?: number;
55 /**
56 * Callback to render a single label. Useful for formatting numbers as currency or percentages.
57 * If `true`, labels will use number value formatted to `labelPrecision` decimal places.
58 * If `false`, labels will not be shown.
59 *
60 * The callback is provided a numeric value and optional rendering options, which include:
61 * - isHandleTooltip: whether this label is being rendered within a handle tooltip
62 *
63 * @default true
64 */
65 labelRenderer?: boolean | ((value: number, opts?: {
66 isHandleTooltip: boolean;
67 }) => string | JSX.Element);
68 /**
69 * Whether to show the slider in a vertical orientation.
70 *
71 * @default false
72 */
73 vertical?: boolean;
74}
75export declare type MultiSliderProps = IMultiSliderProps;
76/** @deprecated use MultiSliderProps */
77export interface IMultiSliderProps extends ISliderBaseProps {
78 /** Default intent of a track segment, used only if no handle specifies `intentBefore/After`. */
79 defaultTrackIntent?: Intent;
80 /** Callback invoked when a handle value changes. Receives handle values in sorted order. */
81 onChange?(values: number[]): void;
82 /** Callback invoked when a handle is released. Receives handle values in sorted order. */
83 onRelease?(values: number[]): void;
84}
85export interface ISliderState {
86 labelPrecision: number;
87 /** the client size, in pixels, of one tick */
88 tickSize: number;
89 /** the size of one tick as a ratio of the component's client size */
90 tickSizeRatio: number;
91}
92export declare class MultiSlider extends AbstractPureComponent2<MultiSliderProps, ISliderState> {
93 static defaultSliderProps: ISliderBaseProps;
94 static defaultProps: MultiSliderProps;
95 static displayName: string;
96 static Handle: React.FunctionComponent<import("./handleProps").IHandleProps>;
97 static getDerivedStateFromProps(props: MultiSliderProps): {
98 labelPrecision: number;
99 };
100 private static getLabelPrecision;
101 state: ISliderState;
102 private handleElements;
103 private trackElement;
104 getSnapshotBeforeUpdate(prevProps: MultiSliderProps): null;
105 render(): JSX.Element;
106 componentDidMount(): void;
107 componentDidUpdate(prevProps: MultiSliderProps, prevState: ISliderState): void;
108 protected validateProps(props: React.PropsWithChildren<MultiSliderProps>): void;
109 private formatLabel;
110 private renderLabels;
111 private renderTracks;
112 private renderTrackFill;
113 private renderHandles;
114 private addHandleRef;
115 private maybeHandleTrackClick;
116 private maybeHandleTrackTouch;
117 private canHandleTrackEvent;
118 private nearestHandleForValue;
119 private getHandlerForIndex;
120 private getNewHandleValues;
121 private findFirstLockedHandleIndex;
122 private handleChange;
123 private handleRelease;
124 private getLabelValues;
125 private getOffsetRatio;
126 private getTrackIntent;
127 private updateTickSize;
128}