aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui
diff options
context:
space:
mode:
authorLibravatar Bennett <hello@vantezzen.io>2020-10-04 16:27:26 +0200
committerLibravatar GitHub <noreply@github.com>2020-10-04 15:27:26 +0100
commitc9c067b286505621fbae3fc212638b45ae1c733a (patch)
treebeb3001b26ec3ffc05528d11fe60033971655a7c /src/components/ui
parentFine-tune nightly releases scripts (diff)
downloadferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.tar.gz
ferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.tar.zst
ferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.zip
Add setting to enable nightly releases updates (#742)
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/components/ui')
-rw-r--r--src/components/ui/ToggleRaw.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/components/ui/ToggleRaw.js b/src/components/ui/ToggleRaw.js
new file mode 100644
index 000000000..ee817356b
--- /dev/null
+++ b/src/components/ui/ToggleRaw.js
@@ -0,0 +1,74 @@
1/**
2 * "Raw" Toggle - for usage without a MobX Form element
3 */
4import React, { Component } from 'react';
5import PropTypes from 'prop-types';
6import { observer } from 'mobx-react';
7import classnames from 'classnames';
8
9export default @observer class ToggleRaw extends Component {
10 static propTypes = {
11 onChange: PropTypes.func.isRequired,
12 field: PropTypes.shape({
13 value: PropTypes.bool.isRequired,
14 id: PropTypes.string,
15 name: PropTypes.string,
16 label: PropTypes.string,
17 }).isRequired,
18 className: PropTypes.string,
19 showLabel: PropTypes.bool,
20 disabled: PropTypes.bool,
21 };
22
23 static defaultProps = {
24 className: '',
25 showLabel: true,
26 disabled: false,
27 };
28
29 onChange(e) {
30 const { onChange } = this.props;
31
32 onChange(e);
33 }
34
35 render() {
36 const {
37 field,
38 className,
39 showLabel,
40 disabled,
41 } = this.props;
42
43 return (
44 <div
45 className={classnames([
46 'franz-form__field',
47 'franz-form__toggle-wrapper',
48 'franz-form__toggle-disabled',
49 className,
50 ])}
51 >
52 <label
53 htmlFor={field.id}
54 className={classnames({
55 'franz-form__toggle': true,
56 'is-active': field.value,
57 })}
58 >
59 <div className="franz-form__toggle-button" />
60 <input
61 type="checkbox"
62 id={field.id}
63 name={field.name}
64 value={field.name}
65 checked={field.value}
66 onChange={e => (!disabled ? this.onChange(e) : null)}
67 />
68 </label>
69 {field.error && <div className={field.error}>{field.error}</div>}
70 {field.label && showLabel && <label className="franz-form__label" htmlFor={field.id}>{field.label}</label>}
71 </div>
72 );
73 }
74}