about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/local_settings/page/deprecated_item/index.jsx
blob: 362bd97c0a03fadab4e6193bd4e24db9a48a0490 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//  Package imports
import React from 'react';
import PropTypes from 'prop-types';

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

export default class LocalSettingsPageItem extends React.PureComponent {

  static propTypes = {
    children: PropTypes.node.isRequired,
    id: PropTypes.string.isRequired,
    options: PropTypes.arrayOf(PropTypes.shape({
      value: PropTypes.string.isRequired,
      message: PropTypes.string.isRequired,
      hint: PropTypes.string,
    })),
    value: PropTypes.any,
    placeholder: PropTypes.string,
  };

  render () {
    const { id, options, children, placeholder, value } = this.props;

    if (options && options.length > 0) {
      const currentValue = value;
      const optionElems = options && options.length > 0 && options.map((opt) => {
        let optionId = `${id}--${opt.value}`;
        return (
          <label htmlFor={optionId}>
            <input
              type='radio'
              name={id}
              id={optionId}
              value={opt.value}
              checked={currentValue === opt.value}
              disabled
            />
            {opt.message}
            {opt.hint && <span className='hint'>{opt.hint}</span>}
          </label>
        );
      });
      return (
        <div className='glitch local-settings__page__item radio_buttons'>
          <fieldset>
            <legend>{children}</legend>
            {optionElems}
          </fieldset>
        </div>
      );
    } else if (placeholder) {
      return (
        <div className='glitch local-settings__page__item string'>
          <label htmlFor={id}>
            <p>{children}</p>
            <p>
              <input
                id={id}
                type='text'
                value={value}
                placeholder={placeholder}
                disabled
              />
            </p>
          </label>
        </div>
      );
    } else return (
      <div className='glitch local-settings__page__item boolean'>
        <label htmlFor={id}>
          <input
            id={id}
            type='checkbox'
            checked={value}
            disabled
          />
          {children}
        </label>
      </div>
    );
  }

}