phungtuan commited on
Commit
7fc6598
·
1 Parent(s): 867b630

raised caption z index

Browse files
components/builder/config/ImageGallery.tsx CHANGED
@@ -1,11 +1,125 @@
 
1
  import { Input } from "@heroui/input";
2
  import { Select, SelectItem } from "@heroui/select";
3
  import { Button } from "@heroui/button";
4
- import { X, Plus } from "lucide-react";
5
 
 
6
  import { BaseComponentConfigProps } from "@/types/shop-components";
7
  import { ImageGalleryConfig as ImageGalleryConfigType } from "@/types/shop";
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  export default function ImageGallery({
10
  config,
11
  onUpdate,
@@ -13,7 +127,7 @@ export default function ImageGallery({
13
  const images = config.images || [];
14
 
15
  const handleAddImage = () => {
16
- const newImages = [...images, { url: "", alt: "" }];
17
 
18
  onUpdate("images", newImages);
19
  };
@@ -78,38 +192,13 @@ export default function ImageGallery({
78
 
79
  <div className="space-y-4">
80
  {images.map((image: any, index: number) => (
81
- <div
82
  key={index}
83
- className="p-3 bg-default-100 rounded-lg space-y-2 relative group"
84
- >
85
- <Button
86
- isIconOnly
87
- className="absolute -top-2 -right-2 opacity-0 group-hover:opacity-100 transition-opacity"
88
- color="danger"
89
- size="sm"
90
- variant="light"
91
- onPress={() => handleRemoveImage(index)}
92
- >
93
- <X className="w-4 h-4" />
94
- </Button>
95
-
96
- <Input
97
- label="Image URL"
98
- size="sm"
99
- value={image.url}
100
- onValueChange={(value) =>
101
- handleUpdateImage(index, "url", value)
102
- }
103
- />
104
- <Input
105
- label="Alt Text"
106
- size="sm"
107
- value={image.alt}
108
- onValueChange={(value) =>
109
- handleUpdateImage(index, "alt", value)
110
- }
111
- />
112
- </div>
113
  ))}
114
  </div>
115
  </div>
 
1
+ import { useRef } from "react";
2
  import { Input } from "@heroui/input";
3
  import { Select, SelectItem } from "@heroui/select";
4
  import { Button } from "@heroui/button";
5
+ import { X, Plus, Upload, Loader2, Image as ImageIcon } from "lucide-react";
6
 
7
+ import { useCloudinaryUpload } from "@/hooks/use-cloudinary-upload";
8
  import { BaseComponentConfigProps } from "@/types/shop-components";
9
  import { ImageGalleryConfig as ImageGalleryConfigType } from "@/types/shop";
10
 
11
+ interface GalleryImageProps {
12
+ image: { url: string; alt: string; caption?: string };
13
+ index: number;
14
+ onUpdate: (index: number, field: string, value: string) => void;
15
+ onRemove: (index: number) => void;
16
+ }
17
+
18
+ function GalleryImageRow({
19
+ image,
20
+ index,
21
+ onUpdate,
22
+ onRemove,
23
+ }: GalleryImageProps) {
24
+ const { upload, isUploading } = useCloudinaryUpload();
25
+ const fileInputRef = useRef<HTMLInputElement>(null);
26
+
27
+ const handleUploadClick = () => {
28
+ fileInputRef.current?.click();
29
+ };
30
+
31
+ const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
32
+ const file = e.target.files?.[0];
33
+
34
+ if (!file) return;
35
+
36
+ try {
37
+ const result = await upload(file);
38
+
39
+ if (result) {
40
+ onUpdate(index, "url", result.url);
41
+ }
42
+ } catch (error) {
43
+ console.error("Upload failed:", error);
44
+ } finally {
45
+ // Reset input so same file can be selected again if needed
46
+ if (fileInputRef.current) {
47
+ fileInputRef.current.value = "";
48
+ }
49
+ }
50
+ };
51
+
52
+ return (
53
+ <div className="p-3 bg-default-100 rounded-lg space-y-3 relative group">
54
+ <input
55
+ ref={fileInputRef}
56
+ accept="image/*"
57
+ className="hidden"
58
+ type="file"
59
+ onChange={handleFileChange}
60
+ />
61
+
62
+ <div className="flex items-start justify-between gap-2">
63
+ <h4 className="text-xs font-semibold text-default-500 uppercase mt-1">
64
+ Image {index + 1}
65
+ </h4>
66
+ <Button
67
+ isIconOnly
68
+ className="opacity-0 group-hover:opacity-100 transition-opacity h-6 w-6 min-w-6"
69
+ color="danger"
70
+ size="sm"
71
+ variant="light"
72
+ onPress={() => onRemove(index)}
73
+ >
74
+ <X className="w-3 h-3" />
75
+ </Button>
76
+ </div>
77
+
78
+ <div className="flex gap-2">
79
+ <Input
80
+ className="flex-1"
81
+ label="Image URL"
82
+ placeholder="https://..."
83
+ size="sm"
84
+ startContent={
85
+ <ImageIcon className="w-3 h-3 text-default-400 pointer-events-none flex-shrink-0" />
86
+ }
87
+ value={image.url}
88
+ onValueChange={(value) => onUpdate(index, "url", value)}
89
+ />
90
+ <Button
91
+ isIconOnly
92
+ isLoading={isUploading}
93
+ className="h-full aspect-square"
94
+ color="primary"
95
+ title="Upload Image"
96
+ variant="flat"
97
+ onPress={handleUploadClick}
98
+ >
99
+ {!isUploading && <Upload className="w-4 h-4" />}
100
+ </Button>
101
+ </div>
102
+
103
+ <div className="grid grid-cols-2 gap-2">
104
+ <Input
105
+ label="Alt Text"
106
+ placeholder="Description"
107
+ size="sm"
108
+ value={image.alt}
109
+ onValueChange={(value) => onUpdate(index, "alt", value)}
110
+ />
111
+ <Input
112
+ label="Caption (Optional)"
113
+ placeholder="Caption"
114
+ size="sm"
115
+ value={image.caption || ""}
116
+ onValueChange={(value) => onUpdate(index, "caption", value)}
117
+ />
118
+ </div>
119
+ </div>
120
+ );
121
+ }
122
+
123
  export default function ImageGallery({
124
  config,
125
  onUpdate,
 
127
  const images = config.images || [];
128
 
129
  const handleAddImage = () => {
130
+ const newImages = [...images, { url: "", alt: "", caption: "" }];
131
 
132
  onUpdate("images", newImages);
133
  };
 
192
 
193
  <div className="space-y-4">
194
  {images.map((image: any, index: number) => (
195
+ <GalleryImageRow
196
  key={index}
197
+ image={image}
198
+ index={index}
199
+ onRemove={handleRemoveImage}
200
+ onUpdate={handleUpdateImage}
201
+ />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  ))}
203
  </div>
204
  </div>
components/shop/components/ImageGallery.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use client";
2
 
3
- import { Image as HeroUIImage } from "@heroui/image";
4
 
5
  import { ImageGalleryConfig } from "@/types/shop";
6
  import { BaseComponentProps } from "@/types/shop-components";
@@ -37,17 +37,18 @@ export default function ImageGallery({
37
  {images.map((image, index) => (
38
  <div
39
  key={index}
40
- className={`relative overflow-hidden ${aspectClasses}`}
41
  >
42
- <HeroUIImage
43
  alt={image.alt}
44
- className="w-full h-full object-cover hover:scale-105 transition-transform duration-300"
45
  height="100%"
46
- src={image.url}
47
  width="100%"
 
48
  />
49
  {image.caption && (
50
- <div className="absolute bottom-0 left-0 right-0 bg-black/60 text-white p-3">
51
  <p className="text-sm">{image.caption}</p>
52
  </div>
53
  )}
 
1
  "use client";
2
 
3
+ import { Image } from "@heroui/image";
4
 
5
  import { ImageGalleryConfig } from "@/types/shop";
6
  import { BaseComponentProps } from "@/types/shop-components";
 
37
  {images.map((image, index) => (
38
  <div
39
  key={index}
40
+ className={`relative overflow-hidden rounded-xl ${aspectClasses}`}
41
  >
42
+ <Image
43
  alt={image.alt}
44
+ className="w-full h-full object-cover"
45
  height="100%"
46
+ src={image.url || "https://placehold.co/600x400/EEE/31343C"}
47
  width="100%"
48
+ isZoomed
49
  />
50
  {image.caption && (
51
+ <div className="absolute bottom-0 left-0 right-0 bg-black/10 text-white p-3 backdrop-blur-sm z-20">
52
  <p className="text-sm">{image.caption}</p>
53
  </div>
54
  )}