From 2739b0fb964c5e1b48775e89bc7f602708fccd54 Mon Sep 17 00:00:00 2001 From: Shingo Yamazaki Date: Tue, 27 Aug 2019 23:55:23 +0900 Subject: [PATCH 1/6] #289 Select: mv .js -> .tsx --- src/scripts/{Select.js => Select.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/scripts/{Select.js => Select.tsx} (100%) diff --git a/src/scripts/Select.js b/src/scripts/Select.tsx similarity index 100% rename from src/scripts/Select.js rename to src/scripts/Select.tsx From 66b7ce4831f29ec734e02397fe192426486754ee Mon Sep 17 00:00:00 2001 From: Shingo Yamazaki Date: Wed, 28 Aug 2019 00:22:29 +0900 Subject: [PATCH 2/6] #289 Select: Convert PropTypes to TypeScript types --- src/scripts/Select.tsx | 57 +++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/scripts/Select.tsx b/src/scripts/Select.tsx index b9fe23cd8..216f9a485 100644 --- a/src/scripts/Select.tsx +++ b/src/scripts/Select.tsx @@ -1,16 +1,32 @@ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; import classnames from 'classnames'; -import { FormElement } from './FormElement'; +import { FormElement, FormElementProps } from './FormElement'; import { uuid } from './util'; -export default class Select extends Component { - constructor() { - super(); +export type SelectProps = { + id?: string; + className?: string; + label?: string; + required?: boolean; + totalCols?: number; + cols?: number; + error?: FormElementProps['error']; + onChange?: (e: React.ChangeEvent, value: string) => void; +} & React.SelectHTMLAttributes; + +export type SelectState = { + id: string; +}; + +export default class Select extends Component { + static isFormElement = true; + + constructor(props: Readonly) { + super(props); this.state = { id: `form-element-${uuid()}` }; } - onChange(e) { + onChange(e: React.ChangeEvent) { const { value } = e.target; if (this.props.onChange) { this.props.onChange(e, value); @@ -44,32 +60,11 @@ export default class Select extends Component { } } -Select.propTypes = { - id: PropTypes.string, - className: PropTypes.string, - label: PropTypes.string, - required: PropTypes.bool, - totalCols: PropTypes.number, - cols: PropTypes.number, - // FormElement.propTypes.error - error: PropTypes.oneOfType([ - PropTypes.bool, - PropTypes.string, - PropTypes.shape({ - message: PropTypes.string, - }), - ]), - onChange: PropTypes.func, -}; - -Select.isFormElement = true; +export type OptionProps = { + label: string | number; +} & React.OptionHTMLAttributes; -export const Option = (props) => { +export const Option: React.FC = (props) => { const { label, children, ...pprops } = props; return ; }; - -Option.propTypes = { - children: PropTypes.node, - label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), -}; From adf5f5b6fe3ddf16b19368e274dcb2dbcf4818a5 Mon Sep 17 00:00:00 2001 From: Shingo Yamazaki Date: Wed, 28 Aug 2019 00:22:50 +0900 Subject: [PATCH 3/6] #289 Select: mv story .js -> .tsx --- stories/{SelectStories.js => SelectStories.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stories/{SelectStories.js => SelectStories.tsx} (100%) diff --git a/stories/SelectStories.js b/stories/SelectStories.tsx similarity index 100% rename from stories/SelectStories.js rename to stories/SelectStories.tsx From f821bef0632720daa964c017d0d4d6c9ad106805 Mon Sep 17 00:00:00 2001 From: Shingo Yamazaki Date: Wed, 28 Aug 2019 00:36:56 +0900 Subject: [PATCH 4/6] #289 Select: Fix type errors of story --- stories/SelectStories.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stories/SelectStories.tsx b/stories/SelectStories.tsx index c027af4c9..2067582ea 100644 --- a/stories/SelectStories.tsx +++ b/stories/SelectStories.tsx @@ -10,10 +10,10 @@ storiesOf('Select', module) () => (