-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(select, option): add Select and Option components
- Loading branch information
1 parent
1fe344a
commit cf50244
Showing
8 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Option as $Option } from '@twilio-paste/core'; | ||
|
||
export const Option = $Option; | ||
|
||
export default Option; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Option } from './Option'; | ||
|
||
export { Option }; | ||
|
||
export default Option; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Button, FormLabel } from '@twilio-paste/core'; | ||
import { Theme } from '@twilio-paste/theme'; | ||
import { Formik } from 'formik'; | ||
import * as React from 'react'; | ||
|
||
import { Option } from '../Option'; | ||
import { Select } from './Select'; | ||
|
||
export default { | ||
title: 'Select', | ||
}; | ||
|
||
export const Basic: React.FC = () => ( | ||
<Theme.Provider theme="default"> | ||
<Formik | ||
initialValues={{ callbackMethod: 'get' }} | ||
onSubmit={(values) => { | ||
window.alert(JSON.stringify(values)); | ||
}} | ||
> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<FormLabel htmlFor="callbackMethod">Callback Method</FormLabel> | ||
<Select required id="callbackMethod" name="callbackMethod"> | ||
<Option value="get">GET</Option> | ||
<Option value="post">POST</Option> | ||
<Option value="put">PUT</Option> | ||
</Select> | ||
|
||
<Button variant="primary" type="submit"> | ||
Submit | ||
</Button> | ||
</form> | ||
)} | ||
</Formik> | ||
</Theme.Provider> | ||
); | ||
|
||
export const SelectWithOnChangeCallback: React.FC = () => ( | ||
<Theme.Provider theme="default"> | ||
<Formik | ||
initialValues={{ callbackMethod: 'get' }} | ||
onSubmit={(values) => { | ||
window.alert(JSON.stringify(values)); | ||
}} | ||
> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<FormLabel htmlFor="callbackMethod">Callback Method</FormLabel> | ||
<Select | ||
required | ||
id="callbackMethod" | ||
name="callbackMethod" | ||
onChange={(e) => { | ||
window.alert(`new value: ${e.target.value}`); | ||
}} | ||
> | ||
<Option value="get">GET</Option> | ||
<Option value="post">POST</Option> | ||
<Option value="put">PUT</Option> | ||
</Select> | ||
|
||
<Button variant="primary" type="submit"> | ||
Submit | ||
</Button> | ||
</form> | ||
)} | ||
</Formik> | ||
</Theme.Provider> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react'; | ||
import { FieldProps } from 'formik'; | ||
import { Select as $Select, SelectProps as $SelectProps } from '@twilio-paste/core'; | ||
|
||
import { FormikFieldProps } from '../../interfaces'; | ||
import { Field } from '../Field'; | ||
|
||
export type SelectProps = FormikFieldProps & | ||
Omit<$SelectProps, 'value' | 'onChange'> & | ||
Partial<Pick<$SelectProps, 'onChange'>>; | ||
|
||
export const Select: React.FC<SelectProps> = ({ name, validate, fast, children, onChange, onBlur, ...restProps }) => { | ||
return ( | ||
<Field name={name} validate={validate} fast={fast}> | ||
{({ form: { setFieldValue, setFieldTouched } }: FieldProps) => ( | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
<$Select | ||
onChange={(e) => { | ||
setFieldValue(name, e.target.value); | ||
onChange?.(e); | ||
}} | ||
onBlur={(e) => { | ||
setFieldTouched(name); | ||
onBlur?.(e); | ||
}} | ||
{...restProps} | ||
> | ||
{children} | ||
</$Select> | ||
)} | ||
</Field> | ||
); | ||
}; | ||
|
||
Select.displayName = 'Select'; | ||
|
||
export default Select; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Select } from './Select'; | ||
|
||
export { Select }; | ||
|
||
export default Select; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './Checkbox'; | ||
export * from './Field'; | ||
export * from './Option'; | ||
export * from './Select'; |