Skip to content

Commit c6323c0

Browse files
committed
add some unique styling for pips outside of limits
1 parent 426919b commit c6323c0

12 files changed

+425
-302
lines changed

dist/range-slider-pips.js

+181-146
Large diffs are not rendered by default.

dist/range-slider-pips.mjs

+181-146
Large diffs are not rendered by default.

dist/svelte/components/RangePips.svelte

+20-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
normalisedClient,
55
isInRange,
66
isSelected,
7-
getValueFromIndex
7+
getValueFromIndex,
8+
isOutOfLimit
89
} from "../utils.js";
910
export let range = false;
1011
export let min = 0;
@@ -16,6 +17,7 @@ export let vertical = false;
1617
export let reversed = false;
1718
export let hoverable = true;
1819
export let disabled = false;
20+
export let limits = null;
1921
export let pipstep = void 0;
2022
export let all = true;
2123
export let first = void 0;
@@ -64,6 +66,7 @@ function labelUp(pipValue, event) {
6466
class="pip first"
6567
class:selected={isSelected(min, values, precision)}
6668
class:in-range={isInRange(min, values, range)}
69+
class:out-of-limit={isOutOfLimit(min, limits)}
6770
style="{orientationStart}: 0%;"
6871
data-val={coerceFloat(min, precision)}
6972
on:pointerdown={(e) => {
@@ -91,6 +94,7 @@ function labelUp(pipValue, event) {
9194
class="pip"
9295
class:selected={isSelected(val, values, precision)}
9396
class:in-range={isInRange(val, values, range)}
97+
class:out-of-limit={isOutOfLimit(val, limits)}
9498
style="{orientationStart}: {valueAsPercent(val, min, max, precision)}%;"
9599
data-val={val}
96100
on:pointerdown={(e) => {
@@ -117,6 +121,7 @@ function labelUp(pipValue, event) {
117121
class="pip last"
118122
class:selected={isSelected(max, values, precision)}
119123
class:in-range={isInRange(max, values, range)}
124+
class:out-of-limit={isOutOfLimit(max, limits)}
120125
style="{orientationStart}: 100%;"
121126
data-val={coerceFloat(max, precision)}
122127
on:pointerdown={(e) => {
@@ -151,6 +156,8 @@ function labelUp(pipValue, event) {
151156
--pip-hover-text: var(--range-pip-hover-text, var(--pip-hover));
152157
--pip-in-range: var(--range-pip-in-range, var(--pip-active));
153158
--pip-in-range-text: var(--range-pip-in-range-text, var(--pip-active-text));
159+
--pip-out-of-range: var(--range-pip-out-of-range, #aebecf);
160+
--pip-out-of-range-text: var(--range-pip-out-of-range-text, var(--pip-out-of-range));
154161
}
155162
156163
:global(.rangePips) {
@@ -225,7 +232,7 @@ function labelUp(pipValue, event) {
225232
background-color: var(--pip-active);
226233
}
227234
228-
:global(.rangePips.hoverable:not(.disabled) .pip:hover) {
235+
:global(.rangePips.hoverable:not(.disabled) .pip:not(.out-of-limit):hover) {
229236
color: darkslategrey;
230237
color: var(--pip-hover-text);
231238
background-color: darkslategrey;
@@ -239,6 +246,13 @@ function labelUp(pipValue, event) {
239246
background-color: var(--pip-in-range);
240247
}
241248
249+
:global(.rangePips .pip.out-of-limit) {
250+
color: #aebecf;
251+
color: var(--pip-out-of-range-text);
252+
background-color: #aebecf;
253+
background-color: var(--pip-out-of-range);
254+
}
255+
242256
:global(.rangePips .pip.selected) {
243257
height: 0.75em;
244258
}
@@ -258,11 +272,13 @@ function labelUp(pipValue, event) {
258272
left: 0.75em;
259273
}
260274
261-
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):hover) {
275+
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):not(.out-of-limit):hover) {
262276
transition: none;
263277
}
264278
265-
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):hover .pipVal) {
279+
:global(
280+
.rangePips.hoverable:not(.disabled) .pip:not(.selected):not(.out-of-limit):hover .pipVal
281+
) {
266282
transition: none;
267283
font-weight: bold;
268284
}

dist/svelte/components/RangePips.svelte.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare const __propDef: {
1212
reversed?: boolean | undefined;
1313
hoverable?: boolean | undefined;
1414
disabled?: boolean | undefined;
15+
limits?: [number, number] | null | undefined;
1516
pipstep?: number | undefined;
1617
all?: Pip;
1718
first?: Pip;

dist/svelte/components/RangeSlider.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ function ariaLabelFormatter(value2, index) {
468468
{orientationStart}
469469
{hoverable}
470470
{disabled}
471+
{limits}
471472
{all}
472473
{first}
473474
{last}

dist/svelte/utils.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export declare const elementIndex: (el: Element | null) => number;
6363
* @returns {boolean} true if the value is in the range
6464
*/
6565
export declare const isInRange: (value: number, range: number[], type: string | boolean) => boolean | undefined;
66+
export declare const isOutOfLimit: (value: number, limits: number[] | null) => boolean;
6667
/**
6768
* helper to check if the given value is selected
6869
* @param value the value to check if is selected

dist/svelte/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ export const isInRange = (value, range, type) => {
122122
return range[0] < value && range[1] > value;
123123
}
124124
};
125+
export const isOutOfLimit = (value, limits) => {
126+
if (!limits)
127+
return false;
128+
return value < limits[0] || value > limits[1];
129+
};
125130
/**
126131
* helper to check if the given value is selected
127132
* @param value the value to check if is selected

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-range-slider-pips",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "Multi-Thumb, Accessible, Beautiful Range Slider with Pips",
55
"repository": {
66
"type": "git",

src/lib/components/RangePips.svelte

+20-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
normalisedClient,
66
isInRange,
77
isSelected,
8-
getValueFromIndex
8+
getValueFromIndex,
9+
isOutOfLimit
910
} from '$lib/utils.js';
1011
import type { Pip, Formatter, NormalisedClient } from '$lib/types.js';
1112
@@ -20,6 +21,7 @@
2021
export let reversed: boolean = false;
2122
export let hoverable: boolean = true;
2223
export let disabled: boolean = false;
24+
export let limits: null | [number, number] = null;
2325
2426
// range pips / values props
2527
export let pipstep: number | undefined = undefined;
@@ -86,6 +88,7 @@
8688
class="pip first"
8789
class:selected={isSelected(min, values, precision)}
8890
class:in-range={isInRange(min, values, range)}
91+
class:out-of-limit={isOutOfLimit(min, limits)}
8992
style="{orientationStart}: 0%;"
9093
data-val={coerceFloat(min, precision)}
9194
on:pointerdown={(e) => {
@@ -113,6 +116,7 @@
113116
class="pip"
114117
class:selected={isSelected(val, values, precision)}
115118
class:in-range={isInRange(val, values, range)}
119+
class:out-of-limit={isOutOfLimit(val, limits)}
116120
style="{orientationStart}: {valueAsPercent(val, min, max, precision)}%;"
117121
data-val={val}
118122
on:pointerdown={(e) => {
@@ -139,6 +143,7 @@
139143
class="pip last"
140144
class:selected={isSelected(max, values, precision)}
141145
class:in-range={isInRange(max, values, range)}
146+
class:out-of-limit={isOutOfLimit(max, limits)}
142147
style="{orientationStart}: 100%;"
143148
data-val={coerceFloat(max, precision)}
144149
on:pointerdown={(e) => {
@@ -173,6 +178,8 @@
173178
--pip-hover-text: var(--range-pip-hover-text, var(--pip-hover));
174179
--pip-in-range: var(--range-pip-in-range, var(--pip-active));
175180
--pip-in-range-text: var(--range-pip-in-range-text, var(--pip-active-text));
181+
--pip-out-of-range: var(--range-pip-out-of-range, #aebecf);
182+
--pip-out-of-range-text: var(--range-pip-out-of-range-text, var(--pip-out-of-range));
176183
}
177184
178185
:global(.rangePips) {
@@ -247,7 +254,7 @@
247254
background-color: var(--pip-active);
248255
}
249256
250-
:global(.rangePips.hoverable:not(.disabled) .pip:hover) {
257+
:global(.rangePips.hoverable:not(.disabled) .pip:not(.out-of-limit):hover) {
251258
color: darkslategrey;
252259
color: var(--pip-hover-text);
253260
background-color: darkslategrey;
@@ -261,6 +268,13 @@
261268
background-color: var(--pip-in-range);
262269
}
263270
271+
:global(.rangePips .pip.out-of-limit) {
272+
color: #aebecf;
273+
color: var(--pip-out-of-range-text);
274+
background-color: #aebecf;
275+
background-color: var(--pip-out-of-range);
276+
}
277+
264278
:global(.rangePips .pip.selected) {
265279
height: 0.75em;
266280
}
@@ -280,11 +294,13 @@
280294
left: 0.75em;
281295
}
282296
283-
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):hover) {
297+
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):not(.out-of-limit):hover) {
284298
transition: none;
285299
}
286300
287-
:global(.rangePips.hoverable:not(.disabled) .pip:not(.selected):hover .pipVal) {
301+
:global(
302+
.rangePips.hoverable:not(.disabled) .pip:not(.selected):not(.out-of-limit):hover .pipVal
303+
) {
288304
transition: none;
289305
font-weight: bold;
290306
}

src/lib/components/RangeSlider.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@
679679
{orientationStart}
680680
{hoverable}
681681
{disabled}
682+
{limits}
682683
{all}
683684
{first}
684685
{last}

src/lib/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export const alignValueToStep = function (
6666
precision: number = 2,
6767
limits: [number, number] | null = null
6868
) {
69-
7069
// if limits are provided, clamp the value between the limits
7170
// if no limits are provided, clamp the value between the min and max
7271
value = clampValue(value, limits?.[0] ?? min, limits?.[1] ?? max);
@@ -142,6 +141,11 @@ export const isInRange = (value: number, range: number[], type: string | boolean
142141
}
143142
};
144143

144+
export const isOutOfLimit = (value: number, limits: number[] | null) => {
145+
if (!limits) return false;
146+
return value < limits[0] || value > limits[1];
147+
};
148+
145149
/**
146150
* helper to check if the given value is selected
147151
* @param value the value to check if is selected

src/routes/+page.svelte

+8
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@
318318
bind:values={limitBind}
319319
range
320320
limits={null}
321+
pips
322+
all="label"
321323
pushy
322324
float
323325
{reversed}
@@ -336,6 +338,8 @@
336338
<RangeSlider
337339
bind:values={limitBind2}
338340
limits={[20, 80]}
341+
pips
342+
all="label"
339343
pushy
340344
float
341345
{reversed}
@@ -356,6 +360,8 @@
356360
bind:values={limitBind2}
357361
range
358362
limits={[20, 80]}
363+
pips
364+
all="label"
359365
pushy
360366
float
361367
{reversed}
@@ -375,6 +381,8 @@
375381
bind:values={limitBind3}
376382
range="min"
377383
limits={[20, 80]}
384+
pips
385+
all="label"
378386
pushy
379387
float
380388
{reversed}

0 commit comments

Comments
 (0)