feishin/src/renderer/components/select/index.tsx

143 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-12-19 15:59:14 -08:00
import type {
2023-07-01 19:10:05 -07:00
SelectProps as MantineSelectProps,
MultiSelectProps as MantineMultiSelectProps,
2022-12-19 15:59:14 -08:00
} from '@mantine/core';
import { Select as MantineSelect, MultiSelect as MantineMultiSelect } from '@mantine/core';
import styled from 'styled-components';
interface SelectProps extends MantineSelectProps {
2023-07-01 19:10:05 -07:00
maxWidth?: number | string;
width?: number | string;
2022-12-19 15:59:14 -08:00
}
export interface MultiSelectProps extends MantineMultiSelectProps {
2023-07-01 19:10:05 -07:00
maxWidth?: number | string;
width?: number | string;
2022-12-19 15:59:14 -08:00
}
const StyledSelect = styled(MantineSelect)`
2023-07-01 19:10:05 -07:00
& [data-selected='true'] {
background: var(--input-bg);
}
2022-12-19 15:59:14 -08:00
2023-07-01 19:10:05 -07:00
& [data-disabled='true'] {
background: var(--input-bg);
opacity: 0.6;
}
2022-12-19 15:59:14 -08:00
2023-07-01 19:10:05 -07:00
& .mantine-Select-itemsWrapper {
& .mantine-Select-item {
padding: 40px;
}
2022-12-19 15:59:14 -08:00
}
`;
export const Select = ({ width, maxWidth, ...props }: SelectProps) => {
2023-07-01 19:10:05 -07:00
return (
<StyledSelect
withinPortal
styles={{
dropdown: {
background: 'var(--dropdown-menu-bg)',
filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 20%))',
},
input: {
background: 'var(--input-bg)',
color: 'var(--input-fg)',
},
item: {
'&:hover': {
background: 'var(--dropdown-menu-bg-hover)',
},
'&[data-hovered]': {
background: 'var(--dropdown-menu-bg-hover)',
},
'&[data-selected="true"]': {
'&:hover': {
background: 'var(--dropdown-menu-bg-hover)',
},
background: 'none',
color: 'var(--primary-color)',
},
color: 'var(--dropdown-menu-fg)',
padding: '.3rem',
},
}}
sx={{ maxWidth, width }}
transitionProps={{ duration: 100, transition: 'fade' }}
{...props}
/>
);
2022-12-19 15:59:14 -08:00
};
const StyledMultiSelect = styled(MantineMultiSelect)`
2023-07-01 19:10:05 -07:00
& [data-selected='true'] {
background: var(--input-select-bg);
}
2022-12-19 15:59:14 -08:00
2023-07-01 19:10:05 -07:00
& [data-disabled='true'] {
background: var(--input-bg);
opacity: 0.6;
}
2022-12-19 15:59:14 -08:00
2023-07-01 19:10:05 -07:00
& .mantine-MultiSelect-itemsWrapper {
& .mantine-Select-item {
padding: 40px;
}
2022-12-19 15:59:14 -08:00
}
`;
export const MultiSelect = ({ width, maxWidth, ...props }: MultiSelectProps) => {
2023-07-01 19:10:05 -07:00
return (
<StyledMultiSelect
withinPortal
styles={{
dropdown: {
background: 'var(--dropdown-menu-bg)',
filter: 'drop-shadow(0 0 5px rgb(0, 0, 0, 20%))',
},
input: {
background: 'var(--input-bg)',
color: 'var(--input-fg)',
},
item: {
'&:hover': {
background: 'var(--dropdown-menu-bg-hover)',
},
'&[data-hovered]': {
background: 'var(--dropdown-menu-bg-hover)',
},
'&[data-selected="true"]': {
'&:hover': {
background: 'var(--dropdown-menu-bg-hover)',
},
background: 'none',
color: 'var(--primary-color)',
},
color: 'var(--dropdown-menu-fg)',
padding: '.5rem .1rem',
},
value: {
margin: '.2rem',
paddingBottom: '1rem',
paddingLeft: '1rem',
paddingTop: '1rem',
},
}}
sx={{ maxWidth, width }}
transitionProps={{ duration: 100, transition: 'fade' }}
{...props}
/>
);
2022-12-19 15:59:14 -08:00
};
Select.defaultProps = {
2023-07-01 19:10:05 -07:00
maxWidth: undefined,
width: undefined,
2022-12-19 15:59:14 -08:00
};
MultiSelect.defaultProps = {
2023-07-01 19:10:05 -07:00
maxWidth: undefined,
width: undefined,
2022-12-19 15:59:14 -08:00
};