Skip to content

Commit

Permalink
chore: taggable popover sort by selection and name
Browse files Browse the repository at this point in the history
  • Loading branch information
luizakp committed Feb 13, 2024
1 parent 52c4fdd commit 31bb814
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/components/TaggablePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,34 @@ export const TaggablePopover = ({ tags, selectedTags, onSelect }) => (
<Command>
<CommandInput placeholder="tags" />
<CommandList>
{tags.map((option) => {
const isSelected = selectedTags.includes(option.value);
return (
<CommandItem
key={option.value}
onSelect={(tag) => onSelect({ tag })}
>
<div
className={cn(
"border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
isSelected
? "bg-primary text-primary-foreground"
: "opacity-50 [&_svg]:invisible"
)}
{tags
.sort(
(a, b) =>
selectedTags.includes(b.value) -
selectedTags.includes(a.value) ||
a.label.localeCompare(b.label)
)
.map((option) => {
const isSelected = selectedTags.includes(option.value);
return (
<CommandItem
key={option.value}
onSelect={(tag) => onSelect({ tag })}
>
<CheckIcon className={cn("h-4 w-4")} />
</div>
<span>{option.label}</span>
</CommandItem>
);
})}
<div
className={cn(
"border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
isSelected
? "bg-primary text-primary-foreground"
: "opacity-50 [&_svg]:invisible"
)}
>
<CheckIcon className={cn("h-4 w-4")} />
</div>
<span>{option.label}</span>
</CommandItem>
);
})}
<SubItem tags={tags} onSelect={onSelect} />
</CommandList>
</Command>
Expand Down

0 comments on commit 31bb814

Please sign in to comment.