diff --git a/www/components/CodeWindow.tsx b/www/components/CodeWindow.tsx index fdaebadd..a91eccfe 100644 --- a/www/components/CodeWindow.tsx +++ b/www/components/CodeWindow.tsx @@ -8,7 +8,7 @@ export function CodeWindow(props: CodeWindowProps) { return (
*]: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} diff --git a/www/components/PageSection.tsx b/www/components/PageSection.tsx index 19e7a36a..4d69782d 100644 --- a/www/components/PageSection.tsx +++ b/www/components/PageSection.tsx @@ -3,7 +3,8 @@ import { JSX } from "preact"; export function PageSection(props: JSX.HTMLAttributes) { return (
diff --git a/www/components/SideBySide.tsx b/www/components/SideBySide.tsx index 8142384b..52242d27 100644 --- a/www/components/SideBySide.tsx +++ b/www/components/SideBySide.tsx @@ -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 (
*]:order-1" : "" } ${mdSplitClass} ${lgSplitClass} ${props.class ?? ""}`} > diff --git a/www/components/homepage/CTA.tsx b/www/components/homepage/CTA.tsx index 0ee77913..068af4e2 100644 --- a/www/components/homepage/CTA.tsx +++ b/www/components/homepage/CTA.tsx @@ -3,19 +3,16 @@ import { FancyLink } from "$fresh/www/components/FancyLink.tsx"; export function CTA() { return ( -
- +
+
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

- Time for a Fresh Start + Time for a Fresh start

diff --git a/www/components/homepage/FormsSection.tsx b/www/components/homepage/FormsSection.tsx index 8043b54c..bbf87812 100644 --- a/www/components/homepage/FormsSection.tsx +++ b/www/components/homepage/FormsSection.tsx @@ -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 ( - - -

+ + +

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.

Since Fresh is built on{" "} @@ -77,14 +77,10 @@ export function FormsSection() { lang="jsx" /> - { - /* + -

- TODO: something goes here. -

- */ - } + +
diff --git a/www/components/homepage/Hero.tsx b/www/components/homepage/Hero.tsx index f5953640..c0532d78 100644 --- a/www/components/homepage/Hero.tsx +++ b/www/components/homepage/Hero.tsx @@ -11,7 +11,7 @@ export function Hero(props: { origin: string }) {
-

+

The simple, approachable, productive web framework

diff --git a/www/components/homepage/IslandsSection.tsx b/www/components/homepage/IslandsSection.tsx index 2d382bbc..89fbbf31 100644 --- a/www/components/homepage/IslandsSection.tsx +++ b/www/components/homepage/IslandsSection.tsx @@ -29,8 +29,13 @@ export default function Counter(props) { export function IslandsSection() { return ( - -
+ +

- Because it's{" "} - Preact, you - get best-in-class performance, plus the convenience of{" "} + Because it's Preact, you get best-in-class performance, plus the + convenience of{" "} Signals . diff --git a/www/components/homepage/PartialsSection.tsx b/www/components/homepage/PartialsSection.tsx index 4ca330db..35c924e2 100644 --- a/www/components/homepage/PartialsSection.tsx +++ b/www/components/homepage/PartialsSection.tsx @@ -35,8 +35,13 @@ export const Recipes = () => ( export function PartialsSection() { return ( - -

+ +
Stream HTML straight from the server

- 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.

Learn more about Partials diff --git a/www/components/homepage/RenderingSection.tsx b/www/components/homepage/RenderingSection.tsx index 14b2a7c9..9e3657e4 100644 --- a/www/components/homepage/RenderingSection.tsx +++ b/www/components/homepage/RenderingSection.tsx @@ -16,8 +16,8 @@ const serverCode = `export default function HomePage() { export function RenderingSection() { return ( - -
+ +

- 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{" "} + Preact{" "} + components, so there's zero JavaScript shipped to the browser by + default.

Simple to write; fast to run.

diff --git a/www/components/homepage/Simple.tsx b/www/components/homepage/Simple.tsx index 2b67dfcd..44f7bca1 100644 --- a/www/components/homepage/Simple.tsx +++ b/www/components/homepage/Simple.tsx @@ -2,7 +2,7 @@ import { PageSection } from "$fresh/www/components/PageSection.tsx"; export function Simple() { return ( - +

Introducing Fresh:

diff --git a/www/fresh.gen.ts b/www/fresh.gen.ts index bc654923..b16a2d6d 100644 --- a/www/fresh.gen.ts +++ b/www/fresh.gen.ts @@ -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, diff --git a/www/islands/FormSubmitDemo.tsx b/www/islands/FormSubmitDemo.tsx new file mode 100644 index 00000000..ca80895e --- /dev/null +++ b/www/islands/FormSubmitDemo.tsx @@ -0,0 +1,55 @@ +export function FormSubmitDemo() { + return ( +
+
+ What's your favorite treat? + + + + + +
+ + +
+ ); +} diff --git a/www/routes/index.tsx b/www/routes/index.tsx index 0852aaa4..d305951f 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -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) {

-
+
diff --git a/www/routes/thanks.tsx b/www/routes/thanks.tsx new file mode 100644 index 00000000..fbcab565 --- /dev/null +++ b/www/routes/thanks.tsx @@ -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 ( + <> + + + + + +
+

+ {vote + ? `Thanks for voting for ${vote}!` + : `Form submitted successfully`} +

+

+ That was all handled server-side, with{" "} + no client-side JavaScript! Nifty, huh? +

+

+ …Anyway, you probably want to{" "} + go back now. +

+ + + Back home + +
+
+
+ + ); +}