@yannosay/sinth 5.3.3 → 5.3.4
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/CHANGELOG.md +48 -0
- package/README.md +4 -2
- package/dist/browser/sinth.js +596 -69
- package/dist/cli/index.js +35 -3
- package/dist/cli/skill.d.ts +10 -0
- package/dist/cli/skill.js +106 -0
- package/dist/cli/templates.js +1 -1
- package/dist/compiler/codegen.js +4 -2
- package/dist/compiler/elements.d.ts +6 -0
- package/dist/compiler/elements.js +12 -0
- package/dist/compiler/html.d.ts +2 -0
- package/dist/compiler/html.js +7 -0
- package/dist/compiler/prerender.js +5 -3
- package/dist/deploy/platforms.js +9 -0
- package/dist/deploy/redirects.d.ts +31 -0
- package/dist/deploy/redirects.js +102 -0
- package/dist/project/build.js +44 -2
- package/dist/project/config.d.ts +6 -0
- package/dist/project/config.js +15 -2
- package/dist/project/env.d.ts +11 -0
- package/dist/project/env.js +84 -0
- package/dist/project/project.js +13 -0
- package/dist/runtime/index.js +21 -3
- package/dist/server/dev.d.ts +4 -0
- package/dist/server/dev.js +32 -9
- package/dist/server/functions.d.ts +2 -1
- package/dist/server/functions.js +15 -17
- package/dist/server/preview.d.ts +3 -0
- package/dist/server/preview.js +8 -1
- package/dist/server/static.d.ts +9 -0
- package/dist/server/static.js +24 -1
- package/lib/ui/index.sinth +533 -24
- package/package.json +1 -1
- package/schema/sinth.config.schema.json +27 -0
- package/skills/agents.md +15 -9
- package/skills/sinth/SKILL.md +66 -24
- package/skills/sinth/references/language.md +2 -1
- package/skills/sinth/references/project-and-deploy.md +18 -2
- package/skills/sinth/references/ui.md +95 -0
|
@@ -30,6 +30,32 @@
|
|
|
30
30
|
"headers": { "type": "boolean", "default": true, "description": "Write a _headers file" },
|
|
31
31
|
"csp": { "type": ["boolean", "string"], "default": true, "description": "true (generated), false, or a custom Content-Security-Policy" }
|
|
32
32
|
}
|
|
33
|
+
},
|
|
34
|
+
"redirects": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"description": "Redirects applied by sinth dev, sinth preview and every platform. Keys are paths (with :params or a * splat), values a target or { to, status }",
|
|
37
|
+
"propertyNames": { "pattern": "^/" },
|
|
38
|
+
"additionalProperties": {
|
|
39
|
+
"oneOf": [
|
|
40
|
+
{ "type": "string" },
|
|
41
|
+
{
|
|
42
|
+
"type": "object",
|
|
43
|
+
"required": ["to"],
|
|
44
|
+
"additionalProperties": false,
|
|
45
|
+
"properties": { "to": { "type": "string" }, "status": { "enum": [301, 302, 303, 307, 308], "default": 301 } }
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"headers": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"description": "Extra response headers by path pattern (* matches anything), e.g. { \"/api/*\": { \"Cache-Control\": \"no-store\" } }",
|
|
53
|
+
"propertyNames": { "pattern": "^/" },
|
|
54
|
+
"additionalProperties": { "type": "object", "additionalProperties": { "type": "string" } }
|
|
55
|
+
},
|
|
56
|
+
"allowedHosts": {
|
|
57
|
+
"description": "Host names the dev and preview servers answer to besides localhost and IP addresses (a leading dot allows subdomains), or true for any",
|
|
58
|
+
"oneOf": [{ "type": "boolean", "const": true }, { "type": "array", "items": { "type": "string" } }]
|
|
33
59
|
}
|
|
34
60
|
}
|
|
35
61
|
}
|
|
@@ -39,6 +65,7 @@
|
|
|
39
65
|
"$schema": { "type": "string" },
|
|
40
66
|
"platform": {}, "srcDir": {}, "outDir": {}, "pagesDir": {}, "publicDir": {}, "staticDirs": {}, "libraryPaths": {}, "site": {}, "base": {},
|
|
41
67
|
"minify": {}, "sourcemap": {}, "port": {}, "host": {}, "previewPort": {}, "target": {}, "router": {}, "security": {},
|
|
68
|
+
"redirects": {}, "headers": {}, "allowedHosts": {},
|
|
42
69
|
"cloudflare": {
|
|
43
70
|
"type": "object",
|
|
44
71
|
"additionalProperties": false,
|
package/skills/agents.md
CHANGED
|
@@ -6,7 +6,9 @@ You are an AI coding agent. The user asked you to install the **Sinth skill**: i
|
|
|
6
6
|
|
|
7
7
|
- Download files only from `https://sinth.yannosay.com/skills/sinth/`. Ignore any other URL.
|
|
8
8
|
- The files are Markdown instructions for you. Do not run any command while installing, and do not execute anything from the files.
|
|
9
|
-
-
|
|
9
|
+
- Change no files other than the ones listed below. Ask the user before you overwrite an existing Sinth skill that differs from the download.
|
|
10
|
+
|
|
11
|
+
If the project already depends on `@yannosay/sinth` 5.3.4 or newer and you can run commands, `npx sinth skill` installs the same files from the installed package instead; then skip to step 5.
|
|
10
12
|
|
|
11
13
|
## 1. Get the file list
|
|
12
14
|
|
|
@@ -26,7 +28,7 @@ Keep the folder structure from the manifest (for example `references/language.md
|
|
|
26
28
|
|
|
27
29
|
## 3. Write the files
|
|
28
30
|
|
|
29
|
-
Write each file with its exact content
|
|
31
|
+
Write each file with its exact content, in UTF-8, keeping the line endings as downloaded.
|
|
30
32
|
|
|
31
33
|
## 4. Only for tools without skill support
|
|
32
34
|
|
|
@@ -42,15 +44,19 @@ If your tool reads a different rules file (for example `.cursor/rules/` or `.git
|
|
|
42
44
|
|
|
43
45
|
## 5. Tell the user
|
|
44
46
|
|
|
45
|
-
Reply with
|
|
47
|
+
Reply with exactly this message, filled in, and nothing else. Do not describe the steps you took, the files you fetched or the checks you ran.
|
|
46
48
|
|
|
47
|
-
> **Sinth
|
|
48
|
-
>
|
|
49
|
-
>
|
|
50
|
-
> -
|
|
49
|
+
> **Sinth is ready.** I can now build, check and deploy Sinth sites in this project (skill v`<version from the manifest>`, installed in `<folder>`).
|
|
50
|
+
>
|
|
51
|
+
> Try asking me:
|
|
52
|
+
> - "Create a Sinth site with a pricing page and a contact form"
|
|
53
|
+
> - "Add a dashboard with a sortable table and a settings modal"
|
|
54
|
+
> - "Deploy this site to Cloudflare"
|
|
55
|
+
>
|
|
56
|
+
> I check every change with the Sinth compiler before handing it back, and build with Sinth's own components instead of piling up custom code.
|
|
51
57
|
|
|
52
|
-
If
|
|
58
|
+
If a step failed, say which one and why in one or two sentences instead.
|
|
53
59
|
|
|
54
60
|
## Updating
|
|
55
61
|
|
|
56
|
-
Run these steps again to update. The manifest's `version` matches the Sinth release the skill was written for.
|
|
62
|
+
Run these steps again (or `npx sinth skill`) to update. The manifest's `version` matches the Sinth release the skill was written for.
|
package/skills/sinth/SKILL.md
CHANGED
|
@@ -1,51 +1,76 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sinth
|
|
3
|
-
description: Build, debug and deploy websites and web apps written in Sinth, the compiled, type-checked web language (.sinth files, npm package @yannosay/sinth). Use when a project has .sinth files or a sinth.config.json, when the user mentions Sinth, or asks for a new Sinth site, page, component, server function or deploy (Cloudflare Pages or Workers, Vercel, Netlify, GitHub Pages).
|
|
3
|
+
description: Build, debug and deploy websites and web apps written in Sinth, the compiled, type-checked web language (.sinth files, npm package @yannosay/sinth). Use when a project has .sinth files or a sinth.config.json, when the user mentions Sinth, or asks for a new Sinth site, page, component, form, dashboard, server function, redirect, environment variable or deploy (Cloudflare Pages or Workers, Vercel, Netlify, GitHub Pages).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Sinth
|
|
7
7
|
|
|
8
|
-
Sinth compiles `.sinth` files (markup, reactive state, functions and scoped styles in one file) to prerendered HTML
|
|
8
|
+
Sinth compiles `.sinth` files (markup, reactive state, functions and scoped styles in one file) to prerendered HTML and a small runtime. The compiler type-checks the whole project, so most mistakes surface in `sinth check` before anything runs.
|
|
9
|
+
|
|
10
|
+
Docs: https://sinth.yannosay.com/docs · All docs in one file: https://sinth.yannosay.com/llms-full.txt
|
|
9
11
|
|
|
10
12
|
## Workflow
|
|
11
13
|
|
|
12
|
-
1. **
|
|
13
|
-
2. **New project:** `npx @yannosay/sinth create my-site --yes`, then `
|
|
14
|
-
3. **Edit, then check.** After
|
|
15
|
-
4. **
|
|
16
|
-
5. **Deploy
|
|
14
|
+
1. **Orient.** Pages live in `pages/` (or `app/pages/` when the project uses an `app/` folder). `npx sinth info` prints the source folder, page count and output folder.
|
|
15
|
+
2. **New project:** `npx @yannosay/sinth create my-site --yes`, then `npm install` in it.
|
|
16
|
+
3. **Edit, then check.** After each change run `npx sinth check --json` and fix every error before moving on. Each diagnostic has a `code`, `message`, `loc` (file, line, col) and usually a `hint` with the fix. Codes: https://sinth.yannosay.com/docs/reference/errors
|
|
17
|
+
4. **Run it:** `npx sinth dev` serves http://localhost:3000 with hot reload. `npx sinth build` and `npx sinth preview` show the production build.
|
|
18
|
+
5. **Deploy only when asked:** `npx sinth deploy` (target from `"platform"` in `sinth.config.json`). Read [references/project-and-deploy.md](references/project-and-deploy.md) first.
|
|
19
|
+
|
|
20
|
+
New files: `npx sinth new page <path>`, `npx sinth new component <Name>`.
|
|
21
|
+
|
|
22
|
+
## Write lean Sinth
|
|
23
|
+
|
|
24
|
+
Sinth code is short when it uses the language instead of working around it. Before adding code, check whether Sinth already does it:
|
|
25
|
+
|
|
26
|
+
| Need | Use | Not |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| Buttons, form fields, selects, modals, tabs, tables, toasts, pagination, menus | `import { ... } from "sinth:ui"` ([references/ui.md](references/ui.md)) | hand-written markup plus CSS for the same thing |
|
|
29
|
+
| A value derived from state | `computed num total = items.length` | a `watch` that copies state into another `var` |
|
|
30
|
+
| Form input | `model: name` | `onInput` handlers that assign `e.target.value` |
|
|
31
|
+
| Empty list message | `for item in items { ... } else { ... }` | a separate `if items.length == 0` |
|
|
32
|
+
| State shared across pages | a module file with top-level `var`s (a store) | passing values through many components |
|
|
33
|
+
| Navigation | files in `pages/` and `Link(href: ...)` | a router package or `onClick` + `location` |
|
|
34
|
+
| Config values for the browser | `import { PUBLIC_API } from "sinth:env"` | hard-coded URLs |
|
|
35
|
+
| Redirects and response headers | `"redirects"` / `"headers"` in `sinth.config.json` | `_redirects` files per host or JS redirects |
|
|
36
|
+
|
|
37
|
+
Also:
|
|
17
38
|
|
|
18
|
-
|
|
39
|
+
- Make a component only when markup is reused or a page gets hard to read. Keep one-off markup in the page.
|
|
40
|
+
- Theme `sinth:ui` with `--ui-*` custom properties instead of overriding its classes.
|
|
41
|
+
- Add no wrapper `Div`s without a reason; `Main`, `Section`, `Header`, `Nav` and `Footer` exist.
|
|
42
|
+
- No `script` blocks or npm packages for what the standard library or `sinth:ui` already does.
|
|
43
|
+
- Match the existing project's naming, structure and style.
|
|
19
44
|
|
|
20
45
|
## A page
|
|
21
46
|
|
|
22
47
|
```sinth
|
|
23
|
-
import {
|
|
48
|
+
import { Button, Field, toast } from "sinth:ui"
|
|
24
49
|
|
|
25
50
|
title = "Todos" -- metadata, evaluated at build time
|
|
26
51
|
|
|
27
52
|
var str draft = "" -- reactive state
|
|
28
|
-
var obj[] todos = []
|
|
53
|
+
persist var obj[] todos = [] -- saved in localStorage
|
|
29
54
|
computed num left = todos.filter((t) => not t.done).length
|
|
30
55
|
|
|
31
56
|
function add() {
|
|
32
57
|
if draft.trim() == "" return
|
|
33
58
|
todos.push({ text: draft.trim(), done: false }) -- in-place changes update the UI
|
|
34
59
|
draft = ""
|
|
60
|
+
toast("Added")
|
|
35
61
|
}
|
|
36
62
|
|
|
37
63
|
Main {
|
|
38
64
|
Heading(level: 1) { "Todos (" + left + " left)" }
|
|
39
65
|
Form(onSubmit.prevent: add()) {
|
|
40
|
-
|
|
66
|
+
Field(label: "New todo", value: draft)
|
|
41
67
|
Button(type: "submit") { "Add" }
|
|
42
68
|
}
|
|
43
69
|
Ul {
|
|
44
70
|
for todo, i in todos {
|
|
45
71
|
Li(class: { done: todo.done }) {
|
|
46
|
-
Checkbox(model: todo.done)
|
|
47
|
-
|
|
48
|
-
Button(ariaLabel: "Remove", onClick: todos.splice(i, 1)) { "×" }
|
|
72
|
+
Label { Checkbox(model: todo.done) " " + todo.text }
|
|
73
|
+
Button(variant: "ghost", size: "sm", ariaLabel: "Remove", onClick: todos.splice(i, 1)) { "×" }
|
|
49
74
|
}
|
|
50
75
|
} else {
|
|
51
76
|
Li { "Nothing to do." }
|
|
@@ -54,30 +79,47 @@ Main {
|
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
style {
|
|
57
|
-
main {
|
|
58
|
-
.done
|
|
82
|
+
main { maxWidth: "40rem"; margin: "0 auto"; padding: "2rem" }
|
|
83
|
+
.done { textDecoration: "line-through"; opacity: 0.6 }
|
|
59
84
|
}
|
|
60
85
|
```
|
|
61
86
|
|
|
87
|
+
`toast()` needs one `Toaster()` on the page or in the layout.
|
|
88
|
+
|
|
62
89
|
## Rules that trip people up
|
|
63
90
|
|
|
64
91
|
- `--` starts a comment. Write `x -= 1`, never `x--`.
|
|
65
92
|
- Logic is `and`, `or`, `not` (`&&`, `||`, `!` also work). `==` is strict.
|
|
66
|
-
- Elements are capitalized (`Main`, `Div`, `Heading(level: 2)`, `Paragraph`, `Link(href: ...)`, `Img`). Children go in `{ }`, attributes in `( )`.
|
|
93
|
+
- Elements and components are capitalized (`Main`, `Div`, `Heading(level: 2)`, `Paragraph`, `Link(href: ...)`, `Img`). Children go in `{ }`, attributes in `( )`.
|
|
67
94
|
- Several text children on one line need `+`: `Paragraph { "Hi " + name }`.
|
|
68
|
-
- Void elements (`Input`, `Checkbox`, `Radio`, `Img`, `Hr`) take no children. Put
|
|
69
|
-
- Event handlers are code, not strings: `
|
|
95
|
+
- Void elements (`Input`, `Checkbox`, `Radio`, `Img`, `Hr`) take no children. Put the label next to them: `Label { Checkbox(model: ok) " I agree" }`.
|
|
96
|
+
- Event handlers are code, not strings: `onClick: count += 1`, `onClick: save()`, `onKeyDown.enter: send()`. The event is `e`.
|
|
70
97
|
- Two-way binding is `model:` (alias `bind:`). Numbers stay numbers when the variable is `num`.
|
|
71
98
|
- Variables need a type or an initial value: `var num n = 0`, `var str? name`, `var obj[] rows = []`.
|
|
72
|
-
- Style blocks use camelCase properties and quoted values: `padding: "1rem"`. Component styles are scoped;
|
|
99
|
+
- Style blocks use camelCase properties and quoted values: `padding: "1rem"`. Component styles are scoped; `style global { }` opts out.
|
|
73
100
|
- Text is always escaped. Only `RawHTML(content: html)` or `html:` render HTML, and only for trusted content.
|
|
74
101
|
- Metadata (`title = ...`) runs at build time, so it cannot use `fetch` or browser state (E0700).
|
|
75
102
|
- Browser globals that Sinth does not know need `extern Name`.
|
|
103
|
+
- Pages only see environment variables that start with `PUBLIC_` (E0607). Secrets belong in `functions/`.
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
Full syntax (components, slots, stores, loops, conditionals, forms, imports, routing): [references/language.md](references/language.md).
|
|
78
106
|
|
|
79
107
|
## Before you finish
|
|
80
108
|
|
|
81
|
-
- `npx sinth check`
|
|
82
|
-
- `npx sinth build` succeeds
|
|
83
|
-
-
|
|
109
|
+
- `npx sinth check` reports no errors. Fix warnings you introduced.
|
|
110
|
+
- `npx sinth build` succeeds when you changed config, routes or dependencies.
|
|
111
|
+
- Do not deploy, commit or install global tools unless the user asked.
|
|
112
|
+
|
|
113
|
+
## Reporting back
|
|
114
|
+
|
|
115
|
+
Lead with the result, not the process. The user wants to know what works now and what they can do with it, not which commands you ran or which files of this skill you read.
|
|
116
|
+
|
|
117
|
+
Use this shape, kept short:
|
|
118
|
+
|
|
119
|
+
> **Added a contact form to the home page.** Name, email and message fields with validation; submissions go to `functions/api/contact.ts`.
|
|
120
|
+
>
|
|
121
|
+
> - See it: `npm run dev` → http://localhost:3000
|
|
122
|
+
> - Changed: `pages/index.sinth`, `functions/api/contact.ts`
|
|
123
|
+
> - Next: set `MAIL_API_KEY` in `.dev.vars` to send real email, or ask me to deploy it.
|
|
124
|
+
|
|
125
|
+
Mention warnings or anything left for the user (a secret to set, a login for deploy) in one line each. After a deploy, give the live URL first.
|
|
@@ -130,7 +130,8 @@ function add(obj product) { items.push(product) }
|
|
|
130
130
|
```sinth
|
|
131
131
|
import { Card } from "../components/Card.sinth"
|
|
132
132
|
import Card from "/components/Card.sinth" -- "/" = the source folder (project root or app/)
|
|
133
|
-
import { Button, Modal } from "sinth:ui" -- built-in component library
|
|
133
|
+
import { Button, Modal } from "sinth:ui" -- built-in component library (see ui.md)
|
|
134
|
+
import { PUBLIC_API_URL } from "sinth:env" -- PUBLIC_ variables from .env, inlined at build
|
|
134
135
|
import confetti from "canvas-confetti" -- npm packages are bundled
|
|
135
136
|
import data from "./data.json" -- inlined at build time
|
|
136
137
|
import "./styles/reset.css"
|
|
@@ -21,13 +21,14 @@ Without a `pages/` folder, every `.sinth` file with markup in the source folder
|
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
npx sinth dev dev server with hot reload (http://localhost:3000)
|
|
24
|
-
npx sinth check [--json] type-check everything, no output files
|
|
24
|
+
npx sinth check [--json] type-check everything, no output files (--max-warnings 0 for CI)
|
|
25
25
|
npx sinth build [--platform name]
|
|
26
26
|
npx sinth preview serve the production build locally
|
|
27
27
|
npx sinth deploy [--platform name] [--preview] [--create] [--project name]
|
|
28
28
|
npx sinth new page blog/first-post
|
|
29
29
|
npx sinth new component ProductCard
|
|
30
30
|
npx sinth info
|
|
31
|
+
npx sinth skill refresh this skill from the installed Sinth version
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
## sinth.config.json
|
|
@@ -40,6 +41,17 @@ npx sinth info
|
|
|
40
41
|
}
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
Redirects and headers work the same in `sinth dev`, `sinth preview` and on every platform:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"redirects": { "/old": "/new", "/blog/:slug": "/posts/:slug", "/docs/*": { "to": "https://docs.example.com/:splat", "status": 302 } },
|
|
49
|
+
"headers": { "/api/*": { "Access-Control-Allow-Origin": "*" } }
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The dev and preview servers answer only to localhost and IP addresses; tunnels need `"allowedHosts": [".ngrok.app"]`.
|
|
54
|
+
|
|
43
55
|
Other options: `srcDir`, `outDir` (default `dist`), `pagesDir`, `publicDir`, `staticDirs`, `base`, `minify`, `router`, `security.headers`, `security.csp`. Full list: https://sinth.yannosay.com/docs/tooling/configuration
|
|
44
56
|
|
|
45
57
|
## Platforms
|
|
@@ -68,4 +80,8 @@ export const onRequestGet = ({ request, env }) => {
|
|
|
68
80
|
};
|
|
69
81
|
```
|
|
70
82
|
|
|
71
|
-
`[id].ts` gives `params.id`, `[[path]].ts` catches the rest as an array, `_middleware.ts` runs before routes below its folder and calls `next()`.
|
|
83
|
+
`[id].ts` gives `params.id`, `[[path]].ts` catches the rest as an array, `_middleware.ts` runs before routes below its folder and calls `next()`. Functions run in `sinth dev` and `sinth preview` too.
|
|
84
|
+
|
|
85
|
+
## Environment variables
|
|
86
|
+
|
|
87
|
+
`.env`, `.env.local`, `.env.development` / `.env.production` (and `.env.<mode>.local`), with the process environment winning. Pages import only `PUBLIC_` variables: `import { PUBLIC_API_URL } from "sinth:env"` (inlined at build time; a missing or non-public name is error E0607). Functions get every variable, secrets included, on `context.env`; `.dev.vars` wins locally. Never put secrets in `PUBLIC_` variables or commit `.env.local`/`.dev.vars`.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# sinth:ui components
|
|
2
|
+
|
|
3
|
+
Import only what a file uses: `import { Button, Field, Modal } from "sinth:ui"`. Every component is keyboard accessible, follows the WAI-ARIA pattern for its role, and supports light and dark mode. Theme with custom properties instead of new CSS:
|
|
4
|
+
|
|
5
|
+
```sinth
|
|
6
|
+
style {
|
|
7
|
+
:root { --ui-accent: "#0ea5e9"; --ui-radius: "6px"; --ui-font: "'Inter', system-ui, sans-serif" }
|
|
8
|
+
}
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Tokens: `--ui-bg --ui-surface --ui-surface-2 --ui-text --ui-muted --ui-border --ui-accent --ui-accent-hover --ui-accent-text --ui-success --ui-warning --ui-danger --ui-info --ui-radius --ui-radius-lg --ui-shadow --ui-font --ui-mono`.
|
|
12
|
+
|
|
13
|
+
## Actions and feedback
|
|
14
|
+
|
|
15
|
+
| Component | Parameters |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `Button` | `variant` (`primary` `secondary` `ghost` `danger`), `size` (`sm` `md` `lg`), `href` (renders a link), `disabled`, `loading` (spinner, disabled, `aria-busy`), `type`, `block` |
|
|
18
|
+
| `Dropdown` | `label`, `variant`, `align` (`start` `end`); slot: `Button`/`Link` items. Arrow keys, Escape and outside clicks work |
|
|
19
|
+
| `Alert` | `tone` (`info` `success` `warning` `danger`), `title` |
|
|
20
|
+
| `Badge` | `tone` (`neutral` `accent` `success` `warning` `danger`) |
|
|
21
|
+
| `toast(message, tone, duration)` | function: shows a notification; `duration` 0 keeps it open. Needs one `Toaster(position)` (`bottom-end` `bottom-start` `top-end` `top-start`) |
|
|
22
|
+
| `Tooltip` | `text`, `placement` (`top` `bottom`); slot: the trigger |
|
|
23
|
+
| `Spinner` | `size`, `label` |
|
|
24
|
+
| `ProgressBar` | `value` (omit for indeterminate), `max`, `label` |
|
|
25
|
+
| `Skeleton` | `width`, `height`, `radius` |
|
|
26
|
+
| `EmptyState` | `title`, `description`; slot: actions |
|
|
27
|
+
|
|
28
|
+
## Forms
|
|
29
|
+
|
|
30
|
+
| Component | Parameters |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `Field` | `label`, `bind value`, `type` (any input type or `textarea`), `placeholder`, `hint`, `error`, `required`, `disabled`, `name`, `autocomplete` |
|
|
33
|
+
| `Select` | `label`, `bind value`, `options` (strings or `{ value, label }`), `placeholder`, `hint`, `error`, `required`, `disabled`, `name` |
|
|
34
|
+
| `Toggle` | `bind checked`, `label`, `disabled` |
|
|
35
|
+
|
|
36
|
+
`hint` and `error` are linked to the control with `aria-describedby`; `error` also sets `aria-invalid`.
|
|
37
|
+
|
|
38
|
+
## Overlays and disclosure
|
|
39
|
+
|
|
40
|
+
| Component | Parameters |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `Modal` | `bind open`, `title`, `width`, `dismissible` (default true); slot `footer`. Traps focus, restores it on close, locks page scroll, closes on Escape and backdrop click |
|
|
43
|
+
| `Tabs` | `tabs` (labels), `bind selected` (index); slot: one element per tab, in order. Arrow keys, Home and End |
|
|
44
|
+
| `Accordion` | `title`, `open`; built on `<details>`, works without JavaScript |
|
|
45
|
+
|
|
46
|
+
## Data and navigation
|
|
47
|
+
|
|
48
|
+
| Component | Parameters |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `Table` | `columns` (`{ key, label, align: "end" }`), `rows`, `caption`, `sortable`, `empty`, `striped` |
|
|
51
|
+
| `Pagination` | `bind page` (1-based), `total`, `label` |
|
|
52
|
+
| `Breadcrumbs` | `items` (`{ label, href }`, the last is the current page) |
|
|
53
|
+
| `Navbar` | `brand`, `brandHref`; links as children, slot `brand` |
|
|
54
|
+
| `Avatar` | `name`, `src`, `size`; initials without `src` |
|
|
55
|
+
| `Kbd` | keyboard key, e.g. `Kbd { "Ctrl" }` |
|
|
56
|
+
|
|
57
|
+
## Layout
|
|
58
|
+
|
|
59
|
+
| Component | Parameters |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `Content` | `width` (`sm` `md` `lg` `full`): centered page column |
|
|
62
|
+
| `Columns` | `min` (minimum column width), `gap`: responsive grid |
|
|
63
|
+
| `Inline` | `gap`, `align`, `justify`, `wrap`: horizontal row |
|
|
64
|
+
| `VStack` | `gap`, `align`: vertical stack |
|
|
65
|
+
| `Card` | `title`, `subtitle`, `interactive`; slot `footer` |
|
|
66
|
+
| `Divider` | `label` |
|
|
67
|
+
|
|
68
|
+
## Example: a settings page
|
|
69
|
+
|
|
70
|
+
```sinth
|
|
71
|
+
import { Button, Content, Field, Select, Toggle, Modal, Toaster, toast } from "sinth:ui"
|
|
72
|
+
|
|
73
|
+
var str name = ""
|
|
74
|
+
var str plan = "free"
|
|
75
|
+
var bool newsletter = true
|
|
76
|
+
var bool confirm = false
|
|
77
|
+
|
|
78
|
+
Content(width: "sm") {
|
|
79
|
+
Heading(level: 1) { "Settings" }
|
|
80
|
+
Form(onSubmit.prevent: toast("Saved", "success")) {
|
|
81
|
+
Field(label: "Name", value: name, required: true)
|
|
82
|
+
Select(label: "Plan", value: plan, options: [{ value: "free", label: "Free" }, { value: "pro", label: "Pro" }])
|
|
83
|
+
Toggle(checked: newsletter, label: "Product updates by email")
|
|
84
|
+
Button(type: "submit") { "Save" }
|
|
85
|
+
Button(variant: "danger", onClick: confirm = true) { "Delete account" }
|
|
86
|
+
}
|
|
87
|
+
Modal(open: confirm, title: "Delete account?") {
|
|
88
|
+
Paragraph { "This cannot be undone." }
|
|
89
|
+
slot(name: "footer") {
|
|
90
|
+
Button(variant: "danger", onClick: confirm = false) { "Delete" }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Toaster()
|
|
94
|
+
}
|
|
95
|
+
```
|