Skip to content

Commit

Permalink
feat(docs): start any example in stackblitz (t3-oss#1576)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Marminge <[email protected]>
  • Loading branch information
mqshaikh8 and juliusmarminge committed Oct 6, 2023
1 parent d1055df commit 64517a3
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@headlessui/react": "^1.7.14",
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"@resvg/resvg-js": "^2.4.1",
"@stackblitz/sdk": "^1.9.0",
"@vercel/analytics": "^1.0.1",
"clsx": "^1.2.1",
"embla-carousel": "^7.1.0",
Expand Down
104 changes: 104 additions & 0 deletions www/src/components/docs/exampleOptionForm.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
const options = {
nextAuth: "NextAuth.js",
prisma: "Prisma",
tailwind: "Tailwind CSS",
trpc: "tRPC",
drizzle: "Drizzle",
};
---

<script>
import sdk from "@stackblitz/sdk";

function directToStackBlitz(checkedInputs: any) {
try {
sdk.openProject(
{
title: "T3 Examples",
description: "T3 example apps.",
template: "node",
files: {
"package.json": `{
"name": "T3 Examples",
"version": "1.0.0",
"description": "My Next.js app",
"scripts":{
"dev": " echo 'y' | npx create-t3-app example-app --CI ${checkedInputs} && cd ./example-app && rm ../package.json " }
}`,
},
settings: {
compile: {
trigger: "auto",
clearConsole: false,
},
},
},
{
newWindow: true,
openFile: ["package.json"],
},
);
} catch (error) {
console.error("Error", error);
}
}

function handleFormSubmit(e: Event) {
e.preventDefault();

const inputs = Array.from(
(e.target as HTMLFormElement).querySelectorAll("input"),
);
let checkedInputs = "";
inputs
.filter((input) => input.checked)
.map((input) => (checkedInputs += ` --${input.value}`));

directToStackBlitz(checkedInputs);
}

const form = document.getElementById("componentForm") as HTMLFormElement;

const prismaInput = document.getElementById("prisma") as HTMLInputElement;
const drizzleInput = document.getElementById("drizzle") as HTMLInputElement;

function handleCheckboxChange(e: Event) {
if (e.target === prismaInput && drizzleInput.checked) {
drizzleInput.checked = false;
} else if (e.target === drizzleInput && prismaInput.checked) {
prismaInput.checked = false;
}
}

prismaInput.addEventListener("change", handleCheckboxChange);
drizzleInput.addEventListener("change", handleCheckboxChange);

form.addEventListener("submit", handleFormSubmit);
</script>

<form
method="get"
id="componentForm"
class="mb-4 w-full rounded border border-t3-purple-300 p-4 text-lg"
>
{
Object.entries(options).map(([code, name]) => (
<div>
<input
id={code}
type="checkbox"
name={name}
value={code}
class="h-4 w-4"
/>
<label for={code}>{name}</label>
</div>
))
}
<button
class="text-md inline-flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-md border-2 bg-t3-purple-200/50 px-3 py-2 font-medium hover:bg-t3-purple-200/75 dark:border-t3-purple-200/20 dark:bg-t3-purple-200/10 dark:hover:border-t3-purple-200/50"
>
View in StackBlitz
</button>
</form>
1 change: 1 addition & 0 deletions www/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const SIDEBAR: Sidebar = {
{ text: "Folder Structure", link: "en/folder-structure" },
{ text: "FAQ", link: "en/faq" },
{ text: "T3 Collection", link: "en/t3-collection" },
{ text: "Examples", link: "en/examples" },
{ text: "Other Recommendations", link: "en/other-recs" },
],
Usage: [
Expand Down
22 changes: 22 additions & 0 deletions www/src/pages/en/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Examples
description: Examples of different live apps
layout: ../../layouts/docs.astro
lang: en
isMdx: true
---

import Callout from "../../components/docs/callout.tsx";
import Form from "../../components/docs/exampleOptionForm.astro";

You can try out different combinations of technologies that create-t3-app offers.

<Callout type="info">
You cannot select `prisma` and `drizzle` at the same time.
</Callout>

<Form />

<Callout type="warning">
Some features might not work unless you create an env file
</Callout>

0 comments on commit 64517a3

Please sign in to comment.