Last active
May 20, 2017 14:51
-
-
Save Conaws/7ffd9077592e309e7db4d1eb72cd3418 to your computer and use it in GitHub Desktop.
CSS for Multiple Sliders using Re-Com
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
(ns devcards.sliders | |
(:require [re-com.core :as rc] | |
[reagent.core :as r]) | |
(:require-macros | |
[devcards.core :as dc :refer [defcard-rg]])) | |
(def rangeatom (r/atom 50)) | |
(def rangeatom2 (r/atom 5)) | |
(defcard-rg sliders | |
[:div | |
[rc/slider | |
:class "multirange original" | |
:model rangeatom | |
:on-change #(reset! rangeatom %)] | |
[rc/slider | |
:class "multirange ghost" | |
:model rangeatom2 | |
:on-change #(reset! rangeatom2 %)] | |
]) | |
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
@supports (--css: variables) { | |
input[type="range"].multirange { | |
padding: 0; | |
margin: 0; | |
display: inline-block; | |
vertical-align: top; | |
} | |
input[type="range"].multirange.original { | |
position: absolute; | |
} | |
input[type="range"].multirange.original::-webkit-slider-thumb { | |
position: relative; | |
z-index: 2; | |
} | |
input[type="range"].multirange.original::-moz-range-thumb { | |
transform: scale(1); /* FF doesn't apply position it seems */ | |
z-index: 1; | |
} | |
input[type="range"].multirange::-moz-range-track { | |
border-color: transparent; /* needed to switch FF to "styleable" control */ | |
} | |
input[type="range"].multirange.ghost { | |
position: relative; | |
background: var(--track-background); | |
--track-background: linear-gradient(to right, | |
transparent var(--low), var(--range-color) 0, | |
var(--range-color) var(--high), transparent 0 | |
) no-repeat 0 45% / 100% 40%; | |
--range-color: hsl(190, 80%, 40%); | |
} | |
input[type="range"].multirange.ghost::-webkit-slider-runnable-track { | |
background: var(--track-background); | |
} | |
input[type="range"].multirange.ghost::-moz-range-track { | |
background: var(--track-background); | |
} | |
} |
this approach works well, would be a good extension of the re-com slider
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allows two sliders to sit on same track
If you use reagent/track it'd be possible to have the on-change fn's react to the value of both reactions so that the sliders could restrict each other's motion
Might be cool as an option to component, for now just an example