Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): start any example in stackblitz #1576

Merged
merged 13 commits into from
Oct 6, 2023
Merged
5 changes: 5 additions & 0 deletions .changeset/purple-sheep-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

Added examples page that lets users try out different combinations of the create-t3-app
62 changes: 56 additions & 6 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",
mqshaikh8 marked this conversation as resolved.
Show resolved Hide resolved
};
---

<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
18 changes: 18 additions & 0 deletions www/src/pages/en/examples.mdx
mqshaikh8 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
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.

<Form />

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