create-kerf-component 5.0.0-beta.8 → 6.0.0-beta.1

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.
@@ -0,0 +1,71 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/brianwestphal/kerf/main/create-kerf-component/component-metadata.schema.json",
3
+ "schemaVersion": 1,
4
+ "componentCatalog": "not-applicable",
5
+ "components": [
6
+ {
7
+ "id": "counter",
8
+ "name": "Counter",
9
+ "kind": "component",
10
+ "purpose": "Render a controlled counter with delegated increment and decrement actions.",
11
+ "source": "src/counter.tsx",
12
+ "publicExports": [
13
+ { "name": "Counter", "subpath": "." },
14
+ { "name": "CounterProps", "subpath": "." },
15
+ { "name": "CounterState", "subpath": "." },
16
+ { "name": "CounterStore", "subpath": "." },
17
+ { "name": "createCounter", "subpath": "." },
18
+ { "name": "wireCounter", "subpath": "." },
19
+ { "name": "Counter", "subpath": "./counter" },
20
+ { "name": "CounterProps", "subpath": "./counter" },
21
+ { "name": "CounterState", "subpath": "./counter" },
22
+ { "name": "CounterStore", "subpath": "./counter" },
23
+ { "name": "createCounter", "subpath": "./counter" },
24
+ { "name": "wireCounter", "subpath": "./counter" }
25
+ ],
26
+ "sourceLinks": ["README.md#use-it", "src/counter.tsx"],
27
+ "composition": {
28
+ "parents": { "mode": "any", "entries": [] },
29
+ "contexts": ["controlled-counter"],
30
+ "zones": [],
31
+ "children": {
32
+ "mode": "listed",
33
+ "concepts": ["decrement-control", "value", "increment-control"],
34
+ "requiredConcepts": [
35
+ "decrement-control",
36
+ "value",
37
+ "increment-control"
38
+ ]
39
+ },
40
+ "state": [{ "id": "count", "owner": "controlled", "required": true }],
41
+ "wiring": {
42
+ "required": true,
43
+ "helpers": ["wireCounter"],
44
+ "obligations": [
45
+ "Retain and call the disposer returned by wireCounter."
46
+ ]
47
+ },
48
+ "responsive": { "owner": "not-applicable", "behaviors": [] },
49
+ "layout": {
50
+ "roles": ["counter"],
51
+ "geometry": { "margin": "none", "border": "none", "padding": "none" }
52
+ }
53
+ },
54
+ "boundaries": {
55
+ "rootClass": "kerf-counter",
56
+ "publicClasses": ["kerf-counter"],
57
+ "publicTokens": ["--kerf-counter-gap"]
58
+ },
59
+ "accessibility": {
60
+ "obligations": [
61
+ "Keep increment and decrement controls named and expose the current count as output."
62
+ ]
63
+ },
64
+ "diagnostics": [],
65
+ "provenance": {
66
+ "selection": "README.md#use-it",
67
+ "composition": "README.md#the-rules-this-package-follows"
68
+ }
69
+ }
70
+ ]
71
+ }
@@ -12,23 +12,35 @@
12
12
  "./counter": {
13
13
  "types": "./dist/counter.d.ts",
14
14
  "import": "./dist/counter.js"
15
- }
15
+ },
16
+ "./counter.css": "./src/counter.css"
16
17
  },
17
18
  "files": [
18
19
  "dist",
20
+ "src/counter.css",
21
+ "component-composition.json",
22
+ "kerf.components.json",
19
23
  "README.md",
20
24
  "LICENSE"
21
25
  ],
22
26
  "scripts": {
23
27
  "build": "tsup",
28
+ "catalog:generate": "node scripts/kerf-component-catalog.mjs --write",
29
+ "catalog:check": "node scripts/kerf-component-catalog.mjs --check",
30
+ "check:styles": "kerf-ui-analyze --root . src",
24
31
  "typecheck": "tsc --noEmit",
25
- "prepublishOnly": "npm run build"
32
+ "prepublishOnly": "npm run catalog:check && npm run check:styles && npm run build"
33
+ },
34
+ "kerfComponentCatalog": {
35
+ "source": "./kerf.components.json",
36
+ "output": "./component-composition.json"
26
37
  },
27
38
  "peerDependencies": {
28
- "kerfjs": "^5.0.0-0"
39
+ "kerfjs": "^6.0.0-0"
29
40
  },
