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/src/react-templates.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Templates Generator Module
|
|
3
|
+
*
|
|
4
|
+
* Generates complete React project files including App.jsx, index files,
|
|
5
|
+
* configuration files, and documentation for component-based projects.
|
|
6
|
+
*
|
|
7
|
+
* @module react-templates
|
|
8
|
+
* @requires react-component-templates
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
getComponentTemplate,
|
|
13
|
+
getComponentImports,
|
|
14
|
+
hasComponent,
|
|
15
|
+
getAllComponentNames
|
|
16
|
+
} from './react-component-templates.js';
|
|
17
|
+
|
|
1
18
|
// ============================================================================
|
|
2
19
|
// CONSTANTS
|
|
3
20
|
// ============================================================================
|
|
4
21
|
|
|
5
|
-
|
|
22
|
+
/**
|
|
23
|
+
* React and Vite version constants
|
|
24
|
+
* Ensures consistent dependency versions across generated projects
|
|
25
|
+
*
|
|
26
|
+
* @constant {string}
|
|
27
|
+
*/
|
|
6
28
|
const REACT_VERSION = "^18.2.0";
|
|
7
29
|
const VITE_VERSION = "^5.0.0";
|
|
8
30
|
const VITE_REACT_PLUGIN_VERSION = "^4.2.0";
|
|
@@ -13,22 +35,62 @@ const VITE_REACT_PLUGIN_VERSION = "^4.2.0";
|
|
|
13
35
|
|
|
14
36
|
/**
|
|
15
37
|
* Create App.jsx template wrapper
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
38
|
+
*
|
|
39
|
+
* Wraps component usage examples in a complete React App component structure,
|
|
40
|
+
* including proper imports and export statements.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} componentName - Component name in PascalCase (e.g., 'Button')
|
|
43
|
+
* @param {string} additionalImports - React hooks to import (e.g., 'useState, useEffect')
|
|
44
|
+
* @param {string} content - JSX content for the App component body
|
|
45
|
+
* @returns {string} Complete App.jsx file content
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* createAppTemplate('Button', 'useState', 'return <div>...</div>');
|
|
20
49
|
*/
|
|
21
50
|
function createAppTemplate(componentName, additionalImports = '', content) {
|
|
22
51
|
const reactImports = additionalImports
|
|
23
|
-
? `import
|
|
24
|
-
:
|
|
52
|
+
? `import { ${additionalImports} } from 'react';`
|
|
53
|
+
: '';
|
|
54
|
+
|
|
55
|
+
const importsSection = reactImports ? `${reactImports}\n` : '';
|
|
56
|
+
return `${importsSection}import ${componentName} from './components/${componentName}/${componentName}';
|
|
57
|
+
import './components/${componentName}/${componentName}.css';
|
|
58
|
+
|
|
59
|
+
function App() {
|
|
60
|
+
${content}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default App;`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create App.jsx template with Lazy Loading
|
|
68
|
+
*
|
|
69
|
+
* Wraps component usage in React.lazy() and Suspense for code splitting.
|
|
70
|
+
* Reduces initial bundle size by loading components on demand.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} componentName - Component name in PascalCase
|
|
73
|
+
* @param {string} additionalImports - React hooks to import
|
|
74
|
+
* @param {string} content - JSX content for the App component body
|
|
75
|
+
* @returns {string} Complete App.jsx with lazy loading
|
|
76
|
+
*/
|
|
77
|
+
function createAppTemplateWithLazyLoading(componentName, additionalImports = '', content) {
|
|
78
|
+
const reactImports = additionalImports
|
|
79
|
+
? `import { lazy, Suspense, ${additionalImports} } from 'react';`
|
|
80
|
+
: `import { lazy, Suspense } from 'react';`;
|
|
25
81
|
|
|
26
82
|
return `${reactImports}
|
|
27
|
-
import ${componentName} from './components/${componentName}/${componentName}';
|
|
28
83
|
import './components/${componentName}/${componentName}.css';
|
|
29
84
|
|
|
85
|
+
// Lazy load component for code splitting
|
|
86
|
+
const ${componentName} = lazy(() => import('./components/${componentName}/${componentName}'));
|
|
87
|
+
|
|
30
88
|
function App() {
|
|
89
|
+
return (
|
|
90
|
+
<Suspense fallback={<div className="loading">Loading...</div>}>
|
|
31
91
|
${content}
|
|
92
|
+
</Suspense>
|
|
93
|
+
);
|
|
32
94
|
}
|
|
33
95
|
|
|
34
96
|
export default App;`;
|
|
@@ -39,125 +101,47 @@ export default App;`;
|
|
|
39
101
|
// ============================================================================
|
|
40
102
|
|
|
41
103
|
/**
|
|
42
|
-
* Generate App.jsx content
|
|
104
|
+
* Generate App.jsx content with component examples
|
|
105
|
+
*
|
|
106
|
+
* Creates a complete App.jsx file that demonstrates the component's features.
|
|
107
|
+
* Falls back to a basic example if the component template is not found.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} componentName - Component name in PascalCase (e.g., 'MyButton')
|
|
110
|
+
* @param {string} componentKebab - Component name in kebab-case (e.g., 'my-button')
|
|
111
|
+
* @param {object} options - Generation options
|
|
112
|
+
* @param {boolean} options.lazyLoad - Enable lazy loading with Suspense
|
|
113
|
+
* @returns {string} Complete App.jsx file content
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const appContent = generateAppJsx('Button', 'button', { lazyLoad: true });
|
|
43
117
|
*/
|
|
44
|
-
function generateAppJsx(componentName, componentKebab) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<div className="App" style={{
|
|
53
|
-
padding: '40px',
|
|
54
|
-
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
55
|
-
backgroundColor: '#f5f5f5',
|
|
56
|
-
minHeight: '100vh'
|
|
57
|
-
}}>
|
|
58
|
-
<h1 style={{ marginBottom: '30px', color: '#333' }}>${componentName} Component Examples</h1>
|
|
59
|
-
|
|
60
|
-
<div style={{ marginBottom: '30px' }}>
|
|
61
|
-
<h3 style={{ marginBottom: '15px', color: '#666' }}>Variants:</h3>
|
|
62
|
-
<div style={{ display: 'flex', gap: '15px', flexWrap: 'wrap' }}>
|
|
63
|
-
<${componentName} variant="primary" onClick={handleClick}>Primary</${componentName}>
|
|
64
|
-
<${componentName} variant="secondary" onClick={handleClick}>Secondary</${componentName}>
|
|
65
|
-
<${componentName} variant="success" onClick={handleClick}>Success</${componentName}>
|
|
66
|
-
<${componentName} variant="danger" onClick={handleClick}>Danger</${componentName}>
|
|
67
|
-
<${componentName} variant="outline" onClick={handleClick}>Outline</${componentName}>
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
|
|
71
|
-
<div style={{ marginBottom: '30px' }}>
|
|
72
|
-
<h3 style={{ marginBottom: '15px', color: '#666' }}>Sizes:</h3>
|
|
73
|
-
<div style={{ display: 'flex', gap: '15px', alignItems: 'center', flexWrap: 'wrap' }}>
|
|
74
|
-
<${componentName} size="small" onClick={handleClick}>Small</${componentName}>
|
|
75
|
-
<${componentName} size="medium" onClick={handleClick}>Medium</${componentName}>
|
|
76
|
-
<${componentName} size="large" onClick={handleClick}>Large</${componentName}>
|
|
77
|
-
</div>
|
|
78
|
-
</div>
|
|
79
|
-
|
|
80
|
-
<div style={{ marginBottom: '30px' }}>
|
|
81
|
-
<h3 style={{ marginBottom: '15px', color: '#666' }}>States:</h3>
|
|
82
|
-
<div style={{ display: 'flex', gap: '15px', flexWrap: 'wrap' }}>
|
|
83
|
-
<${componentName} onClick={handleClick}>Normal</${componentName}>
|
|
84
|
-
<${componentName} disabled>Disabled</${componentName}>
|
|
85
|
-
</div>
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
88
|
-
);`,
|
|
89
|
-
|
|
90
|
-
card: ` return (
|
|
91
|
-
<div className="App" style={{ padding: '40px', backgroundColor: '#f5f5f5', minHeight: '100vh' }}>
|
|
92
|
-
<h1 style={{ marginBottom: '30px' }}>${componentName} Component</h1>
|
|
93
|
-
<${componentName}
|
|
94
|
-
title="Example Card"
|
|
95
|
-
description="This is an example card component with a beautiful design"
|
|
96
|
-
image="https://via.placeholder.com/400x200"
|
|
97
|
-
/>
|
|
98
|
-
</div>
|
|
99
|
-
);`,
|
|
100
|
-
|
|
101
|
-
counter: ` return (
|
|
102
|
-
<div className="App" style={{ padding: '40px' }}>
|
|
103
|
-
<h1>Counter Component</h1>
|
|
104
|
-
<${componentName}
|
|
105
|
-
initialValue={0}
|
|
106
|
-
min={0}
|
|
107
|
-
max={100}
|
|
108
|
-
onChange={(value) => console.log('Count:', value)}
|
|
109
|
-
/>
|
|
110
|
-
</div>
|
|
111
|
-
);`,
|
|
112
|
-
|
|
113
|
-
form: ` return (
|
|
114
|
-
<div className="App" style={{ padding: '40px' }}>
|
|
115
|
-
<${componentName}
|
|
116
|
-
title="Contact Form"
|
|
117
|
-
fields={[
|
|
118
|
-
{ name: 'name', label: 'Name', type: 'text', required: true },
|
|
119
|
-
{ name: 'email', label: 'Email', type: 'email', required: true },
|
|
120
|
-
]}
|
|
121
|
-
onSubmit={(data) => console.log('Form data:', data)}
|
|
122
|
-
/>
|
|
123
|
-
</div>
|
|
124
|
-
);`,
|
|
125
|
-
|
|
126
|
-
"todo-list": ` return (
|
|
127
|
-
<div className="App" style={{ padding: '40px' }}>
|
|
128
|
-
<h1>Todo List</h1>
|
|
129
|
-
<${componentName} />
|
|
130
|
-
</div>
|
|
131
|
-
);`,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// Modal needs useState import
|
|
135
|
-
if (componentKebab === 'modal') {
|
|
136
|
-
const content = ` const [isOpen, setIsOpen] = useState(false);
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<div className="App" style={{ padding: '40px' }}>
|
|
140
|
-
<button onClick={() => setIsOpen(true)}>Open Modal</button>
|
|
141
|
-
<${componentName}
|
|
142
|
-
isOpen={isOpen}
|
|
143
|
-
onClose={() => setIsOpen(false)}
|
|
144
|
-
title="Example Modal"
|
|
145
|
-
>
|
|
146
|
-
<p>This is the modal content</p>
|
|
147
|
-
</${componentName}>
|
|
148
|
-
</div>
|
|
149
|
-
);`;
|
|
150
|
-
return createAppTemplate(componentName, 'useState', content);
|
|
118
|
+
function generateAppJsx(componentName, componentKebab, options = {}) {
|
|
119
|
+
const { lazyLoad = false } = options;
|
|
120
|
+
|
|
121
|
+
// Validate component exists (optional - could add warning)
|
|
122
|
+
if (!hasComponent(componentKebab)) {
|
|
123
|
+
console.warn(`Warning: No template found for component '${componentKebab}'. Using default template.`);
|
|
151
124
|
}
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
const
|
|
125
|
+
|
|
126
|
+
// Get template content from separate file
|
|
127
|
+
const templateContent = getComponentTemplate(componentKebab, componentName);
|
|
128
|
+
|
|
129
|
+
// Get required React imports for this component
|
|
130
|
+
const requiredImports = getComponentImports(componentKebab);
|
|
131
|
+
|
|
132
|
+
// Use template content if available, otherwise use default
|
|
133
|
+
const content = templateContent || ` return (
|
|
155
134
|
<div className="App">
|
|
156
135
|
<${componentName} />
|
|
157
136
|
</div>
|
|
158
137
|
);`;
|
|
159
138
|
|
|
160
|
-
|
|
139
|
+
// Use lazy loading template if requested
|
|
140
|
+
if (lazyLoad) {
|
|
141
|
+
return createAppTemplateWithLazyLoading(componentName, requiredImports, content);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return createAppTemplate(componentName, requiredImports, content);
|
|
161
145
|
}
|
|
162
146
|
|
|
163
147
|
// ============================================================================
|
|
@@ -166,23 +150,33 @@ function generateAppJsx(componentName, componentKebab) {
|
|
|
166
150
|
|
|
167
151
|
/**
|
|
168
152
|
* Generate index.jsx content
|
|
153
|
+
*
|
|
154
|
+
* Creates the main entry point file that renders the React app.
|
|
155
|
+
* Uses React 18's createRoot API for better performance.
|
|
156
|
+
*
|
|
157
|
+
* @returns {string} Complete index.jsx file content
|
|
169
158
|
*/
|
|
170
159
|
function generateIndexJs() {
|
|
171
|
-
return `import
|
|
160
|
+
return `import { StrictMode } from 'react';
|
|
172
161
|
import ReactDOM from 'react-dom/client';
|
|
173
162
|
import App from './App';
|
|
174
163
|
|
|
175
164
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
|
176
165
|
root.render(
|
|
177
|
-
<
|
|
166
|
+
<StrictMode>
|
|
178
167
|
<App />
|
|
179
|
-
</
|
|
168
|
+
</StrictMode>
|
|
180
169
|
);
|
|
181
170
|
`;
|
|
182
171
|
}
|
|
183
172
|
|
|
184
173
|
/**
|
|
185
174
|
* Generate index.html content
|
|
175
|
+
*
|
|
176
|
+
* Creates the HTML entry point with proper meta tags and root div.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} title - Page title to display in browser tab
|
|
179
|
+
* @returns {string} Complete index.html file content
|
|
186
180
|
*/
|
|
187
181
|
function generateIndexHtml(title) {
|
|
188
182
|
return `<!DOCTYPE html>
|
|
@@ -206,6 +200,16 @@ function generateIndexHtml(title) {
|
|
|
206
200
|
|
|
207
201
|
/**
|
|
208
202
|
* Generate package.json content
|
|
203
|
+
*
|
|
204
|
+
* Creates a package.json with React, Vite, and all necessary scripts.
|
|
205
|
+
* Configured as ES module with dev, build, and preview scripts.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} name - Project name (used as package name)
|
|
208
|
+
* @returns {Object} Package.json configuration object
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* const pkg = generatePackageJson('my-react-app');
|
|
212
|
+
* // Returns complete package.json object
|
|
209
213
|
*/
|
|
210
214
|
function generatePackageJson(name) {
|
|
211
215
|
return {
|
|
@@ -231,6 +235,11 @@ function generatePackageJson(name) {
|
|
|
231
235
|
|
|
232
236
|
/**
|
|
233
237
|
* Generate .gitignore content
|
|
238
|
+
*
|
|
239
|
+
* Creates a comprehensive .gitignore file for React/Vite projects.
|
|
240
|
+
* Includes patterns for dependencies, build outputs, environment files, and editors.
|
|
241
|
+
*
|
|
242
|
+
* @returns {string} Complete .gitignore file content
|
|
234
243
|
*/
|
|
235
244
|
function generateGitignore() {
|
|
236
245
|
return `# Dependencies
|
|
@@ -259,20 +268,63 @@ build/
|
|
|
259
268
|
|
|
260
269
|
/**
|
|
261
270
|
* Generate vite.config.js content
|
|
271
|
+
*
|
|
272
|
+
* Creates a minimal Vite configuration file with React plugin enabled.
|
|
273
|
+
*
|
|
274
|
+
* @param {boolean} withOptimization - Include code splitting optimizations
|
|
275
|
+
* @returns {string} Complete vite.config.js file content
|
|
262
276
|
*/
|
|
263
|
-
function generateViteConfig() {
|
|
277
|
+
function generateViteConfig(withOptimization = false) {
|
|
278
|
+
if (!withOptimization) {
|
|
279
|
+
return `import { defineConfig } from 'vite';
|
|
280
|
+
import react from '@vitejs/plugin-react';
|
|
281
|
+
|
|
282
|
+
// https://vitejs.dev/config/
|
|
283
|
+
export default defineConfig({
|
|
284
|
+
plugins: [react()],
|
|
285
|
+
});
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
|
|
264
289
|
return `import { defineConfig } from 'vite';
|
|
265
290
|
import react from '@vitejs/plugin-react';
|
|
266
291
|
|
|
267
292
|
// https://vitejs.dev/config/
|
|
268
293
|
export default defineConfig({
|
|
269
294
|
plugins: [react()],
|
|
295
|
+
build: {
|
|
296
|
+
rollupOptions: {
|
|
297
|
+
output: {
|
|
298
|
+
manualChunks: {
|
|
299
|
+
// Split vendor code into separate chunk
|
|
300
|
+
vendor: ['react', 'react-dom'],
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
// Enable code splitting
|
|
305
|
+
minify: 'terser',
|
|
306
|
+
terserOptions: {
|
|
307
|
+
compress: {
|
|
308
|
+
drop_console: true, // Remove console.log in production
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
},
|
|
270
312
|
});
|
|
271
313
|
`;
|
|
272
314
|
}
|
|
273
315
|
|
|
274
316
|
/**
|
|
275
317
|
* Generate README.md content
|
|
318
|
+
*
|
|
319
|
+
* Creates a comprehensive README with installation instructions,
|
|
320
|
+
* available scripts, project structure, and customization guidance.
|
|
321
|
+
*
|
|
322
|
+
* @param {string} name - Project name
|
|
323
|
+
* @param {string} componentName - Component name in PascalCase
|
|
324
|
+
* @returns {string} Complete README.md file content in Markdown format
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* const readme = generateReadme('my-app', 'Button');
|
|
276
328
|
*/
|
|
277
329
|
function generateReadme(name, componentName) {
|
|
278
330
|
return `# ${name}
|
|
@@ -339,6 +391,21 @@ MIT
|
|
|
339
391
|
// EXPORTS
|
|
340
392
|
// ============================================================================
|
|
341
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Public API exports for React template generation
|
|
396
|
+
*
|
|
397
|
+
* All generator functions for creating a complete React project structure.
|
|
398
|
+
* These functions are used by the CLI to generate project files.
|
|
399
|
+
*
|
|
400
|
+
* @exports generateAppJsx - Generate App.jsx with component examples
|
|
401
|
+
* @exports generateIndexJs - Generate index.jsx entry point
|
|
402
|
+
* @exports generateIndexHtml - Generate index.html
|
|
403
|
+
* @exports generatePackageJson - Generate package.json with dependencies
|
|
404
|
+
* @exports generateGitignore - Generate .gitignore file
|
|
405
|
+
* @exports generateViteConfig - Generate vite.config.js
|
|
406
|
+
* @exports generateReadme - Generate README.md documentation
|
|
407
|
+
* @exports createAppTemplateWithLazyLoading - Create lazy loaded App component
|
|
408
|
+
*/
|
|
342
409
|
export {
|
|
343
410
|
generateAppJsx,
|
|
344
411
|
generateIndexJs,
|
|
@@ -347,4 +414,5 @@ export {
|
|
|
347
414
|
generateGitignore,
|
|
348
415
|
generateViteConfig,
|
|
349
416
|
generateReadme,
|
|
417
|
+
createAppTemplateWithLazyLoading,
|
|
350
418
|
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic UI Component Templates
|
|
3
|
+
* Simple display components without complex state management
|
|
4
|
+
*
|
|
5
|
+
* @module templates/basic-components-templates
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const BASIC_TEMPLATES = {
|
|
9
|
+
alert: ` return (
|
|
10
|
+
<div className="App" style={{ padding: '40px', maxWidth: '600px', margin: '0 auto' }}>
|
|
11
|
+
<h1 style={{ marginBottom: '30px' }}>Alert Component Examples</h1>
|
|
12
|
+
|
|
13
|
+
<{ComponentName} type="success" title="Success!">
|
|
14
|
+
Your changes have been saved successfully.
|
|
15
|
+
</{ComponentName}>
|
|
16
|
+
|
|
17
|
+
<{ComponentName} type="error" title="Error">
|
|
18
|
+
Something went wrong. Please try again.
|
|
19
|
+
</{ComponentName}>
|
|
20
|
+
|
|
21
|
+
<{ComponentName} type="warning" title="Warning">
|
|
22
|
+
This action cannot be undone.
|
|
23
|
+
</{ComponentName}>
|
|
24
|
+
|
|
25
|
+
<{ComponentName} type="info" title="Information">
|
|
26
|
+
Check out our new features!
|
|
27
|
+
</{ComponentName}>
|
|
28
|
+
</div>
|
|
29
|
+
);`,
|
|
30
|
+
|
|
31
|
+
badge: ` return (
|
|
32
|
+
<div className="App" style={{ padding: '40px', maxWidth: '800px', margin: '0 auto' }}>
|
|
33
|
+
<h1 style={{ marginBottom: '30px' }}>Badge Component Examples</h1>
|
|
34
|
+
|
|
35
|
+
<div style={{ marginBottom: '30px' }}>
|
|
36
|
+
<h2>Basic Badges</h2>
|
|
37
|
+
<div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap' }}>
|
|
38
|
+
<{ComponentName} variant="primary">Primary</{ComponentName}>
|
|
39
|
+
<{ComponentName} variant="success">Success</{ComponentName}>
|
|
40
|
+
<{ComponentName} variant="warning">Warning</{ComponentName}>
|
|
41
|
+
<{ComponentName} variant="error">Error</{ComponentName}>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div style={{ marginBottom: '30px' }}>
|
|
46
|
+
<h2>Pill Badges</h2>
|
|
47
|
+
<div style={{ display: 'flex', gap: '1rem', flexWrap: 'wrap' }}>
|
|
48
|
+
<{ComponentName} pill variant="info">New</{ComponentName}>
|
|
49
|
+
<{ComponentName} pill variant="success">Hot</{ComponentName}>
|
|
50
|
+
<{ComponentName} pill variant="warning">Sale</{ComponentName}>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div style={{ marginBottom: '30px' }}>
|
|
55
|
+
<h2>Count Badges</h2>
|
|
56
|
+
<div style={{ display: 'flex', gap: '2rem', flexWrap: 'wrap' }}>
|
|
57
|
+
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
58
|
+
<button style={{ padding: '0.5rem 1rem', backgroundColor: '#3b82f6', color: 'white', border: 'none', borderRadius: '0.375rem' }}>
|
|
59
|
+
Messages
|
|
60
|
+
</button>
|
|
61
|
+
<{ComponentName} count={5} variant="error" size="small" />
|
|
62
|
+
</div>
|
|
63
|
+
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
64
|
+
<button style={{ padding: '0.5rem 1rem', backgroundColor: '#3b82f6', color: 'white', border: 'none', borderRadius: '0.375rem' }}>
|
|
65
|
+
Notifications
|
|
66
|
+
</button>
|
|
67
|
+
<{ComponentName} count={99} variant="primary" size="small" />
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div style={{ marginBottom: '30px' }}>
|
|
73
|
+
<h2>Dot Badges</h2>
|
|
74
|
+
<div style={{ display: 'flex', gap: '2rem', flexWrap: 'wrap' }}>
|
|
75
|
+
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
76
|
+
<div style={{ width: '48px', height: '48px', borderRadius: '50%', backgroundColor: '#e5e7eb', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '1.5rem' }}>
|
|
77
|
+
👤
|
|
78
|
+
</div>
|
|
79
|
+
<{ComponentName} dot variant="success" position="top-right" />
|
|
80
|
+
</div>
|
|
81
|
+
<div style={{ position: 'relative', display: 'inline-block' }}>
|
|
82
|
+
<div style={{ width: '48px', height: '48px', borderRadius: '50%', backgroundColor: '#e5e7eb', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '1.5rem' }}>
|
|
83
|
+
👤
|
|
84
|
+
</div>
|
|
85
|
+
<{ComponentName} dot variant="error" position="top-left" />
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
);`,
|
|
91
|
+
|
|
92
|
+
button: ` const handleClick = () => {
|
|
93
|
+
alert('Button clicked!');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className="App" style={{
|
|
98
|
+
padding: '40px',
|
|
99
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
100
|
+
backgroundColor: '#f5f5f5',
|
|
101
|
+
minHeight: '100vh'
|
|
102
|
+
}}>
|
|
103
|
+
<h1 style={{ marginBottom: '30px', color: '#333' }}>{ComponentName} Component Examples</h1>
|
|
104
|
+
|
|
105
|
+
<div style={{ marginBottom: '30px' }}>
|
|
106
|
+
<h3 style={{ marginBottom: '15px', color: '#666' }}>Variants:</h3>
|
|
107
|
+
<div style={{ display: 'flex', gap: '15px', flexWrap: 'wrap' }}>
|
|
108
|
+
<{ComponentName} variant="primary" onClick={handleClick}>Primary</{ComponentName}>
|
|
109
|
+
<{ComponentName} variant="secondary" onClick={handleClick}>Secondary</{ComponentName}>
|
|
110
|
+
<{ComponentName} variant="success" onClick={handleClick}>Success</{ComponentName}>
|
|
111
|
+
<{ComponentName} variant="danger" onClick={handleClick}>Danger</{ComponentName}>
|
|
112
|
+
<{ComponentName} variant="outline" onClick={handleClick}>Outline</{ComponentName}>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div style={{ marginBottom: '30px' }}>
|
|
117
|
+
<h3 style={{ marginBottom: '15px', color: '#666' }}>Sizes:</h3>
|
|
118
|
+
<div style={{ display: 'flex', gap: '15px', alignItems: 'center', flexWrap: 'wrap' }}>
|
|
119
|
+
<{ComponentName} size="small" onClick={handleClick}>Small</{ComponentName}>
|
|
120
|
+
<{ComponentName} size="medium" onClick={handleClick}>Medium</{ComponentName}>
|
|
121
|
+
<{ComponentName} size="large" onClick={handleClick}>Large</{ComponentName}>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div style={{ marginBottom: '30px' }}>
|
|
126
|
+
<h3 style={{ marginBottom: '15px', color: '#666' }}>States:</h3>
|
|
127
|
+
<div style={{ display: 'flex', gap: '15px', flexWrap: 'wrap' }}>
|
|
128
|
+
<{ComponentName} onClick={handleClick}>Normal</{ComponentName}>
|
|
129
|
+
<{ComponentName} disabled>Disabled</{ComponentName}>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
);`,
|
|
134
|
+
|
|
135
|
+
card: ` return (
|
|
136
|
+
<div className="App" style={{ padding: '40px', backgroundColor: '#f5f5f5', minHeight: '100vh' }}>
|
|
137
|
+
<h1 style={{ marginBottom: '30px' }}>{ComponentName} Component</h1>
|
|
138
|
+
<{ComponentName}
|
|
139
|
+
title="Example Card"
|
|
140
|
+
description="This is an example card component with a beautiful design"
|
|
141
|
+
image="https://via.placeholder.com/400x200"
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
);`,
|
|
145
|
+
|
|
146
|
+
counter: ` return (
|
|
147
|
+
<div className="App" style={{ padding: '40px' }}>
|
|
148
|
+
<h1>Counter Component</h1>
|
|
149
|
+
<{ComponentName}
|
|
150
|
+
initialValue={0}
|
|
151
|
+
min={0}
|
|
152
|
+
max={100}
|
|
153
|
+
onChange={(value) => console.log('Count:', value)}
|
|
154
|
+
/>
|
|
155
|
+
</div>
|
|
156
|
+
);`,
|
|
157
|
+
};
|