@lctafrica/ui 1.1.4 → 1.1.5
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 +161 -74
- package/dist/index.css +1 -1
- package/dist/index.js +11 -11
- package/package.json +1 -2
- package/dist/lib/utils.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,141 +1,228 @@
|
|
|
1
1
|
# LCT Africa UI Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This repository contains the internal UI component library for LCT Africa. It is built with React, TypeScript and Vite and is intended to provide reusable, tested, and consistently styled UI components for LCT Africa frontend projects.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quickstart
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
src/
|
|
9
|
-
components/
|
|
10
|
-
ui/
|
|
11
|
-
button/
|
|
12
|
-
Button.tsx
|
|
13
|
-
Button.stories.tsx
|
|
14
|
-
Button.test.tsx
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Getting Started
|
|
20
|
-
|
|
21
|
-
### Prerequisites
|
|
7
|
+
Prerequisites
|
|
22
8
|
|
|
23
9
|
- Node.js v18+ (recommended)
|
|
24
|
-
- npm
|
|
10
|
+
- npm
|
|
25
11
|
|
|
26
|
-
|
|
12
|
+
Install dependencies
|
|
27
13
|
|
|
28
14
|
```bash
|
|
29
15
|
npm install
|
|
30
|
-
# or
|
|
31
|
-
yarn install
|
|
32
16
|
```
|
|
33
17
|
|
|
34
|
-
|
|
18
|
+
Development
|
|
35
19
|
|
|
36
|
-
|
|
20
|
+
- Storybook (recommended for developing components in isolation):
|
|
37
21
|
|
|
38
22
|
```bash
|
|
39
|
-
npm run
|
|
40
|
-
# or
|
|
41
|
-
yarn dev
|
|
23
|
+
npm run storybook
|
|
42
24
|
```
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Building for Production
|
|
26
|
+
Build (production)
|
|
47
27
|
|
|
48
28
|
```bash
|
|
49
29
|
npm run build
|
|
50
|
-
# or
|
|
51
|
-
yarn build
|
|
52
30
|
```
|
|
53
31
|
|
|
54
|
-
|
|
32
|
+
Testing
|
|
33
|
+
|
|
34
|
+
- Run tests (watch mode):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm run test
|
|
38
|
+
```
|
|
55
39
|
|
|
56
|
-
|
|
40
|
+
- Run tests once (CI):
|
|
57
41
|
|
|
58
|
-
|
|
42
|
+
```bash
|
|
43
|
+
npm run test:no-watch
|
|
44
|
+
```
|
|
59
45
|
|
|
60
|
-
|
|
46
|
+
Linting & Typecheck
|
|
61
47
|
|
|
62
48
|
```bash
|
|
63
|
-
npm
|
|
49
|
+
npm run lint
|
|
50
|
+
npm run typecheck
|
|
64
51
|
```
|
|
65
52
|
|
|
66
|
-
|
|
53
|
+
Release / Publish
|
|
67
54
|
|
|
68
|
-
|
|
55
|
+
The `release` script builds the package and publishes to the configured npm registry. Ensure the package `version` is updated before publishing.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run release
|
|
59
|
+
```
|
|
69
60
|
|
|
70
|
-
##
|
|
61
|
+
## Project layout
|
|
71
62
|
|
|
72
|
-
|
|
63
|
+
Typical files and folders:
|
|
73
64
|
|
|
74
65
|
```
|
|
75
|
-
src/
|
|
66
|
+
src/
|
|
67
|
+
index.ts # library entry (re-exports public API from components)
|
|
68
|
+
styles.css # exported global styles
|
|
69
|
+
components/
|
|
70
|
+
ui/ # all components live here, each colocated with stories/tests
|
|
71
|
+
button/
|
|
72
|
+
Button.tsx
|
|
73
|
+
index.ts # barrel export for the component (re-exports public API)
|
|
74
|
+
Button.stories.tsx
|
|
75
|
+
Button.test.tsx
|
|
76
|
+
vitest.setup.ts # test setup for vitest
|
|
77
|
+
vite.config.ts # build + dts + test config
|
|
78
|
+
tsconfig.app.json
|
|
76
79
|
```
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
Build output
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
- The built package is emitted to `dist/` and includes:
|
|
84
|
+
- `index.js` (ES module)
|
|
85
|
+
- `index.d.ts` (types)
|
|
86
|
+
- `index.css` (compiled CSS exported as `styles.css`)
|
|
87
|
+
|
|
88
|
+
Module exports are configured in `package.json` so consumers can import the package as `@lctafrica/ui` and the stylesheet as `@lctafrica/ui/styles.css`.
|
|
89
|
+
|
|
90
|
+
## Conventions & patterns
|
|
91
|
+
|
|
92
|
+
- Components are colocated with their stories and tests under `src/components/ui/`.
|
|
93
|
+
- Stories: Storybook is the canonical environment for browsing and developing components in isolation.
|
|
94
|
+
- Tests: Vitest + Testing Library are used for unit/interaction tests. `vitest.setup.ts` configures globals and test environment.
|
|
95
|
+
- Styling: Tailwind CSS is used along with utility helpers (e.g., `class-variance-authority`, `tailwind-merge`). Import the package stylesheet in consumers to get base styles.
|
|
96
|
+
- Accessibility: We use Radix primitives for some components; follow Radix guidance (e.g., provide `DialogTitle` / `Dialog.Description` when using `DialogContent`).
|
|
97
|
+
- Types: Type declarations are produced and emitted to `dist/` by the build pipeline.
|
|
98
|
+
|
|
99
|
+
- Component folder convention: each component lives in its own folder and includes the implementation, a component-level `index.ts` that re-exports the component's public API (barrel export), a story (`*.stories.*`) and tests (`*.test.*`). Example:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
src/components/ui/button/
|
|
103
|
+
Button.tsx
|
|
104
|
+
index.ts # re-exports `Button` and related types
|
|
105
|
+
Button.stories.tsx
|
|
106
|
+
Button.test.tsx
|
|
84
107
|
```
|
|
85
108
|
|
|
86
|
-
|
|
109
|
+
- Barrel export pattern: every component provides a small `index.ts` (barrel) that re-exports its public symbols. The library root `src/index.ts` then re-exports all components and utilities, creating a single public surface. This allows consumers to import from `@lctafrica/ui`:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { Button } from "@lctafrica/ui";
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- All public exports are unified at `src/index.ts` so consumers do not need to import deep paths.
|
|
87
116
|
|
|
88
|
-
|
|
117
|
+
### Naming conventions
|
|
89
118
|
|
|
90
|
-
Component
|
|
119
|
+
- Component folder names: kebab-case. Example: `my-button/`, `date-picker/`.
|
|
120
|
+
|
|
121
|
+
- Component, story and test filenames: PascalCase. Example:
|
|
91
122
|
|
|
92
123
|
```
|
|
93
|
-
src/components/ui/button/
|
|
124
|
+
src/components/ui/my-button/
|
|
125
|
+
MyButton.tsx
|
|
126
|
+
MyButton.stories.tsx
|
|
127
|
+
MyButton.test.tsx
|
|
128
|
+
index.ts
|
|
94
129
|
```
|
|
95
130
|
|
|
96
|
-
|
|
131
|
+
- Utility files (helpers, formatters, small libraries) should be kebab-case filenames. Example:
|
|
97
132
|
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
yarn storybook
|
|
133
|
+
```
|
|
134
|
+
src/lib/format-date.ts
|
|
135
|
+
src/lib/validate-url.ts
|
|
102
136
|
```
|
|
103
137
|
|
|
104
|
-
|
|
138
|
+
- Component names: PascalCase and implemented as React functional components using the `function` keyword (not `const` with arrow functions). Example:
|
|
105
139
|
|
|
106
|
-
|
|
140
|
+
```tsx
|
|
141
|
+
// src/components/ui/my-button/MyButton.tsx
|
|
142
|
+
export function MyButton(props: MyButtonProps) {
|
|
143
|
+
return <button {...props}>Click</button>;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
107
146
|
|
|
108
|
-
-
|
|
109
|
-
- **Vite:** Fast build and dev server
|
|
110
|
-
- **Component-driven:** UI components organized under `ui`
|
|
111
|
-
- **Testing:** Example tests using Vitest
|
|
112
|
-
- **ESLint:** Ensures code quality and consistency
|
|
147
|
+
- Exports: components must use named exports (the `export` keyword). Do not use default exports. Example barrel `index.ts` for the component:
|
|
113
148
|
|
|
114
|
-
|
|
149
|
+
```ts
|
|
150
|
+
// src/components/ui/my-button/index.ts
|
|
151
|
+
export { MyButton } from "./MyButton";
|
|
152
|
+
export type { MyButtonProps } from "./MyButton";
|
|
153
|
+
```
|
|
115
154
|
|
|
116
|
-
|
|
155
|
+
- Utility constants: use ALL_CAPS with underscores. Example:
|
|
117
156
|
|
|
118
|
-
|
|
119
|
-
|
|
157
|
+
```ts
|
|
158
|
+
export const API_TIMEOUT_MS = 5000;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- Rationale: these conventions improve discoverability, consistent import paths, and make automated refactors and code generation simpler.
|
|
162
|
+
|
|
163
|
+
## Scripts (available)
|
|
164
|
+
|
|
165
|
+
- `build` — `tsc -b && vite build` — build JS, CSS and types
|
|
166
|
+
- `lint` — run ESLint across the codebase
|
|
167
|
+
- `test` — `vitest` (watch by default)
|
|
168
|
+
- `test:no-watch` — `vitest run` (single run, for CI)
|
|
169
|
+
- `storybook` — start Storybook (dev)
|
|
170
|
+
- `build-storybook` — build Storybook static site
|
|
171
|
+
- `prepare` — `husky` (installs Git hooks)
|
|
172
|
+
- `release` — builds and publishes the package
|
|
173
|
+
- `typecheck` — `tsc -b --noEmit` (strict type checking)
|
|
174
|
+
|
|
175
|
+
## How to consume
|
|
176
|
+
|
|
177
|
+
Install the package as a dependency in your app (internal registry or from npm if published):
|
|
120
178
|
|
|
121
179
|
```bash
|
|
122
|
-
|
|
180
|
+
npm install @lctafrica/ui
|
|
123
181
|
```
|
|
124
182
|
|
|
125
|
-
|
|
183
|
+
Then import components and styles in your application:
|
|
126
184
|
|
|
127
|
-
```
|
|
128
|
-
|
|
185
|
+
```tsx
|
|
186
|
+
import React from "react";
|
|
187
|
+
import { Button } from "@lctafrica/ui";
|
|
188
|
+
import "@lctafrica/ui/styles.css";
|
|
189
|
+
|
|
190
|
+
export default function App() {
|
|
191
|
+
return <Button>Click me</Button>;
|
|
192
|
+
}
|
|
129
193
|
```
|
|
130
194
|
|
|
131
|
-
|
|
195
|
+
Note: `react` and `react-dom` are peer dependencies and must be provided by the consumer (React 18+).
|
|
196
|
+
|
|
197
|
+
## CI / Recommended checks
|
|
198
|
+
|
|
199
|
+
Typical CI steps:
|
|
132
200
|
|
|
133
201
|
```bash
|
|
134
|
-
|
|
202
|
+
npm ci
|
|
203
|
+
npm run lint
|
|
204
|
+
npm run typecheck
|
|
205
|
+
npm run test:no-watch
|
|
206
|
+
npm run build
|
|
135
207
|
```
|
|
136
208
|
|
|
137
|
-
|
|
209
|
+
## Developer tooling
|
|
210
|
+
|
|
211
|
+
- Formatting: `prettier` (configured via `lint-staged`)
|
|
212
|
+
- Linting: `eslint` with TypeScript and React rules
|
|
213
|
+
- Pre-commit: Husky + lint-staged run formatting and ESLint fixes on staged files
|
|
214
|
+
|
|
215
|
+
## Troubleshooting & notes
|
|
216
|
+
|
|
217
|
+
- If you see Radix warnings like "`DialogContent` requires a `DialogTitle`", add a `DialogTitle` or wrap it with a visually-hidden title to meet accessibility requirements.
|
|
218
|
+
- This repo does not ship React itself — make sure the consuming app provides `react`/`react-dom` matching the peer dependency range.
|
|
219
|
+
|
|
220
|
+
## Contributing
|
|
221
|
+
|
|
222
|
+
1. Clone the repo and create a feature branch from dev branch: `git checkout -b feature/your-feature`
|
|
223
|
+
2. Add tests and stories for UI work
|
|
224
|
+
3. Run `npm run lint`, `npm run typecheck`, and `npm run test` before opening a PR
|
|
138
225
|
|
|
139
|
-
|
|
226
|
+
This library is intended for internal use within LCT Africa projects.
|
|
140
227
|
|
|
141
228
|
---
|