add Fresh Components (#872)

This commit is contained in:
hashrock
2022-11-07 22:24:32 +09:00
committed by GitHub
parent ff7cac13dd
commit fea7a27029
19 changed files with 450 additions and 25 deletions
+2 -2
View File
@@ -1,13 +1,13 @@
import DocsTitle from "./DocsTitle.tsx";
export default function DocsHeader() {
export default function DocsHeader(props: { title: string }) {
return (
<div class="bg-green-300">
<header class="mx-auto max-w-screen-lg flex gap-3 justify-between">
<div class="p-4 flex">
<Logo />
<div>
<DocsTitle />
<DocsTitle title={props.title} />
</div>
</div>
<label
+2 -2
View File
@@ -1,4 +1,4 @@
export default function DocsTitle() {
export default function DocsTitle(props: { title: string }) {
return (
<>
<a
@@ -18,7 +18,7 @@ export default function DocsTitle() {
fill="#0A140C"
/>
</svg>
<span class="font-light block pb-[1px]">docs</span>
<span class="font-light block pb-[1px]">{props.title}</span>
</a>
<p class="text(sm gray-700)">The next-gen web framework.</p>
</>
+4
View File
@@ -12,6 +12,10 @@ export default function NavigationBar(props: { active: string }) {
name: "Showcase",
href: "/showcase",
},
{
name: "Components",
href: "/components",
},
];
return (
+11
View File
@@ -0,0 +1,11 @@
import { JSX } from "preact";
export default function Background(props: JSX.HTMLAttributes<HTMLDivElement>) {
return (
<div
{...props}
class="bg-gray-200 py-16 px-8 flex items-center justify-center rounded"
style="background-image: url(/gallery/grid.svg)"
/>
);
}
+14
View File
@@ -0,0 +1,14 @@
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 disabled:(opacity-50 cursor-not-allowed) ${
props.class ?? ""
}`}
/>
);
}
+43
View File
@@ -0,0 +1,43 @@
import { useState } from "preact/hooks";
import Prism from "https://esm.sh/prismjs@1.27.0";
import "https://esm.sh/prismjs@1.27.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);
setCopied(true);
};
const [copied, setCopied] = useState(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>
<code class="relative">
<pre
class="bg-gray-800 text-blue-300 p-2 text-sm rounded whitespace-pre-wrap"
dangerouslySetInnerHTML={{ __html: highlighted }}
/>
<button
onClick={onCopy}
class="absolute top-2 right-2 px-3 py-2 border border-gray-400 rounded text-white"
>
{copied ? "Copied!" : "Copy"}
</button>
</code>
</details>
</div>
);
}
+14
View File
@@ -0,0 +1,14 @@
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"
/>
);
}
+76
View File
@@ -0,0 +1,76 @@
import { ComponentChildren } from "preact";
import LemonIcon from "https://deno.land/x/tabler_icons_tsx@0.0.1/tsx/lemon-2.tsx";
import BrandGithub from "https://deno.land/x/tabler_icons_tsx@0.0.1/tsx/brand-github.tsx";
type Props = {
children: ComponentChildren;
};
export default function Footer({ children }: Props) {
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 w-full max-w-screen-lg gap-16 px-8 py-8 text-sm">
<div class="flex-1">
<div class="flex items-center gap-1">
<LemonIcon class="inline-block" />
<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"
>
<BrandGithub />
</a>
</div>
</div>
);
}
+35
View File
@@ -0,0 +1,35 @@
import LemonIcon from "https://deno.land/x/tabler_icons_tsx@0.0.1/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 items-center justify-center">
<LemonIcon />
<div class="text-2xl flex-1 ml-1 font-bold">
Fresh
</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>
);
}
+14
View File
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,14 @@
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 ?? ""
}`}
/>
);
}
+22 -18
View File
@@ -5,31 +5,35 @@
import config from "./deno.json" assert { type: "json" };
import * as $0 from "./routes/_404.tsx";
import * as $1 from "./routes/_500.tsx";
import * as $2 from "./routes/docs/[...slug].tsx";
import * as $3 from "./routes/gfm.css.ts";
import * as $4 from "./routes/index.tsx";
import * as $5 from "./routes/raw.ts";
import * as $6 from "./routes/showcase.tsx";
import * as $7 from "./routes/update.tsx";
import * as $$0 from "./islands/CopyArea.tsx";
import * as $$1 from "./islands/Counter.tsx";
import * as $$2 from "./islands/LemonDrop.tsx";
import * as $2 from "./routes/components.tsx";
import * as $3 from "./routes/docs/[...slug].tsx";
import * as $4 from "./routes/gfm.css.ts";
import * as $5 from "./routes/index.tsx";
import * as $6 from "./routes/raw.ts";
import * as $7 from "./routes/showcase.tsx";
import * as $8 from "./routes/update.tsx";
import * as $$0 from "./islands/ComponentGallery.tsx";
import * as $$1 from "./islands/CopyArea.tsx";
import * as $$2 from "./islands/Counter.tsx";
import * as $$3 from "./islands/LemonDrop.tsx";
const manifest = {
routes: {
"./routes/_404.tsx": $0,
"./routes/_500.tsx": $1,
"./routes/docs/[...slug].tsx": $2,
"./routes/gfm.css.ts": $3,
"./routes/index.tsx": $4,
"./routes/raw.ts": $5,
"./routes/showcase.tsx": $6,
"./routes/update.tsx": $7,
"./routes/components.tsx": $2,
"./routes/docs/[...slug].tsx": $3,
"./routes/gfm.css.ts": $4,
"./routes/index.tsx": $5,
"./routes/raw.ts": $6,
"./routes/showcase.tsx": $7,
"./routes/update.tsx": $8,
},
islands: {
"./islands/CopyArea.tsx": $$0,
"./islands/Counter.tsx": $$1,
"./islands/LemonDrop.tsx": $$2,
"./islands/ComponentGallery.tsx": $$0,
"./islands/CopyArea.tsx": $$1,
"./islands/Counter.tsx": $$2,
"./islands/LemonDrop.tsx": $$3,
},
baseUrl: import.meta.url,
config,
+105
View File
@@ -0,0 +1,105 @@
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 { ComponentChildren } from "preact";
import IconHappy from "https://deno.land/x/tabler_icons_tsx@0.0.2/tsx/mood-crazy-happy.tsx";
import IconHeart from "https://deno.land/x/tabler_icons_tsx@0.0.2/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">
{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 ml-2">
<IconHappy class="w-6 h-6 inline-block text-gray-500" />
<div>
With an Icon
</div>
</Button>
<Button disabled class="ml-2">
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" />
Like me
</LinkButton>
</Section>
<Section
title="Input"
island={true}
source={props.sources.Input}
>
<Input placeholder="Placeholder" />
<Input class="ml-2" placeholder="Disabled" disabled />
</Section>
<Section title="Header" source={props.sources.Header}>
<Header active="/" />
</Section>
<Section title="Footer" source={props.sources.Footer}>
<Footer>
</Footer>
</Section>
</>
);
}
+80
View File
@@ -0,0 +1,80 @@
import PageFooter from "../components/Footer.tsx";
import DocsHeader from "../components/DocsHeader.tsx";
import NavigationBar from "../components/NavigationBar.tsx";
import ComponentGallery from "../islands/ComponentGallery.tsx";
import { Head } from "$fresh/runtime.ts";
import { Handlers, PageProps } from "$fresh/server.ts";
function getSource(path: string) {
return Deno.readTextFile(new URL(path, import.meta.url));
}
export const handler: Handlers<HomeProps> = {
async GET(req, ctx) {
const props: HomeProps = {
sources: {
"Button": await getSource("../components/gallery/Button.tsx"),
"LinkButton": await getSource("../components/gallery/LinkButton.tsx"),
"ColoredButton": await getSource(
"../components/gallery/ColoredButton.tsx",
),
"Input": await getSource("../components/gallery/Input.tsx"),
"Header": await getSource("../components/gallery/Header.tsx"),
"Footer": await getSource("../components/gallery/Footer.tsx"),
},
};
return ctx.render(props);
},
};
interface HomeProps {
sources: Record<string, string>;
}
export default function Home(props: PageProps<HomeProps>) {
return (
<div class="bg-white h-full">
<Head>
<title>Components | fresh</title>
<link
rel="stylesheet"
href="https://esm.sh/prismjs@1.27.0/themes/prism-dark.min.css"
/>
</Head>
<DocsHeader title="components" />
<NavigationBar active="/components" />
<section class="my-16 px(4 sm:6 md:8) mx-auto max-w-screen-lg space-y-5">
<h2 class="text(3xl gray-600) font-bold">
Fresh Components
</h2>
<p class="text-gray-600">
A collection of components made for Fresh.
</p>
</section>
<div class="p-4 mx-auto max-w-screen-lg space-y-24 mb-16">
<ComponentGallery sources={props.data.sources} />
<a class="block" href="https://tabler-icons-tsx.deno.dev/">
<div
style="background-image: url(/gallery/banner-tabler-icons.png)"
class="h-48 bg(cover no-repeat white) hover:opacity-50 hover:underline rounded"
>
<h2 class="text-4xl font-bold p-4">Icons</h2>
</div>
</a>
<a class="block" href="https://github.com/denoland/fresh_charts">
<div
style="background-image: url(/gallery/banner-chart.png)"
class="h-48 bg(cover no-repeat white) hover:opacity-50 hover:underline rounded"
>
<h2 class="text-4xl font-bold p-4">Charts</h2>
</div>
</a>
</div>
<PageFooter />
</div>
);
}
+2 -2
View File
@@ -59,7 +59,7 @@ export default function DocsPage(props: PageProps<Data>) {
{description && <meta name="description" content={description} />}
</Head>
<div class="flex flex-col min-h-screen">
<DocsHeader />
<DocsHeader title="docs" />
<NavigationBar active="/docs" />
<Main path={props.url.pathname} page={props.data.page} />
<Footer />
@@ -97,7 +97,7 @@ function MobileSidebar(props: { path: string }) {
/>
<div class="relative flex-1 flex flex-col w-[16rem] h-full bg-white border(r-2 gray-100)">
<div class="p-4 border(b-2 gray-100) bg-green-300">
<DocsTitle />
<DocsTitle title="docs" />
</div>
<nav class="pt-2 pb-16 px-4 overflow-x-auto">
<DocsSidebar path={props.path} />
+1 -1
View File
@@ -11,7 +11,7 @@ export default function ShowcasePage() {
<Head>
<title>Showcase | fresh</title>
</Head>
<DocsHeader />
<DocsHeader title="showcase" />
<NavigationBar active="/showcase" />
<div class="flex flex-col min-h-screen">
Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

+11
View File
@@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<style type="text/css">
circle { fill: #bbb; }
</style>
<defs>
<pattern id="grid" patternUnits="userSpaceOnUse" width="20" height="20">
<circle cx="10" cy="10" r="1"></circle>
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#grid)" />
</svg>

After

Width:  |  Height:  |  Size: 389 B