Files
react/components/select/select-multiple-value.tsx
William a588ae8901 feat(select): add clearable option to select multiple with test and english doc (#396)
* docs: add clearable option to select multiple with test and english doc

* fix: fix types for onClear

* fix: fix import path for use-theme

add more test for coverage

* docs(select): add chinese document

Co-authored-by: unix <unix.bio@gmail.com>
2021-01-31 17:49:30 +08:00

54 lines
1.3 KiB
TypeScript

import React from 'react'
import useTheme from '../use-theme'
import Grid from '../grid'
import SelectClearIcon from './select-icon-clear'
interface Props {
disabled: boolean
onClear: (() => void) | null
size: string
}
const SelectMultipleValue: React.FC<React.PropsWithChildren<Props>> = ({
disabled,
size,
onClear,
children,
}) => {
const theme = useTheme()
return (
<Grid>
<div className="item">
{children}
{!!onClear && <SelectClearIcon heightRatio="1.5" onClick={onClear} />}
</div>
<style jsx>{`
.item {
display: inline-flex;
height: calc(${size} * 2);
justify-items: center;
align-items: center;
line-height: 1;
padding: 0 0.5rem;
font-size: ${size};
border-radius: ${theme.layout.radius};
background-color: ${theme.palette.accents_2};
color: ${disabled ? theme.palette.accents_4 : theme.palette.accents_6};
}
.item > :global(div:not(.clear-icon)),
.item > :global(div:not(.clear-icon):hover) {
border-radius: 0;
background-color: transparent;
padding: 0;
margin: 0;
color: inherit;
}
`}</style>
</Grid>
)
}
export default SelectMultipleValue