sidedish 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +54 -2
- package/bin/sidedish.mjs +62 -0
- package/fonts.css +2 -0
- package/index.d.ts +26 -0
- package/index.js +25 -0
- package/package.json +49 -3
- package/sidedish.css +266 -0
- package/sidedish.js +214 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sidedish contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sidedish
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small component kit for **Next.js**, built on **Tailwind CSS v4**, in terracotta, warm off-white and near-black, set in DM Sans and Red Hat Mono.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm dlx sidedish init # or: npx sidedish init
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
This installs `sidedish`, `tailwindcss`, `@tailwindcss/postcss` and `postcss` using your lockfile's package manager, adds `postcss.config.mjs` if you have none, and patches `globals.css` and `app/layout.tsx` (or `src/app/…`):
|
|
10
|
+
|
|
11
|
+
```css
|
|
12
|
+
/* app/globals.css */
|
|
13
|
+
@import "sidedish/fonts.css";
|
|
14
|
+
@import "tailwindcss";
|
|
15
|
+
@import "sidedish/sidedish.css"; /* sits in Tailwind layers: your utilities always win */
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import "./globals.css";
|
|
20
|
+
import { Sidedish } from "sidedish";
|
|
21
|
+
// …
|
|
22
|
+
<body>
|
|
23
|
+
<Sidedish /> {/* optional: theme={{ accent: "#7c3aed" }} */}
|
|
24
|
+
{children}
|
|
25
|
+
</body>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Flags: `--no-install`, `--no-fonts`.
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
- HTML tags and classes work in Server Components: `<button data-tone="good">`, `<article className="card">`, `<sd-tabs>`.
|
|
33
|
+
- Client helpers: `import { toast, theme, useSidedishEvent } from "sidedish"`.
|
|
34
|
+
- Colours are props: `data-tone="good|warn|bad|info|ink|neutral"`, `style={{ "--tone": "#hex" }}` (typed), or `<Sidedish theme={{ accent }} />`.
|
|
35
|
+
- Layout and responsiveness are Tailwind: `grid grid-cols-1 sm:grid-cols-3 gap-4`, `md:flex`, and so on.
|
|
36
|
+
- Colours are Tailwind colours too: `bg-accent`, `text-muted`, `border-line`, `bg-tint`, `text-good`.
|
|
37
|
+
- Dark mode: `<html data-theme="dark">`; `dark:` variants follow it.
|
|
38
|
+
|
|
39
|
+
## Package contents
|
|
40
|
+
|
|
41
|
+
| File | Purpose |
|
|
42
|
+
|------|---------|
|
|
43
|
+
| `sidedish.css` | All styles, in Tailwind `base`/`components` layers, plus the `@theme` colour tokens |
|
|
44
|
+
| `sidedish.js` | Web components + toast/theme (~2.8 KB gz), no-op on the server |
|
|
45
|
+
| `index.js` / `index.d.ts` | `<Sidedish />`, `toast`, `theme`, `useSidedishEvent`, JSX types for `sd-*` |
|
|
46
|
+
| `fonts.css` | Optional Google Fonts import |
|
|
47
|
+
| `bin/sidedish.mjs` | The `init` CLI |
|
|
48
|
+
|
|
49
|
+
The docs site lives in the repo at `apps/docs` and is not part of the npm package.
|
|
50
|
+
|
|
51
|
+
## Publish
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pnpm publish # check that the name "sidedish" is free first
|
|
55
|
+
```
|
package/bin/sidedish.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pnpm dlx sidedish init: installs sidedish + Tailwind v4 and wires them into your Next.js app. No prompts.
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2), cwd = process.cwd();
|
|
8
|
+
const has = (f) => existsSync(join(cwd, f));
|
|
9
|
+
const fail = (m) => { console.error("✖ " + m); process.exit(1); };
|
|
10
|
+
|
|
11
|
+
if ((args[0] ?? "init") !== "init") fail("Usage: sidedish init [--no-install] [--no-fonts]");
|
|
12
|
+
if (!has("package.json")) fail("No package.json here. Run this in your Next.js project root.");
|
|
13
|
+
|
|
14
|
+
if (!args.includes("--no-install")) {
|
|
15
|
+
// Lockfile first; without one (new app, or a workspace package) use whoever ran us, else pnpm.
|
|
16
|
+
const ran = process.env.npm_config_user_agent?.match(/^(pnpm|npm|yarn|bun)\//)?.[1];
|
|
17
|
+
const name = has("pnpm-lock.yaml") ? "pnpm" : has("yarn.lock") ? "yarn" : has("bun.lockb") || has("bun.lock") ? "bun" : has("package-lock.json") ? "npm" : ran ?? "pnpm";
|
|
18
|
+
const pm = name === "npm" ? "npm install" : `${name} add`;
|
|
19
|
+
const pkgs = "sidedish tailwindcss @tailwindcss/postcss postcss";
|
|
20
|
+
console.log(`→ ${pm} ${pkgs}`);
|
|
21
|
+
execSync(`${pm} ${pkgs}`, { stdio: "inherit", cwd });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Tailwind v4 needs the PostCSS plugin. Keep any config the project already has.
|
|
25
|
+
if (!["postcss.config.mjs", "postcss.config.js", "postcss.config.cjs"].some(has)) {
|
|
26
|
+
writeFileSync(join(cwd, "postcss.config.mjs"), 'export default { plugins: { "@tailwindcss/postcss": {} } };\n');
|
|
27
|
+
console.log("✓ Created postcss.config.mjs");
|
|
28
|
+
} else console.log("• postcss config already exists. Make sure it uses @tailwindcss/postcss.");
|
|
29
|
+
|
|
30
|
+
const dirs = ["src/app", "app"];
|
|
31
|
+
const find = (name) => dirs.flatMap((d) => ["tsx", "jsx", "js"].map((e) => `${d}/${name}.${e}`)).find(has);
|
|
32
|
+
const layout = find("layout");
|
|
33
|
+
const manual = `\nAdd this to your root layout:\n\n import "./globals.css";\n import { Sidedish } from "sidedish";\n\n <body>\n <Sidedish />\n {children}\n </body>\n\nAnd to globals.css:\n\n @import "tailwindcss";\n @import "sidedish/sidedish.css";\n`;
|
|
34
|
+
if (!layout) fail("No app/layout found (App Router)." + manual);
|
|
35
|
+
|
|
36
|
+
// globals.css: Tailwind first, then Sidedish (its rules live in Tailwind layers, so your utilities always win).
|
|
37
|
+
const css = dirs.map((d) => `${d}/globals.css`).find(has) ?? `${layout.split("/").slice(0, -1).join("/")}/globals.css`;
|
|
38
|
+
let c = has(css) ? readFileSync(join(cwd, css), "utf8") : "";
|
|
39
|
+
if (!c.includes("sidedish")) {
|
|
40
|
+
const add = (args.includes("--no-fonts") ? "" : '@import "sidedish/fonts.css";\n') + (c.includes('"tailwindcss"') ? "" : '@import "tailwindcss";\n') + '@import "sidedish/sidedish.css";\n';
|
|
41
|
+
writeFileSync(join(cwd, css), add + c);
|
|
42
|
+
console.log(`✓ Patched ${css}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let src = readFileSync(join(cwd, layout), "utf8");
|
|
46
|
+
if (src.includes("sidedish")) { console.log(`✓ ${layout} already uses Sidedish.`); process.exit(0); }
|
|
47
|
+
if (!/<body[^>]*>/.test(src)) fail(`Couldn't find <body> in ${layout}.` + manual);
|
|
48
|
+
|
|
49
|
+
// Keep a leading "use …" directive on top.
|
|
50
|
+
const dir = src.match(/^\s*["']use \w+["'];?\s*\n/);
|
|
51
|
+
const at = dir ? dir[0].length : 0;
|
|
52
|
+
const imp = (/globals\.css/.test(src) ? "" : 'import "./globals.css";\n') + 'import { Sidedish } from "sidedish";\n';
|
|
53
|
+
src = src.slice(0, at) + imp + src.slice(at);
|
|
54
|
+
src = src.replace(/<body[^>]*>/, (m) => `${m}\n <Sidedish />`);
|
|
55
|
+
writeFileSync(join(cwd, layout), src);
|
|
56
|
+
|
|
57
|
+
console.log(`✓ Patched ${layout}
|
|
58
|
+
✓ Sidedish is ready. Try it in any page:
|
|
59
|
+
|
|
60
|
+
<button data-tone="good" className="md:w-auto w-full">Hello Sidedish</button>
|
|
61
|
+
|
|
62
|
+
Docs: open the Sidedish docs site → Installation`);
|
package/fonts.css
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DetailedHTMLProps, HTMLAttributes, ReactElement, RefObject } from "react";
|
|
2
|
+
|
|
3
|
+
export type Tone = "good" | "warn" | "bad" | "info" | "ink" | "neutral";
|
|
4
|
+
export type Tokens = Partial<Record<"accent" | "bg" | "surface" | "ink" | "sub" | "muted" | "line" | "tint" | "on" | "good" | "warn" | "bad" | "info" | "r" | "font" | "mono", string>>;
|
|
5
|
+
|
|
6
|
+
export declare function Sidedish(props?: { theme?: Tokens }): ReactElement | null;
|
|
7
|
+
export declare function toast(msg: string, opts?: { title?: string; tone?: Tone; duration?: number }): HTMLElement | undefined;
|
|
8
|
+
export declare function theme(vars: Tokens, scope?: HTMLElement): void;
|
|
9
|
+
export declare function useSidedishEvent<D = any>(ref: RefObject<HTMLElement | null>, name: "select" | "change" | "files" | "sort" | (string & {}), fn: (e: CustomEvent<D>) => void): void;
|
|
10
|
+
|
|
11
|
+
type El<T = {}> = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & T;
|
|
12
|
+
|
|
13
|
+
declare module "react" {
|
|
14
|
+
// Allow style={{ "--tone": "#7c3aed" }} without casts.
|
|
15
|
+
interface CSSProperties { [key: `--${string}`]: string | number | undefined }
|
|
16
|
+
namespace JSX {
|
|
17
|
+
interface IntrinsicElements {
|
|
18
|
+
"sd-tabs": El<{ selected?: number | string }>;
|
|
19
|
+
"sd-dropdown": El<{ align?: "end" }>;
|
|
20
|
+
"sd-tag-input": El<{ name?: string; value?: string; placeholder?: string }>;
|
|
21
|
+
"sd-table": El<{}>;
|
|
22
|
+
"sd-calendar": El<{ name?: string; value?: string; min?: string; max?: string }>;
|
|
23
|
+
"sd-upload": El<{ name?: string; accept?: string; multiple?: boolean; required?: boolean; label?: string; hint?: string }>;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "./sidedish.js";
|
|
3
|
+
import { createElement, useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
const sd = () => (typeof window != "undefined" ? window.Sidedish : undefined);
|
|
6
|
+
|
|
7
|
+
/** Mount once in app/layout.tsx. Ships the web components to the client; `theme` sets --sd-* tokens with no flash (rendered on the server). */
|
|
8
|
+
export function Sidedish({ theme: vars } = {}) {
|
|
9
|
+
if (!vars) return null;
|
|
10
|
+
const css = Object.entries(vars).map(([k, v]) => `--sd-${k}:${String(v).replace(/[<>{};]/g, "")}`).join(";");
|
|
11
|
+
return createElement("style", null, `:root{${css}}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const toast = (msg, opts) => sd()?.toast(msg, opts);
|
|
15
|
+
export const theme = (vars, scope) => sd()?.theme(vars, scope);
|
|
16
|
+
|
|
17
|
+
/** Listen to a Sidedish web-component event (select, change, files) from React. */
|
|
18
|
+
export function useSidedishEvent(ref, name, fn) {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const el = ref.current;
|
|
21
|
+
if (!el) return;
|
|
22
|
+
el.addEventListener(name, fn);
|
|
23
|
+
return () => el.removeEventListener(name, fn);
|
|
24
|
+
}, [ref, name, fn]);
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sidedish",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Sidedish: a small Tailwind CSS v4 component kit for Next.js. One command to install.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"./sidedish.css": "./sidedish.css",
|
|
15
|
+
"./fonts.css": "./fonts.css",
|
|
16
|
+
"./sidedish.js": "./sidedish.js"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"sidedish": "./bin/sidedish.mjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"sidedish.css",
|
|
25
|
+
"sidedish.js",
|
|
26
|
+
"fonts.css",
|
|
27
|
+
"bin"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"*.css",
|
|
31
|
+
"./sidedish.js",
|
|
32
|
+
"./index.js"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=18",
|
|
36
|
+
"tailwindcss": ">=4"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"react": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"nextjs",
|
|
45
|
+
"react",
|
|
46
|
+
"tailwindcss",
|
|
47
|
+
"ui",
|
|
48
|
+
"css",
|
|
49
|
+
"web-components",
|
|
50
|
+
"design-system"
|
|
51
|
+
]
|
|
6
52
|
}
|
package/sidedish.css
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/* Sidedish v0.1 · Tailwind CSS v4 layer · MIT
|
|
2
|
+
Import after tailwindcss: @import "tailwindcss"; @import "sidedish/sidedish.css"; */
|
|
3
|
+
@custom-variant dark (&:where([data-theme=dark],[data-theme=dark] *));
|
|
4
|
+
@theme inline{
|
|
5
|
+
--font-sans:var(--sd-font);--font-mono:var(--sd-mono);
|
|
6
|
+
--color-bg:var(--sd-bg);--color-surface:var(--sd-surface);--color-ink:var(--sd-ink);--color-sub:var(--sd-sub);--color-muted:var(--sd-muted);
|
|
7
|
+
--color-line:var(--sd-line);--color-tint:var(--sd-tint);--color-accent:var(--sd-accent);--color-on:var(--sd-on);
|
|
8
|
+
--color-good:var(--sd-good);--color-bad:var(--sd-bad);--color-warn:var(--sd-warn);--color-info:var(--sd-info);
|
|
9
|
+
}
|
|
10
|
+
@layer base{
|
|
11
|
+
:root{--sd-bg:#fdfcf9;--sd-surface:#fff;--sd-ink:#1a1a1a;--sd-sub:#443c35;--sd-muted:#6b5e52;--sd-line:#eeebe7;--sd-tint:#f7f2ee;--sd-accent:#d08873;--sd-on:#fff;--sd-good:#1f8a5b;--sd-bad:#c4213f;--sd-warn:#b57b08;--sd-info:#3b6fd4;--sd-r:2px;--sd-font:var(--sd-font-sans,"DM Sans",system-ui,sans-serif);--sd-mono:var(--sd-font-mono,"Red Hat Mono",ui-monospace,monospace);--sd-ease:cubic-bezier(.16,1,.3,1);color-scheme:light}
|
|
12
|
+
[data-theme=dark]{--sd-bg:#12100f;--sd-surface:#1c1917;--sd-ink:#fdfcf9;--sd-sub:#cfc7c0;--sd-muted:#9b9088;--sd-line:#332e2a;--sd-tint:#26221f;color-scheme:dark}
|
|
13
|
+
[data-tone=good]{--tone:var(--sd-good)}[data-tone=bad]{--tone:var(--sd-bad)}[data-tone=warn]{--tone:var(--sd-warn)}[data-tone=info]{--tone:var(--sd-info)}[data-tone=ink]{--tone:var(--sd-ink)}[data-tone=neutral]{--tone:var(--sd-muted)}
|
|
14
|
+
[data-theme=dark] [data-tone=ink]{--sd-on:var(--sd-bg)}
|
|
15
|
+
[hidden]{display:none!important}
|
|
16
|
+
body{margin:0;background:var(--sd-bg);color:var(--sd-ink);font:400 14px/1.6 var(--sd-font);-webkit-font-smoothing:antialiased}
|
|
17
|
+
:focus-visible{outline:2px solid var(--tone,var(--sd-accent));outline-offset:2px}
|
|
18
|
+
::selection{background:color-mix(in srgb,var(--sd-accent) 22%,transparent)}
|
|
19
|
+
|
|
20
|
+
/* Typography */
|
|
21
|
+
h1,h2,h3,h4,h5,h6{margin:0 0 .5em;line-height:1.2;font-weight:600;letter-spacing:-.02em}
|
|
22
|
+
h1{font-size:2.25rem}h2{font-size:1.5rem}h3{font-size:1.2rem}h4{font-size:1rem}h5,h6{font-size:.875rem}
|
|
23
|
+
p{margin:0 0 1em;color:var(--sd-sub)}
|
|
24
|
+
a{color:var(--sd-accent);text-underline-offset:3px}
|
|
25
|
+
small,.muted{color:var(--sd-muted)}small{font-size:12px}
|
|
26
|
+
code,kbd,pre{font-family:var(--sd-mono);font-size:12.5px}
|
|
27
|
+
code{background:var(--sd-tint);padding:.15em .4em;border-radius:var(--sd-r)}
|
|
28
|
+
kbd{border:1px solid var(--sd-line);border-bottom-width:2px;padding:.1em .45em;border-radius:var(--sd-r);background:var(--sd-surface)}
|
|
29
|
+
pre{margin:0 0 1em;background:#1f1b18;color:#ece7e2;padding:16px;overflow:auto;border:1px solid var(--sd-line);border-radius:var(--sd-r);line-height:1.65}
|
|
30
|
+
pre code{background:none;padding:0;color:inherit}
|
|
31
|
+
blockquote{margin:0 0 1em;padding-left:16px;border-left:2px solid var(--sd-accent);color:var(--sd-sub);font-style:italic}
|
|
32
|
+
hr{border:0;border-top:1px solid var(--sd-line);margin:24px 0}
|
|
33
|
+
.lead{font-size:1.125rem;color:var(--sd-sub)}
|
|
34
|
+
.eyebrow{font:500 11px/1.4 var(--sd-mono);letter-spacing:.08em;text-transform:uppercase;color:var(--sd-muted)}
|
|
35
|
+
}
|
|
36
|
+
@layer components{
|
|
37
|
+
/* Button */
|
|
38
|
+
button,.btn{--h:36px;display:inline-flex;align-items:center;justify-content:center;gap:8px;height:var(--h);padding:0 16px;border:1px solid transparent;border-radius:var(--sd-r);background:var(--tone,var(--sd-accent));color:var(--sd-on);font:500 13px/1 var(--sd-font);letter-spacing:.02em;text-transform:none;white-space:nowrap;text-decoration:none;cursor:pointer;transition:transform .2s var(--sd-ease),background .2s,opacity .2s}
|
|
39
|
+
button:hover,.btn:hover{transform:translateY(-1px);opacity:.9}
|
|
40
|
+
button:active,.btn:active{transform:scale(.985)}
|
|
41
|
+
button:disabled,.btn[aria-disabled=true]{opacity:.5;pointer-events:none}
|
|
42
|
+
:is(button,.btn)[data-variant=ghost]{background:transparent;border-color:var(--sd-line);color:var(--sd-sub)}
|
|
43
|
+
:is(button,.btn)[data-variant=quiet]{background:transparent;color:var(--sd-muted)}
|
|
44
|
+
:is(button,.btn):is([data-variant=ghost],[data-variant=quiet]):hover{background:var(--sd-tint);color:var(--sd-ink);opacity:1}
|
|
45
|
+
:is(button,.btn,.badge)[data-variant=soft]{background:color-mix(in srgb,var(--tone,var(--sd-accent)) 12%,transparent);color:var(--tone,var(--sd-accent))}
|
|
46
|
+
:is(button,.btn)[data-size=sm]{--h:30px;padding:0 12px;font-size:12px}
|
|
47
|
+
:is(button,.btn)[data-size=lg]{--h:44px;padding:0 24px;font-size:14px}
|
|
48
|
+
:is(button,.btn)[data-size=icon]{width:var(--h);padding:0}
|
|
49
|
+
button[aria-busy=true]{pointer-events:none;opacity:.8}
|
|
50
|
+
button[aria-busy=true]::before,.spinner{content:"";width:1em;height:1em;border:2px solid color-mix(in srgb,currentColor 25%,transparent);border-top-color:currentColor;border-radius:50%;animation:sd-spin .7s linear infinite}
|
|
51
|
+
.spinner{display:inline-block;width:18px;height:18px;color:var(--tone,var(--sd-accent))}
|
|
52
|
+
.spinner[data-size=sm]{width:12px;height:12px}.spinner[data-size=lg]{width:28px;height:28px;border-width:3px}
|
|
53
|
+
|
|
54
|
+
/* Form elements */
|
|
55
|
+
label{display:grid;gap:6px;font-size:13px;font-weight:500;color:var(--sd-sub)}
|
|
56
|
+
label:has(>[type=checkbox],>[type=radio]){display:flex;align-items:center;gap:8px;font-weight:400;cursor:pointer}
|
|
57
|
+
input:not([type=checkbox],[type=radio],[type=range],[type=file]),select,textarea{width:100%;height:38px;padding:0 12px;border:1px solid var(--sd-line);border-radius:var(--sd-r);background:var(--sd-surface);color:var(--sd-ink);font:400 13px var(--sd-font);outline:0;transition:border-color .2s,box-shadow .2s}
|
|
58
|
+
textarea{height:auto;min-height:88px;padding:10px 12px;resize:vertical}
|
|
59
|
+
select{appearance:none;padding-right:32px;background:var(--sd-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center}
|
|
60
|
+
:is(input,select,textarea):hover{border-color:color-mix(in srgb,var(--sd-ink) 22%,var(--sd-line))}
|
|
61
|
+
:is(input,select,textarea):focus{border-color:var(--sd-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--sd-accent) 15%,transparent)}
|
|
62
|
+
:is(input,select,textarea):disabled{opacity:.55;cursor:not-allowed}
|
|
63
|
+
[aria-invalid=true]{border-color:var(--sd-bad)!important}
|
|
64
|
+
[type=checkbox],[type=radio],[type=range]{accent-color:var(--tone,var(--sd-accent));margin:0}
|
|
65
|
+
[type=checkbox],[type=radio]{width:16px;height:16px}
|
|
66
|
+
[type=range]{width:100%}
|
|
67
|
+
fieldset{display:grid;gap:12px;margin:0;padding:16px;border:1px solid var(--sd-line);border-radius:var(--sd-r)}
|
|
68
|
+
legend{padding:0 6px;font-weight:600}
|
|
69
|
+
.hint{font-size:12px;font-weight:400;color:var(--sd-muted)}
|
|
70
|
+
.error{font-size:12px;font-weight:400;color:var(--sd-bad)}
|
|
71
|
+
|
|
72
|
+
/* Switch: <input type="checkbox" role="switch"> */
|
|
73
|
+
input[role=switch]{appearance:none;position:relative;width:34px;height:20px;border-radius:99px;background:var(--sd-line);cursor:pointer;transition:background .2s}
|
|
74
|
+
input[role=switch]::before{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:#fff;box-shadow:0 1px 2px #0003;transition:transform .2s var(--sd-ease)}
|
|
75
|
+
input[role=switch]:checked{background:var(--tone,var(--sd-accent))}
|
|
76
|
+
input[role=switch]:checked::before{transform:translateX(14px)}
|
|
77
|
+
|
|
78
|
+
/* Card */
|
|
79
|
+
.card{padding:20px;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r);overflow:hidden;min-width:0}
|
|
80
|
+
.card>header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px;font:600 13px/1.4 var(--sd-font);color:var(--sd-ink)}
|
|
81
|
+
.card>footer{display:flex;justify-content:flex-end;gap:8px;margin:16px -20px -20px;padding:12px 20px;border-top:1px solid var(--sd-line)}
|
|
82
|
+
.card[data-variant=flat]{background:var(--sd-tint);border-color:transparent}
|
|
83
|
+
.card[data-variant=accent]{background:var(--tone,var(--sd-accent));border-color:transparent;color:var(--sd-on)}
|
|
84
|
+
.card[data-variant=accent] :is(p,small,.muted){color:color-mix(in srgb,var(--sd-on) 75%,transparent)}
|
|
85
|
+
a.card{display:block;color:inherit;text-decoration:none;transition:box-shadow .2s}a.card:hover{box-shadow:0 4px 12px #00000014}
|
|
86
|
+
|
|
87
|
+
/* Stat tile: <div class="card stat"><small>Label</small><strong>1,516 <small>tasks</small></strong></div> */
|
|
88
|
+
.stat{display:grid;align-content:start;gap:4px}
|
|
89
|
+
.stat>p{margin:0}
|
|
90
|
+
.stat>strong{font-size:28px;font-weight:600;line-height:1.15;letter-spacing:-.03em;color:var(--tone,var(--sd-ink));font-variant-numeric:tabular-nums}
|
|
91
|
+
.stat>strong>small{margin-left:2px;font-weight:400;letter-spacing:0}
|
|
92
|
+
|
|
93
|
+
/* Bars: <div class="bars" role="img" aria-label="…"><span style="--v:60" data-label="Mon"></span></div> */
|
|
94
|
+
.bars{display:flex;align-items:flex-end;gap:4px;width:100%;height:96px}
|
|
95
|
+
.bars:has(>[data-label]){margin-bottom:20px}
|
|
96
|
+
.bars>span{position:relative;flex:1;min-width:4px;height:calc(var(--v,0)*1%);min-height:2px;background:var(--sd-line);border-radius:var(--sd-r) var(--sd-r) 0 0}
|
|
97
|
+
.bars>span:hover{background:color-mix(in srgb,var(--sd-ink) 25%,var(--sd-line))}
|
|
98
|
+
.bars>[data-on]{background:var(--tone,var(--sd-accent))!important}
|
|
99
|
+
.bars>[data-label]::before{content:attr(data-label);position:absolute;top:calc(100% + 4px);left:50%;translate:-50%;font:400 10px/1.4 var(--sd-mono);color:var(--sd-muted);white-space:nowrap}
|
|
100
|
+
|
|
101
|
+
/* Heatmap: one <span data-level="0-4"> per day, filled top to bottom, 7 per column */
|
|
102
|
+
.heatmap{display:grid;grid-auto-flow:column;grid-template-rows:repeat(7,12px);grid-auto-columns:12px;gap:3px;width:max-content;max-width:100%}
|
|
103
|
+
.heatmap>span{background:var(--sd-tint);border-radius:var(--sd-r)}
|
|
104
|
+
.heatmap>[data-level="1"]{background:color-mix(in srgb,var(--tone,var(--sd-accent)) 22%,var(--sd-surface))}
|
|
105
|
+
.heatmap>[data-level="2"]{background:color-mix(in srgb,var(--tone,var(--sd-accent)) 45%,var(--sd-surface))}
|
|
106
|
+
.heatmap>[data-level="3"]{background:color-mix(in srgb,var(--tone,var(--sd-accent)) 70%,var(--sd-surface))}
|
|
107
|
+
.heatmap>[data-level="4"]{background:var(--tone,var(--sd-accent))}
|
|
108
|
+
|
|
109
|
+
/* Alert */
|
|
110
|
+
.alert{display:grid;gap:2px;padding:12px 16px;background:color-mix(in srgb,var(--tone,var(--sd-accent)) 8%,var(--sd-surface));border:1px solid color-mix(in srgb,var(--tone,var(--sd-accent)) 25%,transparent);border-left:3px solid var(--tone,var(--sd-accent));border-radius:var(--sd-r);font-size:13px;color:var(--sd-sub)}
|
|
111
|
+
.alert>strong{color:var(--tone,var(--sd-accent))}
|
|
112
|
+
|
|
113
|
+
/* Badge */
|
|
114
|
+
.badge{display:inline-flex;align-items:center;gap:4px;padding:2px 7px;border-radius:var(--sd-r);background:color-mix(in srgb,var(--tone,var(--sd-accent)) 12%,transparent);color:var(--tone,var(--sd-accent));font:500 11px/1.5 var(--sd-font);white-space:nowrap}
|
|
115
|
+
.badge[data-variant=solid]{background:var(--tone,var(--sd-accent));color:var(--sd-on)}
|
|
116
|
+
.badge[data-variant=outline]{background:none;border:1px solid var(--sd-line);color:var(--sd-muted)}
|
|
117
|
+
|
|
118
|
+
/* Avatar */
|
|
119
|
+
.avatar{--s:36px;display:inline-grid;place-items:center;flex:none;width:var(--s);height:var(--s);border-radius:50%;overflow:hidden;background:var(--tone,var(--sd-accent));color:var(--sd-on);font:600 calc(var(--s)*.36)/1 var(--sd-font);text-transform:uppercase}
|
|
120
|
+
.avatar img{width:100%;height:100%;object-fit:cover}
|
|
121
|
+
.avatar[data-size=sm]{--s:26px}.avatar[data-size=lg]{--s:52px}
|
|
122
|
+
.avatar-group{display:flex}.avatar-group>.avatar{margin-left:-8px;box-shadow:0 0 0 2px var(--sd-bg)}.avatar-group>.avatar:first-child{margin:0}
|
|
123
|
+
|
|
124
|
+
/* Breadcrumb */
|
|
125
|
+
.breadcrumb ol{display:flex;flex-wrap:wrap;gap:8px;margin:0;padding:0;list-style:none;font-size:13px;color:var(--sd-muted)}
|
|
126
|
+
.breadcrumb li+li::before{content:"/";margin-right:8px;color:var(--sd-line)}
|
|
127
|
+
.breadcrumb a{color:inherit;text-decoration:none}.breadcrumb a:hover{color:var(--sd-ink)}
|
|
128
|
+
.breadcrumb [aria-current]{color:var(--sd-ink);font-weight:500}
|
|
129
|
+
|
|
130
|
+
/* Accordion: native <details>, group with name="" for one-open-at-a-time */
|
|
131
|
+
details{border-bottom:1px solid var(--sd-line)}
|
|
132
|
+
summary{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 0;font-weight:500;cursor:pointer;list-style:none}
|
|
133
|
+
summary::-webkit-details-marker{display:none}
|
|
134
|
+
summary::after{content:"";width:7px;height:7px;margin-right:4px;border:solid var(--sd-muted);border-width:0 1.5px 1.5px 0;transform:rotate(45deg);transition:transform .2s var(--sd-ease)}
|
|
135
|
+
details[open]>summary::after{transform:rotate(-135deg)}
|
|
136
|
+
details>:not(summary){margin:0 0 14px;color:var(--sd-sub)}
|
|
137
|
+
|
|
138
|
+
/* Dialog: native <dialog> */
|
|
139
|
+
dialog{width:min(520px,calc(100% - 32px));padding:0;background:var(--sd-surface);color:var(--sd-ink);border:1px solid var(--sd-line);border-radius:var(--sd-r);box-shadow:0 24px 64px #00000038}
|
|
140
|
+
dialog::backdrop{background:#0006}
|
|
141
|
+
dialog[data-side=right]{height:100dvh;max-height:100dvh;margin:0 0 0 auto;overflow-y:auto;border-width:0 0 0 1px;border-radius:0}
|
|
142
|
+
dialog[data-side=right][open]{display:flex;flex-direction:column}dialog[data-side=right]>:last-child{flex:1 0 auto}
|
|
143
|
+
dialog[open]{animation:sd-pop .22s var(--sd-ease)}
|
|
144
|
+
dialog>*{margin:0;padding:20px 24px}
|
|
145
|
+
dialog>header{display:flex;align-items:center;justify-content:space-between;gap:12px;border-bottom:1px solid var(--sd-line)}
|
|
146
|
+
dialog>header :is(h2,h3){margin:0;font-size:17px}
|
|
147
|
+
dialog>footer{display:flex;justify-content:flex-end;gap:8px;padding:14px 24px;background:var(--sd-tint);border-top:1px solid var(--sd-line)}
|
|
148
|
+
|
|
149
|
+
/* Dropdown: <sd-dropdown> */
|
|
150
|
+
sd-dropdown{position:relative;display:inline-block}
|
|
151
|
+
sd-dropdown>menu{position:absolute;z-index:50;top:calc(100% + 4px);left:0;display:none;min-width:180px;margin:0;padding:4px;list-style:none;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r);box-shadow:0 8px 24px #0000001f}
|
|
152
|
+
sd-dropdown[open]>menu{display:block;animation:sd-pop .15s var(--sd-ease)}
|
|
153
|
+
sd-dropdown[align=end]>menu{left:auto;right:0}
|
|
154
|
+
sd-dropdown menu button{width:100%;height:32px;justify-content:flex-start;padding:0 10px;background:none;color:var(--sd-sub);font-weight:400;transform:none!important}
|
|
155
|
+
sd-dropdown menu button:is(:hover,:focus){background:var(--sd-tint);color:var(--sd-ink);opacity:1;outline:0}
|
|
156
|
+
sd-dropdown menu hr{margin:4px 0}
|
|
157
|
+
|
|
158
|
+
/* Tabs: <sd-tabs> */
|
|
159
|
+
sd-tabs{display:block}
|
|
160
|
+
sd-tabs:not(:defined)>section:not(:first-of-type){display:none}
|
|
161
|
+
sd-tabs>nav{display:inline-flex;max-width:100%;gap:2px;padding:3px;overflow-x:auto;background:var(--sd-tint);border-radius:var(--sd-r)}
|
|
162
|
+
sd-tabs>nav>button{--h:32px;background:none;color:var(--sd-muted);font-weight:400;transform:none!important}
|
|
163
|
+
sd-tabs>nav>button:hover{color:var(--sd-ink);opacity:1}
|
|
164
|
+
sd-tabs>nav>[aria-selected=true]{background:var(--sd-surface);color:var(--tone,var(--sd-ink));font-weight:600;box-shadow:0 1px 3px #0000001a}
|
|
165
|
+
[data-theme=dark] sd-tabs>nav>[aria-selected=true]{background:var(--sd-line)}
|
|
166
|
+
sd-tabs>section{padding-top:16px}
|
|
167
|
+
|
|
168
|
+
/* TagInput: <sd-tag-input> */
|
|
169
|
+
sd-tag-input{display:flex;flex-wrap:wrap;align-items:center;gap:6px;min-height:38px;padding:5px 8px;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r);cursor:text}
|
|
170
|
+
sd-tag-input:focus-within{border-color:var(--sd-accent);box-shadow:0 0 0 3px color-mix(in srgb,var(--sd-accent) 15%,transparent)}
|
|
171
|
+
sd-tag-input .badge button{all:unset;cursor:pointer;opacity:.6}sd-tag-input .badge button:hover{opacity:1}
|
|
172
|
+
sd-tag-input>input{flex:1;min-width:80px;height:26px!important;padding:0!important;border:0!important;box-shadow:none!important}
|
|
173
|
+
|
|
174
|
+
/* Upload: <sd-upload> */
|
|
175
|
+
sd-upload{display:grid;gap:8px}
|
|
176
|
+
sd-upload>label{position:relative;display:grid;place-items:center;gap:2px;padding:28px 16px;text-align:center;background:var(--sd-surface);border:1.5px dashed var(--sd-line);border-radius:var(--sd-r);cursor:pointer;transition:border-color .2s,background .2s}
|
|
177
|
+
sd-upload>label:hover,sd-upload[dragging]>label,sd-upload>label:focus-within{border-color:var(--sd-accent);background:color-mix(in srgb,var(--sd-accent) 5%,var(--sd-surface))}
|
|
178
|
+
sd-upload input{position:absolute;opacity:0;width:1px;height:1px}
|
|
179
|
+
sd-upload ul{display:grid;gap:4px;margin:0;padding:0;list-style:none;font-size:13px}
|
|
180
|
+
sd-upload li{display:flex;justify-content:space-between;padding:8px 12px;background:var(--sd-tint);border-radius:var(--sd-r)}
|
|
181
|
+
|
|
182
|
+
/* Progress & Meter: native elements */
|
|
183
|
+
progress,meter{display:block;width:100%;height:6px;border:0;border-radius:99px;background:var(--sd-tint);overflow:hidden;appearance:none}
|
|
184
|
+
progress::-webkit-progress-bar{background:var(--sd-tint)}
|
|
185
|
+
progress::-webkit-progress-value{background:var(--tone,var(--sd-accent));transition:width .3s}
|
|
186
|
+
progress::-moz-progress-bar{background:var(--tone,var(--sd-accent))}
|
|
187
|
+
progress:indeterminate{background:linear-gradient(90deg,transparent,var(--tone,var(--sd-accent)),transparent) no-repeat var(--sd-tint);background-size:40% 100%;animation:sd-slide 1.2s ease-in-out infinite}
|
|
188
|
+
progress:indeterminate::-webkit-progress-bar{background:none}
|
|
189
|
+
progress:indeterminate::-moz-progress-bar{background:none}
|
|
190
|
+
meter{height:8px}
|
|
191
|
+
meter::-webkit-meter-bar{height:8px;background:var(--sd-tint);border:0;border-radius:99px}
|
|
192
|
+
meter::-webkit-meter-optimum-value{background:var(--sd-good)}meter:-moz-meter-optimum::-moz-meter-bar{background:var(--sd-good)}
|
|
193
|
+
meter::-webkit-meter-suboptimum-value{background:var(--sd-warn)}meter:-moz-meter-sub-optimum::-moz-meter-bar{background:var(--sd-warn)}
|
|
194
|
+
meter::-webkit-meter-even-less-good-value{background:var(--sd-bad)}meter:-moz-meter-sub-sub-optimum::-moz-meter-bar{background:var(--sd-bad)}
|
|
195
|
+
|
|
196
|
+
/* Skeleton */
|
|
197
|
+
.skeleton{min-height:12px;border-radius:var(--sd-r);background:linear-gradient(90deg,var(--sd-tint) 30%,color-mix(in srgb,var(--sd-tint) 40%,var(--sd-surface)) 50%,var(--sd-tint) 70%) 0 0/200% 100%;animation:sd-shimmer 1.4s infinite}
|
|
198
|
+
|
|
199
|
+
/* Pagination */
|
|
200
|
+
.pagination{display:flex;flex-wrap:wrap;gap:4px}
|
|
201
|
+
.pagination a{display:inline-grid;place-items:center;min-width:32px;height:32px;padding:0 8px;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r);color:var(--sd-sub);font-size:13px;text-decoration:none}
|
|
202
|
+
.pagination a:hover{background:var(--sd-tint)}
|
|
203
|
+
.pagination [aria-current]{background:var(--sd-accent);border-color:var(--sd-accent);color:var(--sd-on)}
|
|
204
|
+
.pagination [aria-disabled=true]{opacity:.4;pointer-events:none}
|
|
205
|
+
|
|
206
|
+
/* Sidebar layout */
|
|
207
|
+
.layout{display:grid;grid-template-columns:248px minmax(0,1fr);min-height:100dvh}
|
|
208
|
+
.sidebar{position:sticky;top:0;height:100dvh;overflow-y:auto;padding:16px 12px;background:var(--sd-bg);border-right:1px solid var(--sd-line);scrollbar-width:thin}
|
|
209
|
+
.sidebar nav{display:grid;gap:1px;margin-bottom:16px}
|
|
210
|
+
.sidebar .eyebrow{padding:8px 10px 4px}
|
|
211
|
+
.sidebar a{display:flex;align-items:center;gap:10px;padding:6px 10px;border-radius:var(--sd-r);color:var(--sd-sub);font-size:13px;text-decoration:none}
|
|
212
|
+
.sidebar a:hover{background:color-mix(in srgb,var(--sd-ink) 6%,transparent);color:var(--sd-ink)}
|
|
213
|
+
.sidebar a[aria-current]{background:var(--sd-tint);color:var(--sd-ink);font-weight:600}
|
|
214
|
+
.sidebar a .badge{margin-left:auto}
|
|
215
|
+
@media (max-width:860px){.layout{grid-template-columns:1fr}.sidebar{position:fixed;z-index:60;inset:0 auto 0 0;width:264px;transform:translateX(-100%);transition:transform .25s var(--sd-ease)}.sidebar[data-open]{transform:none;box-shadow:0 0 0 100vmax #0006}}
|
|
216
|
+
|
|
217
|
+
/* Table */
|
|
218
|
+
.table-wrap{overflow-x:auto;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r)}
|
|
219
|
+
table{width:100%;border-collapse:collapse;font-size:13px}
|
|
220
|
+
th,td{padding:10px 14px;text-align:left;border-bottom:1px solid var(--sd-line)}
|
|
221
|
+
th{font:500 11px/1.4 var(--sd-font);color:var(--sd-muted)}
|
|
222
|
+
td{color:var(--sd-sub)}
|
|
223
|
+
tbody tr:last-child td{border-bottom:0}
|
|
224
|
+
tbody tr:hover{background:color-mix(in srgb,var(--sd-tint) 45%,transparent)}
|
|
225
|
+
.num{text-align:right;font-variant-numeric:tabular-nums}
|
|
226
|
+
sd-table{display:block}
|
|
227
|
+
sd-table th[aria-sort]{cursor:pointer;user-select:none;white-space:nowrap}
|
|
228
|
+
sd-table th[aria-sort]:hover{color:var(--sd-ink)}
|
|
229
|
+
sd-table th[aria-sort]::after{content:"\2195";margin-left:6px;opacity:.35}
|
|
230
|
+
sd-table th[aria-sort=ascending]::after{content:"\2191";opacity:1;color:var(--sd-accent)}
|
|
231
|
+
sd-table th[aria-sort=descending]::after{content:"\2193";opacity:1;color:var(--sd-accent)}
|
|
232
|
+
|
|
233
|
+
/* Calendar: <sd-calendar> */
|
|
234
|
+
sd-calendar{display:block;width:288px;max-width:100%;padding:12px;background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r)}
|
|
235
|
+
sd-calendar>header{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}
|
|
236
|
+
sd-calendar>header strong{font-size:13px}
|
|
237
|
+
sd-calendar>header button{--h:28px;width:28px;padding:0;background:none;color:var(--sd-muted)}
|
|
238
|
+
sd-calendar>header button:hover{background:var(--sd-tint);color:var(--sd-ink);opacity:1}
|
|
239
|
+
sd-calendar>div{display:grid;grid-template-columns:repeat(7,1fr);gap:2px;text-align:center}
|
|
240
|
+
sd-calendar>div>span{padding:4px 0;font:500 10px/1.4 var(--sd-mono);letter-spacing:.06em;text-transform:uppercase;color:var(--sd-muted)}
|
|
241
|
+
sd-calendar>div>button{--h:34px;padding:0;background:none;color:var(--sd-sub);font-weight:400;transform:none!important}
|
|
242
|
+
sd-calendar>div>button:hover{background:var(--sd-tint);color:var(--sd-ink);opacity:1}
|
|
243
|
+
sd-calendar>div>button[data-out]{color:var(--sd-muted);opacity:.5}
|
|
244
|
+
sd-calendar>div>button[data-today]{box-shadow:inset 0 0 0 1px var(--sd-accent)}
|
|
245
|
+
sd-calendar>div>button[aria-selected=true]{background:var(--sd-accent);color:var(--sd-on);font-weight:500;opacity:1}
|
|
246
|
+
|
|
247
|
+
/* Tooltip: data-tooltip="text" */
|
|
248
|
+
[data-tooltip]{position:relative}
|
|
249
|
+
[data-tooltip]::after{content:attr(data-tooltip);position:absolute;z-index:70;bottom:calc(100% + 6px);left:50%;translate:-50% 4px;padding:5px 8px;background:var(--sd-ink);color:var(--sd-bg);border-radius:var(--sd-r);font:500 12px/1.3 var(--sd-font);letter-spacing:0;white-space:nowrap;opacity:0;pointer-events:none;transition:opacity .15s,translate .15s}
|
|
250
|
+
[data-tooltip]:is(:hover,:focus-visible)::after{opacity:1;translate:-50% 0}
|
|
251
|
+
[data-tooltip-pos=bottom]::after{bottom:auto;top:calc(100% + 6px)}
|
|
252
|
+
|
|
253
|
+
/* Toast: Sidedish.toast() */
|
|
254
|
+
.toasts{position:fixed;z-index:100;right:16px;bottom:16px;display:grid;gap:8px;width:min(360px,calc(100% - 32px))}
|
|
255
|
+
.toast{display:grid;gap:2px;padding:12px 16px;background:var(--sd-surface);border:1px solid var(--sd-line);border-left:3px solid var(--tone,var(--sd-accent));border-radius:var(--sd-r);box-shadow:0 8px 24px #0000001f;font-size:13px;color:var(--sd-sub);cursor:pointer;animation:sd-pop .25s var(--sd-ease);transition:opacity .2s,transform .2s}
|
|
256
|
+
.toast strong{color:var(--sd-ink)}
|
|
257
|
+
.toast[data-leaving]{opacity:0;transform:translateY(8px)}
|
|
258
|
+
|
|
259
|
+
/* Helpers (everything else: use Tailwind utilities) */
|
|
260
|
+
.tone{color:var(--tone,var(--sd-accent))}.surface{background:var(--sd-surface);border:1px solid var(--sd-line);border-radius:var(--sd-r)}
|
|
261
|
+
}
|
|
262
|
+
@keyframes sd-spin{to{transform:rotate(360deg)}}
|
|
263
|
+
@keyframes sd-pop{from{opacity:0;transform:translateY(6px) scale(.98)}}
|
|
264
|
+
@keyframes sd-slide{from{background-position:-40% 0}to{background-position:140% 0}}
|
|
265
|
+
@keyframes sd-shimmer{to{background-position:-200% 0}}
|
|
266
|
+
@media (prefers-reduced-motion:reduce){*,::before,::after{animation-duration:.01ms!important;transition-duration:.01ms!important}}
|
package/sidedish.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/* Sidedish v0.1 · tiny behaviours + web components · MIT */
|
|
2
|
+
(() => {
|
|
3
|
+
if (typeof document == 'undefined') return; // server render (Next.js SSR): nothing to do
|
|
4
|
+
const d = document, uid = () => 'sd' + Math.random().toString(36).slice(2, 8);
|
|
5
|
+
const on = (t, e, f) => t.addEventListener(e, f);
|
|
6
|
+
const el = (tag, props) => Object.assign(d.createElement(tag), props);
|
|
7
|
+
const emit = (t, n, detail) => t.dispatchEvent(new CustomEvent(n, { detail, bubbles: true }));
|
|
8
|
+
const once = t => t._sd ? 0 : (t._sd = 1);
|
|
9
|
+
|
|
10
|
+
// data-open="dialogId", data-close (inside a dialog), data-toggle="#selector" (toggles data-open). Backdrop click closes a dialog.
|
|
11
|
+
on(d, 'click', e => {
|
|
12
|
+
const t = e.target.closest('[data-open],[data-close],[data-toggle]');
|
|
13
|
+
if (t?.dataset.open) d.getElementById(t.dataset.open)?.showModal();
|
|
14
|
+
if (t?.hasAttribute('data-close')) t.closest('dialog')?.close();
|
|
15
|
+
if (t?.dataset.toggle) d.querySelector(t.dataset.toggle)?.toggleAttribute('data-open');
|
|
16
|
+
if (e.target.tagName == 'DIALOG') e.target.close();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
let box;
|
|
20
|
+
const toast = (msg, o = {}) => {
|
|
21
|
+
if (!box) { box = d.body.appendChild(el('div', { className: 'toasts' })); box.setAttribute('aria-live', 'polite'); }
|
|
22
|
+
const t = el('div', { className: 'toast', onclick: () => t.remove() });
|
|
23
|
+
if (o.tone) t.dataset.tone = o.tone;
|
|
24
|
+
if (o.title) t.append(el('strong', { textContent: o.title }));
|
|
25
|
+
t.append(el('span', { textContent: msg }));
|
|
26
|
+
box.append(t);
|
|
27
|
+
setTimeout(() => { t.dataset.leaving = ''; setTimeout(() => t.remove(), 200); }, o.duration ?? 3500);
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Sidedish.theme({ accent: '#7c3aed', bg: '#fff' }) sets --sd-* tokens on the root (or on `scope`).
|
|
32
|
+
const theme = (vars, scope = d.documentElement) => Object.entries(vars).forEach(([k, v]) => scope.style.setProperty('--sd-' + k, v));
|
|
33
|
+
|
|
34
|
+
class Tabs extends HTMLElement {
|
|
35
|
+
connectedCallback() {
|
|
36
|
+
if (!once(this)) return;
|
|
37
|
+
const nav = this.querySelector(':scope>nav'), tabs = [...nav.children], panels = [...this.querySelectorAll(':scope>section')];
|
|
38
|
+
nav.setAttribute('role', 'tablist');
|
|
39
|
+
const sel = (i, fire) => {
|
|
40
|
+
tabs.forEach((t, j) => { t.setAttribute('aria-selected', i == j); t.tabIndex = i == j ? 0 : -1; if (panels[j]) panels[j].hidden = i != j; });
|
|
41
|
+
this.index = i;
|
|
42
|
+
if (fire) emit(this, 'change', { index: i });
|
|
43
|
+
};
|
|
44
|
+
tabs.forEach((t, i) => {
|
|
45
|
+
const p = panels[i], id = uid();
|
|
46
|
+
t.type = 'button'; t.id = id; t.setAttribute('role', 'tab');
|
|
47
|
+
if (p) { p.id ||= uid(); p.setAttribute('role', 'tabpanel'); p.setAttribute('aria-labelledby', id); t.setAttribute('aria-controls', p.id); }
|
|
48
|
+
on(t, 'click', () => sel(i, 1));
|
|
49
|
+
});
|
|
50
|
+
on(nav, 'keydown', e => {
|
|
51
|
+
const k = { ArrowRight: 1, ArrowLeft: -1 }[e.key];
|
|
52
|
+
if (k) { const n = (this.index + k + tabs.length) % tabs.length; sel(n, 1); tabs[n].focus(); }
|
|
53
|
+
});
|
|
54
|
+
this.select = i => sel(i, 1);
|
|
55
|
+
sel(+this.getAttribute('selected') || 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class Dropdown extends HTMLElement {
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
if (!once(this)) return;
|
|
62
|
+
const btn = this.querySelector(':scope>button'), menu = this.querySelector(':scope>menu');
|
|
63
|
+
const items = () => [...menu.querySelectorAll('button:not(:disabled)')];
|
|
64
|
+
menu.setAttribute('role', 'menu');
|
|
65
|
+
items().forEach(i => { i.setAttribute('role', 'menuitem'); i.type = 'button'; });
|
|
66
|
+
btn.setAttribute('aria-haspopup', 'menu');
|
|
67
|
+
const set = o => { this.toggleAttribute('open', o); btn.setAttribute('aria-expanded', o); if (o) items()[0]?.focus(); };
|
|
68
|
+
set(false);
|
|
69
|
+
on(btn, 'click', () => set(!this.hasAttribute('open')));
|
|
70
|
+
on(menu, 'click', e => {
|
|
71
|
+
const i = e.target.closest('button');
|
|
72
|
+
if (i) { emit(this, 'select', { value: i.value || i.textContent.trim() }); set(false); btn.focus(); }
|
|
73
|
+
});
|
|
74
|
+
on(this, 'keydown', e => {
|
|
75
|
+
if (e.key == 'Escape') { set(false); btn.focus(); }
|
|
76
|
+
const k = { ArrowDown: 1, ArrowUp: -1 }[e.key];
|
|
77
|
+
if (k && this.hasAttribute('open')) { e.preventDefault(); const l = items(); l[(l.indexOf(d.activeElement) + k + l.length) % l.length].focus(); }
|
|
78
|
+
});
|
|
79
|
+
// ponytail: document listener is never removed; fine unless dropdowns are created and destroyed thousands of times.
|
|
80
|
+
on(d, 'click', e => this.hasAttribute('open') && !this.contains(e.target) && set(false));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
class TagInput extends HTMLElement {
|
|
85
|
+
static formAssociated = true;
|
|
86
|
+
constructor() { super(); this.tags = []; this._in = this.attachInternals?.(); }
|
|
87
|
+
get value() { return this.tags.join(','); }
|
|
88
|
+
set value(v) { this.tags = [...new Set(String(v ?? '').split(',').map(s => s.trim()).filter(Boolean))]; this.render(); }
|
|
89
|
+
connectedCallback() {
|
|
90
|
+
if (!once(this)) return;
|
|
91
|
+
this.input = el('input', { placeholder: this.getAttribute('placeholder') || 'Add tag…' });
|
|
92
|
+
this.input.setAttribute('aria-label', this.getAttribute('aria-label') || 'Add tag');
|
|
93
|
+
on(this.input, 'keydown', e => {
|
|
94
|
+
const v = this.input.value.trim().replace(/,$/, '');
|
|
95
|
+
if ((e.key == 'Enter' || e.key == ',') && v) { e.preventDefault(); this.input.value = ''; this.add(v); }
|
|
96
|
+
else if (e.key == 'Backspace' && !this.input.value && this.tags.length) this.remove(this.tags.length - 1);
|
|
97
|
+
});
|
|
98
|
+
on(this, 'click', e => { const x = e.target.closest('[data-i]'); x ? this.remove(+x.dataset.i) : this.input.focus(); });
|
|
99
|
+
this.value = this.getAttribute('value') ?? this.value;
|
|
100
|
+
}
|
|
101
|
+
add(v) { if (this.tags.includes(v)) return; this.tags.push(v); this.render(1); }
|
|
102
|
+
remove(i) { this.tags.splice(i, 1); this.render(1); }
|
|
103
|
+
render(changed) {
|
|
104
|
+
if (!this.input) return;
|
|
105
|
+
this.replaceChildren(...this.tags.map((t, i) => {
|
|
106
|
+
const b = el('button', { type: 'button', textContent: '×' }), s = el('span', { className: 'badge', textContent: t });
|
|
107
|
+
b.dataset.i = i; b.setAttribute('aria-label', 'Remove ' + t); s.append(b); return s;
|
|
108
|
+
}), this.input);
|
|
109
|
+
this._in?.setFormValue(this.value);
|
|
110
|
+
if (changed) { this.input.focus(); emit(this, 'change', { tags: [...this.tags] }); }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const size = b => b < 1024 ? b + ' B' : b < 1048576 ? (b / 1024).toFixed(1) + ' KB' : (b / 1048576).toFixed(1) + ' MB';
|
|
115
|
+
class Upload extends HTMLElement {
|
|
116
|
+
connectedCallback() {
|
|
117
|
+
if (!once(this)) return;
|
|
118
|
+
const inp = el('input', { type: 'file' }), zone = el('label'), list = el('ul');
|
|
119
|
+
['name', 'accept', 'multiple', 'required'].forEach(a => this.hasAttribute(a) && inp.setAttribute(a, this.getAttribute(a)));
|
|
120
|
+
zone.append(el('strong', { textContent: this.getAttribute('label') || 'Drop files here or click to browse' }), el('small', { textContent: this.getAttribute('hint') || '' }), inp);
|
|
121
|
+
const show = () => {
|
|
122
|
+
list.replaceChildren(...[...inp.files].map(f => { const li = el('li', { textContent: f.name }); li.append(el('small', { textContent: size(f.size) })); return li; }));
|
|
123
|
+
emit(this, 'files', { files: inp.files });
|
|
124
|
+
};
|
|
125
|
+
on(inp, 'change', show);
|
|
126
|
+
['dragenter', 'dragover'].forEach(n => on(zone, n, e => { e.preventDefault(); this.setAttribute('dragging', ''); }));
|
|
127
|
+
['dragleave', 'drop'].forEach(n => on(zone, n, e => { e.preventDefault(); this.removeAttribute('dragging'); }));
|
|
128
|
+
on(zone, 'drop', e => {
|
|
129
|
+
let f = e.dataTransfer.files;
|
|
130
|
+
if (!inp.multiple && f.length > 1) { const dt = new DataTransfer(); dt.items.add(f[0]); f = dt.files; }
|
|
131
|
+
inp.files = f; show();
|
|
132
|
+
});
|
|
133
|
+
this.append(zone, list);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// <sd-table><table>…</table></sd-table>: click a header to sort. Numbers sort numerically, everything else as text.
|
|
138
|
+
class SortTable extends HTMLElement {
|
|
139
|
+
connectedCallback() {
|
|
140
|
+
if (!once(this)) return;
|
|
141
|
+
const ths = [...this.querySelectorAll('thead th')], body = this.querySelector('tbody');
|
|
142
|
+
const val = (r, i) => r.cells[i]?.dataset.sort ?? r.cells[i]?.textContent.trim() ?? '';
|
|
143
|
+
const num = v => parseFloat(v.replace(/[^\d.\-\u2212]/g, '').replace('\u2212', '-'));
|
|
144
|
+
ths.forEach((th, i) => {
|
|
145
|
+
th.setAttribute('aria-sort', 'none'); th.tabIndex = 0;
|
|
146
|
+
const go = () => {
|
|
147
|
+
const dir = th.getAttribute('aria-sort') == 'ascending' ? -1 : 1;
|
|
148
|
+
ths.forEach(t => t.setAttribute('aria-sort', 'none'));
|
|
149
|
+
th.setAttribute('aria-sort', dir > 0 ? 'ascending' : 'descending');
|
|
150
|
+
const rows = [...body.rows], isNum = rows.every(r => !isNaN(num(val(r, i))));
|
|
151
|
+
rows.sort((a, b) => dir * (isNum ? num(val(a, i)) - num(val(b, i)) : val(a, i).localeCompare(val(b, i), undefined, { numeric: true })));
|
|
152
|
+
body.append(...rows);
|
|
153
|
+
emit(this, 'sort', { column: i, direction: dir > 0 ? 'ascending' : 'descending' });
|
|
154
|
+
};
|
|
155
|
+
on(th, 'click', go);
|
|
156
|
+
on(th, 'keydown', e => (e.key == 'Enter' || e.key == ' ') && (e.preventDefault(), go()));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// <sd-calendar value="2026-11-18" min="" max="">: month grid, Arrow keys move by day/week. Fires `change` with { value: 'YYYY-MM-DD' }.
|
|
162
|
+
const iso = x => `${x.getFullYear()}-${String(x.getMonth() + 1).padStart(2, '0')}-${String(x.getDate()).padStart(2, '0')}`;
|
|
163
|
+
const parse = v => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(v || ''); return m ? new Date(+m[1], m[2] - 1, +m[3]) : null; };
|
|
164
|
+
class Calendar extends HTMLElement {
|
|
165
|
+
static formAssociated = true;
|
|
166
|
+
constructor() { super(); this._in = this.attachInternals?.(); }
|
|
167
|
+
get value() { return this.getAttribute('value') || ''; }
|
|
168
|
+
set value(v) { v ? this.setAttribute('value', v) : this.removeAttribute('value'); this.view = parse(v) || this.view; this.render(); }
|
|
169
|
+
connectedCallback() {
|
|
170
|
+
if (!once(this)) return;
|
|
171
|
+
this.view = parse(this.value) || new Date();
|
|
172
|
+
this.view.setDate(1);
|
|
173
|
+
on(this, 'click', e => {
|
|
174
|
+
const b = e.target.closest('button');
|
|
175
|
+
if (!b) return;
|
|
176
|
+
if (b.dataset.nav) { this.view = new Date(this.view.getFullYear(), this.view.getMonth() + +b.dataset.nav, 1); this.render(); this.querySelector('[tabindex="0"]')?.focus(); }
|
|
177
|
+
else if (b.dataset.date) this.pick(b.dataset.date);
|
|
178
|
+
});
|
|
179
|
+
on(this, 'keydown', e => {
|
|
180
|
+
const k = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key], cur = parse(d.activeElement?.dataset?.date);
|
|
181
|
+
if (!k || !cur) return;
|
|
182
|
+
e.preventDefault(); cur.setDate(cur.getDate() + k);
|
|
183
|
+
this.view = new Date(cur.getFullYear(), cur.getMonth(), 1); this.render(); this.querySelector(`[data-date="${iso(cur)}"]`)?.focus();
|
|
184
|
+
});
|
|
185
|
+
this.render();
|
|
186
|
+
}
|
|
187
|
+
pick(v) { this.value = v; this._in?.setFormValue(v); emit(this, 'change', { value: v }); this.querySelector(`[data-date="${v}"]`)?.focus(); }
|
|
188
|
+
render() {
|
|
189
|
+
if (!this.view) return;
|
|
190
|
+
const y = this.view.getFullYear(), m = this.view.getMonth(), sel = this.value, today = iso(new Date());
|
|
191
|
+
const min = this.getAttribute('min'), max = this.getAttribute('max');
|
|
192
|
+
const start = new Date(y, m, 1 - ((new Date(y, m, 1).getDay() + 6) % 7)); // weeks start on Monday
|
|
193
|
+
const focus = sel && parse(sel).getMonth() == m && parse(sel).getFullYear() == y ? sel : iso(new Date(y, m, 1));
|
|
194
|
+
const cells = Array.from({ length: 42 }, (_, i) => {
|
|
195
|
+
const x = new Date(start.getFullYear(), start.getMonth(), start.getDate() + i), v = iso(x);
|
|
196
|
+
const b = el('button', { type: 'button', textContent: x.getDate(), tabIndex: v == focus ? 0 : -1, disabled: (min && v < min) || (max && v > max) });
|
|
197
|
+
b.dataset.date = v; b.setAttribute('aria-selected', v == sel);
|
|
198
|
+
b.setAttribute('aria-label', x.toLocaleDateString(undefined, { dateStyle: 'full' }));
|
|
199
|
+
if (x.getMonth() != m) b.dataset.out = ''; if (v == today) b.dataset.today = '';
|
|
200
|
+
return b;
|
|
201
|
+
});
|
|
202
|
+
const nav = n => { const b = el('button', { type: 'button', textContent: n < 0 ? '‹' : '›' }); b.dataset.nav = n; b.setAttribute('aria-label', n < 0 ? 'Previous month' : 'Next month'); return b; };
|
|
203
|
+
const head = el('header'), title = el('strong', { textContent: this.view.toLocaleDateString(undefined, { month: 'long', year: 'numeric' }) });
|
|
204
|
+
title.setAttribute('aria-live', 'polite'); head.append(nav(-1), title, nav(1));
|
|
205
|
+
const days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'].map(t => el('span', { textContent: t }));
|
|
206
|
+
const grid = el('div'); grid.append(...days, ...cells);
|
|
207
|
+
this.replaceChildren(head, grid);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const def = (n, c) => customElements.get(n) || customElements.define(n, c);
|
|
212
|
+
def('sd-tabs', Tabs); def('sd-dropdown', Dropdown); def('sd-tag-input', TagInput); def('sd-upload', Upload); def('sd-table', SortTable); def('sd-calendar', Calendar);
|
|
213
|
+
window.Sidedish = { toast, theme };
|
|
214
|
+
})();
|