OpenSourceUIOpenSourceUIOpensource UI
GitHub—
  1. Home
  2. Components
  3. Frames
  4. Transform Plus Frame
Back to FramesComponents / Frames

Transform Plus Frame

Free Frames React component — TransformPlusFrame. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Bounding box with plus corner handles — thicker handle strokes than border lines. Defaults to all black; pass lineColor and handleColor for dual-tone frames.

Preview

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/frames/transform-plus-frame.tsx in your project.

  4. 4

    Import and render:

    Example

    import { TransformPlusFrame } from "@/components/frames/transform-plus-frame";

    <TransformPlusFrame width={320} height={320} lineColor="#737373" handleColor="#171717"><img src="/photo.jpg" alt="" /></TransformPlusFrame>

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/frames/transform-plus-frame.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import {
forwardRef,
type ComponentPropsWithoutRef,
type CSSProperties,
type ReactNode,
} from "react";
 
import { cn } from "@/lib/cn";
 
const DEFAULT_LINE_COLOR = "#171717";
const DEFAULT_HANDLE_COLOR = "#171717";
const PLUS_STROKE = 2;
 
function resolveFrameColors({
color,
lineColor,
handleColor,
}: Readonly<{
color?: string;
lineColor?: string;
handleColor?: string;
}>) {
const shared = color ?? DEFAULT_LINE_COLOR;
 
return {
line: lineColor ?? shared,
handle: handleColor ?? color ?? DEFAULT_HANDLE_COLOR,
};
}
 
const MEDIA_SLOT =
"[&_img]:block [&_img]:size-full [&_img]:object-cover [&_video]:block [&_video]:size-full [&_video]:object-cover [&_iframe]:block [&_iframe]:size-full [&_iframe]:border-0";
 
const FRAME_INSET = "top-2 right-2 bottom-2 left-2";
const FRAME_EDGE_X = "inset-x-0";
const FRAME_EDGE_Y = "inset-y-0";
 
function toCssSize(value: string | number) {
return typeof value === "number" ? `${value}px` : value;
}
 
function MediaSkeleton() {
return (
<div className="absolute inset-0 overflow-hidden bg-neutral-100">
<div className="absolute inset-0 bg-neutral-200/45 motion-safe:animate-pulse" />
 
<div className="absolute inset-0 flex items-center justify-center">
<svg
viewBox="0 0 48 48"
aria-hidden
className="size-14 text-neutral-300"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
>
<rect x="4" y="8" width="40" height="32" rx="2" />
<circle cx="16" cy="18" r="3" fill="currentColor" stroke="none" />
<path
d="M8 34l10-9 7 6 6-5 9 8"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</div>
</div>
);
}
 
function MediaIcon({
children,
label,
}: Readonly<{ children: ReactNode; label: string }>) {
return (
<div className="flex flex-col items-center gap-1.5">
<div className="flex size-9 items-center justify-center rounded-md border border-neutral-200 bg-white text-neutral-500">
{children}
</div>
<span className="font-mono text-[9px] text-neutral-400">{label}</span>
</div>
);
}
 
function MediaPlaceholder() {
return (
<div className="flex size-full flex-col items-center justify-center gap-3 bg-neutral-50 p-4">
<div className="flex items-center gap-4">
<MediaIcon label="image">
<svg
viewBox="0 0 20 20"
aria-hidden
className="size-4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
>
<rect x="2.5" y="4" width="15" height="12" rx="1.5" />
<circle
cx="7"
cy="8.5"
r="1.25"
fill="currentColor"
stroke="none"
/>
<path
d="M5.5 14l3.5-3 2.5 2 2-1.5 3 2.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</MediaIcon>
 
<MediaIcon label="video">
<svg
viewBox="0 0 20 20"
aria-hidden
className="size-4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
>
<rect x="2.5" y="5" width="10" height="10" rx="1.5" />
<path d="M12.5 8.5l4.5-2.5v8l-4.5-2.5z" strokeLinejoin="round" />
</svg>
</MediaIcon>
 
<MediaIcon label="media">
<svg
viewBox="0 0 20 20"
aria-hidden
className="size-4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
>
<rect x="3" y="3" width="14" height="14" rx="2" />
<path d="M7 10h6M10 7v6" strokeLinecap="round" />
</svg>
</MediaIcon>
</div>
 
<p className="font-sans text-[11px] text-neutral-500">
Pass image, video, or media as children
</p>
</div>
);
}
 
