Skip to content

Commit

Permalink
do the thing with prominent options set
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordfirespeed committed Jun 21, 2024
1 parent 6a2f57a commit f91f67a
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/components/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandList, CommandSeparator,
} from "@/components/ui/command"
import {
Drawer,
Expand Down Expand Up @@ -195,27 +195,41 @@ const ComboBoxContent = React.forwardRef<
ComboBoxContent.displayName = "ComboBoxContent"

function OptionList() {
const { options, setSelectedOption, setOpen, onChange } = useComboBox();
const { options, prominentOptions, setSelectedOption, setOpen, onChange } = useComboBox();

function renderOption(option: Option<React.Key>) {
return (
<CommandItem
key={option.value}
value={option.value.toString()}
onSelect={() => {
setSelectedOption(option)
onChange(option.value)
setOpen(false)
}}
>
{option.label}
</CommandItem>
)
}

return (
<Command>
<CommandInput placeholder="Filter options..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
{options.map((option) => (
<CommandItem
key={option.value}
value={option.value.toString()}
onSelect={() => {
setSelectedOption(option)
onChange(option.value)
setOpen(false)
}}
>
{option.label}
</CommandItem>
))}
{options
.filter(option => prominentOptions?.has(option.value) ?? false)
.map(renderOption)
}
</CommandGroup>
<CommandSeparator />
<CommandGroup>
{options
.filter(option => !(prominentOptions?.has(option.value) ?? false))
.map(renderOption)
}
</CommandGroup>
</CommandList>
</Command>
Expand Down

0 comments on commit f91f67a

Please sign in to comment.