aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/components/ui')
-rw-r--r--src/settings/components/ui/AddButton.tsx (renamed from src/settings/components/ui/AddButton.jsx)5
-rw-r--r--src/settings/components/ui/DeleteButton.tsx (renamed from src/settings/components/ui/DeleteButton.jsx)5
-rw-r--r--src/settings/components/ui/Input.jsx60
-rw-r--r--src/settings/components/ui/Input.tsx82
4 files changed, 90 insertions, 62 deletions
diff --git a/src/settings/components/ui/AddButton.jsx b/src/settings/components/ui/AddButton.tsx
index 185a03b..0577068 100644
--- a/src/settings/components/ui/AddButton.jsx
+++ b/src/settings/components/ui/AddButton.tsx
@@ -1,7 +1,10 @@
import './AddButton.scss';
import React from 'react';
-class AddButton extends React.Component {
+interface Props extends React.AllHTMLAttributes<HTMLInputElement> {
+}
+
+class AddButton extends React.Component<Props> {
render() {
return <input
className='ui-add-button' type='button' value='&#x271a;'
diff --git a/src/settings/components/ui/DeleteButton.jsx b/src/settings/components/ui/DeleteButton.tsx
index 75811cd..f0ef6c9 100644
--- a/src/settings/components/ui/DeleteButton.jsx
+++ b/src/settings/components/ui/DeleteButton.tsx
@@ -1,7 +1,10 @@
import './DeleteButton.scss';
import React from 'react';
-class DeleteButton extends React.Component {
+interface Props extends React.AllHTMLAttributes<HTMLInputElement> {
+}
+
+class DeleteButton extends React.Component<Props> {
render() {
return <input
className='ui-delete-button' type='button' value='&#x2716;'
diff --git a/src/settings/components/ui/Input.jsx b/src/settings/components/ui/Input.jsx
deleted file mode 100644
index 13a246b..0000000
--- a/src/settings/components/ui/Input.jsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import './Input.scss';
-
-class Input extends React.Component {
-
- renderText(props) {
- let inputClassName = props.error ? 'input-error' : '';
- return <div className='settings-ui-input'>
- <label htmlFor={props.id}>{ props.label }</label>
- <input type='text' className={inputClassName} {...props} />
- </div>;
- }
-
- renderRadio(props) {
- let inputClassName = props.error ? 'input-error' : '';
- return <div className='settings-ui-input'>
- <label>
- <input type='radio' className={inputClassName} {...props} />
- { props.label }
- </label>
- </div>;
- }
-
- renderTextArea(props) {
- let inputClassName = props.error ? 'input-error' : '';
- return <div className='settings-ui-input'>
- <label
- htmlFor={props.id}
- >{ props.label }</label>
- <textarea className={inputClassName} {...props} />
- <p className='settings-ui-input-error'>{ this.props.error }</p>
- </div>;
- }
-
- render() {
- let { type } = this.props;
-
- switch (this.props.type) {
- case 'text':
- return this.renderText(this.props);
- case 'radio':
- return this.renderRadio(this.props);
- case 'textarea':
- return this.renderTextArea(this.props);
- default:
- console.warn(`Unsupported input type ${type}`);
- }
- return null;
- }
-}
-
-Input.propTypes = {
- type: PropTypes.string,
- error: PropTypes.string,
- label: PropTypes.string,
- value: PropTypes.string,
-};
-
-export default Input;
diff --git a/src/settings/components/ui/Input.tsx b/src/settings/components/ui/Input.tsx
new file mode 100644
index 0000000..b7593b9
--- /dev/null
+++ b/src/settings/components/ui/Input.tsx
@@ -0,0 +1,82 @@
+import React from 'react';
+import './Input.scss';
+
+interface Props extends React.AllHTMLAttributes<HTMLElement> {
+ name: string;
+ type: string;
+ error?: string;
+ label: string;
+ value: string;
+ onValueChange?: (name: string, value: string) => void;
+ onBlur?: (e: React.FocusEvent<Element>) => void;
+}
+
+class Input extends React.Component<Props> {
+ renderText(props: Props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ let pp = { ...props };
+ delete pp.onValueChange;
+ return <div className='settings-ui-input'>
+ <label htmlFor={props.id}>{ props.label }</label>
+ <input
+ type='text' className={inputClassName}
+ onChange={this.bindOnChange.bind(this)}
+ { ...pp } />
+ </div>;
+ }
+
+ renderRadio(props: Props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ let pp = { ...props };
+ delete pp.onValueChange;
+ return <div className='settings-ui-input'>
+ <label>
+ <input
+ type='radio' className={inputClassName}
+ onChange={this.bindOnChange.bind(this)}
+ { ...pp } />
+ { props.label }
+ </label>
+ </div>;
+ }
+
+ renderTextArea(props: Props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ let pp = { ...props };
+ delete pp.onValueChange;
+ return <div className='settings-ui-input'>
+ <label
+ htmlFor={props.id}
+ >{ props.label }</label>
+ <textarea
+ className={inputClassName}
+ onChange={this.bindOnChange.bind(this)}
+ { ...pp } />
+ <p className='settings-ui-input-error'>{ this.props.error }</p>
+ </div>;
+ }
+
+ render() {
+ let { type } = this.props;
+
+ switch (this.props.type) {
+ case 'text':
+ return this.renderText(this.props);
+ case 'radio':
+ return this.renderRadio(this.props);
+ case 'textarea':
+ return this.renderTextArea(this.props);
+ default:
+ console.warn(`Unsupported input type ${type}`);
+ }
+ return null;
+ }
+
+ bindOnChange(e: React.ChangeEvent<HTMLInputElement|HTMLTextAreaElement>) {
+ if (this.props.onValueChange) {
+ this.props.onValueChange(e.target.name, e.target.value);
+ }
+ }
+}
+
+export default Input;