@idds/js 1.0.37 → 1.0.38

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.
@@ -31,6 +31,7 @@ var InaUI = (() => {
31
31
  initModal: () => initModal,
32
32
  initRangeDatepicker: () => initRangeDatepicker,
33
33
  initTab: () => initTab,
34
+ initTimepicker: () => initTimepicker,
34
35
  initToggle: () => initToggle,
35
36
  showToast: () => showToast
36
37
  });
@@ -886,6 +887,212 @@ var InaUI = (() => {
886
887
  });
887
888
  }
888
889
 
890
+ // src/js/components/stateful/timepicker.js
891
+ function initTimepicker() {
892
+ document.querySelectorAll(".ina-time-picker").forEach((picker) => {
893
+ if (picker.dataset.initialized === "true") return;
894
+ picker.dataset.initialized = "true";
895
+ const input = picker.querySelector(".ina-time-picker__input");
896
+ const wrapper = picker.querySelector(".ina-time-picker__wrapper");
897
+ if (!input || !wrapper) return;
898
+ const format = picker.dataset.format || "HH:mm";
899
+ const use12Hours = picker.dataset.use12Hours === "true";
900
+ const showSecond = picker.dataset.showSecond === "true";
901
+ const disabled = picker.classList.contains("ina-time-picker--disabled");
902
+ const allowClear = picker.dataset.allowClear !== "false";
903
+ let isOpen = false;
904
+ let internalValue = input.value || "";
905
+ let panel = picker.querySelector(".ina-time-picker__panel");
906
+ if (!panel) {
907
+ panel = document.createElement("div");
908
+ panel.className = "ina-time-picker__panel";
909
+ panel.style.display = "none";
910
+ picker.appendChild(panel);
911
+ }
912
+ let content = panel.querySelector(".ina-time-picker__content");
913
+ if (!content) {
914
+ content = document.createElement("div");
915
+ content.className = "ina-time-picker__content";
916
+ panel.appendChild(content);
917
+ } else {
918
+ content.innerHTML = "";
919
+ }
920
+ let actions = panel.querySelector(".ina-time-picker__actions");
921
+ if (!actions) {
922
+ actions = document.createElement("div");
923
+ actions.className = "ina-time-picker__actions";
924
+ const confirmBtn = document.createElement("button");
925
+ confirmBtn.type = "button";
926
+ confirmBtn.className = "ina-time-picker__confirm-button";
927
+ confirmBtn.textContent = "Pilih";
928
+ confirmBtn.onclick = (e) => {
929
+ e.stopPropagation();
930
+ close();
931
+ };
932
+ actions.appendChild(confirmBtn);
933
+ panel.appendChild(actions);
934
+ }
935
+ const parseTime = (timeStr) => {
936
+ if (!timeStr) return { hours: 0, minutes: 0, seconds: 0, period: "AM" };
937
+ let hours = 0, minutes = 0, seconds = 0, period = "AM";
938
+ try {
939
+ if (use12Hours) {
940
+ const [time, p] = timeStr.split(" ");
941
+ const [h, m, s] = time.split(":");
942
+ hours = parseInt(h || "0", 10);
943
+ minutes = parseInt(m || "0", 10);
944
+ seconds = parseInt(s || "0", 10);
945
+ period = p || "AM";
946
+ } else {
947
+ const [h, m, s] = timeStr.split(":");
948
+ hours = parseInt(h || "0", 10);
949
+ minutes = parseInt(m || "0", 10);
950
+ seconds = parseInt(s || "0", 10);
951
+ }
952
+ } catch (e) {
953
+ console.warn("Invalid time format", timeStr);
954
+ }
955
+ return { hours, minutes, seconds, period };
956
+ };
957
+ const formatTime = (h, m, s, p) => {
958
+ const pad = (n) => n.toString().padStart(2, "0");
959
+ if (use12Hours) {
960
+ let displayHours = h;
961
+ if (displayHours === 0) displayHours = 12;
962
+ const main = `${pad(displayHours)}:${pad(m)}`;
963
+ const sec = showSecond ? `:${pad(s)}` : "";
964
+ return `${main}${sec} ${p}`;
965
+ } else {
966
+ const main = `${pad(h)}:${pad(m)}`;
967
+ const sec = showSecond ? `:${pad(s)}` : "";
968
+ return `${main}${sec}`;
969
+ }
970
+ };
971
+ let currentTime = parseTime(internalValue);
972
+ const renderColumn = (type, max) => {
973
+ const column = document.createElement("div");
974
+ column.className = `ina-time-picker__column ina-time-picker__column--${type}`;
975
+ const colContent = document.createElement("div");
976
+ colContent.className = "ina-time-picker__column-content";
977
+ column.appendChild(colContent);
978
+ const start = type === "hour" && use12Hours ? 1 : 0;
979
+ const end = type === "hour" && use12Hours ? 12 : max - 1;
980
+ for (let i = start; i <= end; i++) {
981
+ const option = document.createElement("div");
982
+ option.className = "ina-time-picker__option";
983
+ option.textContent = i.toString().padStart(2, "0");
984
+ option.dataset.value = i;
985
+ let isSelected = false;
986
+ if (type === "hour") {
987
+ isSelected = currentTime.hours === i || use12Hours && currentTime.hours === 0 && i === 12;
988
+ } else if (type === "minute") isSelected = currentTime.minutes === i;
989
+ else if (type === "second") isSelected = currentTime.seconds === i;
990
+ if (isSelected)
991
+ option.classList.add("ina-time-picker__option--selected");
992
+ option.addEventListener("click", (e) => {
993
+ e.stopPropagation();
994
+ const val = parseInt(option.dataset.value, 10);
995
+ if (type === "hour")
996
+ currentTime.hours = use12Hours && val === 12 ? 0 : val;
997
+ if (type === "hour") currentTime.hours = val;
998
+ if (type === "minute") currentTime.minutes = val;
999
+ if (type === "second") currentTime.seconds = val;
1000
+ updateInput();
1001
+ colContent.querySelectorAll(".ina-time-picker__option").forEach(
1002
+ (el) => el.classList.remove("ina-time-picker__option--selected")
1003
+ );
1004
+ option.classList.add("ina-time-picker__option--selected");
1005
+ });
1006
+ colContent.appendChild(option);
1007
+ }
1008
+ return column;
1009
+ };
1010
+ const renderPeriodColumn = () => {
1011
+ const column = document.createElement("div");
1012
+ column.className = `ina-time-picker__column ina-time-picker__column--period`;
1013
+ const colContent = document.createElement("div");
1014
+ colContent.className = "ina-time-picker__column-content";
1015
+ column.appendChild(colContent);
1016
+ ["AM", "PM"].forEach((p) => {
1017
+ const option = document.createElement("div");
1018
+ option.className = "ina-time-picker__option";
1019
+ option.textContent = p;
1020
+ if (currentTime.period === p)
1021
+ option.classList.add("ina-time-picker__option--selected");
1022
+ option.addEventListener("click", (e) => {
1023
+ e.stopPropagation();
1024
+ currentTime.period = p;
1025
+ updateInput();
1026
+ colContent.querySelectorAll(".ina-time-picker__option").forEach(
1027
+ (el) => el.classList.remove("ina-time-picker__option--selected")
1028
+ );
1029
+ option.classList.add("ina-time-picker__option--selected");
1030
+ });
1031
+ colContent.appendChild(option);
1032
+ });
1033
+ return column;
1034
+ };
1035
+ const updateInput = () => {
1036
+ const val = formatTime(
1037
+ currentTime.hours,
1038
+ currentTime.minutes,
1039
+ currentTime.seconds,
1040
+ currentTime.period
1041
+ );
1042
+ input.value = val;
1043
+ picker.dataset.value = val;
1044
+ input.dispatchEvent(new Event("change", { bubbles: true }));
1045
+ };
1046
+ const buildPanel = () => {
1047
+ content.innerHTML = "";
1048
+ content.appendChild(renderColumn("hour", use12Hours ? 13 : 24));
1049
+ content.appendChild(renderColumn("minute", 60));
1050
+ if (showSecond) content.appendChild(renderColumn("second", 60));
1051
+ if (use12Hours) content.appendChild(renderPeriodColumn());
1052
+ };
1053
+ const open = () => {
1054
+ if (disabled) return;
1055
+ isOpen = true;
1056
+ picker.classList.add("ina-time-picker--open");
1057
+ panel.style.display = "block";
1058
+ currentTime = parseTime(input.value);
1059
+ buildPanel();
1060
+ document.dispatchEvent(
1061
+ new CustomEvent("closeTimePicker", { detail: { exclude: picker } })
1062
+ );
1063
+ };
1064
+ const close = () => {
1065
+ isOpen = false;
1066
+ picker.classList.remove("ina-time-picker--open");
1067
+ panel.style.display = "none";
1068
+ };
1069
+ const toggle = (e) => {
1070
+ e.stopPropagation();
1071
+ if (isOpen) close();
1072
+ else open();
1073
+ };
1074
+ wrapper.addEventListener("click", toggle);
1075
+ input.addEventListener("click", (e) => {
1076
+ });
1077
+ document.addEventListener("click", (e) => {
1078
+ if (!picker.contains(e.target)) close();
1079
+ });
1080
+ document.addEventListener("closeTimePicker", (e) => {
1081
+ if (e.detail && e.detail.exclude !== picker) close();
1082
+ });
1083
+ const clearBtn = picker.querySelector(".ina-time-picker__clear-button");
1084
+ if (clearBtn && allowClear) {
1085
+ clearBtn.addEventListener("click", (e) => {
1086
+ e.stopPropagation();
1087
+ input.value = "";
1088
+ currentTime = { hours: 0, minutes: 0, seconds: 0, period: "AM" };
1089
+ picker.dataset.value = "";
1090
+ input.dispatchEvent(new Event("change", { bubbles: true }));
1091
+ });
1092
+ }
1093
+ });
1094
+ }
1095
+
889
1096
  // src/js/index.js
890
1097
  var PREFIX = "ina-ss";
891
1098
 
@@ -1363,6 +1570,7 @@ var InaUI = (() => {
1363
1570
  initModal();
1364
1571
  initRangeDatepicker();
1365
1572
  initTab();
1573
+ initTimepicker();
1366
1574
  initToggle();
1367
1575
  });
1368
1576
  }
package/dist/index.js CHANGED
@@ -1211,53 +1211,6 @@ function initRangeDatepicker() {
1211
1211
  });
1212
1212
  }
1213
1213
 
1214
- // src/js/components/stateless/img-compare.js
1215
- function initImgCompare(rootSelector = `.${PREFIX}-img-compare`) {
1216
- document.querySelectorAll(rootSelector).forEach((imgCompare) => {
1217
- const sliderEl = document.createElement("input");
1218
- sliderEl.type = "range";
1219
- sliderEl.min = "0";
1220
- sliderEl.max = "100";
1221
- sliderEl.value = "50";
1222
- sliderEl.setAttribute("aria-label", "Percentage of the image to show");
1223
- sliderEl.setAttribute("aria-valuenow", "50");
1224
- sliderEl.setAttribute("aria-valuemin", "0");
1225
- sliderEl.setAttribute("aria-valuemax", "100");
1226
- sliderEl.classList.add("ina-ss-img__slider");
1227
- sliderEl.addEventListener("input", () => {
1228
- imgCompare.style.setProperty(
1229
- `--${PREFIX}-position`,
1230
- `${sliderEl.value}%`
1231
- );
1232
- });
1233
- const sliderLineEl = document.createElement("div");
1234
- sliderLineEl.classList.add("ina-ss-img__slider-line");
1235
- const sliderButtonEl = document.createElement("button");
1236
- sliderButtonEl.classList.add("ina-ss-img__slider-button");
1237
- imgCompare.appendChild(sliderEl);
1238
- imgCompare.appendChild(sliderLineEl);
1239
- imgCompare.appendChild(sliderButtonEl);
1240
- });
1241
- }
1242
-
1243
- // src/js/bundle.js
1244
- if (typeof window !== void 0) {
1245
- document.addEventListener("DOMContentLoaded", () => {
1246
- initAccordion();
1247
- initBanner();
1248
- initButtonGroup();
1249
- initDatepicker();
1250
- initDropdown();
1251
- initFileUploadBase();
1252
- initFileUploadItem();
1253
- initImgCompare();
1254
- initModal();
1255
- initRangeDatepicker();
1256
- initTab();
1257
- initToggle();
1258
- });
1259
- }
1260
-
1261
1214
  // src/js/components/stateful/timepicker.js
