- );
+ // HACK: Temporary disablement of theme selection.
+ // We don't support changing themes on experimental anyways, and radio groups aren't
+ // a thing anymore for setting flags. We're also dropping this view in the very near
+ // future, so just replace the theme selection with placeholder text.
+ const currentTheme = SettingsStore.getValue("theme");
+ return
;
},
_renderCryptoInfo: function() {
diff --git a/src/components/views/elements/SettingsFlag.js b/src/components/views/elements/SettingsFlag.js
index 7f6c74538a..f1bd72f53d 100644
--- a/src/components/views/elements/SettingsFlag.js
+++ b/src/components/views/elements/SettingsFlag.js
@@ -18,6 +18,7 @@ import React from "react";
import PropTypes from 'prop-types';
import SettingsStore from "../../../settings/SettingsStore";
import { _t } from '../../../languageHandler';
+import ToggleSwitch from "./ToggleSwitch";
module.exports = React.createClass({
displayName: 'SettingsFlag',
@@ -29,10 +30,6 @@ module.exports = React.createClass({
onChange: PropTypes.func,
isExplicit: PropTypes.bool,
manualSave: PropTypes.bool,
-
- // If group is supplied, then this will create a radio button instead.
- group: PropTypes.string,
- value: PropTypes.any, // the value for the radio button
},
getInitialState: function() {
@@ -46,13 +43,12 @@ module.exports = React.createClass({
};
},
- onChange: function(e) {
- if (this.props.group && !e.target.checked) return;
+ onChange: function(checked) {
+ if (this.props.group && !checked) return;
- const newState = this.props.group ? this.props.value : e.target.checked;
- if (!this.props.manualSave) this.save(newState);
- else this.setState({ value: newState });
- if (this.props.onChange) this.props.onChange(newState);
+ if (!this.props.manualSave) this.save(checked);
+ else this.setState({ value: checked });
+ if (this.props.onChange) this.props.onChange(checked);
},
save: function(val = undefined) {
@@ -78,34 +74,11 @@ module.exports = React.createClass({
if (!label) label = SettingsStore.getDisplayName(this.props.name, this.props.level);
else label = _t(label);
- // We generate a relatively complex ID to avoid conflicts
- const id = this.props.name + "_" + this.props.group + "_" + this.props.value + "_" + this.props.level;
- let checkbox = (
-
- );
- if (this.props.group) {
- checkbox = (
-
- );
- }
-
return (
-
+
+ {label}
+
+
);
},
});
diff --git a/src/components/views/elements/ToggleSwitch.js b/src/components/views/elements/ToggleSwitch.js
new file mode 100644
index 0000000000..5c3aaeb323
--- /dev/null
+++ b/src/components/views/elements/ToggleSwitch.js
@@ -0,0 +1,66 @@
+/*
+Copyright 2019 New Vector Ltd
+
+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
+
+ http://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.
+*/
+
+import React from 'react';
+import PropTypes from 'prop-types';
+import classNames from "classnames";
+
+export default class ToggleSwitch extends React.Component {
+ static propTypes = {
+ // Whether or not this toggle is in the 'on' position. Default false (off).
+ checked: PropTypes.bool,
+
+ // Whether or not the user can interact with the switch
+ disabled: PropTypes.bool,
+
+ // Called when the checked state changes. First argument will be the new state.
+ onChange: PropTypes.func,
+ };
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ checked: props.checked || false, // default false
+ };
+ }
+
+ _onClick = (e) => {
+ e.stopPropagation();
+ e.preventDefault();
+
+ if (this.props.disabled) return;
+
+ const newState = !this.state.checked;
+ this.setState({checked: newState});
+ if (this.props.onChange) {
+ this.props.onChange(newState);
+ }
+ };
+
+ render() {
+ const classes = classNames({
+ "mx_ToggleSwitch": true,
+ "mx_ToggleSwitch_on": this.state.checked,
+ "mx_ToggleSwitch_enabled": !this.props.disabled,
+ });
+ return (
+
+
+
+ )
+ }
+}
diff --git a/src/components/views/settings/tabs/GeneralSettingsTab.js b/src/components/views/settings/tabs/GeneralSettingsTab.js
index 6f4ebed848..fef6abfb17 100644
--- a/src/components/views/settings/tabs/GeneralSettingsTab.js
+++ b/src/components/views/settings/tabs/GeneralSettingsTab.js
@@ -154,6 +154,7 @@ export default class GeneralSettingsTab extends React.Component {
_renderThemeSection() {
// TODO: Re-enable theme selection once the themes actually work
+ const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag");
return (