@idds/js 1.6.1 → 1.6.3
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/dist/index.iife.js +49 -9
- package/dist/index.js +49 -9
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -1299,7 +1299,7 @@ var InaUI = (() => {
|
|
|
1299
1299
|
input.classList.add(`${PREFIX}-time-picker__input--with-suffix`);
|
|
1300
1300
|
input.placeholder = this.container.getAttribute("placeholder") || "Select time";
|
|
1301
1301
|
if (this.options.disabled) input.disabled = true;
|
|
1302
|
-
|
|
1302
|
+
input.readOnly = !!this.options.readonly;
|
|
1303
1303
|
wrapper.appendChild(input);
|
|
1304
1304
|
if (this.options.allowClear) {
|
|
1305
1305
|
clearBtn = document.createElement("button");
|
|
@@ -1315,8 +1315,22 @@ var InaUI = (() => {
|
|
|
1315
1315
|
wrapper.setAttribute("role", "combobox");
|
|
1316
1316
|
wrapper.setAttribute("aria-haspopup", "listbox");
|
|
1317
1317
|
wrapper.setAttribute("aria-expanded", "false");
|
|
1318
|
-
if (input
|
|
1319
|
-
|
|
1318
|
+
if (input) {
|
|
1319
|
+
if (!input.id) input.id = this.inputId;
|
|
1320
|
+
input.readOnly = !!this.options.readonly;
|
|
1321
|
+
}
|
|
1322
|
+
if (this.options.allowClear && !clearBtn) {
|
|
1323
|
+
clearBtn = document.createElement("button");
|
|
1324
|
+
clearBtn.type = "button";
|
|
1325
|
+
clearBtn.className = `${PREFIX}-time-picker__clear-button`;
|
|
1326
|
+
clearBtn.setAttribute("aria-label", "Hapus waktu");
|
|
1327
|
+
clearBtn.innerHTML = this.createIcon("x");
|
|
1328
|
+
clearBtn.style.display = "none";
|
|
1329
|
+
wrapper.appendChild(clearBtn);
|
|
1330
|
+
if (input) {
|
|
1331
|
+
input.classList.add(`${PREFIX}-time-picker__input--with-suffix`);
|
|
1332
|
+
}
|
|
1333
|
+
} else if (clearBtn && !clearBtn.hasAttribute("aria-label")) {
|
|
1320
1334
|
clearBtn.setAttribute("aria-label", "Hapus waktu");
|
|
1321
1335
|
}
|
|
1322
1336
|
}
|
|
@@ -1620,18 +1634,44 @@ var InaUI = (() => {
|
|
|
1620
1634
|
}
|
|
1621
1635
|
});
|
|
1622
1636
|
this.elements.input.addEventListener("input", (e) => {
|
|
1623
|
-
|
|
1624
|
-
this.
|
|
1637
|
+
let val = e.target.value;
|
|
1638
|
+
const allowedChars = this.options.use12Hours ? /[0-9: apm]/gi : /[0-9:]/g;
|
|
1639
|
+
val = (val.match(allowedChars) || []).join("");
|
|
1640
|
+
let rawDigits = val.replace(/[^0-9]/g, "");
|
|
1641
|
+
let formatted = "";
|
|
1642
|
+
if (rawDigits.length > 0) {
|
|
1643
|
+
formatted += rawDigits.slice(0, 2);
|
|
1644
|
+
if (rawDigits.length > 2) {
|
|
1645
|
+
formatted += ":" + rawDigits.slice(2, 4);
|
|
1646
|
+
if (this.options.showSecond && rawDigits.length > 4) {
|
|
1647
|
+
formatted += ":" + rawDigits.slice(4, 6);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (this.options.use12Hours) {
|
|
1652
|
+
const periodMatch = val.match(/(am|pm)/i);
|
|
1653
|
+
if (periodMatch) {
|
|
1654
|
+
formatted += " " + periodMatch[0].toUpperCase();
|
|
1655
|
+
} else if (val.includes(" ")) {
|
|
1656
|
+
formatted += " ";
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
let maxLen = 5;
|
|
1660
|
+
if (this.options.showSecond) maxLen = 8;
|
|
1661
|
+
if (this.options.use12Hours) maxLen += 3;
|
|
1662
|
+
formatted = formatted.slice(0, maxLen);
|
|
1663
|
+
e.target.value = formatted;
|
|
1664
|
+
this.state.internalValue = formatted;
|
|
1625
1665
|
const timeRegex = this.options.use12Hours ? /^(\d{1,2}):(\d{2})(?::(\d{2}))?\s?(AM|PM|am|pm)?$/ : /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;
|
|
1626
|
-
if (timeRegex.test(
|
|
1627
|
-
this.state.currentTime = this.parseTime(
|
|
1666
|
+
if (timeRegex.test(formatted)) {
|
|
1667
|
+
this.state.currentTime = this.parseTime(formatted);
|
|
1628
1668
|
if (this.state.isOpen) this.buildPanel();
|
|
1629
1669
|
}
|
|
1630
1670
|
if (this.elements.clearBtn && this.options.allowClear) {
|
|
1631
|
-
this.elements.clearBtn.style.display =
|
|
1671
|
+
this.elements.clearBtn.style.display = formatted && !this.options.disabled ? "flex" : "none";
|
|
1632
1672
|
}
|
|
1633
1673
|
if (typeof this.options.onChange === "function") {
|
|
1634
|
-
this.options.onChange(
|
|
1674
|
+
this.options.onChange(formatted);
|
|
1635
1675
|
}
|
|
1636
1676
|
});
|
|
1637
1677
|
this.elements.input.addEventListener("click", (e) => {
|
package/dist/index.js
CHANGED
|
@@ -1318,7 +1318,7 @@ var TimePicker = class {
|
|
|
1318
1318
|
input.classList.add(`${PREFIX}-time-picker__input--with-suffix`);
|
|
1319
1319
|
input.placeholder = this.container.getAttribute("placeholder") || "Select time";
|
|
1320
1320
|
if (this.options.disabled) input.disabled = true;
|
|
1321
|
-
|
|
1321
|
+
input.readOnly = !!this.options.readonly;
|
|
1322
1322
|
wrapper.appendChild(input);
|
|
1323
1323
|
if (this.options.allowClear) {
|
|
1324
1324
|
clearBtn = document.createElement("button");
|
|
@@ -1334,8 +1334,22 @@ var TimePicker = class {
|
|
|
1334
1334
|
wrapper.setAttribute("role", "combobox");
|
|
1335
1335
|
wrapper.setAttribute("aria-haspopup", "listbox");
|
|
1336
1336
|
wrapper.setAttribute("aria-expanded", "false");
|
|
1337
|
-
if (input
|
|
1338
|
-
|
|
1337
|
+
if (input) {
|
|
1338
|
+
if (!input.id) input.id = this.inputId;
|
|
1339
|
+
input.readOnly = !!this.options.readonly;
|
|
1340
|
+
}
|
|
1341
|
+
if (this.options.allowClear && !clearBtn) {
|
|
1342
|
+
clearBtn = document.createElement("button");
|
|
1343
|
+
clearBtn.type = "button";
|
|
1344
|
+
clearBtn.className = `${PREFIX}-time-picker__clear-button`;
|
|
1345
|
+
clearBtn.setAttribute("aria-label", "Hapus waktu");
|
|
1346
|
+
clearBtn.innerHTML = this.createIcon("x");
|
|
1347
|
+
clearBtn.style.display = "none";
|
|
1348
|
+
wrapper.appendChild(clearBtn);
|
|
1349
|
+
if (input) {
|
|
1350
|
+
input.classList.add(`${PREFIX}-time-picker__input--with-suffix`);
|
|
1351
|
+
}
|
|
1352
|
+
} else if (clearBtn && !clearBtn.hasAttribute("aria-label")) {
|
|
1339
1353
|
clearBtn.setAttribute("aria-label", "Hapus waktu");
|
|
1340
1354
|
}
|
|
1341
1355
|
}
|
|
@@ -1639,18 +1653,44 @@ var TimePicker = class {
|
|
|
1639
1653
|
}
|
|
1640
1654
|
});
|
|
1641
1655
|
this.elements.input.addEventListener("input", (e) => {
|
|
1642
|
-
|
|
1643
|
-
this.
|
|
1656
|
+
let val = e.target.value;
|
|
1657
|
+
const allowedChars = this.options.use12Hours ? /[0-9: apm]/gi : /[0-9:]/g;
|
|
1658
|
+
val = (val.match(allowedChars) || []).join("");
|
|
1659
|
+
let rawDigits = val.replace(/[^0-9]/g, "");
|
|
1660
|
+
let formatted = "";
|
|
1661
|
+
if (rawDigits.length > 0) {
|
|
1662
|
+
formatted += rawDigits.slice(0, 2);
|
|
1663
|
+
if (rawDigits.length > 2) {
|
|
1664
|
+
formatted += ":" + rawDigits.slice(2, 4);
|
|
1665
|
+
if (this.options.showSecond && rawDigits.length > 4) {
|
|
1666
|
+
formatted += ":" + rawDigits.slice(4, 6);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
if (this.options.use12Hours) {
|
|
1671
|
+
const periodMatch = val.match(/(am|pm)/i);
|
|
1672
|
+
if (periodMatch) {
|
|
1673
|
+
formatted += " " + periodMatch[0].toUpperCase();
|
|
1674
|
+
} else if (val.includes(" ")) {
|
|
1675
|
+
formatted += " ";
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
let maxLen = 5;
|
|
1679
|
+
if (this.options.showSecond) maxLen = 8;
|
|
1680
|
+
if (this.options.use12Hours) maxLen += 3;
|
|
1681
|
+
formatted = formatted.slice(0, maxLen);
|
|
1682
|
+
e.target.value = formatted;
|
|
1683
|
+
this.state.internalValue = formatted;
|
|
1644
1684
|
const timeRegex = this.options.use12Hours ? /^(\d{1,2}):(\d{2})(?::(\d{2}))?\s?(AM|PM|am|pm)?$/ : /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/;
|
|
1645
|
-
if (timeRegex.test(
|
|
1646
|
-
this.state.currentTime = this.parseTime(
|
|
1685
|
+
if (timeRegex.test(formatted)) {
|
|
1686
|
+
this.state.currentTime = this.parseTime(formatted);
|
|
1647
1687
|
if (this.state.isOpen) this.buildPanel();
|
|
1648
1688
|
}
|
|
1649
1689
|
if (this.elements.clearBtn && this.options.allowClear) {
|
|
1650
|
-
this.elements.clearBtn.style.display =
|
|
1690
|
+
this.elements.clearBtn.style.display = formatted && !this.options.disabled ? "flex" : "none";
|
|
1651
1691
|
}
|
|
1652
1692
|
if (typeof this.options.onChange === "function") {
|
|
1653
|
-
this.options.onChange(
|
|
1693
|
+
this.options.onChange(formatted);
|
|
1654
1694
|
}
|
|
1655
1695
|
});
|
|
1656
1696
|
this.elements.input.addEventListener("click", (e) => {
|