Updated Select and SelectItem
Part of this was combining PictureSelectItem and SelectItem, so the former has been removed.
This commit is contained in:
parent
3f70a78838
commit
93007f48f6
6 changed files with 112 additions and 133 deletions
|
|
@ -1,42 +0,0 @@
|
||||||
.SelectItem.Picture {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: $unit;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.preview {
|
|
||||||
$diameter: $unit-4x;
|
|
||||||
border-radius: $unit-2x;
|
|
||||||
width: $diameter;
|
|
||||||
height: $diameter;
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: $diameter;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.fire {
|
|
||||||
background: $fire-bg-20;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.water {
|
|
||||||
background: $water-bg-20;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.wind {
|
|
||||||
background: $wind-bg-20;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.earth {
|
|
||||||
background: $earth-bg-20;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.dark {
|
|
||||||
background: $dark-bg-10;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.light {
|
|
||||||
background: $light-bg-20;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import React, { ComponentProps } from 'react'
|
|
||||||
import * as Select from '@radix-ui/react-select'
|
|
||||||
|
|
||||||
import styles from './index.module.scss'
|
|
||||||
import classNames from 'classnames'
|
|
||||||
|
|
||||||
interface Props extends ComponentProps<'div'> {
|
|
||||||
src: string[]
|
|
||||||
element: string
|
|
||||||
value: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const PictureSelectItem = React.forwardRef<HTMLDivElement, Props>(
|
|
||||||
function selectItem({ children, ...props }, forwardedRef) {
|
|
||||||
return (
|
|
||||||
<Select.Item
|
|
||||||
className={classNames('SelectItem Picture', props.className)}
|
|
||||||
{...props}
|
|
||||||
ref={forwardedRef}
|
|
||||||
value={`${props.value}`}
|
|
||||||
>
|
|
||||||
<div className={`preview ${props.element}`}>
|
|
||||||
<img
|
|
||||||
alt={`${props.value}`}
|
|
||||||
src={props.src[0]}
|
|
||||||
srcSet={props.src.join(', ')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<Select.ItemText>{children}</Select.ItemText>
|
|
||||||
</Select.Item>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export default PictureSelectItem
|
|
||||||
|
|
@ -27,36 +27,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.hidden {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--input-bg-hover);
|
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
span:not(.SelectIcon),
|
|
||||||
&[data-placeholder] > span:not(.SelectIcon) {
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.disabled:hover {
|
|
||||||
background-color: var(--input-bg);
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
&[data-placeholder='true'] > span:not(.SelectIcon) {
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
& > span:not(.SelectIcon) {
|
|
||||||
color: var(--text-primary);
|
|
||||||
flex-grow: 1;
|
|
||||||
font-size: $font-regular;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.bound {
|
&.bound {
|
||||||
background-color: var(--select-contained-bg);
|
background-color: var(--select-contained-bg);
|
||||||
|
|
||||||
|
|
@ -65,10 +35,44 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.Table {
|
&.table {
|
||||||
min-width: $unit * 30;
|
min-width: $unit * 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--input-bg-hover);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
span:not(.icon),
|
||||||
|
&[data-placeholder] > span:not(.icon) {
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg {
|
||||||
|
fill: var(--text-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.disabled:hover {
|
||||||
|
background-color: var(--input-bg);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-placeholder='true'] > span:not(.icon) {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
& > span:not(.icon) {
|
||||||
|
color: var(--text-primary);
|
||||||
|
flex-grow: 1;
|
||||||
|
font-size: $font-regular;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: $unit-4x;
|
width: $unit-4x;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
@ -82,10 +86,6 @@
|
||||||
fill: var(--icon-secondary);
|
fill: var(--icon-secondary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
span:not(.icon) {
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.select {
|
.select {
|
||||||
|
|
@ -98,6 +98,10 @@
|
||||||
max-height: 40vh;
|
max-height: 40vh;
|
||||||
z-index: 40;
|
z-index: 40;
|
||||||
|
|
||||||
|
&.bound {
|
||||||
|
background-color: var(--select-content-contained-bg);
|
||||||
|
}
|
||||||
|
|
||||||
.scroll.up,
|
.scroll.up,
|
||||||
.scroll.down {
|
.scroll.down {
|
||||||
padding: $unit 0;
|
padding: $unit 0;
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,34 @@ interface Props
|
||||||
overlayVisible?: boolean
|
overlayVisible?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const Select = React.forwardRef<HTMLButtonElement, Props>(function Select(
|
const Select = React.forwardRef<HTMLButtonElement, Props>(function select(
|
||||||
props: Props,
|
props: Props,
|
||||||
forwardedRef
|
forwardedRef
|
||||||
) {
|
) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [value, setValue] = useState('')
|
const [value, setValue] = useState('')
|
||||||
|
|
||||||
const triggerClasses = classNames({
|
const triggerClasses = classNames(
|
||||||
[styles.trigger]: true,
|
{
|
||||||
[styles.disabled]: props.disabled,
|
[styles.trigger]: true,
|
||||||
[styles.bound]: props.trigger ? props.trigger.bound : false,
|
[styles.disabled]: props.disabled,
|
||||||
[styles.small]: props.trigger?.size === 'small',
|
[styles.bound]: props.trigger ? props.trigger.bound : false,
|
||||||
[styles.medium]: !props.trigger || props.trigger?.size === 'medium',
|
[styles.small]: props.trigger?.size === 'small',
|
||||||
[styles.large]: props.trigger?.size === 'large',
|
[styles.medium]: !props.trigger || props.trigger?.size === 'medium',
|
||||||
})
|
[styles.large]: props.trigger?.size === 'large',
|
||||||
|
},
|
||||||
|
props.trigger?.className?.split(' ').map((className) => {
|
||||||
|
console.log('className', className)
|
||||||
|
return styles[className]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const selectClasses = classNames(
|
const selectClasses = classNames(
|
||||||
{
|
{
|
||||||
[styles.select]: true,
|
[styles.select]: true,
|
||||||
|
[styles.bound]: props.trigger ? props.trigger.bound : false,
|
||||||
},
|
},
|
||||||
props.className
|
props.className?.split(' ').map((className) => styles[className])
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,39 @@
|
||||||
margin-bottom: $unit;
|
margin-bottom: $unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
.preview {
|
||||||
width: $unit-4x;
|
$diameter: $unit-4x;
|
||||||
height: auto;
|
border-radius: $unit-2x;
|
||||||
|
width: $diameter;
|
||||||
|
height: $diameter;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: $diameter;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.fire {
|
||||||
|
background: $fire-bg-20;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.water {
|
||||||
|
background: $water-bg-20;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.wind {
|
||||||
|
background: $wind-bg-20;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.earth {
|
||||||
|
background: $earth-bg-20;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.dark {
|
||||||
|
background: $dark-bg-10;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.light {
|
||||||
|
background: $light-bg-20;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,9 @@ import classNames from 'classnames'
|
||||||
|
|
||||||
interface Props extends ComponentProps<'div'> {
|
interface Props extends ComponentProps<'div'> {
|
||||||
value: string | number
|
value: string | number
|
||||||
|
element?: string
|
||||||
icon?: {
|
icon?: {
|
||||||
src: string
|
src: string[]
|
||||||
alt: string
|
alt: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,19 +17,32 @@ const SelectItem = React.forwardRef<HTMLDivElement, Props>(function selectItem(
|
||||||
{ icon, value, children, ...props },
|
{ icon, value, children, ...props },
|
||||||
forwardedRef
|
forwardedRef
|
||||||
) {
|
) {
|
||||||
|
const itemClasses = classNames(
|
||||||
|
{
|
||||||
|
[styles.item]: true,
|
||||||
|
},
|
||||||
|
props.className?.split(' ').map((className) => styles[className])
|
||||||
|
)
|
||||||
|
|
||||||
|
const wrapperClasses = classNames(
|
||||||
|
{
|
||||||
|
[styles.preview]: true,
|
||||||
|
},
|
||||||
|
props.element && styles[props.element]
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select.Item
|
<Select.Item
|
||||||
{...props}
|
{...props}
|
||||||
className={classNames(
|
className={itemClasses}
|
||||||
{
|
|
||||||
[styles.item]: true,
|
|
||||||
},
|
|
||||||
props.className
|
|
||||||
)}
|
|
||||||
ref={forwardedRef}
|
ref={forwardedRef}
|
||||||
value={`${value}`}
|
value={`${value}`}
|
||||||
>
|
>
|
||||||
{icon ? <img alt={icon.alt} src={icon.src} /> : ''}
|
{icon && (
|
||||||
|
<div className={wrapperClasses}>
|
||||||
|
<img alt={icon.alt} src={icon.src[0]} srcSet={icon.src.join(', ')} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<Select.ItemText>{children}</Select.ItemText>
|
<Select.ItemText>{children}</Select.ItemText>
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue