@qlover/create-app 0.6.2 → 0.7.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/templates/react-app/README.en.md +257 -0
  5. package/dist/templates/react-app/README.md +29 -231
  6. package/dist/templates/react-app/__tests__/__mocks__/I18nService.ts +13 -0
  7. package/dist/templates/react-app/__tests__/__mocks__/MockAppConfit.ts +48 -0
  8. package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +16 -0
  9. package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +14 -0
  10. package/dist/templates/react-app/__tests__/__mocks__/createMockGlobals.ts +92 -0
  11. package/dist/templates/react-app/__tests__/setup/index.ts +51 -0
  12. package/dist/templates/react-app/__tests__/src/App.test.tsx +139 -0
  13. package/dist/templates/react-app/__tests__/src/base/cases/AppConfig.test.ts +288 -0
  14. package/dist/templates/react-app/__tests__/src/base/cases/AppError.test.ts +102 -0
  15. package/dist/templates/react-app/__tests__/src/base/cases/DialogHandler.test.ts +228 -0
  16. package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +207 -0
  17. package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +181 -0
  18. package/dist/templates/react-app/__tests__/src/base/cases/PublicAssetsPath.test.ts +61 -0
  19. package/dist/templates/react-app/__tests__/src/base/cases/RequestLogger.test.ts +199 -0
  20. package/dist/templates/react-app/__tests__/src/base/cases/RequestStatusCatcher.test.ts +192 -0
  21. package/dist/templates/react-app/__tests__/src/base/cases/RouterLoader.test.ts +235 -0
  22. package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +224 -0
  23. package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +257 -0
  24. package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +72 -0
  25. package/dist/templates/react-app/__tests__/src/main.integration.test.tsx +62 -0
  26. package/dist/templates/react-app/__tests__/src/main.test.tsx +46 -0
  27. package/dist/templates/react-app/__tests__/src/uikit/components/BaseHeader.test.tsx +88 -0
  28. package/dist/templates/react-app/config/app.router.ts +155 -0
  29. package/dist/templates/react-app/config/common.ts +9 -1
  30. package/dist/templates/react-app/docs/en/bootstrap.md +562 -0
  31. package/dist/templates/react-app/docs/en/development-guide.md +523 -0
  32. package/dist/templates/react-app/docs/en/env.md +482 -0
  33. package/dist/templates/react-app/docs/en/global.md +509 -0
  34. package/dist/templates/react-app/docs/en/i18n.md +268 -0
  35. package/dist/templates/react-app/docs/en/index.md +173 -0
  36. package/dist/templates/react-app/docs/en/ioc.md +424 -0
  37. package/dist/templates/react-app/docs/en/project-structure.md +434 -0
  38. package/dist/templates/react-app/docs/en/request.md +425 -0
  39. package/dist/templates/react-app/docs/en/router.md +404 -0
  40. package/dist/templates/react-app/docs/en/store.md +321 -0
  41. package/dist/templates/react-app/docs/en/test-guide.md +782 -0
  42. package/dist/templates/react-app/docs/en/theme.md +424 -0
  43. package/dist/templates/react-app/docs/en/typescript-guide.md +473 -0
  44. package/dist/templates/react-app/docs/zh/bootstrap.md +7 -0
  45. package/dist/templates/react-app/docs/zh/development-guide.md +523 -0
  46. package/dist/templates/react-app/docs/zh/env.md +24 -25
  47. package/dist/templates/react-app/docs/zh/global.md +28 -27
  48. package/dist/templates/react-app/docs/zh/i18n.md +268 -0
  49. package/dist/templates/react-app/docs/zh/index.md +173 -0
  50. package/dist/templates/react-app/docs/zh/ioc.md +44 -32
  51. package/dist/templates/react-app/docs/zh/project-structure.md +434 -0
  52. package/dist/templates/react-app/docs/zh/request.md +429 -0
  53. package/dist/templates/react-app/docs/zh/router.md +408 -0
  54. package/dist/templates/react-app/docs/zh/store.md +321 -0
  55. package/dist/templates/react-app/docs/zh/test-guide.md +782 -0
  56. package/dist/templates/react-app/docs/zh/theme.md +424 -0
  57. package/dist/templates/react-app/docs/zh/typescript-guide.md +473 -0
  58. package/dist/templates/react-app/package.json +9 -20
  59. package/dist/templates/react-app/src/base/cases/AppConfig.ts +16 -9
  60. package/dist/templates/react-app/src/base/cases/PublicAssetsPath.ts +7 -1
  61. package/dist/templates/react-app/src/base/services/I18nService.ts +15 -4
  62. package/dist/templates/react-app/src/base/services/RouteService.ts +43 -7
  63. package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +31 -10
  64. package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +1 -1
  65. package/dist/templates/react-app/src/core/globals.ts +1 -3
  66. package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +5 -3
  67. package/dist/templates/react-app/src/main.tsx +6 -1
  68. package/dist/templates/react-app/src/pages/404.tsx +0 -1
  69. package/dist/templates/react-app/src/pages/500.tsx +1 -1
  70. package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +3 -1
  71. package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +3 -1
  72. package/dist/templates/react-app/src/styles/css/antd-themes/index.css +1 -1
  73. package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +6 -1
  74. package/dist/templates/react-app/src/styles/css/page.css +1 -1
  75. package/dist/templates/react-app/src/uikit/components/BaseHeader.tsx +9 -2
  76. package/dist/templates/react-app/src/uikit/components/LocaleLink.tsx +5 -3
  77. package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +4 -6
  78. package/dist/templates/react-app/tsconfig.json +2 -1
  79. package/dist/templates/react-app/tsconfig.test.json +13 -0
  80. package/dist/templates/react-app/vite.config.ts +3 -2
  81. package/package.json +1 -1
