-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: select component that also has the possibility to add new tags
- Loading branch information
1 parent
f1d9b07
commit 3bd1cf8
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,78 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import CreatableSelect from 'react-select/creatable'; | ||
import styled, { css, withTheme } from 'styled-components'; | ||
|
||
import { Body } from '../typography'; | ||
|
||
const SelectCreatableEnum = { | ||
disabled: 'disabled', | ||
error: 'error', | ||
default: 'default', | ||
}; | ||
|
||
const StyledCreatableSelect = styled(CreatableSelect)` | ||
${props => { | ||
if (props.variant === SelectCreatableEnum.error) { | ||
// error variant style | ||
return css` | ||
div[class*='control'] { | ||
border-radius: 0.125rem; | ||
border: 1px solid ${props.theme.colors.default.status.error.primary}; | ||
} | ||
div[class*='control']:focus-within { | ||
border: 1px solid #f5222d; | ||
box-shadow: 0px 0px 4px rgba(245, 34, 45, 0.5); | ||
} | ||
`; | ||
} else { | ||
// default variant style | ||
return css` | ||
div[class*='control'] { | ||
border-radius: 0.125rem; | ||
border: 0.0625rem solid #d9d9d9; | ||
} | ||
div[class*='control']:hover { | ||
border: 1px solid #40a9ff; | ||
} | ||
div[class*='control']:focus-within { | ||
border: 1px solid #1890ff; | ||
box-shadow: 0px 0px 4px rgba(24, 144, 255, 0.5); | ||
} | ||
`; | ||
} | ||
}} | ||
`; | ||
|
||
const SelectCreatable = withTheme(({ variant, options, onChange }) => { | ||
const optionsList = useMemo( | ||
() => | ||
options?.map(optionItem => ({ | ||
value: optionItem, | ||
label: optionItem, | ||
})) ?? [], | ||
[options], | ||
); | ||
|
||
const handleChange = useCallback( | ||
newValue => | ||
onChange(newValue?.map(selectedItem => selectedItem.value) ?? []), | ||
[onChange], | ||
); | ||
|
||
return ( | ||
<Body> | ||
<StyledCreatableSelect | ||
isMulti | ||
onChange={handleChange} | ||
options={optionsList} | ||
variant={variant} | ||
isDisabled={variant === SelectCreatableEnum.disabled} | ||
/> | ||
</Body> | ||
); | ||
}); | ||
|
||
export { SelectCreatable, SelectCreatableEnum }; |
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