feat(ui): IAICustomSelect tweak styles

This commit is contained in:
psychedelicious 2023-06-03 20:39:14 +10:00
parent aa3a969bd2
commit d0406024e3
2 changed files with 79 additions and 58 deletions

View File

@ -1,4 +1,4 @@
import { CheckIcon } from '@chakra-ui/icons'; import { CheckIcon, ChevronUpIcon } from '@chakra-ui/icons';
import { import {
Box, Box,
Flex, Flex,
@ -10,7 +10,6 @@ import {
GridItem, GridItem,
List, List,
ListItem, ListItem,
Select,
Text, Text,
Tooltip, Tooltip,
TooltipProps, TooltipProps,
@ -20,6 +19,7 @@ import { useSelect } from 'downshift';
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'; import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
import { memo } from 'react'; import { memo } from 'react';
import { getInputOutlineStyles } from 'theme/util/getInputOutlineStyles';
export type ItemTooltips = { [key: string]: string }; export type ItemTooltips = { [key: string]: string };
@ -82,16 +82,20 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
</FormLabel> </FormLabel>
)} )}
<Tooltip label={tooltip} {...tooltipProps}> <Tooltip label={tooltip} {...tooltipProps}>
<Select <Flex
{...getToggleButtonProps({ ref: refs.setReference })} {...getToggleButtonProps({ ref: refs.setReference })}
{...buttonProps} {...buttonProps}
as={Flex}
sx={{ sx={{
alignItems: 'center', alignItems: 'center',
userSelect: 'none', userSelect: 'none',
cursor: 'pointer', cursor: 'pointer',
overflow: 'hidden', overflow: 'hidden',
width: 'full', width: 'full',
py: 1,
px: 2,
gap: 2,
justifyContent: 'space-between',
...getInputOutlineStyles(),
}} }}
> >
<Text <Text
@ -106,7 +110,15 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
> >
{selectedItem} {selectedItem}
</Text> </Text>
</Select> <ChevronUpIcon
sx={{
color: 'base.300',
transform: isOpen ? 'rotate(0deg)' : 'rotate(180deg)',
transitionProperty: 'common',
transitionDuration: 'normal',
}}
/>
</Flex>
</Tooltip> </Tooltip>
<Box {...getMenuProps()}> <Box {...getMenuProps()}>
{isOpen && ( {isOpen && (
@ -115,9 +127,8 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
ref={refs.setFloating} ref={refs.setFloating}
sx={{ sx={{
...floatingStyles, ...floatingStyles,
width: 'full',
top: 0, top: 0,
left: 0, insetInlineStart: 0,
flexDirection: 'column', flexDirection: 'column',
zIndex: 2, zIndex: 2,
bg: 'base.800', bg: 'base.800',
@ -133,7 +144,16 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
}} }}
> >
<OverlayScrollbarsComponent> <OverlayScrollbarsComponent>
{items.map((item, index) => ( {items.map((item, index) => {
const isSelected = selectedItem === item;
const isHighlighted = highlightedIndex === index;
const fontWeight = isSelected ? 700 : 500;
const bg = isHighlighted
? 'base.700'
: isSelected
? 'base.750'
: undefined;
return (
<Tooltip <Tooltip
isDisabled={!itemTooltips} isDisabled={!itemTooltips}
key={`${item}${index}`} key={`${item}${index}`}
@ -143,7 +163,7 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
> >
<ListItem <ListItem
sx={{ sx={{
bg: highlightedIndex === index ? 'base.700' : undefined, bg,
py: 1, py: 1,
paddingInlineStart: 3, paddingInlineStart: 3,
paddingInlineEnd: 6, paddingInlineEnd: 6,
@ -157,14 +177,14 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
{withCheckIcon ? ( {withCheckIcon ? (
<Grid gridTemplateColumns="1.25rem auto"> <Grid gridTemplateColumns="1.25rem auto">
<GridItem> <GridItem>
{selectedItem === item && <CheckIcon boxSize={2} />} {isSelected && <CheckIcon boxSize={2} />}
</GridItem> </GridItem>
<GridItem> <GridItem>
<Text <Text
sx={{ sx={{
fontSize: 'sm', fontSize: 'sm',
color: 'base.100', color: 'base.100',
fontWeight: 500, fontWeight,
}} }}
> >
{item} {item}
@ -175,8 +195,8 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
<Text <Text
sx={{ sx={{
fontSize: 'sm', fontSize: 'sm',
color: 'base.100', color: 'base.50',
fontWeight: 500, fontWeight,
}} }}
> >
{item} {item}
@ -184,7 +204,8 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
)} )}
</ListItem> </ListItem>
</Tooltip> </Tooltip>
))} );
})}
</OverlayScrollbarsComponent> </OverlayScrollbarsComponent>
</List> </List>
)} )}

View File

@ -1,6 +1,6 @@
import { StyleFunctionProps } from '@chakra-ui/theme-tools'; import { StyleFunctionProps } from '@chakra-ui/theme-tools';
export const getInputOutlineStyles = (_props: StyleFunctionProps) => ({ export const getInputOutlineStyles = (_props?: StyleFunctionProps) => ({
outline: 'none', outline: 'none',
borderWidth: 2, borderWidth: 2,
borderStyle: 'solid', borderStyle: 'solid',