Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit addc1b1

Browse files
authored
Merge pull request #57 from microsoft/users-t-famoun/sliderBar
Created the slider Bar to control sensor inputs.
2 parents 42fbb4f + 792fa33 commit addc1b1

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

src/view/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"use strict";
55
import * as React from "react";
66
import Simulator from "./components/Simulator";
7+
import InputSlider from "./components/toolbar/InputSlider"
78
import "./App.css";
89

910
class App extends React.Component {
@@ -12,6 +13,7 @@ class App extends React.Component {
1213
<div className="App">
1314
<header className="App-header">
1415
<Simulator />
16+
<InputSlider min={0} max={250} step={1} min_label={"min"} max_label={"max"}/>
1517
<a
1618
className="App-link"
1719
href="https://github.com/microsoft/vscode-python-embedded"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
.inputSlider{
3+
height: 50px;
4+
margin-bottom: 100px;
5+
}
6+
.sliderValue{
7+
text-align: center;
8+
width: 50px;
9+
height: 50px;
10+
background-color: var(--vscode-editor-background);
11+
color: white;
12+
border:0;
13+
margin-right: 15px;
14+
}
15+
16+
.slider{
17+
-webkit-appearance: none;
18+
background-color: #cccccc;
19+
height: 1px;
20+
width: 280px;
21+
vertical-align: middle;
22+
23+
}
24+
.slider::-webkit-slider-thumb{
25+
-webkit-appearance: none;
26+
appearance: none;
27+
width: 16px;
28+
height: 16px;
29+
border-radius: 50%;
30+
background:var(--vscode-textLink-activeForeground);
31+
cursor: pointer;
32+
}
33+
34+
.slider::-webkit-slider-runnable-track:focus,
35+
.inputSlider:focus,
36+
.slider:focus{
37+
outline: none;
38+
}
39+
40+
.sliderValue:focus{
41+
outline-color: var(--vscode-textLink-activeForeground);
42+
}
43+
.maxLabel,
44+
.minLabel{
45+
display: inline-block;
46+
font-size: 12px;
47+
position: relative;
48+
vertical-align: top;
49+
50+
}
51+
52+
.maxLabel{
53+
margin-left: 220px;
54+
}
55+
56+
.sliderArea,
57+
.sliderValue{
58+
display: inline-block;
59+
}
60+
61+
.sliderArea{
62+
width: 280px;
63+
height: 30px;
64+
vertical-align: middle;
65+
66+
}
67+
.downLabelArea{
68+
width: 280px;
69+
height: 15px;
70+
margin-top: 10px
71+
72+
}
73+
.upLabelArea{
74+
width: 280px;
75+
height: 15px;
76+
margin-bottom: 10px;
77+
78+
}
79+
80+
.slider,.upLabelArea,.downLabelArea{
81+
display: block;
82+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import * as React from "react";
5+
import "./InputSlider.css"
6+
7+
interface ISliderProps{
8+
min:number;
9+
max: number;
10+
min_label: string;
11+
max_label: string;
12+
step:number;
13+
}
14+
15+
16+
17+
class InputSlider extends React.Component<ISliderProps,any,any>{
18+
19+
constructor(props: ISliderProps){
20+
super(props);
21+
this.state = {
22+
value:0,
23+
};
24+
25+
this.handleOnChange = this.handleOnChange.bind(this);
26+
this.validateRange = this.validateRange.bind(this);
27+
}
28+
29+
30+
render(){
31+
return (
32+
<div className="inputSlider">
33+
<input type="text" className="sliderValue" value={this.state.value}
34+
onInput={this.handleOnChange} defaultValue={this.props.min.toLocaleString()} pattern="^-?[0-9]*$" onKeyUp={this.validateRange}/>
35+
<div className="sliderArea">
36+
<div className="upLabelArea">
37+
<div className='minLabel'>
38+
{this.props.min_label}
39+
</div>
40+
<div className='maxLabel'>
41+
{this.props.max_label}
42+
</div>
43+
</div>
44+
<input type="range" className="slider" min={this.props.min} max={this.props.max}
45+
step={this.props.step} onChange={this.handleOnChange} value={this.state.value} defaultValue={this.props.min.toLocaleString()}/>
46+
<div className="downLabelArea">
47+
<div className='minLabel'>
48+
{this.props.min_label}
49+
</div>
50+
<div className='maxLabel'>
51+
{this.props.max_label}
52+
</div>
53+
</div>
54+
</div>
55+
</div>
56+
57+
58+
)
59+
}
60+
61+
private handleOnChange(event: React.ChangeEvent<HTMLInputElement>){
62+
this.updateValue(event);
63+
this.validateRange();
64+
65+
66+
}
67+
68+
private updateValue(event: React.ChangeEvent<HTMLInputElement>){
69+
const newValue = (event.target.validity.valid) ? event.target.value : this.state.value;
70+
this.setState({value:newValue});
71+
72+
}
73+
74+
private validateRange(){
75+
if(this.state.value<this.props.min){
76+
this.setState({value:this.props.min,dummy:2});
77+
}
78+
if(this.state.value>this.props.max){
79+
this.setState({value:this.props.max,dummy:1});
80+
}
81+
82+
}
83+
84+
85+
}
86+
87+
export default InputSlider;
88+

0 commit comments

Comments
 (0)