Fix select classes
This commit is contained in:
parent
316ca19515
commit
45d4eda1ab
2 changed files with 60 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
.SelectTrigger {
|
.trigger {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: var(--input-bg);
|
background-color: var(--input-bg);
|
||||||
border-radius: $input-corner;
|
border-radius: $input-corner;
|
||||||
|
|
@ -7,6 +7,18 @@
|
||||||
gap: $unit;
|
gap: $unit;
|
||||||
padding: ($unit * 1.5) $unit-2x;
|
padding: ($unit * 1.5) $unit-2x;
|
||||||
|
|
||||||
|
&.small > span:not(.icon) {
|
||||||
|
font-size: $font-small;
|
||||||
|
margin: 0;
|
||||||
|
max-width: 200px;
|
||||||
|
|
||||||
|
@include breakpoint(tablet) {
|
||||||
|
width: 100%;
|
||||||
|
max-width: inherit;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.modal {
|
&.modal {
|
||||||
background-color: var(--select-modal-bg);
|
background-color: var(--select-modal-bg);
|
||||||
|
|
||||||
|
|
@ -29,7 +41,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.Disabled:hover {
|
&.disabled:hover {
|
||||||
background-color: var(--input-bg);
|
background-color: var(--input-bg);
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +57,7 @@
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.Bound {
|
&.bound {
|
||||||
background-color: var(--select-contained-bg);
|
background-color: var(--select-contained-bg);
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|
@ -62,7 +74,7 @@
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.SelectIcon {
|
.icon {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
|
@ -71,12 +83,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
span:not(.SelectIcon) {
|
span:not(.icon) {
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.Select {
|
.select {
|
||||||
background: var(--dialog-bg);
|
background: var(--dialog-bg);
|
||||||
border-radius: $card-corner;
|
border-radius: $card-corner;
|
||||||
border: 1px solid rgba(0, 0, 0, 0.24);
|
border: 1px solid rgba(0, 0, 0, 0.24);
|
||||||
|
|
@ -86,8 +98,8 @@
|
||||||
max-height: 40vh;
|
max-height: 40vh;
|
||||||
z-index: 40;
|
z-index: 40;
|
||||||
|
|
||||||
.Scroll.Up,
|
.scroll.up,
|
||||||
.Scroll.Down {
|
.scroll.down {
|
||||||
padding: $unit 0;
|
padding: $unit 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
|
@ -100,7 +112,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.Scroll.Up {
|
.scroll.up {
|
||||||
transform: scale(1, -1);
|
transform: scale(1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,21 @@ interface Props
|
||||||
React.SelectHTMLAttributes<HTMLSelectElement>,
|
React.SelectHTMLAttributes<HTMLSelectElement>,
|
||||||
HTMLSelectElement
|
HTMLSelectElement
|
||||||
> {
|
> {
|
||||||
altText?: string
|
|
||||||
iconSrc?: string
|
|
||||||
open: boolean
|
open: boolean
|
||||||
trigger?: React.ReactNode
|
icon?: {
|
||||||
|
src: string
|
||||||
|
alt: string
|
||||||
|
}
|
||||||
|
trigger?: {
|
||||||
|
bound?: boolean
|
||||||
|
className?: string
|
||||||
|
placeholder?: string
|
||||||
|
size?: 'small' | 'medium' | 'large'
|
||||||
|
}
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
onOpenChange?: () => void
|
onOpenChange?: () => void
|
||||||
onValueChange?: (value: string) => void
|
onValueChange?: (value: string) => void
|
||||||
onClose?: () => void
|
onClose?: () => void
|
||||||
triggerClass?: string
|
|
||||||
overlayVisible?: boolean
|
overlayVisible?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,12 +39,20 @@ const Select = React.forwardRef<HTMLButtonElement, Props>(function Select(
|
||||||
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.bound]: props.trigger ? props.trigger.bound : false,
|
||||||
|
[styles.small]: props.trigger?.size === 'small',
|
||||||
|
[styles.medium]: !props.trigger || props.trigger?.size === 'medium',
|
||||||
|
[styles.large]: props.trigger?.size === 'large',
|
||||||
|
})
|
||||||
|
|
||||||
|
const selectClasses = classNames(
|
||||||
{
|
{
|
||||||
SelectTrigger: true,
|
[styles.select]: true,
|
||||||
Disabled: props.disabled,
|
|
||||||
},
|
},
|
||||||
props.triggerClass
|
props.className
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -82,10 +96,10 @@ const Select = React.forwardRef<HTMLButtonElement, Props>(function Select(
|
||||||
placeholder={props.placeholder}
|
placeholder={props.placeholder}
|
||||||
ref={forwardedRef}
|
ref={forwardedRef}
|
||||||
>
|
>
|
||||||
{props.iconSrc ? <img alt={props.altText} src={props.iconSrc} /> : ''}
|
{props.icon ? <img alt={props.icon.alt} src={props.icon.src} /> : ''}
|
||||||
<RadixSelect.Value placeholder={props.placeholder} />
|
<RadixSelect.Value placeholder={props.trigger?.placeholder} />
|
||||||
{!props.disabled ? (
|
{!props.disabled ? (
|
||||||
<RadixSelect.Icon className="SelectIcon">
|
<RadixSelect.Icon className={styles.icon}>
|
||||||
<ChevronIcon />
|
<ChevronIcon />
|
||||||
</RadixSelect.Icon>
|
</RadixSelect.Icon>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -93,7 +107,7 @@ const Select = React.forwardRef<HTMLButtonElement, Props>(function Select(
|
||||||
)}
|
)}
|
||||||
</RadixSelect.Trigger>
|
</RadixSelect.Trigger>
|
||||||
|
|
||||||
<RadixSelect.Portal className="SelectPortal">
|
<RadixSelect.Portal>
|
||||||
<>
|
<>
|
||||||
<Overlay
|
<Overlay
|
||||||
open={open}
|
open={open}
|
||||||
|
|
@ -101,18 +115,28 @@ const Select = React.forwardRef<HTMLButtonElement, Props>(function Select(
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RadixSelect.Content
|
<RadixSelect.Content
|
||||||
className={classNames({ Select: true }, props.className)}
|
className={selectClasses}
|
||||||
position="popper"
|
position="popper"
|
||||||
sideOffset={6}
|
sideOffset={6}
|
||||||
onCloseAutoFocus={onCloseAutoFocus}
|
onCloseAutoFocus={onCloseAutoFocus}
|
||||||
onEscapeKeyDown={onEscapeKeyDown}
|
onEscapeKeyDown={onEscapeKeyDown}
|
||||||
onPointerDownOutside={onPointerDownOutside}
|
onPointerDownOutside={onPointerDownOutside}
|
||||||
>
|
>
|
||||||
<RadixSelect.ScrollUpButton className="Scroll Up">
|
<RadixSelect.ScrollUpButton
|
||||||
|
className={classNames({
|
||||||
|
[styles.scroll]: true,
|
||||||
|
[styles.up]: true,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<ChevronIcon />
|
<ChevronIcon />
|
||||||
</RadixSelect.ScrollUpButton>
|
</RadixSelect.ScrollUpButton>
|
||||||
<RadixSelect.Viewport>{props.children}</RadixSelect.Viewport>
|
<RadixSelect.Viewport>{props.children}</RadixSelect.Viewport>
|
||||||
<RadixSelect.ScrollDownButton className="Scroll Down">
|
<RadixSelect.ScrollDownButton
|
||||||
|
className={classNames({
|
||||||
|
[styles.scroll]: true,
|
||||||
|
[styles.down]: true,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<ChevronIcon />
|
<ChevronIcon />
|
||||||
</RadixSelect.ScrollDownButton>
|
</RadixSelect.ScrollDownButton>
|
||||||
</RadixSelect.Content>
|
</RadixSelect.Content>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue