-
Notifications
You must be signed in to change notification settings - Fork 5
Cursor Preview, 프로필 수정 컴포넌트 구현 #274
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| import MousePointer from "@/icons/mousePointer"; | ||
|
|
||
| interface CursorButtonProps { | ||
| color: string; | ||
| } | ||
|
|
||
| export default function CursorButton({ color }: CursorButtonProps) { | ||
| return ( | ||
| <button className="flex h-9 w-9 items-center justify-center rounded-md hover:bg-[#F5F5F5]"> | ||
| <MousePointer fill={color} className="h-6 w-6" /> | ||
| </button> | ||
| ); | ||
| } |
42 changes: 42 additions & 0 deletions
42
apps/frontend/src/components/canvasTools/CursorPreview.tsx
This file contains hidden or 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,42 @@ | ||
| import { useState, useRef } from "react"; | ||
| import BiggerCursor from "@/components/cursor/BiggerCursor"; | ||
|
|
||
| interface CursorPreviewProps { | ||
| color: string; | ||
| clientId: string; | ||
| defaultCoors: { x: number; y: number }; | ||
| } | ||
|
|
||
| export default function CursorPreview({ | ||
| color, | ||
| clientId, | ||
| defaultCoors, | ||
| }: CursorPreviewProps) { | ||
| const [coors, setCoors] = useState(defaultCoors); | ||
| const previewRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const handleMouseMove = (e: React.MouseEvent) => { | ||
| if (previewRef.current) { | ||
| const rect = previewRef.current.getBoundingClientRect(); | ||
| setCoors({ | ||
| x: e.clientX - rect.left, | ||
| y: e.clientY - rect.top, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const handleMouseLeave = () => { | ||
| setCoors(defaultCoors); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| ref={previewRef} | ||
| onMouseMove={handleMouseMove} | ||
| onMouseLeave={handleMouseLeave} | ||
| className="relative h-48 w-60 overflow-hidden rounded-md border-[1px] border-[#d0d9e0] bg-white bg-[radial-gradient(#e5e7eb_1px,transparent_1px)] [background-size:7px_7px]" | ||
| > | ||
| <BiggerCursor coors={coors} clientId={clientId} color={color} /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,13 @@ | ||
| interface FormFieldProps { | ||
| label: string; | ||
| input: React.ReactNode; | ||
| } | ||
|
|
||
| export default function FormField({ label, input }: FormFieldProps) { | ||
| return ( | ||
| <div className="flex flex-col gap-1.5"> | ||
| <label className="font-medium text-[#433d3f]">{label}</label> | ||
| {input} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,91 @@ | ||
| import { RefreshCcw } from "lucide-react"; | ||
| import FormField from "./FormField"; | ||
| import useUserStore from "@/store/useUserStore"; | ||
| import { getRandomColor } from "@/lib/utils"; | ||
|
|
||
| interface ProfileFormProps { | ||
| color: string; | ||
| clientId: string; | ||
| onColorChange: (color: string) => void; | ||
| onClientIdChange: (clientId: string) => void; | ||
| onSave: () => void; | ||
| } | ||
|
|
||
| export default function ProfileForm({ | ||
| color, | ||
| clientId, | ||
| onColorChange, | ||
| onClientIdChange, | ||
| onSave, | ||
| }: ProfileFormProps) { | ||
| const { currentUser, setCurrentUser, provider } = useUserStore(); | ||
|
|
||
| const handleRefreshClick = () => { | ||
| const newColor = getRandomColor(); | ||
| onColorChange(newColor); | ||
| }; | ||
|
|
||
| const handleColorInput = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const isValidHex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/; | ||
| if (isValidHex.test(e.target.value)) { | ||
| onColorChange(e.target.value); | ||
| } | ||
| onColorChange(e.target.value); | ||
| }; | ||
|
|
||
| const handleSave = () => { | ||
| provider.awareness.setLocalStateField("color", color); | ||
| provider.awareness.setLocalStateField("clientId", clientId); | ||
|
|
||
| setCurrentUser({ | ||
| ...currentUser, | ||
| color, | ||
| clientId, | ||
| }); | ||
|
|
||
| onSave(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex w-36 flex-col justify-between"> | ||
| <div className="flex flex-col gap-2"> | ||
| <FormField | ||
| label="프로필" | ||
| input={ | ||
| <input | ||
| value={clientId} | ||
| onChange={(e) => onClientIdChange(e.target.value)} | ||
| className="h-8 rounded-md border-[1px] border-[#d0d9e0] bg-[#f5f6fa] px-2" | ||
| placeholder="닉네임을 입력하세요" | ||
| /> | ||
| } | ||
| /> | ||
| <FormField | ||
| label="색상" | ||
| input={ | ||
| <div className="flex flex-row gap-1.5 overflow-hidden"> | ||
| <button | ||
| onClick={handleRefreshClick} | ||
| style={{ backgroundColor: color }} | ||
| className="flex h-[32px] w-[32px] shrink-0 items-center justify-center rounded-sm transition-colors" | ||
| > | ||
| <RefreshCcw size={18} color="#464646" strokeWidth={2.2} /> | ||
| </button> | ||
| <input | ||
| value={color} | ||
| onChange={handleColorInput} | ||
| className="h-8 min-w-0 flex-1 rounded-md border-[1px] border-[#d0d9e0] bg-[#f5f6fa] px-2" | ||
| /> | ||
| </div> | ||
| } | ||
| /> | ||
| </div> | ||
| <button | ||
| onClick={handleSave} | ||
| className="self-end rounded-md bg-[#231f20] px-3.5 py-1.5 font-normal text-white" | ||
| > | ||
| 저장 | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,48 @@ | ||
| import { Plus } from "lucide-react"; | ||
| import { Popover } from "@/components/commons/popover"; | ||
| import CursorButton from "./CursorButton"; | ||
| import CursorPreview from "./CursorPreview"; | ||
| import ProfileForm from "./ProfileForm"; | ||
| import useUserStore from "@/store/useUserStore"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| export default function CanvasTools() { | ||
| const { currentUser } = useUserStore(); | ||
| const [color, setColor] = useState(currentUser.color); | ||
| const [clientId, setClientId] = useState(currentUser.clientId); | ||
|
|
||
| useEffect(() => { | ||
| setColor(currentUser.color); | ||
| setClientId(currentUser.clientId); | ||
| }, [currentUser]); | ||
|
|
||
| return ( | ||
| <div className="z-10 flex flex-row rounded-xl border-[1px] border-neutral-200 bg-white p-1.5 text-black shadow-md"> | ||
| <Popover placement="bottom" align="start" offset={{ x: -6, y: 16 }}> | ||
| <Popover.Trigger> | ||
| <CursorButton color={color} /> | ||
| </Popover.Trigger> | ||
| <Popover.Content className="rounded-lg border border-neutral-200 bg-white p-2 shadow-md"> | ||
| <div className="flex flex-row gap-4 p-4"> | ||
| <CursorPreview | ||
| defaultCoors={{ x: 90, y: 80 }} | ||
| clientId={clientId} | ||
| color={color} | ||
| /> | ||
| <ProfileForm | ||
| color={color} | ||
| clientId={clientId} | ||
| onColorChange={setColor} | ||
| onClientIdChange={setClientId} | ||
| onSave={() => {}} | ||
| /> | ||
| </div> | ||
| </Popover.Content> | ||
| </Popover> | ||
|
|
||
| <button className="flex h-9 w-9 items-center justify-center rounded-md hover:bg-[#F5F5F5]"> | ||
| <Plus size={26} color="#3f3f3f" strokeWidth={1.5} /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,57 @@ | ||
| import { motion } from "framer-motion"; | ||
|
|
||
| export interface Coors { | ||
| x: number; | ||
| y: number; | ||
| } | ||
|
|
||
| interface CursorProps { | ||
| coors: Coors; | ||
| clientId: string; | ||
| color?: string; | ||
| } | ||
|
|
||
| export default function BiggerCursor({ | ||
| coors, | ||
| color = "#ffb8b9", | ||
| clientId, | ||
| }: CursorProps) { | ||
| const { x, y } = coors; | ||
|
|
||
| return ( | ||
| <motion.div | ||
| className="pointer-events-none absolute left-0 top-0 z-50" | ||
| initial={{ x, y }} | ||
| animate={{ x, y }} | ||
| transition={{ | ||
| type: "spring", | ||
| bounce: 0.6, | ||
| damping: 30, | ||
| mass: 0.8, | ||
| stiffness: 350, | ||
| restSpeed: 0.01, | ||
| }} | ||
| > | ||
| <div className="relative"> | ||
| <svg | ||
| width="27" | ||
| height="27" | ||
| viewBox="0 0 27 27" | ||
| fill={color} | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M2.701 0.771174L24.8693 8.80848C26.1506 9.27302 26.1985 11.064 24.9439 11.5962L16.9292 14.9958C16.3473 15.2426 15.8806 15.7 15.6229 16.2762L11.704 25.0374C11.1542 26.2666 9.38566 26.2051 8.92279 24.9408L0.778147 2.69403C0.340278 1.498 1.50186 0.336418 2.701 0.771174Z" | ||
| stroke="black" | ||
| /> | ||
| </svg> | ||
| <div | ||
| className="absolute left-6 top-6 max-w-28 truncate rounded-md border-[1px] border-black px-2 py-1 text-center text-sm font-semibold shadow-sm" | ||
| style={{ backgroundColor: color }} | ||
| > | ||
| {clientId} | ||
| </div> | ||
| </div> | ||
| </motion.div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| interface MousePointerProps { | ||
| fill?: string; | ||
| className?: string; | ||
| } | ||
| export default function MousePointer({ fill, className }: MousePointerProps) { | ||
| return ( | ||
| <svg | ||
| width="22" | ||
| height="22" | ||
| viewBox="0 0 22 22" | ||
| fill="none" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| className={className} | ||
| > | ||
| <g clip-path="url(#clip0_570_13)"> | ||
| <path | ||
| d="M5.65655 3.8599L18.6378 8.63731C19.9139 9.10697 19.9565 10.9034 18.704 11.4334L14.652 13.1481C14.0711 13.3939 13.6044 13.8514 13.3458 14.4285L11.2629 19.0757C10.7112 20.3068 8.94797 20.24 8.49015 18.9707L3.73369 5.78276C3.3006 4.58195 4.4622 3.42035 5.65655 3.8599Z" | ||
| stroke="black" | ||
| fill={fill} | ||
| /> | ||
| </g> | ||
| <defs> | ||
| <clipPath id="clip0_570_13"> | ||
| <rect | ||
| width="18" | ||
| height="18" | ||
| fill="white" | ||
| transform="translate(3 3)" | ||
| /> | ||
| </clipPath> | ||
| </defs> | ||
| </svg> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거에요!