mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 10:15:41 +00:00
1e70fb391f
MozReview-Commit-ID: 1jdAAo1Kb21 --HG-- rename : devtools/client/performance-new/components/PerfSettings.js => devtools/client/performance-new/components/Settings.js extra : rebase_source : 8670fd718c05491dfb769a1da49c4941c2a7c7ef
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
"use strict";
|
|
const { PureComponent } = require("devtools/client/shared/vendor/react");
|
|
const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
|
|
const { div, input, label } = require("devtools/client/shared/vendor/react-dom-factories");
|
|
|
|
/**
|
|
* Provide a numeric range slider UI that works off of custom numeric scales.
|
|
*/
|
|
class Range extends PureComponent {
|
|
static get propTypes() {
|
|
return {
|
|
value: PropTypes.number.isRequired,
|
|
label: PropTypes.string.isRequired,
|
|
id: PropTypes.string.isRequired,
|
|
scale: PropTypes.object.isRequired,
|
|
onChange: PropTypes.func.isRequired,
|
|
display: PropTypes.func.isRequired,
|
|
};
|
|
}
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleInput = this.handleInput.bind(this);
|
|
}
|
|
|
|
handleInput(e) {
|
|
e.preventDefault();
|
|
const { scale, onChange } = this.props;
|
|
const frac = e.target.value / 100;
|
|
onChange(scale.fromFractionToSingleDigitValue(frac));
|
|
}
|
|
|
|
render() {
|
|
const { label: labelText, scale, id, value, display } = this.props;
|
|
return (
|
|
div(
|
|
{ className: "perf-settings-row" },
|
|
label(
|
|
{
|
|
className: "perf-settings-label",
|
|
htmlFor: id
|
|
},
|
|
labelText
|
|
),
|
|
div(
|
|
{ className: "perf-settings-value" },
|
|
div(
|
|
{ className: "perf-settings-range-input" },
|
|
input({
|
|
type: "range",
|
|
className: `perf-settings-range-input-el`,
|
|
min: "0",
|
|
max: "100",
|
|
value: scale.fromValueToFraction(value) * 100,
|
|
onChange: this.handleInput,
|
|
id,
|
|
})
|
|
),
|
|
div(
|
|
{ className: `perf-settings-range-value`},
|
|
display(value)
|
|
)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = Range;
|