@@ -0,0 +1,424 @@
1
+ # Theme System
2
+
3
+ ## Overview
4
+
5
+ The theme system is implemented using CSS variables, combined with Tailwind CSS and Ant Design component library, providing flexible and powerful theme customization capabilities. Main features:
6
+
7
+ - **CSS Variable Driven**: Implement theme switching using CSS variables
8
+ - **Tailwind Integration**: Perfect integration with Tailwind CSS
9
+ - **Multi-theme Support**: Built-in light, dark, and pink themes
10
+ - **Ant Design Integration**: Custom Ant Design component styles
11
+ - **Responsive Design**: Support system theme following
12
+ - **State Management**: Integration with Store system
13
+ - **Type Safety**: Complete TypeScript type support
14
+
15
+ ## Technology Stack Integration
16
+
17
+ ### 1. Tailwind CSS Configuration
18
+
19
+ The project uses Tailwind CSS for style management, integrated through PostCSS plugins:
20
+
21
+ ```javascript
22
+ // postcss.config.js
23
+ export default {
24
+ plugins: {
25
+ '@tailwindcss/postcss': {}
26
+ }
27
+ };
28
+
29
+ // tailwind.config.js
30
+ export default {
31
+ darkMode: 'class',
32
+ content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}']
33
+ };
34
+ ```
35
+
36
+ ### 2. Style Layer Management
37
+
38
+ ```css
39
+ /* styles/css/tailwind.css */
40
+ @layer theme, base, antd, components, utilities;
41
+
42
+ @import 'tailwindcss';
43
+ @import './themes/index.css';
44
+ ```
45
+
46
+ ### 3. CSS Variables and Tailwind Integration
47
+
48
+ Theme variables are designed considering collaboration with Tailwind:
49
+
50
+ ```css
51
+ /* Define theme variables */
52
+ :root {
53
+ --color-bg-base: 255 255 255; /* Support Tailwind's rgb value format */
54
+ --text-primary: 15 23 42; /* slate-900 */
55
+ --color-brand: 37 99 235; /* blue-600 */
56
+ }
57
+
58
+ /* Use theme variables in Tailwind */
59
+ .custom-element {
60
+ @apply bg-[rgb(var(--color-bg-base))] /* Background color */
61
+ text-[rgb(var(--text-primary))] /* Text color */
62
+ border-[rgb(var(--color-border))] /* Border color */;
63
+ }
64
+ ```
65
+
66
+ ## Theme Configuration
67
+
68
+ ### 1. Basic Configuration
69
+
70
+ Define theme configuration in `config/theme.ts`:
71
+
72
+ ```typescript
73
+ export const themeConfig: ThemeConfig = {
74
+ domAttribute: 'data-theme', // Theme attribute name
75
+ defaultTheme: 'system', // Default theme
76
+ target: 'html', // Theme attribute target element
77
+ supportedThemes: [
78
+ // Supported theme list
79
+ 'light',
80
+ 'dark',
81
+ 'pink'
82
+ ],
83
+ storageKey: 'fe_theme', // Theme storage key
84
+ init: true, // Auto initialization
85
+ prioritizeStore: true // Prioritize stored theme
86
+ };
87
+ ```
88
+
89
+ ### 2. Theme Variable Definition
90
+
91
+ Each theme defines a complete set of CSS variables:
92
+
93
+ ```css
94
+ /* Default theme (_default.css) */
95
+ :root {
96
+ /* Base background colors */
97
+ --color-bg-base: 255 255 255;
98
+ --color-bg-secondary: 241 245 249;
99
+ --color-bg-elevated: 248 250 252;
100
+
101
+ /* Text colors */
102
+ --text-primary: 15 23 42;
103
+ --text-secondary: 71 85 105;
104
+ --text-tertiary: 100 116 139;
105
+
106
+ /* Border colors */
107
+ --color-border: 226 232 240;
108
+
109
+ /* Brand colors */
110
+ --color-brand: 37 99 235;
111
+ --color-brand-hover: 59 130 246;
112
+ }
113
+
114
+ /* Dark theme (dark.css) */
115
+ [data-theme='dark'] {
116
+ /* Base background colors */
117
+ --color-bg-base: 15 23 42;
118
+ --color-bg-secondary: 30 41 59;
119
+ --color-bg-elevated: 51 65 85;
120
+
121
+ /* Text colors */
122
+ --text-primary: 255 255 255;
123
+ --text-secondary: 148 163 184;
124
+ --text-tertiary: 100 116 139;
125
+ }
126
+
127
+ /* Pink theme (pink.css) */
128
+ [data-theme='pink'] {
129
+ /* Base background colors */
130
+ --color-bg-base: 255 241 242;
131
+ --color-bg-secondary: 255 228 230;
132
+ --color-bg-elevated: 254 205 211;
133
+
134
+ /* Text colors */
135
+ --text-primary: 190 18 60;
136
+ --text-secondary: 225 29 72;
137
+ --text-tertiary: 244 63 94;
138
+ }
139
+ ```
140
+
141
+ ## Ant Design Theme Customization
142
+
143
+ ### 1. Component Variables
144
+
145
+ CSS variables customized for Ant Design components:
146
+
147
+ ```css
148
+ .fe-theme {
149
+ /* Primary colors */
150
+ --fe-color-primary: #60a5fa;
151
+ --fe-color-primary-hover: #3b82f6;
152
+ --fe-color-primary-active: #2563eb;
153
+
154
+ /* Status colors */
155
+ --fe-color-success: #52c41a;
156
+ --fe-color-warning: #faad14;
157
+ --fe-color-error: #ff4d4f;
158
+ --fe-color-info: var(--fe-color-primary);
159
+
160
+ /* Text colors */
161
+ --fe-color-text: rgba(15 23 42 / 0.85);
162
+ --fe-color-text-secondary: rgba(15 23 42 / 0.45);
163
+ --fe-color-text-tertiary: rgba(15 23 42 / 0.35);
164
+
165
+ /* Component styles */
166
+ --fe-border-radius: 6px;
167
+ --fe-line-width: 1px;
168
+ --fe-motion-duration-mid: 0.2s;
169
+ }
170
+ ```
171
+
172
+ ### 2. Component-level Customization
173
+
174
+ Style customization for specific components:
175
+
176
+ ```css
177
+ /* Button component */
178
+ .ant-btn {
179
+ --fe-button-primary-color: #fff;
180
+ --fe-button-primary-bg: #60a5fa;
181
+ --fe-button-primary-hover-bg: #3b82f6;
182
+ --fe-button-padding-inline: 15px;
183
+ --fe-button-font-size: 14px;
184
+ }
185
+
186
+ /* Input component */
187
+ .ant-input {
188
+ --fe-input-padding-block: 4px;
189
+ --fe-input-hover-border-color: #4096ff;
190
+ --fe-input-active-shadow: 0 0 0 2px rgba(5, 145, 255, 0.1);
191
+ }
192
+
193
+ /* Select component */
194
+ .ant-select {
195
+ --fe-select-option-selected-bg: var(--fe-color-primary-bg);
196
+ --fe-select-hover-border-color: var(--fe-color-primary);
197
+ }
198
+ ```
199
+
200
+ ## Theme Switching Implementation
201
+
202
+ ### 1. Theme Switcher Component
203
+
204
+ ```tsx
205
+ export default function ThemeSwitcher() {
206
+ const themeService = IOC(ThemeService);
207
+ const { theme } = useStore(themeService);
208
+ const themes = themeService.getSupportedThemes();
209
+
210
+ const themeOptions = useMemo(() => {
211
+ return themes.map((themeName) => ({
212
+ value: themeName,
213
+ label: (
214
+ <div className={clsx('flex items-center gap-2')}>
215
+ <ThemeIcon theme={themeName} />
216
+ <span>{t(`HEADER_THEME_${themeName.toUpperCase()}`)}</span>
217
+ </div>
218
+ )
219
+ }));
220
+ }, [themes, t]);
221
+
222
+ return (
223
+ <Select
224
+ value={theme}
225
+ onChange={(value) => themeService.changeTheme(value)}
226
+ options={themeOptions}
227
+ />
228
+ );
229
+ }
230
+ ```
231
+
232
+ ### 2. Theme Service Integration
233
+
234
+ ```tsx
235
+ function App() {
236
+ return (
237
+ <AntdThemeProvider
238
+ staticApi={IOC('DialogHandler')}
239
+ theme={{
240
+ cssVar: {
241
+ key: 'fe-theme',
242
+ prefix: 'fe'
243
+ }
244
+ }}
245
+ >
246
+ <RouterProvider router={routerBase} />
247
+ </AntdThemeProvider>
248
+ );
249
+ }
250
+ ```
251
+
252
+ ## Usage
253
+
254
+ ### 1. Tailwind Utility Classes and Theme Variables
255
+
256
+ ```tsx
257
+ function CustomCard() {
258
+ return (
259
+ <div
260
+ className="
261
+ /* Background and border */
262
+ bg-[rgb(var(--color-bg-base))]
263
+ border-[1px]
264
+ border-[rgb(var(--color-border))]
265
+ rounded-lg
266
+
267
+ /* Spacing and shadow */
268
+ p-4
269
+ shadow-md
270
+
271
+ /* Text styles */
272
+ text-[rgb(var(--text-primary))]
273
+
274
+ /* Interactive states */
275
+ hover:bg-[rgb(var(--color-bg-secondary))]
276
+ transition-colors
277
+ "
278
+ >
279
+ <h3 className="text-lg font-medium mb-2">Card Title</h3>
280
+ <p className="text-[rgb(var(--text-secondary))]">Card Content</p>
281
+ </div>
282
+ );
283
+ }
284
+ ```
285
+
286
+ ### 2. Responsive Design
287
+
288
+ ```tsx
289
+ function ResponsiveLayout() {
290
+ return (
291
+ <div
292
+ className="
293
+ /* Responsive layout */
294
+ grid
295
+ grid-cols-1
296
+ sm:grid-cols-2
297
+ lg:grid-cols-3
298
+ gap-4
299
+
300
+ /* Theme-related styles */
301
+ bg-[rgb(var(--color-bg-secondary))]
302
+ p-4
303
+ sm:p-6
304
+ lg:p-8
305
+ "
306
+ >
307
+ {/* Content */}
308
+ </div>
309
+ );
310
+ }
311
+ ```
312
+
313
+ ### 3. Component Style Reuse
314
+
315
+ ```tsx
316
+ // Define common button styles
317
+ const buttonStyles = {
318
+ base: `
319
+ px-4
320
+ py-2
321
+ rounded-md
322
+ transition-colors
323
+ disabled:opacity-50
324
+ `,
325
+ primary: `
326
+ bg-[rgb(var(--color-brand))]
327
+ text-white
328
+ hover:bg-[rgb(var(--color-brand-hover))]
329
+ `,
330
+ secondary: `
331
+ bg-[rgb(var(--color-bg-secondary))]
332
+ text-[rgb(var(--text-primary))]
333
+ hover:bg-[rgb(var(--color-bg-elevated))]
334
+ `
335
+ };
336
+
337
+ function Button({ variant = 'primary', className = '', ...props }) {
338
+ return (
339
+ <button
340
+ className={`
341
+ ${buttonStyles.base}
342
+ ${buttonStyles[variant]}
343
+ ${className}
344
+ `}
345
+ {...props}
346
+ />
347
+ );
348
+ }
349
+ ```
350
+
351
+ ### 2. Theme Switching
352
+
353
+ ```tsx
354
+ function ThemeToggle() {
355
+ const themeService = IOC(ThemeService);
356
+
357
+ const toggleTheme = () => {
358
+ const currentTheme = themeService.getTheme();
359
+ const newTheme = currentTheme === 'light' ? 'dark' : 'light';
360
+ themeService.changeTheme(newTheme);
361
+ };
362
+
363
+ return <button onClick={toggleTheme}>Toggle Theme</button>;
364
+ }
365
+ ```
366
+
367
+ ## Best Practices
368
+
369
+ 1. **Variable Naming**
370
+ - Use semantic variable names
371
+ - Follow namespace conventions
372
+ - Maintain variable name consistency
373
+
374
+ 2. **Theme Organization**
375
+ - Categorize variables by functionality
376
+ - Use CSS layer management
377
+ - Avoid duplicate definitions
378
+
379
+ 3. **Performance Optimization**
380
+ - Use CSS variables judiciously
381
+ - Avoid runtime calculations
382
+ - Use CSS preprocessing
383
+
384
+ 4. **Maintainability**
385
+ - Unified variable management
386
+ - Clear theme structure
387
+ - Complete type definitions
388
+
389
+ 5. **Tailwind Usage Suggestions**
390
+ - Use theme variables instead of hardcoded colors
391
+ - Organize utility classes logically
392
+ - Extract common style combinations
393
+ - Use @apply for complex styles
394
+
395
+ 6. **Performance Optimization**
396
+ - Use PurgeCSS to clean unused styles
397
+ - Use dynamic class names reasonably
398
+ - Avoid overuse of custom properties
399
+
400
+ ## Common Issues
401
+
402
+ ### 1. Theme Switching Not Working
403
+
404
+ Check the following:
405
+
406
+ - Ensure theme configuration is correct
407
+ - Check if CSS variables are properly loaded
408
+ - Verify theme switching service is working
409
+
410
+ ### 2. Component Style Issues
411
+
412
+ Possible solutions:
413
+
414
+ - Check component variable overrides
415
+ - Confirm CSS specificity
416
+ - Review theme variable inheritance
417
+
418
+ ### 3. Custom Themes
419
+
420
+ Development suggestions:
421
+
422
+ - Follow existing theme structure
423
+ - Define all necessary variables completely
424
+ - Consider compatibility with component library