@khipu/design-system 0.2.0-alpha.2 → 0.2.0-alpha.21

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.
@@ -923,16 +923,34 @@ const ui = _context.ui;
923
923
  }
924
924
 
925
925
  /**
926
- * Initialize flash messages with auto-dismiss
926
+ * Dismiss and remove a snackbar with fade-out
927
+ */
928
+ function dismissSnackbar(snackbar) {
929
+ snackbar.classList.remove('active');
930
+ setTimeout(function() { snackbar.remove(); }, 300);
931
+ }
932
+
933
+ /**
934
+ * Initialize flash messages with auto-dismiss and close button
927
935
  */
928
936
  function initFlashMessages() {
929
- const snackbars = document.querySelectorAll('.snackbar[data-auto-dismiss="true"]');
937
+ var snackbars = document.querySelectorAll('.snackbar[data-auto-dismiss="true"]');
930
938
 
931
939
  snackbars.forEach(function(snackbar) {
940
+ // Give text span flex-grow so close button stays right
941
+ var span = snackbar.querySelector('span');
942
+ if (span) span.classList.add('max');
943
+
944
+ // Inject close button
945
+ var closeBtn = document.createElement('button');
946
+ closeBtn.className = 'kds-snackbar-close';
947
+ closeBtn.setAttribute('aria-label', 'Cerrar');
948
+ closeBtn.innerHTML = '<i class="material-symbols-outlined">close</i>';
949
+ closeBtn.onclick = function() { dismissSnackbar(snackbar); };
950
+ snackbar.appendChild(closeBtn);
951
+
932
952
  // Auto-dismiss after 5 seconds
933
- setTimeout(function() {
934
- snackbar.classList.remove('active');
935
- }, 5000);
953
+ setTimeout(function() { dismissSnackbar(snackbar); }, 5000);
936
954
  });
937
955
  }
938
956
 
@@ -973,10 +991,15 @@ const ui = _context.ui;
973
991
 
974
992
  if (!logoSource) return;
975
993
 
994
+ // Insert inside the amount div (first child of .kds-invoice-header)
995
+ var header = card.querySelector('.kds-invoice-header');
996
+ var amountDiv = header ? header.firstElementChild : null;
997
+ if (!amountDiv) return;
998
+
976
999
  var inner = document.createElement('div');
977
1000
  inner.className = 'kds-brand-inner';
978
1001
  inner.appendChild(logoSource.cloneNode(true));
979
- card.insertBefore(inner, card.firstChild);
1002
+ amountDiv.insertBefore(inner, amountDiv.firstChild);
980
1003
  });
981
1004
  }
982
1005
 
