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.
- package/CHANGELOG.md +436 -0
- package/CODE-SPLITTING-GUIDE.md +274 -0
- package/COMPONENTS-GALLERY.html +143 -8
- package/HTML-VS-REACT.md +289 -0
- package/QUICKSTART-REACT.md +293 -0
- package/REACT-SUPPORT-SUMMARY.md +235 -0
- package/README.md +261 -12
- package/bin/cli.js +100 -759
- package/bin/commands/create.js +288 -0
- package/bin/commands/gallery.js +42 -0
- package/bin/commands/insert.js +123 -0
- package/bin/commands/list.js +73 -0
- package/package.json +10 -3
- package/src/component-choices.js +7 -0
- package/src/components-registry.js +112 -0
- package/src/format-utils.js +49 -0
- package/src/generator.js +83 -594
- package/src/generators/color-schemes.js +78 -0
- package/src/generators/color-utils.js +108 -0
- package/src/generators/component-filters.js +151 -0
- package/src/generators/html-generators.js +180 -0
- package/src/generators/validation.js +43 -0
- package/src/index.js +2 -1
- package/src/inserter.js +55 -233
- package/src/inserters/backup-utils.js +20 -0
- package/src/inserters/component-loader.js +68 -0
- package/src/inserters/html-utils.js +31 -0
- package/src/inserters/indentation-utils.js +90 -0
- package/src/inserters/validation-utils.js +49 -0
- package/src/react-component-choices.js +97 -0
- package/src/react-component-templates.js +182 -0
- package/src/react-file-operations.js +172 -0
- package/src/react-generator.js +219 -0
- package/src/react-templates.js +418 -0
- 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/src/utils/file-utils.js +97 -0
- package/src/utils/path-utils.js +32 -0
- package/src/utils/string-utils.js +51 -0
- package/src/utils/template-loader.js +91 -0
- package/templates/_shared/PATTERNS.md +246 -0
- package/templates/_shared/README.md +74 -0
- package/templates/_shared/base.css +18 -0
- package/templates/blackjack/index.html +1 -1
- package/templates/breakout/index.html +1 -1
- package/templates/connect-four/index.html +1 -1
- package/templates/dice-game/index.html +1 -1
- package/templates/flappy-bird/index.html +1 -1
- package/templates/pong/index.html +1 -1
- package/templates/skeleton/index.html +4 -4
- package/templates/slot-machine/index.html +1 -1
- package/templates/tetris/index.html +1 -1
- package/templates-react/README.md +126 -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.css +88 -0
- package/templates-react/button/Button.example.jsx +40 -0
- package/templates-react/button/Button.jsx +29 -0
- package/templates-react/card/Card.css +86 -0
- package/templates-react/card/Card.example.jsx +49 -0
- package/templates-react/card/Card.jsx +35 -0
- 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.css +99 -0
- package/templates-react/counter/Counter.example.jsx +45 -0
- package/templates-react/counter/Counter.jsx +70 -0
- 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.css +128 -0
- package/templates-react/form/Form.example.jsx +64 -0
- package/templates-react/form/Form.jsx +125 -0
- 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.css +152 -0
- package/templates-react/modal/Modal.example.jsx +90 -0
- package/templates-react/modal/Modal.jsx +46 -0
- 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.css +236 -0
- package/templates-react/todo-list/TodoList.example.jsx +15 -0
- package/templates-react/todo-list/TodoList.jsx +84 -0
- 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
|
@@ -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;
|