Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-baboons-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@genseki/ui': patch
---

[FIX] Filter Component UI
17 changes: 12 additions & 5 deletions packages/ui/src/components/primitives/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
setInternalOptions(options)
}, [options])

function handleOpenChange(open: boolean) {
if (!open) {
setInternalOptions(options)
}
setOpenModal(open)
}

function toggleItem(column: string, label: string) {
setInternalOptions((prev) => {
const prevOptions = prev[column]
Expand Down Expand Up @@ -73,8 +80,8 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
setOpenModal(false)
}

function columnCount(column: string) {
return internalOptions[column]?.length || 0
function columnSelectedCount(column: string) {
return internalOptions[column]?.filter((o) => o.isSelected).length || 0
}

const columns = Object.keys(internalOptions)
Expand All @@ -84,7 +91,7 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
)

return (
<Popover open={openModal} onOpenChange={setOpenModal}>
<Popover open={openModal} onOpenChange={handleOpenChange}>
<PopoverTrigger asChild>
<Button variant="outline" className={cn('w-fit', classNames?.trigger)}>
<Typography className="text-icon-tertiary">Filter</Typography>
Expand Down Expand Up @@ -114,7 +121,7 @@ export function Filter<T extends FilterOptions>({ options, onChange, classNames
<Typography weight="normal" type="body">
{column}
</Typography>
<CountBadge count={columnCount(column)} />
<CountBadge count={columnSelectedCount(column)} />
</li>
))}
</ul>
Expand Down Expand Up @@ -164,7 +171,7 @@ function CountBadge({ count }: { count: number }) {
return (
<div
className={cn(
'size-[22px] rounded-full bg-surface-primary border flex items-center justify-center',
'size-[22px] rounded-full bg-surface-primary border flex items-center justify-center text-xs',
{
'opacity-0': count === 0,
}
Expand Down
Loading