@mohammadsalman/storybook-custom-ui 1.0.0 → 1.0.2
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 +60 -176
- package/dist/assets/index-BWMuc5b_.js +9 -0
- package/dist/assets/index-COcDBgFa.css +1 -0
- package/dist/assets/react-CHdo91hT.svg +1 -0
- package/dist/index.html +14 -0
- package/dist/vite.svg +1 -0
- package/package.json +50 -39
- package/src/components/Button/Button.stories.tsx +0 -109
- package/src/components/Button/Button.tsx +0 -144
- package/src/components/Button/index.ts +0 -1
- package/src/components/index.ts +0 -1
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useFormInput.stories.tsx +0 -126
- package/src/hooks/useFormInput.ts +0 -114
- package/src/index.ts +0 -0
- package/src/theme/ThemeProvider.tsx +0 -34
- package/src/theme/defaultTheme.ts +0 -182
- package/src/theme/index.ts +0 -3
- package/src/theme/types.ts +0 -106
- package/src/utils/styles.ts +0 -15
package/README.md
CHANGED
|
@@ -1,189 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- ✅ TypeScript support with full type safety
|
|
10
|
-
- ✅ Theming system that can be adapted to any project
|
|
11
|
-
- ✅ Storybook with interactive controls
|
|
12
|
-
- ✅ Zero external UI library dependencies
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
13
9
|
|
|
14
|
-
##
|
|
10
|
+
## React Compiler
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
npm install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Running Storybook
|
|
14
|
+
## Expanding the ESLint configuration
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
npm run storybook
|
|
26
|
-
```
|
|
16
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
27
17
|
|
|
28
|
-
|
|
18
|
+
```js
|
|
19
|
+
export default defineConfig([
|
|
20
|
+
globalIgnores(['dist']),
|
|
21
|
+
{
|
|
22
|
+
files: ['**/*.{ts,tsx}'],
|
|
23
|
+
extends: [
|
|
24
|
+
// Other configs...
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
+
tseslint.configs.recommendedTypeChecked,
|
|
28
|
+
// Alternatively, use this for stricter rules
|
|
29
|
+
tseslint.configs.strictTypeChecked,
|
|
30
|
+
// Optionally, add this for stylistic rules
|
|
31
|
+
tseslint.configs.stylisticTypeChecked,
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
// Other configs...
|
|
34
|
+
],
|
|
35
|
+
languageOptions: {
|
|
36
|
+
parserOptions: {
|
|
37
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
+
tsconfigRootDir: import.meta.dirname,
|
|
39
|
+
},
|
|
40
|
+
// other options...
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
])
|
|
34
44
|
```
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
}
|
|
46
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// eslint.config.js
|
|
50
|
+
import reactX from 'eslint-plugin-react-x'
|
|
51
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
52
|
+
|
|
53
|
+
export default defineConfig([
|
|
54
|
+
globalIgnores(['dist']),
|
|
55
|
+
{
|
|
56
|
+
files: ['**/*.{ts,tsx}'],
|
|
57
|
+
extends: [
|
|
58
|
+
// Other configs...
|
|
59
|
+
// Enable lint rules for React
|
|
60
|
+
reactX.configs['recommended-typescript'],
|
|
61
|
+
// Enable lint rules for React DOM
|
|
62
|
+
reactDom.configs.recommended,
|
|
63
|
+
],
|
|
64
|
+
languageOptions: {
|
|
65
|
+
parserOptions: {
|
|
66
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
+
tsconfigRootDir: import.meta.dirname,
|
|
68
|
+
},
|
|
69
|
+
// other options...
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
])
|
|
65
73
|
```
|
|
66
|
-
|
|
67
|
-
## Available Components
|
|
68
|
-
|
|
69
|
-
### Button
|
|
70
|
-
|
|
71
|
-
A versatile button component with multiple variants, colors, and sizes.
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
import { Button } from './components';
|
|
75
|
-
|
|
76
|
-
<Button variant="contained" color="primary" size="medium">
|
|
77
|
-
Click Me
|
|
78
|
-
</Button>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
**Props:**
|
|
82
|
-
- `variant`: 'contained' | 'outlined' | 'text'
|
|
83
|
-
- `color`: 'primary' | 'secondary' | 'success' | 'error' | 'warning' | 'info'
|
|
84
|
-
- `size`: 'small' | 'medium' | 'large'
|
|
85
|
-
- `fullWidth`: boolean
|
|
86
|
-
- `disabled`: boolean
|
|
87
|
-
|
|
88
|
-
## Available Hooks
|
|
89
|
-
|
|
90
|
-
### useFormInput
|
|
91
|
-
|
|
92
|
-
A custom hook for managing form input state, validation, and error handling.
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
import { useFormInput } from './hooks';
|
|
96
|
-
|
|
97
|
-
const MyForm = () => {
|
|
98
|
-
const emailInput = useFormInput({
|
|
99
|
-
initialValue: '',
|
|
100
|
-
validate: (value) => {
|
|
101
|
-
if (!value) return 'Email is required';
|
|
102
|
-
if (!/\S+@\S+\.\S+/.test(value)) return 'Invalid email format';
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div>
|
|
109
|
-
<input
|
|
110
|
-
value={emailInput.value}
|
|
111
|
-
onChange={emailInput.onChange}
|
|
112
|
-
onBlur={emailInput.onBlur}
|
|
113
|
-
/>
|
|
114
|
-
{emailInput.error && <span>{emailInput.error}</span>}
|
|
115
|
-
<button onClick={emailInput.reset}>Reset</button>
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
**Options:**
|
|
122
|
-
- `initialValue`: string (default: '')
|
|
123
|
-
- `validate`: (value: string) => string | null
|
|
124
|
-
- `onChange`: (value: string) => void (optional callback)
|
|
125
|
-
|
|
126
|
-
**Returns:**
|
|
127
|
-
- `value`: string
|
|
128
|
-
- `error`: string | null
|
|
129
|
-
- `onChange`: (e: ChangeEvent) => void
|
|
130
|
-
- `onBlur`: () => void
|
|
131
|
-
- `setValue`: (value: string) => void
|
|
132
|
-
- `setError`: (error: string | null) => void
|
|
133
|
-
- `reset`: () => void
|
|
134
|
-
- `isValid`: boolean
|
|
135
|
-
|
|
136
|
-
## Project Structure
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
src/
|
|
140
|
-
├── components/ # UI components
|
|
141
|
-
│ └── Button/
|
|
142
|
-
│ ├── Button.tsx
|
|
143
|
-
│ ├── Button.stories.tsx
|
|
144
|
-
│ └── index.ts
|
|
145
|
-
├── hooks/ # Custom hooks
|
|
146
|
-
│ ├── useFormInput.ts
|
|
147
|
-
│ ├── useFormInput.stories.tsx
|
|
148
|
-
│ └── index.ts
|
|
149
|
-
├── theme/ # Theming system
|
|
150
|
-
│ ├── types.ts
|
|
151
|
-
│ ├── defaultTheme.ts
|
|
152
|
-
│ ├── ThemeProvider.tsx
|
|
153
|
-
│ └── index.ts
|
|
154
|
-
└── utils/ # Utility functions
|
|
155
|
-
└── styles.ts
|
|
156
|
-
.storybook/ # Storybook configuration
|
|
157
|
-
├── main.ts
|
|
158
|
-
├── preview.tsx
|
|
159
|
-
└── global.css
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## Adding New Components
|
|
163
|
-
|
|
164
|
-
To add a new component:
|
|
165
|
-
|
|
166
|
-
1. Create a new directory in `src/components/`
|
|
167
|
-
2. Add your component file (e.g., `MyComponent.tsx`)
|
|
168
|
-
3. Create an `index.ts` file that exports your component
|
|
169
|
-
4. Create a `MyComponent.stories.tsx` file for Storybook
|
|
170
|
-
5. Export from `src/components/index.ts`
|
|
171
|
-
|
|
172
|
-
## Adding New Hooks
|
|
173
|
-
|
|
174
|
-
To add a new hook:
|
|
175
|
-
|
|
176
|
-
1. Create a new file in `src/hooks/` (e.g., `useMyHook.ts`)
|
|
177
|
-
2. Export from `src/hooks/index.ts`
|
|
178
|
-
3. Optionally create a `useMyHook.stories.tsx` file for Storybook
|
|
179
|
-
|
|
180
|
-
## Adapting to Your Project
|
|
181
|
-
|
|
182
|
-
To use these components and hooks in your project:
|
|
183
|
-
|
|
184
|
-
1. Copy the `src/components`, `src/hooks`, `src/theme`, and `src/utils` directories to your project
|
|
185
|
-
2. Create your custom theme based on your design system
|
|
186
|
-
3. Wrap your app with `ThemeProvider` using your custom theme
|
|
187
|
-
4. Import and use components and hooks as needed
|
|
188
|
-
|
|
189
|
-
The theme system is designed to be flexible - you can override any part of it to match your brand colors, typography, spacing, and more.
|