-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: redesign select dropdown (#4727)
- Loading branch information
Showing
13 changed files
with
126 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
apps/web/src/store/non-persisted/publication/usePublicationLicenseStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,80 @@ | ||
import type { ComponentProps } from 'react'; | ||
|
||
import { forwardRef, useId } from 'react'; | ||
import { Listbox, Transition } from '@headlessui/react'; | ||
import { CheckCircleIcon, ChevronDownIcon } from '@heroicons/react/24/solid'; | ||
import { forwardRef, Fragment } from 'react'; | ||
|
||
import cn from '../cn'; | ||
|
||
interface SelectProps extends ComponentProps<'select'> { | ||
interface SelectProps { | ||
className?: string; | ||
label?: string; | ||
defaultValue?: string; | ||
onChange: (value: any) => any; | ||
options?: { | ||
disabled?: boolean; | ||
helper?: string; | ||
label: string; | ||
selected?: boolean; | ||
value: number | string; | ||
}[]; | ||
} | ||
|
||
export const Select = forwardRef<HTMLSelectElement, SelectProps>( | ||
function Select({ className = '', label, options, ...rest }, ref) { | ||
const id = useId(); | ||
function Select({ className, defaultValue, onChange, options }) { | ||
const selected = options?.find((option) => option.selected) || options?.[0]; | ||
|
||
return ( | ||
<label htmlFor={id}> | ||
{label ? <div className="label">{label}</div> : null} | ||
<select | ||
className={cn( | ||
'w-full rounded-xl border border-gray-300 bg-white outline-none focus:border-gray-500 focus:ring-gray-400 dark:border-gray-700 dark:bg-gray-800', | ||
className | ||
)} | ||
id={id} | ||
ref={ref} | ||
{...rest} | ||
> | ||
{options?.map(({ disabled, label, selected, value }) => ( | ||
<option disabled={disabled} selected={selected} value={value}> | ||
{label} | ||
</option> | ||
))} | ||
</select> | ||
</label> | ||
<Listbox onChange={onChange} value={defaultValue || selected?.value}> | ||
<div className="relative"> | ||
<Listbox.Button | ||
className={cn( | ||
'flex w-full items-center justify-between space-x-3 rounded-xl border border-gray-300 bg-white px-3 py-2 text-left outline-none focus:border-gray-500 focus:ring-gray-400 dark:border-gray-700 dark:bg-gray-800', | ||
className | ||
)} | ||
> | ||
<span>{selected?.label}</span> | ||
<ChevronDownIcon className="mr-1 size-5 text-gray-400" /> | ||
</Listbox.Button> | ||
<Transition | ||
as={Fragment} | ||
enter="transition ease-out duration-100" | ||
enterFrom="transform opacity-0 scale-95" | ||
enterTo="transform opacity-100 scale-100" | ||
leave="transition ease-in duration-75" | ||
leaveFrom="transform opacity-100 scale-100" | ||
leaveTo="transform opacity-0 scale-95" | ||
> | ||
<Listbox.Options className="absolute z-[5] mt-2 max-h-60 w-full overflow-y-scroll rounded-xl border bg-white shadow-sm focus:outline-none dark:border-gray-700 dark:bg-gray-900"> | ||
{options?.map((option, id) => ( | ||
<Listbox.Option | ||
className={({ active }: { active: boolean }) => | ||
cn( | ||
{ 'dropdown-active': active }, | ||
'm-2 cursor-pointer rounded-lg' | ||
) | ||
} | ||
key={id} | ||
value={option.value} | ||
> | ||
{({ selected }) => ( | ||
<div className="flex flex-col space-y-0 px-2 py-1.5"> | ||
<span className="flex w-full items-center justify-between space-x-3 text-gray-700 dark:text-gray-200"> | ||
<span className="block truncate">{option.label}</span> | ||
{selected ? ( | ||
<CheckCircleIcon className="size-5" /> | ||
) : null} | ||
</span> | ||
{option.helper ? ( | ||
<span className="ld-text-gray-500 text-xs"> | ||
{option.helper} | ||
</span> | ||
) : null} | ||
</div> | ||
)} | ||
</Listbox.Option> | ||
))} | ||
</Listbox.Options> | ||
</Transition> | ||
</div> | ||
</Listbox> | ||
); | ||
} | ||
); |
20e8bf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
web – ./apps/web
web-git-main-heyxyz.vercel.app
heyxyz.vercel.app
web-heyxyz.vercel.app
hey.xyz