Created
March 30, 2020 14:32
-
-
Save snewcomer/f66cefe63dff9e3c5520874dd4dfaf01 to your computer and use it in GitHub Desktop.
Range Slider
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
import Component from '@glimmer/component'; | |
import { action } from '@ember/object'; | |
export default class extends Component { | |
get handleStyles() { | |
const fraction = (this.args.currentValue / this.args.max) * 100; | |
return `left: ${fraction}%`; | |
} | |
@action | |
onClick(event) { | |
const { clientX } = event; | |
const { width, x } = event.target.getBoundingClientRect(); | |
this.args.onChange(((clientX - x) / width) * 100); | |
} | |
} |
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
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class ApplicationController extends Controller { | |
@tracked | |
currentValue = 30; | |
@action | |
onChange(value) { | |
this.currentValue = value; | |
} | |
} |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.range-slider { | |
height: 100px; | |
background-color: lightgrey; | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
padding: 10px; | |
} | |
.range-slider--interactive { | |
position: relative; | |
display: flex; | |
justify-content: center; | |
height: 10px; | |
background-color: grey; | |
} | |
.range-slider--handle { | |
position: absolute; | |
left: 40%; | |
height: 10px; | |
width: 10px; | |
border-radius: 50%; | |
background-color: red; | |
margin-left: -5px; | |
} |
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
{ | |
"version": "0.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment