-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9190bd
commit 57f3839
Showing
21 changed files
with
501 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script hide> | ||
import RangeSlider from "svelte-range-slider-pips"; | ||
let values = [25, 75]; | ||
</script> | ||
|
||
<RangeSlider id="always" float range bind:values /> | ||
|
||
<style> | ||
:global(#always .rangeFloat) { | ||
opacity: 1; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
import RangeSlider from 'svelte-range-slider-pips'; | ||
let slider; | ||
$: if ( slider ) { | ||
slider.querySelector('.rangeHandle').focus(); | ||
} | ||
</script> | ||
|
||
<RangeSlider bind:slider float /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script> | ||
import RangeSlider from 'svelte-range-slider-pips'; | ||
let values = [40,60]; | ||
let min = 0; | ||
let max = 100; | ||
let gap = 15; | ||
/** | ||
* maintain a distance of 1 between the handles when | ||
* the user is dragging the handle | ||
*/ | ||
const slide = ({ detail }) => { | ||
if (detail.activeHandle === 0 && values[1] < detail.value + gap) { | ||
values[1] = detail.value + gap; | ||
} | ||
if (detail.activeHandle === 1 && values[0] > detail.value - gap) { | ||
values[0] = detail.value - gap; | ||
} | ||
}; | ||
/** | ||
* enforce the gap between the handles when the user | ||
* stops dragging the handle | ||
*/ | ||
const stop = ({ detail }) => { | ||
if (detail.activeHandle === 0 && detail.value >= max - gap) { | ||
values[0] = max - gap; | ||
} | ||
if (detail.activeHandle === 1 && detail.value <= min + gap) { | ||
values[1] = min + gap; | ||
} | ||
}; | ||
</script> | ||
|
||
<RangeSlider range pushy pips bind:values on:change={slide} on:stop={stop} {min } {max} /> | ||
|
||
<code data-values title="The output slider values">{values}</code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* general RangeSlider styling */ | ||
#label.rangeSlider { | ||
font-size: 12px; | ||
text-transform: uppercase; | ||
} | ||
|
||
#label.rangeSlider.focus .rangeBar { | ||
background: linear-gradient(to left, var(--handle) 20%, var(--handle-focus)); | ||
} | ||
|
||
#label.rangeSlider.focus:has([data-handle="1"].active) .rangeBar { | ||
background: linear-gradient(to right, var(--handle) 20%, var(--handle-focus)); | ||
} | ||
|
||
/* Move the floating label on top of the handle */ | ||
|
||
#label.rangeSlider .rangeHandle { | ||
width: 2.8em; | ||
height: 2.8em; | ||
background: none; | ||
} | ||
|
||
#label.rangeSlider .rangeFloat { | ||
opacity: 1; | ||
background: transparent; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
/* Make the handles look like Squircles */ | ||
|
||
#label.rangeSlider .rangeHandle .rangeNub { | ||
border-radius: 0; | ||
transform: translate(0, 0); | ||
mask-image: url("data:image/svg+xml;utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E %3Cpath d=' M 100,0 C 22.460000000000008,0 0,22.460000000000008 0,100 0,177.54 22.460000000000008,200 100,200 177.54,200 200,177.54 200,100 200,22.460000000000008 177.54,0 100,0 ' style='fill: black;'%3E%3C/path%3E %3C/svg%3E"); | ||
mask-size: cover; | ||
} | ||
|
||
/* Hide the pips, and values when selected */ | ||
|
||
#label.rangeSlider .pip { | ||
background: transparent; | ||
} | ||
|
||
#label.rangeSlider .pip.selected .pipVal { | ||
opacity: 0; | ||
transition: all 0.25s ease; | ||
} |
59 changes: 59 additions & 0 deletions
59
src/components/Demos/recipes/monthpicker/MonthPicker.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script> | ||
import RangeSlider from "svelte-range-slider-pips"; | ||
import css from './MonthPicker.css?inline'; | ||
/* hide */ | ||
const renderCss = `<style>${css}</style>`; | ||
/* endhide */ | ||
let values = [2, 9]; | ||
let dateFormat = new Intl.DateTimeFormat("en", { month: "short" }); | ||
const formatter = (v, i, p) => { | ||
return dateFormat.format(new Date(new Date().getFullYear(), v, 1)); | ||
}; | ||
/** | ||
* maintain a distance of 1 between the handles when | ||
* the user is dragging the handle | ||
*/ | ||
const slide = ({ detail }) => { | ||
if (detail.activeHandle === 0 && values[1] < detail.value + 1) { | ||
values[1] = detail.value + 1; | ||
} | ||
if (detail.activeHandle === 1 && values[0] > detail.value - 1) { | ||
values[0] = detail.value - 1; | ||
} | ||
}; | ||
/** | ||
* enforce the gap between the handles when the user | ||
* stops dragging the handle | ||
*/ | ||
const stop = ({ detail }) => { | ||
if (detail.activeHandle === 0 && detail.value >= 10) { | ||
values[0] = 10; | ||
} | ||
if (detail.activeHandle === 1 && detail.value <= 0) { | ||
values[1] = 1; | ||
} | ||
}; | ||
</script> | ||
|
||
<RangeSlider | ||
id="label" | ||
bind:values | ||
float | ||
pips | ||
first="label" | ||
last="label" | ||
range | ||
max={11} | ||
{formatter} | ||
on:change={slide} | ||
on:stop={stop} | ||
/> | ||
|
||
|
||
<!-- hide --> | ||
{@html renderCss} | ||
<!-- endhide --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Mohave:ital,wght@0,300..700;1,300..700&display=swap'); | ||
|
||
/* Here we target specific pips and show them, | ||
which was the imaginary requirement of the slider design */ | ||
|
||
#future .pip[data-val="75000"], | ||
#future .pip[data-val="250000"], | ||
#future .pip[data-val="750000"], | ||
#future .pip[data-val="925000"] { | ||
display: block; | ||
} | ||
|
||
#future .pip[data-val="75000"] .pipVal, | ||
#future .pip[data-val="925000"] .pipVal { | ||
top: -2.25em; | ||
transform: translateX(-20%); | ||
} | ||
|
||
#future .pip[data-val="925000"] .pipVal { | ||
transform: translateX(-80%); | ||
} | ||
|
||
/* Range Slider / Bar customization */ | ||
|
||
#future.rangeSlider { | ||
font-family: "Mohave", sans-serif; | ||
font-weight: 300; | ||
font-style: italic; | ||
margin-inline: 100px; | ||
--handle-focus: limegreen; | ||
--float-text: black; | ||
height: 3px; | ||
background: black; | ||
} | ||
|
||
#future .rangeBar { | ||
height: 5px; | ||
top: -1px; | ||
background: limegreen; | ||
} | ||
|
||
/* Pips customization */ | ||
|
||
#future .pip { | ||
display: none; | ||
} | ||
|
||
#future .pip { | ||
background: none; | ||
top: 0; | ||
height: 1px; | ||
} | ||
|
||
#future .pip::before { | ||
content: ""; | ||
position: absolute; | ||
background: black; | ||
height: 1em; | ||
width: 1px; | ||
top: -0.5em; | ||
transform: translateY(-2px) translateX(-1px) rotate(10deg); | ||
} | ||
|
||
#future .pip.first, | ||
#future .pip.last { | ||
display: block; | ||
top: 0; | ||
background: transparent; | ||
} | ||
|
||
#future .pipVal { | ||
font-size: 14px; | ||
} | ||
|
||
#future .pip.first .pipVal { | ||
top: 0; | ||
left: -1em; | ||
transform: translateX(-100%) translateY(-50%); | ||
text-align: right; | ||
} | ||
|
||
#future .pip.last .pipVal { | ||
top: 0; | ||
right: -1em; | ||
transform: translateX(100%) translateY(-50%); | ||
text-align: left; | ||
} | ||
|
||
#future .pip.selected .pipVal { | ||
opacity: 0; | ||
} | ||
|
||
/* Floats / Handles customization */ | ||
|
||
#future .rangeHandle { | ||
height: 7px; | ||
top: 1px; | ||
} | ||
|
||
#future .rangeNub { | ||
transform: none; | ||
background: lime; | ||
box-shadow: 0 0 0px 2px black; | ||
} | ||
|
||
#future .rangeFloat { | ||
background: linear-gradient(to right, rgb(240, 241, 245, 0.25), rgb(240, 241, 245, 1) 20% 80%, rgb(240, 241, 245, 0.25)); | ||
top: -0.4em; | ||
padding: 0.1em 1em; | ||
line-height: 1; | ||
font-weight: 600; | ||
font-size: 1.25em; | ||
} |
Oops, something went wrong.