Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions skills/flat-layers-design/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ stores ──► services ──► shared
| `services` | `services`, `shared` | `stores`, `uikit`, `blocks`, `pages` |
| `stores` | `stores`, `services`, `shared` | `uikit`, `blocks`, `pages` |
| `uikit` | `uikit`, `assets`, `shared` | `stores`, `blocks`, `pages`; `services` only as a `type` import, and only when the type can't reasonably be declared in `uikit` |
| `blocks` | `blocks`, `uikit`, `stores`, `services`, `shared` | `pages` |
| `blocks` | `blocks`, `uikit`, `stores`, `services`, `shared`, `assets` | `pages` |
| `pages` | everything | — |

Blocks and pages take from `services` only types, error codes, constants and pure helpers; queries and mutations go through `stores`.
Expand All @@ -83,7 +83,7 @@ Blocks and pages take from `services` only types, error codes, constants and pur
| a visual element with no copy and no data knowledge | `uikit/<Name>/` |
| a component that reads a store, has copy, or collects analytics | `blocks/<Name>/` |
| a part of one block's own job: a sub-part, a variant | inside that block: `blocks/<Name>/<Part>.tsx`, `blocks/<Name>/types/` |
| a helper, hook/composable or messages factory about a domain or a topic rather than one module's job, however many use it today | that layer's `shared/`: `blocks/shared/garden.ts`, `uikit/shared/readOnly.ts` |
| a helper, hook/composable or messages factory about a domain or a topic rather than one module's job, however many use it today | that layer's `shared/`: `blocks/shared/garden.ts`, `uikit/shared/readOnly.ts`; a hook in `shared/hooks.ts` or `shared/hooks/<domain>.ts` |
| a screen bound to a route, or a layout | `pages/<Name>/` |
| a route path | `stores/router.ts`, then register the page in `index.tsx` |
| domain state, derived state, queries, mutations, redirects after actions | `stores/<domain>.ts` |
Expand Down Expand Up @@ -120,13 +120,13 @@ Where code goes follows what it is about, never how many modules use it today. C
services/shared/ — wire-format helpers several adapters use
stores/shared/ — helpers several domain stores repeat
uikit/shared/ — readOnly.ts: read-only props for Checkbox and Radio
blocks/shared/ — messages.ts, garden.ts…: message sets and per-domain helpers
blocks/shared/ — messages.ts, garden.ts, hooks.ts…: message sets, per-domain helpers and hooks
pages/shared/ — messages.tsx: titles and breadcrumbs shared by pages
```

- It is part of its layer and imports only what the layer may import.
- It has no `index.ts`: import its files by name (`../shared/readOnly`).
- Files are named by domain (`garden.ts`) or, in a layer without domains such as uikit, by topic (`readOnly.ts`) — never by kind (no `hooks.ts`, `utils.ts` dumps).
- Files are named by domain (`garden.ts`) or, in a layer without domains such as uikit, by topic (`readOnly.ts`) — never by kind (no `utils.ts` dumps). Hooks are the one exception: they go to `hooks.ts`, or to a `hooks/` folder of files named by domain or topic, so the linter finds them (see the `react-component` skill).
- Domain-free code that needs nothing from the layer (array, date, hashing utils) goes to the app-wide `shared/` instead.

### `services/`
Expand Down Expand Up @@ -220,7 +220,8 @@ The business-logic tier: a block composes uikit components with stores and owns
blocks/
shared/
messages.ts — message sets used by many blocks (common, password…)
garden.ts post.ts report.tsx image.ts — per-domain helpers: messages, hooks/composables, render helpers
garden.ts post.ts report.tsx image.ts — per-domain helpers: messages, render helpers
hooks.ts — hooks several blocks share; a `hooks/` folder of domain files when there are many
GardenForm/
index.ts
GardenForm.tsx
Expand Down
4 changes: 3 additions & 1 deletion skills/react-component/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ Use the `ui-component` skill as the base — it holds the framework-agnostic HTM
[ComponentName].module.css — component styles
[ComponentName].stories.tsx — stories (optional, if Storybook is used)
[ComponentName].spec.tsx — tests (optional, on request)
use[HookName].ts — component logic extracted into a hook (optional, for complex components with a lot of logic)
hooks.ts — component logic extracted into hooks (optional, for complex components with a lot of logic); a `hooks/` folder when there are several
loadable.tsx — lazy-loaded wrapper (optional, when the component pulls in a heavy dependency)
skeleton.tsx — the component's skeleton, its shape while it or its data loads (optional)
```

