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
Next Next commit
feature: added an example page that will let users see different comb…
…ination of t3 apps in stackblitz
  • Loading branch information
mqshaikh8 committed Sep 25, 2023
commit 875dff2041159c9e618667c93535684b79121ea2
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
94 changes: 94 additions & 0 deletions www/src/components/docs/exampleOptionForm.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
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 my-app --CI ${checkedInputs} && cd ./my-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;

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}
checked
mqshaikh8 marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 14 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,14 @@
---
title: Examples
description: Examples of different live apps
layout: ../../layouts/docs.astro
lang: en
isMdx: true
---


import Form from "../../components/docs/exampleOptionForm.astro";

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

<Form />