@idds/js 1.0.54 → 1.0.56

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.
@@ -21,8 +21,8 @@ var InaUI = (() => {
21
21
  var bundle_exports = {};
22
22
  __export(bundle_exports, {
23
23
  initAccordion: () => initAccordion,
24
- initBanner: () => initBanner,
25
24
  initButtonGroup: () => initButtonGroup,
25
+ initCheckbox: () => initCheckbox,
26
26
  initDatepicker: () => initDatepicker,
27
27
  initDropdown: () => initDropdown,
28
28
  initFileUploadBase: () => initFileUploadBase,
@@ -36,6 +36,50 @@ var InaUI = (() => {
36
36
  showToast: () => showToast
37
37
  });
38
38
 
39
+ // src/js/components/stateful/checkbox.js
40
+ function initCheckbox(rootSelector = `.${PREFIX}-checkbox`) {
41
+ const checkboxes = document.querySelectorAll(rootSelector);
42
+ checkboxes.forEach((checkboxLabel) => {
43
+ if (checkboxLabel.__inaCheckboxInitialized) return;
44
+ const input = checkboxLabel.querySelector(`.${PREFIX}-checkbox__input`);
45
+ const box = checkboxLabel.querySelector(`.${PREFIX}-checkbox__box`);
46
+ if (!input || !box) return;
47
+ const ICON_CHECK = `
48
+ <svg class="${PREFIX}-checkbox__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
49
+ <path d="M20 6L9 17L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
50
+ </svg>
51
+ `;
52
+ const ICON_MINUS = `
53
+ <svg class="${PREFIX}-checkbox__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
54
+ <path d="M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
55
+ </svg>
56
+ `;
57
+ const updateState = () => {
58
+ box.classList.remove(`${PREFIX}-checkbox__box--checked`);
59
+ box.classList.remove(`${PREFIX}-checkbox__box--unchecked`);
60
+ box.classList.remove(`${PREFIX}-checkbox__box--indeterminate`);
61
+ checkboxLabel.classList.remove(`${PREFIX}-checkbox--disabled`);
62
+ if (input.disabled) {
63
+ checkboxLabel.classList.add(`${PREFIX}-checkbox--disabled`);
64
+ }
65
+ if (input.indeterminate) {
66
+ box.classList.add(`${PREFIX}-checkbox__box--indeterminate`);
67
+ box.innerHTML = ICON_MINUS;
68
+ } else if (input.checked) {
69
+ box.classList.add(`${PREFIX}-checkbox__box--checked`);
70
+ box.innerHTML = ICON_CHECK;
71
+ } else {
72
+ box.classList.add(`${PREFIX}-checkbox__box--unchecked`);
73
+ box.innerHTML = "";
74
+ }
75
+ };
76
+ updateState();
77
+ input.addEventListener("change", updateState);
78
+ checkboxLabel.__inaCheckboxInitialized = true;
79
+ checkboxLabel.updateState = updateState;
80
+ });
81
+ }
82
+
39
83
  // src/js/components/stateful/tab.js
40
84
  function initTab(rootSelector = `.${PREFIX}-tab`) {
41
85
  document.querySelectorAll(rootSelector).forEach((tab) => {
@@ -927,68 +971,6 @@ var InaUI = (() => {
927
971
  });
928
972
  }
929
973
 
930
- // src/js/components/stateless/banner.js
931
- function initBanner(rootSelector = `.${PREFIX}-banner`) {
932
- document.querySelectorAll(rootSelector).forEach((banner) => {
933
- const mediaQuery = window.matchMedia("(max-width: 1279px)");
934
- function updateElText(targetEl, mediaQuery2) {
935
- targetEl.textContent = mediaQuery2.matches ? "Situs ini merupakan platform resmi pemerintah." : "Situs ini merupakan platform resmi pemerintah Indonesia yang dikelola oleh INA Digital.";
936
- }
937
- const contentEl = document.createElement("div");
938
- contentEl.className = `${PREFIX}-banner__content`;
939
- const iconEl = document.createElement("div");
940
- iconEl.className = `${PREFIX}-banner__icon`;
941
- const wrapperEl = document.createElement("div");
942
- wrapperEl.className = `${PREFIX}-banner__wrapper`;
943
- const headerEl = document.createElement("div");
944
- headerEl.className = `${PREFIX}-banner__header`;
945
- const headerWrapperEl = document.createElement("div");
946
- headerWrapperEl.className = `${PREFIX}-banner__header-wrapper`;
947
- const headerTitleEl = document.createElement("p");
948
- headerTitleEl.className = `${PREFIX}-banner__title`;
949
- headerTitleEl.textContent = "Situs ini merupakan platform resmi pemerintah. ";
950
- updateElText(headerTitleEl, mediaQuery);
951
- const identityEl = document.createElement("a");
952
- identityEl.href = "#";
953
- identityEl.className = `${PREFIX}-banner__identity`;
954
- identityEl.textContent = "Lebih Lanjut";
955
- identityEl.addEventListener("click", (e) => {
956
- e.preventDefault();
957
- banner.classList.toggle("open");
958
- });
959
- const chevronEl = document.createElement("button");
960
- chevronEl.className = `${PREFIX}-banner__chevron`;
961
- chevronEl.addEventListener("click", (e) => {
962
- e.preventDefault();
963
- banner.classList.toggle("open");
964
- const isOpen = banner.classList.contains("open");
965
- headerTitleEl.textContent = isOpen ? "Situs ini merupakan platform resmi pemerintah Indonesia yang dikelola oleh INA Digital." : "Situs ini merupakan platform resmi pemerintah. ";
966
- });
967
- headerWrapperEl.appendChild(headerTitleEl);
968
- headerWrapperEl.appendChild(identityEl);
969
- headerEl.appendChild(headerWrapperEl);
970
- headerEl.appendChild(chevronEl);
971
- const bodyEl = document.createElement("div");
972
- bodyEl.className = `${PREFIX}-banner__body`;
973
- const bodyTitleEl = document.createElement("p");
974
- bodyTitleEl.className = `${PREFIX}-banner__title`;
975
- bodyTitleEl.textContent = "INA Digital adalah inisiatif pemerintah Indonesia untuk membangun ekosistem layanan publik digital yang terintegrasi, aman, dan mudah digunakan oleh masyarakat.";
976
- const descEl = document.createElement("p");
977
- descEl.className = `${PREFIX}-banner__desc`;
978
- descEl.textContent = "Pastikan untuk memperhatikan ikon kunci (\u{1F512}) dan alamat https:// sebagai penanda keamanan.";
979
- bodyEl.appendChild(bodyTitleEl);
980
- bodyEl.appendChild(descEl);
981
- wrapperEl.appendChild(headerEl);
982
- wrapperEl.appendChild(bodyEl);
983
- contentEl.appendChild(iconEl);
984
- contentEl.appendChild(wrapperEl);
985
- banner.appendChild(contentEl);
986
- mediaQuery.addEventListener("change", () => {
987
- updateElText(headerTitleEl, mediaQuery);
988
- });
989
- });
990
- }
991
-
992
974
  // src/js/components/stateful/file-upload-base.js
993
975
  function initFileUploadBase(rootSelector = `.${PREFIX}-file-base`) {
994
976
  document.querySelectorAll(rootSelector).forEach((fileUploadBase) => {
@@ -1375,28 +1357,45 @@ var InaUI = (() => {
1375
1357
  var PREFIX = "ina";
1376
1358
 
1377
1359
  // src/js/components/stateful/button-group.js
1378
- function initButtonGroup(rootSelector = `.${PREFIX}-btn-group`) {
1379
- document.querySelectorAll(rootSelector).forEach((buttonGroup) => {
1380
- const buttons = buttonGroup.querySelectorAll(`.${PREFIX}-btn`);
1360
+ function initButtonGroup(rootSelector = `.${PREFIX}-button-group`) {
1361
+ const buttonGroups = document.querySelectorAll(rootSelector);
1362
+ buttonGroups.forEach((buttonGroup) => {
1363
+ if (buttonGroup.__inaButtonGroupInitialized) return;
1364
+ const buttons = buttonGroup.querySelectorAll(
1365
+ `.${PREFIX}-button-group__button`
1366
+ );
1367
+ const updateState = (clickedButton) => {
1368
+ const isDisabled = clickedButton.hasAttribute("disabled") || clickedButton.classList.contains(
1369
+ `${PREFIX}-button-group__button--disabled`
1370
+ );
1371
+ if (isDisabled) return;
1372
+ const value = clickedButton.getAttribute("data-value");
1373
+ buttons.forEach((btn) => {
1374
+ if (btn === clickedButton) {
1375
+ btn.classList.add(`${PREFIX}-button-group__button--selected`);
1376
+ btn.setAttribute("aria-pressed", "true");
1377
+ } else {
1378
+ btn.classList.remove(`${PREFIX}-button-group__button--selected`);
1379
+ btn.setAttribute("aria-pressed", "false");
1380
+ }
1381
+ });
1382
+ buttonGroup.dispatchEvent(
1383
+ new CustomEvent("button-group:change", {
1384
+ detail: { value },
1385
+ bubbles: true,
1386
+ composed: true
1387
+ })
1388
+ );
1389
+ };
1381
1390
  buttons.forEach((button) => {
1382
- function updateState() {
1383
- const index = Array.from(buttons).indexOf(button);
1384
- buttons.forEach((button2, i) => {
1385
- button2.classList.remove(`${PREFIX}-btn--active`);
1386
- if (i === index) {
1387
- button2.classList.add(`${PREFIX}-btn--active`);
1388
- }
1389
- });
1390
- button.dispatchEvent(
1391
- new CustomEvent("button:change", {
1392
- detail: { activeIndex: index },
1393
- bubbles: true,
1394
- composed: true
1395
- })
1396
- );
1397
- }
1398
- button.addEventListener("click", updateState);
1391
+ button.addEventListener("click", (e) => {
1392
+ if (button.type !== "submit") {
1393
+ e.preventDefault();
1394
+ }
1395
+ updateState(button);
1396
+ });
1399
1397
  });
1398
+ buttonGroup.__inaButtonGroupInitialized = true;
1400
1399
  });
1401
1400
  }
1402
1401
 
@@ -1838,8 +1837,8 @@ var InaUI = (() => {
1838
1837
  if (typeof window !== void 0) {
1839
1838
  document.addEventListener("DOMContentLoaded", () => {
1840
1839
  initAccordion();
1841
- initBanner();
1842
1840
  initButtonGroup();
1841
+ initCheckbox();
1843
1842
  initDatepicker();
1844
1843
  initDropdown();
1845
1844
  initFileUploadBase();
package/dist/index.js CHANGED
@@ -1,26 +1,87 @@
1
1
  // src/js/components/stateful/button-group.js
2
- function initButtonGroup(rootSelector = `.${PREFIX}-btn-group`) {
3
- document.querySelectorAll(rootSelector).forEach((buttonGroup) => {
4
- const buttons = buttonGroup.querySelectorAll(`.${PREFIX}-btn`);
2
+ function initButtonGroup(rootSelector = `.${PREFIX}-button-group`) {
3
+ const buttonGroups = document.querySelectorAll(rootSelector);
4
+ buttonGroups.forEach((buttonGroup) => {
5
+ if (buttonGroup.__inaButtonGroupInitialized) return;
6
+ const buttons = buttonGroup.querySelectorAll(
7
+ `.${PREFIX}-button-group__button`
8
+ );
9
+ const updateState = (clickedButton) => {
10
+ const isDisabled = clickedButton.hasAttribute("disabled") || clickedButton.classList.contains(
11
+ `${PREFIX}-button-group__button--disabled`
12
+ );
13
+ if (isDisabled) return;
14
+ const value = clickedButton.getAttribute("data-value");
15
+ buttons.forEach((btn) => {
16
+ if (btn === clickedButton) {
17
+ btn.classList.add(`${PREFIX}-button-group__button--selected`);
18
+ btn.setAttribute("aria-pressed", "true");
19
+ } else {
20
+ btn.classList.remove(`${PREFIX}-button-group__button--selected`);
21
+ btn.setAttribute("aria-pressed", "false");
22
+ }
23
+ });
24
+ buttonGroup.dispatchEvent(
25
+ new CustomEvent("button-group:change", {
26
+ detail: { value },
27
+ bubbles: true,
28
+ composed: true
29
+ })
30
+ );
31
+ };
5
32
  buttons.forEach((button) => {
6
- function updateState() {
7
- const index = Array.from(buttons).indexOf(button);
8
- buttons.forEach((button2, i) => {
9
- button2.classList.remove(`${PREFIX}-btn--active`);
10
- if (i === index) {
11
- button2.classList.add(`${PREFIX}-btn--active`);
12
- }
13
- });
14
- button.dispatchEvent(
15
- new CustomEvent("button:change", {
16
- detail: { activeIndex: index },
17
- bubbles: true,
18
- composed: true
19
- })
20
- );
21
- }
22
- button.addEventListener("click", updateState);
33
+ button.addEventListener("click", (e) => {
34
+ if (button.type !== "submit") {
35
+ e.preventDefault();
36
+ }
37
+ updateState(button);
38
+ });
23
39
  });
40
+ buttonGroup.__inaButtonGroupInitialized = true;
41
+ });
42
+ }
43
+
44
+ // src/js/components/stateful/checkbox.js
45
+ function initCheckbox(rootSelector = `.${PREFIX}-checkbox`) {
46
+ const checkboxes = document.querySelectorAll(rootSelector);
47
+ checkboxes.forEach((checkboxLabel) => {
48
+ if (checkboxLabel.__inaCheckboxInitialized) return;
49
+ const input = checkboxLabel.querySelector(`.${PREFIX}-checkbox__input`);
50
+ const box = checkboxLabel.querySelector(`.${PREFIX}-checkbox__box`);
51
+ if (!input || !box) return;
52
+ const ICON_CHECK = `
53
+ <svg class="${PREFIX}-checkbox__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
54
+ <path d="M20 6L9 17L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
55
+ </svg>
56
+ `;
57
+ const ICON_MINUS = `
58
+ <svg class="${PREFIX}-checkbox__icon" width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
59
+ <path d="M5 12H19" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
60
+ </svg>
61
+ `;
62
+ const updateState = () => {
63
+ box.classList.remove(`${PREFIX}-checkbox__box--checked`);
64
+ box.classList.remove(`${PREFIX}-checkbox__box--unchecked`);
65
+ box.classList.remove(`${PREFIX}-checkbox__box--indeterminate`);
66
+ checkboxLabel.classList.remove(`${PREFIX}-checkbox--disabled`);
67
+ if (input.disabled) {
68
+ checkboxLabel.classList.add(`${PREFIX}-checkbox--disabled`);
69
+ }
70
+ if (input.indeterminate) {
71
+ box.classList.add(`${PREFIX}-checkbox__box--indeterminate`);
72
+ box.innerHTML = ICON_MINUS;
73
+ } else if (input.checked) {
74
+ box.classList.add(`${PREFIX}-checkbox__box--checked`);
75
+ box.innerHTML = ICON_CHECK;
76
+ } else {
77
+ box.classList.add(`${PREFIX}-checkbox__box--unchecked`);
78
+ box.innerHTML = "";
79
+ }
80
+ };
81
+ updateState();
82
+ input.addEventListener("change", updateState);
83
+ checkboxLabel.__inaCheckboxInitialized = true;
84
+ checkboxLabel.updateState = updateState;
24
85
  });
25
86
  }
26
87
 
@@ -915,68 +976,6 @@ function initDropdown(rootSelector = `.${PREFIX}-dropdown`) {
915
976
  });
916
977
  }
917
978
 
918
- // src/js/components/stateless/banner.js
919
- function initBanner(rootSelector = `.${PREFIX}-banner`) {
920
- document.querySelectorAll(rootSelector).forEach((banner) => {
921
- const mediaQuery = window.matchMedia("(max-width: 1279px)");
922
- function updateElText(targetEl, mediaQuery2) {
923
- targetEl.textContent = mediaQuery2.matches ? "Situs ini merupakan platform resmi pemerintah." : "Situs ini merupakan platform resmi pemerintah Indonesia yang dikelola oleh INA Digital.";
924
- }
925
- const contentEl = document.createElement("div");
926
- contentEl.className = `${PREFIX}-banner__content`;
927
- const iconEl = document.createElement("div");
928
- iconEl.className = `${PREFIX}-banner__icon`;
929
- const wrapperEl = document.createElement("div");
930
- wrapperEl.className = `${PREFIX}-banner__wrapper`;
931
- const headerEl = document.createElement("div");
932
- headerEl.className = `${PREFIX}-banner__header`;
933
- const headerWrapperEl = document.createElement("div");
934
- headerWrapperEl.className = `${PREFIX}-banner__header-wrapper`;
935
- const headerTitleEl = document.createElement("p");
936
- headerTitleEl.className = `${PREFIX}-banner__title`;
937
- headerTitleEl.textContent = "Situs ini merupakan platform resmi pemerintah. ";
938
- updateElText(headerTitleEl, mediaQuery);
939
- const identityEl = document.createElement("a");
940
- identityEl.href = "#";
941
- identityEl.className = `${PREFIX}-banner__identity`;
942
- identityEl.textContent = "Lebih Lanjut";
943
- identityEl.addEventListener("click", (e) => {
944
- e.preventDefault();
945
- banner.classList.toggle("open");
946
- });
947
- const chevronEl = document.createElement("button");
948
- chevronEl.className = `${PREFIX}-banner__chevron`;
949
- chevronEl.addEventListener("click", (e) => {
950
- e.preventDefault();
951
- banner.classList.toggle("open");
952
- const isOpen = banner.classList.contains("open");
953
- headerTitleEl.textContent = isOpen ? "Situs ini merupakan platform resmi pemerintah Indonesia yang dikelola oleh INA Digital." : "Situs ini merupakan platform resmi pemerintah. ";
954
- });
955
- headerWrapperEl.appendChild(headerTitleEl);
956
- headerWrapperEl.appendChild(identityEl);
957
- headerEl.appendChild(headerWrapperEl);
958
- headerEl.appendChild(chevronEl);
959
- const bodyEl = document.createElement("div");
960
- bodyEl.className = `${PREFIX}-banner__body`;
961
- const bodyTitleEl = document.createElement("p");
962
- bodyTitleEl.className = `${PREFIX}-banner__title`;
963
- bodyTitleEl.textContent = "INA Digital adalah inisiatif pemerintah Indonesia untuk membangun ekosistem layanan publik digital yang terintegrasi, aman, dan mudah digunakan oleh masyarakat.";
964
- const descEl = document.createElement("p");
965
- descEl.className = `${PREFIX}-banner__desc`;
966
- descEl.textContent = "Pastikan untuk memperhatikan ikon kunci (\u{1F512}) dan alamat https:// sebagai penanda keamanan.";
967
- bodyEl.appendChild(bodyTitleEl);
968
- bodyEl.appendChild(descEl);
969
- wrapperEl.appendChild(headerEl);
970
- wrapperEl.appendChild(bodyEl);
971
- contentEl.appendChild(iconEl);
972
- contentEl.appendChild(wrapperEl);
973
- banner.appendChild(contentEl);
974
- mediaQuery.addEventListener("change", () => {
975
- updateElText(headerTitleEl, mediaQuery);
976
- });
977
- });
978
- }
979
-
980
979
  // src/js/components/stateful/file-upload-base.js
981
980
  function initFileUploadBase(rootSelector = `.${PREFIX}-file-base`) {
982
981
  document.querySelectorAll(rootSelector).forEach((fileUploadBase) => {
@@ -1728,8 +1727,8 @@ function initImgCompare(rootSelector = `.${PREFIX}-img-compare`) {
1728
1727
  if (typeof window !== void 0) {
1729
1728
  document.addEventListener("DOMContentLoaded", () => {
1730
1729
  initAccordion();
1731
- initBanner();
1732
1730
  initButtonGroup();
1731
+ initCheckbox();
1733
1732
  initDatepicker();
1734
1733
  initDropdown();
1735
1734
  initFileUploadBase();
@@ -1749,6 +1748,7 @@ function initAll() {
1749
1748
  initAccordion();
1750
1749
  initBanner();
1751
1750
  initButtonGroup();
1751
+ initCheckbox();
1752
1752
  initDatepicker();
1753
1753
  initDropdown();
1754
1754
  initFileUploadBase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idds/js",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },