-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81c466b
commit b523fa4
Showing
16 changed files
with
335 additions
and
36 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
121 changes: 121 additions & 0 deletions
121
src/components/data-table/DesktopFilterToolbar/TableDappFilter.tsx
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import SelectedLabels from '@/components/selected-labels'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Command, CommandGroup, CommandItem, CommandList } from '@/components/ui/command'; | ||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; | ||
import { cn } from '@/lib/utils'; | ||
import { TableFilterOption } from '@/types/helper'; | ||
import { CheckIcon } from '@radix-ui/react-icons'; | ||
import { ChevronDown } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import dappConfig from '@/dappRemark/config.json'; | ||
import { capitalize } from 'lodash-es'; | ||
import { DAppConfigKeys } from '@/utils'; | ||
|
||
interface TableDappFilterProps { | ||
value: DAppConfigKeys[]; | ||
onChange: (newValue: DAppConfigKeys[]) => void; | ||
title: React.ReactNode; | ||
onClearFilters?: () => void; | ||
buttonClassName?: string; | ||
contentClassName?: string; | ||
} | ||
|
||
const TableDappFilter = ({ | ||
value, | ||
onChange, | ||
title, | ||
onClearFilters, | ||
buttonClassName, | ||
contentClassName | ||
}: TableDappFilterProps) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
const options: TableFilterOption[] = Object.keys(dappConfig)?.map((dapp) => ({ | ||
label: capitalize(dapp), | ||
value: dapp | ||
})); | ||
|
||
const toggleItem = (itemValue: DAppConfigKeys) => { | ||
if (value.includes(itemValue)) { | ||
onChange(value.filter((s) => s !== itemValue)); | ||
} else { | ||
onChange([...value, itemValue]); | ||
} | ||
}; | ||
|
||
return ( | ||
<Popover onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
className={cn( | ||
'flex items-center gap-[0.31rem] border-none text-sm font-normal', | ||
buttonClassName | ||
)} | ||
> | ||
<span className="text-secondary-foreground">{title}:</span> | ||
<div className="flex items-center gap-[0.31rem]"> | ||
<SelectedLabels options={options} value={value} /> | ||
<ChevronDown | ||
size={16} | ||
strokeWidth={1.5} | ||
className={cn('transform transition-transform', open ? 'rotate-180' : 'rotate-0')} | ||
/> | ||
</div> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className={cn('p-0', contentClassName)} align="end"> | ||
<Command> | ||
<CommandList> | ||
<CommandGroup className="p-0"> | ||
{options.map(({ value: optionValue, label }) => { | ||
const isSelected = value.includes(optionValue as DAppConfigKeys); | ||
return ( | ||
<CommandItem | ||
key={optionValue} | ||
onSelect={() => toggleItem(optionValue as DAppConfigKeys)} | ||
className="cursor-pointer px-[1.25rem] py-[0.62rem]" | ||
> | ||
<div | ||
className={cn( | ||
'mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary', | ||
isSelected | ||
? 'bg-primary text-primary-foreground [&_svg]:visible' | ||
: 'opacity-50 [&_svg]:invisible' | ||
)} | ||
> | ||
<CheckIcon className={cn('h-4 w-4', isSelected ? 'visible' : 'invisible')} /> | ||
</div> | ||
<span | ||
className={cn( | ||
'text-sm', | ||
isSelected ? 'text-foreground' : 'text-secondary-foreground' | ||
)} | ||
> | ||
{label} | ||
</span> | ||
</CommandItem> | ||
); | ||
})} | ||
</CommandGroup> | ||
{value.length > 0 && ( | ||
<> | ||
<CommandGroup> | ||
<CommandItem | ||
onSelect={onClearFilters} | ||
className="cursor-pointer justify-center text-center text-sm text-secondary-foreground" | ||
> | ||
Clear filters | ||
</CommandItem> | ||
</CommandGroup> | ||
</> | ||
)} | ||
</CommandList> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default TableDappFilter; |
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
67 changes: 67 additions & 0 deletions
67
src/components/data-table/MobileFilterToolbar/TableDappFilter.tsx
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { cn } from '@/lib/utils'; | ||
import { TableFilterOption } from '@/types/helper'; | ||
import { DAppConfigKeys } from '@/utils'; | ||
import { CheckIcon } from '@radix-ui/react-icons'; | ||
|
||
interface TableDappFilterProps { | ||
value: DAppConfigKeys[]; | ||
options: TableFilterOption[]; | ||
onChange: (newValue: DAppConfigKeys[]) => void; | ||
onClearFilters?: () => void; | ||
} | ||
|
||
const TableDappFilter = ({ value, options, onChange, onClearFilters }: TableDappFilterProps) => { | ||
const toggleItem = (itemValue: DAppConfigKeys) => { | ||
if (value.includes(itemValue)) { | ||
onChange(value.filter((s) => s !== itemValue)); | ||
} else { | ||
onChange([...value, itemValue]); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="absolute left-0 top-0 w-[calc(100vw-3rem)] bg-background"> | ||
{options.map(({ value: optionValue, label }) => { | ||
const isSelected = value.includes(optionValue as DAppConfigKeys); | ||
return ( | ||
<div | ||
key={optionValue} | ||
onClick={() => toggleItem(optionValue as DAppConfigKeys)} | ||
className="flex items-center gap-2 py-[0.62rem]" | ||
> | ||
<div | ||
className={cn( | ||
'mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary', | ||
isSelected | ||
? 'bg-primary text-primary-foreground [&_svg]:visible' | ||
: 'opacity-50 [&_svg]:invisible' | ||
)} | ||
> | ||
<CheckIcon className={cn('h-4 w-4', isSelected ? 'visible' : 'invisible')} /> | ||
</div> | ||
<span | ||
className={cn( | ||
'text-sm', | ||
isSelected ? 'text-foreground' : 'text-secondary-foreground' | ||
)} | ||
> | ||
{label} | ||
</span> | ||
</div> | ||
); | ||
})} | ||
<Button | ||
size="sm" | ||
className="mt-5 w-full border-none bg-card px-0 text-sm font-normal text-foreground hover:bg-card/80 hover:text-foreground/80" | ||
onClick={onClearFilters} | ||
> | ||
Reset | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default TableDappFilter; |
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
Oops, something went wrong.