Skip to content

Commit af67f2e

Browse files
authored
Merge pull request #12 from PriDebnath/feat/add-bg
Feat/add bg
2 parents dec0f07 + 7a9ace8 commit af67f2e

4 files changed

Lines changed: 140 additions & 44 deletions

File tree

199 KB
Loading
132 KB
Loading
102 KB
Loading
Lines changed: 140 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,146 @@
1+
import { useState } from "react";
12
import {
23
Drawer,
34
DrawerClose,
45
DrawerContent,
5-
DrawerDescription,
6-
DrawerFooter,
7-
DrawerHeader,
8-
DrawerTitle,
96
DrawerTrigger,
10-
} from "@/components/ui/drawer"
11-
import { Button} from "@/components/ui/button"
12-
import { ArrowLeftIcon,Save, Shirt } from 'lucide-react'
13-
14-
export default function ChooseBackground (){
15-
let backgrounds = ["red", "blue", "yellow", "green"]
16-
return (
17-
<Drawer>
18-
<DrawerTrigger>
19-
<Button variant="outline" size="icon">
20-
<Shirt/>
7+
} from "@/components/ui/drawer";
8+
import { Button } from "@/components/ui/button";
9+
import { ArrowLeftIcon, Save, Shirt } from "lucide-react";
10+
11+
export default function ChooseBackground({ onApply } = {}) {
12+
// separate lists: textures and color/overlay presets
13+
const textures = [
14+
"src/assets/images/fresh-snow.png",
15+
"src/assets/images/dark-wood.png",
16+
"src/assets/images/cardboard.png",
17+
];
18+
19+
const colorPresets = [
20+
{ id: "red", color: "red" }, // solid color
21+
{ id: "sun", overlay: "linear-gradient(to right, #ff512f, #dd2476)" }, // gradient overlay
22+
{ id: "yellow", color: "yellow" },
23+
{ id: "blue", color: "blue" },
24+
{ id: "dark-fade", overlay: "linear-gradient(to bottom, rgba(0,0,0,0.2), rgba(0,0,0,0.6))" },
25+
];
26+
27+
// state
28+
const [selectedTexture, setSelectedTexture] = useState(textures[0]);
29+
const [selectedPreset, setSelectedPreset] = useState(colorPresets[0]);
30+
31+
// build inline style for preview & thumbnails that need composition
32+
const buildStyle = (texture, preset) => {
33+
return {
34+
backgroundImage: `${preset?.overlay ?? "none"}, ${texture ? `url(${texture})` : "none"}`,
35+
backgroundColor: preset?.color ?? undefined,
36+
backgroundSize: "cover",
37+
backgroundPosition: "center",
38+
};
39+
};
40+
41+
const apply = () => {
42+
const result = {
43+
image: selectedTexture,
44+
color: selectedPreset.color ?? undefined,
45+
overlay: selectedPreset.overlay ?? undefined,
46+
};
47+
if (typeof onApply === "function") onApply(result);
48+
};
49+
50+
return (
51+
<Drawer>
52+
<DrawerTrigger>
53+
<Button variant="outline" size="icon">
54+
<Shirt />
55+
</Button>
56+
</DrawerTrigger>
57+
58+
<DrawerContent className="p-4">
59+
{/* Top bar */}
60+
<div className="flex items-center justify-between ">
61+
<h3 className="w-full text-center text-lg font-medium p-4">Choose Background</h3>
62+
{/*
63+
<div className="flex items-center justify-center gap-2 p-4">
64+
<ArrowLeftIcon className="w-5 h-5" />
65+
</div>
66+
*/}
67+
{/*
68+
<div className="flex items-center gap-2">
69+
<DrawerClose>
70+
<Button variant="ghost">Close</Button>
71+
</DrawerClose>
72+
<Button onClick={apply} leftIcon={<Save />}>
73+
Apply
2174
</Button>
22-
</DrawerTrigger>
23-
<DrawerContent>
24-
{/*
25-
<DrawerHeader>
26-
<DrawerTitle>Are you absolutely sure?</DrawerTitle>
27-
<DrawerDescription>This action cannot be undone.</DrawerDescription>
28-
</DrawerHeader>
29-
<DrawerFooter>
30-
<Button>Submit</Button>
31-
<DrawerClose>
32-
<Button variant="outline">Cancel</Button>
33-
</DrawerClose>
34-
</DrawerFooter>
35-
*/}
36-
37-
<div className="flex flex-row gap-4 p-4 overflow-auto ">
38-
{backgrounds.map((bg, i) => (
39-
<div
40-
key={i}
41-
style={{ background: bg }}
42-
className="w-40 h-40 border rounded-lg flex-shrink-0"
43-
/>
44-
))}
45-
</div>
46-
47-
</DrawerContent>
48-
</Drawer>
49-
)
50-
}
75+
</div>
76+
*/}
77+
</div>
78+
79+
{/* Live preview */}
80+
<div className="w-full h-48 rounded-lg mb-4 overflow-hidden shadow">
81+
<div
82+
className="w-full h-full"
83+
style={buildStyle(selectedTexture, selectedPreset)}
84+
/>
85+
</div>
86+
87+
{/* Textures (images) */}
88+
<div className="mb-4">
89+
<h4 className="text-sm font-semibold mb-2">Textures</h4>
90+
<div className="flex gap-4 overflow-auto p-2">
91+
{textures.map((t) => (
92+
<button
93+
key={t}
94+
onClick={() => setSelectedTexture(t)}
95+
className={`w-28 h-20 rounded-lg flex-shrink-0 focus:outline-none ${
96+
selectedTexture === t ? "ring-2 ring-primary" : "border"
97+
}`}
98+
aria-pressed={selectedTexture === t}
99+
title={t}
100+
>
101+
<div
102+
className="w-full h-full rounded-lg"
103+
style={{
104+
backgroundImage: `url(${t})`,
105+
backgroundSize: "cover",
106+
backgroundPosition: "center",
107+
}}
108+
/>
109+
</button>
110+
))}
111+
</div>
112+
</div>
113+
114+
{/* Colors / Overlays */}
115+
<div>
116+
<h4 className="text-sm font-semibold mb-2">Colors & Overlays</h4>
117+
<div className="flex gap-4 overflow-auto p-2">
118+
{colorPresets.map((p) => {
119+
const isSelected = selectedPreset.id === p.id;
120+
return (
121+
<button
122+
key={p.id}
123+
onClick={() => setSelectedPreset(p)}
124+
className={`w-20 h-20 rounded-lg flex-shrink-0 p-0 relative focus:outline-none ${
125+
isSelected ? "ring-2 ring-primary" : "border"
126+
}`}
127+
aria-pressed={isSelected}
128+
title={p.id}
129+
>
130+
<div
131+
className="w-full h-full rounded-lg"
132+
style={{
133+
...(p.overlay
134+
? { backgroundImage: p.overlay, backgroundSize: "cover", backgroundPosition: "center" }
135+
: { backgroundColor: p.color }),
136+
}}
137+
/>
138+
</button>
139+
);
140+
})}
141+
</div>
142+
</div>
143+
</DrawerContent>
144+
</Drawer>
145+
);
146+
}

0 commit comments

Comments
 (0)