iPhone
magicui/iphoneFreeComponent
A mockup of the iPhone
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/iphone.jsonSource
1import type { HTMLAttributes } from "react"23const PHONE_WIDTH = 4334const PHONE_HEIGHT = 8825const SCREEN_X = 21.256const SCREEN_Y = 19.257const SCREEN_WIDTH = 389.58const SCREEN_HEIGHT = 843.59const SCREEN_RADIUS = 55.751011// Calculated percentages12const LEFT_PCT = (SCREEN_X / PHONE_WIDTH) * 10013const TOP_PCT = (SCREEN_Y / PHONE_HEIGHT) * 10014const WIDTH_PCT = (SCREEN_WIDTH / PHONE_WIDTH) * 10015const HEIGHT_PCT = (SCREEN_HEIGHT / PHONE_HEIGHT) * 10016const RADIUS_H = (SCREEN_RADIUS / SCREEN_WIDTH) * 10017const RADIUS_V = (SCREEN_RADIUS / SCREEN_HEIGHT) * 1001819export interface IphoneProps extends HTMLAttributes<HTMLDivElement> {20 src?: string21 videoSrc?: string22}2324export function Iphone({25 src,26 videoSrc,27 className,28 style,29 ...props30}: IphoneProps) {31 const hasVideo = !!videoSrc32 const hasMedia = hasVideo || !!src3334 return (35 <div36 className={`relative inline-block w-full align-middle leading-none ${className}`}37 style={{38 aspectRatio: `${PHONE_WIDTH}/${PHONE_HEIGHT}`,39 ...style,40 }}41 {...props}42 >43 {hasVideo && (44 <div45 className="pointer-events-none absolute z-0 overflow-hidden"46 style={{47 left: `${LEFT_PCT}%`,48 top: `${TOP_PCT}%`,49 width: `${WIDTH_PCT}%`,50 height: `${HEIGHT_PCT}%`,51 borderRadius: `${RADIUS_H}% / ${RADIUS_V}%`,52 }}53 >54 <video55 className="block size-full object-cover"56 src={videoSrc}57 autoPlay58 loop59 muted60 playsInline61 preload="metadata"62 />63 </div>64 )}6566 {!hasVideo && src && (67 <div68 className="pointer-events-none absolute z-0 overflow-hidden"69 style={{70 left: `${LEFT_PCT}%`,71 top: `${TOP_PCT}%`,72 width: `${WIDTH_PCT}%`,73 height: `${HEIGHT_PCT}%`,74 borderRadius: `${RADIUS_H}% / ${RADIUS_V}%`,75 }}76 >77 <img78 src={src}79 alt=""80 className="block size-full object-cover object-top"81 />82 </div>83 )}8485 <svg86 viewBox={`0 0 ${PHONE_WIDTH} ${PHONE_HEIGHT}`}87 fill="none"88 xmlns="http://www.w3.org/2000/svg"89 className="absolute inset-0 size-full"90 style={{ transform: "translateZ(0)" }}91 >92 <g mask={hasMedia ? "url(#screenPunch)" : undefined}>93 <path94// … truncated
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
