-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...mitives/ColorInput/PopoverColorPicker.tsx → ...mitives/ColorInput/PopoverColorPicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...el/inputs/primitives/ColorInput/index.tsx → ...el/inputs/primitives/ColorInput/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { ChevronDownIcon, ChevronUpIcon } from '@radix-ui/react-icons'; | ||
import useEmblaCarousel from 'embla-carousel-react'; | ||
import { WheelGesturesPlugin } from 'embla-carousel-wheel-gestures'; | ||
import React, { useCallback, useEffect, useRef, useState } from 'react'; | ||
|
||
type CarouselProps = { | ||
slides: { id: number; imgSrc: string; title: string }[]; | ||
}; | ||
|
||
const EmblaCarousel: React.FC<CarouselProps> = ({ slides }) => { | ||
const [emblaRef, emblaApi] = useEmblaCarousel( | ||
{ | ||
axis: 'y', | ||
loop: false, | ||
align: 'center', | ||
dragFree: false, | ||
skipSnaps: false, | ||
containScroll: 'trimSnaps', | ||
}, | ||
[WheelGesturesPlugin()], | ||
); | ||
const [prevBtnEnabled, setPrevBtnEnabled] = useState(false); | ||
const [nextBtnEnabled, setNextBtnEnabled] = useState(false); | ||
const [scrollProgress, setScrollProgress] = useState(0); | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
|
||
const scrollPrev = useCallback(() => emblaApi && emblaApi.scrollPrev(), [emblaApi]); | ||
const scrollNext = useCallback(() => emblaApi && emblaApi.scrollNext(), [emblaApi]); | ||
|
||
const onSelect = useCallback(() => { | ||
if (!emblaApi) { | ||
return; | ||
} | ||
setPrevBtnEnabled(emblaApi.canScrollPrev()); | ||
setNextBtnEnabled(emblaApi.canScrollNext()); | ||
}, [emblaApi]); | ||
|
||
const onScroll = useCallback(() => { | ||
if (!emblaApi) { | ||
return; | ||
} | ||
const progress = emblaApi.scrollProgress(); | ||
setScrollProgress(progress); | ||
}, [emblaApi]); | ||
|
||
useEffect(() => { | ||
if (!emblaApi) { | ||
return; | ||
} | ||
onSelect(); | ||
onScroll(); | ||
emblaApi.on('select', onSelect); | ||
emblaApi.on('scroll', onScroll); | ||
emblaApi.on('reInit', onSelect); | ||
}, [emblaApi, onSelect, onScroll]); | ||
|
||
const calculateImageSize = (imageNaturalWidth: number, imageNaturalHeight: number) => { | ||
if (!containerRef.current) { | ||
return { width: 'auto', height: 'auto' }; | ||
} | ||
|
||
const containerWidth = containerRef.current.clientWidth; | ||
const containerHeight = containerRef.current.clientHeight; | ||
const targetSize = Math.min(containerWidth, containerHeight) * 0.6; | ||
|
||
const imageAspectRatio = imageNaturalWidth / imageNaturalHeight; | ||
const containerAspectRatio = containerWidth / containerHeight; | ||
|
||
if (imageAspectRatio > containerAspectRatio) { | ||
return { width: targetSize, height: 'auto' }; | ||
} else { | ||
return { width: 'auto', height: targetSize }; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="embla relative h-full overflow-hidden" ref={containerRef}> | ||
<div className="embla__viewport h-full" ref={emblaRef}> | ||
<div className="embla__container h-full"> | ||
{slides.map((slide) => ( | ||
<div | ||
key={slide.id} | ||
className="embla__slide h-full relative flex items-center justify-center" | ||
style={{ | ||
flex: '0 0 100%', | ||
minWidth: 0, | ||
}} | ||
> | ||
<img | ||
src={slide.imgSrc} | ||
alt={slide.title} | ||
className="rounded-lg object-contain" | ||
style={{ | ||
maxWidth: '60%', | ||
maxHeight: '60%', | ||
}} | ||
onLoad={(e) => { | ||
const img = e.target as HTMLImageElement; | ||
const { width, height } = calculateImageSize( | ||
img.naturalWidth, | ||
img.naturalHeight, | ||
); | ||
img.style.width = | ||
typeof width === 'number' ? `${width}px` : width; | ||
img.style.height = | ||
typeof height === 'number' ? `${height}px` : height; | ||
}} | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
<div className="embla__buttons absolute left-24 top-1/2 transform -translate-y-1/2 flex flex-col gap-4 z-10"> | ||
<button | ||
className="embla__button embla__button--prev" | ||
onClick={scrollPrev} | ||
disabled={!prevBtnEnabled} | ||
> | ||
<ChevronUpIcon | ||
className={`w-8 h-8 ${prevBtnEnabled ? 'text-white' : 'text-gray-400'}`} | ||
/> | ||
</button> | ||
<button | ||
className="embla__button embla__button--next" | ||
onClick={scrollNext} | ||
disabled={!nextBtnEnabled} | ||
> | ||
<ChevronDownIcon | ||
className={`w-8 h-8 ${nextBtnEnabled ? 'text-white' : 'text-gray-400'}`} | ||
/> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EmblaCarousel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { DotsVerticalIcon, Pencil2Icon } from '@radix-ui/react-icons'; | ||
import EmblaCarousel from './Carousel'; | ||
|
||
export default function Projects() { | ||
const slides = [ | ||
{ id: 0, imgSrc: 'https://picsum.photos/id/237/200/300', title: '0' }, | ||
{ id: 1, imgSrc: 'https://picsum.photos/id/238/300/200', title: '1' }, | ||
{ id: 2, imgSrc: 'https://picsum.photos/id/239/500/500', title: '2' }, | ||
]; | ||
|
||
return ( | ||
<div className="flex h-[calc(100vh-2.5rem)] w-full relative"> | ||
<div className="absolute top-0 w-full h-8 flex justify-center items-center px-32"> | ||
<div className="bg-bg h-full w-48"> </div> | ||
<div className="bg-bg mx-auto h-full w-48"> </div> | ||
<div className="bg-bg h-full w-48"> </div> | ||
</div> | ||
<div className="w-3/5 h-full"> | ||
<EmblaCarousel slides={slides} /> | ||
</div> | ||
<div className="w-2/5 h-full flex flex-col justify-center items-start p-20 gap-4 font-light"> | ||
<p className="text-text-active text-4xl ">Airbnb.com</p> | ||
<div className="text-text flex gap-7 text-sm"> | ||
<p>Last edited 3 days ago </p> | ||
<p> localhost: 3000</p> | ||
</div> | ||
<div className="flex gap-4"> | ||
<Button | ||
size="default" | ||
variant={'outline'} | ||
className="gap-4 bg-bg-active border border-border-active" | ||
> | ||
<Pencil2Icon /> | ||
<p> Edit App </p> | ||
</Button> | ||
<Button size="default" variant={'ghost'} className="gap-4"> | ||
<DotsVerticalIcon /> | ||
<p> Project settings</p> | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters