Allow text inputs in local settings dialog

This commit is contained in:
Thibaut Girka 2018-08-28 17:15:50 +02:00 committed by ThibG
parent 9d2739d74d
commit 5c400a2842

View file

@ -19,18 +19,20 @@ export default class LocalSettingsPageItem extends React.PureComponent {
message: PropTypes.string.isRequired, message: PropTypes.string.isRequired,
})), })),
settings: ImmutablePropTypes.map.isRequired, settings: ImmutablePropTypes.map.isRequired,
placeholder: PropTypes.string,
}; };
handleChange = e => { handleChange = e => {
const { target } = e; const { target } = e;
const { item, onChange, options } = this.props; const { item, onChange, options, placeholder } = this.props;
if (options && options.length > 0) onChange(item, target.value); if (options && options.length > 0) onChange(item, target.value);
else if (placeholder) onChange(item, target.value);
else onChange(item, target.checked); else onChange(item, target.checked);
} }
render () { render () {
const { handleChange } = this; const { handleChange } = this;
const { settings, item, id, options, children, dependsOn, dependsOnNot } = this.props; const { settings, item, id, options, children, dependsOn, dependsOnNot, placeholder } = this.props;
let enabled = true; let enabled = true;
if (dependsOn) { if (dependsOn) {
@ -70,6 +72,22 @@ export default class LocalSettingsPageItem extends React.PureComponent {
</p> </p>
</label> </label>
); );
} else if (placeholder) {
return (
<label className='glitch local-settings__page__item' htmlFor={id}>
<p>{children}</p>
<p>
<input
id={id}
type='text'
value={settings.getIn(item)}
placeholder={placeholder}
onChange={handleChange}
disabled={!enabled}
/>
</p>
</label>
);
} else return ( } else return (
<label className='glitch local-settings__page__item' htmlFor={id}> <label className='glitch local-settings__page__item' htmlFor={id}>
<input <input