create-template-html-css 2.0.4 → 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.
Files changed (99) hide show
  1. package/CHANGELOG.md +436 -0
  2. package/CODE-SPLITTING-GUIDE.md +274 -0
  3. package/COMPONENTS-GALLERY.html +143 -8
  4. package/HTML-VS-REACT.md +289 -0
  5. package/QUICKSTART-REACT.md +293 -0
  6. package/REACT-SUPPORT-SUMMARY.md +235 -0
  7. package/README.md +261 -12
  8. package/bin/cli.js +100 -759
  9. package/bin/commands/create.js +288 -0
  10. package/bin/commands/gallery.js +42 -0
  11. package/bin/commands/insert.js +123 -0
  12. package/bin/commands/list.js +73 -0
  13. package/package.json +10 -3
  14. package/src/component-choices.js +7 -0
  15. package/src/components-registry.js +112 -0
  16. package/src/format-utils.js +49 -0
  17. package/src/generator.js +83 -594
  18. package/src/generators/color-schemes.js +78 -0
  19. package/src/generators/color-utils.js +108 -0
  20. package/src/generators/component-filters.js +151 -0
  21. package/src/generators/html-generators.js +180 -0
  22. package/src/generators/validation.js +43 -0
  23. package/src/index.js +2 -1
  24. package/src/inserter.js +55 -233
  25. package/src/inserters/backup-utils.js +20 -0
  26. package/src/inserters/component-loader.js +68 -0
  27. package/src/inserters/html-utils.js +31 -0
  28. package/src/inserters/indentation-utils.js +90 -0
  29. package/src/inserters/validation-utils.js +49 -0
  30. package/src/react-component-choices.js +97 -0
  31. package/src/react-component-templates.js +182 -0
  32. package/src/react-file-operations.js +172 -0
  33. package/src/react-generator.js +219 -0
  34. package/src/react-templates.js +418 -0
  35. package/src/templates/basic-components-templates.js +157 -0
  36. package/src/templates/form-components-templates.js +194 -0
  37. package/src/templates/interactive-components-templates.js +139 -0
  38. package/src/utils/file-utils.js +97 -0
  39. package/src/utils/path-utils.js +32 -0
  40. package/src/utils/string-utils.js +51 -0
  41. package/src/utils/template-loader.js +91 -0
  42. package/templates/_shared/PATTERNS.md +246 -0
  43. package/templates/_shared/README.md +74 -0
  44. package/templates/_shared/base.css +18 -0
  45. package/templates/blackjack/index.html +1 -1
  46. package/templates/breakout/index.html +1 -1
  47. package/templates/connect-four/index.html +1 -1
  48. package/templates/dice-game/index.html +1 -1
  49. package/templates/flappy-bird/index.html +1 -1
  50. package/templates/pong/index.html +1 -1
  51. package/templates/skeleton/index.html +4 -4
  52. package/templates/slot-machine/index.html +1 -1
  53. package/templates/tetris/index.html +1 -1
  54. package/templates-react/README.md +126 -0
  55. package/templates-react/alert/Alert.css +158 -0
  56. package/templates-react/alert/Alert.example.jsx +106 -0
  57. package/templates-react/alert/Alert.jsx +61 -0
  58. package/templates-react/badge/Badge.css +196 -0
  59. package/templates-react/badge/Badge.example.jsx +182 -0
  60. package/templates-react/badge/Badge.jsx +44 -0
  61. package/templates-react/button/Button.css +88 -0
  62. package/templates-react/button/Button.example.jsx +40 -0
  63. package/templates-react/button/Button.jsx +29 -0
  64. package/templates-react/card/Card.css +86 -0
  65. package/templates-react/card/Card.example.jsx +49 -0
  66. package/templates-react/card/Card.jsx +35 -0
  67. package/templates-react/checkbox/Checkbox.css +217 -0
  68. package/templates-react/checkbox/Checkbox.example.jsx +141 -0
  69. package/templates-react/checkbox/Checkbox.jsx +82 -0
  70. package/templates-react/counter/Counter.css +99 -0
  71. package/templates-react/counter/Counter.example.jsx +45 -0
  72. package/templates-react/counter/Counter.jsx +70 -0
  73. package/templates-react/dropdown/Dropdown.css +237 -0
  74. package/templates-react/dropdown/Dropdown.example.jsx +98 -0
  75. package/templates-react/dropdown/Dropdown.jsx +154 -0
  76. package/templates-react/form/Form.css +128 -0
  77. package/templates-react/form/Form.example.jsx +64 -0
  78. package/templates-react/form/Form.jsx +125 -0
  79. package/templates-react/input/Input.css +113 -0
  80. package/templates-react/input/Input.example.jsx +82 -0
  81. package/templates-react/input/Input.jsx +87 -0
  82. package/templates-react/modal/Modal.css +152 -0
  83. package/templates-react/modal/Modal.example.jsx +90 -0
  84. package/templates-react/modal/Modal.jsx +46 -0
  85. package/templates-react/navbar/Navbar.css +139 -0
  86. package/templates-react/navbar/Navbar.example.jsx +37 -0
  87. package/templates-react/navbar/Navbar.jsx +62 -0
  88. package/templates-react/progress/Progress.css +247 -0
  89. package/templates-react/progress/Progress.example.jsx +244 -0
  90. package/templates-react/progress/Progress.jsx +79 -0
  91. package/templates-react/switch/Switch.css +244 -0
  92. package/templates-react/switch/Switch.example.jsx +221 -0
  93. package/templates-react/switch/Switch.jsx +98 -0
  94. package/templates-react/todo-list/TodoList.css +236 -0
  95. package/templates-react/todo-list/TodoList.example.jsx +15 -0
  96. package/templates-react/todo-list/TodoList.jsx +84 -0
  97. package/templates-react/tooltip/Tooltip.css +165 -0
  98. package/templates-react/tooltip/Tooltip.example.jsx +166 -0
  99. package/templates-react/tooltip/Tooltip.jsx +176 -0
