Skip to content

Commit

Permalink
Add Dual Range Example
Browse files Browse the repository at this point in the history
  • Loading branch information
coliff committed Jul 12, 2024
1 parent 1695f83 commit 25947b1
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/css/_footer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.footer {
background-color: rgb(14, 65, 108);
border-top: 1px solid transparent;
content-visibility: auto; /* stylelint-disable-line */
contain-intrinsic-size: 333px; /* stylelint-disable-line */
font-size: 14px;
Expand Down
6 changes: 0 additions & 6 deletions content/components/toasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ div to create an toast.
<i class="modus-icon modus-icons" aria-hidden="true">close</i>
</button>
</div>
<div class="toast toast-warning show" role="alert" aria-live="assertive" aria-atomic="true">
Aww yeah, you read a warning toast.
<button type="button" class="close" data-dismiss="toast" aria-label="Close">
<i class="modus-icon modus-icons" aria-hidden="true">close</i>
</button>
</div>
<div class="toast toast-success show" role="alert" aria-live="assertive" aria-atomic="true">
Aww yeah, you read a success toast.
<button type="button" class="close" data-dismiss="toast" aria-label="Close">
Expand Down
1 change: 1 addition & 0 deletions content/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ hidden: true
- [Table with Sticky Header and First Column](/examples/table-with-sticky-header-and-column/) <small class="text-muted"></small>
- [Collapsible Side Panel](/examples/collapsible-side-panel)
- [Maps Webapp](/examples/maps-webapp)
- [Dual-Range Slider](/examples/dual-range-meter/)
80 changes: 80 additions & 0 deletions static/examples/dual-range-meter/dual-range.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.dual-range-container {
flex-direction: column;
width: 400px;
}

.dual-range-container .input-group-text {
background-color: #cbcdd6;
border: 0;
color: #252a2e;
font-size: 12px;
}

.dual-range-container .input-group-append .input-group-text {
padding-left: 1px;
}

#fromSlider {
z-index: 1;
height: 0;
margin-top: 3px;
}