type CornerPlusProps = Readonly<{
handleColor: string;
className?: string;
}>;
 
function CornerPlus({ className, handleColor }: CornerPlusProps) {
return (
<span
aria-hidden
className={cn(
"pointer-events-none absolute z-20 size-4 -translate-x-1/2 -translate-y-1/2",
className,
)}
>
<svg
viewBox="0 0 16 16"
className="size-full overflow-visible"
fill="none"
shapeRendering="crispEdges"
>
<path
d="M8 0v16M0 8h16"
stroke={handleColor}
strokeLinecap="butt"
strokeWidth={PLUS_STROKE}
/>
</svg>
</span>
);
}
 
type FrameEdgeProps = Readonly<{
lineColor: string;
className?: string;
}>;
 
function FrameEdge({ className, lineColor }: FrameEdgeProps) {
return (
<span
aria-hidden
style={{ borderColor: lineColor }}
className={cn("pointer-events-none absolute z-10", className)}
/>
);
}
 
export type TransformPlusFrameProps = Readonly<
{
children?: ReactNode;
width?: string | number;
height?: string | number;
color?: string;
lineColor?: string;
handleColor?: string;
mediaClassName?: string;
label?: string;
skeleton?: boolean;
} & ComponentPropsWithoutRef<"div">
>;
 
export const TransformPlusFrame = forwardRef<
HTMLDivElement,
TransformPlusFrameProps
>(
(
{
className,
children,
width,
height,
color,
lineColor,
handleColor,
mediaClassName,
label,
skeleton = false,
style,
...props
},
ref,
) => {
const hasFixedHeight = height !== undefined;
const colors = resolveFrameColors({ color, lineColor, handleColor });
 
const frameStyle: CSSProperties = {
...(width !== undefined ? { width: toCssSize(width) } : undefined),
...(height !== undefined ? { height: toCssSize(height) } : undefined),
...style,
};
 
return (
<div
ref={ref}
data-slot="transform-plus-frame"
className={cn(
"font-sans",
width === undefined && "w-full max-w-xl",
className,
)}
style={frameStyle}
{...props}
>
<div className={cn("relative p-2", hasFixedHeight && "h-full")}>
<div
className={cn(
"relative z-0 min-h-0 overflow-hidden bg-neutral-50",
hasFixedHeight ? "h-full" : (mediaClassName ?? "aspect-video"),
)}
>
<div className={cn("absolute inset-0", MEDIA_SLOT)}>
{skeleton ? (
<MediaSkeleton />
) : (
(children ?? <MediaPlaceholder />)
)}
</div>
</div>
 
<FrameEdge
lineColor={colors.line}
className={cn(FRAME_INSET, FRAME_EDGE_X, "border-t")}
/>
<FrameEdge
lineColor={colors.line}
className={cn(FRAME_INSET, FRAME_EDGE_Y, "border-r")}
/>
<FrameEdge
lineColor={colors.line}
className={cn(FRAME_INSET, FRAME_EDGE_X, "border-b")}
/>
<FrameEdge
lineColor={colors.line}
className={cn(FRAME_INSET, FRAME_EDGE_Y, "border-l")}
/>
 
<CornerPlus handleColor={colors.handle} className="top-2 left-2" />
<CornerPlus
handleColor={colors.handle}
className="top-2 right-2 translate-x-1/2"
/>
<CornerPlus
handleColor={colors.handle}
className="bottom-2 left-2 translate-y-1/2"
/>
<CornerPlus
handleColor={colors.handle}
className="right-2 bottom-2 translate-x-1/2 translate-y-1/2"
/>
</div>
 
{label ? (
<p className="mt-2 text-center font-mono text-[10px] tracking-[0.16em] text-neutral-400 uppercase">
{label}
</p>
) : null}
</div>
);
},
);
 
TransformPlusFrame.displayName = "TransformPlusFrame";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/frames/transform-plus-frame.tsx
Platinum slotAvailable

Feature your product here.

Sticky card next to every component — highest-intent placement.

Claim this card