|
1 | | -import { useState } from "react"; |
2 | 1 | import { |
3 | 2 | Drawer, |
| 3 | + DrawerTitle, |
4 | 4 | DrawerClose, |
5 | | - DrawerContent, |
6 | | - DrawerDescription, |
7 | 5 | DrawerHeader, |
8 | | - DrawerTitle, |
| 6 | + DrawerContent, |
9 | 7 | DrawerTrigger, |
| 8 | + DrawerDescription, |
10 | 9 | } from "@/components/ui/drawer"; |
| 10 | +import { useState } from "react"; |
11 | 11 | import { Button } from "@/components/ui/button"; |
12 | | -import useBackground, { type Pri_set, type TextureKey } from "@/hook/use-background.hook"; |
| 12 | +import type { QuoteFormData } from "@/model/quote.model"; |
13 | 13 | import { ArrowLeftIcon, Save, Shirt } from "lucide-react"; |
| 14 | +import useBackground, { type Pri_set, type TextureKey } from "@/hook/use-background.hook"; |
14 | 15 |
|
15 | | -export default function ChooseBackground() { |
| 16 | +interface Props { |
| 17 | + onValueUpdate: (key: keyof QuoteFormData, value: string) => void |
| 18 | +} |
16 | 19 |
|
| 20 | +export default function ChooseBackground(props: Props) { |
| 21 | + const { onValueUpdate} = props |
17 | 22 | const { textures, colorPresets, buildStyle } = useBackground() |
18 | | - |
19 | 23 | const [selectedTexture, setSelectedTexture] = useState<TextureKey> ( "cardboard"); |
20 | 24 | const [selectedPreset, setSelectedPreset] = useState<Pri_set>('pri_set_1'); |
21 | 25 |
|
22 | | - const apply = () => { |
23 | | - // const result = { |
24 | | - // image: selectedTexture, |
25 | | - // color: selectedPreset.color ?? undefined, |
26 | | - // overlay: selectedPreset.overlay ?? undefined, |
27 | | - // }; |
28 | | - }; |
| 26 | + const handleTextureClick = (key: TextureKey)=>{ |
| 27 | + setSelectedTexture(key) |
| 28 | + onValueUpdate("texture", key) |
| 29 | + } |
| 30 | + |
| 31 | + const handlePriSetClick = (pri: Pri_set)=>{ |
| 32 | + setSelectedPreset(pri) |
| 33 | + onValueUpdate("pri_set", pri) |
| 34 | + } |
29 | 35 |
|
30 | 36 | return ( |
31 | 37 | <Drawer |
@@ -79,7 +85,7 @@ export default function ChooseBackground() { |
79 | 85 | return ( |
80 | 86 | <button |
81 | 87 | key={ key} |
82 | | - onClick={() => setSelectedTexture(key as TextureKey)} |
| 88 | + onClick={() => handleTextureClick(key as TextureKey)} |
83 | 89 | className={`w-28 h-20 rounded-lg shrink-0 focus:outline-none ${selectedTexture === key ? "ring-2 ring-primary" : "border" |
84 | 90 | }`} |
85 | 91 | aria-pressed={selectedTexture === key} |
@@ -110,7 +116,7 @@ export default function ChooseBackground() { |
110 | 116 | return ( |
111 | 117 | <button |
112 | 118 | key={key} |
113 | | - onClick={() => setSelectedPreset(key as Pri_set)} |
| 119 | + onClick={() => handlePriSetClick(key as Pri_set)} |
114 | 120 | className={`w-20 h-20 rounded-lg shrink-0 p-0 relative focus:outline-none ${isSelected ? "ring-2 ring-primary" : "border" |
115 | 121 | }`} |
116 | 122 | aria-pressed={isSelected} |
|
0 commit comments