@ksojecki/purpose-ui 0.4.0 → 0.5.0-next.20261201221427

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  React components and daisyUI themes with semantic `purpose` props: buttons, forms, tables, feedback, navigation, overlays and page layout.
4
4
 
5
- Documentation, with live examples and props for every component: [sojecki.pl/ui](https://sojecki.pl/ui/).
5
+ Documentation with live examples and props for each component: [sojecki.pl/ui](https://sojecki.pl/ui/).
6
6
 
7
7
  ## Install
8
8
 
@@ -73,6 +73,20 @@ Choose a `purpose` (`ActionPurpose`, `StatusPurpose`, `BadgePurpose`), not a col
73
73
 
74
74
  Motion utilities (`animate-fade-in`, `animate-slide-up`, `animate-scale-in`) come from `theme.css` and switch off under `prefers-reduced-motion`.
75
75
 
76
+ ## Agent skills
77
+
78
+ The package ships agent skills for Claude Code, Codex and Devin: `purpose-ui` (components, `purpose` values, layout) and `purpose-ui-theming` (styles, palettes, dark mode, custom themes). Copy the installed version's skills into your repository and check them in CI:
79
+
80
+ ```sh
81
+ npx purpose-ui-skills sync # writes .agents/skills/purpose-ui*
82
+ npx purpose-ui-skills sync --target .claude/skills # or wherever your agent reads skills
83
+ npx purpose-ui-skills sync --check # fails when the copies are stale
84
+ ```
85
+
86
+ `sync` replaces only the skills it copied earlier and records them in `.purpose-ui-skills.json`; other skills in the directory stay, and it stops rather than replace a same-named skill it did not copy. Run it again after each upgrade.
87
+
88
+ The repository is also a plugin with the latest stable skills: in Claude Code, `/plugin install purpose-ui --marketplace ksojecki/purpose-ui`; in Devin, add `https://github.com/ksojecki/purpose-ui` as a plugin. Prefer the synced copy in a repository, since it matches the installed version.
89
+
76
90
  ## Links
77
91
 
78
92
  - [Documentation](https://sojecki.pl/ui/)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ import { cpSync as e, existsSync as t, lstatSync as n, mkdirSync as r, readFileSync as i, readdirSync as a, rmSync as o, statSync as s, writeFileSync as c } from "node:fs";
3
+ import { dirname as l, join as u, relative as d, resolve as f } from "node:path";
4
+ import { fileURLToPath as p } from "node:url";
5
+ import { parseArgs as m } from "node:util";
6
+ // src/internal/agent-skills/sync.ts
7
+ var h = ".purpose-ui-skills.json";
8
+ function g(e) {
9
+ let n = a(e, { withFileTypes: !0 }).filter((n) => n.isDirectory() && t(u(e, n.name, "SKILL.md"))).map((e) => e.name);
10
+ return n.sort(), n;
11
+ }
12
+ function _(e) {
13
+ return n(e, { throwIfNoEntry: !1 }) !== void 0;
14
+ }
15
+ var v = /^[a-z0-9][a-z0-9-]*$/;
16
+ function y(e) {
17
+ return typeof e == "string" && v.test(e);
18
+ }
19
+ function b(e) {
20
+ let n = u(e, h);
21
+ if (t(n)) try {
22
+ let e = JSON.parse(i(n, "utf8")), t = Array.isArray(e.skills) ? e.skills : [];
23
+ return {
24
+ version: String(e.version ?? ""),
25
+ skills: t.filter(y)
26
+ };
27
+ } catch {
28
+ return;
29
+ }
30
+ }
31
+ function x(e) {
32
+ let t = a(e, { recursive: !0 }).filter((t) => s(u(e, t)).isFile());
33
+ return t.sort(), t;
34
+ }
35
+ function S(e, n) {
36
+ if (!t(n)) return !1;
37
+ let r = x(e), a = x(n);
38
+ return r.length === a.length && r.every((t, r) => t === a[r] && i(u(e, t)).equals(i(u(n, t))));
39
+ }
40
+ function C(e, t) {
41
+ return e?.version === t ? [] : [`synced from ${e?.version || "nothing"}, installed ${t}`];
42
+ }
43
+ function w(e, t, n) {
44
+ let r = b(t), i = g(e), a = i.filter((n) => !S(u(e, n), u(t, n))).map((e) => `${e} differs`), o = (r?.skills ?? []).filter((e) => !i.includes(e) && _(u(t, e))).map((e) => `${e} is no longer shipped`);
45
+ return [
46
+ ...C(r, n),
47
+ ...a,
48
+ ...o
49
+ ];
50
+ }
51
+ function T(t, n, r, i) {
52
+ for (let e of [...i, ...r]) o(u(n, e), {
53
+ recursive: !0,
54
+ force: !0
55
+ });
56
+ for (let i of r) e(u(t, i), u(n, i), { recursive: !0 });
57
+ }
58
+ function E(e, t, n) {
59
+ let r = g(e), i = b(t)?.skills ?? [], a = r.filter((e) => !i.includes(e) && _(u(t, e)));
60
+ if (a.length > 0) return {
61
+ copied: [],
62
+ removed: [],
63
+ conflicts: a
64
+ };
65
+ let o = i.filter((e) => !r.includes(e) && _(u(t, e)));
66
+ T(e, t, r, o);
67
+ let s = {
68
+ version: n,
69
+ skills: r
70
+ };
71
+ return c(u(t, h), `${JSON.stringify(s, void 0, 2)}\n`), {
72
+ copied: r,
73
+ removed: o,
74
+ conflicts: a
75
+ };
76
+ }
77
+ // src/internal/agent-skills/cli.ts
78
+ var D = {
79
+ ok: 0,
80
+ stale: 1,
81
+ invalid: 2
82
+ }, O = "Usage:\n purpose-ui-skills sync [--target <dir>] Copy the installed version's agent skills (default .agents/skills)\n purpose-ui-skills sync --check [--target <dir>] Fail when the copies differ from the installed version";
83
+ function k(e) {
84
+ try {
85
+ return m({
86
+ args: e,
87
+ allowPositionals: !0,
88
+ options: {
89
+ target: {
90
+ type: "string",
91
+ short: "t",
92
+ default: ".agents/skills"
93
+ },
94
+ check: {
95
+ type: "boolean",
96
+ default: !1
97
+ },
98
+ help: {
99
+ type: "boolean",
100
+ short: "h",
101
+ default: !1
102
+ }
103
+ }
104
+ });
105
+ } catch (e) {
106
+ return e;
107
+ }
108
+ }
109
+ function A(e, t, n, r) {
110
+ let i = `purpose-ui-skills sync --target ${d(r.cwd, t) || "."}`, a = w(e, t, n);
111
+ for (let e of a) r.stderr(e);
112
+ return a.length > 0 ? (r.stderr(`Skills in ${t} are stale. Run ${i}.`), D.stale) : (r.stdout(`Skills in ${t} match @ksojecki/purpose-ui ${n}.`), D.ok);
113
+ }
114
+ function j(e, t, n, i) {
115
+ r(t, { recursive: !0 });
116
+ let { copied: a, removed: o, conflicts: s } = E(e, t, n);
117
+ if (s.length > 0) return i.stderr(`${s.join(", ")} in ${t} not made by purpose-ui-skills. Remove or rename it, then sync again.`), D.invalid;
118
+ for (let e of o) i.stdout(`removed ${e}`);
119
+ return i.stdout(`Synced ${a.join(", ")} from @ksojecki/purpose-ui ${n} to ${t}.`), D.ok;
120
+ }
121
+ function M(e, t) {
122
+ let n = k(e);
123
+ if (n instanceof Error) t.stderr(n.message);
124
+ else if (n.values.help) return { help: !0 };
125
+ else if (n.positionals.length === 1 && n.positionals[0] === "sync") return {
126
+ help: !1,
127
+ target: n.values.target,
128
+ check: n.values.check
129
+ };
130
+ t.stderr(O);
131
+ }
132
+ function N(e, t, n) {
133
+ let r = M(e, n);
134
+ if (!r) return D.invalid;
135
+ if (r.help) return n.stdout(O), D.ok;
136
+ let i = u(t.root, "skills"), a = f(n.cwd, r.target);
137
+ return r.check ? A(i, a, t.version, n) : j(i, a, t.version, n);
138
+ }
139
+ // src/agent-skills/cli.ts
140
+ var P = f(l(p(import.meta.url)), "../.."), { version: F } = JSON.parse(i(f(P, "package.json"), "utf8"));
141
+ process.exitCode = N(process.argv.slice(2), {
142
+ root: P,
143
+ version: F
144
+ }, {
145
+ cwd: process.cwd(),
146
+ stdout: (e) => process.stdout.write(`${e}\n`),
147
+ stderr: (e) => process.stderr.write(`${e}\n`)
148
+ });
@@ -0,0 +1,15 @@
1
+ export declare const EXIT: {
2
+ readonly ok: 0;
3
+ readonly stale: 1;
4
+ readonly invalid: 2;
5
+ };
6
+ export interface SkillsCliIo {
7
+ cwd: string;
8
+ stdout: (line: string) => void;
9
+ stderr: (line: string) => void;
10
+ }
11
+ export interface InstalledPackage {
12
+ root: string;
13
+ version: string;
14
+ }
15
+ export declare function runSkillsCli(args: string[], installed: InstalledPackage, io: SkillsCliIo): 0 | 1 | 2;
@@ -0,0 +1,20 @@
1
+ export declare const MANIFEST_FILE = ".purpose-ui-skills.json";
2
+ interface Manifest {
3
+ version: string;
4
+ skills: string[];
5
+ }
6
+ /** Names of the skill directories (each with a `SKILL.md`) in `source`. */
7
+ export declare function listSkills(source: string): string[];
8
+ export declare function readManifest(target: string): Manifest | undefined;
9
+ /** Problems that make `target` differ from the skills in `source` at `version`; empty when current. */
10
+ export declare function staleSkills(source: string, target: string, version: string): string[];
11
+ /**
12
+ * Replaces the copies an earlier sync made with the skills in `source`; other directories stay.
13
+ * Changes nothing and returns `conflicts` when a shipped skill's directory exists but no earlier sync made it.
14
+ */
15
+ export declare function syncSkills(source: string, target: string, version: string): {
16
+ copied: string[];
17
+ removed: string[];
18
+ conflicts: string[];
19
+ };
20
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ksojecki/purpose-ui",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-next.20261201221427",
4
4
  "description": "React UI components and daisyUI themes with semantic purpose props.",
5
5
  "keywords": [
6
6
  "components",
@@ -20,6 +20,7 @@
20
20
  "url": "git+https://github.com/ksojecki/purpose-ui.git"
21
21
  },
22
22
  "bin": {
23
+ "purpose-ui-skills": "dist/agent-skills/cli.js",
23
24
  "purpose-ui-theme": "dist/theme-generator/cli.js"
24
25
  },
25
26
  "files": [
@@ -29,6 +30,7 @@
29
30
  "themes",
30
31
  "styles",
31
32
  "theme-config.schema.json",
33
+ "skills",
32
34
  "LICENSE",
33
35
  "!**/*.tsbuildinfo"
34
36
  ],
@@ -0,0 +1,106 @@
1
+ ---
2
+ name: purpose-ui
3
+ description: Build React UI with @ksojecki/purpose-ui components, semantic purpose props and plain page layout instead of hand-written daisyUI classes or raw elements. Use when writing or reviewing JSX in a project that depends on @ksojecki/purpose-ui.
4
+ ---
5
+
6
+ # purpose-ui
7
+
8
+ Use `@ksojecki/purpose-ui` for every pattern it covers. Docs with live examples and props: [sojecki.pl/ui](https://sojecki.pl/ui/). For styles, palettes and dark mode, use `purpose-ui-theming`.
9
+
10
+ ## Rules
11
+
12
+ - Import from a group subpath (`@ksojecki/purpose-ui/actions`), never from the package root.
13
+ - Do not hand-write daisyUI component classes (`btn`, `alert`, `badge`, `table`, `input`, `select`, `card`, `modal`, ...) or raw `<button>`, `<input>`, `<select>`, `<textarea>`, `<table>`, `<dialog>` and `<h1>`-`<h4>` when a component below covers them.
14
+ - Pick a semantic `purpose`, never a colour. `tone` and `variant` are escape hatches; use one only when no purpose fits and say why in the review.
15
+ - Lay out with Tailwind utilities in your JSX (flex, grid, gap, responsive variants). Do not add local classes or components that repeat a pattern the library has.
16
+ - Do not size icons inside `Button` or `IconButton`; the button sizes them.
17
+ - `Link`, `NavMenu`, `Menu` and the consent components render `react-router` links, so mount them inside a router.
18
+
19
+ ## Purpose values
20
+
21
+ - `ActionPurpose` (`Button`, `Link`, icon actions): `save`, `cancel`, `delete`, `create`, `edit`, `confirm`, `neutral`
22
+ - `StatusPurpose` (`Alert`): `info`, `success`, `warning`, `error`
23
+ - `BadgePurpose` (`Badge`) and `ProgressPurpose` (`Progress`): `StatusPurpose` plus `neutral`
24
+ - `RangePurpose` (`Range`): `primary` plus `StatusPurpose`
25
+
26
+ ## Layout: plain first
27
+
28
+ Lay out pages with plain sections, spacing and dividers: `PageHeader appearance="plain"`, `Section appearance="plain"`, `Divider`. Frame a block (`Card`, a default `Section`, `Metric appearance="boxed"`) only when the box carries meaning: a repeated item in a collection, a dialog, or a group that must stand apart from its surroundings.
29
+
30
+ ## Components
31
+
32
+ Each line starts with the components it describes.
33
+
34
+ ### actions
35
+
36
+ - `Button`: a labelled action; set `purpose` and `type`.
37
+ - `ButtonGroup`: buttons that belong together.
38
+ - `IconButton`: an icon-only action; always pass an accessible `label`.
39
+ - `EditButton`, `DeleteButton`, `NewButton`: icon actions with a fixed purpose and icon.
40
+ - `ButtonSizeProvider`: sets the size of every button inside it.
41
+
42
+ ### data
43
+
44
+ - `DataTable`: tables from objects (`rows`, optional `columns` with `kind: 'number'`, `format`, `render`). Prefer it over writing `thead`/`tr`/`td`.
45
+ - `Table`: a styled table when you need to write the rows yourself.
46
+ - `Metric`, `MetricGroup`: a labelled value and a row of them.
47
+ - `Avatar`: an image or initials for a person.
48
+
49
+ ### feedback
50
+
51
+ - `Alert`: a status message with a `StatusPurpose`.
52
+ - `Badge`: a short status label.
53
+ - `Toast`, `ToastRegion`: transient notifications and the region that announces them.
54
+ - `Progress`, `Spinner`, `Skeleton`: determinate progress, indeterminate wait, and a loading placeholder.
55
+ - `Tooltip`: a short hint for a control.
56
+ - `ConfirmDeletePanel`: inline confirmation before a destructive action.
57
+ - `EmptyState`: what to show when a list or page has no data yet.
58
+
59
+ ### forms
60
+
61
+ - `Field`, `FieldMessage`, `FieldMessages`: label, hint and error wiring around any control.
62
+ - `FormField`: `Field` plus a control that takes the result of react-hook-form's `register()`.
63
+ - `Input`, `Select`, `Textarea`, `Checkbox`, `Radio`, `RadioGroup`, `Switch`, `Range`, `ColorInput`, `FileInput`: form controls.
64
+ - `DatePicker`, `TimePicker`: date and time entry.
65
+ - `SegmentedControl`: one choice from a few options shown side by side.
66
+ - `FilterBar`, `FilterRow`: filters above a list or table.
67
+ - `FormActions`: the submit and cancel row of a form.
68
+
69
+ ### layout
70
+
71
+ - `Page`: the page frame, with `Page.Title` and `Page.Content`.
72
+ - `PageContainer`: the width and padding of page content.
73
+ - `PageHeader`: page title, description and actions.
74
+ - `Section`: a titled block of a page.
75
+ - `Card`: a framed repeated item.
76
+ - `Divider`: a separator between plain sections.
77
+ - `Disclosure`: content that opens and closes.
78
+ - `BottomSheet`: a panel that slides up on small screens.
79
+ - `PublicLayout`, `Navbar`, `Footer`: the application shell and its parts.
80
+
81
+ ### navigation
82
+
83
+ - `Link`: a router link with an optional `purpose`.
84
+ - `Menu`, `MenuItem`, `MenuButton`, `MenuTitle`, `MenuNavLink`: vertical menus.
85
+ - `Dropdown`: a menu that opens from a trigger.
86
+ - `NavMenu`, `NavMenuItem`, `NavMenuColumn`: site navigation.
87
+
88
+ ### overlays
89
+
90
+ - `ModalWindow`, `NativeDialog`: dialogs (`size`: `sm`, `md`, `lg`).
91
+ - `ConsentBanner`, `ConsentSettings`: cookie consent.
92
+
93
+ ### typography
94
+
95
+ - `Heading`: headings; use it instead of `<h1>`-`<h4>`.
96
+ - `Paragraph`: body text.
97
+ - `Prose`: long-form rich text.
98
+
99
+ ### Other subpaths
100
+
101
+ - `icons`: the Tabler icon set from `react-icons/tb` (`TbPlus`, `TbTrash`, ...) and `IconType`. Import icons by name, never `import * as`.
102
+ - `theme-generator`: the theme config schema and `themeCss` for building palettes in code; see `purpose-ui-theming`.
103
+
104
+ ## Missing component
105
+
106
+ If no component fits, do not work around it with raw markup or local copies. Add the component to [ksojecki/purpose-ui](https://github.com/ksojecki/purpose-ui) first (an issue or a PR to `next`), then use the release that has it.
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: purpose-ui-theming
3
+ description: Set up @ksojecki/purpose-ui styles, pick a palette, handle dark mode and theme tokens, and build a custom palette with purpose-ui-theme. Use when editing stylesheets, colours or themes in a project that depends on @ksojecki/purpose-ui.
4
+ ---
5
+
6
+ # purpose-ui theming
7
+
8
+ ## Import contract
9
+
10
+ In the app's main stylesheet, import Tailwind and exactly one palette entry:
11
+
12
+ ```css
13
+ @import 'tailwindcss';
14
+ @import '@ksojecki/purpose-ui/styles/generic.css';
15
+ ```
16
+
17
+ The entry loads daisyUI with its built-in themes off, the shared rules from `theme.css` (Karla font, motion utilities), one palette, and a Tailwind `@source` for the built components.
18
+
19
+ To compose the pieces yourself: `@plugin "daisyui" { themes: false; }`, then `@import '@ksojecki/purpose-ui/theme.css'`, then one `@ksojecki/purpose-ui/themes/<palette>.css`, and `@source '../node_modules/@ksojecki/purpose-ui/dist';`.
20
+
21
+ ## Palettes and dark mode
22
+
23
+ - Palettes: `generic`, `budget`, `traffic`, `roadsign`. Each defines `<name>` (light) and `<name>-dark`.
24
+ - With no `data-theme` on `<html>`, the OS colour scheme decides. `data-theme="<name>"` or `"<name>-dark"` forces one.
25
+ - Check every UI change in light and dark.
26
+
27
+ ## Tokens, not colours
28
+
29
+ - Use semantic daisyUI colours (`bg-base-100`, `text-base-content`, `text-error`) and the theme tokens: `--paper-border`, `--paper-shadow`, `--ink-muted`, `--surface-highlight`, `--control-border`, `--navbar-bg`, `--navbar-content`, `--elevation-1` to `--elevation-3`, `--overlay-scrim`, `--focus-ring-color`.
30
+ - Never use hex values, `rgb()` literals or Tailwind palette classes (`bg-red-500`).
31
+ - An app-local token that changes in dark mode needs an override under both `[data-theme='<palette>-dark']` and `:root:not([data-theme])` inside `@media (prefers-color-scheme: dark)`.
32
+ - Motion: `animate-fade-in`, `animate-slide-up`, `animate-scale-in`, and `--motion-fast`, `--motion-base`, `--motion-slow` with `--motion-ease`. They switch off under `prefers-reduced-motion`.
33
+
34
+ ## Custom palette
35
+
36
+ Keep a `purpose-ui.theme.json` in the repository (schema: `@ksojecki/purpose-ui/theme-config.schema.json`) and generate the CSS:
37
+
38
+ ```sh
39
+ npx purpose-ui-theme init # starter config
40
+ npx purpose-ui-theme build purpose-ui.theme.json -o src/<name>.theme.css
41
+ npx purpose-ui-theme check purpose-ui.theme.json -o src/<name>.theme.css # in CI
42
+ ```
43
+
44
+ `build` fails when a required contrast pair fails (`--allow-contrast-failures` writes anyway); `check` fails when the CSS is stale. The [theme generator](https://sojecki.pl/ui/theme-generator/) previews a config. Import the generated file in place of `themes/<palette>.css`.