@@ -1298,7 +1321,7 @@ const ui = _context.ui;
1298
1321
  /**
1299
1322
  * Initialize sticky invoice card progressive collapse on scroll
1300
1323
  * MOBILE ONLY - Desktop mantiene cajitas normales
1301
- * Uses scroll-linked animation (0-150px) for smooth collapse/expand
1324
+ * Uses scroll-linked animation (0-60px) for smooth collapse/expand
1302
1325
  * Updates CSS custom property --collapse-progress (0 to 1) for GPU-accelerated animations
1303
1326
  * Works with multiple screens - targets sticky element in currently active screen
1304
1327
  * Safari-compatible: uses native CSS custom properties, calc(), and requestAnimationFrame
@@ -1307,9 +1330,9 @@ const ui = _context.ui;
1307
1330
  function initStickyInvoice(root) {
1308
1331
  root = root || document;
1309
1332
 
1310
- // Progressive collapse range: 0px (expanded) to 150px (collapsed)
1333
+ // Progressive collapse range: 0px (expanded) to 20px (collapsed)
1311
1334
  var COLLAPSE_START = 0;
1312
- var COLLAPSE_END = 150;
1335
+ var COLLAPSE_END = 20;
1313
1336
 
1314
1337
  var lastScrollY = 0;
1315
1338
  var ticking = false;
@@ -1364,6 +1387,19 @@ const ui = _context.ui;
1364
1387
  // Single DOM write per frame — set on screen (parent) so it cascades to sticky + siblings
1365
1388
  currentScreen.style.setProperty('--collapse-progress', progress);
1366
1389
 
1390
+ // Toggle collapsed state class for discrete styling that can't interpolate (e.g. align-items)
1391
+ currentSticky.classList.toggle('is-collapsed', progress >= 1);
1392
+
1393
+ // Close expand panels as soon as the sticky header starts collapsing
1394
+ if (progress > 0) {
1395
+ currentSticky.querySelectorAll('[data-expand-toggle][aria-expanded="true"]').forEach(function(toggle) {
1396
+ toggle.setAttribute('aria-expanded', 'false');
1397
+ var panelId = toggle.getAttribute('aria-controls');
1398
+ var panel = panelId ? document.getElementById(panelId) : null;
1399
+ if (panel) panel.classList.remove('open');
1400
+ });
1401
+ }
1402
+
1367
1403
  lastScrollY = scrollY;
1368
1404
  });
1369
1405
  }
@@ -1377,6 +1413,9 @@ const ui = _context.ui;
1377
1413
  screen.style.removeProperty('--collapse-progress');
1378
1414
  screen.style.removeProperty('--collapse-collapsible-h');
1379
1415
  });
1416
+ root.querySelectorAll('.kds-invoice-sticky.is-collapsed').forEach(function(el) {
1417
+ el.classList.remove('is-collapsed');
1418
+ });
1380
1419
  }
1381
1420
  });
1382
1421
 
@@ -1511,25 +1550,24 @@ const ui = _context.ui;
1511
1550
  type = type || 'info';
1512
1551
  duration = duration || 5000;
1513
1552
 
1514
- const snackbar = document.createElement('div');
1553
+ var snackbar = document.createElement('div');
1515
1554
  snackbar.className = 'snackbar active ' + type;
1555
+ snackbar.setAttribute('data-auto-dismiss', 'true');
1556
+ snackbar.style.setProperty('--kds-snackbar-duration', duration + 'ms');
1516
1557
 
1517
- const icon = document.createElement('i');
1558
+ var icon = document.createElement('i');
1518
1559
  icon.className = 'material-symbols-outlined';
1519
1560
  icon.textContent = type === 'success' ? 'check_circle' : (type === 'error' ? 'error' : 'info');
1520
1561
 
1521
- const span = document.createElement('span');
1562
+ var span = document.createElement('span');
1563
+ span.className = 'max';
1522
1564
  span.textContent = message;
1523
1565
 
1524
- const closeBtn = document.createElement('button');
1525
- closeBtn.className = 'transparent circle';
1566
+ var closeBtn = document.createElement('button');
1567
+ closeBtn.className = 'kds-snackbar-close';
1568
+ closeBtn.setAttribute('aria-label', 'Cerrar');
1526
1569
  closeBtn.innerHTML = '<i class="material-symbols-outlined">close</i>';
1527
- closeBtn.onclick = function() {
1528
- snackbar.classList.remove('active');
1529
- setTimeout(function() {
1530
- snackbar.remove();
1531
- }, 300);
1532
- };
1570
+ closeBtn.onclick = function() { dismissSnackbar(snackbar); };
1533
1571
 
1534
1572
  snackbar.appendChild(icon);
1535
1573
  snackbar.appendChild(span);
@@ -1537,12 +1575,7 @@ const ui = _context.ui;
1537
1575
 
1538
1576
  document.body.appendChild(snackbar);
1539
1577
 
1540
- setTimeout(function() {
1541
- snackbar.classList.remove('active');
1542
- setTimeout(function() {
1543
- snackbar.remove();
1544
- }, 300);
1545
- }, duration);
1578
+ setTimeout(function() { dismissSnackbar(snackbar); }, duration);
1546
1579
  }
1547
1580
 
1548
1581
  // Export utilities to window for backward compatibility