www: fully remove component gallery (#2430)

This commit is contained in:
Marvin Hagemeister
2024-05-17 18:39:32 +02:00
committed by GitHub
parent e126196fe5
commit 25d4d16a8f
31 changed files with 0 additions and 1079 deletions
-11
View File
@@ -1,11 +0,0 @@
import { JSX } from "preact";
export default function Background(props: JSX.HTMLAttributes<HTMLDivElement>) {
return (
<div
{...props}
class="bg-gray-200 py-16 px-8 flex gap-4 items-center justify-center rounded flex-wrap"
style="background-image: url(/gallery/grid.svg)"
/>
);
}
-14
View File
@@ -1,14 +0,0 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";
export default function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
return (
<button
{...props}
disabled={!IS_BROWSER || props.disabled}
class={`px-3 py-2 bg-white rounded border(gray-500 2) hover:bg-gray-200 active:bg-gray-300 disabled:(opacity-50 cursor-not-allowed) ${
props.class ?? ""
}`}
/>
);
}
-204
View File
@@ -1,204 +0,0 @@
import { asset } from "$fresh/runtime.ts";
import { useSignal } from "@preact/signals";
import { useEffect, useRef } from "preact/hooks";
import IconCircleChevronsRight from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/circle-chevrons-right.tsx";
import IconCircleChevronsLeft from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/circle-chevrons-left.tsx";
const SLIDE_DATA = [
{
color: "bg-green-300",
text: "slide one",
url: asset("/illustration/deno-plush.svg"),
},
{
color: "bg-yellow-300",
text: "slide two",
url: asset("/illustration/lemon-squash.svg"),
},
{
color: "bg-blue-300",
text: "slide three",
url: asset("/illustration/deno-plush.svg"),
},
{
color: "bg-yellow-300",
text: "slide four",
url: asset("/illustration/lemon-squash.svg"),
},
];
type SlideProps = {
class?: string;
key?: number;
data: {
color: string;
text: string;
url: string;
};
};
const Slide = (props: SlideProps) => {
const { key, data } = props;
const { color, text, url } = data;
if (props.class === undefined) props.class = "";
return (
<div
key={key}
class={`${props.class} ${color} h-80 w-full text-center text-black p-5`}
>
{text}
<img src={url} alt={text} />
</div>
);
};
type CarouselProps = {
showNavigation?: boolean;
interval?: number;
currentSlide?: number;
automatic?: boolean;
class?: string;
};
const Carousel = (props: CarouselProps) => {
const NAVIGATION_COLOR = `hover:text-gray-300 text-white`;
const CHEVRON_STYLE =
`absolute z-30 w-10 h-10 ${NAVIGATION_COLOR} cursor-pointer`;
const SHOW_NAVIGATION = props.showNavigation === false ? false : true;
const SLIDE_INTERVAL = props.interval ? props.interval : 3500;
const currentSlide = useSignal(props.currentSlide ? props.currentSlide : 0);
const automatic = useSignal(props.automatic === false ? false : true);
const slideshowRef = useRef<HTMLDivElement>(null);
const slideClasses = (idx = 0) => {
let outgoingSlide = currentSlide.value - 1;
let incomingSlide = currentSlide.value + 1;
if (outgoingSlide === -1) outgoingSlide = SLIDE_DATA.length - 1;
if (incomingSlide === SLIDE_DATA.length) incomingSlide = 0;
const TRANSITION_CLASS = () => {
if (currentSlide.value === idx) return "translate-x-0 z-20";
if (incomingSlide === idx) return "translate-x-full z-10";
if (outgoingSlide === idx) return "-translate-x-full z-10";
return "translate-x-full";
};
return `slide absolute top-0 left-0 transition-all ease-in-out duration-700 transform ${TRANSITION_CLASS()}`;
};
const nextSlide = () => {
if (SLIDE_DATA.length === currentSlide.value + 1) {
currentSlide.value = 0;
} else {
currentSlide.value++;
}
};
const previousSlide = () => {
if (currentSlide.value === 0) {
currentSlide.value = SLIDE_DATA.length - 1;
} else {
currentSlide.value--;
}
};
const chevronClick = (doCallback = () => {}) => {
if (automatic.value) automatic.value = false;
return doCallback();
};
useEffect(() => {
const interval = setInterval(() => {
if (automatic.value) nextSlide();
}, SLIDE_INTERVAL);
return () => clearInterval(interval);
}, []);
const ArrowKeyNavigation = () => {
const keydownHandler = (event: KeyboardEvent) => {
if (automatic.value) automatic.value = false;
switch (event.code) {
case "ArrowLeft":
event.preventDefault();
previousSlide();
break;
case "ArrowRight":
event.preventDefault();
nextSlide();
break;
default:
break;
}
};
slideshowRef.current?.addEventListener("keydown", keydownHandler);
return () =>
slideshowRef.current?.removeEventListener("keydown", keydownHandler);
};
useEffect(ArrowKeyNavigation, []);
const goToSlide = (slide_index = 0) => {
if (automatic.value) automatic.value = false;
currentSlide.value = slide_index;
};
const DotsNavigation = () => (
<div class={"slide_nav z-30 w-full absolute bottom-0 flex justify-center"}>
{SLIDE_DATA.map((_item, idx) => {
return (
<button
class={`px-1 ${NAVIGATION_COLOR}`}
onClick={() => {
goToSlide(idx);
}}
key={idx}
>
<span class="sr-only">Go to slide {idx}</span>
{idx === currentSlide.value
? <span class="not-sr-only">●</span>
: <span class="not-sr-only">○</span>}
</button>
);
})}
</div>
);
return (
<div
ref={slideshowRef}
class={`slideshow relative flex-1 flex-end p-0 overflow-hidden ${
props.class !== undefined ? props.class : ""
}`}
tabIndex={0}
>
<button
class={`left-0 ${CHEVRON_STYLE}`}
style="top: calc(50% - 20px)"
onClick={() => chevronClick(previousSlide)}
>
<IconCircleChevronsLeft class="w-10 h-10" aria-hidden="true" />
<span class="sr-only">Previous slide</span>
</button>
<button
class={`right-0 ${CHEVRON_STYLE}`}
style="top: calc(50% - 20px)"
onClick={() => chevronClick(nextSlide)}
>
<IconCircleChevronsRight class="w-10 h-10" aria-hidden="true" />
<span class="sr-only">Next slide</span>
</button>
{SLIDE_DATA.map((item, idx) => (
<Slide
data={item}
key={idx}
class={slideClasses(idx)}
/>
))}
{SHOW_NAVIGATION &&
<DotsNavigation />}
<Slide
data={SLIDE_DATA[0]}
class="opacity-0 pointer-events-none"
/>
</div>
);
};
export default Carousel;
-44
View File
@@ -1,44 +0,0 @@
import { useSignal } from "@preact/signals";
import Prism from "https://esm.sh/prismjs@1.29.0";
import "https://esm.sh/prismjs@1.29.0/components/prism-typescript?no-check";
interface CodeBoxProps {
code: string;
}
export default function CodeBox(props: CodeBoxProps) {
const highlighted = Prism.highlight(
props.code,
Prism.languages.typescript,
"typescript",
);
const onCopy = () => {
navigator.clipboard.writeText(props.code);
copied.value = true;
};
const copied = useSignal(false);
return (
<div class="">
<details>
<summary class="text-center cursor-pointer bg-gray-50 select-none text-gray-600 hover:text-gray-800 hover:bg-gray-100 py-2 rounded-b">
Code
</summary>
<div class="relative">
<pre class="bg-gray-800 text-blue-300 p-2 text-sm rounded whitespace-pre-wrap">
<code
dangerouslySetInnerHTML={{ __html: highlighted }}
/>
</pre>
<button
onClick={onCopy}
class="absolute top-2 right-2 px-3 py-2 border border-gray-400 rounded text-white bg-gray-800"
>
{copied.value ? "Copied!" : "Copy"}
</button>
</div>
</details>
</div>
);
}
-14
View File
@@ -1,14 +0,0 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";
export default function ColoredButton(
props: JSX.HTMLAttributes<HTMLButtonElement>,
) {
return (
<button
{...props}
disabled={!IS_BROWSER || props.disabled}
class="px-3 py-2 bg-blue-200 text-blue-800 rounded hover:bg-blue-300 active:bg-blue-400"
/>
);
}
-55
View File
@@ -1,55 +0,0 @@
import IconAlarm from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/alarm.tsx";
import IconAirBalloon from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/air-balloon.tsx";
import IconArmchair from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/armchair.tsx";
import IconChevronRight from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/chevron-right.tsx";
export default function Features() {
const featureItems = [
{
icon: IconAlarm,
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut aliquam aliquam",
link: "#",
},
{
icon: IconAirBalloon,
description:
"Nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl, ",
},
{
icon: IconArmchair,
description: "Eget aliquam nisl nisl sit amet lorem.",
link: "#",
},
];
return (
<div class="flex flex-col md:flex-row gap-8 bg-white p-8">
{featureItems.map((item) => {
return (
<div class="flex-1 space-y-2">
<div class="bg-blue-600 inline-block p-3 rounded-xl text-white">
<item.icon class="w-10 h-10" aria-hidden="true" />
</div>
<p class="text-xl">
{item.description}
</p>
{item.link &&
(
<a class="block" href={item.link}>
<p class="text-blue-600 cursor-pointer hover:underline inline-flex items-center group">
Read More{" "}
<IconChevronRight
class="inline-block w-5 h-5 transition group-hover:translate-x-0.5"
aria-hidden="true"
/>
</p>
</a>
)}
</div>
);
})}
</div>
);
}
-73
View File
@@ -1,73 +0,0 @@
import LemonIcon from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/lemon-2.tsx";
import BrandGithub from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/brand-github.tsx";
export default function Footer() {
const menus = [
{
title: "Documentation",
children: [
{ name: "Getting Started", href: "#" },
{ name: "Guide", href: "#" },
{ name: "API", href: "#" },
{ name: "Showcase", href: "#" },
{ name: "Pricing", href: "#" },
],
},
{
title: "Community",
children: [
{ name: "Forum", href: "#" },
{ name: "Discord", href: "#" },
],
},
];
return (
<div class="bg-white flex flex-col md:flex-row w-full max-w-screen-lg gap-8 md:gap-16 px-8 py-8 text-sm">
<div class="flex-1">
<div class="flex items-center gap-1">
<LemonIcon class="inline-block" aria-hidden="true" />
<div class="font-bold text-2xl">
Fresh
</div>
</div>
<div class="text-gray-500">
Full Stack Framework
</div>
</div>
{menus.map((item) => (
<div class="mb-4" key={item.title}>
<div class="font-bold">{item.title}</div>
<ul class="mt-2">
{item.children.map((child) => (
<li class="mt-2" key={child.name}>
<a
class="text-gray-500 hover:text-gray-700"
href={child.href}
>
{child.name}
</a>
</li>
))}
</ul>
</div>
))}
<div class="text-gray-500 space-y-2">
<div class="text-xs">
Copyright © 2020 DenoLand<br />
All right reserved.
</div>
<a
href="https://github.com/denoland/fresh"
class="inline-block hover:text-black"
aria-label="GitHub"
>
<BrandGithub aria-hidden="true" />
</a>
</div>
</div>
);
}
-37
View File
@@ -1,37 +0,0 @@
import LemonIcon from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/lemon-2.tsx";
type Props = {
active: string;
};
export default function Header({ active }: Props) {
const menus = [
{ name: "Home", href: "/" },
// { name: "Components", href: "/components" },
{ name: "Docs", href: "/docs" },
];
return (
<div class="bg-white w-full max-w-screen-lg py-6 px-8 flex flex-col md:flex-row gap-4">
<div class="flex items-center flex-1">
<LemonIcon aria-hidden="true" />
<div class="text-2xl ml-1 font-bold">
Fresh
</div>
</div>
<ul class="flex items-center gap-6">
{menus.map((menu) => (
<li>
<a
href={menu.href}
class={"text-gray-500 hover:text-gray-700 py-1 border-gray-500" +
(menu.href === active ? " font-bold border-b-2" : "")}
>
{menu.name}
</a>
</li>
))}
</ul>
</div>
);
}
-37
View File
@@ -1,37 +0,0 @@
import IconChevronRight from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/chevron-right.tsx";
export default function Hero() {
return (
<div
class="w-full flex px-8 py-10 min-h-[24em] justify-center items-center flex-col gap-8 bg-cover bg-center bg-no-repeat bg-gray-100 rounded-xl text-white"
style="background-image:linear-gradient(rgba(0, 0, 40, 0.8),rgba(0, 0, 40, 0.8)), url('/gallery/hero-bg.webp');"
>
<div class="space-y-4 text-center">
<h1 class="text-4xl inline-block font-bold">Fresh Components Beta</h1>
<p class="text-xl max-w-lg text-blue-100">
Fresh Components is a collection of components built with Preact and
Tailwind CSS.
</p>
</div>
<div class="flex flex-col md:flex-row items-center">
<a
href="#"
class="block mt-4 text-blue-600 cursor-pointer inline-flex items-center group text-blue-800 bg-white px-8 py-2 rounded-md hover:bg-blue-50 font-bold"
>
Sign Up{" "}
</a>
<a
href="#"
class="block mt-4 transition-colors text-blue-400 cursor-pointer inline-flex items-center group px-4 py-2 hover:text-blue-100"
>
Documentation{" "}
<IconChevronRight
class="inline-block w-5 h-5 transition group-hover:translate-x-0.5"
aria-hidden="true"
/>
</a>
</div>
</div>
);
}
-14
View File
@@ -1,14 +0,0 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";
export default function Input(props: JSX.HTMLAttributes<HTMLInputElement>) {
return (
<input
{...props}
disabled={!IS_BROWSER || props.disabled}
class={`px-3 py-2 bg-white rounded border(gray-500 2) disabled:(opacity-50 cursor-not-allowed) ${
props.class ?? ""
}`}
/>
);
}
-14
View File
@@ -1,14 +0,0 @@
import { JSX } from "preact";
export default function LinkButton(
props: JSX.HTMLAttributes<HTMLAnchorElement>,
) {
return (
<a
{...props}
class={`inline-block cursor-pointer px-3 py-2 bg-white rounded hover:bg-gray-100 ${
props.class ?? ""
}`}
/>
);
}
-2
View File
@@ -17,8 +17,6 @@
"$std/": "https://deno.land/std@0.216.0/",
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts",
"$marked-mangle": "https://esm.sh/marked-mangle@1.1.7",
"$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.8.0/mod.ts",
"$fresh-testing-library/": "https://deno.land/x/fresh_testing_library@0.8.0/",
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/": "npm:/tailwindcss@3.4.1/",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js"
-2
View File
@@ -17,7 +17,6 @@ import * as $recipes_lemonade from "./routes/recipes/lemonade.tsx";
import * as $recipes_lemondrop from "./routes/recipes/lemondrop.tsx";
import * as $showcase from "./routes/showcase.tsx";
import * as $update from "./routes/update.tsx";
import * as $ComponentGallery from "./islands/ComponentGallery.tsx";
import * as $CopyArea from "./islands/CopyArea.tsx";
import * as $Counter from "./islands/Counter.tsx";
import * as $LemonBottom from "./islands/LemonBottom.tsx";
@@ -47,7 +46,6 @@ const manifest = {
"./routes/update.tsx": $update,
},
islands: {
"./islands/ComponentGallery.tsx": $ComponentGallery,
"./islands/CopyArea.tsx": $CopyArea,
"./islands/Counter.tsx": $Counter,
"./islands/LemonBottom.tsx": $LemonBottom,
-125
View File
@@ -1,125 +0,0 @@
import Button from "../components/gallery/Button.tsx";
import LinkButton from "../components/gallery/LinkButton.tsx";
import ColoredButton from "../components/gallery/ColoredButton.tsx";
import Input from "../components/gallery/Input.tsx";
import Header from "../components/gallery/Header.tsx";
import Footer from "../components/gallery/Footer.tsx";
import Hero from "../components/gallery/Hero.tsx";
import Features from "../components/gallery/Features.tsx";
import Carousel from "../components/gallery/Carousel.tsx";
import { ComponentChildren } from "preact";
import IconHappy from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/mood-crazy-happy.tsx";
import IconHeart from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/heart.tsx";
import Background from "../components/gallery/Background.tsx";
import CodeBox from "../components/gallery/CodeBox.tsx";
interface SectionProps {
title: string;
children: ComponentChildren;
source: string;
island?: boolean;
}
function Section(props: SectionProps) {
return (
<div>
<h2 class="text-2xl font-bold py-2" id={props.title}>
{props.title}
{props.island && (
<span class="text-sm font-normal inline-block bg-green-200 rounded px-2 mx-2">
island
</span>
)}
</h2>
<Background>
{props.children}
</Background>
<CodeBox code={props.source} />
</div>
);
}
interface ComponentGalleryProps {
sources: Record<string, string>;
}
export default function ComponentGallery(props: ComponentGalleryProps) {
return (
<>
<Section
title="Button"
island={true}
source={props.sources.Button}
>
<Button>
Click me
</Button>
<Button class="flex gap-1">
<IconHappy
class="w-6 h-6 inline-block text-gray-500"
aria-hidden="true"
/>
<div>
With an Icon
</div>
</Button>
<Button disabled>
Disabled
</Button>
</Section>
<Section
title="ColoredButton"
island={true}
source={props.sources.ColoredButton}
>
<ColoredButton>
Click me
</ColoredButton>
</Section>
<Section
title="LinkButton"
source={props.sources.LinkButton}
>
<LinkButton>
<IconHeart
class="w-5 h-5 mr-1 inline-block text-gray-400"
aria-hidden="true"
/>
Like me
</LinkButton>
</Section>
<Section
title="Input"
island={true}
source={props.sources.Input}
>
<Input placeholder="Placeholder" />
<Input placeholder="Disabled" disabled />
</Section>
<Section title="Header" source={props.sources.Header}>
<Header active="/" />
</Section>
<Section title="Footer" source={props.sources.Footer}>
<Footer />
</Section>
<Section title="Hero" source={props.sources.Hero}>
<Hero />
</Section>
<Section title="Features" source={props.sources.Features}>
<Features />
</Section>
<Section title="Carousel" island={true} source={props.sources.Carousel}>
<Carousel />
</Section>
</>
);
}