Change side-by-side sections to sticky (#2445)

This commit is contained in:
Josh Collinsworth
2024-05-22 12:08:41 -05:00
committed by GitHub
parent cda9bdec6f
commit 8ef3e89a8c
14 changed files with 186 additions and 44 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ export function CodeWindow(props: CodeWindowProps) {
return (
<div
{...props}
class={`rounded-lg bg-slate-700 overflow-hidden w-full max-w-full [&>*]:rounded-t-none ${
class={`-mx-4 sm:mx-0 w-[calc(100%+2rem)] sm:w-full sm:rounded-lg bg-slate-700 overflow-hidden sm:max-w-full [&>*]:rounded-t-none ${
props.class ?? ""
}`}
style={props.style}
+2 -1
View File
@@ -3,7 +3,8 @@ import { JSX } from "preact";
export function PageSection(props: JSX.HTMLAttributes<HTMLDivElement>) {
return (
<section
class={`w-full max-w-screen-xl mx-auto my-8 sm:my-16 md:my-24 lg:my-32 px-4 sm:px-8 lg:px-16 2xl:px-0 flex flex-col gap-8 md:gap-16 ${
id={props.id ?? ""}
class={`w-full max-w-screen-xl mx-auto my-16 md:my-24 lg:my-32 px-4 sm:px-8 lg:px-16 2xl:px-0 flex flex-col gap-8 md:gap-16 ${
props.class ?? ""
}`}
>
+1 -3
View File
@@ -24,11 +24,9 @@ export function SideBySide(props: SideBySideProps) {
lgSplitClass = "lg:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]";
}
const swapClass = props.reverseOnDesktop ? "swap-on-mobile" : "";
return (
<div
class={`grid grid-cols-1 items-center gap-8 md:gap-16 xl:gap-32 ${
class={`grid grid-cols-1 items-center gap-12 md:gap-16 xl:gap-32 ${
props.reverseOnDesktop ? "md:first:[&>*]:order-1" : ""
} ${mdSplitClass} ${lgSplitClass} ${props.class ?? ""}`}
>
+4 -7
View File
@@ -3,19 +3,16 @@ import { FancyLink } from "$fresh/www/components/FancyLink.tsx";
export function CTA() {
return (
<div
class="bg-gradient-to-br from-blue-100 via-green-200 to-yellow-100 pb-32"
style="clip-path: polygon(0% 10%, 0% 100%, 100% 100%, 100% 0%)"
>
<PageSection class="text-center">
<div class="relative mt-16">
<PageSection class="text-center bg-gradient-to-br from-blue-100 via-green-200 to-yellow-100 pb-32 md:pb-48 before:w-full before:bg-white before:h-16 md:before:h-32 xl:before:h-48 before:[clip-path:polygon(0%_0%,_100%_0%,_0%_100%)] z-0 before:absolute before:top-0 before:left-0">
<div class="flex flex-col gap-4">
<img
src="/lemon.svg"
alt="Illustration of a lemon sliced cleanly in half, suspended in midair as though frozen in time the instant after the cut, the juice flung from the edges"
class="w-full max-w-64 mx-auto mb-8"
class="w-full max-w-48 sm:max-w-64 -mt-24 mx-auto mb-8 relative z-0"
/>
<h2 class="text-3xl sm:text-4xl md:text-5xl lg:text-6xl text-gray-600 font-extrabold">
Time for a Fresh Start
Time for a Fresh start
</h2>
<div class="flex flex-col justify-start items-center gap-4">
<p class="text-xl">
+12 -16
View File
@@ -6,19 +6,19 @@ import { SectionHeading } from "$fresh/www/components/homepage/SectionHeading.ts
import { DemoBox } from "$fresh/www/components/homepage/DemoBox.tsx";
import { ExampleArrow } from "$fresh/www/components/homepage/ExampleArrow.tsx";
import { FancyLink } from "$fresh/www/components/FancyLink.tsx";
import { FormSubmitDemo } from "../../islands/FormSubmitDemo.tsx";
const routingCode = `import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
async POST(req, ctx) {
async POST(req) {
const form = await req.formData();
const email = form.get("email")?.toString();
// Save email to database here
// Do something with the form data here,
// then redirect user to thank you page
// Redirect user to thank you page.
const headers = new Headers();
headers.set("location", "/thanks-for-subscribing");
headers.set("location", "/thanks");
return new Response(null, {
status: 303,
headers,
@@ -28,9 +28,9 @@ export const handler: Handlers = {
export function FormsSection() {
return (
<PageSection>
<SideBySide mdColSplit="2/3" lgColSplit="2/3">
<div class="flex flex-col gap-4">
<PageSection id="forms-section">
<SideBySide mdColSplit="2/3" lgColSplit="2/3" class="!items-start">
<div class="flex flex-col gap-4 md:sticky md:top-4">
<div
role="img"
alt="Arrows routing and crossing each other emoji"
@@ -59,7 +59,7 @@ export function FormsSection() {
</SectionHeading>
<p>
Don't fight the browser. Fresh helps you handle form submissions and
other dynamic requests server-side, simply and easily.
other dynamic requests server-side, from any route.
</p>
<p>
Since Fresh is built on{" "}
@@ -77,14 +77,10 @@ export function FormsSection() {
lang="jsx"
/>
</CodeWindow>
{
/* <ExampleArrow />
<ExampleArrow />
<DemoBox>
<p>
TODO: something goes here.
</p>
</DemoBox> */
}
<FormSubmitDemo />
</DemoBox>
</div>
</SideBySide>
</PageSection>
+1 -1
View File
@@ -11,7 +11,7 @@ export function Hero(props: { origin: string }) {
<div class="bg-green-300 mt-0 pt-32 md:pt-48 !mb-0 bg-gradient-to-br from-blue-100 via-green-200 to-yellow-100">
<div class="md:grid grid-cols-5 gap-8 md:gap-16 items-center w-full max-w-screen-xl mx-auto px-4 md:px-8 lg:px-16 2xl:px-0">
<div class="flex-1 text-center md:text-left md:col-span-3 pb-8 md:pb-32">
<h2 class="text-4xl sm:text-5xl lg:text-6xl sm:tracking-tight sm:leading-none! font-extrabold">
<h2 class="text-[calc(1rem+4vw)] leading-tight sm:text-5xl lg:text-6xl sm:tracking-tight sm:leading-none! font-extrabold">
The simple, approachable, productive web framework
</h2>
<div class="mt-12 flex flex-wrap justify-center items-stretch md:justify-start gap-4">
+9 -5
View File
@@ -29,8 +29,13 @@ export default function Counter(props) {
export function IslandsSection() {
return (
<PageSection>
<SideBySide mdColSplit="3/2" lgColSplit="3/2" reverseOnDesktop={true}>
<div class="flex flex-col gap-4">
<SideBySide
mdColSplit="3/2"
lgColSplit="3/2"
reverseOnDesktop={true}
class="!items-start"
>
<div class="flex flex-col gap-4 md:sticky md:top-4">
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-beach text-fresh"
@@ -56,9 +61,8 @@ export function IslandsSection() {
JavaScript only where needed.
</p>
<p>
Because it's{" "}
<a href="https://preactjs.com/" class="underline">Preact</a>, you
get best-in-class performance, plus the convenience of{" "}
Because it's Preact, you get best-in-class performance, plus the
convenience of{" "}
<a href="https://preactjs.com/guide/v10/signals/" class="underline">
Signals
</a>.
+9 -4
View File
@@ -35,8 +35,13 @@ export const Recipes = () => (
export function PartialsSection() {
return (
<PageSection>
<SideBySide mdColSplit="3/2" lgColSplit="3/2" reverseOnDesktop={true}>
<div class="flex flex-col gap-4">
<SideBySide
mdColSplit="3/2"
lgColSplit="3/2"
reverseOnDesktop={true}
class="!items-start"
>
<div class="flex flex-col gap-4 md:sticky md:top-4">
<svg
role="img"
alt="Arrows transferring data down "
@@ -62,8 +67,8 @@ export function PartialsSection() {
<SectionHeading>Stream HTML straight from the server</SectionHeading>
<p>
Fresh Partials let you fetch HTML and update only the parts of the
page that need to change, without reloading the entire page.
Fresh Partials let you fetch HTML and slot it directly into the
page, without a full page reload.
</p>
<FancyLink href="/docs/concepts/partials" class="mt-4">
Learn more about Partials
+6 -4
View File
@@ -16,8 +16,8 @@ const serverCode = `export default function HomePage() {
export function RenderingSection() {
return (
<PageSection>
<SideBySide mdColSplit="2/3" lgColSplit="2/3">
<div class="flex flex-col gap-4">
<SideBySide mdColSplit="2/3" lgColSplit="2/3" class="!items-start">
<div class="flex flex-col gap-4 md:sticky md:top-4">
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-atom text-fresh"
@@ -41,8 +41,10 @@ export function RenderingSection() {
Build fast apps fast
</SectionHeading>
<p>
Fresh routes are dynamically server-rendered Preact components, so
there's zero JavaScript shipped to the browser by default.
Fresh routes are dynamically server-rendered{" "}
<a href="https://preactjs.com/" class="underline">Preact</a>{" "}
components, so there's zero JavaScript shipped to the browser by
default.
</p>
<p>Simple to write; fast to run.</p>
</div>
+1 -1
View File
@@ -2,7 +2,7 @@ import { PageSection } from "$fresh/www/components/PageSection.tsx";
export function Simple() {
return (
<PageSection class="!my-16">
<PageSection class="!mb-12 !mt-20">
<div class="text-center max-w-max mx-auto flex flex-col gap-4">
<p class="italic text-gray-500 text-lg">Introducing Fresh:</p>
<h2 class="text-4xl sm:text-5xl md:text-6xl lg:text-7xl sm:tracking-tight sm:leading-[1.1]! font-extrabold text-balance text-gray-600">
+4
View File
@@ -16,9 +16,11 @@ import * as $recipes_lemon_honey_tea from "./routes/recipes/lemon-honey-tea.tsx"
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 $thanks from "./routes/thanks.tsx";
import * as $update from "./routes/update.tsx";
import * as $CopyArea from "./islands/CopyArea.tsx";
import * as $Counter from "./islands/Counter.tsx";
import * as $FormSubmitDemo from "./islands/FormSubmitDemo.tsx";
import * as $LemonBottom from "./islands/LemonBottom.tsx";
import * as $LemonDrop from "./islands/LemonDrop.tsx";
import * as $LemonTop from "./islands/LemonTop.tsx";
@@ -43,11 +45,13 @@ const manifest = {
"./routes/recipes/lemonade.tsx": $recipes_lemonade,
"./routes/recipes/lemondrop.tsx": $recipes_lemondrop,
"./routes/showcase.tsx": $showcase,
"./routes/thanks.tsx": $thanks,
"./routes/update.tsx": $update,
},
islands: {
"./islands/CopyArea.tsx": $CopyArea,
"./islands/Counter.tsx": $Counter,
"./islands/FormSubmitDemo.tsx": $FormSubmitDemo,
"./islands/LemonBottom.tsx": $LemonBottom,
"./islands/LemonDrop.tsx": $LemonDrop,
"./islands/LemonTop.tsx": $LemonTop,
+55
View File
@@ -0,0 +1,55 @@
export function FormSubmitDemo() {
return (
<form action="/" method="POST" class="text-left md:px-8">
<fieldset class="mb-4">
<legend class="mb-2 font-bold">What's your favorite treat?</legend>
<label for="lemon-meringue-pie" class="flex gap-2 items-center">
<input
type="radio"
value="lemon-meringue-pie"
id="lemon-meringue-pie"
name="treat"
checked={true}
/>
Lemon meringue pie
</label>
<label for="lemon-shortbread-cookies" class="flex gap-2 items-center">
<input
type="radio"
value="lemon-shortbread-cookies"
id="lemon-shortbread-cookies"
name="treat"
/>
Lemon shortbread cookies
</label>
<label for="lemon-sherbet" class="flex gap-2 items-center">
<input
type="radio"
value="lemon-sherbet"
id="lemon-sherbet"
name="treat"
/>
Lemon sherbet
</label>
<label for="lemon-bars" class="flex gap-2 items-center">
<input
type="radio"
value="lemon-bars"
id="lemon-bars"
name="treat"
/>
Lemon bars
</label>
</fieldset>
<button
type="submit"
value="Submit"
class="pt-2 pb-1 px-3 rounded border-current border-[1.5px] font-semibold"
>
Submit
</button>
</form>
);
}
+11 -1
View File
@@ -26,6 +26,16 @@ export const handler: Handlers = {
}
return ctx.render();
},
async POST(req) {
const headers = new Headers();
const form = await req.formData();
const treat = form.get("treat");
headers.set("location", `/thanks?vote=${treat}`);
return new Response(null, {
status: 303,
headers,
});
},
};
const TITLE = "Fresh - The simple, approachable, productive web framework.";
@@ -55,7 +65,7 @@ export default function MainPage(props: PageProps) {
<HelloBar />
<Header title="" active="/" />
</div>
<div class="flex flex-col overflow-hidden -mt-20 relative">
<div class="flex flex-col -mt-20 relative">
<Hero origin={origin} />
<Simple />
<RenderingSection />
+70
View File
@@ -0,0 +1,70 @@
import { PageSection } from "$fresh/www/components/PageSection.tsx";
import { DemoBox } from "$fresh/www/components/homepage/DemoBox.tsx";
import { Head } from "$fresh/runtime.ts";
import { Handlers, PageProps } from "$fresh/server.ts";
export const handler: Handlers = {
GET(req, ctx) {
const url = new URL(req.url);
const search = new URLSearchParams(url.search);
const vote = search.get("vote");
return ctx.render({ vote });
},
};
export default function ThanksForSubscribing(
props: PageProps & { vote?: string },
) {
const vote = props?.data?.vote ? props.data.vote.replaceAll(/-/g, " ") : null;
return (
<>
<Head>
<meta name="robots" content="noindex" />
</Head>
<PageSection>
<DemoBox>
<div class="space-y-2">
<h1 class="text-lg sm:text-2xl md:text-3xl lg:text-4xl">
{vote
? `Thanks for voting for ${vote}!`
: `Form submitted successfully`}
</h1>
<p>
That was all handled server-side, with{" "}
<strong>no client-side JavaScript</strong>! Nifty, huh?
</p>
<p class="!mt-8">
…Anyway, you probably want to{" "}
<a href="/#forms-section" class="underline">go back now</a>.
</p>
<a
href="/#forms-section"
class="flex items-center gap-2 max-w-max !mt-4 mx-auto pt-3 pb-2 px-4 border-[1.5px] border-current rounded"
>
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-arrow-right relative bottom-[0.05em] transition-transform ease-out duration-150"
width="1em"
height="1em"
viewBox="0 0 24 24"
stroke-width="3"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
style="transform:rotateY(180deg);"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M5 12l14 0" />
<path d="M13 18l6 -6" />
<path d="M13 6l6 6" />
</svg>
Back home
</a>
</div>
</DemoBox>
</PageSection>
</>
);
}