feat: Dropdown don't use children length * 2

This commit is contained in:
LynithDev 2024-06-16 13:04:18 +02:00
parent a17bcbb471
commit 43621b4038
3 changed files with 14 additions and 19 deletions

View file

@ -1,11 +1,11 @@
.dropdown { .dropdown {
@apply relative; @apply relative w-52;
.row { .row {
@apply flex flex-row justify-start items-center gap-1.5 h-4; @apply w-full flex flex-row justify-start items-center gap-1.5 h-4 text-nowrap overflow-hidden;
> svg { > svg {
@apply w-4 h-4; @apply min-w-4 min-h-4 w-4 h-4;
} }
} }

View file

@ -1,17 +1,19 @@
import { Index, type JSX, type ParentProps, children, createSignal } from 'solid-js'; import { Index, type JSX, type ParentProps, children, createEffect, createSignal, splitProps } from 'solid-js';
import { ChevronDownIcon } from '@untitled-theme/icons-solid'; import { ChevronDownIcon } from '@untitled-theme/icons-solid';
import Popup from '../overlay/Popup'; import Popup from '../overlay/Popup';
import Button from './Button'; import Button from './Button';
import styles from './Dropdown.module.scss'; import styles from './Dropdown.module.scss';
export type DropdownProps = ParentProps; export type DropdownProps = JSX.HTMLAttributes<HTMLDivElement>;
function Dropdown(props: DropdownProps) { function Dropdown(props: DropdownProps) {
const [split, rest] = splitProps(props, ['children', 'class']);
const [visible, setVisible] = createSignal(false); const [visible, setVisible] = createSignal(false);
const [selected, setSelected] = createSignal<number>(0); const [selected, setSelected] = createSignal<number>(0);
let ref!: HTMLDivElement; let ref!: HTMLDivElement;
const items = () => children(() => props.children).toArray(); const items = () => children(() => split.children).toArray();
function select(index: number) { function select(index: number) {
setSelected(index); setSelected(index);
@ -19,24 +21,17 @@ function Dropdown(props: DropdownProps) {
} }
return ( return (
<div ref={ref} class={styles.dropdown}> <div ref={ref} class={`${styles.dropdown} ${split.class}`} {...rest}>
<Button <Button
class="h-full" class="h-full w-full"
buttonStyle="secondary" buttonStyle="secondary"
onClick={() => setVisible(true)} onClick={() => setVisible(true)}
iconRight={<ChevronDownIcon />} iconRight={<ChevronDownIcon />}
> >
<div <div
class="w-full h-full overflow-hidden mt-px" class="w-full h-full mt-px"
> >
<div {items()[selected()]}
class="flex flex-col justify-start relative gap-4"
style={{
transform: `translateY(-${(selected() * 16) * 2}px)`,
}}
>
{items()}
</div>
</div> </div>
</Button> </Button>
@ -44,7 +39,7 @@ function Dropdown(props: DropdownProps) {
mount={ref} mount={ref}
visible={visible} visible={visible}
setVisible={setVisible} setVisible={setVisible}
ref={ref => ref.classList.add('mt-1', 'left-0', 'right-0')} ref={ref => ref.classList.add('mt-1', 'w-full')}
> >
<div class="bg-secondary rounded-lg border border-gray-05 p-1 shadow-md shadow-black/30"> <div class="bg-secondary rounded-lg border border-gray-05 p-1 shadow-md shadow-black/30">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">

View file

@ -40,7 +40,7 @@ function BrowserMain() {
<div class="flex flex-col flex-grow-1"> <div class="flex flex-col flex-grow-1">
<div class="flex flex-row gap-2 h-8"> <div class="flex flex-row gap-2 h-8">
<TextField iconLeft={<SearchMdIcon />} /> <TextField iconLeft={<SearchMdIcon />} />
<Dropdown> <Dropdown class="w-32!">
<Dropdown.Row> <Dropdown.Row>
<HeartIcon /> <HeartIcon />
<p>Test</p> <p>Test</p>