Skip to content

Commit

Permalink
feat:added customizable filter button
Browse files Browse the repository at this point in the history
  • Loading branch information
ssikande committed Jul 29, 2024
1 parent 767690f commit 3600ce8
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function DisableButton({ isDisabling, handleClick }: DisableButto
return (
<Button
className={cn(
'pr-h-8 pr-rounded-md pr-bg-gray-300 pr-text-black pr-transition pr-duration-300 pr-ease-in-out hover:pr-text-white',
'pr-h-8 pr-rounded-md pr-bg-gray-300 pr-text-black pr-transition pr-duration-300 pr-ease-in-out hover:pr-bg-gray-400',
{
'pr-cursor-not-allowed pr-bg-gray-400': isDisabling,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function EnableButton({ isEnabling, handleClick }: EnableButtonPr
return (
<Button
className={cn(
'pr-h-8 pr-rounded-md pr-bg-blue-600 pr-px-4 pr-text-white pr-transition pr-duration-300 pr-ease-in-out hover:pr-text-white',
'pr-h-8 pr-rounded-md pr-bg-blue-600 pr-px-4 pr-text-white pr-transition pr-duration-300 pr-ease-in-out hover:pr-bg-blue-700',
{
'pr-cursor-not-allowed pr-bg-blue-700': isEnabling,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Filter, ChevronDown } from 'lucide-react';
import { forwardRef } from 'react';
import { Button } from '@/components/shadcn-ui/button';

/**
* The FilterButton component is a button designed for initiating filtering of data. It includes
* dropdown visuals for active filtering and idle states. it uses forwardRef to pass the button to the
* dropdown trigger asChild.
*
* @returns A button that can be used to filter.
*/
const FilterButton = forwardRef<HTMLButtonElement>((props, ref) => {
return (
<Button
ref={ref}
className="pr-rounded-md pr-border pr-border-dashed pr-border-gray-400 pr-bg-white pr-px-4 pr-py-2 pr-text-black pr-transition pr-duration-300 pr-ease-in-out hover:pr-text-white"
{...props}
>
<Filter size={16} className="pr-mr-2 pr-h-4 pr-w-4 pr-text-gray-700" />
Filter
<ChevronDown size={16} className="pr-ml-2 pr-h-4 pr-w-4 pr-text-gray-700" />
</Button>
);
});

export default FilterButton;
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export default function InstallButton({
return (
<Button
className={cn(
'pr-h-8 pr-rounded-md pr-text-white pr-transition pr-duration-300 pr-ease-in-out',
'pr-h-8 pr-rounded-md pr-text-white pr-transition pr-duration-300 pr-ease-in-out hover:pr-bg-blue-700',
{
'pr-cursor-not-allowed pr-bg-blue-700': isInstalling,
'pr-bg-blue-600': !isInstalling,
'pr-bg-white pr-text-blue-600': !buttonText,
'pr-bg-white pr-text-blue-600 hover:pr-text-white': !buttonText,
'pr-w-20': buttonText,
},
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function UpdateButton({ isUpdating, handleClick }: UpdateButtonPr
return (
<Button
className={cn(
'pr-h-8 pr-rounded-md pr-bg-blue-600 pr-px-4 pr-text-white pr-transition pr-duration-300 pr-ease-in-out hover:pr-text-white',
'pr-h-8 pr-rounded-md pr-bg-blue-600 pr-px-4 pr-text-white pr-transition pr-duration-300 pr-ease-in-out hover:pr-text-white hover:pr-bg-blue-700',
{
'pr-cursor-not-allowed pr-bg-blue-700': isUpdating,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuGroup,
DropdownMenuCheckboxItem,
DropdownMenuRadioItem,
DropdownMenuSeparator,
} from '@/components/shadcn-ui/dropdown-menu';
import FilterButton from './buttons/filter-button.component';

interface DropdownItem {
/**
* The label is the text that will be displayed on the dropdown item.
*/
label: string;
/**
* The checkbox boolean value determines if the item is a checkbox or radio
* item.
*/
checkbox: boolean;
/**
* The onClick function is called when the item is clicked.
*/
onClick: () => void;
}

interface DropdownGroup {
/**
* The label is the text that will be displayed on the dropdown group.
* It is used to categorize the items in the group.
*/
label: string;
/**
* The items array contains the items that will be displayed in the dropdown
* group
*/
items: DropdownItem[];
}

interface FilterDropdownProps {
/**
* The groups array contains the groups that will be displayed in the
* dropdown
*/
groups: DropdownGroup[];
}

/**
* The FilterDropdown component is a dropdown designed for filtering content.
* It includes groups of items that can be checkboxes or radio items.
*
* @param groups The groups array contains the groups that will be displayed in the dropdown
* @returns A filter dropdown.
*/
export default function FilterDropdown({ groups }: FilterDropdownProps) {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<FilterButton />
</DropdownMenuTrigger>
<DropdownMenuContent>
{groups.map((group) => (
<>
<DropdownMenuLabel>{group.label}</DropdownMenuLabel>
<DropdownMenuGroup>
{group.items.map((item) => (
<div>
{item.checkbox ? (
<DropdownMenuCheckboxItem onClick={item.onClick}>
{item.label}
</DropdownMenuCheckboxItem>
) : (
<DropdownMenuRadioItem onClick={item.onClick} value={item.label}>
{item.label}
</DropdownMenuRadioItem>
)}
</div>
))}
</DropdownMenuGroup>
<DropdownMenuSeparator />
</>
))}
</DropdownMenuContent>
</DropdownMenu>
);
}
4 changes: 3 additions & 1 deletion lib/platform-bible-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Filter } from 'lucide-react';
import './index.css';

// Components and Types
Expand Down Expand Up @@ -74,13 +75,14 @@ export {
} from './components/basics/tabs-vertical';

// Paratext components

export { default as CharacterInventory } from './components/paratext-10-studio-components/inventory/character-inventory.component';
export { default as InstallButton } from './components/advanced-components/extension-marketplace/buttons/install-button.component';
export { default as EnableButton } from './components/advanced-components/extension-marketplace/buttons/enable-button.component';
export { default as DisableButton } from './components/advanced-components/extension-marketplace/buttons/disable-button.component';
export { default as UpdateButton } from './components/advanced-components/extension-marketplace/buttons/update-button.component';
export { default as MarkdownRenderer } from './components/advanced-components/extension-marketplace/markdown-renderer.component';
export { default as FilterDropdown } from './components/advanced-components/extension-marketplace/filter-dropdown.component';
export { default as FilterButton } from './components/advanced-components/extension-marketplace/buttons/filter-button.component';

// Hooks
export { default as useEvent } from './hooks/use-event.hook';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ import InstallButton from '@/components/advanced-components/extension-marketplac
import DisableButton from '@/components/advanced-components/extension-marketplace/buttons/disable-button.component';
import UpdateButton from '@/components/advanced-components/extension-marketplace/buttons/update-button.component';
import EnableButton from '@/components/advanced-components/extension-marketplace/buttons/enable-button.component';
import FilterDropdown from '@/components/advanced-components/extension-marketplace/filter-dropdown.component';

export default function MarketplaceButtonExamples() {
const filterItems = ['All', 'Verified', 'Experimental'];

const filterGroup = {
label: 'Publishers',
items: [
...filterItems.map((items) => ({
label: items,
checkbox: true,
onClick: () => {},
})),
],
};

const sortGroup = {
label: 'Sort by',
items: [
{ label: 'Release Date (Newest First)', checkbox: false, onClick: () => {} },
{ label: 'Name A-Z', checkbox: false, onClick: () => {} },
],
};
return (
<>
<p>
Note: These buttons are currently styled with fixed colors and are therefore not themeable
Note: These buttons are currently styled with fixed colors and are therefore not theme-able
</p>
<br />
InstallButton Button:
Expand All @@ -32,6 +53,10 @@ export default function MarketplaceButtonExamples() {
<UpdateButton isUpdating={false} handleClick={() => {}} />
<UpdateButton isUpdating handleClick={() => {}} />
</div>
FilterButton Button:
<div className="pr-space-x-2">
<FilterDropdown groups={[filterGroup, sortGroup]} />
</div>
</>
);
}

0 comments on commit 3600ce8

Please sign in to comment.