create-template-html-css 2.1.0 → 2.2.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/CHANGELOG.md +131 -0
- package/CODE-SPLITTING-GUIDE.md +274 -0
- package/COMPONENTS-GALLERY.html +143 -8
- package/README.md +71 -3
- package/bin/cli.js +2 -0
- package/bin/commands/create.js +16 -0
- package/package.json +1 -1
- package/src/react-component-choices.js +53 -1
- package/src/react-component-templates.js +182 -0
- package/src/react-generator.js +15 -4
- package/src/react-templates.js +192 -124
- package/src/templates/basic-components-templates.js +157 -0
- package/src/templates/form-components-templates.js +194 -0
- package/src/templates/interactive-components-templates.js +139 -0
- package/templates-react/alert/Alert.css +158 -0
- package/templates-react/alert/Alert.example.jsx +106 -0
- package/templates-react/alert/Alert.jsx +61 -0
- package/templates-react/badge/Badge.css +196 -0
- package/templates-react/badge/Badge.example.jsx +182 -0
- package/templates-react/badge/Badge.jsx +44 -0
- package/templates-react/button/Button.example.jsx +1 -1
- package/templates-react/button/Button.jsx +1 -1
- package/templates-react/card/Card.example.jsx +1 -1
- package/templates-react/card/Card.jsx +1 -1
- package/templates-react/checkbox/Checkbox.css +217 -0
- package/templates-react/checkbox/Checkbox.example.jsx +141 -0
- package/templates-react/checkbox/Checkbox.jsx +82 -0
- package/templates-react/counter/Counter.example.jsx +1 -1
- package/templates-react/counter/Counter.jsx +1 -1
- package/templates-react/dropdown/Dropdown.css +237 -0
- package/templates-react/dropdown/Dropdown.example.jsx +98 -0
- package/templates-react/dropdown/Dropdown.jsx +154 -0
- package/templates-react/form/Form.example.jsx +0 -1
- package/templates-react/form/Form.jsx +1 -1
- package/templates-react/input/Input.css +113 -0
- package/templates-react/input/Input.example.jsx +82 -0
- package/templates-react/input/Input.jsx +87 -0
- package/templates-react/modal/Modal.example.jsx +1 -1
- package/templates-react/modal/Modal.jsx +1 -1
- package/templates-react/navbar/Navbar.css +139 -0
- package/templates-react/navbar/Navbar.example.jsx +37 -0
- package/templates-react/navbar/Navbar.jsx +62 -0
- package/templates-react/progress/Progress.css +247 -0
- package/templates-react/progress/Progress.example.jsx +244 -0
- package/templates-react/progress/Progress.jsx +79 -0
- package/templates-react/switch/Switch.css +244 -0
- package/templates-react/switch/Switch.example.jsx +221 -0
- package/templates-react/switch/Switch.jsx +98 -0
- package/templates-react/todo-list/TodoList.example.jsx +1 -1
- package/templates-react/todo-list/TodoList.jsx +1 -1
- package/templates-react/tooltip/Tooltip.css +165 -0
- package/templates-react/tooltip/Tooltip.example.jsx +166 -0
- package/templates-react/tooltip/Tooltip.jsx +176 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ npm install -g create-template-html-css
|
|
|
34
34
|
- 🌈 **Stunning Gradients** - Colorful and attractive designs
|
|
35
35
|
- ⚡ **Animations** - Smooth and professional effects
|
|
36
36
|
- 🔧 **Customizable** - Easy to edit and modify the code
|
|
37
|
-
- 📦 **46 HTML Templates +
|
|
37
|
+
- 📦 **46 HTML Templates + 15 React Components** - Button, Card, Form, Navigation, Modal, Footer, Hero, Slider, Table, Login, Register, Skeleton, Spinner, Animated Cards, Typing Effect, Fade Gallery, Grid Layouts, Masonry Grid, Dashboard, Flexbox Layouts, Todo List, Counter, Accordion, Tabs, 16 Interactive Games, + React: Alert, Badge, Button, Card, Checkbox, Counter, Dropdown, Form, Input, Modal, Navbar, Progress, Switch, Todo List, Tooltip
|
|
38
38
|
- 🎯 **Two Modes** - Create new projects or insert into existing HTML pages
|
|
39
39
|
- 🔒 **Secure** - Input validation and path protection
|
|
40
40
|
- 📚 **Well Documented** - Comprehensive guides and examples
|
|
@@ -46,12 +46,14 @@ npm install -g create-template-html-css
|
|
|
46
46
|
- 🏗️ **Modern Architecture** - ES Modules for better performance and tree-shaking (v2.1.0+)
|
|
47
47
|
- 🧩 **Modular CLI** - Refactored command structure for better maintainability (v2.1.0+)
|
|
48
48
|
- ⚡ **Vite Integration** - React projects use Vite for fast development (v2.1.0+)
|
|
49
|
+
- 🚀 **Code Splitting** - Lazy loading and build optimizations for better performance (v2.2.0+)
|
|
50
|
+
- 📦 **Bundle Optimization** - Automatic vendor chunking and tree-shaking (v2.2.0+)
|
|
49
51
|
|
|
50
52
|
## 🆕 What's New in v2.1.0
|
|
51
53
|
|
|
52
54
|
### ⚛️ **React Support**
|
|
53
55
|
- **React Components** - Generate React components with JSX
|
|
54
|
-
- **
|
|
56
|
+
- **15 React Components** - Alert 🚨, Badge 🏷️, Button 🔘, Card 🃏, Checkbox ☑️, Counter 🔢, Dropdown 📋, Form 📝, Input ✏️, Modal 🪟, Navbar 🧭, Progress 📊, Switch 🔀, Todo List ✅, Tooltip 💬
|
|
55
57
|
- **Two Modes**:
|
|
56
58
|
- **Full Project** - Complete React + Vite project with all dependencies
|
|
57
59
|
- **Component Only** - Just JSX + CSS files for existing projects
|
|
@@ -96,13 +98,70 @@ create-template create --react --component-only -c modal --color-scheme vibrant
|
|
|
96
98
|
- Works with all color schemes
|
|
97
99
|
- Usage instructions displayed after creation
|
|
98
100
|
|
|
99
|
-
**Available React Components:**
|
|
101
|
+
**Available React Components (15 total):**
|
|
102
|
+
- 🔔 **Alert** - Alert/notification component with types (success, error, warning, info), dismissible
|
|
103
|
+
- 🏷️ **Badge** - Status badge with counts, dots, variants, and positioning (new, hot, notification counts)
|
|
100
104
|
- 🔘 **Button** - Customizable button with variants (primary, secondary, success, danger) and sizes
|
|
101
105
|
- 🎴 **Card** - Display content in an elegant card with image support
|
|
106
|
+
- ☑️ **Checkbox** - Checkbox with sizes, colors, indeterminate state, and validation
|
|
102
107
|
- 🔢 **Counter** - Interactive counter with increment/decrement and limits
|
|
108
|
+
- 📋 **Dropdown** - Select dropdown with search, multi-select, and keyboard navigation
|
|
103
109
|
- 📝 **Form** - Flexible form with validation and multiple field types
|
|
110
|
+
- 📄 **Input** - Text input with validation, error messages, icons, and states
|
|
104
111
|
- 🪟 **Modal** - Dialog modal component with overlay
|
|
112
|
+
- 🧭 **Navbar** - Responsive navigation bar with mobile hamburger menu
|
|
113
|
+
- 📊 **Progress** - Progress bar with variants, animations, striped patterns, and indeterminate state
|
|
114
|
+
- 🔀 **Switch** - Toggle switch for on/off states with colors, sizes, icons, disabled and loading states
|
|
105
115
|
- ✅ **Todo List** - Complete todo list with CRUD operations
|
|
116
|
+
- 💬 **Tooltip** - Contextual tooltip with positions (top, bottom, left, right) and triggers
|
|
117
|
+
|
|
118
|
+
## 🚀 Code Splitting & Performance Optimization (v2.2.0+)
|
|
119
|
+
|
|
120
|
+
### ⚡ **Reduce Bundle Size by 40-60%**
|
|
121
|
+
|
|
122
|
+
Generate React projects with advanced code splitting and lazy loading:
|
|
123
|
+
|
|
124
|
+
**Enable Lazy Loading:**
|
|
125
|
+
```bash
|
|
126
|
+
# Interactive mode
|
|
127
|
+
create-template create --react --lazy-load
|
|
128
|
+
|
|
129
|
+
# With flags
|
|
130
|
+
create-template create --react -c counter -n my-app --lazy-load
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Enable Build Optimizations:**
|
|
134
|
+
```bash
|
|
135
|
+
# Full optimization with code splitting
|
|
136
|
+
create-template create --react -c button -n my-app --optimize-build
|
|
137
|
+
|
|
138
|
+
# Combine both for maximum performance
|
|
139
|
+
create-template create --react -c todo-list -n my-app --lazy-load --optimize-build
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**What You Get:**
|
|
143
|
+
|
|
144
|
+
1. **Lazy Loading (--lazy-load)**
|
|
145
|
+
- Components loaded with `React.lazy()` and `Suspense`
|
|
146
|
+
- Reduces initial bundle size
|
|
147
|
+
- Faster page load time
|
|
148
|
+
- Loading states included
|
|
149
|
+
|
|
150
|
+
2. **Build Optimizations (--optimize-build)**
|
|
151
|
+
- Automatic vendor chunking (React, ReactDOM)
|
|
152
|
+
- Better browser caching
|
|
153
|
+
- Tree-shaking enabled
|
|
154
|
+
- Console.log removal in production
|
|
155
|
+
- Terser minification
|
|
156
|
+
|
|
157
|
+
**Performance Impact:**
|
|
158
|
+
```
|
|
159
|
+
Without optimization: bundle.js (150 KB)
|
|
160
|
+
With optimization: vendor.js (85 KB) + main.js (35 KB) + lazy chunks
|
|
161
|
+
Result: 40%+ smaller initial load! ⚡
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**📖 Learn More:** See [CODE-SPLITTING-GUIDE.md](CODE-SPLITTING-GUIDE.md) for detailed documentation, best practices, and migration guide.
|
|
106
165
|
|
|
107
166
|
## 🆕 What's New in v2.0.0
|
|
108
167
|
|
|
@@ -463,12 +522,21 @@ npm run dev
|
|
|
463
522
|
Open [http://localhost:5173](http://localhost:5173) in your browser.
|
|
464
523
|
|
|
465
524
|
**Available React Components:**
|
|
525
|
+
- � **Alert** - Types: success, error, warning, info | Dismissible with close button
|
|
526
|
+
- 🏷️ **Badge** - Variants, sizes, pill shape, count badges, dot badges with positioning
|
|
466
527
|
- 🔘 **Button** - Variants: primary, secondary, success, danger | Sizes: small, medium, large
|
|
467
528
|
- 🎴 **Card** - Image, title, description, footer support with hover effects
|
|
529
|
+
- ☑️ **Checkbox** - Sizes, colors, indeterminate state, validation, disabled states
|
|
468
530
|
- 🔢 **Counter** - Increment/decrement with limits, step customization, reset button
|
|
531
|
+
- 📋 **Dropdown** - Search, multi-select, keyboard navigation, custom placeholder
|
|
469
532
|
- 📝 **Form** - Multiple field types, built-in validation, error messages
|
|
533
|
+
- 📄 **Input** - Validation, error messages, icons, disabled/readonly states
|
|
470
534
|
- 🪟 **Modal** - Customizable sizes (small, medium, large), overlay, close handlers
|
|
535
|
+
- 🧭 **Navbar** - Responsive with mobile hamburger menu, logo, navigation links
|
|
536
|
+
- 📊 **Progress** - Colors, sizes, labels, striped patterns, animations, indeterminate state
|
|
537
|
+
- 🔀 **Switch** - Colors, sizes, icons, disabled and loading states for toggles
|
|
471
538
|
- ✅ **Todo List** - Add, toggle complete, delete tasks with statistics
|
|
539
|
+
- 💬 **Tooltip** - Positions: top, bottom, left, right | Triggers: hover, click, focus
|
|
472
540
|
|
|
473
541
|
### Mode 2: Insert Component into Existing HTML Page
|
|
474
542
|
|
package/bin/cli.js
CHANGED
|
@@ -43,6 +43,8 @@ program
|
|
|
43
43
|
.option("--include-js", "Include JavaScript file", true)
|
|
44
44
|
.option("--no-include-js", "Exclude JavaScript file")
|
|
45
45
|
.option("--dark-mode", "Add dark mode support")
|
|
46
|
+
.option("--lazy-load", "Enable lazy loading with React.lazy() and Suspense (React only)")
|
|
47
|
+
.option("--optimize-build", "Enable build optimizations and code splitting (React only)")
|
|
46
48
|
.option("--primary-color <color>", "Primary color (hex: #667eea)")
|
|
47
49
|
.option("--secondary-color <color>", "Secondary color (hex: #764ba2)")
|
|
48
50
|
.option("--color-scheme <scheme>", "Color scheme preset")
|
package/bin/commands/create.js
CHANGED
|
@@ -56,6 +56,8 @@ async function createCommand(options) {
|
|
|
56
56
|
colorScheme: options.colorScheme,
|
|
57
57
|
primaryColor: options.primaryColor,
|
|
58
58
|
secondaryColor: options.secondaryColor,
|
|
59
|
+
lazyLoad: options.lazyLoad || false,
|
|
60
|
+
optimizeBuild: options.optimizeBuild || false,
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
if (isReactMode) {
|
|
@@ -163,6 +165,20 @@ async function createCommand(options) {
|
|
|
163
165
|
message: "Add dark mode support (prefers-color-scheme)?",
|
|
164
166
|
default: false,
|
|
165
167
|
},
|
|
168
|
+
{
|
|
169
|
+
type: "confirm",
|
|
170
|
+
name: "lazyLoad",
|
|
171
|
+
message: "Enable lazy loading with Suspense? (reduces initial bundle size)",
|
|
172
|
+
default: false,
|
|
173
|
+
when: (answers) => answers.framework === "react" && answers.projectType !== "component-only",
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: "confirm",
|
|
177
|
+
name: "optimizeBuild",
|
|
178
|
+
message: "Enable build optimizations and code splitting?",
|
|
179
|
+
default: false,
|
|
180
|
+
when: (answers) => answers.framework === "react" && answers.projectType !== "component-only",
|
|
181
|
+
},
|
|
166
182
|
{
|
|
167
183
|
type: "list",
|
|
168
184
|
name: "colorOption",
|
package/package.json
CHANGED
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
export const REACT_COMPONENT_CHOICES = [
|
|
6
6
|
{
|
|
7
|
-
name: "
|
|
7
|
+
name: "� Alert - Alert/notification component with variants",
|
|
8
|
+
value: "alert",
|
|
9
|
+
short: "Alert",
|
|
10
|
+
},
|
|
11
|
+
{ name: "🏷️ Badge - Status badge with counts, dots, and variants",
|
|
12
|
+
value: "badge",
|
|
13
|
+
short: "Badge",
|
|
14
|
+
},
|
|
15
|
+
{ name: "🔘 Button - Customizable button with variants and sizes",
|
|
8
16
|
value: "button",
|
|
9
17
|
short: "Button",
|
|
10
18
|
},
|
|
@@ -13,33 +21,77 @@ export const REACT_COMPONENT_CHOICES = [
|
|
|
13
21
|
value: "card",
|
|
14
22
|
short: "Card",
|
|
15
23
|
},
|
|
24
|
+
{
|
|
25
|
+
name: "☑️ Checkbox - Checkbox with sizes, colors, and states",
|
|
26
|
+
value: "checkbox",
|
|
27
|
+
short: "Checkbox",
|
|
28
|
+
},
|
|
16
29
|
{
|
|
17
30
|
name: "🔢 Counter - Interactive counter with increment/decrement",
|
|
18
31
|
value: "counter",
|
|
19
32
|
short: "Counter",
|
|
20
33
|
},
|
|
34
|
+
{
|
|
35
|
+
name: "📋 Dropdown - Select dropdown with search and multi-select",
|
|
36
|
+
value: "dropdown",
|
|
37
|
+
short: "Dropdown",
|
|
38
|
+
},
|
|
21
39
|
{
|
|
22
40
|
name: "📝 Form - Flexible form with validation",
|
|
23
41
|
value: "form",
|
|
24
42
|
short: "Form",
|
|
25
43
|
},
|
|
44
|
+
{
|
|
45
|
+
name: "📄 Input - Text input with validation and states",
|
|
46
|
+
value: "input",
|
|
47
|
+
short: "Input",
|
|
48
|
+
},
|
|
26
49
|
{
|
|
27
50
|
name: "🪟 Modal - Dialog modal component",
|
|
28
51
|
value: "modal",
|
|
29
52
|
short: "Modal",
|
|
30
53
|
},
|
|
54
|
+
{
|
|
55
|
+
name: "🧭 Navbar - Navigation bar with mobile menu",
|
|
56
|
+
value: "navbar",
|
|
57
|
+
short: "Navbar",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "📊 Progress - Progress bar with variants and animations",
|
|
61
|
+
value: "progress",
|
|
62
|
+
short: "Progress",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "🔀 Switch - Toggle switch for on/off states",
|
|
66
|
+
value: "switch",
|
|
67
|
+
short: "Switch",
|
|
68
|
+
},
|
|
31
69
|
{
|
|
32
70
|
name: "✅ Todo List - Complete todo list with CRUD operations",
|
|
33
71
|
value: "todo-list",
|
|
34
72
|
short: "Todo List",
|
|
35
73
|
},
|
|
74
|
+
{
|
|
75
|
+
name: "💬 Tooltip - Contextual tooltip with positions and triggers",
|
|
76
|
+
value: "tooltip",
|
|
77
|
+
short: "Tooltip",
|
|
78
|
+
},
|
|
36
79
|
];
|
|
37
80
|
|
|
38
81
|
export const REACT_COMPONENT_DESCRIPTIONS = {
|
|
82
|
+
alert: "An alert component for displaying notifications with different types (success, error, warning, info). Supports dismissible and custom icons",
|
|
83
|
+
badge: "A status badge component for displaying labels, counts, and indicators. Supports sizes, colors, pill shape, dot badges, and position variants",
|
|
39
84
|
button: "A customizable button component with multiple variants (primary, secondary, success, danger) and sizes (small, medium, large)",
|
|
40
85
|
card: "A versatile card component for displaying content with image, title, description, and footer support",
|
|
86
|
+
checkbox: "A checkbox component with different sizes, colors (primary, secondary, success, error), indeterminate state, and validation support",
|
|
41
87
|
counter: "A simple counter component with increment, decrement, and reset functionality. Supports min/max limits and custom steps",
|
|
88
|
+
dropdown: "A dropdown select component with searchable options, multi-select support, custom positioning, and keyboard navigation",
|
|
42
89
|
form: "A flexible form component with built-in validation, supporting multiple field types (text, email, textarea, select)",
|
|
90
|
+
input: "A text input component with validation, error messages, icons, and different states (focused, error, disabled)",
|
|
43
91
|
modal: "A modal dialog component with overlay, customizable sizes, and close handlers",
|
|
92
|
+
navbar: "A responsive navigation bar with logo, menu items, and mobile hamburger menu. Supports sticky positioning",
|
|
93
|
+
progress: "A progress bar component with colors, sizes, labels, striped patterns, animations, and indeterminate state for loading",
|
|
94
|
+
switch: "A toggle switch component for on/off states. Supports colors, sizes, icons, disabled and loading states",
|
|
44
95
|
"todo-list": "A complete todo list component with add, toggle, and delete functionality. Includes task statistics",
|
|
96
|
+
tooltip: "A contextual tooltip component with multiple positions (top, bottom, left, right), triggers (hover, click, focus), and customizable delays",
|
|
45
97
|
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Component Templates Module
|
|
3
|
+
*
|
|
4
|
+
* Central registry for all React component templates organized by category.
|
|
5
|
+
* This module aggregates templates from specialized sub-modules and provides
|
|
6
|
+
* a unified API for accessing component templates and their metadata.
|
|
7
|
+
*
|
|
8
|
+
* @module react-component-templates
|
|
9
|
+
* @author create-template-html-css
|
|
10
|
+
* @version 2.0.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { BASIC_TEMPLATES } from './templates/basic-components-templates.js';
|
|
14
|
+
import { FORM_TEMPLATES } from './templates/form-components-templates.js';
|
|
15
|
+
import { INTERACTIVE_TEMPLATES } from './templates/interactive-components-templates.js';
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// COMPONENT TEMPLATES REGISTRY
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unified component template registry
|
|
23
|
+
*
|
|
24
|
+
* Aggregates all component templates from different categories into a single
|
|
25
|
+
* accessible object. Templates are organized by component name (kebab-case).
|
|
26
|
+
*
|
|
27
|
+
* Categories:
|
|
28
|
+
* - Basic components: alert, badge, button, card, counter
|
|
29
|
+
* - Form components: form, input, checkbox, dropdown, switch
|
|
30
|
+
* - Interactive components: modal, navbar, tooltip, progress, todo-list
|
|
31
|
+
*
|
|
32
|
+
* @constant {Object.<string, string>}
|
|
33
|
+
*/
|
|
34
|
+
export const COMPONENT_TEMPLATES = {
|
|
35
|
+
...BASIC_TEMPLATES,
|
|
36
|
+
...FORM_TEMPLATES,
|
|
37
|
+
...INTERACTIVE_TEMPLATES,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// REACT IMPORTS MAPPING
|
|
42
|
+
// ============================================================================
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* React hooks import requirements for components
|
|
46
|
+
*
|
|
47
|
+
* Maps component names (kebab-case) to the React hooks they require.
|
|
48
|
+
* Components not listed here don't need any React hooks.
|
|
49
|
+
*
|
|
50
|
+
* @constant {Object.<string, string>}
|
|
51
|
+
* @property {string} modal - Requires useState for open/close state
|
|
52
|
+
* @property {string} input - Requires useState for controlled inputs
|
|
53
|
+
* @property {string} checkbox - Requires useState for checked state
|
|
54
|
+
* @property {string} dropdown - Requires useState for selection state
|
|
55
|
+
* @property {string} switch - Requires useState for toggle state
|
|
56
|
+
* @property {string} progress - Requires useState and useEffect for animations
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Get imports for a component
|
|
60
|
+
* const imports = COMPONENT_IMPORTS['modal']; // Returns 'useState'
|
|
61
|
+
*/
|
|
62
|
+
export const COMPONENT_IMPORTS = {
|
|
63
|
+
modal: 'useState',
|
|
64
|
+
input: 'useState',
|
|
65
|
+
checkbox: 'useState',
|
|
66
|
+
dropdown: 'useState',
|
|
67
|
+
switch: 'useState',
|
|
68
|
+
progress: 'useState, useEffect',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// HELPER FUNCTIONS
|
|
73
|
+
// ============================================================================
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get template content for a component with placeholders replaced
|
|
77
|
+
*
|
|
78
|
+
* Retrieves the JSX template for the specified component and replaces
|
|
79
|
+
* placeholder tokens with the actual component name.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} componentKebab - Component name in kebab-case (e.g., 'my-button')
|
|
82
|
+
* @param {string} componentName - Component name in PascalCase (e.g., 'MyButton')
|
|
83
|
+
* @returns {string|null} Template content with placeholders replaced, or null if not found
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const template = getComponentTemplate('button', 'Button');
|
|
87
|
+
* // Returns JSX string with <Button> tags instead of {ComponentName}
|
|
88
|
+
*/
|
|
89
|
+
export function getComponentTemplate(componentKebab, componentName) {
|
|
90
|
+
const template = COMPONENT_TEMPLATES[componentKebab];
|
|
91
|
+
if (!template) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Replace {ComponentName} placeholder with actual component name
|
|
96
|
+
return template.replace(/\{ComponentName\}/g, componentName);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get required React imports for a component
|
|
101
|
+
*
|
|
102
|
+
* Returns a comma-separated string of React hooks that the component needs.
|
|
103
|
+
* If the component doesn't require any hooks, returns an empty string.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} componentKebab - Component name in kebab-case
|
|
106
|
+
* @returns {string} Comma-separated imports (e.g., 'useState, useEffect') or empty string
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* const imports = getComponentImports('progress');
|
|
110
|
+
* // Returns 'useState, useEffect'
|
|
111
|
+
*
|
|
112
|
+
* const imports2 = getComponentImports('button');
|
|
113
|
+
* // Returns '' (no hooks needed)
|
|
114
|
+
*/
|
|
115
|
+
export function getComponentImports(componentKebab) {
|
|
116
|
+
return COMPONENT_IMPORTS[componentKebab] || '';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get all available component names
|
|
121
|
+
*
|
|
122
|
+
* Returns an array of all component names (in kebab-case) that have templates available.
|
|
123
|
+
* Useful for validation, CLI autocomplete, or displaying available options.
|
|
124
|
+
*
|
|
125
|
+
* @returns {string[]} Array of component names in kebab-case
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const components = getAllComponentNames();
|
|
129
|
+
* // Returns ['alert', 'badge', 'button', 'card', ...]
|
|
130
|
+
*/
|
|
131
|
+
export function getAllComponentNames() {
|
|
132
|
+
return Object.keys(COMPONENT_TEMPLATES);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check if a component template exists
|
|
137
|
+
*
|
|
138
|
+
* Validates whether a template is available for the specified component name.
|
|
139
|
+
* Case-sensitive - expects kebab-case.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} componentKebab - Component name in kebab-case
|
|
142
|
+
* @returns {boolean} True if template exists, false otherwise
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* if (hasComponent('button')) {
|
|
146
|
+
* console.log('Button template is available');
|
|
147
|
+
* }
|
|
148
|
+
*/
|
|
149
|
+
export function hasComponent(componentKebab) {
|
|
150
|
+
return componentKebab in COMPONENT_TEMPLATES;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get all components that require React imports
|
|
155
|
+
*
|
|
156
|
+
* Returns an array of component names that need React hooks.
|
|
157
|
+
* Useful for documenting which components have state management.
|
|
158
|
+
*
|
|
159
|
+
* @returns {string[]} Array of component names that require React imports
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const statefulComponents = getComponentsWithImports();
|
|
163
|
+
* // Returns ['modal', 'input', 'checkbox', 'dropdown', 'switch', 'progress']
|
|
164
|
+
*/
|
|
165
|
+
export function getComponentsWithImports() {
|
|
166
|
+
return Object.keys(COMPONENT_IMPORTS);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get component count
|
|
171
|
+
*
|
|
172
|
+
* Returns the total number of available component templates.
|
|
173
|
+
*
|
|
174
|
+
* @returns {number} Total number of components
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* console.log(`${getComponentCount()} components available`);
|
|
178
|
+
* // Output: "15 components available"
|
|
179
|
+
*/
|
|
180
|
+
export function getComponentCount() {
|
|
181
|
+
return Object.keys(COMPONENT_TEMPLATES).length;
|
|
182
|
+
}
|
package/src/react-generator.js
CHANGED
|
@@ -24,12 +24,21 @@ import {
|
|
|
24
24
|
|
|
25
25
|
// Valid React components
|
|
26
26
|
export const VALID_REACT_COMPONENTS = [
|
|
27
|
+
"alert",
|
|
28
|
+
"badge",
|
|
27
29
|
"button",
|
|
28
30
|
"card",
|
|
31
|
+
"checkbox",
|
|
29
32
|
"counter",
|
|
33
|
+
"dropdown",
|
|
30
34
|
"form",
|
|
35
|
+
"input",
|
|
31
36
|
"modal",
|
|
37
|
+
"navbar",
|
|
38
|
+
"progress",
|
|
39
|
+
"switch",
|
|
32
40
|
"todo-list",
|
|
41
|
+
"tooltip",
|
|
33
42
|
];
|
|
34
43
|
|
|
35
44
|
// ============================================================================
|
|
@@ -66,6 +75,8 @@ async function generateReactTemplate(options) {
|
|
|
66
75
|
primaryColor,
|
|
67
76
|
secondaryColor,
|
|
68
77
|
darkMode,
|
|
78
|
+
lazyLoad = false,
|
|
79
|
+
optimizeBuild = false,
|
|
69
80
|
} = options;
|
|
70
81
|
|
|
71
82
|
// Resolve colors
|
|
@@ -104,8 +115,8 @@ async function generateReactTemplate(options) {
|
|
|
104
115
|
// Write component files
|
|
105
116
|
await writeComponentFiles(componentDir, componentName, jsxContent, cssContent);
|
|
106
117
|
|
|
107
|
-
// Create App.jsx
|
|
108
|
-
const appContent = generateAppJsx(componentName, component);
|
|
118
|
+
// Create App.jsx (with optional lazy loading)
|
|
119
|
+
const appContent = generateAppJsx(componentName, component, { lazyLoad });
|
|
109
120
|
await fs.writeFile(path.join(srcDir, "App.jsx"), appContent, "utf-8");
|
|
110
121
|
|
|
111
122
|
// Create index.jsx
|
|
@@ -128,8 +139,8 @@ async function generateReactTemplate(options) {
|
|
|
128
139
|
const gitignoreContent = generateGitignore();
|
|
129
140
|
await fs.writeFile(path.join(outputDir, ".gitignore"), gitignoreContent, "utf-8");
|
|
130
141
|
|
|
131
|
-
// Create vite.config.js
|
|
132
|
-
const viteConfig = generateViteConfig();
|
|
142
|
+
// Create vite.config.js (with optional optimizations)
|
|
143
|
+
const viteConfig = generateViteConfig(optimizeBuild);
|
|
133
144
|
await fs.writeFile(path.join(outputDir, "vite.config.js"), viteConfig, "utf-8");
|
|
134
145
|
|
|
135
146
|
// Create README.md
|