-
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.
fix: better integrated select component
- Loading branch information
Showing
11 changed files
with
225 additions
and
111 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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ComponentProps, useMemo } from 'react' | ||
import { SystemStyleObject, useColorMode } from '@chakra-ui/react' | ||
import { | ||
Select as ChakraReactSelect, | ||
ChakraStylesConfig, | ||
} from 'chakra-react-select' | ||
import { GroupBase } from 'react-select' | ||
|
||
export const Select = < | ||
Option = unknown, | ||
IsMulti extends boolean = false, | ||
Group extends GroupBase<Option> = GroupBase<Option>, | ||
>( | ||
props: ComponentProps<typeof ChakraReactSelect<Option, IsMulti, Group>>, | ||
) => { | ||
const { colorMode } = useColorMode() | ||
const chakraStyles = useMemo(() => { | ||
let bg = 'transparent' | ||
if (colorMode === 'light') { | ||
bg = 'white' | ||
} else if (colorMode === 'dark') { | ||
bg = 'gray.800' | ||
} | ||
return { | ||
control: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
bg, | ||
}), | ||
dropdownIndicator: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
bg, | ||
cursor: 'inherit', | ||
position: 'absolute', | ||
right: '0px', | ||
}), | ||
menuList: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
borderRadius: '15px', | ||
}), | ||
indicatorSeparator: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
display: 'none', | ||
}), | ||
placeholder: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
textAlign: 'center', | ||
}), | ||
singleValue: (provided: SystemStyleObject) => ({ | ||
...provided, | ||
textAlign: 'center', | ||
}), | ||
} as ChakraStylesConfig<Option, IsMulti, Group> | ||
}, [colorMode]) | ||
return ( | ||
<ChakraReactSelect<Option, IsMulti, Group> | ||
{...props} | ||
chakraStyles={chakraStyles} | ||
/> | ||
) | ||
} |
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
Oops, something went wrong.