@varialkit/core 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/README.md +163 -0
- package/package.json +22 -0
- package/src/index.ts +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Core Package
|
|
2
|
+
|
|
3
|
+
This package is the anchor for Solara UI primitives and shared frontend utilities.
|
|
4
|
+
Today the actual UI components live under `packages/core/components/*` (each as its own publishable package), and the website app consumes those component packages directly.
|
|
5
|
+
|
|
6
|
+
The core package itself (`@solara/core`) is currently minimal, but the directory structure and tooling are set up so the component library can expand without changing the website integration model.
|
|
7
|
+
|
|
8
|
+
## How Core Fits In The Repo
|
|
9
|
+
|
|
10
|
+
High level flow:
|
|
11
|
+
|
|
12
|
+
1. UI components are implemented as individual packages under `packages/core/components/<component>`.
|
|
13
|
+
2. Each component package exports its React component from `src/index.ts` and exports stories from `examples/index.tsx` via a `./examples` subpath.
|
|
14
|
+
3. The website app (`apps/website`) consumes component packages by name (`@solara/button`) and loads story modules through the `./examples` export.
|
|
15
|
+
4. Local sync mode can alias package imports to local source for instant iteration, while npm artifact mode simulates production resolution.
|
|
16
|
+
|
|
17
|
+
This keeps the website app decoupled from the component source tree while still enabling fast local iteration.
|
|
18
|
+
|
|
19
|
+
## Current Component Library Structure
|
|
20
|
+
|
|
21
|
+
The canonical component package example is `packages/core/components/button`.
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
packages/core/components/button/
|
|
25
|
+
├── examples/ # Story definitions and preview helpers
|
|
26
|
+
│ ├── index.tsx # Stories manifest (exported via ./examples)
|
|
27
|
+
│ ├── overview.tsx # Story render helper
|
|
28
|
+
│ └── variants.tsx # Story render helper
|
|
29
|
+
├── src/ # Component source
|
|
30
|
+
│ ├── Button.tsx
|
|
31
|
+
│ └── index.ts
|
|
32
|
+
├── docs.md # Package notes for contributors (site docs live in apps/website)
|
|
33
|
+
└── package.json # Package entrypoints and exports
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Key conventions:
|
|
37
|
+
|
|
38
|
+
- `src/index.ts` exports the component API (`export { Button } from "./Button"`).
|
|
39
|
+
- `examples/index.tsx` exports a `stories` object with metadata, render functions, and optional prop controls.
|
|
40
|
+
- `docs.md` is a package-local README for contributors.
|
|
41
|
+
- `package.json` exposes `./examples` so the website can import `@solara/button/examples` without touching internal file paths.
|
|
42
|
+
|
|
43
|
+
## How The Website Uses Core Components
|
|
44
|
+
|
|
45
|
+
The website app is a Next.js App Router project at `apps/website`.
|
|
46
|
+
For component routes (`/components/<slug>`), the server component page fetches metadata and guidelines, and a client component renders the stories.
|
|
47
|
+
|
|
48
|
+
Runtime flow for a component page:
|
|
49
|
+
|
|
50
|
+
1. The route `/components/button` resolves to `apps/website/app/(main)/components/[slug]/page.tsx`.
|
|
51
|
+
2. The page reads component metadata from `apps/website/lib/components.json` and guidelines from `apps/website/app/(main)/components/_docs/<slug>.mdx`.
|
|
52
|
+
- Guidelines are MDX so the docs can use columns, figures, and custom layouts without coupling to package files.
|
|
53
|
+
3. The Demo tab renders `apps/website/app/components/ComponentStories/index.tsx`.
|
|
54
|
+
4. `ComponentStories` calls `loadComponentStories` (from `apps/website/lib/component-stories.ts`), which delegates to the centralized loader registry at `apps/website/app/(main)/components/_stories/index.ts`.
|
|
55
|
+
5. The loader registry imports `@solara/button/examples`, reads the `stories` export (or legacy `examples`), and returns a normalized `stories` object to the demo UI.
|
|
56
|
+
6. Each story has a localized props panel (RightPanel `story` variant) so adjustments are scoped to that story only. All stories should expose their full prop surface in the Props tab, not just the overview/primary example.
|
|
57
|
+
|
|
58
|
+
The only requirement for a component to appear on the website is:
|
|
59
|
+
|
|
60
|
+
- The component is listed in `apps/website/lib/components.json`.
|
|
61
|
+
- The story loader registry in `apps/website/app/(main)/components/_stories/index.ts` has an entry for the component slug.
|
|
62
|
+
- The component package exports `./examples`.
|
|
63
|
+
- The website includes a matching MDX guidelines file (or gracefully falls back).
|
|
64
|
+
- Any doc imagery lives in `apps/website/public/components/<slug>` and is referenced with `/components/<slug>/...` paths.
|
|
65
|
+
|
|
66
|
+
## Component Guidelines Workflow (MDX)
|
|
67
|
+
|
|
68
|
+
Guidelines are authored in the app (not in the package) so they can use rich layouts and images without coupling package
|
|
69
|
+
artifacts to site content.
|
|
70
|
+
|
|
71
|
+
Authoring locations:
|
|
72
|
+
|
|
73
|
+
- MDX doc: `apps/website/app/(main)/components/_docs/<slug>.mdx`
|
|
74
|
+
- Doc loader map: `apps/website/app/(main)/components/_docs/index.ts`
|
|
75
|
+
- Shared MDX components: `apps/website/mdx-components.tsx`
|
|
76
|
+
- MDX UI primitives: `apps/website/app/components/Docs/*`
|
|
77
|
+
- Assets: `apps/website/public/components/<slug>/*` (referenced as `/components/<slug>/...`)
|
|
78
|
+
|
|
79
|
+
## Local Sync vs npm Artifact Mode
|
|
80
|
+
|
|
81
|
+
Local iteration uses the same import paths as production (`@solara/*`) but resolves them differently depending on the mode.
|
|
82
|
+
|
|
83
|
+
- npm artifact mode (`pnpm dev`): package imports resolve normally, simulating published packages.
|
|
84
|
+
- local sync mode (`pnpm dev:local` or `pnpm dev:local:components`): the website aliases `@solara/*` to local source paths for rapid iteration.
|
|
85
|
+
|
|
86
|
+
This behavior is wired through:
|
|
87
|
+
|
|
88
|
+
- `apps/website/lib/package-aliases.mjs`
|
|
89
|
+
- `apps/website/next.config.mjs`
|
|
90
|
+
|
|
91
|
+
## Story Contract
|
|
92
|
+
|
|
93
|
+
Stories are the integration contract between component packages and the website demo UI.
|
|
94
|
+
Each story entry includes:
|
|
95
|
+
|
|
96
|
+
- `title`: label displayed in the demo UI
|
|
97
|
+
- `description` (optional): short context text
|
|
98
|
+
- `render`: function that receives props and returns a React element
|
|
99
|
+
- `controls` (optional): list of prop controls for the localized props panel. Prefer defining controls for every story so each example is adjustable in place.
|
|
100
|
+
- `initialProps` (optional): initial values for those controls
|
|
101
|
+
|
|
102
|
+
Example shape:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
export const stories = {
|
|
106
|
+
playground: {
|
|
107
|
+
title: "Playground",
|
|
108
|
+
render: (props) => <Button {...props} />,
|
|
109
|
+
controls: [{ name: "variant", type: "select", options: ["default", "primary"] }],
|
|
110
|
+
initialProps: { variant: "primary" }
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The website reads this object and renders each story card in the Demo tab. Code snippets shown in the Code tab should include any `const` setup logic required for the example, not just the JSX, so the snippet is copy/paste-ready.
|
|
116
|
+
The preview frame background can be adjusted via the CSS variable `--story-preview-background` in `apps/website/app/globals.scss` if a component needs more contrast.
|
|
117
|
+
|
|
118
|
+
## Current Component Library
|
|
119
|
+
|
|
120
|
+
The following components are currently available in the Solara design system:
|
|
121
|
+
|
|
122
|
+
- **Button**: A versatile button component for user actions.
|
|
123
|
+
- **TextField**: A text field for single-line input.
|
|
124
|
+
- **TextArea**: A text area for multi-line input.
|
|
125
|
+
- **Dropdown**: A dropdown for selecting from a list of options.
|
|
126
|
+
- **Avatar**: A component for displaying a user's avatar.
|
|
127
|
+
|
|
128
|
+
## How To Add A New Component Package
|
|
129
|
+
|
|
130
|
+
Create a new component under `packages/core/components/<component>` and then wire it into the website.
|
|
131
|
+
|
|
132
|
+
1. Scaffold the package:
|
|
133
|
+
- `src/<Component>.tsx`
|
|
134
|
+
- `src/index.ts`
|
|
135
|
+
- `examples/index.tsx`
|
|
136
|
+
- `docs.md` (package notes for contributors)
|
|
137
|
+
- `package.json` (with `./examples` export)
|
|
138
|
+
|
|
139
|
+
2. Export the component API from `src/index.ts`.
|
|
140
|
+
|
|
141
|
+
3. Define a `stories` object in `examples/index.tsx`.
|
|
142
|
+
|
|
143
|
+
4. Add the component metadata to `apps/website/lib/components.json`.
|
|
144
|
+
|
|
145
|
+
5. Add a loader entry in `apps/website/app/(main)/components/_stories/index.ts`.
|
|
146
|
+
|
|
147
|
+
6. Add a guidelines doc at `apps/website/app/(main)/components/_docs/<slug>.mdx`.
|
|
148
|
+
- Use `Columns`, `Column`, and `Figure` from `apps/website/mdx-components.tsx` for richer layouts.
|
|
149
|
+
- Keep package notes in `packages/core/components/<slug>/docs.md` for contributors.
|
|
150
|
+
|
|
151
|
+
7. Register the MDX file in `apps/website/app/(main)/components/_docs/index.ts`.
|
|
152
|
+
|
|
153
|
+
8. Add any guideline imagery to `apps/website/public/components/<slug>`.
|
|
154
|
+
|
|
155
|
+
9. Verify the new route under `/components/<slug>` in the website.
|
|
156
|
+
|
|
157
|
+
This keeps the component source colocated with its stories and package notes, while the website owns rich guidelines content.
|
|
158
|
+
|
|
159
|
+
## Where This Is Headed
|
|
160
|
+
|
|
161
|
+
The core package is intentionally minimal today.
|
|
162
|
+
As the component library grows, `@solara/core` can become the host for shared hooks, providers, or tokens that are not tied to a single component package.
|
|
163
|
+
The current structure is already compatible with that growth without changing the website integration model.
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@varialkit/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@testing-library/react": "^16.0.0",
|
|
15
|
+
"@types/jest": "^29.5.12",
|
|
16
|
+
"@types/react": "19.0.10",
|
|
17
|
+
"@types/react-dom": "19.0.4",
|
|
18
|
+
"@types/testing-library__react": "^10.2.0",
|
|
19
|
+
"jest": "^29.7.0",
|
|
20
|
+
"ts-jest": "^29.1.4"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
ADDED