.sliders-control {
height: 18px;
background: repeating-linear-gradient(90deg, #888, #888 1px, transparent 1px, transparent 38.8px) no-repeat 50% 50%;
background-position: bottom center;
background-size: 393px 6px;
position: relative;
}

.form-control-container-time-input {
background-color: #cbcdd6;
border: 0 !important;
color: #252a2e;
max-width: 28px;
height: 32px;
padding-left: 0 !important;
padding-right: 0 !important;
opacity: 1 !important;
text-align: center;
}

.dual-range-container input[type="range"] {
appearance: none;
border-radius: 4px;
height: 6px;
forced-color-adjust: none;
pointer-events: none;
position: absolute;
width: 100%;
}

.dual-range-container input[type="range"]::-webkit-slider-thumb {
width: 1rem;
height: 1rem;
appearance: none;
pointer-events: all;
cursor: pointer;
background-color: #fff;
border-radius: 50%;
box-shadow: 0 0 0 2px #0063a3;
}

.dual-range-container input[type="range"]::-moz-range-thumb {
width: 1rem;
height: 1rem;
pointer-events: all;
cursor: pointer;
background-color: #fff;
border-radius: 50%;
box-shadow: 0 0 0 2px #0063a3;
}

.dual-range-container input[type="range"]::-webkit-slider-thumb:hover {
background: #f7f7f7;
}

.dual-range-container input[type="range"]::-webkit-slider-thumb:active {
box-shadow: inset 0 0 3px #387bbe, 0 0 9px #387bbe;
}
100 changes: 100 additions & 0 deletions static/examples/dual-range-meter/dual-range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
function controlFromInput(fromSlider, fromInput, toInput, controlSlider) {
const [from, to] = getParsed(fromInput, toInput);
fillSlider(fromInput, toInput, '#0063a3', '#ddd', controlSlider);
if (from > to) {
fromSlider.value = to;
fromInput.value = to;
} else {
fromSlider.value = from;
}
}

function controlToInput(toSlider, fromInput, toInput, controlSlider) {
const [from, to] = getParsed(fromInput, toInput);
fillSlider(fromInput, toInput, '#0063a3', '#ddd', controlSlider);
setToggleAccessible(toInput);
if (from <= to) {
toSlider.value = to;
toInput.value = to;
} else {
toInput.value = from;
}
}

function controlFromSlider(fromSlider, toSlider, fromInput) {
const [from, to] = getParsed(fromSlider, toSlider);
fillSlider(fromSlider, toSlider, '#0063a3', '#ddd', toSlider);
if (from > to) {
fromSlider.value = to;
fromInput.value = to;
} else {
fromInput.value = from;
}
}

function controlToSlider(fromSlider, toSlider, toInput) {
const [from, to] = getParsed(fromSlider, toSlider);
fillSlider(fromSlider, toSlider, '#0063a3', '#ddd', toSlider);
setToggleAccessible(toSlider);
if (from <= to) {
toSlider.value = to;
toInput.value = to;
} else {
toInput.value = from;
toSlider.value = from;
}
}

function getParsed(currentFrom, currentTo) {
const from = parseInt(currentFrom.value, 10);
const to = parseInt(currentTo.value, 10);
return [from, to];
}

function fillSlider(from, to, sliderColor, rangeColor, controlSlider) {
const rangeDistance = to.max - to.min;
const fromPosition = from.value - to.min;
const toPosition = to.value - to.min;
controlSlider.style.background = `linear-gradient(
to right,
${sliderColor} 0%,
${sliderColor} ${(fromPosition / rangeDistance) * 100}%,
${rangeColor} ${(fromPosition / rangeDistance) * 100}%,
${rangeColor} ${(toPosition / rangeDistance) * 100}%,
${sliderColor} ${(toPosition / rangeDistance) * 100}%,
${sliderColor} 100%)`;
}

function setToggleAccessible(currentTarget) {
const toSlider = document.querySelector('#toSlider');
if (Number(currentTarget.value) <= 0) {
toSlider.style.zIndex = 2;
} else {
toSlider.style.zIndex = 0;
}
}

const fromSlider = document.querySelector('#fromSlider');
const toSlider = document.querySelector('#toSlider');
const fromInput = document.querySelector('#fromInput');
const toInput = document.querySelector('#toInput');
fillSlider(fromSlider, toSlider, '#0063a3', '#ddd', toSlider);
setToggleAccessible(toSlider);

fromSlider.oninput = () => controlFromSlider(fromSlider, toSlider, fromInput);
toSlider.oninput = () => controlToSlider(fromSlider, toSlider, toInput);
fromInput.oninput = () =>
controlFromInput(fromSlider, fromInput, toInput, toSlider);
toInput.oninput = () => controlToInput(toSlider, fromInput, toInput, toSlider);

document.addEventListener('DOMContentLoaded', function () {
var fromInput = document.getElementById('fromInput');
var fromSlider = document.getElementById('fromSlider');

fromInput.addEventListener('blur', function () {
if (this.value === '') {
this.value = '30';
fromSlider.value = '30';
}
});
});
50 changes: 50 additions & 0 deletions static/examples/dual-range-meter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

<!DOCTYPE html>
<html lang="en" data-bs-theme="auto">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Dual Range with Meter</title>
<meta name="description" content="Dual Range with Meter" />
<link href="https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.4/dist/modus.min.css" rel="stylesheet" />
<link href="dual-range.css" rel="stylesheet" />
<script src="dual-range.js" defer></script>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2280%22>🌡️</text></svg>" />
<meta name="robots" content="noindex, nofollow" />
</head>

<body class="mt-5 overflow-hidden">
<div class="d-flex dual-range-container mx-auto">
<div class="mb-2">
<h4>Temperature Threshold</h4>
</div>

<div class="sliders-control my-2">
<input id="fromSlider" aria-label="from" type="range" value="30" min="0" max="99" />
<input id="toSlider" aria-label="to" type="range" value="70" min="1" max="100" />
</div>

<div class="mt-1 row">
<div class="input-group input-group-sm col-6">
<div class="input-group-prepend">
<label class="input-group-text pl-1 pr-0">Less than</label>
</div>
<input disabled type="text" id="fromInput" value="30" class="form-control form-control-container-time-input" required />
<div class="input-group-append">
<span class="input-group-text">&deg;F</span>
</div>
</div>

<div class="input-group input-group-sm col-6 justify-content-end">
<div class="input-group-prepend">
<label class="input-group-text px-1">Greater than</label>
</div>
<input disabled type="text" id="toInput" value="70" class="form-control form-control-container-time-input" required />
<div class="input-group-append">
<span class="input-group-text">&deg;F</span>
</div>
</div>
</div>
</div>
</body>
</html>
8 changes: 4 additions & 4 deletions static/examples/maps-webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ <h5 class="card-title">Panel Content</h5>
</div>
<!-- .modus-layout -->

<script src="https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.2/dist/modus-layout.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.4/dist/modus-layout.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@trimblemaps/trimblemaps-js@3.16.0/trimblemaps.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@trimblemaps/trimblemaps-js@3.17.0/trimblemaps.min.js"></script>
<script>
TrimbleMaps.APIKey = "68B06901AF7DA34884CE5FB7A202A743";

Expand All @@ -284,9 +284,9 @@ <h5 class="card-title">Panel Content</h5>
var toggle = document.getElementById("style-switch");
toggle.onchange = function (e) {
if (e.target.checked) {
swapStyleSheet("https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.2/dist/modus-dark.min.css");
swapStyleSheet("https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.4/dist/modus-dark.min.css");
} else {
swapStyleSheet("https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.2/dist/modus.min.css");
swapStyleSheet("https://cdn.jsdelivr.net/npm/@trimbleinc/modus-bootstrap@1.6.4/dist/modus.min.css");
}
};
}
Expand Down

0 comments on commit 25947b1

Please sign in to comment.