UNPKG

8.13 kBTypeScriptView Raw
1declare namespace FomanticUI {
2 interface Slider {
3 settings: SliderSettings;
4
5 /**
6 * Get the current selected value.
7 */
8 (behavior: 'get value'): number;
9
10 /**
11 * Get the selected value of one of the range thumbs.
12 * Provide either 'first' or 'second' as a string parameter.
13 */
14 (behavior: 'get thumbValue', which: 'first' | 'second'): number;
15
16 /**
17 * Get the number of rendered label ticks.
18 */
19 (behavior: 'get numLabels'): number;
20
21 /**
22 * Set the current slider value.
23 * Pass 'false' to 'fireChange' to skip the 'onChange' and 'onMove' callbacks.
24 */
25 (behavior: 'set value', value: number, fireChange: boolean): void;
26
27 /**
28 * Set the current range slider values.
29 * Pass 'false' to 'fireChange' to skip the 'onChange' and 'onMove' callbacks.
30 */
31 (behavior: 'set rangeValue', fromValue: number, toValue: number, fireChange: boolean): JQuery;
32
33 /**
34 * Destroys instance and removes all events.
35 */
36 (behavior: 'destroy'): JQuery;
37
38 <K extends keyof SliderSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<SliderSettings, keyof SliderSettings>>;
39 <K extends keyof SliderSettings>(behavior: 'setting', name: K, value: SliderSettings[K]): JQuery;
40 (behavior: 'setting', value: Partial<Pick<SliderSettings, keyof SliderSettings>>): JQuery;
41 (settings?: Partial<Pick<SliderSettings, keyof SliderSettings>>): JQuery;
42 }
43
44 /**
45 * @see {@link https://fomantic-ui.com/modules/slider.html#/settings}
46 */
47 interface SliderSettings {
48 // region Slider Settings
49
50 /**
51 * The lowest value the slider can be.
52 * @default 0
53 */
54 min: number;
55
56 /**
57 * The max value the slider can be.
58 * @default 20
59 */
60 max: number;
61
62 /**
63 * The slider step.
64 * Set to '0' to disable step.
65 * @default 1
66 */
67 step: number;
68
69 /**
70 * The value the slider will start at.
71 * @default 0
72 */
73 start: number;
74
75 /**
76 * The second value to set in case of a range slider.
77 * @default 20
78 */
79 end: number;
80
81 /**
82 * The type of label to display for a labeled slider.
83 * Can be 'number' or 'letter'.
84 * @default 'number'
85 */
86 labelType: 'number' | 'letter';
87
88 /**
89 * You can specify a function here which consumes the current label value as parameter and should return a custom label text according to the given value.
90 * @default false
91 */
92 interpretLabel: false | Function;
93
94 /**
95 * Show ticks on a labeled slider.
96 * @default false
97 */
98 showLabelTicks: boolean;
99
100 /**
101 * Define smoothness when the slider is moving.
102 * @default false
103 */
104 smooth: boolean;
105
106 /**
107 * Whether labels should auto adjust on window resize.
108 * @default true
109 */
110 autoAdjustLabels: boolean;
111
112 /**
113 * The distance between labels.
114 * @default 100
115 */
116 labelDistance: number;
117
118 /**
119 * Number of decimals to use with an unstepped slider.
120 * @default 2
121 */
122 decimalPlaces: number;
123
124 /**
125 * Page up/down multiplier.
126 * Define how many more times the steps to take on page up/down press.
127 * @default 2
128 */
129 pageMultiplier: number;
130
131 /**
132 * Prevents the lower thumb to crossover the thumb handle.
133 * @default true
134 */
135 preventCrossover: boolean;
136
137 // endregion
138
139 // region Callbacks
140
141 /**
142 * Is called when the slider value is changed.
143 */
144 onChange(this: JQuery, value: number, thumbVal: number, secondThumbVal: number): void;
145
146 /**
147 * Is called when the slider is moving.
148 */
149 onMove(this: JQuery, value: number, thumbVal: number, secondThumbVal: number): void;
150
151 // endregion
152
153 // region DOM Settings
154
155 /**
156 * Class names used to determine element state.
157 */
158 className: Slider.ClassNameSettings;
159
160 /**
161 * DOM metadata used by module.
162 */
163 metadata: Slider.MetadataSettings;
164
165 /**
166 * Keys used by module.
167 */
168 keys: Slider.KeySettings;
169
170 // endregion
171
172 // region Debug Settings
173
174 /**
175 * Name used in log statements
176 * @default 'Slider'
177 */
178 name: string;
179
180 /**
181 * Event namespace. Makes sure module teardown does not effect other events attached to an element.
182 * @default 'slider'
183 */
184 namespace: string;
185
186 /**
187 * Silences all console output including error messages, regardless of other debug settings.
188 * @default false
189 */
190 silent: boolean;
191
192 /**
193 * Debug output to console
194 * @default false
195 */
196 debug: boolean;
197
198 /**
199 * Show console.table output with performance metrics
200 * @default true
201 */
202 performance: boolean;
203
204 /**
205 * Debug output includes all internal behaviors
206 * @default false
207 */
208 verbose: boolean;
209
210 error: Slider.ErrorSettings;
211
212 // endregion
213 }
214
215 namespace Slider {
216 type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
217 type MetadataSettings = Partial<Pick<Settings.Metadatas, keyof Settings.Metadatas>>;
218 type KeySettings = Partial<Pick<Settings.Keys, keyof Settings.Keys>>;
219 type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
220
221 namespace Settings {
222 interface ClassNames {
223 /**
224 * @default 'reversed'
225 */
226 reversed: string;
227
228 /**
229 * @default 'disabled'
230 */
231 disabled: string;
232
233 /**
234 * @default 'labeled'
235 */
236 labeled: string;
237
238 /**
239 * @default 'ticked'
240 */
241 ticked: string;
242
243 /**
244 * @default 'vertical'
245 */
246 vertical: string;
247
248 /**
249 * @default 'range'
250 */
251 range: string;
252
253 /**
254 * @default 'smooth'
255 */
256 smooth: string;
257 }
258
259 interface Metadatas {
260 /**
261 * @default 'thumbVal'
262 */
263 thumbVal: string;
264
265 /**
266 * @default 'secondThumbVal'
267 */
268 secondThumbVal: string;
269 }
270
271 interface Keys {
272 /**
273 * @default 33
274 */
275 pageUp: number;
276
277 /**
278 * @default 34
279 */
280 pageDown: number;
281
282 /**
283 * @default 37
284 */
285 leftArrow: number;
286
287 /**
288 * @default 38
289 */
290 upArrow: number;
291
292 /**
293 * @default 39
294 */
295 rightArrow: number;
296
297 /**
298 * @default 40
299 */
300 downArrow: number;
301 }
302
303 interface Errors {
304 /**
305 * @default 'The method you called is not defined.'
306 */
307 method: string;
308
309 /**
310 * @default 'This slider is not a range slider.'
311 */
312 notrange: string;
313 }
314 }
315 }
316}