The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Screenshot Carousel
Kiran K895b6e62fed2
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsxindex a4fda0b1c1..37477f178f 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx@@ -5,9 +5,14 @@ import { InstalledIntegrationInfoProps } from "@/lib/types";import { useUninstallIntegrationModal } from "@/ui/modals/uninstall-integration-modal";import { ThreeDots } from "@/ui/shared/icons";import {+ AssetImage,Avatar,BlurImage,Button,+ Carousel,+ CarouselContent,+ CarouselItem,+ CarouselNavBar,MaxWidthWrapper,Popover,TokenAvatar,@@ -18,6 +23,7 @@ import { BookOpenText, ChevronLeft, Trash } from "lucide-react";import Link from "next/link";import { useState } from "react";import Markdown from "react-markdown";+import "react-medium-image-zoom/dist/styles.css";export default function IntegrationPageClient({integration,@@ -131,6 +137,31 @@ export default function IntegrationPageClient({</div></div>+ <Carousel autoplay={{ delay: 5000 }} className="w-full bg-gray-100 rounded-lg">+ <CarouselContent>+ {[+ "https://assets.dub.co/brand/screenshot-01.jpg",+ "https://assets.dub.co/brand/screenshot-02.jpg",+ ].map((src, idx) => (+ <CarouselItem key={idx}>+ <div className="group relative">+ <AssetImage+ image={{+ src,+ alt: "Screenshot",+ fill: true,+ style: { objectFit: "cover" },+ }}+ className="static mx-auto mt-10 aspect-[2880/1640] w-5/6 overflow-hidden rounded-t-2xl border border-gray-200"+ />+ {/* <div className="absolute bottom-0 h-32 w-full bg-gradient-to-t from-white via-white/75 to-transparent" /> */}+ </div>+ </CarouselItem>+ ))}+ </CarouselContent>+ <CarouselNavBar variant="floating" />+ </Carousel>+{integration.readme && (<div className="w-full rounded-lg border border-gray-200 bg-white"><div className="flex items-center gap-x-2 border-b border-gray-200 px-6 py-4">diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex c8d2ef4c1a..a17043ba30 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -54,6 +54,8 @@"class-variance-authority": "^0.7.0","cmdk": "^0.2.0","date-fns": "^3.6.0",+ "embla-carousel-autoplay": "^8.1.7",+ "embla-carousel-react": "^8.1.7","framer-motion": "^10.16.16","js-cookie": "^3.0.5","linkify-react": "^4.1.3",diff --git a/packages/ui/src/asset-image.tsx b/packages/ui/src/asset-image.tsxnew file mode 100644index 0000000000..24f9d8a943--- /dev/null+++ b/packages/ui/src/asset-image.tsx@@ -0,0 +1,42 @@+import { cn } from "@dub/utils";+import { DownloadIcon } from "lucide-react";+import Image, { ImageProps } from "next/image";++export function AssetImage({+ className,+ imageContainerClassName,+ image,+}: {+ className?: string;+ imageContainerClassName?: string;+ image: Omit<ImageProps, "src"> & { src: string };+}) {+ return (+ <a+ href={image.src}+ download={image.src}+ className={cn(+ "relative block outline-none ring-inset ring-blue-500 focus-visible:ring",+ className,+ )}+ >+ <div className={cn("relative h-full w-full", imageContainerClassName)}>+ <Image {...image} className={cn("relative", image.className)} />+ </div>++ {/* Download button (shown on hover) */}+ <div className="group/inner absolute bottom-4 right-4 z-20 rounded-full px-3 py-3 shadow-sm transition-all group-hover:translate-y-0 group-hover:opacity-100 group-focus-visible:translate-y-0 group-focus-visible:opacity-100 sm:translate-y-2 sm:py-1 sm:opacity-0">+ {/* Background based on currentColor */}+ <div className="absolute inset-0 rounded-full bg-current opacity-0 group-hover/inner:opacity-[.05]"></div>++ {/* Border based on currentColor */}+ <div className="absolute inset-0 rounded-full border border-current opacity-[.15]"></div>++ <div className="flex items-center gap-2 text-sm">+ <DownloadIcon className="h-4 w-4" />+ <span className="hidden sm:block">Download</span>+ </div>+ </div>+ </a>+ );+}diff --git a/packages/ui/src/carousel.tsx b/packages/ui/src/carousel.tsxnew file mode 100644index 0000000000..d6a4ba6c87--- /dev/null+++ b/packages/ui/src/carousel.tsx@@ -0,0 +1,392 @@+"use client";++import { cn } from "@dub/utils";+import { VariantProps, cva } from "class-variance-authority";+import Autoplay from "embla-carousel-autoplay";+import useEmblaCarousel, {+ type UseEmblaCarouselType,+} from "embla-carousel-react";+import { motion } from "framer-motion";+import { ArrowLeft, ArrowRight, ChevronLeft, ChevronRight } from "lucide-react";+import * as React from "react";+import { buttonVariants } from "./button";++const AUTOPLAY_DEFAULT_DELAY = 2000;++type CarouselApi = UseEmblaCarouselType[1];+type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;+type CarouselOptions = UseCarouselParameters[0];+type CarouselPlugin = UseCarouselParameters[1];+type AutoplayOptions = Parameters<typeof Autoplay>[0];++type CarouselProps = {+ opts?: CarouselOptions;+ plugins?: CarouselPlugin;+ orientation?: "horizontal" | "vertical";+ autoplay?: boolean | AutoplayOptions;+ setApi?: (api: CarouselApi) => void;+};++type CarouselContextProps = {+ carouselRef: ReturnType<typeof useEmblaCarousel>[0];+ api: ReturnType<typeof useEmblaCarousel>[1];+ scrollPrev: () => void;+ scrollNext: () => void;+ canScrollPrev: boolean;+ canScrollNext: boolean;+} & CarouselProps;++const CarouselContext = React.createContext<CarouselContextProps | null>(null);++export function useCarousel() {+ const context = React.useContext(CarouselContext);++ if (!context) {+ throw new Error("useCarousel must be used within a <Carousel />");+ }++ return context;+}++const Carousel = React.forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement> & CarouselProps+>(+ (+ {+ orientation = "horizontal",+ opts,+ setApi,+ autoplay,+ plugins,+ className,+ children,+ ...props+ },+ ref,+ ) => {+ const [carouselRef, api] = useEmblaCarousel(+ {+ ...opts,+ axis: orientation === "horizontal" ? "x" : "y",+ },+ [+ ...(autoplay+ ? [+ Autoplay(+ typeof autoplay === "object"+ ? autoplay+ : {+ delay: AUTOPLAY_DEFAULT_DELAY,+ },+ ),+ ]+ : []),+ ...(plugins || []),+ ],+ );+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);+ const [canScrollNext, setCanScrollNext] = React.useState(false);++ const onSelect = React.useCallback((api: CarouselApi) => {+ if (!api) {+ return;+ }++ setCanScrollPrev(api.canScrollPrev());+ setCanScrollNext(api.canScrollNext());+ }, []);++ const scrollPrev = React.useCallback(() => {+ api?.scrollPrev();+ }, [api]);++ const scrollNext = React.useCallback(() => {+ api?.scrollNext();+ }, [api]);++ const handleKeyDown = React.useCallback(+ (event: React.KeyboardEvent<HTMLDivElement>) => {+ if (event.key === "ArrowLeft") {+ event.preventDefault();+ scrollPrev();+ } else if (event.key === "ArrowRight") {+ event.preventDefault();+ scrollNext();+ }+ },+ [scrollPrev, scrollNext],+ );++ React.useEffect(() => {+ if (!api || !setApi) {+ return;+ }++ setApi(api);+ }, [api, setApi]);++ React.useEffect(() => {+ if (!api) {+ return;+ }++ onSelect(api);+ api.on("reInit", onSelect);+ api.on("select", onSelect);++ return () => {+ api?.off("select", onSelect);+ };+ }, [api, onSelect]);++ return (+ <CarouselContext.Provider+ value={{+ carouselRef,+ api: api,+ opts,+ orientation:+ orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),+ scrollPrev,+ scrollNext,+ canScrollPrev,+ canScrollNext,+ }}+ >+ <div+ ref={ref}+ onKeyDownCapture={handleKeyDown}+ className={cn("relative", className)}+ role="region"+ aria-roledescription="carousel"+ {...props}+ >+ {children}+ </div>+ </CarouselContext.Provider>+ );+ },+);+Carousel.displayName = "Carousel";++const CarouselContent = React.forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement>+>(({ className, ...props }, ref) => {+ const { carouselRef, orientation } = useCarousel();++ return (+ <div ref={carouselRef} className="overflow-hidden">+ <div+ ref={ref}+ className={cn(+ "flex",+ orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",+ className,+ )}+ {...props}+ />+ </div>+ );+});+CarouselContent.displayName = "CarouselContent";++const CarouselItem = React.forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement>+>(({ className, ...props }, ref) => {+ const { orientation } = useCarousel();++ return (+ <div+ ref={ref}+ role="group"+ aria-roledescription="slide"+ className={cn(+ "min-w-0 shrink-0 grow-0 basis-full",+ orientation === "horizontal" ? "pl-4" : "pt-4",+ className,+ )}+ {...props}+ />+ );+});+CarouselItem.displayName = "CarouselItem";++const CarouselPrevious = React.forwardRef<+ HTMLButtonElement,+ { className?: string }+>(({ className, ...props }, ref) => {+ const { orientation, scrollPrev, canScrollPrev } = useCarousel();++ return (+ <button+ ref={ref}+ className={cn(+ "absolute",+ orientation === "horizontal"+ ? "-left-12 top-1/2 -translate-y-1/2"+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90",+ buttonVariants({ variant: "secondary", className: "p-2" }),+ className,+ )}+ disabled={!canScrollPrev}+ onClick={scrollPrev}+ {...props}+ >+ <ArrowLeft className="h-4 w-4" />+ <span className="sr-only">Previous slide</span>+ </button>+ );+});+CarouselPrevious.displayName = "CarouselPrevious";++const CarouselNext = React.forwardRef<+ HTMLButtonElement,+ { className?: string }+>(({ className, ...props }, ref) => {+ const { orientation, scrollNext, canScrollNext } = useCarousel();++ return (+ <button+ ref={ref}+ className={cn(+ "absolute",+ orientation === "horizontal"+ ? "-right-12 top-1/2 -translate-y-1/2"+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",+ buttonVariants({ variant: "secondary", className: "p-2" }),+ className,+ )}+ disabled={!canScrollNext}+ onClick={scrollNext}+ {...props}+ >+ <ArrowRight className="h-4 w-4" />+ <span className="sr-only">Next slide</span>+ </button>+ );+});+CarouselNext.displayName = "CarouselNext";++const CarouselNavBarVariants = cva(+ "flex items-center justify-center gap-3 sm:gap-6",+ {+ variants: {+ variant: {+ simple: "relative",+ floating:+ "absolute bottom-4 left-1/2 -translate-x-1/2 rounded-full border border-gray-800/10 bg-white sm:bottom-6 ",+ },+ },+ },+);++const CarouselNavBar = ({+ variant = "simple",+ className,+}: VariantProps<typeof CarouselNavBarVariants> & { className?: string }) => {+ const { scrollNext, scrollPrev, canScrollNext, canScrollPrev, api } =+ useCarousel();++ const autoplay = api?.plugins()?.autoplay;++ const [selectedIndex, setSelectedIndex] = React.useState(0);++ const [isPlaying, setIsPlaying] = React.useState(false);++ const onSelect = React.useCallback((api: any) => {+ setSelectedIndex(api.selectedScrollSnap());+ }, []);++ const stopAutoplayAnd = React.useCallback(+ (fn: any) => () => {+ if (autoplay && autoplay.isPlaying()) autoplay.stop();+ fn();+ },+ [autoplay],+ );++ React.useEffect(() => {+ if (!api) return;++ onSelect(api);+ setIsPlaying(autoplay?.isPlaying() ?? false);+ api.on("reInit", onSelect);+ api.on("select", onSelect);+ api.on("autoplay:play", () => setIsPlaying(true));+ api.on("autoplay:stop", () => setIsPlaying(false));+ }, [api, autoplay, onSelect]);++ return (+ <div className={cn(CarouselNavBarVariants({ variant }), className)}>+ {variant !== "simple" && (+ <button+ className="cursor-pointer rounded-full p-2 hover:bg-gray-50 active:bg-gray-100"+ disabled={!canScrollPrev}+ onClick={stopAutoplayAnd(scrollPrev)}+ >+ <ChevronLeft className="h-4 w-4" />+ <span className="sr-only">Previous slide</span>+ </button>+ )}++ {api != null && (+ <div className="flex items-center gap-1">+ {api.slideNodes().map((_, idx) => (+ <button+ key={idx}+ onClick={stopAutoplayAnd(() => api.scrollTo(idx))}+ className="rounded-full p-0.5 hover:bg-gray-100 active:bg-gray-200 sm:p-1.5"+ >+ <div+ className={cn(+ "relative isolate h-1.5 w-1.5 overflow-hidden rounded-full transition-all",+ idx === selectedIndex ? "bg-black" : "bg-black/20",+ isPlaying && idx === selectedIndex && "w-6 bg-black/20",+ )}+ >+ {isPlaying && idx === selectedIndex && (+ <motion.div+ initial={{ x: "-100%" }}+ animate={{ x: 0 }}+ transition={{+ type: "tween",+ duration:+ (autoplay?.options.delay ?? AUTOPLAY_DEFAULT_DELAY) /+ 1000,+ }}+ className="animate-fill-width h-full w-full rounded-full bg-black"+ />+ )}+ </div>+ <span className="sr-only">Slide {idx + 1}</span>+ </button>+ ))}+ </div>+ )}++ {variant !== "simple" && (+ <button+ className="cursor-pointer rounded-full p-2 hover:bg-gray-50 active:bg-gray-100"+ disabled={!canScrollNext}+ onClick={stopAutoplayAnd(scrollNext)}+ >+ <ChevronRight className="h-4 w-4" />+ <span className="sr-only">Next slide</span>+ </button>+ )}+ </div>+ );+};++export {+ Carousel,+ CarouselContent,+ CarouselItem,+ CarouselNavBar,+ CarouselNext,+ CarouselPrevious,+ type CarouselApi,+};diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsxindex 0ba31731a2..067d947bcf 100644--- a/packages/ui/src/index.tsx+++ b/packages/ui/src/index.tsx@@ -4,10 +4,12 @@ import "./styles.css";// componentsexport * from "./accordion";export * from "./alert";+export * from "./asset-image";export * from "./avatar";export * from "./badge";export * from "./button";export * from "./card-list";+export * from "./carousel";export * from "./checkbox";export * from "./date-picker";export * from "./file-upload";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 1b2df55dda..020bf5edc2 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -490,6 +490,12 @@ importers:date-fns:specifier: ^3.6.0version: 3.6.0+ embla-carousel-autoplay:+ specifier: ^8.1.7+ version: 8.1.7([email protected])+ embla-carousel-react:+ specifier: ^8.1.7+ version: 8.1.7([email protected])framer-motion:specifier: ^10.16.16version: 10.18.0([email protected])([email protected])@@ -11173,6 +11179,36 @@ packages:resolution: {integrity: sha512-aoCqgU6r9+o9/S7wkcSbmPRFi7OWZWiXS9rtjEd+Ouyu/Xyw5RSq2XN8s5Qp8IaFOLiRrhQCphCIjAxgG3eCAg==}+ resolution: {integrity: sha512-UXt1XvCNwzC/Sqd7iU8nYd1CjuDLweIwJClfBL3gVTzHQBVwb68GBBfC/oPFsEeIWNUZe8NO5xDQSI9aTnYO7Q==}+ peerDependencies:+ embla-carousel: 8.1.7+ dependencies:+ embla-carousel: 8.1.7+ dev: false++ resolution: {integrity: sha512-ermMKzQ46LhXE4f81VBCVGxCJWvZfsu504dkyiUDO+cnEEPW8NlC2PpKULmiOWugusYWRLhQLjmyQs3b8vvOjA==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.1 || ^18.0.0+ dependencies:+ embla-carousel: 8.1.7+ embla-carousel-reactive-utils: 8.1.7([email protected])+ react: 18.2.0+ dev: false++ resolution: {integrity: sha512-FDPcWjNtW04KSuvSfGbVeoB8yl5no3E0++HikO/uW12cNkMnWt68C4OBOakZQZlpUdRQSA9KCYoBuQzfpVGvZQ==}+ peerDependencies:+ embla-carousel: 8.1.7+ dependencies:+ embla-carousel: 8.1.7+ dev: false++ resolution: {integrity: sha512-b3kBr2H+S1gx4neki0P+aqN6cA5Ibjqy4CR3Ufi3X+Q3JpoNXJgOmJMSPkoP9DKcDREwADN6UWZzRwF2oo0y9Q==}+ dev: false+resolution: {integrity: sha512-uDfvUjVrfGJJhymx/kz6prltenw1u7WrCg1oa94zYY8xxVpLLUu045LAT0dhDZdXG58/EpPL/5kA180fQ/qudg==}engines: {node: '>=10'}