1262
1215
  function initTimepicker() {
1263
1216
  document.querySelectorAll(".ina-time-picker").forEach((picker) => {
@@ -1464,6 +1417,54 @@ function initTimepicker() {
1464
1417
  });
1465
1418
  }
1466
1419
 
1420
+ // src/js/components/stateless/img-compare.js
1421
+ function initImgCompare(rootSelector = `.${PREFIX}-img-compare`) {
1422
+ document.querySelectorAll(rootSelector).forEach((imgCompare) => {
1423
+ const sliderEl = document.createElement("input");
1424
+ sliderEl.type = "range";
1425
+ sliderEl.min = "0";
1426
+ sliderEl.max = "100";
1427
+ sliderEl.value = "50";
1428
+ sliderEl.setAttribute("aria-label", "Percentage of the image to show");
1429
+ sliderEl.setAttribute("aria-valuenow", "50");
1430
+ sliderEl.setAttribute("aria-valuemin", "0");
1431
+ sliderEl.setAttribute("aria-valuemax", "100");
1432
+ sliderEl.classList.add("ina-ss-img__slider");
1433
+ sliderEl.addEventListener("input", () => {
1434
+ imgCompare.style.setProperty(
1435
+ `--${PREFIX}-position`,
1436
+ `${sliderEl.value}%`
1437
+ );
1438
+ });
1439
+ const sliderLineEl = document.createElement("div");
1440
+ sliderLineEl.classList.add("ina-ss-img__slider-line");
1441
+ const sliderButtonEl = document.createElement("button");
1442
+ sliderButtonEl.classList.add("ina-ss-img__slider-button");
1443
+ imgCompare.appendChild(sliderEl);
1444
+ imgCompare.appendChild(sliderLineEl);
1445
+ imgCompare.appendChild(sliderButtonEl);
1446
+ });
1447
+ }
1448
+
1449
+ // src/js/bundle.js
1450
+ if (typeof window !== void 0) {
1451
+ document.addEventListener("DOMContentLoaded", () => {
1452
+ initAccordion();
1453
+ initBanner();
1454
+ initButtonGroup();
1455
+ initDatepicker();
1456
+ initDropdown();
1457
+ initFileUploadBase();
1458
+ initFileUploadItem();
1459
+ initImgCompare();
1460
+ initModal();
1461
+ initRangeDatepicker();
1462
+ initTab();
1463
+ initTimepicker();
1464
+ initToggle();
1465
+ });
1466
+ }
1467
+
1467
1468
  // src/js/index.js
1468
1469
  var PREFIX = "ina-ss";
1469
1470
  function initAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idds/js",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },