| 1 | import { |
| 2 | ListboxButton as HLButton, |
| 3 | ListboxOption as HLOption, |
| 4 | ListboxOptions as HLOptions, |
| 5 | Listbox, |
| 6 | } from "@headlessui/react"; |
| 7 | import * as React from "react"; |
| 8 | import { defaultBorderRadius, vscCommandCenterInactiveBorder } from ".."; |
| 9 | import { cn } from "../../util/cn"; |
| 10 | import { FontSizeModifier, useFontSize } from "./font"; |
| 11 | |
| 12 | type ListboxButtonProps = React.ComponentProps<typeof HLButton> & { |
| 13 | fontSizeModifier?: FontSizeModifier; |
| 14 | }; |
| 15 | |
| 16 | const ListboxButton = React.forwardRef<HTMLButtonElement, ListboxButtonProps>( |
| 17 | ({ fontSizeModifier = -3, ...props }, ref) => { |
| 18 | const fontSize = useFontSize(fontSizeModifier); |
| 19 | return ( |
| 20 | <HLButton |
| 21 | ref={ref} |
| 22 | {...props} |
| 23 | className={cn( |
| 24 | "bg-vsc-input-background text-vsc-foreground border-border m-0 flex flex-1 cursor-pointer flex-row items-center gap-1 border border-solid px-1 py-0.5 text-left transition-colors duration-200", |
| 25 | props.className, |
| 26 | )} |
| 27 | style={{ |
| 28 | fontSize, |
| 29 | borderRadius: defaultBorderRadius, |
| 30 | ...props.style, |
| 31 | }} |
| 32 | /> |
| 33 | ); |
| 34 | }, |
| 35 | ); |
| 36 | |
| 37 | type ListboxOptionsProps = React.ComponentProps<typeof HLOptions> & { |
| 38 | fontSizeModifier?: FontSizeModifier; |
| 39 | }; |
| 40 | const ListboxOptions = React.forwardRef<HTMLUListElement, ListboxOptionsProps>( |
| 41 | ({ fontSizeModifier = -3, ...props }, ref) => { |
| 42 | const fontSize = useFontSize(fontSizeModifier); |
| 43 | return ( |
| 44 | <HLOptions |
| 45 | ref={ref} |
| 46 | anchor={"bottom start"} |
| 47 | {...props} |
| 48 | className={cn( |
| 49 | "bg-vsc-input-background flex w-max min-w-[160px] max-w-[400px] flex-col overflow-auto px-0 shadow-md", |
| 50 | props.className, |
| 51 | )} |
| 52 | style={{ |
| 53 | border: `1px solid ${vscCommandCenterInactiveBorder}`, |
| 54 | fontSize, |
| 55 | borderRadius: defaultBorderRadius, |
| 56 | zIndex: 200000, |
| 57 | ...props.style, |
| 58 | }} |
| 59 | /> |
| 60 | ); |
| 61 | }, |
| 62 | ); |
| 63 | |
| 64 | type ListboxOptionProps = React.ComponentProps<typeof HLOption> & { |
| 65 | fontSizeModifier?: FontSizeModifier; |
| 66 | }; |
| 67 | const ListboxOption = React.forwardRef<HTMLLIElement, ListboxOptionProps>( |
| 68 | ({ fontSizeModifier = -3, ...props }, ref) => { |
| 69 | const fontSize = useFontSize(fontSizeModifier); |
| 70 | return ( |
| 71 | <HLOption |
| 72 | ref={ref} |
| 73 | {...props} |
| 74 | className={cn( |
| 75 | "text-foreground flex select-none flex-row items-center justify-between px-2 py-1", |
| 76 | props.disabled |
| 77 | ? "opacity-50" |
| 78 | : "background-transparent hover:bg-list-active hover:text-list-active-foreground cursor-pointer opacity-100", |
| 79 | props.className, |
| 80 | )} |
| 81 | style={{ |
| 82 | fontSize, |
| 83 | ...props.style, |
| 84 | }} |
| 85 | /> |
| 86 | ); |
| 87 | }, |
| 88 | ); |
| 89 | |
| 90 | export { Listbox, ListboxButton, ListboxOption, ListboxOptions }; |