30
41
  "devDependencies": {
31
- "kerfjs": "^5.0.0-beta.8",
42
+ "kerfjs": "^6.0.0-beta.1",
43
+ "@kerfjs/ui": "^6.0.0-beta.1",
32
44
  "tsup": "^8",
33
45
  "typescript": "^5 || ^6"
34
46
  }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Counter owns this stylesheet, and this stylesheet styles only Counter.
3
+ *
4
+ * - It selects `.kerf-counter` and Counter's own internals, never another
5
+ * component's class, `[data-component]` root, `wa-*` element, or `::part()`.
6
+ * - It writes only Counter's own `--_kerf-counter-*` private variables. The
7
+ * context Counter hands its buttons is named after Counter, the provider.
8
+ * - Consumers configure Counter through its typed props (`size`) and its one
9
+ * public theme token (`--kerf-counter-gap`), never by restyling
10
+ * `.kerf-counter` from their own CSS. A need with no prop is a gap to add to
11
+ * Counter, not an override for the consumer to write.
12
+ */
13
+ .kerf-counter {
14
+ --_kerf-counter-gap: var(--kerf-counter-gap, 0.5rem);
15
+ --_kerf-counter-control-size: 2rem;
16
+ display: inline-flex;
17
+ align-items: center;
18
+ gap: var(--_kerf-counter-gap);
19
+ }
20
+
21
+ .kerf-counter[data-size="compact"] {
22
+ --_kerf-counter-control-size: 1.5rem;
23
+ }
24
+
25
+ .kerf-counter > button {
26
+ inline-size: var(--_kerf-counter-control-size);
27
+ block-size: var(--_kerf-counter-control-size);
28
+ }
29
+
30
+ /*
31
+ * Parent context: when a Counter sits in a Kerf UI Toolbar, Counter adapts
32
+ * itself here, in its own stylesheet. The parent appears only as an ancestor
33
+ * and Counter stays the subject, so the Toolbar never styles Counter and
34
+ * Counter never styles the Toolbar.
35
+ */
36
+ .kui-toolbar .kerf-counter {
37
+ --_kerf-counter-control-size: 1.75rem;
38
+ }
@@ -28,6 +28,11 @@ export type CounterStore = ReturnType<typeof createCounter>;
28
28
  export interface CounterProps {
29
29
  store: CounterStore;
30
30
  label?: string;
31
+ /**
32
+ * Control density. A typed prop is how consumers configure the component's
33
+ * look; they never restyle `.kerf-counter` from their own CSS.
34
+ */
35
+ size?: 'standard' | 'compact';
31
36
  }
32
37
 
33
38
  /**
@@ -35,10 +40,17 @@ export interface CounterProps {
35
40
  * `data-action` hooks instead of inline event handlers — inline `onClick={...}`
36
41
  * handlers don't survive kerf's morph (and the `no-inline-jsx-event-handlers`
37
42
  * lint rule flags them). The host wires the events; see `wireCounter` below.
43
+ *
44
+ * Its look lives in `counter.css` (the `./counter.css` export), which styles
45
+ * only Counter; `size` is the configuration consumers use instead of CSS.
38
46
  */
39
- export function Counter({ store, label = 'Count' }: CounterProps): SafeHtml {
47
+ export function Counter({
48
+ store,
49
+ label = 'Count',
50
+ size = 'standard',
51
+ }: CounterProps): SafeHtml {
40
52
  return (
41
- <div class="kerf-counter">
53
+ <div class="kerf-counter" data-size={size}>
42
54
  <button type="button" data-action="counter:dec" aria-label="Decrement">
43
55
  −
44
56
  </button>
@@ -61,7 +73,10 @@ export function Counter({ store, label = 'Count' }: CounterProps): SafeHtml {
61
73
  * single listener survives every re-render. Returns the disposer `delegate()`
62
74
  * hands back — call it when the host unmounts.
63
75
  */
64
- export function wireCounter(root: HTMLElement, store: CounterStore): () => void {
76
+ export function wireCounter(
77
+ root: HTMLElement,
78
+ store: CounterStore,
79
+ ): () => void {
65
80
  return delegate(root, 'click', '[data-action^="counter:"]', (_event, el) => {
66
81
  const action = el.getAttribute('data-action');
67
82
  if (action === 'counter:inc') store.actions.inc();