create-strayl-web-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
- package/template/README.md +290 -0
- package/template/components.json +24 -0
- package/template/package.json +56 -0
- package/template/public/favicon.ico +0 -0
- package/template/public/google-logo.svg +6 -0
- package/template/public/logo-dark.ico +0 -0
- package/template/public/logo-dark.webp +0 -0
- package/template/public/logo-light.ico +0 -0
- package/template/public/logo-light.webp +0 -0
- package/template/public/manifest.json +16 -0
- package/template/public/robots.txt +3 -0
- package/template/src/components/Header.tsx +76 -0
- package/template/src/components/language-switcher.tsx +38 -0
- package/template/src/components/theme-provider.tsx +14 -0
- package/template/src/components/themed-logo.tsx +44 -0
- package/template/src/components/ui/accordion.tsx +69 -0
- package/template/src/components/ui/alert-dialog.tsx +169 -0
- package/template/src/components/ui/alert.tsx +80 -0
- package/template/src/components/ui/autocomplete.tsx +301 -0
- package/template/src/components/ui/avatar.tsx +46 -0
- package/template/src/components/ui/badge.tsx +60 -0
- package/template/src/components/ui/breadcrumb.tsx +112 -0
- package/template/src/components/ui/button.tsx +73 -0
- package/template/src/components/ui/card.tsx +244 -0
- package/template/src/components/ui/checkbox-group.tsx +16 -0
- package/template/src/components/ui/checkbox.tsx +60 -0
- package/template/src/components/ui/collapsible.tsx +45 -0
- package/template/src/components/ui/combobox.tsx +415 -0
- package/template/src/components/ui/command.tsx +264 -0
- package/template/src/components/ui/dialog.tsx +196 -0
- package/template/src/components/ui/empty.tsx +127 -0
- package/template/src/components/ui/field.tsx +74 -0
- package/template/src/components/ui/fieldset.tsx +29 -0
- package/template/src/components/ui/form.tsx +17 -0
- package/template/src/components/ui/frame.tsx +82 -0
- package/template/src/components/ui/group.tsx +97 -0
- package/template/src/components/ui/input-group.tsx +101 -0
- package/template/src/components/ui/input.tsx +66 -0
- package/template/src/components/ui/kbd.tsx +28 -0
- package/template/src/components/ui/label.tsx +28 -0
- package/template/src/components/ui/menu.tsx +310 -0
- package/template/src/components/ui/meter.tsx +67 -0
- package/template/src/components/ui/number-field.tsx +160 -0
- package/template/src/components/ui/pagination.tsx +136 -0
- package/template/src/components/ui/popover.tsx +104 -0
- package/template/src/components/ui/preview-card.tsx +55 -0
- package/template/src/components/ui/progress.tsx +81 -0
- package/template/src/components/ui/radio-group.tsx +36 -0
- package/template/src/components/ui/scroll-area.tsx +64 -0
- package/template/src/components/ui/select.tsx +180 -0
- package/template/src/components/ui/separator.tsx +23 -0
- package/template/src/components/ui/sheet.tsx +203 -0
- package/template/src/components/ui/sidebar.tsx +743 -0
- package/template/src/components/ui/skeleton.tsx +16 -0
- package/template/src/components/ui/slider.tsx +74 -0
- package/template/src/components/ui/spinner.tsx +18 -0
- package/template/src/components/ui/switch.tsx +27 -0
- package/template/src/components/ui/table.tsx +126 -0
- package/template/src/components/ui/tabs.tsx +87 -0
- package/template/src/components/ui/textarea.tsx +51 -0
- package/template/src/components/ui/toast.tsx +269 -0
- package/template/src/components/ui/toggle-group.tsx +102 -0
- package/template/src/components/ui/toggle.tsx +45 -0
- package/template/src/components/ui/toolbar.tsx +83 -0
- package/template/src/components/ui/tooltip.tsx +65 -0
- package/template/src/hooks/use-mobile.ts +21 -0
- package/template/src/lib/i18n.ts +70 -0
- package/template/src/lib/utils.ts +6 -0
- package/template/src/routeTree.gen.ts +68 -0
- package/template/src/router.tsx +17 -0
- package/template/src/routes/__root.tsx +62 -0
- package/template/src/routes/index.tsx +71 -0
- package/template/src/styles.css +121 -0
- package/template/tsconfig.json +28 -0
- package/template/vite.config.ts +30 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { cpSync, existsSync, readFileSync, writeFileSync } from "fs";
|
|
8
|
+
import { resolve, dirname, join } from "path";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
var templateDir = resolve(__dirname, "..", "template");
|
|
12
|
+
var program = new Command();
|
|
13
|
+
program.name("create-strayl-web-app").description("Scaffold a new Strayl web application").requiredOption("--name <name>", "Name of the new project").action((opts) => {
|
|
14
|
+
const name = opts.name.trim();
|
|
15
|
+
if (!name) {
|
|
16
|
+
console.error(pc.red("Error: --name must not be empty."));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
if (!/^[a-zA-Z0-9_@\/-][a-zA-Z0-9_.\-@\/]*$/.test(name)) {
|
|
20
|
+
console.error(
|
|
21
|
+
pc.red(
|
|
22
|
+
"Error: Invalid project name. Use only alphanumeric characters, hyphens, underscores, dots, and slashes."
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const targetDir = resolve(process.cwd(), name);
|
|
28
|
+
if (existsSync(targetDir)) {
|
|
29
|
+
console.error(
|
|
30
|
+
pc.red(`Error: Directory "${name}" already exists.`)
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
if (!existsSync(templateDir)) {
|
|
35
|
+
console.error(
|
|
36
|
+
pc.red("Error: Template directory not found. The package may be corrupted.")
|
|
37
|
+
);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
console.log(pc.cyan(`Creating project "${name}"...`));
|
|
41
|
+
cpSync(templateDir, targetDir, { recursive: true });
|
|
42
|
+
const pkgJsonPath = join(targetDir, "package.json");
|
|
43
|
+
if (existsSync(pkgJsonPath)) {
|
|
44
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
45
|
+
pkgJson.name = name;
|
|
46
|
+
delete pkgJson.private;
|
|
47
|
+
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2) + "\n");
|
|
48
|
+
}
|
|
49
|
+
console.log(pc.green(`
|
|
50
|
+
Project "${name}" created successfully!
|
|
51
|
+
`));
|
|
52
|
+
console.log("Next steps:");
|
|
53
|
+
console.log(pc.cyan(` cd ${name}`));
|
|
54
|
+
console.log(pc.cyan(" npm install"));
|
|
55
|
+
console.log(pc.cyan(" npm run dev"));
|
|
56
|
+
console.log();
|
|
57
|
+
});
|
|
58
|
+
program.parse();
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport pc from \"picocolors\";\nimport { cpSync, existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { resolve, dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst templateDir = resolve(__dirname, \"..\", \"template\");\n\nconst program = new Command();\n\nprogram\n .name(\"create-strayl-web-app\")\n .description(\"Scaffold a new Strayl web application\")\n .requiredOption(\"--name <name>\", \"Name of the new project\")\n .action((opts: { name: string }) => {\n const name = opts.name.trim();\n\n if (!name) {\n console.error(pc.red(\"Error: --name must not be empty.\"));\n process.exit(1);\n }\n\n if (!/^[a-zA-Z0-9_@\\/-][a-zA-Z0-9_.\\-@\\/]*$/.test(name)) {\n console.error(\n pc.red(\n \"Error: Invalid project name. Use only alphanumeric characters, hyphens, underscores, dots, and slashes.\"\n )\n );\n process.exit(1);\n }\n\n const targetDir = resolve(process.cwd(), name);\n\n if (existsSync(targetDir)) {\n console.error(\n pc.red(`Error: Directory \"${name}\" already exists.`)\n );\n process.exit(1);\n }\n\n if (!existsSync(templateDir)) {\n console.error(\n pc.red(\"Error: Template directory not found. The package may be corrupted.\")\n );\n process.exit(1);\n }\n\n console.log(pc.cyan(`Creating project \"${name}\"...`));\n\n cpSync(templateDir, targetDir, { recursive: true });\n\n const pkgJsonPath = join(targetDir, \"package.json\");\n if (existsSync(pkgJsonPath)) {\n const pkgJson = JSON.parse(readFileSync(pkgJsonPath, \"utf-8\"));\n pkgJson.name = name;\n delete pkgJson.private;\n writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2) + \"\\n\");\n }\n\n console.log(pc.green(`\\nProject \"${name}\" created successfully!\\n`));\n console.log(\"Next steps:\");\n console.log(pc.cyan(` cd ${name}`));\n console.log(pc.cyan(\" npm install\"));\n console.log(pc.cyan(\" npm run dev\"));\n console.log();\n });\n\nprogram.parse();\n"],"mappings":";;;;AAAA,SAAS,eAAe;AACxB,OAAO,QAAQ;AACf,SAAS,QAAQ,YAAY,cAAc,qBAAqB;AAChE,SAAS,SAAS,SAAS,YAAY;AACvC,SAAS,qBAAqB;AAE9B,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AACxD,IAAM,cAAc,QAAQ,WAAW,MAAM,UAAU;AAEvD,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,uBAAuB,EAC5B,YAAY,uCAAuC,EACnD,eAAe,iBAAiB,yBAAyB,EACzD,OAAO,CAAC,SAA2B;AAClC,QAAM,OAAO,KAAK,KAAK,KAAK;AAE5B,MAAI,CAAC,MAAM;AACT,YAAQ,MAAM,GAAG,IAAI,kCAAkC,CAAC;AACxD,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,CAAC,wCAAwC,KAAK,IAAI,GAAG;AACvD,YAAQ;AAAA,MACN,GAAG;AAAA,QACD;AAAA,MACF;AAAA,IACF;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,YAAY,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAE7C,MAAI,WAAW,SAAS,GAAG;AACzB,YAAQ;AAAA,MACN,GAAG,IAAI,qBAAqB,IAAI,mBAAmB;AAAA,IACrD;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,CAAC,WAAW,WAAW,GAAG;AAC5B,YAAQ;AAAA,MACN,GAAG,IAAI,oEAAoE;AAAA,IAC7E;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,UAAQ,IAAI,GAAG,KAAK,qBAAqB,IAAI,MAAM,CAAC;AAEpD,SAAO,aAAa,WAAW,EAAE,WAAW,KAAK,CAAC;AAElD,QAAM,cAAc,KAAK,WAAW,cAAc;AAClD,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,UAAU,KAAK,MAAM,aAAa,aAAa,OAAO,CAAC;AAC7D,YAAQ,OAAO;AACf,WAAO,QAAQ;AACf,kBAAc,aAAa,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,IAAI;AAAA,EACpE;AAEA,UAAQ,IAAI,GAAG,MAAM;AAAA,WAAc,IAAI;AAAA,CAA2B,CAAC;AACnE,UAAQ,IAAI,aAAa;AACzB,UAAQ,IAAI,GAAG,KAAK,QAAQ,IAAI,EAAE,CAAC;AACnC,UAAQ,IAAI,GAAG,KAAK,eAAe,CAAC;AACpC,UAAQ,IAAI,GAAG,KAAK,eAAe,CAAC;AACpC,UAAQ,IAAI;AACd,CAAC;AAEH,QAAQ,MAAM;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-strayl-web-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a new Strayl web application",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-strayl-web-app": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"dev": "tsup --watch",
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"commander": "^12.1.0",
|
|
21
|
+
"picocolors": "^1.1.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.0",
|
|
25
|
+
"tsup": "^8.3.5",
|
|
26
|
+
"typescript": "^5.7.2"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"strayl",
|
|
33
|
+
"create",
|
|
34
|
+
"web-app",
|
|
35
|
+
"scaffold"
|
|
36
|
+
],
|
|
37
|
+
"author": "Strayl Inc",
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Welcome to your new TanStack app!
|
|
2
|
+
|
|
3
|
+
# Getting Started
|
|
4
|
+
|
|
5
|
+
To run this application:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
# Building For Production
|
|
13
|
+
|
|
14
|
+
To build this application for production:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm run build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Testing
|
|
21
|
+
|
|
22
|
+
This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run test
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Styling
|
|
29
|
+
|
|
30
|
+
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Routing
|
|
36
|
+
This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.
|
|
37
|
+
|
|
38
|
+
### Adding A Route
|
|
39
|
+
|
|
40
|
+
To add a new route to your application just add another a new file in the `./src/routes` directory.
|
|
41
|
+
|
|
42
|
+
TanStack will automatically generate the content of the route file for you.
|
|
43
|
+
|
|
44
|
+
Now that you have two routes you can use a `Link` component to navigate between them.
|
|
45
|
+
|
|
46
|
+
### Adding Links
|
|
47
|
+
|
|
48
|
+
To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { Link } from "@tanstack/react-router";
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then anywhere in your JSX you can use it like so:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<Link to="/about">About</Link>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This will create a link that will navigate to the `/about` route.
|
|
61
|
+
|
|
62
|
+
More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
|
|
63
|
+
|
|
64
|
+
### Using A Layout
|
|
65
|
+
|
|
66
|
+
In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.
|
|
67
|
+
|
|
68
|
+
Here is an example layout that includes a header:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { Outlet, createRootRoute } from '@tanstack/react-router'
|
|
72
|
+
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
|
|
73
|
+
|
|
74
|
+
import { Link } from "@tanstack/react-router";
|
|
75
|
+
|
|
76
|
+
export const Route = createRootRoute({
|
|
77
|
+
component: () => (
|
|
78
|
+
<>
|
|
79
|
+
<header>
|
|
80
|
+
<nav>
|
|
81
|
+
<Link to="/">Home</Link>
|
|
82
|
+
<Link to="/about">About</Link>
|
|
83
|
+
</nav>
|
|
84
|
+
</header>
|
|
85
|
+
<Outlet />
|
|
86
|
+
<TanStackRouterDevtools />
|
|
87
|
+
</>
|
|
88
|
+
),
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
|
|
93
|
+
|
|
94
|
+
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Data Fetching
|
|
98
|
+
|
|
99
|
+
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
|
|
100
|
+
|
|
101
|
+
For example:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
const peopleRoute = createRoute({
|
|
105
|
+
getParentRoute: () => rootRoute,
|
|
106
|
+
path: "/people",
|
|
107
|
+
loader: async () => {
|
|
108
|
+
const response = await fetch("https://swapi.dev/api/people");
|
|
109
|
+
return response.json() as Promise<{
|
|
110
|
+
results: {
|
|
111
|
+
name: string;
|
|
112
|
+
}[];
|
|
113
|
+
}>;
|
|
114
|
+
},
|
|
115
|
+
component: () => {
|
|
116
|
+
const data = peopleRoute.useLoaderData();
|
|
117
|
+
return (
|
|
118
|
+
<ul>
|
|
119
|
+
{data.results.map((person) => (
|
|
120
|
+
<li key={person.name}>{person.name}</li>
|
|
121
|
+
))}
|
|
122
|
+
</ul>
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
|
|
129
|
+
|
|
130
|
+
### React-Query
|
|
131
|
+
|
|
132
|
+
React-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.
|
|
133
|
+
|
|
134
|
+
First add your dependencies:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm install @tanstack/react-query @tanstack/react-query-devtools
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Next we'll need to create a query client and provider. We recommend putting those in `main.tsx`.
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
144
|
+
|
|
145
|
+
// ...
|
|
146
|
+
|
|
147
|
+
const queryClient = new QueryClient();
|
|
148
|
+
|
|
149
|
+
// ...
|
|
150
|
+
|
|
151
|
+
if (!rootElement.innerHTML) {
|
|
152
|
+
const root = ReactDOM.createRoot(rootElement);
|
|
153
|
+
|
|
154
|
+
root.render(
|
|
155
|
+
<QueryClientProvider client={queryClient}>
|
|
156
|
+
<RouterProvider router={router} />
|
|
157
|
+
</QueryClientProvider>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
You can also add TanStack Query Devtools to the root route (optional).
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
166
|
+
|
|
167
|
+
const rootRoute = createRootRoute({
|
|
168
|
+
component: () => (
|
|
169
|
+
<>
|
|
170
|
+
<Outlet />
|
|
171
|
+
<ReactQueryDevtools buttonPosition="top-right" />
|
|
172
|
+
<TanStackRouterDevtools />
|
|
173
|
+
</>
|
|
174
|
+
),
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Now you can use `useQuery` to fetch your data.
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import { useQuery } from "@tanstack/react-query";
|
|
182
|
+
|
|
183
|
+
import "./App.css";
|
|
184
|
+
|
|
185
|
+
function App() {
|
|
186
|
+
const { data } = useQuery({
|
|
187
|
+
queryKey: ["people"],
|
|
188
|
+
queryFn: () =>
|
|
189
|
+
fetch("https://swapi.dev/api/people")
|
|
190
|
+
.then((res) => res.json())
|
|
191
|
+
.then((data) => data.results as { name: string }[]),
|
|
192
|
+
initialData: [],
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<div>
|
|
197
|
+
<ul>
|
|
198
|
+
{data.map((person) => (
|
|
199
|
+
<li key={person.name}>{person.name}</li>
|
|
200
|
+
))}
|
|
201
|
+
</ul>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default App;
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
210
|
+
|
|
211
|
+
## State Management
|
|
212
|
+
|
|
213
|
+
Another common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.
|
|
214
|
+
|
|
215
|
+
First you need to add TanStack Store as a dependency:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
npm install @tanstack/store
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Now let's create a simple counter in the `src/App.tsx` file as a demonstration.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
import { useStore } from "@tanstack/react-store";
|
|
225
|
+
import { Store } from "@tanstack/store";
|
|
226
|
+
import "./App.css";
|
|
227
|
+
|
|
228
|
+
const countStore = new Store(0);
|
|
229
|
+
|
|
230
|
+
function App() {
|
|
231
|
+
const count = useStore(countStore);
|
|
232
|
+
return (
|
|
233
|
+
<div>
|
|
234
|
+
<button onClick={() => countStore.setState((n) => n + 1)}>
|
|
235
|
+
Increment - {count}
|
|
236
|
+
</button>
|
|
237
|
+
</div>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export default App;
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
|
|
245
|
+
|
|
246
|
+
Let's check this out by doubling the count using derived state.
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
import { useStore } from "@tanstack/react-store";
|
|
250
|
+
import { Store, Derived } from "@tanstack/store";
|
|
251
|
+
import "./App.css";
|
|
252
|
+
|
|
253
|
+
const countStore = new Store(0);
|
|
254
|
+
|
|
255
|
+
const doubledStore = new Derived({
|
|
256
|
+
fn: () => countStore.state * 2,
|
|
257
|
+
deps: [countStore],
|
|
258
|
+
});
|
|
259
|
+
doubledStore.mount();
|
|
260
|
+
|
|
261
|
+
function App() {
|
|
262
|
+
const count = useStore(countStore);
|
|
263
|
+
const doubledCount = useStore(doubledStore);
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div>
|
|
267
|
+
<button onClick={() => countStore.setState((n) => n + 1)}>
|
|
268
|
+
Increment - {count}
|
|
269
|
+
</button>
|
|
270
|
+
<div>Doubled - {doubledCount}</div>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export default App;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.
|
|
279
|
+
|
|
280
|
+
Once we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.
|
|
281
|
+
|
|
282
|
+
You can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).
|
|
283
|
+
|
|
284
|
+
# Demo files
|
|
285
|
+
|
|
286
|
+
Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
|
|
287
|
+
|
|
288
|
+
# Learn More
|
|
289
|
+
|
|
290
|
+
You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/styles.css",
|
|
9
|
+
"baseColor": "neutral",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"iconLibrary": "lucide",
|
|
14
|
+
"aliases": {
|
|
15
|
+
"components": "@/components",
|
|
16
|
+
"utils": "@/lib/utils",
|
|
17
|
+
"ui": "@/components/ui",
|
|
18
|
+
"lib": "@/lib",
|
|
19
|
+
"hooks": "@/hooks"
|
|
20
|
+
},
|
|
21
|
+
"registries": {
|
|
22
|
+
"@coss": "https://coss.com/ui/r/{name}.json"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "strayl-web",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite dev --port 3000",
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"preview": "vite preview",
|
|
9
|
+
"test": "vitest run"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@base-ui/react": "^1.1.0",
|
|
13
|
+
"@fontsource-variable/bitcount-prop-single": "^5.2.2",
|
|
14
|
+
"@fontsource-variable/geist": "^5.2.8",
|
|
15
|
+
"@fontsource-variable/geist-mono": "^5.2.7",
|
|
16
|
+
"@radix-ui/react-dialog": "^1.1.4",
|
|
17
|
+
"@radix-ui/react-dropdown-menu": "^2.1.4",
|
|
18
|
+
"@radix-ui/react-navigation-menu": "^1.2.3",
|
|
19
|
+
"@radix-ui/react-slot": "^1.1.1",
|
|
20
|
+
"@tailwindcss/vite": "^4.0.6",
|
|
21
|
+
"@tanstack/react-devtools": "^0.7.0",
|
|
22
|
+
"@tanstack/react-router": "^1.132.0",
|
|
23
|
+
"@tanstack/react-router-devtools": "^1.132.0",
|
|
24
|
+
"@tanstack/react-router-ssr-query": "^1.131.7",
|
|
25
|
+
"@tanstack/react-start": "^1.132.0",
|
|
26
|
+
"@tanstack/router-plugin": "^1.132.0",
|
|
27
|
+
"class-variance-authority": "^0.7.1",
|
|
28
|
+
"clsx": "^2.1.1",
|
|
29
|
+
"i18next": "^25.8.0",
|
|
30
|
+
"i18next-browser-languagedetector": "^8.2.0",
|
|
31
|
+
"lucide-react": "^0.561.0",
|
|
32
|
+
"next-themes": "^0.4.6",
|
|
33
|
+
"nitro": "npm:nitro-nightly@latest",
|
|
34
|
+
"react": "^19.2.0",
|
|
35
|
+
"react-dom": "^19.2.0",
|
|
36
|
+
"react-i18next": "^16.5.3",
|
|
37
|
+
"tailwind-merge": "^2.6.0",
|
|
38
|
+
"tailwindcss": "^4.0.6",
|
|
39
|
+
"tw-animate-css": "^1.4.0",
|
|
40
|
+
"vite-tsconfig-paths": "^6.0.2"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tanstack/devtools-vite": "^0.3.11",
|
|
44
|
+
"@testing-library/dom": "^10.4.0",
|
|
45
|
+
"@testing-library/react": "^16.2.0",
|
|
46
|
+
"@types/node": "^22.10.2",
|
|
47
|
+
"@types/react": "^19.2.0",
|
|
48
|
+
"@types/react-dom": "^19.2.0",
|
|
49
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
50
|
+
"jsdom": "^27.0.0",
|
|
51
|
+
"typescript": "^5.7.2",
|
|
52
|
+
"vite": "^7.1.7",
|
|
53
|
+
"vitest": "^3.0.5",
|
|
54
|
+
"web-vitals": "^5.1.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
2
|
+
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
|
|
3
|
+
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
|
|
4
|
+
<path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
|
|
5
|
+
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
|
|
6
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Strayl",
|
|
3
|
+
"short_name": "Strayl",
|
|
4
|
+
"description": "Build end to end",
|
|
5
|
+
"icons": [
|
|
6
|
+
{
|
|
7
|
+
"src": "favicon.ico",
|
|
8
|
+
"sizes": "64x64 32x32 24x24 16x16",
|
|
9
|
+
"type": "image/x-icon"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"start_url": ".",
|
|
13
|
+
"display": "standalone",
|
|
14
|
+
"theme_color": "#171717",
|
|
15
|
+
"background_color": "#f5f5f5"
|
|
16
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Link } from '@tanstack/react-router'
|
|
2
|
+
import { useTheme } from 'next-themes'
|
|
3
|
+
import { useEffect, useState } from 'react'
|
|
4
|
+
import { Home, Menu, Moon, Sun } from 'lucide-react'
|
|
5
|
+
import { ThemedLogo } from './themed-logo'
|
|
6
|
+
import { Button } from '@/components/ui/button'
|
|
7
|
+
import {
|
|
8
|
+
Sheet,
|
|
9
|
+
SheetTrigger,
|
|
10
|
+
SheetPopup,
|
|
11
|
+
SheetHeader,
|
|
12
|
+
SheetTitle,
|
|
13
|
+
SheetPanel,
|
|
14
|
+
SheetClose,
|
|
15
|
+
} from '@/components/ui/sheet'
|
|
16
|
+
|
|
17
|
+
export default function Header() {
|
|
18
|
+
const { resolvedTheme, setTheme } = useTheme()
|
|
19
|
+
const [mounted, setMounted] = useState(false)
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setMounted(true)
|
|
23
|
+
}, [])
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<header className="p-4 flex items-center justify-between bg-card border-b border-border">
|
|
27
|
+
<div className="flex items-center">
|
|
28
|
+
<Sheet>
|
|
29
|
+
<SheetTrigger render={<Button variant="ghost" size="icon" />}>
|
|
30
|
+
<Menu size={24} />
|
|
31
|
+
</SheetTrigger>
|
|
32
|
+
<SheetPopup side="left">
|
|
33
|
+
<SheetHeader>
|
|
34
|
+
<SheetTitle>Navigation</SheetTitle>
|
|
35
|
+
</SheetHeader>
|
|
36
|
+
<SheetPanel>
|
|
37
|
+
<nav className="flex flex-col gap-2">
|
|
38
|
+
<SheetClose
|
|
39
|
+
render={
|
|
40
|
+
<Link
|
|
41
|
+
to="/"
|
|
42
|
+
className="flex items-center gap-3 p-3 rounded-lg hover:bg-muted transition-colors"
|
|
43
|
+
activeProps={{
|
|
44
|
+
className:
|
|
45
|
+
'flex items-center gap-3 p-3 rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 transition-colors',
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
}
|
|
49
|
+
>
|
|
50
|
+
<Home size={20} />
|
|
51
|
+
<span className="font-medium">Home</span>
|
|
52
|
+
</SheetClose>
|
|
53
|
+
</nav>
|
|
54
|
+
</SheetPanel>
|
|
55
|
+
</SheetPopup>
|
|
56
|
+
</Sheet>
|
|
57
|
+
<Link to="/" className="ml-4 flex items-center gap-2">
|
|
58
|
+
<ThemedLogo width={32} height={32} />
|
|
59
|
+
<span className="text-xl font-semibold">Strayl</span>
|
|
60
|
+
</Link>
|
|
61
|
+
</div>
|
|
62
|
+
<Button
|
|
63
|
+
variant="ghost"
|
|
64
|
+
size="icon"
|
|
65
|
+
onClick={() => setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')}
|
|
66
|
+
aria-label="Toggle theme"
|
|
67
|
+
>
|
|
68
|
+
{mounted ? (
|
|
69
|
+
resolvedTheme === 'dark' ? <Sun size={20} /> : <Moon size={20} />
|
|
70
|
+
) : (
|
|
71
|
+
<div className="w-5 h-5" />
|
|
72
|
+
)}
|
|
73
|
+
</Button>
|
|
74
|
+
</header>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next'
|
|
2
|
+
import { Languages } from 'lucide-react'
|
|
3
|
+
import {
|
|
4
|
+
Select,
|
|
5
|
+
SelectTrigger,
|
|
6
|
+
SelectValue,
|
|
7
|
+
SelectPopup,
|
|
8
|
+
SelectItem,
|
|
9
|
+
} from '@/components/ui/select'
|
|
10
|
+
|
|
11
|
+
const languages = [
|
|
12
|
+
{ code: 'ru', label: 'Русский' },
|
|
13
|
+
{ code: 'en', label: 'English' },
|
|
14
|
+
{ code: 'kk', label: 'Қазақша' },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
export function LanguageSwitcher() {
|
|
18
|
+
const { i18n } = useTranslation()
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Select
|
|
22
|
+
value={i18n.language}
|
|
23
|
+
onValueChange={(value) => i18n.changeLanguage(value)}
|
|
24
|
+
>
|
|
25
|
+
<SelectTrigger size="sm" className="w-auto min-w-0 gap-1.5">
|
|
26
|
+
<Languages className="size-4" />
|
|
27
|
+
<SelectValue placeholder="Language" />
|
|
28
|
+
</SelectTrigger>
|
|
29
|
+
<SelectPopup>
|
|
30
|
+
{languages.map((lang) => (
|
|
31
|
+
<SelectItem key={lang.code} value={lang.code}>
|
|
32
|
+
{lang.label}
|
|
33
|
+
</SelectItem>
|
|
34
|
+
))}
|
|
35
|
+
</SelectPopup>
|
|
36
|
+
</Select>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
|
2
|
+
|
|
3
|
+
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
4
|
+
return (
|
|
5
|
+
<NextThemesProvider
|
|
6
|
+
attribute="class"
|
|
7
|
+
defaultTheme="system"
|
|
8
|
+
enableSystem
|
|
9
|
+
disableTransitionOnChange
|
|
10
|
+
>
|
|
11
|
+
{children}
|
|
12
|
+
</NextThemesProvider>
|
|
13
|
+
)
|
|
14
|
+
}
|