@nectary/cli 1.0.57 → 1.0.58-alpha.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.
package/README.md CHANGED
@@ -1,11 +1,61 @@
1
1
  # Nectary CLI
2
2
 
3
- Add Nectary compositions (higher-order React components built on `@nectary/components`) directly into your project. This follows the same “copy source into your repo” approach as [Shadcn UI](https://ui.shadcn.com/), so you own the code and can edit it. It is aimed at React 16–18 apps where using these compositions as web components would require awkward serialization of objects/arrays.
3
+ Add Nectary compositions (higher-order React components built on `@nectary/components`) directly into your project. This follows the same "copy source into your repo" approach as [Shadcn UI](https://ui.shadcn.com/), so you own the code and can edit it. It is aimed at React 16–18 apps where using these compositions as web components would require awkward serialization of objects/arrays.
4
+
5
+ Composition source is authored and maintained in `@nectary/kb` — the Nectary knowledge base. The CLI is a thin consumer: it resolves composition JSON from the installed `@nectary/kb` package and copies the source files into your project.
4
6
 
5
7
  ## Prerequisites
6
8
 
7
9
  - Node ^18.19.0 or >=20.5.0 (see `engines` in package.json)
8
- - A project with `@nectary/components` installed
10
+ - A React project with `@nectary/components` installed
11
+
12
+ `@nectary/kb` is installed automatically as a dependency of the CLI — you do not add it to your app.
13
+
14
+ ## Installation
15
+
16
+ `@nectary/cli` is published to [npm](https://www.npmjs.com/package/@nectary/cli). Run commands from your **project root** (where `@nectary/components` is already a dependency).
17
+
18
+ ### Recommended: `npx` (no install)
19
+
20
+ No need to add the CLI to `package.json`. npm downloads it on demand:
21
+
22
+ ```bash
23
+ npx @nectary/cli list
24
+ npx @nectary/cli add button
25
+ ```
26
+
27
+ Pin a version for reproducible runs:
28
+
29
+ ```bash
30
+ npx @nectary/cli@0.0.1 add select
31
+ ```
32
+
33
+ ### Global install
34
+
35
+ ```bash
36
+ npm install -g @nectary/cli
37
+ ```
38
+
39
+ Then from your project root:
40
+
41
+ ```bash
42
+ nectary list
43
+ nectary add button
44
+ ```
45
+
46
+ ### Project dev dependency
47
+
48
+ If you want a fixed version in the repo (e.g. for CI or team scripts):
49
+
50
+ ```bash
51
+ pnpm add -D @nectary/cli
52
+ # or: npm install --save-dev @nectary/cli
53
+ ```
54
+
55
+ ```bash
56
+ pnpm exec nectary add button
57
+ # or: npx nectary add button
58
+ ```
9
59
 
10
60
  ## Usage
11
61
 
@@ -69,43 +119,47 @@ If `nectary.json` is missing, the CLI uses `src/components/nectary`.
69
119
 
70
120
  ## Available compositions
71
121
 
72
- Compositions live in this package under `registry/` and can be customized (e.g. add props) without touching the docs.
73
-
74
122
  | Name | Description | Dependencies |
75
123
  |------|-------------|--------------|
76
124
  | `button` | Simple Button (sinch-button). Props: `text`, `aria-label`, `type`, `size`, `disabled`, `toggled`, `formType`, `onClick`. | — |
77
125
  | `select` | Select with search. Props: `options`, `placeholder`, `searchPlaceholder`, `value`, `onChange`, `style`, `ariaLabel`. | — |
78
126
  | `phone-input` | Phone input with country code selector. Props: `placeholder`, `value`, `onChange`, `style`, `ariaLabel`. | countries-phone-masks |
79
127
  | `table` | Table composition. Props: `columns`, `data`, `getRowKey`. | — |
128
+ | `dropdown` | Action menu dropdown. Props: `options`, `trigger`, `triggerLabel`, `ariaLabel`, `orientation`, `allowScroll`. | — |
129
+ | `time-input` | Time input with picker. Props: `value`, `onChange`, `label`, `placeholder`, `style`, `ariaLabel`. | — |
130
+ | `date-input` | Date input with picker (DD-MM-YYYY). Props: `value`, `onChange`, `min`, `max`, `locale`, `label`, `style`, `ariaLabel`. | — |
131
+ | `color-select` | Color select. Props: `options`, `value`, `onChange`, `placeholder`, `style`, `ariaLabel`. | — |
132
+ | `emoji-input` | Textarea with emoji picker. Props: `value`, `onChange`, `label`, `placeholder`, `additionalText`, `style`, `ariaLabel`. | — |
133
+ | `file-input` | File picker or drop zone. Props: `variant`, `multiple`, `onChange`, `onInvalid`, `label`, `buttonText`, `placeholder`, etc. | — |
134
+ | `search-input` | Search with async autocomplete. Props: `value`, `onChange`, `onSearch`, `label`, `placeholder`, `noResultsText`. | — |
135
+ | `form` | Minimal form with configurable fields. Props: `fields`, `onSubmit`, `submitLabel`, `style`. | — |
136
+ | `rich-textarea` | Rich text editor with toolbar, emoji, link, chips. Props: `value`, `onChange`, `placeholder`, `chipOptions`, `toolbar`. | — |
80
137
 
81
138
  ## Running locally (development)
82
139
 
83
- From the monorepo root or from `packages/nectary-cli`:
84
-
85
140
  ```bash
86
- pnpm --filter nectary build
141
+ pnpm run build
142
+ node dist/index.js add select
87
143
  ```
88
144
 
89
- Then from the project where you want to add a composition:
145
+ Or with a `--path` override:
90
146
 
91
147
  ```bash
92
- node /path/to/nectary/packages/nectary-cli/dist/index.js add select
148
+ node dist/index.js add button --path src/ui/nectary
93
149
  ```
94
150
 
95
- Or from `packages/nectary-cli`:
151
+ ## Adding or editing compositions
96
152
 
97
- ```bash
98
- node dist/index.js add select
99
- ```
153
+ Compositions are authored in `nectary-kb/packages/compositions/`. To add a new composition:
154
+
155
+ 1. Add `<name>/<ComponentName>.tsx` in `nectary-kb/packages/compositions/`.
156
+ 2. Register it in `nectary-kb/packages/compositions/registry.json`.
157
+ 3. Run `pnpm run kb:generate` in `nectary-kb` to rebuild `dist/`.
158
+ 4. Bump and publish `@nectary/kb`, then bump this CLI's `@nectary/kb` dependency and publish.
159
+
160
+ See `nectary-kb/packages/compositions/README.md` for full authoring instructions.
161
+
162
+ ## Architecture
100
163
 
101
- ## Adding a new composition to the registry
102
-
103
- 1. **Add the composition source** in this package under `registry/<name>/` (e.g. `registry/select/Search.tsx`). You can add whatever props you want; these files are the single source of truth for the CLI and are independent of the docs.
104
- 2. **Edit `registry.json`** in this package. Add an item with:
105
- - `name` – Kebab-case id used in `nectary add <name>`.
106
- - `description` – Short description.
107
- - `dependencies` – Array of npm package names (e.g. `"zod"`, `"@hookform/resolvers"`).
108
- - `files` – Array of `{ "path": "OutputPath/File.tsx", "source": "registry/<name>/File.tsx" }`.
109
- `path` is where the file will be written in the user's project (relative to their components path). `source` is relative to **this package root** (e.g. `registry/select/Search.tsx`).
110
- 3. **Rebuild the registry**: from `packages/nectary-cli`, run `pnpm run build` (or `pnpm run build:registry` after `tsc`). This reads the manifest and writes `dist/registry/<name>.json`.
111
- 4. **Publish** the `nectary` package so users can run `npx @nectary/cli add <name>`.
164
+ - `@nectary/kb` is the single source of truth. Compositions are authored in its `packages/compositions/` directory and distributed as `dist/compositions/<name>.json` with inlined file content.
165
+ - This CLI's `src/registry.ts` resolves `@nectary/kb/compositions/<name>.json` via Node module resolution at runtime. No composition source is bundled in this package.
package/dist/add.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { fileURLToPath } from 'url';
4
3
  import { Command } from 'commander';
5
4
  import { filterMissingDependencies, resolvePathWithinBase } from './add-helpers.js';
6
5
  import { getComponentsPath, loadNectaryConfig } from './config.js';
@@ -19,10 +18,9 @@ export function addCommand() {
19
18
  validateProjectDependencies(cwd);
20
19
  const config = loadNectaryConfig(cwd);
21
20
  const basePath = options.path ?? getComponentsPath(config);
22
- const cliDir = path.dirname(fileURLToPath(import.meta.url));
23
- const item = await loadRegistryItem(name, cliDir);
21
+ const item = await loadRegistryItem(name);
24
22
  if (item == null) {
25
- console.error(`Error: composition "${name}" not found.`);
23
+ console.error(`Error: composition "${name}" not found. Ensure @nectary/kb is installed.`);
26
24
  process.exit(1);
27
25
  }
28
26
  const baseDir = path.resolve(cwd, basePath);
package/dist/list.js CHANGED
@@ -1,15 +1,12 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
1
  import { Command } from 'commander';
4
2
  import { listRegistryItems } from './registry.js';
5
3
  export function listCommand() {
6
4
  return new Command('list')
7
5
  .description('List available compositions (name and description)')
8
6
  .action(() => {
9
- const cliDir = path.dirname(fileURLToPath(import.meta.url));
10
- const items = listRegistryItems(cliDir);
7
+ const items = listRegistryItems();
11
8
  if (items.length === 0) {
12
- console.log('No compositions found.');
9
+ console.log('No compositions found. Ensure @nectary/kb is installed.');
13
10
  return;
14
11
  }
15
12
  for (const { name, description } of items) {
package/dist/registry.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
- import path from 'path';
2
+ import { createRequire } from 'module';
3
+ const require = createRequire(import.meta.url);
3
4
  function isRegistryFile(value) {
4
5
  return (typeof value === 'object' &&
5
6
  value !== null &&
@@ -23,16 +24,10 @@ function parseRegistryItem(data) {
23
24
  if (description !== undefined && typeof description !== 'string') {
24
25
  return null;
25
26
  }
26
- if (!Array.isArray(dependencies)) {
27
+ if (!Array.isArray(dependencies) || !dependencies.every((d) => typeof d === 'string')) {
27
28
  return null;
28
29
  }
29
- if (!dependencies.every((d) => typeof d === 'string')) {
30
- return null;
31
- }
32
- if (!Array.isArray(files)) {
33
- return null;
34
- }
35
- if (!files.every(isRegistryFile)) {
30
+ if (!Array.isArray(files) || !files.every(isRegistryFile)) {
36
31
  return null;
37
32
  }
38
33
  return {
@@ -58,47 +53,54 @@ async function loadFromUrl(url) {
58
53
  return null;
59
54
  }
60
55
  }
61
- function loadFromBundle(name, cliDir) {
62
- const registryDir = path.join(cliDir, 'registry');
63
- const filePath = path.join(registryDir, `${name}.json`);
64
- if (!fs.existsSync(filePath)) {
56
+ /**
57
+ * Compositions ship inside `@nectary/kb` at `dist/compositions/<name>.json`,
58
+ * exposed via the package's `./compositions/*.json` export pattern. The CLI is
59
+ * a thin client — it resolves the file through Node's module resolution and
60
+ * parses it. Compositions are authored in `nectary-kb/packages/compositions/`.
61
+ */
62
+ function loadFromKb(name) {
63
+ let filePath;
64
+ try {
65
+ filePath = require.resolve(`@nectary/kb/compositions/${name}.json`);
66
+ }
67
+ catch {
65
68
  return null;
66
69
  }
67
70
  const raw = fs.readFileSync(filePath, 'utf8');
68
71
  const data = JSON.parse(raw);
69
72
  return parseRegistryItem(data);
70
73
  }
71
- export function loadRegistryItem(name, cliDir) {
74
+ export function loadRegistryItem(name) {
72
75
  if (isUrl(name)) {
73
76
  return loadFromUrl(name);
74
77
  }
75
- return Promise.resolve(loadFromBundle(name, cliDir));
78
+ return Promise.resolve(loadFromKb(name));
76
79
  }
77
- export function listRegistryItems(cliDir) {
78
- const registryDir = path.join(cliDir, 'registry');
79
- if (!fs.existsSync(registryDir)) {
80
+ export function listRegistryItems() {
81
+ let catalogPath;
82
+ try {
83
+ catalogPath = require.resolve('@nectary/kb/compositions/catalog');
84
+ }
85
+ catch {
86
+ return [];
87
+ }
88
+ const raw = fs.readFileSync(catalogPath, 'utf8');
89
+ const data = JSON.parse(raw);
90
+ if (!Array.isArray(data)) {
80
91
  return [];
81
92
  }
82
- const files = fs.readdirSync(registryDir);
83
93
  const items = [];
84
- for (const file of files) {
85
- if (!file.endsWith('.json')) {
94
+ for (const entry of data) {
95
+ if (entry === null || typeof entry !== 'object')
86
96
  continue;
87
- }
88
- const filePath = path.join(registryDir, file);
89
- try {
90
- const raw = fs.readFileSync(filePath, 'utf8');
91
- const data = JSON.parse(raw);
92
- if (data.name != null) {
93
- items.push({
94
- name: data.name,
95
- description: data.description ?? '',
96
- });
97
- }
98
- }
99
- catch {
100
- // skip invalid or unreadable files
101
- }
97
+ const obj = entry;
98
+ if (typeof obj.name !== 'string')
99
+ continue;
100
+ items.push({
101
+ name: obj.name,
102
+ description: typeof obj.description === 'string' ? obj.description : '',
103
+ });
102
104
  }
103
105
  return items.sort((a, b) => a.name.localeCompare(b.name));
104
106
  }
package/dist/view.js CHANGED
@@ -1,5 +1,3 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
1
  import { Command } from 'commander';
4
2
  import { loadRegistryItem } from './registry.js';
5
3
  export function viewCommand() {
@@ -7,10 +5,9 @@ export function viewCommand() {
7
5
  .description('Preview a composition (description, dependencies, files) without adding it')
8
6
  .argument('<name>', 'Registry item name or URL to a registry item JSON')
9
7
  .action(async (name) => {
10
- const cliDir = path.dirname(fileURLToPath(import.meta.url));
11
- const item = await loadRegistryItem(name, cliDir);
8
+ const item = await loadRegistryItem(name);
12
9
  if (item == null) {
13
- console.error(`Error: composition "${name}" not found.`);
10
+ console.error(`Error: composition "${name}" not found. Ensure @nectary/kb is installed.`);
14
11
  process.exit(1);
15
12
  }
16
13
  console.log(item.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/cli",
3
- "version": "1.0.57",
3
+ "version": "1.0.58-alpha.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "CLI to add Nectary compositions as React components to your project",
@@ -8,30 +8,32 @@
8
8
  "access": "public"
9
9
  },
10
10
  "bin": {
11
- "nectary": "./dist/index.js"
11
+ "nectary": "dist/index.js"
12
12
  },
13
13
  "main": "dist/index.js",
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
17
  "scripts": {
18
- "build": "tsc && node scripts/build-registry.mjs",
19
- "build:registry": "node scripts/build-registry.mjs",
18
+ "build": "tsc",
19
+ "typecheck": "tsc --noEmit",
20
20
  "prepublishOnly": "pnpm run build",
21
- "test": "pnpm run build && node --test test/add.select.smoke.test.mjs"
21
+ "test": "pnpm run build && node --test tests/smoke/*.test.mjs",
22
+ "test:smoke": "pnpm run build && node --test tests/smoke/*.test.mjs",
23
+ "smoke": "pnpm run build && node scripts/smoke.mjs"
22
24
  },
23
25
  "dependencies": {
24
26
  "@antfu/ni": "^0.21.0",
27
+ "@nectary/kb": "1.0.0-alpha.2",
25
28
  "commander": "^12.0.0",
26
29
  "execa": "^9.0.0"
27
30
  },
28
31
  "devDependencies": {
29
- "react": "^18.2.0",
30
- "@nectary/components": "5.41.0",
31
32
  "@types/node": "^18.17.17",
32
33
  "typescript": "^5.2.2"
33
34
  },
34
35
  "engines": {
35
36
  "node": "^18.19.0 || >=20.5.0"
36
- }
37
+ },
38
+ "packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
37
39
  }
package/readme.md ADDED
@@ -0,0 +1,165 @@
1
+ # Nectary CLI
2
+
3
+ Add Nectary compositions (higher-order React components built on `@nectary/components`) directly into your project. This follows the same "copy source into your repo" approach as [Shadcn UI](https://ui.shadcn.com/), so you own the code and can edit it. It is aimed at React 16–18 apps where using these compositions as web components would require awkward serialization of objects/arrays.
4
+
5
+ Composition source is authored and maintained in `@nectary/kb` — the Nectary knowledge base. The CLI is a thin consumer: it resolves composition JSON from the installed `@nectary/kb` package and copies the source files into your project.
6
+
7
+ ## Prerequisites
8
+
9
+ - Node ^18.19.0 or >=20.5.0 (see `engines` in package.json)
10
+ - A React project with `@nectary/components` installed
11
+
12
+ `@nectary/kb` is installed automatically as a dependency of the CLI — you do not add it to your app.
13
+
14
+ ## Installation
15
+
16
+ `@nectary/cli` is published to [npm](https://www.npmjs.com/package/@nectary/cli). Run commands from your **project root** (where `@nectary/components` is already a dependency).
17
+
18
+ ### Recommended: `npx` (no install)
19
+
20
+ No need to add the CLI to `package.json`. npm downloads it on demand:
21
+
22
+ ```bash
23
+ npx @nectary/cli list
24
+ npx @nectary/cli add button
25
+ ```
26
+
27
+ Pin a version for reproducible runs:
28
+
29
+ ```bash
30
+ npx @nectary/cli@0.0.1 add select
31
+ ```
32
+
33
+ ### Global install
34
+
35
+ ```bash
36
+ npm install -g @nectary/cli
37
+ ```
38
+
39
+ Then from your project root:
40
+
41
+ ```bash
42
+ nectary list
43
+ nectary add button
44
+ ```
45
+
46
+ ### Project dev dependency
47
+
48
+ If you want a fixed version in the repo (e.g. for CI or team scripts):
49
+
50
+ ```bash
51
+ pnpm add -D @nectary/cli
52
+ # or: npm install --save-dev @nectary/cli
53
+ ```
54
+
55
+ ```bash
56
+ pnpm exec nectary add button
57
+ # or: npx nectary add button
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ ### List compositions
63
+
64
+ ```bash
65
+ npx @nectary/cli list
66
+ ```
67
+
68
+ Prints each available composition name and its one-line description.
69
+
70
+ ### View a composition
71
+
72
+ Preview a composition before adding it (description, dependencies, and files that would be written):
73
+
74
+ ```bash
75
+ npx @nectary/cli view <name>
76
+ ```
77
+
78
+ Example:
79
+
80
+ ```bash
81
+ npx @nectary/cli view table
82
+ ```
83
+
84
+ ### Add a composition
85
+
86
+ From your project root:
87
+
88
+ ```bash
89
+ npx @nectary/cli add <name>
90
+ ```
91
+
92
+ Examples:
93
+
94
+ ```bash
95
+ npx @nectary/cli add button
96
+ npx @nectary/cli add select
97
+ npx @nectary/cli add phone-input
98
+ npx @nectary/cli add table
99
+ ```
100
+
101
+ Files are written under `src/components/nectary/` by default (see [Configuration](#configuration)). The CLI will also install any npm dependencies required by the composition (e.g. `countries-phone-masks` for `phone-input`).
102
+
103
+ ### Options
104
+
105
+ - **`--path <path>`** – Override the output directory (default: `src/components/nectary`).
106
+ - **`--overwrite`** – Replace existing files. Without this, existing files are skipped.
107
+
108
+ ### Configuration
109
+
110
+ Optional: create a `nectary.json` file at your project root to set the default components path:
111
+
112
+ ```json
113
+ {
114
+ "componentsPath": "src/components/nectary"
115
+ }
116
+ ```
117
+
118
+ If `nectary.json` is missing, the CLI uses `src/components/nectary`.
119
+
120
+ ## Available compositions
121
+
122
+ | Name | Description | Dependencies |
123
+ |------|-------------|--------------|
124
+ | `button` | Simple Button (sinch-button). Props: `text`, `aria-label`, `type`, `size`, `disabled`, `toggled`, `formType`, `onClick`. | — |
125
+ | `select` | Select with search. Props: `options`, `placeholder`, `searchPlaceholder`, `value`, `onChange`, `style`, `ariaLabel`. | — |
126
+ | `phone-input` | Phone input with country code selector. Props: `placeholder`, `value`, `onChange`, `style`, `ariaLabel`. | countries-phone-masks |
127
+ | `table` | Table composition. Props: `columns`, `data`, `getRowKey`. | — |
128
+ | `dropdown` | Action menu dropdown. Props: `options`, `trigger`, `triggerLabel`, `ariaLabel`, `orientation`, `allowScroll`. | — |
129
+ | `time-input` | Time input with picker. Props: `value`, `onChange`, `label`, `placeholder`, `style`, `ariaLabel`. | — |
130
+ | `date-input` | Date input with picker (DD-MM-YYYY). Props: `value`, `onChange`, `min`, `max`, `locale`, `label`, `style`, `ariaLabel`. | — |
131
+ | `color-select` | Color select. Props: `options`, `value`, `onChange`, `placeholder`, `style`, `ariaLabel`. | — |
132
+ | `emoji-input` | Textarea with emoji picker. Props: `value`, `onChange`, `label`, `placeholder`, `additionalText`, `style`, `ariaLabel`. | — |
133
+ | `file-input` | File picker or drop zone. Props: `variant`, `multiple`, `onChange`, `onInvalid`, `label`, `buttonText`, `placeholder`, etc. | — |
134
+ | `search-input` | Search with async autocomplete. Props: `value`, `onChange`, `onSearch`, `label`, `placeholder`, `noResultsText`. | — |
135
+ | `form` | Minimal form with configurable fields. Props: `fields`, `onSubmit`, `submitLabel`, `style`. | — |
136
+ | `rich-textarea` | Rich text editor with toolbar, emoji, link, chips. Props: `value`, `onChange`, `placeholder`, `chipOptions`, `toolbar`. | — |
137
+
138
+ ## Running locally (development)
139
+
140
+ ```bash
141
+ pnpm run build
142
+ node dist/index.js add select
143
+ ```
144
+
145
+ Or with a `--path` override:
146
+
147
+ ```bash
148
+ node dist/index.js add button --path src/ui/nectary
149
+ ```
150
+
151
+ ## Adding or editing compositions
152
+
153
+ Compositions are authored in `nectary-kb/packages/compositions/`. To add a new composition:
154
+
155
+ 1. Add `<name>/<ComponentName>.tsx` in `nectary-kb/packages/compositions/`.
156
+ 2. Register it in `nectary-kb/packages/compositions/registry.json`.
157
+ 3. Run `pnpm run kb:generate` in `nectary-kb` to rebuild `dist/`.
158
+ 4. Bump and publish `@nectary/kb`, then bump this CLI's `@nectary/kb` dependency and publish.
159
+
160
+ See `nectary-kb/packages/compositions/README.md` for full authoring instructions.
161
+
162
+ ## Architecture
163
+
164
+ - `@nectary/kb` is the single source of truth. Compositions are authored in its `packages/compositions/` directory and distributed as `dist/compositions/<name>.json` with inlined file content.
165
+ - This CLI's `src/registry.ts` resolves `@nectary/kb/compositions/<name>.json` via Node module resolution at runtime. No composition source is bundled in this package.
@@ -1,11 +0,0 @@
1
- {
2
- "name": "button",
3
- "description": "Simple Button wrapper (sinch-button). Props: text, aria-label, type, size, disabled, toggled, formType, onClick.",
4
- "dependencies": [],
5
- "files": [
6
- {
7
- "path": "Button/Button.tsx",
8
- "content": "import type { FC } from 'react'\nimport '@nectary/components/button'\n\nexport type ButtonType =\n | 'primary'\n | 'secondary'\n | 'subtle-primary'\n | 'subtle-secondary'\n | 'cta-primary'\n | 'cta-secondary'\n | 'destructive'\n\nexport type ButtonSize = 's' | 'm' | 'l'\n\nexport interface ButtonProps {\n /** Button label (visible text). */\n text: string,\n /** Accessible name for the button. */\n 'aria-label': string,\n /** Visual type. Default: primary. */\n type?: ButtonType,\n /** Size: s, m, l. Default: m. */\n size?: ButtonSize,\n isDisabled?: boolean,\n isToggled?: boolean,\n /** Form association: button, submit, reset. Default: button. */\n formType?: 'button' | 'submit' | 'reset',\n onClick?: () => void,\n}\n\nexport const Button: FC<ButtonProps> = ({\n text,\n 'aria-label': ariaLabel,\n type = 'primary',\n size = 'm',\n isDisabled = false,\n isToggled = false,\n formType = 'button',\n onClick,\n}) => {\n return (\n <sinch-button\n text={text}\n aria-label={ariaLabel}\n type={type as 'primary' | 'secondary' | 'subtle-primary' | 'subtle-secondary' | 'cta-primary' | 'cta-secondary' | 'destructive'}\n size={size as 's' | 'm' | 'l'}\n disabled={isDisabled}\n toggled={isToggled}\n form-type={formType}\n on-click={onClick}\n />\n )\n}"
9
- }
10
- ]
11
- }
@@ -1,13 +0,0 @@
1
- {
2
- "name": "phone-input",
3
- "description": "Phone input with country code selector. Accepts placeholder, value, onChange, style and ariaLabel props.",
4
- "dependencies": [
5
- "countries-phone-masks@^1.1.0"
6
- ],
7
- "files": [
8
- {
9
- "path": "PhoneInput/PhoneInput.tsx",
10
- "content": "import countries from 'countries-phone-masks'\nimport { useState } from 'react'\nimport type { CSSProperties, FC } from 'react'\nimport '@nectary/components/popover'\nimport '@nectary/components/input'\nimport '@nectary/components/select-menu'\nimport '@nectary/components/select-menu-option'\nimport '@nectary/components/select-button'\nimport '@nectary/components/flag'\n\nconst defaultInputStyles: CSSProperties = {\n width: 300,\n}\n\nexport interface PhoneInputProps {\n placeholder?: string,\n value?: string,\n onChange?: (value: string) => void,\n style?: CSSProperties,\n ariaLabel?: string,\n}\n\nexport const PhoneInput: FC<PhoneInputProps> = ({\n placeholder = 'Phone Number',\n value: controlledValue,\n onChange,\n style = defaultInputStyles,\n ariaLabel = 'Phone number',\n}) => {\n const [isOpen, setIsOpen] = useState(false)\n const [menuValue, setMenuValue] = useState('')\n const [internalValue, setInternalValue] = useState('')\n const inputValue = controlledValue ?? internalValue\n const setInputValue = onChange != null\n ? (v: string) => {\n onChange(v); setInternalValue(v)\n }\n : setInternalValue\n\n const onClose = () => setIsOpen(false)\n const onOpen = () => setIsOpen(true)\n const onMenuChange = (e: CustomEvent<string>) => {\n onClose()\n setMenuValue(e.detail)\n }\n const onInputChange = (e: CustomEvent<string>) => {\n setInputValue(e.detail)\n }\n const phoneCode = countries.find((country) => country.iso === menuValue)?.code ?? ''\n const phoneMask = countries.find((country) => country.iso === menuValue)?.mask ?? ''\n\n return (\n <sinch-popover\n open={isOpen}\n aria-label=\"Select\"\n orientation=\"bottom\"\n modal\n on-close={onClose}\n >\n <sinch-input\n slot=\"target\"\n aria-label={ariaLabel}\n mask={(Array.isArray(phoneMask) ? phoneMask[0] : phoneMask).replaceAll('#', '0')}\n placeholder={placeholder}\n value={inputValue}\n style={style}\n on-change={onInputChange}\n >\n <sinch-select-button\n slot=\"left\"\n size=\"s\"\n text={phoneCode}\n placeholder=\"+0\"\n aria-label=\"Open area code select\"\n on-click={onOpen}\n >\n {menuValue.length > 0 && (\n <sinch-flag slot=\"icon\" code={menuValue.toLowerCase()}/>\n )}\n </sinch-select-button>\n </sinch-input>\n <sinch-select-menu\n slot=\"content\"\n rows={5}\n aria-label={menuValue !== '' ? `Area code selected ${menuValue}` : 'Select area code'}\n value={menuValue}\n on-change={onMenuChange}\n >\n {countries.map(({ code, iso, name }) => (\n <sinch-select-menu-option\n key={iso}\n value={iso}\n text={`(${code}) ${name}`}\n aria-label={`Select ${name}`}\n >\n <sinch-flag slot=\"icon\" code={iso.toLowerCase()}/>\n </sinch-select-menu-option>\n ))}\n </sinch-select-menu>\n </sinch-popover>\n )\n}"
11
- }
12
- ]
13
- }
@@ -1,11 +0,0 @@
1
- {
2
- "name": "select",
3
- "description": "Select composition with search (Popover + SelectButton + SelectMenu). Accepts options, placeholder, value, onChange and style props.",
4
- "dependencies": [],
5
- "files": [
6
- {
7
- "path": "Select/Search.tsx",
8
- "content": "import { useState } from 'react'\nimport type { CSSProperties, FC } from 'react'\nimport '@nectary/components/popover'\nimport '@nectary/components/select-button'\nimport '@nectary/components/select-menu'\nimport '@nectary/components/select-menu-option'\n\nconst defaultSelectStyles: CSSProperties = {\n width: 300,\n}\n\nexport interface SelectSearchProps {\n /** Options to display. */\n options?: string[],\n placeholder?: string,\n searchPlaceholder?: string,\n /** Controlled value */\n value?: string,\n /** Callback when selection changes */\n onChange?: (value: string) => void,\n style?: CSSProperties,\n ariaLabel?: string,\n}\n\nexport const SelectSearch: FC<SelectSearchProps> = ({\n options = [],\n placeholder = 'Select option',\n searchPlaceholder = 'Search',\n value: controlledValue,\n onChange,\n style = defaultSelectStyles,\n ariaLabel = 'Select',\n}) => {\n const [isOpen, setIsOpen] = useState(false)\n const [internalValue, setInternalValue] = useState('')\n const value = controlledValue ?? internalValue\n const setValue = onChange != null ? (v: string) => {\n onChange(v); setInternalValue(v)\n } : setInternalValue\n\n const onSelectChange = (e: CustomEvent<string>) => {\n setValue(e.detail)\n setIsOpen(false)\n }\n const onClose = () => setIsOpen(false)\n const onOpen = () => setIsOpen(true)\n\n return (\n <sinch-popover\n open={isOpen}\n aria-label={ariaLabel}\n orientation=\"bottom\"\n modal\n on-close={onClose}\n >\n <sinch-select-button\n slot=\"target\"\n text={value}\n placeholder={placeholder}\n aria-label={`Open ${ariaLabel}`}\n style={style}\n on-click={onOpen}\n />\n <sinch-select-menu\n slot=\"content\"\n aria-label={`${ariaLabel} menu`}\n rows={3}\n value={value}\n on-change={onSelectChange}\n search-placeholder={searchPlaceholder}\n >\n {options.map((option) => (\n <sinch-select-menu-option\n key={option}\n value={option}\n text={option}\n aria-label={option}\n />\n ))}\n </sinch-select-menu>\n </sinch-popover>\n )\n}"
9
- }
10
- ]
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "name": "table",
3
- "description": "Table composition (Table + TableHead + TableRow + TableHeadCell + TableCell + TableBody). Accepts columns and data props.",
4
- "dependencies": [],
5
- "files": [
6
- {
7
- "path": "Table/Table.tsx",
8
- "content": "import type { FC, ReactNode } from 'react'\nimport '@nectary/components/table'\nimport '@nectary/components/table-head'\nimport '@nectary/components/table-row'\nimport '@nectary/components/table-head-cell'\nimport '@nectary/components/table-cell'\nimport '@nectary/components/table-body'\nimport '@nectary/components/text'\n\nexport interface TableColumn {\n key: string,\n header: string,\n align?: 'start' | 'end',\n}\n\nexport interface TableProps {\n /** Column definitions (key, header, optional align). */\n columns: TableColumn[],\n /** Row data: array of objects keyed by column keys. */\n data: Record<string, unknown>[],\n /** Optional row key for React list (default: index). */\n getRowKey?: (row: Record<string, unknown>, index: number) => string,\n}\n\nfunction formatCell(value: unknown): ReactNode {\n if (value === null || value === undefined) {\n return ''\n }\n\n if (typeof value === 'object' && typeof (value as { toString?: () => string }).toString === 'function') {\n return String((value as { toString: () => string }).toString())\n }\n\n return String(value)\n}\n\nexport const Table: FC<TableProps> = ({\n columns,\n data,\n getRowKey = (_, index) => String(index),\n}) => {\n return (\n <sinch-table>\n <sinch-table-head>\n <sinch-table-row>\n {columns.map((col) => (\n <sinch-table-head-cell\n key={col.key}\n text={col.header}\n align={col.align}\n />\n ))}\n </sinch-table-row>\n </sinch-table-head>\n\n <sinch-table-body>\n {data.map((row, index) => (\n <sinch-table-row key={getRowKey(row, index)}>\n {columns.map((col) => (\n <sinch-table-cell key={col.key} align={col.align}>\n <sinch-text type=\"s\">{formatCell(row[col.key])}</sinch-text>\n </sinch-table-cell>\n ))}\n </sinch-table-row>\n ))}\n </sinch-table-body>\n </sinch-table>\n )\n}"
9
- }
10
- ]
11
- }