Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
category filter
Browse files Browse the repository at this point in the history
  • Loading branch information
snrondina committed Oct 23, 2024
1 parent 8c0c249 commit 39e939b
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 17 deletions.
7 changes: 6 additions & 1 deletion apps/web/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;

--secondary: 210 40% 96.1%;
--secondary: #ffffff;
--secondary-foreground: 222.2 47.4% 11.2%;

--accent: 210 40% 96.1%;
Expand All @@ -42,6 +42,11 @@

--button: #8a5df6;
--button-foreground: #ffffff;
--button-hover: #a082e9;
--button-stroke: #6947bb;
--button-secondary: #ffffff;
--button-secondary-stroke: #e6e6e6;
--button-secondary-hover: #efefef;
}

.dark {
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/tailwind.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"build": "run-s build:*",
"build:css": "tailwindcss -i ./app/global.css -o ./app/tailwind.css --minify",
"build:migration": "if [ \"$VERCEL_ENV\" = production ] || [ \"$VERCEL_GIT_COMMIT_REF\" = main ]; then pnpm --dir ../../ migration up; else echo 'Skip non prod/staging migration'; fi",
"build:next": "next build",
"codegen:supabase": "supabase gen types typescript --linked --schema public > ./supabase/supabase.gen.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export default {
button: {
DEFAULT: 'var(--button)',
foreground: 'var(--button-foreground)',
hover: 'var(--button-hover)',
stroke: 'var(--button-stroke)',
},
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
Expand All @@ -95,7 +97,7 @@ export default {
foreground: 'hsl(var(--primary-foreground))',
},
secondary: {
DEFAULT: 'hsl(var(--secondary))',
DEFAULT: 'var(--secondary)',
foreground: 'hsl(var(--secondary-foreground))',
},
destructive: {
Expand Down
8 changes: 1 addition & 7 deletions packages/ui/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// import '../../../apps/web/app/global.css'

if (typeof document !== 'undefined') {
const script = document.createElement('script')
script.src = 'https://cdn.tailwindcss.com'
document.head.appendChild(script)
}
import '../../../apps/web/app/tailwind.css'

/** @type { import('@storybook/react').Preview } */
const preview = {
Expand Down
97 changes: 97 additions & 0 deletions packages/ui/components/CheckboxFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {Component} from 'lucide-react'
import {useState} from 'react'
import {Button} from '../shadcn/Button'
import {Checkbox} from '../shadcn/Checkbox'
import {Popover, PopoverContent, PopoverTrigger} from '../shadcn/Popover'

export function CheckboxFilter({
options,
onApply,
}: {
options: string[]
onApply: () => void
}) {
const [checkedState, setCheckedState] = useState<Record<string, boolean>>(
options.reduce(
(acc, option) => {
acc[option] = false
return acc
},
{} as Record<string, boolean>,
),
)

// Handle checkbox change
const handleCheckboxChange = (id: string) => {
setCheckedState((prevState) => ({
...prevState,
[id]: !prevState[id],
}))
}

return (
<Popover>
<PopoverTrigger asChild>
<Button variant="secondary">
<Component className="h-4 w-4" style={{color: '#8A5DF6'}} />{' '}
<span className="ml-2">Category</span>
</Button>
</PopoverTrigger>
<PopoverContent className="w-40 bg-white">
<div className="flex flex-col gap-2">
{options.map((option) => (
<div
key={option}
className="flex w-full cursor-pointer items-center justify-start space-x-2"
onClick={() => handleCheckboxChange(option)}>
<Checkbox
id={option}
checked={checkedState[option]}
onCheckedChange={() => handleCheckboxChange(option)}
className={`rounded-sm border border-gray-300 transition-colors duration-200 ${
checkedState[option]
? 'border-transparent bg-[#8A7DFF]'
: 'hover:bg-[#F6F6F6]'
}`}>
{/* Custom checkmark */}
<span
className={`block h-4 w-4 rounded-sm ${
checkedState[option]
? 'bg-[#8A7DFF] text-white'
: 'bg-transparent'
}`}>
{checkedState[option] && (
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-4 w-4 text-white"
viewBox="0 0 20 20"
fill="currentColor">
<path
fillRule="evenodd"
d="M6.293 9.293a1 1 0 011.414 0L10 11.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z"
clipRule="evenodd"
/>
</svg>
)}
</span>
</Checkbox>
<label
htmlFor={option}
className="cursor-pointer text-sm font-semibold">
{' '}
{option}
</label>
</div>
))}
{/* Added a visible divider here */}
<div className="my-2 w-full border-t border-[#E6E6E6]" />
<div className="col-span-3 flex justify-end">
<Button onClick={onApply} size="sm">
Apply
</Button>
</div>
</div>
</PopoverContent>
</Popover>
)
}
11 changes: 6 additions & 5 deletions packages/ui/shadcn/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import React from 'react'
import {cn} from '../utils'

const buttonVariants = cva(
'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background',
'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background',
{
variants: {
variant: {
default: 'text-primary-foreground bg-[#8A5DF6] hover:bg-[#A082E9]',
default:
'text-button-foreground bg-button hover:bg-button-hover border-button-stroke border',
destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
outline:
'border border-input hover:bg-accent hover:text-accent-foreground',
secondary:
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
'bg-button-secondary text-secondary-foreground hover:bg-button-secondary-hover border-button-secondary-stroke border',
ghost: 'hover:bg-accent hover:text-accent-foreground',
link: 'underline-offset-4 hover:underline text-primary',
},
size: {
default: 'h-10 py-2 px-4',
sm: 'h-9 px-3 rounded-md',
lg: 'h-11 px-8 rounded-md',
sm: 'h-8 px-4 rounded-md',
lg: 'h-12 px-10 rounded-md',
},
},
defaultVariants: {
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/shadcn/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
import {Check} from 'lucide-react'
import * as React from 'react'

import {cn} from '../utils'

const Checkbox = React.forwardRef<
Expand All @@ -13,7 +12,7 @@ const Checkbox = React.forwardRef<
<CheckboxPrimitive.Root
ref={ref}
className={cn(
'peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground',
'peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-button data-[state=checked]:text-primary-foreground',
className,
)}
{...props}>
Expand Down
16 changes: 15 additions & 1 deletion packages/ui/stories/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,24 @@ export default {
}

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary = {
export const Default = {
args: {
'aria-label': 'Copy to clipboard',
variant: 'default',
size: 'default',
},
}
export const Primary = {
args: {
'aria-label': 'Copy to clipboard',
variant: 'primary',
size: 'default',
},
}
export const Secondary = {
args: {
'aria-label': 'Copy to clipboard',
variant: 'secondary',
size: 'default',
},
}
27 changes: 27 additions & 0 deletions packages/ui/stories/CheckboxFilter.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {fn} from '@storybook/test'
import {CheckboxFilter} from '../components/CheckboxFilter'

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
title: 'Example/CheckboxFilter',
component: CheckboxFilter,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: {control: 'color'},
},
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
args: {onApply: fn()},
}

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary = {
args: {
options: ['Accounting', 'ATS', 'Banking', 'Database'],
},
}

0 comments on commit 39e939b

Please sign in to comment.