@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 CHANGED
@@ -1,141 +1,228 @@
1
1
  # LCT Africa UI Library
2
2
 
3
- ## This is an internal UI component library for **LCT Africa**, built with **React**, **TypeScript**, and **Vite**. It provides reusable, consistent, and tested UI components for use across LCT Africa’s frontend projects.
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
- ## Project Structure
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 or yarn
10
+ - npm
25
11
 
26
- ### Installation
12
+ Install dependencies
27
13
 
28
14
  ```bash
29
15
  npm install
30
- # or
31
- yarn install
32
16
  ```
33
17
 
34
- ### Development
18
+ Development
35
19
 
36
- Start the development server with hot module replacement:
20
+ - Storybook (recommended for developing components in isolation):
37
21
 
38
22
  ```bash
39
- npm run dev
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
- ## Linting
40
+ - Run tests once (CI):
57
41
 
58
- This project uses **ESLint** with recommended **TypeScript** and **React** rules.
42
+ ```bash
43
+ npm run test:no-watch
44
+ ```
59
45
 
60
- You can expand the ESLint configuration for type-aware or React-specific lint rules. For example:
46
+ Linting & Typecheck
61
47
 
62
48
  ```bash
63
- npm install --save-dev eslint-plugin-react-x eslint-plugin-react-dom
49
+ npm run lint
50
+ npm run typecheck
64
51
  ```
65
52
 
66
- Check `eslint.config.js` for comments on stricter or stylistic rules.
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
- ## Testing
61
+ ## Project layout
71
62
 
72
- Example tests are located alongside components, e.g.:
63
+ Typical files and folders:
73
64
 
74
65
  ```
75
- src/components/ui/button/Button.test.tsx
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
- Run tests with:
81
+ Build output
79
82
 
80
- ```bash
81
- npm run test
82
- # or
83
- yarn test
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
- ## Storybook
117
+ ### Naming conventions
89
118
 
90
- Component stories are located in:
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/Button.stories.tsx
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
- Run Storybook:
131
+ - Utility files (helpers, formatters, small libraries) should be kebab-case filenames. Example:
97
132
 
98
- ```bash
99
- npm run storybook
100
- # or
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
- ## Project Highlights
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
- - **React + TypeScript:** Modern, type-safe UI development
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
- ## Contributing
155
+ - Utility constants: use ALL_CAPS with underscores. Example:
117
156
 
118
- 1. Fork the repository
119
- 2. Create your feature branch:
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
- git checkout -b feature/YourFeature
180
+ npm install @lctafrica/ui
123
181
  ```
124
182
 
125
- 3. Commit your changes:
183
+ Then import components and styles in your application:
126
184
 
127
- ```bash
128
- git commit -am "Add some feature"
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
- 4. Push to your branch:
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
- git push origin feature/YourFeature
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
- 5. Open a pull request
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
- > **Note:** This library is intended for internal use within LCT Africa projects only.
226
+ This library is intended for internal use within LCT Africa projects.
140
227
 
141
228
  ---