-
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.
- Loading branch information
Showing
19 changed files
with
1,092 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
node_modules | ||
npm-debug.log | ||
yarn-error.log | ||
lerna-debug.log | ||
coverage | ||
jest-report | ||
lib | ||
|
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,245 @@ | ||
--- | ||
name: Select | ||
menu: Lab | ||
route: /lab/select | ||
--- | ||
|
||
import { PropsTable, Playground, Link } from 'docz'; | ||
import { range } from 'ramda'; | ||
import { Select } from '@tailor-ui/lab'; | ||
|
||
# Select | ||
|
||
Select component to select value from options. | ||
|
||
## When To Use | ||
|
||
- A dropdown menu for displaying choices - an elegant alternative to the native `<select>` element. | ||
- Utilizing <Link to="/components/radio">Radio</Link> is recommended when there are fewer total options (less than 5). | ||
|
||
## Examples | ||
|
||
```js | ||
import { Select } from '@tailor-ui/lab'; | ||
``` | ||
|
||
### Basic | ||
|
||
<Playground> | ||
{() => { | ||
const [value, setValue] = React.useState({ label: 'Banana', value: 'Banana' }); | ||
|
||
return ( | ||
<Select | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### other sizes | ||
|
||
<Playground> | ||
{() => { | ||
const [value, setValue] = React.useState({ label: 'Banana', value: 'Banana' }); | ||
|
||
return ( | ||
<div> | ||
<Select | ||
size="sm" | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
<br /> | ||
<br /> | ||
<Select | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
<br /> | ||
<br /> | ||
<Select | ||
size="lg" | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
</div> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### Searchable | ||
|
||
<Playground> | ||
{() => { | ||
const [value, setValue] = React.useState({ label: 'Banana', value: 'Banana' }); | ||
|
||
return ( | ||
<Select | ||
searchable | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### Creatable | ||
|
||
<Playground> | ||
{() => { | ||
const [loading, setLoading] = React.useState(false); | ||
const [value, setValue] = React.useState({ label: 'Banana', value: 'Banana' }); | ||
const [options, setOptions] = React.useState([ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]); | ||
|
||
return ( | ||
<Select | ||
creatable | ||
loading={loading} | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={options} | ||
isValidNewOption={name => | ||
!options.map(option => option.value).includes(name) && name.trim() !== '' | ||
} | ||
onCreateOption={name => { | ||
const newOption = { label: name, value: name }; | ||
setLoading(true); | ||
setTimeout(() => { | ||
setOptions([...options, newOption]); | ||
setValue(newOption); | ||
setLoading(false); | ||
}, 3000) | ||
} | ||
} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### disabled | ||
|
||
<Playground> | ||
{() => { | ||
const [value, setValue] = React.useState({ label: 'Banana', value: 'Banana' }); | ||
|
||
return ( | ||
<Select | ||
disabled | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### With placeholder & clearable | ||
|
||
<Playground> | ||
{() => { | ||
const [value, setValue] = React.useState(null); | ||
|
||
return ( | ||
<Select | ||
clearable | ||
placeholder="どれ" | ||
value={value} | ||
onChange={newValue => setValue(newValue)} | ||
options={[ | ||
{ label: 'Banana', value: 'Banana' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Mango', value: 'Mango' }, | ||
]} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
### Large items & custom menu | ||
|
||
<Playground> | ||
{() => { | ||
const defaultItems = Array | ||
.from({ length: 9999 }) | ||
.fill(0) | ||
.map((_, index) => ({ | ||
label: `item #${index}`, | ||
value: String(index) | ||
})); | ||
|
||
const [value, setValue] = React.useState({ label: 'item #9527', value: '9527' }); | ||
|
||
return ( | ||
<Select | ||
value={value} | ||
menu={<div style={{ padding: 8, borderTop: '1px solid #efefef' }}>I am cutsom menu!</div>} | ||
onChange={newValue => { | ||
console.log(newValue) | ||
setValue(newValue) | ||
}} | ||
options={defaultItems} | ||
/> | ||
); | ||
|
||
}} | ||
|
||
</Playground> | ||
|
||
## API | ||
|
||
<PropsTable of={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
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 |
---|---|---|
@@ -1,23 +1,39 @@ | ||
import styled from 'styled-components'; | ||
import { | ||
MinHeightProps, | ||
MinWidthProps, | ||
SpaceProps, | ||
minHeight, | ||
minWidth, | ||
space, | ||
} from 'styled-system'; | ||
|
||
export const StyledPopover = styled.div` | ||
export type StyledPopoverProps = SpaceProps & MinWidthProps & MinHeightProps; | ||
|
||
export const StyledPopover = styled.div<StyledPopoverProps>` | ||
overflow: hidden; | ||
border: ${p => p.theme.borders.base}; | ||
border-radius: ${p => p.theme.radii.lg}; | ||
border-color: ${p => p.theme.colors.gray300}; | ||
background-color: ${p => p.theme.colors.light}; | ||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); | ||
box-shadow: 0 2px 4px rgba(100, 120, 168, 0.3); | ||
color: ${p => p.theme.colors.gray700}; | ||
font-size: ${p => p.theme.fontSizes.sm}; | ||
text-align: left; | ||
white-space: nowrap; | ||
${space} | ||
${minWidth} | ||
${minHeight} | ||
`; | ||
|
||
StyledPopover.defaultProps = { | ||
p: 2, | ||
}; | ||
|
||
export const PopoverHeader = styled.div` | ||
padding: ${p => p.theme.space[1]} ${p => p.theme.space[2]}; | ||
margin-bottom: ${p => p.theme.space[1]}; | ||
padding-bottom: ${p => p.theme.space[1]}; | ||
border-bottom: ${p => p.theme.borders.base}; | ||
border-color: ${p => p.theme.colors.gray300}; | ||
`; | ||
|
||
export const PopoverContent = styled.div` | ||
padding: ${p => p.theme.space[2]}; | ||
`; |
Oops, something went wrong.