diff --git a/src/scripts/Datepicker.js b/src/scripts/Datepicker.js index 095c0ce19..9c595e4d5 100644 --- a/src/scripts/Datepicker.js +++ b/src/scripts/Datepicker.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import moment from 'moment'; import { Button } from './Button'; -import Select, { Option } from './Select'; +import { Select, Option } from './Select'; import { getToday, isElInChildren } from './util'; function createCalendarObject(date, mnDate, mxDate) { diff --git a/src/scripts/Select.js b/src/scripts/Select.tsx similarity index 59% rename from src/scripts/Select.js rename to src/scripts/Select.tsx index b9fe23cd8..dc741c6a9 100644 --- a/src/scripts/Select.js +++ 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 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]), -}; diff --git a/src/scripts/index.js b/src/scripts/index.js index fbe1f0e6b..dffc4cd08 100644 --- a/src/scripts/index.js +++ b/src/scripts/index.js @@ -5,7 +5,6 @@ import Datepicker from './Datepicker'; import Tabs, { Tab } from './Tabs'; import SalesPath from './SalesPath'; import Modal, { ModalHeader, ModalContent, ModalFooter } from './Modal'; -import Select, { Option } from './Select'; import DateInput from './DateInput'; import Grid, { Row, Col } from './Grid'; import Notification, { Alert, Toast } from './Notification'; @@ -39,8 +38,6 @@ export { ModalContent, ModalFooter, SalesPath, - Select, - Option, DateInput, Grid, Row, @@ -73,6 +70,7 @@ export * from './ButtonGroup'; export * from './Container'; export * from './Checkbox'; export * from './CheckboxGroup'; +export * from './Select'; export * from './DropdownMenu'; export * from './DropdownButton'; export * from './Icon'; diff --git a/stories/SelectStories.js b/stories/SelectStories.tsx similarity index 93% rename from stories/SelectStories.js rename to stories/SelectStories.tsx index c027af4c9..2067582ea 100644 --- a/stories/SelectStories.js +++ b/stories/SelectStories.tsx @@ -10,10 +10,10 @@ storiesOf('Select', module) () => (