aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/form
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/components/form')
-rw-r--r--src/settings/components/form/BlacklistForm.tsx (renamed from src/settings/components/form/BlacklistForm.jsx)28
-rw-r--r--src/settings/components/form/KeymapsForm.tsx (renamed from src/settings/components/form/KeymapsForm.jsx)41
-rw-r--r--src/settings/components/form/PropertiesForm.tsx (renamed from src/settings/components/form/PropertiesForm.jsx)32
-rw-r--r--src/settings/components/form/SearchForm.tsx (renamed from src/settings/components/form/SearchForm.jsx)50
4 files changed, 72 insertions, 79 deletions
diff --git a/src/settings/components/form/BlacklistForm.jsx b/src/settings/components/form/BlacklistForm.tsx
index c470758..637bc1e 100644
--- a/src/settings/components/form/BlacklistForm.jsx
+++ b/src/settings/components/form/BlacklistForm.tsx
@@ -2,9 +2,19 @@ import './BlacklistForm.scss';
import AddButton from '../ui/AddButton';
import DeleteButton from '../ui/DeleteButton';
import React from 'react';
-import PropTypes from 'prop-types';
-class BlacklistForm extends React.Component {
+interface Props {
+ value: string[];
+ onChange: (value: string[]) => void;
+ onBlur: () => void;
+}
+
+class BlacklistForm extends React.Component<Props> {
+ public static defaultProps: Props = {
+ value: [],
+ onChange: () => {},
+ onBlur: () => {},
+ };
render() {
return <div className='form-blacklist-form'>
@@ -28,7 +38,7 @@ class BlacklistForm extends React.Component {
</div>;
}
- bindValue(e) {
+ bindValue(e: any) {
let name = e.target.name;
let index = e.target.getAttribute('data-index');
let next = this.props.value ? this.props.value.slice() : [];
@@ -48,16 +58,4 @@ class BlacklistForm extends React.Component {
}
}
-BlacklistForm.propTypes = {
- value: PropTypes.arrayOf(PropTypes.string),
- onChange: PropTypes.func,
- onBlur: PropTypes.func,
-};
-
-BlacklistForm.defaultProps = {
- value: [],
- onChange: () => {},
- onBlur: () => {},
-};
-
export default BlacklistForm;
diff --git a/src/settings/components/form/KeymapsForm.jsx b/src/settings/components/form/KeymapsForm.tsx
index 01acf61..ad4d0e7 100644
--- a/src/settings/components/form/KeymapsForm.jsx
+++ b/src/settings/components/form/KeymapsForm.tsx
@@ -1,25 +1,35 @@
import './KeymapsForm.scss';
import React from 'react';
-import PropTypes from 'prop-types';
import Input from '../ui/Input';
import keymaps from '../../keymaps';
+import { FormKeymaps } from '../../../shared/SettingData';
-class KeymapsForm extends React.Component {
+interface Props {
+ value: FormKeymaps;
+ onChange: (e: FormKeymaps) => void;
+ onBlur: () => void;
+}
+
+class KeymapsForm extends React.Component<Props> {
+ public static defaultProps: Props = {
+ value: FormKeymaps.valueOf({}),
+ onChange: () => {},
+ onBlur: () => {},
+ }
render() {
+ let values = this.props.value.toJSON();
return <div className='form-keymaps-form'>
{
keymaps.fields.map((group, index) => {
return <div key={index} className='form-keymaps-form-field-group'>
{
- group.map((field) => {
- let name = field[0];
- let label = field[1];
- let value = this.props.value[name] || '';
+ group.map(([name, label]) => {
+ let value = values[name] || '';
return <Input
type='text' id={name} name={name} key={name}
label={label} value={value}
- onChange={this.bindValue.bind(this)}
+ onValueChange={this.bindValue.bind(this)}
onBlur={this.props.onBlur}
/>;
})
@@ -30,22 +40,9 @@ class KeymapsForm extends React.Component {
</div>;
}
- bindValue(e) {
- let next = { ...this.props.value };
- next[e.target.name] = e.target.value;
-
- this.props.onChange(next);
+ bindValue(name: string, value: string) {
+ this.props.onChange(this.props.value.buildWithOverride(name, value));
}
}
-KeymapsForm.propTypes = {
- value: PropTypes.objectOf(PropTypes.string),
- onChange: PropTypes.func,
-};
-
-KeymapsForm.defaultProps = {
- value: {},
- onChange: () => {},
-};
-
export default KeymapsForm;
diff --git a/src/settings/components/form/PropertiesForm.jsx b/src/settings/components/form/PropertiesForm.tsx
index 979fdd8..0be5f5c 100644
--- a/src/settings/components/form/PropertiesForm.jsx
+++ b/src/settings/components/form/PropertiesForm.tsx
@@ -1,8 +1,20 @@
import './PropertiesForm.scss';
import React from 'react';
-import PropTypes from 'prop-types';
-class PropertiesForm extends React.Component {
+interface Props {
+ types: {[key: string]: string};
+ value: {[key: string]: any};
+ onChange: (value: any) => void;
+ onBlur: () => void;
+}
+
+class PropertiesForm extends React.Component<Props> {
+ public static defaultProps: Props = {
+ types: {},
+ value: {},
+ onChange: () => {},
+ onBlur: () => {},
+ };
render() {
let types = this.props.types;
@@ -12,13 +24,15 @@ class PropertiesForm extends React.Component {
{
Object.keys(types).map((name) => {
let type = types[name];
- let inputType = null;
+ let inputType = '';
if (type === 'string') {
inputType = 'text';
} else if (type === 'number') {
inputType = 'number';
} else if (type === 'boolean') {
inputType = 'checkbox';
+ } else {
+ return null;
}
return <div key={name} className='form-properties-form-row'>
<label>
@@ -37,7 +51,7 @@ class PropertiesForm extends React.Component {
</div>;
}
- bindValue(e) {
+ bindValue(e: React.ChangeEvent<HTMLInputElement>) {
let name = e.target.name;
let next = { ...this.props.value };
if (e.target.type.toLowerCase() === 'checkbox') {
@@ -52,14 +66,4 @@ class PropertiesForm extends React.Component {
}
}
-PropertiesForm.propTypes = {
- value: PropTypes.objectOf(PropTypes.any),
- onChange: PropTypes.func,
-};
-
-PropertiesForm.defaultProps = {
- value: {},
- onChange: () => {},
-};
-
export default PropertiesForm;
diff --git a/src/settings/components/form/SearchForm.jsx b/src/settings/components/form/SearchForm.tsx
index 6b0bd01..67dbeba 100644
--- a/src/settings/components/form/SearchForm.jsx
+++ b/src/settings/components/form/SearchForm.tsx
@@ -1,17 +1,24 @@
import './SearchForm.scss';
import React from 'react';
-import PropTypes from 'prop-types';
import AddButton from '../ui/AddButton';
import DeleteButton from '../ui/DeleteButton';
+import { FormSearch } from '../../../shared/SettingData';
-class SearchForm extends React.Component {
+interface Props {
+ value: FormSearch;
+ onChange: (value: FormSearch) => void;
+ onBlur: () => void;
+}
- render() {
- let value = this.props.value;
- if (!value.engines) {
- value.engines = [];
- }
+class SearchForm extends React.Component<Props> {
+ public static defaultProps: Props = {
+ value: FormSearch.valueOf({ default: '', engines: []}),
+ onChange: () => {},
+ onBlur: () => {},
+ }
+ render() {
+ let value = this.props.value.toJSON();
return <div className='form-search-form'>
<div className='form-search-form-header'>
<div className='column-name'>Name</div>
@@ -47,46 +54,33 @@ class SearchForm extends React.Component {
</div>;
}
- bindValue(e) {
- let value = this.props.value;
+ bindValue(e: any) {
+ let value = this.props.value.toJSON();
let name = e.target.name;
- let index = e.target.getAttribute('data-index');
- let next = {
+ let index = Number(e.target.getAttribute('data-index'));
+ let next: typeof value = {
default: value.default,
- engines: value.engines ? value.engines.slice() : [],
+ engines: value.engines.slice(),
};
if (name === 'name') {
next.engines[index][0] = e.target.value;
- next.default = this.props.value.engines[index][0];
+ next.default = value.engines[index][0];
} else if (name === 'url') {
next.engines[index][1] = e.target.value;
} else if (name === 'default') {
- next.default = this.props.value.engines[index][0];
+ next.default = value.engines[index][0];
} else if (name === 'add') {
next.engines.push(['', '']);
} else if (name === 'delete') {
next.engines.splice(index, 1);
}
- this.props.onChange(next);
+ this.props.onChange(FormSearch.valueOf(next));
if (name === 'delete' || name === 'default') {
this.props.onBlur();
}
}
}
-SearchForm.propTypes = {
- value: PropTypes.shape({
- default: PropTypes.string,
- engines: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)),
- }),
- onChange: PropTypes.func,
-};
-
-SearchForm.defaultProps = {
- value: { default: '', engines: []},
- onChange: () => {},
-};
-
export default SearchForm;