Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add icons search to create module popover #383

Merged
merged 2 commits into from
Sep 7, 2024
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
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ words:
- Upstash
- healthcheck
- timeago
- usehooks
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"tailwind-merge": "^2.5.2",
"timeago.js": "^4.0.2",
"use-resize-observer": "^9.1.0",
"usehooks-ts": "^3.1.0",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
67 changes: 49 additions & 18 deletions src/app/(dashboard)/app/_components/create-module-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { api } from '@/lib/trpc/react';
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';
import { Textarea } from '@/primitives/textarea';

import { useDebounceValue } from 'usehooks-ts';
interface StepHeadingProps {
title: string;
description: string;
Expand All @@ -46,6 +46,48 @@ const StepHeading = ({ title, description }: StepHeadingProps) => {
);
};

interface IconPickerProps {
iconOnClickHandler: (icon: IconNames) => void;
}

export function IconPicker({ iconOnClickHandler }: IconPickerProps) {
const [iconSearchTerm, setIconSearchTerm] = useDebounceValue('', 200);

return (
<>
<Input
type="text"
placeholder="Search icons..."
onChange={(e) => {
setIconSearchTerm(e.target.value);
}}
/>
<ScrollArea className="mt-2 h-[300px]">
<div className="mt-2 grid grid-cols-6 gap-2">
{iconNames
.filter((icon) =>
iconSearchTerm === ''
? true
: icon.toLowerCase().includes(iconSearchTerm.toLowerCase()),
)
.map((icon) => (
<button
type="button"
key={icon}
className="grid place-items-center rounded-lg p-2 text-foreground transition-colors hover:bg-gray-element"
onClick={() => {
iconOnClickHandler(icon);
}}
>
<Icon name={icon} size={20} strokeWidth={1.5} />
</button>
))}
</div>
</ScrollArea>
</>
);
}

const formSchema = z.object({
name: z.string().min(2),
description: z.string().optional(),
Expand Down Expand Up @@ -286,23 +328,12 @@ export function CreateModulePopover() {
title="Select an icon"
description="You can select an icon for your module to make it easier to identify."
/>
<ScrollArea className="h-[300px]">
<div className="mt-2 grid grid-cols-6 gap-2">
{iconNames.map((icon) => (
<button
type="button"
key={icon}
className="grid place-items-center rounded-lg p-2 text-foreground transition-colors hover:bg-gray-element"
onClick={() => {
form.setValue('icon', icon);
setStep(1);
}}
>
<Icon name={icon} size={20} strokeWidth={1.5} />
</button>
))}
</div>
</ScrollArea>
<IconPicker
iconOnClickHandler={(icon) => {
form.setValue('icon', icon);
setStep(1);
}}
/>
</div>
)}

Expand Down
Loading