@idds/js 1.0.68 → 1.0.69

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 (3) hide show
  1. package/dist/index.iife.js +1183 -720
  2. package/dist/index.js +281 -195
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1163,6 +1163,30 @@ function initSelectDropdown() {
1163
1163
  window.__inaSelectDropdownInitialized = true;
1164
1164
  }
1165
1165
 
1166
+ // src/js/components/stateful/radio-button.js
1167
+ function initRadioButton() {
1168
+ const radioGroups = document.querySelectorAll(`.${PREFIX}-radio-input`);
1169
+ radioGroups.forEach((group) => {
1170
+ if (group.dataset.initialized === "true") return;
1171
+ group.dataset.initialized = "true";
1172
+ const inputs = group.querySelectorAll('input[type="radio"]');
1173
+ const displayTargetId = group.dataset.displayTarget;
1174
+ const displayTarget = displayTargetId ? document.getElementById(displayTargetId) : null;
1175
+ const updateDisplay = () => {
1176
+ if (!displayTarget) return;
1177
+ const selected = Array.from(inputs).find((input) => input.checked);
1178
+ const value = selected ? selected.value : "";
1179
+ displayTarget.textContent = `Selected: ${value || "None"}`;
1180
+ };
1181
+ if (inputs.length > 0) {
1182
+ inputs.forEach((input) => {
1183
+ input.addEventListener("change", updateDisplay);
1184
+ });
1185
+ updateDisplay();
1186
+ }
1187
+ });
1188
+ }
1189
+
1166
1190
  // src/js/components/stateful/file-upload.js
1167
1191
  var ICONS = {
1168
1192
  upload: `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"></path><polyline points="16 6 12 2 8 6"></polyline><line x1="12" y1="2" x2="12" y2="16"></line></svg>`,
@@ -1686,150 +1710,6 @@ function initFileUploadItem(rootSelector = `.${PREFIX}-file-item`) {
1686
1710
  });
1687
1711
  }
1688
1712
 