@@ -0,0 +1,176 @@
1
+
2
+ import './Tooltip.css';
3
+ import { useState, useRef, useEffect } from 'react';
4
+
5
+ function Tooltip({
6
+ children,
7
+ content,
8
+ position = 'top',
9
+ trigger = 'hover',
10
+ delay = 200,
11
+ arrow = true,
12
+ maxWidth = '200px',
13
+ disabled = false,
14
+ className = ''
15
+ }) {
16
+ const [isVisible, setIsVisible] = useState(false);
17
+ const [tooltipPosition, setTooltipPosition] = useState({});
18
+ const triggerRef = useRef(null);
19
+ const tooltipRef = useRef(null);
20
+ const timeoutRef = useRef(null);
21
+
22
+ const calculatePosition = () => {
23
+ if (!triggerRef.current || !tooltipRef.current) return;
24
+
25
+ const triggerRect = triggerRef.current.getBoundingClientRect();
26
+ const tooltipRect = tooltipRef.current.getBoundingClientRect();
27
+ const gap = arrow ? 12 : 8;
28
+
29
+ let top, left;
30
+
31
+ switch (position) {
32
+ case 'top':
33
+ top = triggerRect.top - tooltipRect.height - gap;
34
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2;
35
+ break;
36
+ case 'bottom':
37
+ top = triggerRect.bottom + gap;
38
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2;
39
+ break;
40
+ case 'left':
41
+ top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2;
42
+ left = triggerRect.left - tooltipRect.width - gap;
43
+ break;
44
+ case 'right':
45
+ top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2;
46
+ left = triggerRect.right + gap;
47
+ break;
48
+ default:
49
+ top = triggerRect.top - tooltipRect.height - gap;
50
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2;
51
+ }
52
+
53
+ // Keep tooltip within viewport
54
+ const padding = 8;
55
+ if (left < padding) left = padding;
56
+ if (left + tooltipRect.width > window.innerWidth - padding) {
57
+ left = window.innerWidth - tooltipRect.width - padding;
58
+ }
59
+ if (top < padding) top = padding;
60
+ if (top + tooltipRect.height > window.innerHeight - padding) {
61
+ top = window.innerHeight - tooltipRect.height - padding;
62
+ }
63
+
64
+ setTooltipPosition({ top, left });
65
+ };
66
+
67
+ const showTooltip = () => {
68
+ if (disabled) return;
69
+
70
+ if (delay > 0) {
71
+ timeoutRef.current = setTimeout(() => {
72
+ setIsVisible(true);
73
+ }, delay);
74
+ } else {
75
+ setIsVisible(true);
76
+ }
77
+ };
78
+
79
+ const hideTooltip = () => {
80
+ if (timeoutRef.current) {
81
+ clearTimeout(timeoutRef.current);
82
+ }
83
+ setIsVisible(false);
84
+ };
85
+
86
+ const handleMouseEnter = () => {
87
+ if (trigger === 'hover' || trigger === 'both') {
88
+ showTooltip();
89
+ }
90
+ };
91
+
92
+ const handleMouseLeave = () => {
93
+ if (trigger === 'hover' || trigger === 'both') {
94
+ hideTooltip();
95
+ }
96
+ };
97
+
98
+ const handleClick = () => {
99
+ if (trigger === 'click' || trigger === 'both') {
100
+ if (isVisible) {
101
+ hideTooltip();
102
+ } else {
103
+ showTooltip();
104
+ }
105
+ }
106
+ };
107
+
108
+ const handleFocus = () => {
109
+ if (trigger === 'focus') {
110
+ showTooltip();
111
+ }
112
+ };
113
+
114
+ const handleBlur = () => {
115
+ if (trigger === 'focus') {
116
+ hideTooltip();
117
+ }
118
+ };
119
+
120
+ useEffect(() => {
121
+ if (isVisible) {
122
+ calculatePosition();
123
+ window.addEventListener('scroll', calculatePosition);
124
+ window.addEventListener('resize', calculatePosition);
125
+ }
126
+
127
+ return () => {
128
+ window.removeEventListener('scroll', calculatePosition);
129
+ window.removeEventListener('resize', calculatePosition);
130
+ };
131
+ }, [isVisible]);
132
+
133
+ useEffect(() => {
134
+ return () => {
135
+ if (timeoutRef.current) {
136
+ clearTimeout(timeoutRef.current);
137
+ }
138
+ };
139
+ }, []);
140
+
141
+ if (!content) return <>{children}</>;
142
+
143
+ return (
144
+ <>
145
+ <span
146
+ ref={triggerRef}
147
+ className={`tooltip-trigger ${className}`}
148
+ onMouseEnter={handleMouseEnter}
149
+ onMouseLeave={handleMouseLeave}
150
+ onClick={handleClick}
151
+ onFocus={handleFocus}
152
+ onBlur={handleBlur}
153
+ aria-describedby={isVisible ? 'tooltip' : undefined}
154
+ >
155
+ {children}
156
+ </span>
157
+
158
+ {isVisible && (
159
+ <div
160
+ ref={tooltipRef}
161
+ id="tooltip"
162
+ className={`tooltip tooltip-${position} ${arrow ? 'tooltip-arrow' : ''}`}
163
+ style={{
164
+ ...tooltipPosition,
165
+ maxWidth
166
+ }}
167
+ role="tooltip"
168
+ >
169
+ {content}
170
+ </div>
171
+ )}
172
+ </>
173
+ );
174
+ }
175
+
176
+ export default Tooltip;