@veevarts/design-system 0.0.2 → 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 CHANGED
@@ -2,276 +2,70 @@
2
2
 
3
3
  This repository contains our **Design System**: a shared library of reusable UI components, design tokens, and utilities built with **React**, **TypeScript**, **Vite**, and **Storybook**.
4
4
 
5
- The goal of this project is to provide:
5
+ ## Goals
6
6
 
7
7
  - A **single source of truth** for UI across products.
8
8
  - **Reusable, well-typed, accessible components**.
9
9
  - **Discoverable documentation** via Storybook.
10
10
 
11
- ---
12
-
13
11
  ## Tech Stack
14
12
 
15
- - **React + TypeScript** – Component library implementation.
16
- - **Vite** – Fast dev server and build tooling.
17
- - **Storybook** – Component explorer and documentation.
18
- - **ESLint + TypeScript ESLint** – Linting and type-aware rules.
19
- - (Optional) **React Compiler** – Can be enabled if needed (see note below).
20
-
21
- ---
13
+ - React + TypeScript
14
+ - Vite
15
+ - Storybook
16
+ - ESLint + TypeScript ESLint
22
17
 
23
18
  ## Getting Started
24
19
 
25
20
  ### Prerequisites
26
21
 
27
22
  - Node.js (LTS, e.g. 18+ recommended)
28
- - pnpm / npm / yarn (examples below use `npm`)
23
+ - npm / pnpm / yarn
29
24
 
30
- ### Install dependencies
25
+ ### Install
31
26
 
32
27
  ```bash
33
28
  npm install
34
29
  ```
35
30
 
36
- ### Run Storybook (recommended entrypoint)
31
+ ### Run Storybook
32
+
37
33
  ```bash
38
34
  npm run storybook
39
35
  ```
40
36
 
41
- This starts Storybook at http://localhost:6006 (or the configured port), where you can browse and interact with all components.
37
+ ### Run Dev Server
42
38
 
43
- ### Run the Vite dev server (if applicable)
44
-
45
- If this repo also includes a small playground app:
46
39
  ```bash
47
40
  npm run dev
48
41
  ```
49
42
 