1689
- // src/js/components/stateful/dropdown.js
1690
- function initDropdown(rootSelector = `.${PREFIX}-dropdown`) {
1691
- document.querySelectorAll(rootSelector).forEach((dropdown) => {
1692
- const trigger = dropdown.querySelector(`.${PREFIX}-dropdown__trigger`);
1693
- const input = dropdown.querySelector(`.${PREFIX}-dropdown__input`);
1694
- const menu = dropdown.querySelector(`.${PREFIX}-dropdown__menu`);
1695
- const menuItems = menu.querySelectorAll("li[role='option']");
1696
- const menuId = menu.id;
1697
- let activeIndex = -1;
1698
- menuItems.forEach((item, index) => {
1699
- item.id = `${menuId}-item-${index}`;
1700
- });
1701
- const toggleMenu = (show) => {
1702
- const isCurrentlyShown = dropdown.classList.contains("show");
1703
- const isShown = show !== void 0 ? show : !isCurrentlyShown;
1704
- if (isShown === isCurrentlyShown) {
1705
- return;
1706
- }
1707
- dropdown.classList.toggle("show", isShown);
1708
- trigger.setAttribute("aria-expanded", isShown);
1709
- if (isShown) {
1710
- input.focus();
1711
- } else {
1712
- input.blur();
1713
- removeHighlight();
1714
- activeIndex = -1;
1715
- input.removeAttribute("aria-activedescendant");
1716
- }
1717
- };
1718
- const filterItems = () => {
1719
- const filterValue = input.value.toLowerCase();
1720
- let hasVisibleItems = false;
1721
- activeIndex = -1;
1722
- removeHighlight();
1723
- input.removeAttribute("aria-activedescendant");
1724
- const activeItem = menu.querySelector("li[role='option'].selected");
1725
- if (activeItem && input.value !== activeItem.textContent.trim()) {
1726
- activeItem.classList.remove("selected");
1727
- }
1728
- menuItems.forEach((item) => {
1729
- const itemText = item.textContent.toLowerCase();
1730
- const isMatch = itemText.includes(filterValue);
1731
- item.classList.toggle("hidden", !isMatch);
1732
- if (isMatch) hasVisibleItems = true;
1733
- });
1734
- if (!dropdown.classList.contains("show") && hasVisibleItems) {
1735
- toggleMenu(true);
1736
- }
1737
- };
1738
- const selectItem = (item) => {
1739
- const itemText = item.textContent.trim();
1740
- input.value = itemText;
1741
- menuItems.forEach((li) => {
1742
- li.classList.remove("selected");
1743
- });
1744
- if (item) {
1745
- item.classList.add("selected");
1746
- dropdown.dispatchEvent(
1747
- new CustomEvent("dropdown:changed", {
1748
- detail: { value: itemText }
1749
- })
1750
- );
1751
- }
1752
- toggleMenu(false);
1753
- };
1754
- const setHighlight = (index) => {
1755
- removeHighlight();
1756
- const visibleItems = menu.querySelectorAll(
1757
- "li[role='option']:not(.hidden)"
1758
- );
1759
- if (visibleItems.length === 0) return;
1760
- if (index < 0) index = 0;
1761
- else if (index >= visibleItems.length) index = visibleItems.length - 1;
1762
- const itemToHighlight = visibleItems[index];
1763
- if (itemToHighlight) {
1764
- itemToHighlight.classList.add("highlighted");
1765
- input.setAttribute("aria-activedescendant", itemToHighlight.id);
1766
- itemToHighlight.scrollIntoView({
1767
- behavior: "smooth",
1768
- block: "nearest"
1769
- });
1770
- activeIndex = index;
1771
- }
1772
- };
1773
- const removeHighlight = () => {
1774
- menuItems.forEach((item) => item.classList.remove("highlighted"));
1775
- };
1776
- trigger.addEventListener("click", () => {
1777
- toggleMenu();
1778
- });
1779
- input.addEventListener("input", filterItems);
1780
- menu.addEventListener("click", (e) => {
1781
- const option = e.target.closest("li[role='option']");
1782
- if (option) {
1783
- e.preventDefault();
1784
- selectItem(option);
1785
- }
1786
- });
1787
- document.addEventListener("click", (e) => {
1788
- if (!dropdown.contains(e.target)) {
1789
- toggleMenu(false);
1790
- }
1791
- });
1792
- input.addEventListener("keydown", (e) => {
1793
- const { key } = e;
1794
- const isMenuOpen = dropdown.classList.contains("show");
1795
- switch (key) {
1796
- case "ArrowDown":
1797
- e.preventDefault();
1798
- if (!isMenuOpen) {
1799
- toggleMenu(true);
1800
- }
1801
- setHighlight(activeIndex + 1);
1802
- break;
1803
- case "ArrowUp":
1804
- e.preventDefault();
1805
- if (isMenuOpen) {
1806
- setHighlight(activeIndex - 1);
1807
- }
1808
- break;
1809
- case "Enter":
1810
- e.preventDefault();
1811
- const firstVisible = menu.querySelector(
1812
- "li[role='option']:not(.hidden)"
1813
- );
1814
- const activeItem = menu.querySelector(".highlighted");
1815
- if (isMenuOpen && activeItem) {
1816
- selectItem(activeItem);
1817
- } else if (isMenuOpen && firstVisible) {
1818
- toggleMenu(false);
1819
- }
1820
- break;
1821
- case "Escape":
1822
- e.preventDefault();
1823
- toggleMenu(false);
1824
- break;
1825
- case "Tab":
1826
- toggleMenu(false);
1827
- break;
1828
- }
1829
- });
1830
- });
1831
- }
1832
-
1833
1713
  // src/js/components/stateful/range-datepicker.js
