From f598f6ba7f2779b4cf7843f14e352ac6aea7c448 Mon Sep 17 00:00:00 2001 From: anth0nycodes Date: Sun, 22 Mar 2026 00:29:37 -0400 Subject: [PATCH] wip --- src/App.tsx | 16 ++-- src/components/popovers/frame-popover.tsx | 80 +++++++++++++++++++ src/components/toolbar.tsx | 8 +- src/context/frame-popover/PopoverProvider.tsx | 12 +++ src/context/frame-popover/constants.ts | 11 +++ .../frame-popover/use-frame-popover.ts | 14 ++++ 6 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 src/components/popovers/frame-popover.tsx create mode 100644 src/context/frame-popover/PopoverProvider.tsx create mode 100644 src/context/frame-popover/constants.ts create mode 100644 src/context/frame-popover/use-frame-popover.ts diff --git a/src/App.tsx b/src/App.tsx index fa7904a..5f7cb98 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import { Toolbar } from "@/components/toolbar"; import { ColorProvider } from "@/context/color/ColorContext"; import { EraserPopoverProvider } from "@/context/eraser-popover/PopoverProvider"; import { PencilPopoverProvider } from "@/context/pencil-popover/PopoverProvider"; +import { FramePopoverProvider } from "@/context/frame-popover/PopoverProvider"; import { TextPopoverProvider } from "@/context/text-popover/PopoverProvider"; export type ToolbarStates = @@ -23,11 +24,16 @@ export function App() { - - + + + + diff --git a/src/components/popovers/frame-popover.tsx b/src/components/popovers/frame-popover.tsx new file mode 100644 index 0000000..c2a3894 --- /dev/null +++ b/src/components/popovers/frame-popover.tsx @@ -0,0 +1,80 @@ +import { + Circle, + Diamond, + Square, + type LucideIcon, +} from "lucide-react"; +import { motion, useReducedMotion } from "motion/react"; +import type { FrameShape } from "@/context/frame-popover/constants"; +import { useFramePopover } from "@/context/frame-popover/use-frame-popover"; +import { Button } from "../ui/button"; + +interface PopoverItem { + icon: LucideIcon; + value: FrameShape; +} + +const popoverItems: PopoverItem[] = [ + { + icon: Square, + value: "square", + }, + { + icon: Circle, + value: "circle", + }, + { + icon: Diamond, + value: "diamond", + }, +]; + +export function FramePopover() { + const { frameShape, setFrameShape } = useFramePopover(); + const prefersReducedMotion = useReducedMotion(); + + return ( +
+ {popoverItems.map((item) => { + const isActive = frameShape === item.value; + + return ( + + ); + })} +
+ ); +} diff --git a/src/components/toolbar.tsx b/src/components/toolbar.tsx index cb0778a..7774279 100644 --- a/src/components/toolbar.tsx +++ b/src/components/toolbar.tsx @@ -18,6 +18,7 @@ import type { ToolbarStates } from "@/App"; import { ColorPicker } from "@/components/color-picker"; import { Line, type CustomIcon } from "@/components/custom-icons/icons"; import { EraserPopover } from "@/components/popovers/erase-popover"; +import { FramePopover } from "@/components/popovers/frame-popover"; import { PencilPopover } from "@/components/popovers/pencil-popover"; import { TextPopover } from "@/components/popovers/text-popover"; import { Button } from "@/components/ui/button"; @@ -53,7 +54,12 @@ const toolbarItems: ToolbarItemsRecord = { tooltipText: "Text", popover: , }, - Frame: { icon: Square, shortcut: "5", tooltipText: "Frame" }, + Frame: { + icon: Square, + shortcut: "5", + tooltipText: "Frame", + popover: , + }, Line: { icon: Line, shortcut: "6", tooltipText: "Line" }, } as const; diff --git a/src/context/frame-popover/PopoverProvider.tsx b/src/context/frame-popover/PopoverProvider.tsx new file mode 100644 index 0000000..6e15b05 --- /dev/null +++ b/src/context/frame-popover/PopoverProvider.tsx @@ -0,0 +1,12 @@ +import { useState, type ReactNode } from "react"; +import { FramePopoverContext, type FrameShape } from "./constants"; + +export function FramePopoverProvider({ children }: { children: ReactNode }) { + const [frameShape, setFrameShape] = useState("square"); + + return ( + + {children} + + ); +} diff --git a/src/context/frame-popover/constants.ts b/src/context/frame-popover/constants.ts new file mode 100644 index 0000000..1589608 --- /dev/null +++ b/src/context/frame-popover/constants.ts @@ -0,0 +1,11 @@ +import { createContext, type Dispatch, type SetStateAction } from "react"; + +export type FrameShape = "square" | "circle" | "diamond"; + +interface FramePopoverContextProps { + frameShape: FrameShape; + setFrameShape: Dispatch>; +} + +export const FramePopoverContext = + createContext(null); diff --git a/src/context/frame-popover/use-frame-popover.ts b/src/context/frame-popover/use-frame-popover.ts new file mode 100644 index 0000000..3506a73 --- /dev/null +++ b/src/context/frame-popover/use-frame-popover.ts @@ -0,0 +1,14 @@ +import { useContext } from "react"; +import { FramePopoverContext } from "./constants"; + +export function useFramePopover() { + const context = useContext(FramePopoverContext); + + if (!context) { + throw new Error( + "useFramePopover must be used within a FramePopoverProvider" + ); + } + + return context; +}