Files
react-native-devtools-frontend/front_end/audits2/RadioSetting.js
T
Paul Irish 8f1e33d0b0 Restore "DevTools: [Audits] Roll Lighthouse to v3.0-beta"
This reverts commit 28abe7802899b037a176426f883c750fec5a6d24.

Bug: 772558, 846211,846551
Change-Id: Ib782b1fb5ee737f31deaa94630fb2bb1021b579b
Reviewed-on: https://chromium-review.googlesource.com/1077597
Reviewed-by: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: Patrick Hulce <phulce@chromium.org>
Commit-Queue: Paul Irish <paulirish@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#563121}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8405e18c05b9e5a1c714db1e204de6aaae3be24d
2018-05-31 02:29:50 +00:00

63 lines
1.8 KiB
JavaScript

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Audits2.RadioSetting = class {
/**
* @param {!Array<!{value: string, label: string}>} options
* @param {!Common.Setting} setting
*/
constructor(options, setting) {
this._setting = setting;
this._options = options;
this.element = createElement('div', 'audits2-radio-group');
this._radioElements = [];
for (const option of this._options) {
const fragment = UI.Fragment.build`
<label $="label" class="audits2-radio">
<input $="input" type="radio" value=${option.value} name=${setting.name}>
${option.label}
</label>
`;
this.element.appendChild(fragment.element());
if (option.title)
UI.Tooltip.install(fragment.$('label'), option.title);
const radioElement = fragment.$('input');
radioElement.addEventListener('change', this._valueChanged.bind(this));
this._radioElements.push(radioElement);
}
this._ignoreChangeEvents = false;
this._selectedIndex = -1;
setting.addChangeListener(this._settingChanged, this);
this._settingChanged();
}
_updateUI() {
this._ignoreChangeEvents = true;
this._radioElements[this._selectedIndex].checked = true;
this._ignoreChangeEvents = false;
}
_settingChanged() {
const value = this._setting.get();
this._selectedIndex = this._options.findIndex(option => option.value === value);
this._updateUI();
}
/**
* @param {!Event} event
*/
_valueChanged(event) {
if (this._ignoreChangeEvents)
return;
const selectedRadio = this._radioElements.find(radio => radio.checked);
this._setting.set(selectedRadio.value);
}
};