Skip to content

Commit

Permalink
style: 馃拕 added screenshots Carousel in landing page hero secito
Browse files Browse the repository at this point in the history
  • Loading branch information
growupanand committed Feb 3, 2024
1 parent d815517 commit f8b5e1e
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 8 deletions.
Binary file modified apps/web/public/screenshots/formEditor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/web/public/screenshots/responses.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions apps/web/src/components/landingPage/hero.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import Image from "next/image";
import Link from "next/link";
import { AspectRatio } from "@convoform/ui/components/ui/aspect-ratio";
import { Badge } from "@convoform/ui/components/ui/badge";
import { Button } from "@convoform/ui/components/ui/button";
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselNext,
CarouselPrevious,
} from "@convoform/ui/components/ui/carousel";
import { ChevronRight } from "lucide-react";

import { montserrat } from "@/app/fonts";
Expand Down Expand Up @@ -71,6 +79,32 @@ export function Hero() {
</LinkN>
</Button>
</div>
<div className="mt-[100px] max-lg:hidden">
<Carousel className="shadow-lg">
<CarouselContent>
<CarouselItem>
<AspectRatio ratio={16 / 9}>
<Image
alt="screenshot of form editor"
src="/screenshots/formEditor.png"
fill
/>
</AspectRatio>
</CarouselItem>
<CarouselItem>
<AspectRatio ratio={16 / 9}>
<Image
alt="screenshot of responses page"
src="/screenshots/responses.png"
fill
/>
</AspectRatio>
</CarouselItem>
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>
</div>
</section>
);
}
18 changes: 10 additions & 8 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@headlessui/tailwindcss": "^0.2.0",
"@hookform/resolvers": "^3.3.2",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-aspect-ratio": "^1.0.3",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
Expand All @@ -30,23 +31,24 @@
"@tremor/react": "^3.13.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"embla-carousel-react": "8.0.0-rc22",
"lucide-react": "^0.292.0",
"react": "^18",
"react-hook-form": "^7.48.2",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.8.0",
"react": "^18",
"react-hook-form": "^7.48.2"
"vaul": "^0.8.0"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"typescript": "^5",
"postcss": "^8",
"@convoform/eslint-config": "workspace:*",
"@convoform/tsconfig": "workspace:*",
"@tailwindcss/forms": "^0.5.7",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/node": "^20",
"tailwindcss": "^3.3.0"
"postcss": "^8",
"tailwindcss": "^3.3.0",
"typescript": "^5"
},
"exports": {
"./globals.css": "./src/globals.css",
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/components/ui/aspect-ratio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client";

import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio";

const AspectRatio = AspectRatioPrimitive.Root;

export { AspectRatio };
262 changes: 262 additions & 0 deletions packages/ui/src/components/ui/carousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
"use client";

import * as React from "react";
import useEmblaCarousel, {
type UseEmblaCarouselType,
} from "embla-carousel-react";
import { ArrowLeft, ArrowRight } from "lucide-react";

import { cn } from "../../lib/utils";
import { Button } from "./button";

type CarouselApi = UseEmblaCarouselType[1];
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
type CarouselOptions = UseCarouselParameters[0];
type CarouselPlugin = UseCarouselParameters[1];

type CarouselProps = {
opts?: CarouselOptions;
plugins?: CarouselPlugin;
orientation?: "horizontal" | "vertical";
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);

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,
plugins,
className,
children,
...props
},
ref,
) => {
const [carouselRef, api] = useEmblaCarousel(
{
...opts,
axis: orientation === "horizontal" ? "x" : "y",
},
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,
React.ComponentProps<typeof Button>
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
const { orientation, scrollPrev, canScrollPrev } = useCarousel();

return (
<Button
ref={ref}
variant={variant}
size={size}
className={cn(
"absolute h-8 w-8 rounded-full",
orientation === "horizontal"
? "-left-12 top-1/2 -translate-y-1/2"
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
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,
React.ComponentProps<typeof Button>
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
const { orientation, scrollNext, canScrollNext } = useCarousel();

return (
<Button
ref={ref}
variant={variant}
size={size}
className={cn(
"absolute h-8 w-8 rounded-full",
orientation === "horizontal"
? "-right-12 top-1/2 -translate-y-1/2"
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
className,
)}
disabled={!canScrollNext}
onClick={scrollNext}
{...props}
>
<ArrowRight className="h-4 w-4" />
<span className="sr-only">Next slide</span>
</Button>
);
});
CarouselNext.displayName = "CarouselNext";

export {
type CarouselApi,
Carousel,
CarouselContent,
CarouselItem,
CarouselPrevious,
CarouselNext,
};

0 comments on commit f8b5e1e

Please sign in to comment.