A macbook-scroll component from Aceternity UI.
From Aceternity UI
1"use client";
2import React, { useEffect, useMemo, useRef, useState } from "react";
3import { MotionValue, motion, useScroll, useTransform } from "motion/react";
4import { cn } from "@/lib/utils";
5import {
6 IconBrightnessDown,
7 IconBrightnessUp,
8 IconCaretRightFilled,
9 IconCaretUpFilled,
10 IconChevronUp,
11 IconMicrophone,
12 IconMoon,
13 IconPlayerSkipForward,
14 IconPlayerTrackNext,
15 IconPlayerTrackPrev,
16 IconTable,
17 IconVolume,
18 IconVolume2,
19 IconVolume3,
20} from "@tabler/icons-react";
21import { IconSearch } from "@tabler/icons-react";
22import { IconWorld } from "@tabler/icons-react";
23import { IconCommand } from "@tabler/icons-react";
24import { IconCaretLeftFilled } from "@tabler/icons-react";
25import { IconCaretDownFilled } from "@tabler/icons-react";
26
27
28export const MacbookScroll = ({
29 src,
30 showGradient,
31 title,
32 badge,
33}: {
34 src?: string;
35 showGradient?: boolean;
36 title?: string | React.ReactNode;
37 badge?: React.ReactNode;
38}) => {
39 const ref = useRef<HTMLDivElement>(null);
40 const { scrollYProgress } = useScroll({
41 target: ref,
42 offset: ["start start", "end start"],
43 });
44
45 const [isMobile, setIsMobile] = useState(false);
46
47 useEffect(() => {
48 if (window && window.innerWidth < 768) {
49 setIsMobile(true);
50 }
51 }, []);
52
53 const scaleX = useTransform(
54 scrollYProgress,
55 [0, 0.3],
56 [1.2, isMobile ? 1 : 1.5],
57 );
58 const scaleY = useTransform(
59 scrollYProgress,
60 [0, 0.3],
61 [0.6, isMobile ? 1 : 1.5],
62 );
63 const translate = useTransform(scrollYProgress, [0, 1], [0, 1500]);
64 const rotate = useTransform(scrollYProgress, [0.1, 0.12, 0.3], [-28, -28, 0]);
65 const textTransform = useTransform(scrollYProgress, [0, 0.3], [0, 100]);
66 const textOpacity = useTransform(scrollYProgress, [0, 0.2], [1, 0]);
67
68 return (
69 <div
70 ref={ref}
71 className="flex min-h-[200vh] shrink-0 scale-[0.35] transform flex-col items-center justify-start py-0 [perspective:800px] sm:scale-50 md:scale-100 md:py-80"
72 >
73 <motion.h2
74 style={{
75 translateY: textTransform,
76 opacity: textOpacity,
77 }}
78 className="mb-20 text-center text-3xl font-bold text-neutral-800 dark:text-white"
79 >
80 {title || (
81 <span>
82 This Macbook is built with Tailwindcss. <br /> No kidding.
83 </span>
84 )}
85 </motion.h2>
86 {/* Lid */}
87 <Lid
88 src={src}
89 scaleX={scaleX}
90 scaleY={scaleY}
91 rotate={rotate}
92 translate={translate}
93 />
94 {/* Base area */}
95 <div className="relative -z-10 h-[22rem] w-[32rem] overflow-hidden rounded-2xl bg-gray-200 dark:bg-[#272729]">
96 {/* above keyboard bar */}
97 <div className="relative h-10 w-full">
98 <div className="absolute inset-x-0 mx-auto h-4 w-[80%] bg-[#050505]" />
99 </div>
100 <div className="relative flex">
101 <div className="mx-auto h-full w-[10%] overflow-hidden">
102 <SpeakerGrid />
103 </div>
104 <div className="mx-auto h-full w-[80%]">
105 <Keypad />
106 </div>
107 <div className="mx-auto h-full w-[10%] overflow-hidden">
108 <SpeakerGrid />
109 </div>
110 </div>
111 <Trackpad />
112 <div className="absolute inset-x-0 bottom-0 mx-auto h-2 w-20 rounded-tl-3xl rounded-tr-3xl bg-gradient-to-t from-[#272729] to-[#050505]" />
113 {showGradient && (
114 <div className="absolute inset-x-0 bottom-0 z-50 h-40 w-full bg-gradient-to-t from-white via-white to-transparent dark:from-black dark:via-black"></div>
115 )}
116 {badge && <div className="absolute bottom-4 left-4">{badge}</div>}
117 </div>
118 </div>
119 );
120};
121
122export const Lid = ({
123 scaleX,
124 scaleY,
125 rotate,
126 translate,
127 src,
128}: {
129 scaleX: MotionValue<number>;
130 scaleY: MotionValue<number>;
131 rotate: MotionValue<number>;
132 translate: MotionValue<number>;
133 src?: string;
134}) => {
135 return (
136 <div className="relative [perspective:800px]">
137 <div
138 style={{
139 transform: "perspective(800px) rotateX(-25deg) translateZ(0px)",
140 transformOrigin: "bottom",
141 transformStyle: "preserve-3d",
142 }}
143 className="relative h-[12rem] w-[32rem] rounded-2xl bg-[#010101] p-2"
144 >
145 <div
146 style={{
147 boxShadow: "0px 2px 0px 2px #171717 inset",
148 }}
149 className="absolute inset-0 flex items-center justify-center rounded-lg bg-[#010101]"
150 >
151 <span className="text-white">
152 <AceternityLogo />
153 </span>
154 </div>
155 </div>
156 <motion.div
157 style={{
158 scaleX: scaleX,
159 scaleY: scaleY,
160 rotateX: rotate,
161 translateY: translate,
162 transformStyle: "preserve-3d",
163 transformOrigin: "top",
164 }}
165 className="absolute inset-0 h-96 w-[32rem] rounded-2xl bg-[#010101] p-2"
166 >
167 <div className="absolute inset-0 rounded-lg bg-[#272729]" />
168 <img
169 src={src as string}
170 alt="aceternity logo"
171 className="absolute inset-0 h-full w-full rounded-lg object-cover object-left-top"
172 />
173 </motion.div>
174 </div>
175 );
176};
177
178export const Trackpad = () => {
179 return (
180 <div
181 className="mx-auto my-1 h-32 w-[40%] rounded-xl"
182 style={{
183 boxShadow: "0px 0px 1px 1px #00000020 inset",
184 }}
185 ></div>
186 );
187};
188
189export const Keypad = () => {
190 return (
191 <div className="mx-1 h-full [transform:translateZ(0)] rounded-md bg-[#050505] p-1 [will-change:transform]">
192 {/* First Row */}
193 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
194 <KBtn
195 className="w-10 items-end justify-start pb-[2px] pl-[4px]"
196 childrenClassName="items-start"
197 >
198 esc
199 </KBtn>
200 <KBtn>
201 <IconBrightnessDown className="h-[6px] w-[6px]" />
202 <span className="mt-1 inline-block">F1</span>
203 </KBtn>
204 <KBtn>
205 <IconBrightnessUp className="h-[6px] w-[6px]" />
206 <span className="mt-1 inline-block">F2</span>
207 </KBtn>
208 <KBtn>
209 <IconTable className="h-[6px] w-[6px]" />
210 <span className="mt-1 inline-block">F3</span>
211 </KBtn>
212 <KBtn>
213 <IconSearch className="h-[6px] w-[6px]" />
214 <span className="mt-1 inline-block">F4</span>
215 </KBtn>
216 <KBtn>
217 <IconMicrophone className="h-[6px] w-[6px]" />
218 <span className="mt-1 inline-block">F5</span>
219 </KBtn>
220 <KBtn>
221 <IconMoon className="h-[6px] w-[6px]" />
222 <span className="mt-1 inline-block">F6</span>
223 </KBtn>
224 <KBtn>
225 <IconPlayerTrackPrev className="h-[6px] w-[6px]" />
226 <span className="mt-1 inline-block">F7</span>
227 </KBtn>
228 <KBtn>
229 <IconPlayerSkipForward className="h-[6px] w-[6px]" />
230 <span className="mt-1 inline-block">F8</span>
231 </KBtn>
232 <KBtn>
233 <IconPlayerTrackNext className="h-[6px] w-[6px]" />
234 <span className="mt-1 inline-block">F8</span>
235 </KBtn>
236 <KBtn>
237 <IconVolume3 className="h-[6px] w-[6px]" />
238 <span className="mt-1 inline-block">F10</span>
239 </KBtn>
240 <KBtn>
241 <IconVolume2 className="h-[6px] w-[6px]" />
242 <span className="mt-1 inline-block">F11</span>
243 </KBtn>
244 <KBtn>
245 <IconVolume className="h-[6px] w-[6px]" />
246 <span className="mt-1 inline-block">F12</span>
247 </KBtn>
248 <KBtn>
249 <div className="h-4 w-4 rounded-full bg-gradient-to-b from-neutral-900 from-20% via-black via-50% to-neutral-900 to-95% p-px">
250 <div className="h-full w-full rounded-full bg-black" />
251 </div>
252 </KBtn>
253 </div>
254
255 {/* Second row */}
256 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
257 <KBtn>
258 <span className="block">~</span>
259 <span className="mt-1 block">`</span>
260 </KBtn>
261 <KBtn>
262 <span className="block">!</span>
263 <span className="block">1</span>
264 </KBtn>
265 <KBtn>
266 <span className="block">@</span>
267 <span className="block">2</span>
268 </KBtn>
269 <KBtn>
270 <span className="block">#</span>
271 <span className="block">3</span>
272 </KBtn>
273 <KBtn>
274 <span className="block">$</span>
275 <span className="block">4</span>
276 </KBtn>
277 <KBtn>
278 <span className="block">%</span>
279 <span className="block">5</span>
280 </KBtn>
281 <KBtn>
282 <span className="block">^</span>
283 <span className="block">6</span>
284 </KBtn>
285 <KBtn>
286 <span className="block">&</span>
287 <span className="block">7</span>
288 </KBtn>
289 <KBtn>
290 <span className="block">*</span>
291 <span className="block">8</span>
292 </KBtn>
293 <KBtn>
294 <span className="block">(</span>
295 <span className="block">9</span>
296 </KBtn>
297 <KBtn>
298 <span className="block">)</span>
299 <span className="block">0</span>
300 </KBtn>
301 <KBtn>
302 <span className="block">—</span>
303 <span className="block">_</span>
304 </KBtn>
305 <KBtn>
306 <span className="block">+</span>
307 <span className="block"> = </span>
308 </KBtn>
309 <KBtn
310 className="w-10 items-end justify-end pr-[4px] pb-[2px]"
311 childrenClassName="items-end"
312 >
313 delete
314 </KBtn>
315 </div>
316
317 {/* Third row */}
318 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
319 <KBtn
320 className="w-10 items-end justify-start pb-[2px] pl-[4px]"
321 childrenClassName="items-start"
322 >
323 tab
324 </KBtn>
325 <KBtn>
326 <span className="block">Q</span>
327 </KBtn>
328 <KBtn>
329 <span className="block">W</span>
330 </KBtn>
331 <KBtn>
332 <span className="block">E</span>
333 </KBtn>
334 <KBtn>
335 <span className="block">R</span>
336 </KBtn>
337 <KBtn>
338 <span className="block">T</span>
339 </KBtn>
340 <KBtn>
341 <span className="block">Y</span>
342 </KBtn>
343 <KBtn>
344 <span className="block">U</span>
345 </KBtn>
346 <KBtn>
347 <span className="block">I</span>
348 </KBtn>
349 <KBtn>
350 <span className="block">O</span>
351 </KBtn>
352 <KBtn>
353 <span className="block">P</span>
354 </KBtn>
355 <KBtn>
356 <span className="block">{`{`}</span>
357 <span className="block">{`[`}</span>
358 </KBtn>
359 <KBtn>
360 <span className="block">{`}`}</span>
361 <span className="block">{`]`}</span>
362 </KBtn>
363 <KBtn>
364 <span className="block">{`|`}</span>
365 <span className="block">{`\\`}</span>
366 </KBtn>
367 </div>
368
369 {/* Fourth Row */}
370 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
371 <KBtn
372 className="w-[2.8rem] items-end justify-start pb-[2px] pl-[4px]"
373 childrenClassName="items-start"
374 >
375 caps lock
376 </KBtn>
377 <KBtn>
378 <span className="block">A</span>
379 </KBtn>
380 <KBtn>
381 <span className="block">S</span>
382 </KBtn>
383 <KBtn>
384 <span className="block">D</span>
385 </KBtn>
386 <KBtn>
387 <span className="block">F</span>
388 </KBtn>
389 <KBtn>
390 <span className="block">G</span>
391 </KBtn>
392 <KBtn>
393 <span className="block">H</span>
394 </KBtn>
395 <KBtn>
396 <span className="block">J</span>
397 </KBtn>
398 <KBtn>
399 <span className="block">K</span>
400 </KBtn>
401 <KBtn>
402 <span className="block">L</span>
403 </KBtn>
404 <KBtn>
405 <span className="block">{`:`}</span>
406 <span className="block">{`;`}</span>
407 </KBtn>
408 <KBtn>
409 <span className="block">{`"`}</span>
410 <span className="block">{`'`}</span>
411 </KBtn>
412 <KBtn
413 className="w-[2.85rem] items-end justify-end pr-[4px] pb-[2px]"
414 childrenClassName="items-end"
415 >
416 return
417 </KBtn>
418 </div>
419
420 {/* Fifth Row */}
421 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
422 <KBtn
423 className="w-[3.65rem] items-end justify-start pb-[2px] pl-[4px]"
424 childrenClassName="items-start"
425 >
426 shift
427 </KBtn>
428 <KBtn>
429 <span className="block">Z</span>
430 </KBtn>
431 <KBtn>
432 <span className="block">X</span>
433 </KBtn>
434 <KBtn>
435 <span className="block">C</span>
436 </KBtn>
437 <KBtn>
438 <span className="block">V</span>
439 </KBtn>
440 <KBtn>
441 <span className="block">B</span>
442 </KBtn>
443 <KBtn>
444 <span className="block">N</span>
445 </KBtn>
446 <KBtn>
447 <span className="block">M</span>
448 </KBtn>
449 <KBtn>
450 <span className="block">{`<`}</span>
451 <span className="block">{`,`}</span>
452 </KBtn>
453 <KBtn>
454 <span className="block">{`>`}</span>
455 <span className="block">{`.`}</span>
456 </KBtn>
457 <KBtn>
458 <span className="block">{`?`}</span>
459 <span className="block">{`/`}</span>
460 </KBtn>
461 <KBtn
462 className="w-[3.65rem] items-end justify-end pr-[4px] pb-[2px]"
463 childrenClassName="items-end"
464 >
465 shift
466 </KBtn>
467 </div>
468
469 {/* sixth Row */}
470 <div className="mb-[2px] flex w-full shrink-0 gap-[2px]">
471 <KBtn className="" childrenClassName="h-full justify-between py-[4px]">
472 <div className="flex w-full justify-end pr-1">
473 <span className="block">fn</span>
474 </div>
475 <div className="flex w-full justify-start pl-1">
476 <IconWorld className="h-[6px] w-[6px]" />
477 </div>
478 </KBtn>
479 <KBtn className="" childrenClassName="h-full justify-between py-[4px]">
480 <div className="flex w-full justify-end pr-1">
481 <IconChevronUp className="h-[6px] w-[6px]" />
482 </div>
483 <div className="flex w-full justify-start pl-1">
484 <span className="block">control</span>
485 </div>
486 </KBtn>
487 <KBtn className="" childrenClassName="h-full justify-between py-[4px]">
488 <div className="flex w-full justify-end pr-1">
489 <OptionKey className="h-[6px] w-[6px]" />
490 </div>
491 <div className="flex w-full justify-start pl-1">
492 <span className="block">option</span>
493 </div>
494 </KBtn>
495 <KBtn
496 className="w-8"
497 childrenClassName="h-full justify-between py-[4px]"
498 >
499 <div className="flex w-full justify-end pr-1">
500 <IconCommand className="h-[6px] w-[6px]" />
501 </div>
502 <div className="flex w-full justify-start pl-1">
503 <span className="block">command</span>
504 </div>
505 </KBtn>
506 <KBtn className="w-[8.2rem]"></KBtn>
507 <KBtn
508 className="w-8"
509 childrenClassName="h-full justify-between py-[4px]"
510 >
511 <div className="flex w-full justify-start pl-1">
512 <IconCommand className="h-[6px] w-[6px]" />
513 </div>
514 <div className="flex w-full justify-start pl-1">
515 <span className="block">command</span>
516 </div>
517 </KBtn>
518 <KBtn className="" childrenClassName="h-full justify-between py-[4px]">
519 <div className="flex w-full justify-start pl-1">
520 <OptionKey className="h-[6px] w-[6px]" />
521 </div>
522 <div className="flex w-full justify-start pl-1">
523 <span className="block">option</span>
524 </div>
525 </KBtn>
526 <div className="mt-[2px] flex h-6 w-[4.9rem] flex-col items-center justify-end rounded-[4px] p-[0.5px]">
527 <KBtn className="h-3 w-6">
528 <IconCaretUpFilled className="h-[6px] w-[6px]" />
529 </KBtn>
530 <div className="flex">
531 <KBtn className="h-3 w-6">
532 <IconCaretLeftFilled className="h-[6px] w-[6px]" />
533 </KBtn>
534 <KBtn className="h-3 w-6">
535 <IconCaretDownFilled className="h-[6px] w-[6px]" />
536 </KBtn>
537 <KBtn className="h-3 w-6">
538 <IconCaretRightFilled className="h-[6px] w-[6px]" />
539 </KBtn>
540 </div>
541 </div>
542 </div>
543 </div>
544 );
545};
546
547export const KBtn = ({
548 className,
549 children,
550 childrenClassName,
551 backlit = true,
552}: {
553 className?: string;
554 children?: React.ReactNode;
555 childrenClassName?: string;
556 backlit?: boolean;
557}) => {
558 return (
559 <div
560 className={cn(
561 "[transform:translateZ(0)] rounded-[4px] p-[0.5px] [will-change:transform]",
562 backlit && "bg-white/[0.2] shadow-xl shadow-white",
563 )}
564 >
565 <div
566 className={cn(
567 "flex h-6 w-6 items-center justify-center rounded-[3.5px] bg-[#0A090D]",
568 className,
569 )}
570 style={{
571 boxShadow:
572 "0px -0.5px 2px 0 #0D0D0F inset, -0.5px 0px 2px 0 #0D0D0F inset",
573 }}
574 >
575 <div
576 className={cn(
577 "flex w-full flex-col items-center justify-center text-[5px] text-neutral-200",
578 childrenClassName,
579 backlit && "text-white",
580 )}
581 >
582 {children}
583 </div>
584 </div>
585 </div>
586 );
587};
588
589export const SpeakerGrid = () => {
590 return (
591 <div
592 className="mt-2 flex h-40 gap-[2px] px-[0.5px]"
593 style={{
594 backgroundImage:
595 "radial-gradient(circle, #08080A 0.5px, transparent 0.5px)",
596 backgroundSize: "3px 3px",
597 }}
598 ></div>
599 );
600};
601
602export const OptionKey = ({ className }: { className: string }) => {
603 return (
604 <svg
605 fill="none"
606 version="1.1"
607 id="icon"
608 xmlns="http://www.w3.org/2000/svg"
609 viewBox="0 0 32 32"
610 className={className}
611 >
612 <rect
613 stroke="currentColor"
614 strokeWidth={2}
615 x="18"
616 y="5"
617 width="10"
618 height="2"
619 />
620 <polygon
621 stroke="currentColor"
622 strokeWidth={2}
623 points="10.6,5 4,5 4,7 9.4,7 18.4,27 28,27 28,25 19.6,25 "
624 />
625 <rect
626 id="_Transparent_Rectangle_"
627 className="st0"
628 width="32"
629 height="32"
630 stroke="none"
631 />
632 </svg>
633 );
634};
635
636const AceternityLogo = () => {
637 return (
638 <svg
639 width="66"
640 height="65"
641 viewBox="0 0 66 65"
642 fill="none"
643 xmlns="http://www.w3.org/2000/svg"
644 className="h-3 w-3 text-white"
645 >
646 <path
647 d="M8 8.05571C8 8.05571 54.9009 18.1782 57.8687 30.062C60.8365 41.9458 9.05432 57.4696 9.05432 57.4696"
648 stroke="currentColor"
649 strokeWidth="15"
650 strokeMiterlimit="3.86874"
651 strokeLinecap="round"
652 />
653 </svg>
654 );
655};
656