This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(slider): Implement continuous slider component #781
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
demos/* linguist-documentation | ||
docs/* linguist-documentation | ||
framework-examples/* linguist-documentation | ||
/package-lock.json linguist-generated |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,225 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Copyright 2017 Google Inc. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License | ||
--> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Slider - Material Components Catalog</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png" /> | ||
<script src="assets/material-components-web.css.js" charset="utf-8"></script> | ||
<script src="assets/demo-styles.css.js" charset="utf-8"></script> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> | ||
<style> | ||
#hero-slider-wrapper { | ||
margin: 0 auto; | ||
width: 100%; | ||
max-width: 600px; | ||
/* Blended equivalent of rgba(0, 0, 0, .05); */ | ||
--mdc-slider-bg-color-behind-component: #f2f2f2; | ||
} | ||
|
||
.mdc-theme--dark { | ||
background-color: #333; | ||
--mdc-theme-primary: #64dd17; | ||
} | ||
|
||
.custom-bg { | ||
background-color: #eee; | ||
--mdc-slider-bg-color-behind-component: #eee; | ||
} | ||
|
||
.mdc-theme--dark.custom-bg { | ||
background-color: #102027; | ||
--mdc-slider-bg-color-behind-component: #102027; | ||
} | ||
|
||
.example-slider-wrapper { | ||
padding: 0 16px; | ||
} | ||
</style> | ||
</head> | ||
<body class="mdc-typography"> | ||
<header class="mdc-toolbar mdc-toolbar--fixed"> | ||
<div class="mdc-toolbar__row"> | ||
<section class="mdc-toolbar__section mdc-toolbar__section--align-start"> | ||
<span class="catalog-back"> | ||
<a href="/" class="mdc-toolbar__icon--menu"><i class="material-icons"></i></a> | ||
</span> | ||
<span class="mdc-toolbar__title catalog-title">Slider</span> | ||
</section> | ||
</div> | ||
</header> | ||
<main> | ||
<div class="mdc-toolbar-fixed-adjust"></div> | ||
<section class="hero"> | ||
<div id="hero-slider-wrapper"> | ||
<div id="hero-slider" class="mdc-slider" tabindex="0" | ||
role="slider" aria-valuemin="0" aria-valuemax="100" aria-valuenow="30" | ||
aria-label="Select Value"> | ||
<div class="mdc-slider__track-container"> | ||
<div class="mdc-slider__track"></div> | ||
</div> | ||
<div class="mdc-slider__thumb-container"> | ||
<svg class="mdc-slider__thumb" width="21" height="21"> | ||
<circle cx="10.5" cy="10.5" r="7.875"></circle> | ||
</svg> | ||
<div class="mdc-slider__focus-ring"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
<section class="example"><em>Note that in browsers that support custom properties, we alter theme's primary | ||
color when using the dark theme toggle so that the slider appears more visible</em></section> | ||
|
||
<section class="example"> | ||
<h2>Continuous Slider</h2> | ||
<div id="continuous-slider-example" class="slider-example"> | ||
<p id="example-cs-label">Select Value:</p> | ||
|
||
<div class="example-slider-wrapper"> | ||
<div class="mdc-slider" tabindex="0" role="slider" | ||
aria-valuemin="0" aria-valuemax="100" aria-valuenow="30" | ||
aria-labelledby="example-cs-label"> | ||
<div class="mdc-slider__track-container"> | ||
<div class="mdc-slider__track"></div> | ||
</div> | ||
<div class="mdc-slider__thumb-container"> | ||
<svg class="mdc-slider__thumb" width="21" height="21"> | ||
<circle cx="10.5" cy="10.5" r="7.875"></circle> | ||
</svg> | ||
<div class="mdc-slider__focus-ring"></div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<label> | ||
Min: <input name="min" type="number" min="0" max="100" value="0"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Max: <input name="max" type="number" min="0" max="100" value="100"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Step: <input name="step" type="number" min="0" max="100" value="0"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Dark Theme: <input type="checkbox" name="dark-theme"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Disabled: <input type="checkbox" name="disabled"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
Use Custom BG Color: <input type="checkbox" name="use-custom-color"> | ||
</label> | ||
</div> | ||
<div> | ||
<label> | ||
RTL: <input type="checkbox" name="rtl"> | ||
</label> | ||
</div> | ||
<p> | ||
Value from <code>MDCSlider:input</code> event: <span class="value">0</span> | ||
</p> | ||
<p> | ||
Value from <code>MDCSlider:change</code> event: <span class="committed-value">0</span> | ||
</p> | ||
</div> | ||
</section> | ||
</main> | ||
<script src="assets/material-components-web.js" charset="utf-8"></script> | ||
<script> | ||
(function() { | ||
setTimeout(function() { | ||
mdc.slider.MDCSlider.attachTo(document.getElementById('hero-slider')); | ||
initDemo(document.getElementById('continuous-slider-example')); | ||
}, 80); | ||
|
||
function initDemo(demoRoot) { | ||
var min = demoRoot.querySelector('[name="min"]'); | ||
var max = demoRoot.querySelector('[name="max"]'); | ||
var step = demoRoot.querySelector('[name="step"]'); | ||
var darkTheme = demoRoot.querySelector('[name="dark-theme"]'); | ||
var disabled = demoRoot.querySelector('[name="disabled"]'); | ||
var useCustomColor = demoRoot.querySelector('[name="use-custom-color"]'); | ||
var rtl = demoRoot.querySelector('[name="rtl"]'); | ||
var value = demoRoot.querySelector('.value'); | ||
var committedValue = demoRoot.querySelector('.committed-value'); | ||
var sliderEl = demoRoot.querySelector('.mdc-slider'); | ||
var slider = new mdc.slider.MDCSlider(sliderEl); | ||
|
||
slider.listen('MDCSlider:input', function() { | ||
value.textContent = slider.value; | ||
}); | ||
|
||
slider.listen('MDCSlider:change', function() { | ||
committedValue.textContent = slider.value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: would demonstrate that the event come with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry but I'm not sure what you mean here... |
||
}); | ||
|
||
min.addEventListener('input', function() { | ||
slider.min = parseFloat(min.value); | ||
}); | ||
|
||
max.addEventListener('input', function() { | ||
slider.max = parseFloat(max.value); | ||
}); | ||
|
||
step.addEventListener('input', function() { | ||
slider.step = parseFloat(step.value); | ||
}); | ||
|
||
darkTheme.addEventListener('change', function() { | ||
demoRoot | ||
.querySelector('.example-slider-wrapper') | ||
.classList[ darkTheme.checked ? 'add' : 'remove']('mdc-theme--dark'); | ||
}); | ||
|
||
disabled.addEventListener('change', function() { | ||
slider.disabled = disabled.checked; | ||
}); | ||
|
||
useCustomColor.addEventListener('change', function() { | ||
demoRoot | ||
.querySelector('.example-slider-wrapper') | ||
.classList[ useCustomColor.checked ? 'add' : 'remove' ]('custom-bg'); | ||
}); | ||
|
||
rtl.addEventListener('change', function() { | ||
var wrapper = demoRoot.querySelector('.example-slider-wrapper'); | ||
if (rtl.checked) { | ||
wrapper.setAttribute('dir', 'rtl'); | ||
} else { | ||
wrapper.removeAttribute('dir'); | ||
} | ||
slider.layout(); | ||
}); | ||
} | ||
})(); | ||
</script> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that we handle the contrast of component/dark background by applying the accent color to the component. I feel this would be useful in other demos as well (
mdc-switch
comes to mind).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed and noted. Should I file an issue? Should we do this within demos.scss and make a general note somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an issue is appropriate. That way we can toss up a
help-wanted
label and see if anyone bites.