1834
1714
  function initRangeDatepicker() {
1835
1715
  document.querySelectorAll(".ina-ss-range-datepicker").forEach((rangeDatepicker) => {
@@ -2195,6 +2075,35 @@ function initRangeDatepicker() {
2195
2075
  });
2196
2076
  }
2197
2077
 
2078
+ // src/js/components/stateless/img-compare.js
2079
+ function initImgCompare(rootSelector = `.${PREFIX}-img-compare`) {
2080
+ document.querySelectorAll(rootSelector).forEach((imgCompare) => {
2081
+ const sliderEl = document.createElement("input");
2082
+ sliderEl.type = "range";
2083
+ sliderEl.min = "0";
2084
+ sliderEl.max = "100";
2085
+ sliderEl.value = "50";
2086
+ sliderEl.setAttribute("aria-label", "Percentage of the image to show");
2087
+ sliderEl.setAttribute("aria-valuenow", "50");
2088
+ sliderEl.setAttribute("aria-valuemin", "0");
2089
+ sliderEl.setAttribute("aria-valuemax", "100");
2090
+ sliderEl.classList.add("ina-ss-img__slider");
2091
+ sliderEl.addEventListener("input", () => {
2092
+ imgCompare.style.setProperty(
2093
+ `--${PREFIX}-position`,
2094
+ `${sliderEl.value}%`
2095
+ );
2096
+ });
2097
+ const sliderLineEl = document.createElement("div");
2098
+ sliderLineEl.classList.add("ina-ss-img__slider-line");
2099
+ const sliderButtonEl = document.createElement("button");
2100
+ sliderButtonEl.classList.add("ina-ss-img__slider-button");
2101
+ imgCompare.appendChild(sliderEl);
2102
+ imgCompare.appendChild(sliderLineEl);
2103
+ imgCompare.appendChild(sliderButtonEl);
2104
+ });
2105
+ }
2106
+
2198
2107
  // src/js/components/stateful/timepicker.js
2199
2108
  function initTimepicker() {
2200
2109
  document.querySelectorAll(`.${PREFIX}-time-picker`).forEach((picker) => {
@@ -2405,56 +2314,6 @@ function initTimepicker() {
2405
2314
  });
2406
2315
  }
2407
2316
 
2408
- // src/js/components/stateless/img-compare.js
2409
- function initImgCompare(rootSelector = `.${PREFIX}-img-compare`) {
2410
- document.querySelectorAll(rootSelector).forEach((imgCompare) => {
2411
- const sliderEl = document.createElement("input");
2412
- sliderEl.type = "range";
2413
- sliderEl.min = "0";
2414
- sliderEl.max = "100";
2415
- sliderEl.value = "50";
2416
- sliderEl.setAttribute("aria-label", "Percentage of the image to show");
2417
- sliderEl.setAttribute("aria-valuenow", "50");
2418
- sliderEl.setAttribute("aria-valuemin", "0");
2419
- sliderEl.setAttribute("aria-valuemax", "100");
2420
- sliderEl.classList.add("ina-ss-img__slider");
2421
- sliderEl.addEventListener("input", () => {
2422
- imgCompare.style.setProperty(
2423
- `--${PREFIX}-position`,
2424
- `${sliderEl.value}%`
2425
- );
2426
- });
2427
- const sliderLineEl = document.createElement("div");
2428
- sliderLineEl.classList.add("ina-ss-img__slider-line");
2429
- const sliderButtonEl = document.createElement("button");
2430
- sliderButtonEl.classList.add("ina-ss-img__slider-button");
2431
- imgCompare.appendChild(sliderEl);
2432
- imgCompare.appendChild(sliderLineEl);
2433
- imgCompare.appendChild(sliderButtonEl);
2434
- });
2435
- }
2436
-
2437
- // src/js/bundle.js
2438
- if (typeof window !== void 0) {
2439
- document.addEventListener("DOMContentLoaded", () => {
2440
- initAccordion();
2441
- initButtonGroup();
2442
- initCheckbox();
2443
- initDatepicker();
2444
- initDropdown();
2445
- initFileUpload();
2446
- initSingleFileUpload();
2447
- initFileUploadBase();
2448
- initFileUploadItem();
2449
- initImgCompare();
2450
- initModal();
2451
- initRangeDatepicker();
2452
- initTab();
2453
- initTimepicker();
2454
- initToggle();
2455
- });
2456
- }
2457
-
2458
2317
  // src/js/components/stateful/chip.js
2459
2318
  var PREFIX5 = "ina";
2460
2319
  function initChip(rootSelector = `.${PREFIX5}-chip`) {
@@ -2564,6 +2423,230 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
2564
2423
  });
2565
2424
  }
