-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
554 lines (483 loc) · 17.4 KB
/
Copy pathindex.html
File metadata and controls
554 lines (483 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>StorePress Tooltip — Demo & Usage</title>
<link rel="stylesheet" href="./build/style-tooltip.css"/>
<script src="./build/storepress-utils.js"></script>
<script src="./build/tooltip.js"></script>
<style>
:root {
color-scheme : light dark;
--page-bg : #F6F7F9;
--page-fg : #1C1E21;
--card-bg : #FFFFFF;
--card-border : #E3E5E8;
--muted : #6B7280;
--accent : #6D28D9;
--code-bg : #F0F0F3;
}
* {
box-sizing : border-box;
}
body {
font-family : -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
background : var(--page-bg);
color : var(--page-fg);
margin : 0;
line-height : 1.5;
}
header.hero {
padding : 56px 24px 40px;
text-align : center;
background : linear-gradient(180deg, #EDE9FE 0%, var(--page-bg) 100%);
border-bottom : 1px solid var(--card-border);
}
header.hero h1 {
margin : 0 0 8px;
font-size : 2.1rem;
}
header.hero p {
margin : 0 auto;
max-width : 640px;
color : var(--muted);
}
nav.toc {
display : flex;
flex-wrap : wrap;
gap : 8px;
justify-content : center;
margin-top : 20px;
}
nav.toc a {
font-size : 0.85rem;
padding : 6px 12px;
border-radius : 999px;
background : var(--card-bg);
border : 1px solid var(--card-border);
color : var(--accent);
text-decoration : none;
}
nav.toc a:hover {
background : var(--accent);
color : #FFFFFF;
border-color : var(--accent);
}
main {
max-width : 960px;
margin : 0 auto;
padding : 40px 24px 100px;
}
section {
margin-bottom : 56px;
scroll-margin-top : 20px;
}
section h2 {
font-size : 1.35rem;
margin-bottom : 4px;
}
section .lede {
color : var(--muted);
margin-top : 0;
margin-bottom : 20px;
max-width : 700px;
}
.card {
background : var(--card-bg);
border : 1px solid var(--card-border);
border-radius : 12px;
padding : 28px;
}
.row {
display : flex;
flex-wrap : wrap;
gap : 20px;
align-items : center;
}
.row.spaced {
justify-content : space-between;
}
.swatch {
--item-width : 48px;
width : var(--item-width);
aspect-ratio : 1;
border-radius : 50%;
position : relative;
cursor : pointer;
border : none;
flex-shrink : 0;
}
.swatch:focus-visible {
outline : 2px solid var(--accent);
outline-offset : 3px;
}
.pill {
padding : 10px 18px;
border-radius : 8px;
border : none;
background : #333333;
color : #FFFFFF;
cursor : pointer;
font-size : 0.9rem;
position : relative;
}
.chip-btn {
padding : 8px 14px;
border-radius : 8px;
border : 1px solid var(--card-border);
background : var(--card-bg);
color : var(--page-fg);
cursor : pointer;
font-size : 0.85rem;
}
.chip-btn:hover {
border-color : var(--accent);
color : var(--accent);
}
pre .line-number {
float : left;
margin : 0 1em 0 -1em;
border-right : 1px solid;
text-align : right;
}
pre .line-number span {
display : block;
padding : 0 .5em 0 1em;
}
pre .cl {
display : block;
clear : both;
}
code, pre {
font-family : ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size : 0.85rem;
}
code {
background : var(--code-bg);
padding : 2px 6px;
border-radius : 4px;
}
pre {
background : var(--code-bg);
padding : 16px;
border-radius : 8px;
overflow-x : auto;
margin : 14px 0 0;
}
pre code {
background : none;
padding : 0;
}
table {
width : 100%;
border-collapse : collapse;
font-size : 0.85rem;
margin-top : 14px;
}
th, td {
text-align : left;
padding : 8px 10px;
border-bottom : 1px solid var(--card-border);
vertical-align : top;
}
th {
color : var(--muted);
font-weight : 600;
}
.edge-row {
display : flex;
justify-content : space-between;
margin-top : 40px;
}
.edge-row .swatch {
margin : 0;
}
.rtl-block {
direction : rtl;
padding : 20px;
border : 1px dashed var(--card-border);
border-radius : 8px;
margin-top : 16px;
}
.status {
margin-top : 16px;
font-size : 0.85rem;
color : var(--muted);
min-height : 1.2em;
}
.badge {
display : inline-block;
font-size : 0.7rem;
text-transform : uppercase;
letter-spacing : 0.04em;
background : var(--accent);
color : #FFFFFF;
padding : 2px 8px;
border-radius : 999px;
margin-left : 8px;
vertical-align : middle;
}
@media (prefers-color-scheme : dark) {
:root {
--page-bg : #000000;
--page-fg : #E7E8EA;
--card-bg : #1F2023;
--card-border : #2C2D31;
--muted : #9A9BA1;
--code-bg : #26272B;
}
header.hero {
background : linear-gradient(180deg, #040D51 0%, var(--page-bg) 100%);
}
}
</style>
</head>
<body>
<header class="hero">
<h1>StorePress Tooltip</h1>
<p>A lightweight, dependency-free tooltip plugin driven entirely by <code>data-*</code> attributes and CSS custom properties. No JS positioning math to fight, no extra markup — hover, focus, or tap any example below.</p>
<nav class="toc">
<a href="#basic">Basic</a>
<a href="#colors">Colors</a>
<a href="#sizing">Sizing</a>
<a href="#image">Image tooltips</a>
<a href="#edges">Viewport edges</a>
<a href="#rtl">RTL</a>
<a href="#accessibility">Accessibility</a>
<a href="#api">JS API</a>
<a href="#install">Install</a>
</nav>
</header>
<main>
<section id="basic">
<h2>Basic usage</h2>
<p class="lede">Add <code>data-storepress-tooltip="…"</code> to any element. That's it — the plugin auto-initializes on <code>DOMContentLoaded</code> and reads the tooltip text straight from the attribute.</p>
<div class="card row">
<button class="pill" type="button" data-storepress-tooltip="Hover over me">Hover me</button>
<a href="#basic" class="pill" style="background: var(--accent); text-decoration:none; display:inline-block;" data-storepress-tooltip="Links work too">A link</a>
<span class="pill" style="background:#2563EB;" tabindex="0" data-storepress-tooltip="Focus me with Tab">Focusable span</span>
</div>
<pre><code><button data-storepress-tooltip="Hover over me">Hover me</button>
<a href="#" data-storepress-tooltip="Links work too">A link</a>
<span tabindex="0" data-storepress-tooltip="Focus me with Tab">Focusable span</span></code></pre>
</section>
<section id="colors">
<h2>Custom colors</h2>
<p class="lede">Styling is entirely CSS-driven. Override <code>--tooltip-text-color</code> and <code>--tooltip-background-color</code> per element (or scope them to any selector).</p>
<div class="card row">
<button class="pill" type="button" data-storepress-tooltip="Default colors">Default</button>
<button class="pill" style="--tooltip-background-color:#E31616; --tooltip-text-color:#FFFFFF;" type="button" data-storepress-tooltip="Danger style">Danger</button>
<button class="pill" style="--tooltip-background-color:#16A34A; --tooltip-text-color:#FFFFFF;" type="button" data-storepress-tooltip="Success style">Success</button>
<button class="pill" style="--tooltip-background-color:#EAB308; --tooltip-text-color:#1C1E21;" type="button" data-storepress-tooltip="Warning style">Warning</button>
<button class="pill" style="--tooltip-background-color:#FFFFFF; --tooltip-text-color:#111827; box-shadow: inset 0 0 0 1px #D1D5DB;" type="button" data-storepress-tooltip="Light style">Light</button>
</div>
<pre><code>
[data-storepress-tooltip] {
--tooltip-background-color: #e31616;
--tooltip-text-color: #ffffff;
}</code></pre>
</section>
<section id="sizing">
<h2>Sizing & spacing</h2>
<p class="lede">Fine-tune the bubble with <code>--tooltip-font-size</code>, <code>--tooltip-max-width</code>, <code>--tooltip-padding</code>, <code>--tooltip-offset</code> (distance from the trigger) and <code>--tooltip-angle</code> (arrow size).</p>
<div class="card row">
<button class="pill" type="button" data-storepress-tooltip="Default sizing">Default</button>
<button class="pill" style="--tooltip-font-size:11px; --tooltip-padding:6px; --tooltip-offset:2px; --tooltip-angle:3px;" type="button" data-storepress-tooltip="Compact">Compact</button>
<button class="pill" style="--tooltip-font-size:18px; --tooltip-padding:14px; --tooltip-offset:12px; --tooltip-max-width:260px;" type="button" data-storepress-tooltip="A larger tooltip with more breathing room and a wider max-width for longer copy.">Large / wide</button>
</div>
<table>
<thead>
<tr>
<th>Custom property</th>
<th>Purpose</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--tooltip-text-color</code></td>
<td>Text color</td>
<td><code>#fff</code></td>
</tr>
<tr>
<td><code>--tooltip-background-color</code></td>
<td>Bubble + arrow color</td>
<td><code>#333</code></td>
</tr>
<tr>
<td><code>--tooltip-font-size</code></td>
<td>Text size</td>
<td><code>15px</code></td>
</tr>
<tr>
<td><code>--tooltip-max-width</code></td>
<td>Bubble max width (and image size)</td>
<td><code>150px</code></td>
</tr>
<tr>
<td><code>--tooltip-min-height</code></td>
<td>Bubble min height</td>
<td><code>30px</code></td>
</tr>
<tr>
<td><code>--tooltip-padding</code></td>
<td>Bubble padding</td>
<td><code>10px</code></td>
</tr>
<tr>
<td><code>--tooltip-offset</code></td>
<td>Gap between trigger and bubble</td>
<td><code>5px</code></td>
</tr>
<tr>
<td><code>--tooltip-angle</code></td>
<td>Arrow size</td>
<td><code>5px</code></td>
</tr>
<tr>
<td><code>--tooltip-image</code></td>
<td>Image URL for image tooltips</td>
<td><code>none</code></td>
</tr>
</tbody>
</table>
</section>
<section id="image">
<h2>Image tooltips</h2>
<p class="lede">Set the <code>--tooltip-image</code> custom property to a <code>url(...)</code> and the same attribute doubles as an image preview. Add <code>.storepress-tooltip-type-image</code> as a fallback for browsers without <code>@container style()</code> support.</p>
<div class="card row">
<div class="swatch storepress-tooltip-type-image" tabindex="0" style="background-color: darkred; --tooltip-image: url('https://picsum.photos/seed/sp1/150')" data-storepress-tooltip="Random image one"></div>
<div class="swatch storepress-tooltip-type-image" tabindex="0" style="background-color: coral; --tooltip-image: url('https://picsum.photos/seed/sp2/150')" data-storepress-tooltip="Random image two"></div>
<div class="swatch storepress-tooltip-type-image" tabindex="0" style="background-color: cadetblue; --tooltip-image: url('https://picsum.photos/seed/sp3/150')" data-storepress-tooltip="Random image three"></div>
</div>
<pre><code><div
class="storepress-tooltip-type-image"
style="--tooltip-image: url('images/sample.jpg')"
data-storepress-tooltip="Image caption"></div></code></pre>
</section>
<section id="edges">
<h2>Viewport-edge handling</h2>
<p class="lede">Tooltips shift horizontally to stay inside the viewport instead of clipping off-screen. Try the swatches pinned to the left and right edges of this card.</p>
<div class="card">
<div class="edge-row">
<button class="pill" style="--tooltip-max-width:220px;" type="button" data-storepress-tooltip="I stay inside the viewport even when my trigger sits at the left edge.">Left edge</button>
<button class="pill" style="--tooltip-max-width:220px;" type="button" data-storepress-tooltip="I stay inside the viewport even when my trigger sits at the right edge.">Right edge</button>
</div>
</div>
</section>
<section id="rtl">
<h2>RTL support</h2>
<p class="lede">Wrap content in a <code>dir="rtl"</code> container and the plugin automatically mirrors tooltip and arrow offsets.</p>
<div class="card">
<div class="rtl-block">
<div class="row">
<button class="pill" type="button" data-storepress-tooltip="نص تلميح بسيط">تحوم هنا</button>
<button class="pill" type="button" data-storepress-tooltip="یک نکته ابزار ساده">روی من نگه دار</button>
</div>
</div>
</div>
</section>
<section id="accessibility">
<h2>Accessibility</h2>
<p class="lede">Elements with <code>tabindex</code> show their tooltip on <code>:focus-visible</code> as well as hover, so keyboard users get the same information. Motion is disabled automatically when the OS <code>prefers-reduced-motion</code>.</p>
<div class="card row">
<button class="pill" type="button" tabindex="0" data-storepress-tooltip="Tab to me, then Shift+Tab back">Try Tab / Shift+Tab</button>
</div>
</section>
<section id="api">
<h2>JavaScript API</h2>
<p class="lede">Every tooltip is controllable at runtime through <code>StorePressTooltip</code> (or <code>StorePress.Utils.getStorePressPlugin('tooltip')</code> when using the global build).</p>
<div class="card">
<div class="row spaced">
<div class="row">
<span class="pill" id="api-target" type="button" tabindex="0" data-storepress-tooltip="Watch me while you click the buttons">API target</span>
</div>
<div class="row">
<button class="chip-btn" id="btn-destroy">destroy()</button>
<button class="chip-btn" id="btn-init">init()</button>
<button class="chip-btn" id="btn-reload">reload()</button>
<button class="chip-btn" id="btn-get">get() instance count</button>
</div>
</div>
<p class="status" id="api-status">Ready.</p>
</div>
<pre><code>import StorePressTooltip from '@storepress/tooltip'
document.addEventListener('DOMContentLoaded', () => {
StorePressTooltip.init() // (re)attach events to matching elements
StorePressTooltip.destroy() // detach events, keep tooltips queryable
StorePressTooltip.reload() // destroy() + init()
})
// From anywhere else, without importing the module directly:
const Tooltip = StorePress.Utils.getStorePressPlugin('tooltip')
Tooltip.destroy()
Tooltip.init()
const all = StorePress.Utils.getStorePressPlugin('tooltip').get()
const one = StorePress.Utils.getPluginInstance('#api-target', 'tooltip')</code></pre>
</section>
<section id="install">
<h2>Install & wire up</h2>
<p class="lede">Two ways to use this in your own project.</p>
<div class="card">
<p><strong>1. Prebuilt (this demo's approach)</strong> — after <code>npm install && npm run build</code>, load the three build files:</p>
<pre><code><link rel="stylesheet" href="./build/style-tooltip.css" />
<script src="./build/storepress-utils.js"></script>
<script src="./build/tooltip.js"></script>
<button data-storepress-tooltip="Tooltip text">Hover</button></code></pre>
<p><strong>2. As a npm package</strong> in a bundled project:</p>
<pre><code>npm i @storepress/tooltip @storepress/utils --save</code></pre>
<pre><code>// custom-tooltip.scss
@use "~@storepress/tooltip/src/mixins" as tooltip;
@include tooltip.init();
[data-storepress-tooltip] {
--tooltip-text-color: #ffffff;
--tooltip-background-color: #e31616;
}</code></pre>
<pre><code>// scripts.js
import StorePressTooltip from '@storepress/tooltip'
document.addEventListener('DOMContentLoaded', () => {
StorePressTooltip.init()
})</code></pre>
<p>See <code>README.md</code> for the full API, including <code>reset()</code> per-instance and RTL/reduced-motion notes.</p>
</div>
</section>
</main>
<script>
document.addEventListener('DOMContentLoaded', () => {
const statusEl = document.getElementById('api-status');
const Tooltip = StorePress.Utils.getStorePressPlugin('tooltip');
const setStatus = (message) => {
statusEl.textContent = message;
};
document.getElementById('btn-destroy').addEventListener('click', () => {
Tooltip.destroy();
setStatus('destroy() called — hover/focus events removed from all tooltips. Now it is plain css tooltip.');
});
document.getElementById('btn-init').addEventListener('click', () => {
Tooltip.init();
setStatus('init() called — hover/focus events (re)attached to all tooltips.');
});
document.getElementById('btn-reload').addEventListener('click', () => {
Tooltip.reload();
setStatus('reload() called — destroy() + init() in one step.');
});
document.getElementById('btn-get').addEventListener('click', () => {
const instances = Tooltip.get();
setStatus(`get() returned ${instances.length} active tooltip instance(s).`);
});
});
(function () {
const pre = document.getElementsByTagName('pre'),
pl = pre.length;
for (let i = 0; i < pl; i++) {
pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="cl"></span>';
let num = pre[i].innerHTML.split(/\n/).length;
for (let j = 0; j < num; j++) {
let line_num = pre[i].getElementsByTagName('span')[0];
line_num.innerHTML += '<span>' + (j + 1) + '</span>';
}
}
})();
</script>
</body>
</html>