BetterDiscordApp-rauenzi/src/ui/settings/switch.js

52 lines
1.7 KiB
JavaScript

import {React} from "modules";
export default class V2C_Switch extends React.Component {
constructor(props) {
super(props);
this.setInitialState();
this.onChange = this.onChange.bind(this);
}
setInitialState() {
this.state = {
checked: this.props.checked
};
}
render() {
const {text, info} = this.props.data;
const {checked} = this.state;
return React.createElement(
"div",
{className: "ui-flex flex-vertical flex-justify-start flex-align-stretch flex-nowrap ui-switch-item"},
React.createElement(
"div",
{className: "ui-flex flex-horizontal flex-justify-start flex-align-stretch flex-nowrap"},
React.createElement(
"h3",
{className: "ui-form-title h3 margin-reset margin-reset ui-flex-child"},
text
),
React.createElement(
"label",
{className: "ui-switch-wrapper ui-flex-child", style: {flex: "0 0 auto"}},
React.createElement("input", {className: "ui-switch-checkbox", type: "checkbox", checked: checked, onChange: e => this.onChange(e)}),
React.createElement("div", {className: `ui-switch ${checked ? "checked" : ""}`})
)
),
React.createElement(
"div",
{className: "ui-form-text style-description margin-top-4", style: {flex: "1 1 auto"}},
info
)
);
}
onChange() {
this.props.onChange(this.props.id, !this.state.checked);
this.setState({
checked: !this.state.checked
});
}
}