50
- This will start the Vite dev server (usually at http://localhost:5173).
51
-
52
43
  ### Build
53
44
 
54
- Build the component library / app:
55
45
  ```bash
56
46
  npm run build
57
47
  ```
58
- Build the Storybook static site (for deployment):
59
- ```bash
60
- npm run build-storybook
61
- ```
62
- npm run build-storybook
63
- ```bash
64
- npm run build-storybook
65
- ```
48
+
66
49
  ### Lint
50
+
67
51
  ```bash
68
52
  npm run lint
69
53
  ```
70
54
 
71
- ## Project Structure (suggested)
55
+ ## Project Structure
72
56
 
73
- Your structure may vary slightly, but the Design System generally follows:
74
57
  ```
75
58
  src/
76
59
  components/
77
- Button/
78
- Button.tsx
79
- Button.types.ts
80
- Button.stories.tsx
81
- Button.test.tsx # if using tests
82
- index.ts
83
- Input/
84
- ...
85
60
  styles/
86
- tokens.css # or tokens.ts, etc.
87
61
  utils/
88
- ...
89
62
  .storybook/
90
- main.ts
91
- preview.tsx
92
63
  ```
93
64
 
94
- ## Creating a New Reusable Component
95
-
96
- When adding a new component to the Design System, follow these steps:
97
- 1. Create a folder under src/components
98
-
99
- Example: src/components/Button.
100
-
101
- 2. Create the component file
102
- - Use TypeScript and function components.
103
- - Export a named component and a typed props interface.
104
-
105
- ```tsx
106
- // src/components/Button/Button.tsx
107
- import type { ButtonHTMLAttributes, ReactNode } from 'react';
108
-
109
- export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
110
- variant?: 'primary' | 'secondary' | 'ghost';
111
- size?: 'sm' | 'md' | 'lg';
112
- isLoading?: boolean;
113
- children: ReactNode;
114
- }
115
-
116
- export function Button({
117
- variant = 'primary',
118
- size = 'md',
119
- isLoading = false,
120
- children,
121
- ...rest
122
- }: ButtonProps) {
123
- return (
124
- <button
125
- data-variant={variant}
126
- data-size={size}
127
- aria-busy={isLoading || undefined}
128
- {...rest}
129
- >
130
- {isLoading ? 'Loading…' : children}
131
- </button>
132
- );
133
- }
134
- ```
135
- 3. Create an index.ts barrel file
136
-
137
- ```tsx
138
- // src/components/Button/index.ts
139
- export * from './Button';
140
- ```
141
- 4. Create the Storybook stories
142
- - Stories should live next to the component: Button.stories.tsx.
143
- - Use Storybook CSF (default export + named stories).
144
- - Document variants, states, and usage guidelines via args and docs.
145
-
146
- ```tsx
147
- // src/components/Button/Button.stories.tsx
148
- import type { Meta, StoryObj } from '@storybook/react';
149
- import { Button } from './Button';
150
-
151
- const meta: Meta<typeof Button> = {
152
- title: 'Components/Button',
153
- component: Button,
154
- args: {
155
- children: 'Click me',
156
- variant: 'primary',
157
- size: 'md',
158
- },
159
- };
160
-
161
- export default meta;
162
- type Story = StoryObj<typeof Button>;
163
-
164
- export const Primary: Story = {};
165
- export const Secondary: Story = {
166
- args: { variant: 'secondary' },
167
- };
168
- export const Loading: Story = {
169
- args: { isLoading: true },
170
- };
171
- ```
172
-
173
- 5. Add tests
174
- - If the project uses a test runner (e.g. Vitest / Jest), add Button.test.tsx with basic behavior and accessibility tests.
175
-
176
- ## Guidelines & Best Practices for Reusable Components
177
-
178
- 1. Design System Principles
179
- - Generic, not app-specific
180
- Components must not depend on product-specific business logic. Keep them generic and configurable via props.
181
- - Composition over configuration
182
- Prefer small building blocks that can be composed, instead of monolithic components with many boolean flags.
183
- - Single responsibility
184
- Each component should do one thing well (e.g. Button, Input, Modal, Tooltip).
185
- - Stable API
186
- Avoid frequent breaking changes to props. If a change is necessary, deprecate carefully and communicate it.
187
-
188
- 2. TypeScript & Props
189
- - Always export a typed props interface (ButtonProps, ModalProps, etc.).
190
- - Follow these patterns:
191
- - Use union types for variants ('primary' | 'secondary').
192
- - Prefer explicit props over any and broad object types.
193
- - Extend native HTML attributes when appropriate (e.g. ButtonHTMLAttributes<HTMLButtonElement>).
194
- - Provide sensible defaults for optional props.
195
-
196
- 3. Styling & Theming
197
- - Use design tokens (colors, spacing, typography) instead of hard-coded values.
198
- - Keep component styling encapsulated and consistent:
199
- - Prefer using a shared tokens/styles system.
200
- - Avoid importing product-specific styles into the Design System.
201
- - Support variants and sizes through props, not through ad-hoc CSS classes.
202
-
203
- 4. Accessibility (a11y)
204
-
205
- Every component should be built with accessibility in mind:
206
- - Ensure correct semantic elements (<button>, <label>, <input> etc.).
207
- - Use ARIA attributes only when necessary and correctly (avoid misusing them).
208
- - Keyboard support:
209
- - Focus states must be visible.
210
- - Interactive elements must be reachable and operable via keyboard.
211
- - Test with screen reader basics when possible (labels, roles, and announcements).
212
-
213
- 5. Storybook Best Practices
214
-
215
- Stories are documentation, not just demos:
216
- - Provide a “Default” story that shows the most common usage.
217
- - Include stories for:
218
- - Different variants and sizes.
219
- - Loading / disabled / error states.
220
- - Edge cases that are relevant for consumers.
221
- - Use args so consumers can experiment via Storybook controls.
222
- - Use Storybook Docs to write short guidelines:
223
- - When to use the component.
224
- - Do’s & Don’ts.
225
- - Example integration snippets.
226
-
227
- 6. Dependencies & Side Effects
228
- - Keep dependencies minimal and generic.
229
- - Avoid:
230
- - Direct calls to APIs.
231
- - Global singletons (e.g. accessing window without guards, global stores).
232
- - Side effects in component bodies (data fetching, logging, etc.).
233
- - If integration with external libraries is needed, wrap them in thin, replaceable adapters.
234
-
235
- ## Linting & Type-Aware Rules
236
-
237
- For production-grade usage, we recommend enabling type-aware ESLint rules. A sample configuration using eslint.config.js might look like this:
65
+ ## Usage Example
238
66
 
239
67
  ```js
240
- // eslint.config.js
241
- import tseslint from 'typescript-eslint';
242
- import reactX from 'eslint-plugin-react-x';
243
- import reactDom from 'eslint-plugin-react-dom';
244
-
245
- export default defineConfig([
246
- globalIgnores(['dist']),
247
- {
248
- files: ['**/*.{ts,tsx}'],
249
- extends: [
250
- // Type-aware TypeScript rules
251
- tseslint.configs.recommendedTypeChecked,
252
- // Alternatively, stricter rules:
253
- // tseslint.configs.strictTypeChecked,
254
- // Optional stylistic rules:
255
- // tseslint.configs.stylisticTypeChecked,
256
-
257
- // React-specific rules
258
- reactX.configs['recommended-typescript'],
259
- reactDom.configs.recommended,
260
- ],
261
- languageOptions: {
262
- parserOptions: {
263
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
264
- tsconfigRootDir: import.meta.dirname,
265
- },
266
- },
267
- },
268
- ]);
68
+ import { Button } from '@veevarts/design-system';
269
69
  ```
270
- Run npm run lint regularly, and ensure no new warnings or errors are introduced in pull requests.
271
70
 
272
- ## Contributing
273
- - Before coding: Check if a similar component already exists or if an existing one can be extended.
274
- - Follow the guidelines above (types, a11y, tokens, stories).
275
- - Add or update stories so that your changes are visible in Storybook.
276
- - Run npm run lint and npm run test (if available) before opening a PR.
277
- - Keep PRs small and focused (one component or one concern per PR where possible).
71
+ For contributing guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md).