A hook lives in a `.jsx` or `.tsx` file, in a `hooks.ts`, or in a file of a `hooks/` folder, wherever that file or folder stands: `uikit/hooks.ts`, `blocks/shared/hooks.ts`, `blocks/shared/hooks/garden.ts`. The linter's rules of hooks and React Compiler's rules find hooks by these files, so a hook in any other module goes unchecked.

## Reference component

```tsx
Expand Down
14 changes: 11 additions & 3 deletions skills/storybook/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const Disabled: Story = {

- **`component` comes first when the component takes props alone:** the renderer renders it from args, and a story that only picks args is `{}` or `{ args }`. A complex example, such as a composition, gets a `render` instead, and so does a nanoviews component with children, which are not props there.
- **`args` give every arg its default,** so each story starts from a complete set and changes only what it is about.
- **`argTypes` give a control to every arg worth playing with,** and the arg goes into the component as it is: `select` (or `inline-radio` for two or three values) with `options` for a union, `boolean`, `text`, `number`, `range` with `min`, `max` and `step`, `object`. The `options` come from a typed constant, the one the component exports (`icons`) or one at the top of the module (`TONES`), never an inline list that drifts from the type. A "none" option maps to `undefined` through `mapping`, or the arg defaults to `null`.
- **`argTypes` give a control to every arg worth playing with,** and the arg goes into the component as it is: `select` (or `inline-radio` for two or three values) with `options` for a union, `boolean`, `text`, `number`, `range` with `min`, `max` and `step`, `object`. The `options` are written inline, `['sm', 'md', 'lg']`, beside the control they feed, where a glance checks them against the type; a list too long to read there, such as every icon, comes from the typed constant the component exports (`icons`). A "none" option maps to `undefined` through `mapping`, or the arg defaults to `null`.
- **`parameters.controls.exclude`** hides a control that does nothing in a given story.
- **`parameters.layout`:** `centered` for controls and widgets, which is most of the UI kit; `padded`, the default, for what spans a column, such as a page header or a list; `fullscreen` for what sets its own width and margins in the app: pages, app shells, a block shown inside the app frame.
- **The typing of `meta` is the framework skill's business:** `satisfies Meta<typeof IconButton>` above, `Meta<Args>` where the renderer can't infer the args from the component. Always `export default meta` and `type Story = StoryObj<typeof meta>`.
Expand Down Expand Up @@ -345,7 +345,9 @@ export function withApp({

## Stories in tests

Stories have no `play` functions: behavior is asserted in `*.spec.ts` by the `unit-tests` conventions. A spec that needs the setup a story already has renders the composed story instead of building the view again. The story comes with its args and decorators, and the test passes the args it drives.
A story's `play` brings it into the state it shows, the way a person gets there: it opens a dialog or a menu, types, submits, presses Escape. A state the story can reach through its args, its decorator or its mock data takes that instead, and a play is left for what only input reaches. A play asserts nothing: a check there runs only where someone opens the story. Behavior is asserted in `*.spec.ts` by the `unit-tests` conventions.

A spec that needs the setup a story already has renders the composed story instead of building the view again. The story comes with its args and decorators, and the test passes the args it drives. `run()` renders it and plays its `play`, so a spec checks the state the story shows without driving the input twice.

```ts
// if.spec.ts
Expand All @@ -354,8 +356,14 @@ import * as Stories from './if.stories'

const {
StaticValue,
ReactiveValue
ReactiveValue,
Opened
} = composeStories(Stories)

it('should trap focus in the opened dialog', async () => {
await Opened.run()
// ...
})
```

## Light and dark theme
Expand Down