@manufosela/device-card-stack 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 manufosela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @manufosela/device-card-stack
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@manufosela/device-card-stack)](https://www.npmjs.com/package/@manufosela/device-card-stack)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Accordion-style card stack with 3D perspective and image preview panel, built with [Lit 3](https://lit.dev/).
7
+
8
+ Cards expand on click to reveal their content while a side panel displays the associated image. On mobile viewports the preview panel is hidden and images appear inline within each card. Supports keyboard navigation and ARIA tablist semantics.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @manufosela/device-card-stack
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```javascript
19
+ import '@manufosela/device-card-stack';
20
+ ```
21
+
22
+ ```html
23
+ <device-card-stack>
24
+ <div slot="card" data-title="Mountain" data-color="#1a1a2e"
25
+ data-image="mountain.jpg" data-num="01">
26
+ <p>Mountain landscape description.</p>
27
+ </div>
28
+ <div slot="card" data-title="Ocean" data-color="#16213e"
29
+ data-image="ocean.jpg" data-num="02">
30
+ <p>Ocean waves description.</p>
31
+ </div>
32
+ <div slot="card" data-title="Forest" data-color="#0f3460"
33
+ data-image="forest.jpg" data-num="03">
34
+ <p>Forest path description.</p>
35
+ </div>
36
+ </device-card-stack>
37
+ ```
38
+
39
+ ## Attributes
40
+
41
+ | Attribute | Type | Default | Description |
42
+ |-----------|------|---------|-------------|
43
+ | `active-index` | Number | `0` | Index of the currently active card |
44
+ | `mobile-breakpoint` | Number | `768` | Viewport width (px) below which mobile layout is used |
45
+ | `stack-rotation` | Number | `3` | Rotation angle in degrees for inactive cards |
46
+ | `transition-duration` | Number | `500` | Transition duration in milliseconds |
47
+
48
+ ## Slots
49
+
50
+ | Slot | Description |
51
+ |------|-------------|
52
+ | `card` | Card elements. Use `data-title`, `data-color`, `data-image`, and `data-num` attributes to configure each card. |
53
+
54
+ ### Card data attributes
55
+
56
+ | Attribute | Description |
57
+ |-----------|-------------|
58
+ | `data-title` | Title displayed in the card header and body |
59
+ | `data-color` | Background color of the card |
60
+ | `data-image` | URL of the image shown in the preview panel |
61
+ | `data-num` | Number label shown in the card header (defaults to zero-padded index) |
62
+
63
+ ## CSS Custom Properties
64
+
65
+ | Property | Default | Description |
66
+ |----------|---------|-------------|
67
+ | `--dcs-border-radius` | `20px` | Border radius of the outer wrapper |
68
+ | `--dcs-height` | `700px` | Height of the component in desktop mode |
69
+ | `--dcs-preview-bg` | `#000` | Background color of the preview panel |
70
+ | `--dcs-text-color` | `#fff` | Text color for the card body title |
71
+ | `--dcs-title-size` | `3.5rem` | Font size of the expanded card title |
72
+
73
+ ## Keyboard Navigation
74
+
75
+ | Key | Action |
76
+ |-----|--------|
77
+ | Arrow Down | Activate next card |
78
+ | Arrow Up | Activate previous card |
79
+ | Home | Activate first card |
80
+ | End | Activate last card |
81
+
82
+ ## License
83
+
84
+ MIT
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@manufosela/device-card-stack",
3
+ "version": "1.0.0",
4
+ "description": "Accordion-style card stack with 3D perspective and image preview panel",
5
+ "license": "MIT",
6
+ "author": "manufosela",
7
+ "type": "module",
8
+ "main": "./src/device-card-stack.js",
9
+ "module": "./src/device-card-stack.js",
10
+ "types": "./src/device-card-stack.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/device-card-stack.d.ts",
14
+ "import": "./src/device-card-stack.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "src"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/manufosela/ui-components",
23
+ "directory": "packages/device-card-stack"
24
+ },
25
+ "keywords": [
26
+ "web-components",
27
+ "lit",
28
+ "card-stack",
29
+ "accordion",
30
+ "device-showcase"
31
+ ],
32
+ "homepage": "https://github.com/manufosela/ui-components/tree/main/packages/device-card-stack#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/manufosela/ui-components/issues"
35
+ },
36
+ "dependencies": {
37
+ "lit": "^3.2.1"
38
+ },
39
+ "customElements": "custom-elements.json",
40
+ "scripts": {
41
+ "start": "web-dev-server --node-resolve --open demo/ --watch",
42
+ "test": "web-test-runner",
43
+ "test:watch": "web-test-runner --watch",
44
+ "test:coverage": "web-test-runner --coverage",
45
+ "build:types": "tsc --declaration --declarationMap --emitDeclarationOnly --allowJs --checkJs --outDir ./src ./src/device-card-stack.js"
46
+ }
47
+ }
@@ -0,0 +1,504 @@
1
+ import { LitElement, html, css } from 'lit';
2
+
3
+ /**
4
+ * Accordion-style card stack with 3D perspective and image preview panel.
5
+ *
6
+ * Cards are provided via slotted elements with `slot="card"` and expand on click
7
+ * to reveal their content. A preview panel on the right displays the image
8
+ * associated with the active card. On mobile viewports the preview panel is
9
+ * hidden and images are shown inline within each card.
10
+ *
11
+ * @element device-card-stack
12
+ *
13
+ * @attr {Number} active-index - Index of the currently active card (default: 0)
14
+ * @attr {Number} mobile-breakpoint - Viewport width in px below which mobile layout is used (default: 768)
15
+ * @attr {Number} stack-rotation - Rotation angle in degrees applied to inactive cards (default: 3)
16
+ * @attr {Number} transition-duration - Transition duration in milliseconds (default: 500)
17
+ *
18
+ * @cssprop [--dcs-border-radius=20px] - Border radius of the outer wrapper
19
+ * @cssprop [--dcs-height=700px] - Height of the component in desktop mode
20
+ * @cssprop [--dcs-preview-bg=#000] - Background color of the preview panel
21
+ * @cssprop [--dcs-text-color=#fff] - Text color for the card body title
22
+ * @cssprop [--dcs-title-size=3.5rem] - Font size of the expanded card title
23
+ *
24
+ * @slot card - Card elements with data-title, data-color, data-image, and data-num attributes
25
+ *
26
+ * @fires card-activated - Fired when a card is activated. detail: { index, title }
27
+ */
28
+ export class DeviceCardStack extends LitElement {
29
+ static properties = {
30
+ activeIndex: { type: Number, attribute: 'active-index' },
31
+ mobileBreakpoint: { type: Number, attribute: 'mobile-breakpoint' },
32
+ stackRotation: { type: Number, attribute: 'stack-rotation' },
33
+ transitionDuration: { type: Number, attribute: 'transition-duration' },
34
+ _cards: { type: Array, state: true },
35
+ _isMobile: { type: Boolean, state: true },
36
+ _reducedMotion: { type: Boolean, state: true },
37
+ };
38
+
39
+ static styles = css`
40
+ :host {
41
+ display: block;
42
+ --dcs-border-radius: 20px;
43
+ --dcs-height: 700px;
44
+ --dcs-preview-bg: #000;
45
+ --dcs-text-color: #fff;
46
+ --dcs-title-size: 3.5rem;
47
+ }
48
+
49
+ *,
50
+ *::before,
51
+ *::after {
52
+ box-sizing: border-box;
53
+ }
54
+
55
+ .wrapper {
56
+ display: flex;
57
+ width: 100%;
58
+ height: var(--dcs-height);
59
+ border-radius: var(--dcs-border-radius);
60
+ overflow: hidden;
61
+ }
62
+
63
+ /* Stack panel (left) */
64
+ .stack-panel {
65
+ width: 50%;
66
+ display: flex;
67
+ flex-direction: column;
68
+ perspective: 1200px;
69
+ perspective-origin: 50% 30%;
70
+ }
71
+
72
+ /* Individual card */
73
+ .card {
74
+ position: relative;
75
+ padding: 0 40px;
76
+ cursor: pointer;
77
+ overflow: hidden;
78
+ display: flex;
79
+ flex-direction: column;
80
+ justify-content: flex-start;
81
+ transition-property: transform, box-shadow, flex-grow;
82
+ transition-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
83
+ transform-style: preserve-3d;
84
+ will-change: transform, box-shadow;
85
+ height: 70px;
86
+ flex-shrink: 0;
87
+ flex-grow: 0;
88
+ }
89
+
90
+ .card[data-active] {
91
+ flex-grow: 1;
92
+ height: auto;
93
+ flex-shrink: 1;
94
+ padding: 20px 40px;
95
+ transform: translateZ(30px) scale(1.01);
96
+ box-shadow: 0 15px 40px rgba(0, 0, 0, 0.35);
97
+ }
98
+
99
+ .card:not([data-active]) {
100
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
101
+ }
102
+
103
+ /* Card header */
104
+ .card-header {
105
+ padding: 24px 0;
106
+ font-size: 1rem;
107
+ color: rgba(255, 255, 255, 0.9);
108
+ font-weight: 500;
109
+ display: flex;
110
+ align-items: center;
111
+ flex-shrink: 0;
112
+ }
113
+
114
+ .card-num {
115
+ margin-right: 15px;
116
+ font-weight: 400;
117
+ opacity: 0.8;
118
+ }
119
+
120
+ /* Card body - only visible when active */
121
+ .card-body {
122
+ margin-top: 40px;
123
+ max-width: 500px;
124
+ opacity: 0;
125
+ transform: translateY(20px);
126
+ pointer-events: none;
127
+ transition:
128
+ opacity 0.5s ease 0.15s,
129
+ transform 0.5s ease 0.15s;
130
+ }
131
+
132
+ .card[data-active] .card-body {
133
+ opacity: 1;
134
+ transform: translateY(0);
135
+ pointer-events: auto;
136
+ }
137
+
138
+ .card-body-title {
139
+ font-size: var(--dcs-title-size);
140
+ line-height: 1.1;
141
+ margin: 0 0 24px;
142
+ color: var(--dcs-text-color);
143
+ font-weight: 400;
144
+ }
145
+
146
+ /* Mobile inline image */
147
+ .card-mobile-image {
148
+ display: none;
149
+ }
150
+
151
+ :host([data-mobile]) .card[data-active] .card-mobile-image {
152
+ display: block;
153
+ width: 100%;
154
+ margin-bottom: 20px;
155
+ }
156
+
157
+ :host([data-mobile]) .card[data-active] .card-mobile-image img {
158
+ width: 100%;
159
+ max-height: 200px;
160
+ object-fit: contain;
161
+ border-radius: 8px;
162
+ }
163
+
164
+ /* Preview panel (right) */
165
+ .preview-panel {
166
+ width: 50%;
167
+ background-color: var(--dcs-preview-bg);
168
+ position: relative;
169
+ overflow: hidden;
170
+ border-radius: 0 var(--dcs-border-radius) var(--dcs-border-radius) 0;
171
+ }
172
+
173
+ .preview-image {
174
+ position: absolute;
175
+ inset: 0;
176
+ display: flex;
177
+ align-items: center;
178
+ justify-content: center;
179
+ opacity: 0;
180
+ transform: scale(0.92);
181
+ transition:
182
+ opacity 0.4s ease,
183
+ transform 0.4s ease;
184
+ pointer-events: none;
185
+ }
186
+
187
+ .preview-image[data-visible] {
188
+ opacity: 1;
189
+ transform: scale(1);
190
+ pointer-events: auto;
191
+ }
192
+
193
+ .preview-image img {
194
+ max-width: 80%;
195
+ max-height: 80%;
196
+ object-fit: contain;
197
+ }
198
+
199
+ /* Mobile mode */
200
+ :host([data-mobile]) .wrapper {
201
+ flex-direction: column;
202
+ height: auto;
203
+ min-height: auto;
204
+ }
205
+
206
+ :host([data-mobile]) .stack-panel {
207
+ width: 100%;
208
+ perspective: 800px;
209
+ }
210
+
211
+ :host([data-mobile]) .preview-panel {
212
+ display: none;
213
+ }
214
+
215
+ :host([data-mobile]) .card {
216
+ padding: 0 20px;
217
+ }
218
+
219
+ :host([data-mobile]) .card[data-active] {
220
+ padding: 16px 20px;
221
+ }
222
+
223
+ :host([data-mobile]) .card-body {
224
+ margin-top: 16px;
225
+ }
226
+
227
+ :host([data-mobile]) .card-body-title {
228
+ font-size: 2rem;
229
+ }
230
+
231
+ :host([data-mobile]) .card-mobile-image img {
232
+ max-height: 160px;
233
+ }
234
+
235
+ /* Focus visible */
236
+ .card:focus-visible {
237
+ outline: 2px solid #fff;
238
+ outline-offset: -2px;
239
+ z-index: 10;
240
+ }
241
+
242
+ /* Reduced motion */
243
+ @media (prefers-reduced-motion: reduce) {
244
+ .card {
245
+ transition: none !important;
246
+ transform: none !important;
247
+ }
248
+
249
+ .card[data-active] {
250
+ transform: none !important;
251
+ }
252
+
253
+ .card-body {
254
+ transition: none !important;
255
+ }
256
+
257
+ .preview-image {
258
+ transition: none !important;
259
+ transform: none !important;
260
+ }
261
+ }
262
+
263
+ /* Slotted content styling */
264
+ ::slotted([slot^='card']) {
265
+ color: rgba(255, 255, 255, 0.9);
266
+ font-size: 1.1rem;
267
+ line-height: 1.5;
268
+ font-weight: 300;
269
+ }
270
+ `;
271
+
272
+ constructor() {
273
+ super();
274
+ this.activeIndex = 0;
275
+ this.mobileBreakpoint = 768;
276
+ this.stackRotation = 3;
277
+ this.transitionDuration = 500;
278
+ this._cards = [];
279
+ this._isMobile = false;
280
+ this._reducedMotion = false;
281
+ this._resizeHandler = null;
282
+ }
283
+
284
+ connectedCallback() {
285
+ super.connectedCallback();
286
+ this._reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
287
+ this._checkMobile();
288
+ this._resizeHandler = this._onResize.bind(this);
289
+ window.addEventListener('resize', this._resizeHandler, { passive: true });
290
+ }
291
+
292
+ disconnectedCallback() {
293
+ super.disconnectedCallback();
294
+ if (this._resizeHandler) {
295
+ window.removeEventListener('resize', this._resizeHandler);
296
+ }
297
+ }
298
+
299
+ firstUpdated() {
300
+ this._extractCards();
301
+ this._applyTransitionDuration();
302
+ }
303
+
304
+ _extractCards() {
305
+ const slottedElements = this.querySelectorAll('[slot="card"]');
306
+ const cards = [];
307
+ slottedElements.forEach((el, i) => {
308
+ const slotName = `card-${i}`;
309
+ el.setAttribute('slot', slotName);
310
+ cards.push({
311
+ index: i,
312
+ slotName,
313
+ num: el.dataset.num || String(i + 1).padStart(2, '0'),
314
+ title: el.dataset.title || '',
315
+ image: el.dataset.image || '',
316
+ imageWebp: el.dataset.imageWebp || '',
317
+ color: el.dataset.color || '#4a4a4a',
318
+ });
319
+ });
320
+ this._cards = cards;
321
+ }
322
+
323
+ _applyTransitionDuration() {
324
+ const duration = `${this.transitionDuration}ms`;
325
+ this.style.setProperty('--_transition-duration', duration);
326
+ }
327
+
328
+ _checkMobile() {
329
+ this._isMobile = window.innerWidth <= this.mobileBreakpoint;
330
+ if (this._isMobile) {
331
+ this.setAttribute('data-mobile', '');
332
+ } else {
333
+ this.removeAttribute('data-mobile');
334
+ }
335
+ }
336
+
337
+ _onResize() {
338
+ this._checkMobile();
339
+ }
340
+
341
+ _activateCard(index) {
342
+ if (index === this.activeIndex) return;
343
+ this.activeIndex = index;
344
+ }
345
+
346
+ _onCardKeydown(e) {
347
+ const total = this._cards.length;
348
+ let handled = true;
349
+
350
+ switch (e.key) {
351
+ case 'ArrowDown':
352
+ this._activateCard((this.activeIndex + 1) % total);
353
+ break;
354
+ case 'ArrowUp':
355
+ this._activateCard((this.activeIndex - 1 + total) % total);
356
+ break;
357
+ case 'Home':
358
+ this._activateCard(0);
359
+ break;
360
+ case 'End':
361
+ this._activateCard(total - 1);
362
+ break;
363
+ case 'Enter':
364
+ case ' ':
365
+ // Already handled by click on the tab role
366
+ break;
367
+ default:
368
+ handled = false;
369
+ }
370
+
371
+ if (handled) {
372
+ e.preventDefault();
373
+ this._focusActiveTab();
374
+ }
375
+ }
376
+
377
+ _focusActiveTab() {
378
+ requestAnimationFrame(() => {
379
+ const tab = this.shadowRoot.querySelector(`.card[data-index="${this.activeIndex}"]`);
380
+ if (tab) tab.focus();
381
+ });
382
+ }
383
+
384
+ _getCardTransform(index) {
385
+ if (this._reducedMotion) return 'none';
386
+
387
+ const active = this.activeIndex;
388
+ if (index === active) {
389
+ return 'translateZ(30px) scale(1.01)';
390
+ }
391
+
392
+ const distance = Math.abs(index - active);
393
+ const direction = index < active ? -1 : 1;
394
+ const z = -(distance * 15);
395
+ const rotation = direction * Math.min(distance * this.stackRotation, this.stackRotation * 2);
396
+
397
+ return `translateZ(${z}px) rotateX(${rotation}deg)`;
398
+ }
399
+
400
+ _getCardShadow(index) {
401
+ if (this._reducedMotion) return 'none';
402
+
403
+ const active = this.activeIndex;
404
+ if (index === active) {
405
+ return '0 15px 40px rgba(0, 0, 0, 0.35)';
406
+ }
407
+
408
+ const distance = Math.abs(index - active);
409
+ const blur = 4 + distance * 6;
410
+ const spread = distance * 2;
411
+ const opacity = 0.1 + distance * 0.05;
412
+ return `0 ${2 + distance * 3}px ${blur}px ${spread}px rgba(0, 0, 0, ${opacity})`;
413
+ }
414
+
415
+ render() {
416
+ const duration = `${this.transitionDuration}ms`;
417
+
418
+ return html`
419
+ <div class="wrapper">
420
+ <div
421
+ class="stack-panel"
422
+ role="tablist"
423
+ aria-label="Dispositivos"
424
+ aria-orientation="vertical"
425
+ >
426
+ ${this._cards.map(
427
+ (card, i) => html`
428
+ <div
429
+ class="card"
430
+ role="tab"
431
+ data-index="${i}"
432
+ ?data-active=${i === this.activeIndex}
433
+ aria-selected=${i === this.activeIndex ? 'true' : 'false'}
434
+ aria-controls="panel-${i}"
435
+ tabindex=${i === this.activeIndex ? '0' : '-1'}
436
+ style="
437
+ background-color: ${i === this.activeIndex ? card.color : card.color};
438
+ transform: ${this._getCardTransform(i)};
439
+ box-shadow: ${this._getCardShadow(i)};
440
+ transition-duration: ${duration};
441
+ "
442
+ @click=${() => this._activateCard(i)}
443
+ @keydown=${this._onCardKeydown}
444
+ >
445
+ <div class="card-header">
446
+ <span class="card-num">${card.num}</span>
447
+ ${card.title}
448
+ </div>
449
+ <div
450
+ id="panel-${i}"
451
+ class="card-body"
452
+ role="tabpanel"
453
+ aria-hidden=${i === this.activeIndex ? 'false' : 'true'}
454
+ >
455
+ ${card.image
456
+ ? html`<picture class="card-mobile-image">
457
+ ${card.imageWebp
458
+ ? html`<source type="image/webp" srcset="${card.imageWebp}" />`
459
+ : ''}
460
+ <img
461
+ src="${card.image}"
462
+ alt="${card.title}"
463
+ loading="lazy"
464
+ width="441"
465
+ height="400"
466
+ />
467
+ </picture>`
468
+ : ''}
469
+ <h3 class="card-body-title">${card.title}</h3>
470
+ <slot name="${card.slotName}"></slot>
471
+ </div>
472
+ </div>
473
+ `
474
+ )}
475
+ </div>
476
+
477
+ <div class="preview-panel" aria-hidden="true">
478
+ ${this._cards.map(
479
+ (card, i) => html`
480
+ <div class="preview-image" ?data-visible=${i === this.activeIndex}>
481
+ ${card.image
482
+ ? html`<picture>
483
+ ${card.imageWebp
484
+ ? html`<source type="image/webp" srcset="${card.imageWebp}" />`
485
+ : ''}
486
+ <img
487
+ src="${card.image}"
488
+ alt="${card.title}"
489
+ loading="${i === this.activeIndex ? 'eager' : 'lazy'}"
490
+ width="441"
491
+ height="400"
492
+ />
493
+ </picture>`
494
+ : ''}
495
+ </div>
496
+ `
497
+ )}
498
+ </div>
499
+ </div>
500
+ `;
501
+ }
502
+ }
503
+
504
+ customElements.define('device-card-stack', DeviceCardStack);