2566
2425
 
2426
+ // src/js/components/stateful/pagination.js
2427
+ function initPagination() {
2428
+ document.querySelectorAll(`.${PREFIX}-pagination`).forEach((container) => {
2429
+ if (container.dataset.initialized === "true") return;
2430
+ container.dataset.initialized = "true";
2431
+ const navButtonsContainer = container.querySelector(
2432
+ `.${PREFIX}-pagination__nav-buttons`
2433
+ );
2434
+ const pageInfo = container.querySelector(
2435
+ `.${PREFIX}-pagination__page-info`
2436
+ );
2437
+ const firstBtn = container.querySelector('[data-action="first"]');
2438
+ const prevBtn = container.querySelector('[data-action="prev"]');
2439
+ const nextBtn = container.querySelector('[data-action="next"]');
2440
+ const lastBtn = container.querySelector('[data-action="last"]');
2441
+ const pageSizeSelect = container.querySelector('[data-role="page-size"]');
2442
+ if (!navButtonsContainer || !pageInfo) return;
2443
+ let currentPage = parseInt(container.dataset.current || "1", 10);
2444
+ let totalPages = parseInt(container.dataset.total || "10", 10);
2445
+ let pageSize = parseInt(container.dataset.pageSize || "10", 10);
2446
+ let pageButtons = [];
2447
+ const updateUI = () => {
2448
+ pageInfo.textContent = `Halaman ${currentPage} dari ${totalPages}`;
2449
+ const isFirst = currentPage === 1;
2450
+ if (firstBtn) {
2451
+ firstBtn.disabled = isFirst;
2452
+ firstBtn.classList.toggle(
2453
+ `${PREFIX}-pagination__nav-button--disabled`,
2454
+ isFirst
2455
+ );
2456
+ firstBtn.classList.toggle(
2457
+ `${PREFIX}-pagination__nav-button--enabled`,
2458
+ !isFirst
2459
+ );
2460
+ }
2461
+ if (prevBtn) {
2462
+ prevBtn.disabled = isFirst;
2463
+ prevBtn.classList.toggle(
2464
+ `${PREFIX}-pagination__nav-button--disabled`,
2465
+ isFirst
2466
+ );
2467
+ prevBtn.classList.toggle(
2468
+ `${PREFIX}-pagination__nav-button--enabled`,
2469
+ !isFirst
2470
+ );
2471
+ }
2472
+ const isLast = currentPage === totalPages;
2473
+ if (nextBtn) {
2474
+ nextBtn.disabled = isLast;
2475
+ nextBtn.classList.toggle(
2476
+ `${PREFIX}-pagination__nav-button--disabled`,
2477
+ isLast
2478
+ );
2479
+ nextBtn.classList.toggle(
2480
+ `${PREFIX}-pagination__nav-button--enabled`,
2481
+ !isLast
2482
+ );
2483
+ }
2484
+ if (lastBtn) {
2485
+ lastBtn.disabled = isLast;
2486
+ lastBtn.classList.toggle(
2487
+ `${PREFIX}-pagination__nav-button--disabled`,
2488
+ isLast
2489
+ );
2490
+ lastBtn.classList.toggle(
2491
+ `${PREFIX}-pagination__nav-button--enabled`,
2492
+ !isLast
2493
+ );
2494
+ }
2495
+ renderPageNumbers();
2496
+ };
2497
+ const renderPageNumbers = () => {
2498
+ let start, end;
2499
+ if (currentPage === 1) {
2500
+ start = 1;
2501
+ end = Math.min(3, totalPages);
2502
+ } else if (currentPage === totalPages) {
2503
+ start = Math.max(1, totalPages - 2);
2504
+ end = totalPages;
2505
+ } else {
2506
+ start = currentPage - 1;
2507
+ end = currentPage + 1;
2508
+ }
2509
+ if (start < 1) start = 1;
2510
+ if (end > totalPages) end = totalPages;
2511
+ pageButtons.forEach((btn) => btn.remove());
2512
+ pageButtons = [];
2513
+ const refNode = nextBtn || null;
2514
+ for (let i = start; i <= end; i++) {
2515
+ const isActive = i === currentPage;
2516
+ const button = document.createElement("button");
2517
+ button.type = "button";
2518
+ button.textContent = i;
2519
+ button.className = `${PREFIX}-pagination__page-button ${PREFIX}-pagination__page-button--${isActive ? "active" : "enabled"}`;
2520
+ button.addEventListener("click", (e) => {
2521
+ e.stopPropagation();
2522
+ if (i !== currentPage) {
2523
+ goToPage(i);
2524
+ }
2525
+ });
2526
+ navButtonsContainer.insertBefore(button, refNode);
2527
+ pageButtons.push(button);
2528
+ }
2529
+ };
2530
+ const goToPage = (page) => {
2531
+ if (page < 1) page = 1;
2532
+ if (page > totalPages) page = totalPages;
2533
+ if (page === currentPage) return;
2534
+ currentPage = page;
2535
+ container.dataset.current = currentPage;
2536
+ updateUI();
2537
+ dispatchChange();
2538
+ };
2539
+ const dispatchChange = () => {
2540
+ container.dispatchEvent(
2541
+ new CustomEvent("pagination:change", {
2542
+ bubbles: true,
2543
+ detail: {
2544
+ page: currentPage,
2545
+ pageSize,
2546
+ totalPages
2547
+ }
2548
+ })
2549
+ );
2550
+ };
2551
+ if (firstBtn)
2552
+ firstBtn.addEventListener("click", () => {
2553
+ if (currentPage > 1) goToPage(1);
2554
+ });
2555
+ if (prevBtn)
2556
+ prevBtn.addEventListener("click", () => {
2557
+ if (currentPage > 1) goToPage(currentPage - 1);
2558
+ });
2559
+ if (nextBtn)
2560
+ nextBtn.addEventListener("click", () => {
2561
+ if (currentPage < totalPages) goToPage(currentPage + 1);
2562
+ });
2563
+ if (lastBtn)
2564
+ lastBtn.addEventListener("click", () => {
2565
+ if (currentPage < totalPages) goToPage(totalPages);
2566
+ });
2567
+ if (pageSizeSelect) {
2568
+ pageSizeSelect.addEventListener("change", (e) => {
2569
+ pageSize = parseInt(e.target.value, 10);
2570
+ currentPage = 1;
2571
+ container.dataset.pageSize = pageSize;
2572
+ container.dataset.current = currentPage;
2573
+ updateUI();
2574
+ dispatchChange();
2575
+ });
2576
+ }
2577
+ updateUI();
2578
+ });
2579
+ }
2580
+
2581
+ // src/js/components/stateless/toast.js
2582
+ function showToast(optionsOrMessage, variant = "default", duration = 3e3) {
2583
+ let message, title, state, style, position, actionHtml;
2584
+ if (typeof optionsOrMessage === "object") {
2585
+ message = optionsOrMessage.message || "";
2586
+ title = optionsOrMessage.title;
2587
+ state = optionsOrMessage.state || "default";
2588
+ style = optionsOrMessage.style || "solid";
2589
+ duration = optionsOrMessage.duration || 3e3;
2590
+ position = optionsOrMessage.position || "top-right";
2591
+ actionHtml = optionsOrMessage.actionHtml || "";
2592
+ } else {
2593
+ message = optionsOrMessage;
2594
+ state = variant;
2595
+ style = "solid";
2596
+ position = "top-right";
2597
+ actionHtml = "";
2598
+ }
2599
+ let containerId = `ina-toast-container-${position}`;
2600
+ let container = document.getElementById(containerId);
2601
+ if (!container) {
2602
+ container = document.createElement("div");
2603
+ container.id = containerId;
2604
+ container.className = `ina-toast-container ina-toast-container--${position}`;
2605
+ document.body.appendChild(container);
2606
+ }
2607
+ const toastItem = document.createElement("div");
2608
+ toastItem.className = "ina-toast-item";
2609
+ const toast = document.createElement("div");
2610
+ toast.className = `ina-toast ina-toast--state-${state} ina-toast--style-${style} ina-toast--visible`;
2611
+ const iconMap = {
2612
+ default: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
2613
+ destructive: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
2614
+ positive: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>'
2615
+ };
2616
+ const iconHtml = iconMap[state] || iconMap.default;
2617
+ let contentHtml = `
2618
+ <div class="ina-toast__icon">${iconHtml}</div>
2619
+ <div class="ina-toast__content">
2620
+ <div class="ina-toast__text-area">
2621
+ ${title ? `<p class="ina-toast__title">${title}</p>` : ""}
2622
+ ${message ? `<p class="ina-toast__description">${message}</p>` : ""}
2623
+ </div>
2624
+ ${actionHtml ? `<div class="ina-toast__action-area">${actionHtml}</div>` : ""}
2625
+ </div>
2626
+ <button class="ina-toast__close-button">
2627
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="ina-toast__close-icon"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
2628
+ </button>
2629
+ `;
2630
+ toast.innerHTML = contentHtml;
2631
+ toastItem.appendChild(toast);
2632
+ const closeBtn = toast.querySelector(".ina-toast__close-button");
2633
+ const close = () => {
2634
+ toast.classList.remove("ina-toast--visible");
2635
+ toast.classList.add("ina-toast--hidden");
2636
+ setTimeout(() => {
2637
+ if (toastItem.parentNode) toastItem.parentNode.removeChild(toastItem);
2638
+ if (container.children.length === 0) {
2639
+ if (container.parentNode) container.parentNode.removeChild(container);
2640
+ }
2641
+ }, 300);
2642
+ };
2643
+ closeBtn.addEventListener("click", close);
2644
+ container.appendChild(toastItem);
2645
+ if (duration > 0) {
2646
+ setTimeout(close, duration);
2647
+ }
2648
+ }
2649
+
2567
2650
  // src/js/index.js
2568
2651
  var PREFIX = "ina";
2569
2652
  function initAll() {
@@ -2576,6 +2659,7 @@ function initAll() {
2576
2659
  initBasicDropdown();
2577
2660
  initActionDropdown();
2578
2661
  initSelectDropdown();
2662
+ initRadioButton();
2579
2663
  initFileUpload();
2580
2664
  initSingleFileUpload();
2581
2665
  initFileUploadBase();
@@ -2586,9 +2670,11 @@ function initAll() {
2586
2670
  initTab();
2587
2671
  initToggle();
2588
2672
  initTimepicker();
2673
+ initPagination();
2589
2674
  initChip();
2590
2675
  }
2591
2676
  export {
2592
2677
  PREFIX,
2593
- initAll
2678
+ initAll,
2679
+ showToast
2594
2680
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idds/js",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },