@idds/js 1.0.98 → 1.2.0
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 +430 -20
- package/dist/index.js +428 -20
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -35,6 +35,7 @@ var InaUI = (() => {
|
|
|
35
35
|
initFileUploadItem: () => initFileUploadItem,
|
|
36
36
|
initImgCompare: () => initImgCompare,
|
|
37
37
|
initModal: () => initModal,
|
|
38
|
+
initMonthPicker: () => initMonthPicker,
|
|
38
39
|
initPagination: () => initPagination,
|
|
39
40
|
initRadioButton: () => initRadioButton,
|
|
40
41
|
initRangeDatepicker: () => initRangeDatepicker,
|
|
@@ -47,6 +48,7 @@ var InaUI = (() => {
|
|
|
47
48
|
initTable: () => initTable,
|
|
48
49
|
initTimepicker: () => initTimepicker,
|
|
49
50
|
initToggle: () => initToggle,
|
|
51
|
+
initYearPicker: () => initYearPicker,
|
|
50
52
|
setBrandTheme: () => setBrandTheme,
|
|
51
53
|
showToast: () => showToast
|
|
52
54
|
});
|
|
@@ -2954,34 +2956,59 @@ var InaUI = (() => {
|
|
|
2954
2956
|
if (container.__inaChipInitialized) return;
|
|
2955
2957
|
const showCustomization = container.getAttribute("data-show-customization") === "true";
|
|
2956
2958
|
const customizationLabel = container.getAttribute("data-customization-label") || "Kustomisasi";
|
|
2959
|
+
const isMultiple = container.getAttribute("data-multiple") === "true";
|
|
2957
2960
|
let selectedValue = container.getAttribute("data-selected") || "";
|
|
2958
2961
|
const list = container.querySelector(`.${PREFIX4}-chip__list`);
|
|
2959
2962
|
const items = list ? list.querySelectorAll(`.${PREFIX4}-chip__item`) : [];
|
|
2960
2963
|
let customFieldContainer = container.querySelector(
|
|
2961
2964
|
`.${PREFIX4}-chip__custom-field`
|
|
2962
2965
|
);
|
|
2966
|
+
const getNormalizedSelected = () => {
|
|
2967
|
+
if (!selectedValue) return [];
|
|
2968
|
+
return isMultiple ? selectedValue.split(",").map((s) => s.trim()).filter(Boolean) : [selectedValue];
|
|
2969
|
+
};
|
|
2963
2970
|
const updateUI = () => {
|
|
2964
|
-
|
|
2971
|
+
const normSelected = getNormalizedSelected();
|
|
2972
|
+
const getInitialFocusIndex = () => {
|
|
2973
|
+
if (normSelected.length > 0) {
|
|
2974
|
+
const standardValues = Array.from(items).filter((item) => item.textContent.trim() !== customizationLabel).map((item) => item.getAttribute("data-value"));
|
|
2975
|
+
const hasCustomVal = normSelected.some(
|
|
2976
|
+
(val) => !standardValues.includes(val) && val !== ""
|
|
2977
|
+
);
|
|
2978
|
+
if (hasCustomVal && showCustomization) {
|
|
2979
|
+
return items.length - 1;
|
|
2980
|
+
}
|
|
2981
|
+
const firstSelectedIndex = Array.from(items).findIndex(
|
|
2982
|
+
(opt) => normSelected.includes(opt.getAttribute("data-value"))
|
|
2983
|
+
);
|
|
2984
|
+
if (firstSelectedIndex !== -1) return firstSelectedIndex;
|
|
2985
|
+
}
|
|
2986
|
+
return 0;
|
|
2987
|
+
};
|
|
2988
|
+
const focusedIndex = getInitialFocusIndex();
|
|
2989
|
+
items.forEach((item, index2) => {
|
|
2965
2990
|
const itemValue = item.getAttribute("data-value");
|
|
2966
|
-
const isSelected = itemValue ===
|
|
2991
|
+
const isSelected = normSelected.includes(itemValue) || showCustomization && item.textContent.trim() === customizationLabel && normSelected.some(
|
|
2992
|
+
(val) => !Array.from(items).filter((i) => i.textContent.trim() !== customizationLabel).map((i) => i.getAttribute("data-value")).includes(val) && val !== ""
|
|
2993
|
+
);
|
|
2967
2994
|
if (isSelected) {
|
|
2968
2995
|
item.classList.add(`${PREFIX4}-chip__item--selected`);
|
|
2969
2996
|
} else {
|
|
2970
2997
|
item.classList.remove(`${PREFIX4}-chip__item--selected`);
|
|
2971
2998
|
}
|
|
2999
|
+
item.setAttribute("tabindex", index2 === focusedIndex ? "0" : "-1");
|
|
2972
3000
|
});
|
|
2973
3001
|
if (showCustomization) {
|
|
2974
|
-
const
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
});
|
|
3002
|
+
const standardValues = Array.from(items).filter((item) => item.textContent.trim() !== customizationLabel).map((item) => item.getAttribute("data-value"));
|
|
3003
|
+
const customValues = normSelected.filter(
|
|
3004
|
+
(val) => !standardValues.includes(val) && val !== ""
|
|
3005
|
+
);
|
|
3006
|
+
const isStandard = customValues.length === 0;
|
|
3007
|
+
const primaryCustomValue = customValues[customValues.length - 1] || "";
|
|
2981
3008
|
const toggleBtn = Array.from(items).find(
|
|
2982
3009
|
(i) => i.textContent.trim() === customizationLabel
|
|
2983
3010
|
);
|
|
2984
|
-
const showInput = toggleBtn &&
|
|
3011
|
+
const showInput = toggleBtn && normSelected.includes(toggleBtn.getAttribute("data-value")) || !isStandard && normSelected.length > 0;
|
|
2985
3012
|
if (showInput) {
|
|
2986
3013
|
if (!customFieldContainer) {
|
|
2987
3014
|
customFieldContainer = document.createElement("div");
|
|
@@ -2995,7 +3022,7 @@ var InaUI = (() => {
|
|
|
2995
3022
|
customFieldContainer.innerHTML = `
|
|
2996
3023
|
<div class="${PREFIX4}-text-field ${PREFIX4}-text-field--size-medium ${PREFIX4}-text-field--variant-outline ${PREFIX4}-chip__input">
|
|
2997
3024
|
<div class="${PREFIX4}-text-field__wrapper">
|
|
2998
|
-
<input type="text" class="${PREFIX4}-text-field__input" placeholder="Masukkan data yang Anda inginkan" value="${!isStandard ?
|
|
3025
|
+
<input type="text" class="${PREFIX4}-text-field__input" placeholder="Masukkan data yang Anda inginkan" value="${!isStandard ? primaryCustomValue : ""}" />
|
|
2999
3026
|
</div>
|
|
3000
3027
|
</div>
|
|
3001
3028
|
`;
|
|
@@ -3003,21 +3030,21 @@ var InaUI = (() => {
|
|
|
3003
3030
|
input.addEventListener("blur", (e) => {
|
|
3004
3031
|
const val = e.target.value;
|
|
3005
3032
|
if (val.trim()) {
|
|
3006
|
-
handleSelect(val);
|
|
3007
|
-
} else {
|
|
3008
|
-
handleSelect("");
|
|
3033
|
+
handleSelect(val.trim());
|
|
3009
3034
|
}
|
|
3010
3035
|
});
|
|
3011
3036
|
input.addEventListener("keydown", (e) => {
|
|
3012
3037
|
if (e.key === "Enter") {
|
|
3013
|
-
|
|
3038
|
+
if (e.target.value.trim()) {
|
|
3039
|
+
handleSelect(e.target.value.trim());
|
|
3040
|
+
}
|
|
3014
3041
|
e.target.blur();
|
|
3015
3042
|
}
|
|
3016
3043
|
});
|
|
3017
3044
|
} else {
|
|
3018
3045
|
const inputEl = customFieldContainer.querySelector("input");
|
|
3019
3046
|
if (inputEl && document.activeElement !== inputEl) {
|
|
3020
|
-
inputEl.value = !isStandard ?
|
|
3047
|
+
inputEl.value = !isStandard ? primaryCustomValue : "";
|
|
3021
3048
|
}
|
|
3022
3049
|
}
|
|
3023
3050
|
customFieldContainer.style.display = "block";
|
|
@@ -3029,17 +3056,41 @@ var InaUI = (() => {
|
|
|
3029
3056
|
}
|
|
3030
3057
|
};
|
|
3031
3058
|
const handleSelect = (val) => {
|
|
3032
|
-
|
|
3033
|
-
|
|
3059
|
+
if (!val) return;
|
|
3060
|
+
let finalVal = val;
|
|
3061
|
+
if (isMultiple) {
|
|
3062
|
+
const normSelected = getNormalizedSelected();
|
|
3063
|
+
let newSelected;
|
|
3064
|
+
if (normSelected.includes(val)) {
|
|
3065
|
+
newSelected = normSelected.filter((v) => v !== val);
|
|
3066
|
+
} else {
|
|
3067
|
+
newSelected = [...normSelected, val];
|
|
3068
|
+
}
|
|
3069
|
+
finalVal = newSelected;
|
|
3070
|
+
selectedValue = newSelected.join(",");
|
|
3071
|
+
} else {
|
|
3072
|
+
selectedValue = val;
|
|
3073
|
+
}
|
|
3074
|
+
container.setAttribute("data-selected", selectedValue);
|
|
3034
3075
|
updateUI();
|
|
3035
3076
|
container.dispatchEvent(
|
|
3036
3077
|
new CustomEvent("chip:select", {
|
|
3037
|
-
detail: { value:
|
|
3078
|
+
detail: { value: finalVal },
|
|
3038
3079
|
bubbles: true
|
|
3039
3080
|
})
|
|
3040
3081
|
);
|
|
3041
3082
|
};
|
|
3042
|
-
|
|
3083
|
+
let currentFocusedIndex = -1;
|
|
3084
|
+
const setItemFocus = (index2) => {
|
|
3085
|
+
items.forEach((item, i) => {
|
|
3086
|
+
item.setAttribute("tabindex", i === index2 ? "0" : "-1");
|
|
3087
|
+
});
|
|
3088
|
+
if (items[index2]) {
|
|
3089
|
+
items[index2].focus();
|
|
3090
|
+
currentFocusedIndex = index2;
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
items.forEach((item, index2) => {
|
|
3043
3094
|
item.addEventListener("click", (e) => {
|
|
3044
3095
|
const val = item.getAttribute("data-value");
|
|
3045
3096
|
const label = item.textContent.trim();
|
|
@@ -3049,6 +3100,39 @@ var InaUI = (() => {
|
|
|
3049
3100
|
handleSelect(val);
|
|
3050
3101
|
}
|
|
3051
3102
|
});
|
|
3103
|
+
item.addEventListener("focus", () => {
|
|
3104
|
+
currentFocusedIndex = index2;
|
|
3105
|
+
});
|
|
3106
|
+
item.addEventListener("keydown", (e) => {
|
|
3107
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
3108
|
+
e.preventDefault();
|
|
3109
|
+
const nextIndex = (index2 + 1) % items.length;
|
|
3110
|
+
setItemFocus(nextIndex);
|
|
3111
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
3112
|
+
e.preventDefault();
|
|
3113
|
+
const prevIndex = (index2 - 1 + items.length) % items.length;
|
|
3114
|
+
setItemFocus(prevIndex);
|
|
3115
|
+
}
|
|
3116
|
+
if (e.key === " " || e.key === "Enter") {
|
|
3117
|
+
e.preventDefault();
|
|
3118
|
+
const val = item.getAttribute("data-value");
|
|
3119
|
+
const label = item.textContent.trim();
|
|
3120
|
+
if (showCustomization && label === customizationLabel) {
|
|
3121
|
+
handleSelect(val);
|
|
3122
|
+
setTimeout(() => {
|
|
3123
|
+
const customFieldContainer2 = container.querySelector(
|
|
3124
|
+
`.${PREFIX4}-chip__custom-field`
|
|
3125
|
+
);
|
|
3126
|
+
if (customFieldContainer2) {
|
|
3127
|
+
const inputEl = customFieldContainer2.querySelector("input");
|
|
3128
|
+
if (inputEl) inputEl.focus();
|
|
3129
|
+
}
|
|
3130
|
+
}, 50);
|
|
3131
|
+
} else {
|
|
3132
|
+
handleSelect(val);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3052
3136
|
});
|
|
3053
3137
|
updateUI();
|
|
3054
3138
|
container.__inaChipInitialized = true;
|
|
@@ -3973,6 +4057,330 @@ var InaUI = (() => {
|
|
|
3973
4057
|
return instances.length === 1 ? instances[0] : instances;
|
|
3974
4058
|
}
|
|
3975
4059
|
|
|
4060
|
+
// src/js/components/stateful/month-picker.js
|
|
4061
|
+
var MONTHS_SHORT_ID = [
|
|
4062
|
+
"Jan",
|
|
4063
|
+
"Feb",
|
|
4064
|
+
"Mar",
|
|
4065
|
+
"Apr",
|
|
4066
|
+
"Mei",
|
|
4067
|
+
"Jun",
|
|
4068
|
+
"Jul",
|
|
4069
|
+
"Agu",
|
|
4070
|
+
"Sep",
|
|
4071
|
+
"Okt",
|
|
4072
|
+
"Nov",
|
|
4073
|
+
"Des"
|
|
4074
|
+
];
|
|
4075
|
+
function initMonthPicker(rootSelector = `.${PREFIX}-month-picker`) {
|
|
4076
|
+
const pickers = document.querySelectorAll(rootSelector);
|
|
4077
|
+
pickers.forEach((container) => {
|
|
4078
|
+
if (container.dataset.initialized === "true") return;
|
|
4079
|
+
container.dataset.initialized = "true";
|
|
4080
|
+
let currentMonthIdx = parseInt(container.dataset.value || "0", 10);
|
|
4081
|
+
const disabled = container.hasAttribute("disabled");
|
|
4082
|
+
const readonly = container.hasAttribute("readonly");
|
|
4083
|
+
const trigger = container.querySelector(`.${PREFIX}-month-picker__trigger`);
|
|
4084
|
+
const panel = container.querySelector(`.${PREFIX}-month-picker__panel`);
|
|
4085
|
+
const grid = container.querySelector(`.${PREFIX}-month-picker__grid`);
|
|
4086
|
+
const options2 = grid ? Array.from(
|
|
4087
|
+
grid.querySelectorAll(`.${PREFIX}-month-picker__month-option`)
|
|
4088
|
+
) : [];
|
|
4089
|
+
if (!trigger || !panel || !grid || options2.length === 0) return;
|
|
4090
|
+
let isPickerOpen = false;
|
|
4091
|
+
const updateText = () => {
|
|
4092
|
+
const textEl = trigger.querySelector(
|
|
4093
|
+
`.${PREFIX}-month-picker__trigger-text`
|
|
4094
|
+
);
|
|
4095
|
+
if (textEl) textEl.textContent = MONTHS_SHORT_ID[currentMonthIdx];
|
|
4096
|
+
options2.forEach((opt, idx) => {
|
|
4097
|
+
if (idx === currentMonthIdx) {
|
|
4098
|
+
opt.classList.add(`${PREFIX}-month-picker__month-option--selected`);
|
|
4099
|
+
opt.setAttribute("aria-selected", "true");
|
|
4100
|
+
opt.tabIndex = 0;
|
|
4101
|
+
} else {
|
|
4102
|
+
opt.classList.remove(
|
|
4103
|
+
`${PREFIX}-month-picker__month-option--selected`
|
|
4104
|
+
);
|
|
4105
|
+
opt.setAttribute("aria-selected", "false");
|
|
4106
|
+
opt.tabIndex = -1;
|
|
4107
|
+
}
|
|
4108
|
+
});
|
|
4109
|
+
};
|
|
4110
|
+
const togglePicker = (show) => {
|
|
4111
|
+
if (disabled || readonly) return;
|
|
4112
|
+
isPickerOpen = show;
|
|
4113
|
+
if (show) {
|
|
4114
|
+
panel.classList.add(`${PREFIX}-month-picker__panel--open`);
|
|
4115
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
4116
|
+
setTimeout(() => {
|
|
4117
|
+
const selectedOpt = options2.find((o) => o.tabIndex === 0);
|
|
4118
|
+
if (selectedOpt) selectedOpt.focus();
|
|
4119
|
+
}, 0);
|
|
4120
|
+
} else {
|
|
4121
|
+
panel.classList.remove(`${PREFIX}-month-picker__panel--open`);
|
|
4122
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
4123
|
+
}
|
|
4124
|
+
};
|
|
4125
|
+
updateText();
|
|
4126
|
+
trigger.addEventListener("click", (e) => {
|
|
4127
|
+
e.stopPropagation();
|
|
4128
|
+
e.preventDefault();
|
|
4129
|
+
togglePicker(!isPickerOpen);
|
|
4130
|
+
});
|
|
4131
|
+
trigger.addEventListener("keydown", (e) => {
|
|
4132
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4133
|
+
e.preventDefault();
|
|
4134
|
+
e.stopPropagation();
|
|
4135
|
+
togglePicker(!isPickerOpen);
|
|
4136
|
+
}
|
|
4137
|
+
});
|
|
4138
|
+
document.addEventListener("click", (e) => {
|
|
4139
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
4140
|
+
});
|
|
4141
|
+
options2.forEach((btn, idx) => {
|
|
4142
|
+
btn.setAttribute("role", "option");
|
|
4143
|
+
btn.addEventListener("click", (e) => {
|
|
4144
|
+
if (disabled || readonly) return;
|
|
4145
|
+
e.stopPropagation();
|
|
4146
|
+
e.preventDefault();
|
|
4147
|
+
currentMonthIdx = idx;
|
|
4148
|
+
updateText();
|
|
4149
|
+
togglePicker(false);
|
|
4150
|
+
trigger.focus();
|
|
4151
|
+
container.dispatchEvent(
|
|
4152
|
+
new CustomEvent("change", {
|
|
4153
|
+
detail: { value: currentMonthIdx },
|
|
4154
|
+
bubbles: true,
|
|
4155
|
+
composed: true
|
|
4156
|
+
})
|
|
4157
|
+
);
|
|
4158
|
+
});
|
|
4159
|
+
btn.addEventListener("keydown", (e) => {
|
|
4160
|
+
if (disabled || readonly) return;
|
|
4161
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4162
|
+
e.preventDefault();
|
|
4163
|
+
e.stopPropagation();
|
|
4164
|
+
currentMonthIdx = idx;
|
|
4165
|
+
updateText();
|
|
4166
|
+
togglePicker(false);
|
|
4167
|
+
trigger.focus();
|
|
4168
|
+
container.dispatchEvent(
|
|
4169
|
+
new CustomEvent("change", {
|
|
4170
|
+
detail: { value: currentMonthIdx },
|
|
4171
|
+
bubbles: true,
|
|
4172
|
+
composed: true
|
|
4173
|
+
})
|
|
4174
|
+
);
|
|
4175
|
+
} else if (["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"].includes(e.key)) {
|
|
4176
|
+
e.preventDefault();
|
|
4177
|
+
e.stopPropagation();
|
|
4178
|
+
let nextIndex = idx;
|
|
4179
|
+
if (e.key === "ArrowRight") nextIndex += 1;
|
|
4180
|
+
else if (e.key === "ArrowLeft") nextIndex -= 1;
|
|
4181
|
+
else if (e.key === "ArrowDown")
|
|
4182
|
+
nextIndex += 3;
|
|
4183
|
+
else if (e.key === "ArrowUp") nextIndex -= 3;
|
|
4184
|
+
if (options2[nextIndex]) {
|
|
4185
|
+
options2[nextIndex].focus();
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
});
|
|
4189
|
+
});
|
|
4190
|
+
});
|
|
4191
|
+
}
|
|
4192
|
+
|
|
4193
|
+
// src/js/components/stateful/year-picker.js
|
|
4194
|
+
function initYearPicker(rootSelector = `.${PREFIX}-year-picker`) {
|
|
4195
|
+
const pickers = document.querySelectorAll(rootSelector);
|
|
4196
|
+
pickers.forEach((container) => {
|
|
4197
|
+
if (container.dataset.initialized === "true") return;
|
|
4198
|
+
container.dataset.initialized = "true";
|
|
4199
|
+
let currentYearVal = parseInt(
|
|
4200
|
+
container.dataset.value || (/* @__PURE__ */ new Date()).getFullYear().toString(),
|
|
4201
|
+
10
|
|
4202
|
+
);
|
|
4203
|
+
const disabled = container.hasAttribute("disabled");
|
|
4204
|
+
const readonly = container.hasAttribute("readonly");
|
|
4205
|
+
const maxYear = container.dataset.max ? parseInt(container.dataset.max, 10) : 2100;
|
|
4206
|
+
const minYear = container.dataset.min ? parseInt(container.dataset.min, 10) : 1900;
|
|
4207
|
+
let isPickerOpen = false;
|
|
4208
|
+
let decadeSize = 20;
|
|
4209
|
+
const trigger = container.querySelector(`.${PREFIX}-year-picker__trigger`);
|
|
4210
|
+
const panel = container.querySelector(`.${PREFIX}-year-picker__panel`);
|
|
4211
|
+
const grid = container.querySelector(`.${PREFIX}-year-picker__grid`);
|
|
4212
|
+
const prevBtn = container.querySelector(
|
|
4213
|
+
`.${PREFIX}-year-picker__nav-button[aria-label="Previous decade"]`
|
|
4214
|
+
);
|
|
4215
|
+
const nextBtn = container.querySelector(
|
|
4216
|
+
`.${PREFIX}-year-picker__nav-button[aria-label="Next decade"]`
|
|
4217
|
+
);
|
|
4218
|
+
const rangeText = container.querySelector(
|
|
4219
|
+
`.${PREFIX}-year-picker__decade-range`
|
|
4220
|
+
);
|
|
4221
|
+
if (!trigger || !panel || !grid) return;
|
|
4222
|
+
let decadeStart = Math.floor(currentYearVal / decadeSize) * decadeSize;
|
|
4223
|
+
const renderGrid = () => {
|
|
4224
|
+
grid.innerHTML = "";
|
|
4225
|
+
if (rangeText) {
|
|
4226
|
+
rangeText.textContent = `${decadeStart} - ${decadeStart + decadeSize - 1}`;
|
|
4227
|
+
}
|
|
4228
|
+
if (prevBtn) {
|
|
4229
|
+
prevBtn.disabled = disabled || readonly || decadeStart <= minYear;
|
|
4230
|
+
}
|
|
4231
|
+
if (nextBtn) {
|
|
4232
|
+
nextBtn.disabled = disabled || readonly || decadeStart + decadeSize > maxYear;
|
|
4233
|
+
}
|
|
4234
|
+
for (let y = decadeStart; y < decadeStart + decadeSize; y++) {
|
|
4235
|
+
const btn = document.createElement("button");
|
|
4236
|
+
btn.type = "button";
|
|
4237
|
+
btn.className = `${PREFIX}-year-picker__year-option`;
|
|
4238
|
+
if (y === currentYearVal) {
|
|
4239
|
+
btn.classList.add(`${PREFIX}-year-picker__year-option--selected`);
|
|
4240
|
+
btn.setAttribute("aria-selected", "true");
|
|
4241
|
+
btn.tabIndex = 0;
|
|
4242
|
+
} else {
|
|
4243
|
+
btn.setAttribute("aria-selected", "false");
|
|
4244
|
+
btn.tabIndex = -1;
|
|
4245
|
+
}
|
|
4246
|
+
if (y < minYear || y > maxYear) {
|
|
4247
|
+
btn.disabled = true;
|
|
4248
|
+
btn.classList.add(`${PREFIX}-year-picker__year-option--disabled`);
|
|
4249
|
+
}
|
|
4250
|
+
btn.textContent = y.toString();
|
|
4251
|
+
btn.setAttribute("role", "option");
|
|
4252
|
+
btn.addEventListener("click", (e) => {
|
|
4253
|
+
if (disabled || readonly || btn.disabled) return;
|
|
4254
|
+
e.stopPropagation();
|
|
4255
|
+
currentYearVal = y;
|
|
4256
|
+
updateText();
|
|
4257
|
+
togglePicker(false);
|
|
4258
|
+
trigger.focus();
|
|
4259
|
+
container.dispatchEvent(
|
|
4260
|
+
new CustomEvent("change", {
|
|
4261
|
+
detail: { value: currentYearVal },
|
|
4262
|
+
bubbles: true,
|
|
4263
|
+
composed: true
|
|
4264
|
+
})
|
|
4265
|
+
);
|
|
4266
|
+
});
|
|
4267
|
+
btn.addEventListener("keydown", (e) => {
|
|
4268
|
+
if (disabled || readonly || btn.disabled) return;
|
|
4269
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4270
|
+
e.preventDefault();
|
|
4271
|
+
e.stopPropagation();
|
|
4272
|
+
currentYearVal = y;
|
|
4273
|
+
updateText();
|
|
4274
|
+
togglePicker(false);
|
|
4275
|
+
trigger.focus();
|
|
4276
|
+
container.dispatchEvent(
|
|
4277
|
+
new CustomEvent("change", {
|
|
4278
|
+
detail: { value: currentYearVal },
|
|
4279
|
+
bubbles: true,
|
|
4280
|
+
composed: true
|
|
4281
|
+
})
|
|
4282
|
+
);
|
|
4283
|
+
} else if (["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"].includes(e.key)) {
|
|
4284
|
+
e.preventDefault();
|
|
4285
|
+
e.stopPropagation();
|
|
4286
|
+
const options2 = Array.from(
|
|
4287
|
+
grid.querySelectorAll(
|
|
4288
|
+
`.${PREFIX}-year-picker__year-option:not(:disabled)`
|
|
4289
|
+
)
|
|
4290
|
+
);
|
|
4291
|
+
const currentIndex = options2.indexOf(btn);
|
|
4292
|
+
if (currentIndex === -1) return;
|
|
4293
|
+
let nextIndex = currentIndex;
|
|
4294
|
+
if (e.key === "ArrowRight") nextIndex += 1;
|
|
4295
|
+
else if (e.key === "ArrowLeft") nextIndex -= 1;
|
|
4296
|
+
else if (e.key === "ArrowDown")
|
|
4297
|
+
nextIndex += 4;
|
|
4298
|
+
else if (e.key === "ArrowUp") nextIndex -= 4;
|
|
4299
|
+
if (options2[nextIndex]) {
|
|
4300
|
+
options2[nextIndex].focus();
|
|
4301
|
+
} else {
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
});
|
|
4305
|
+
grid.appendChild(btn);
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
const updateText = () => {
|
|
4309
|
+
const textEl = trigger.querySelector(
|
|
4310
|
+
`.${PREFIX}-year-picker__trigger-text`
|
|
4311
|
+
);
|
|
4312
|
+
if (textEl) textEl.textContent = currentYearVal.toString();
|
|
4313
|
+
};
|
|
4314
|
+
const togglePicker = (show) => {
|
|
4315
|
+
if (disabled || readonly) return;
|
|
4316
|
+
isPickerOpen = show;
|
|
4317
|
+
if (show) {
|
|
4318
|
+
decadeStart = Math.floor(currentYearVal / decadeSize) * decadeSize;
|
|
4319
|
+
renderGrid();
|
|
4320
|
+
panel.classList.add(`${PREFIX}-year-picker__panel--open`);
|
|
4321
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
4322
|
+
setTimeout(() => {
|
|
4323
|
+
const selectedOpt = grid.querySelector(
|
|
4324
|
+
`.${PREFIX}-year-picker__year-option--selected`
|
|
4325
|
+
);
|
|
4326
|
+
if (selectedOpt) selectedOpt.focus();
|
|
4327
|
+
else if (grid.firstElementChild) grid.firstElementChild.focus();
|
|
4328
|
+
}, 0);
|
|
4329
|
+
} else {
|
|
4330
|
+
panel.classList.remove(`${PREFIX}-year-picker__panel--open`);
|
|
4331
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
4332
|
+
}
|
|
4333
|
+
};
|
|
4334
|
+
updateText();
|
|
4335
|
+
renderGrid();
|
|
4336
|
+
trigger.addEventListener("click", (e) => {
|
|
4337
|
+
e.stopPropagation();
|
|
4338
|
+
e.preventDefault();
|
|
4339
|
+
togglePicker(!isPickerOpen);
|
|
4340
|
+
});
|
|
4341
|
+
trigger.addEventListener("keydown", (e) => {
|
|
4342
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4343
|
+
e.preventDefault();
|
|
4344
|
+
e.stopPropagation();
|
|
4345
|
+
togglePicker(!isPickerOpen);
|
|
4346
|
+
}
|
|
4347
|
+
});
|
|
4348
|
+
document.addEventListener("click", (e) => {
|
|
4349
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
4350
|
+
});
|
|
4351
|
+
if (prevBtn) {
|
|
4352
|
+
prevBtn.addEventListener("click", (e) => {
|
|
4353
|
+
e.stopPropagation();
|
|
4354
|
+
decadeStart -= decadeSize;
|
|
4355
|
+
renderGrid();
|
|
4356
|
+
});
|
|
4357
|
+
prevBtn.addEventListener("keydown", (e) => {
|
|
4358
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4359
|
+
e.preventDefault();
|
|
4360
|
+
e.stopPropagation();
|
|
4361
|
+
decadeStart -= decadeSize;
|
|
4362
|
+
renderGrid();
|
|
4363
|
+
}
|
|
4364
|
+
});
|
|
4365
|
+
}
|
|
4366
|
+
if (nextBtn) {
|
|
4367
|
+
nextBtn.addEventListener("click", (e) => {
|
|
4368
|
+
e.stopPropagation();
|
|
4369
|
+
decadeStart += decadeSize;
|
|
4370
|
+
renderGrid();
|
|
4371
|
+
});
|
|
4372
|
+
nextBtn.addEventListener("keydown", (e) => {
|
|
4373
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4374
|
+
e.preventDefault();
|
|
4375
|
+
e.stopPropagation();
|
|
4376
|
+
decadeStart += decadeSize;
|
|
4377
|
+
renderGrid();
|
|
4378
|
+
}
|
|
4379
|
+
});
|
|
4380
|
+
}
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4383
|
+
|
|
3976
4384
|
// src/js/components/stateless/toast.js
|
|
3977
4385
|
var ICONS3 = {
|
|
3978
4386
|
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>`,
|
|
@@ -4303,6 +4711,8 @@ var InaUI = (() => {
|
|
|
4303
4711
|
initTabVertical();
|
|
4304
4712
|
initTabHorizontal();
|
|
4305
4713
|
initTable();
|
|
4714
|
+
initMonthPicker();
|
|
4715
|
+
initYearPicker();
|
|
4306
4716
|
});
|
|
4307
4717
|
}
|
|
4308
4718
|
return __toCommonJS(bundle_exports);
|
package/dist/index.js
CHANGED
|
@@ -3036,34 +3036,59 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3036
3036
|
if (container.__inaChipInitialized) return;
|
|
3037
3037
|
const showCustomization = container.getAttribute("data-show-customization") === "true";
|
|
3038
3038
|
const customizationLabel = container.getAttribute("data-customization-label") || "Kustomisasi";
|
|
3039
|
+
const isMultiple = container.getAttribute("data-multiple") === "true";
|
|
3039
3040
|
let selectedValue = container.getAttribute("data-selected") || "";
|
|
3040
3041
|
const list = container.querySelector(`.${PREFIX5}-chip__list`);
|
|
3041
3042
|
const items = list ? list.querySelectorAll(`.${PREFIX5}-chip__item`) : [];
|
|
3042
3043
|
let customFieldContainer = container.querySelector(
|
|
3043
3044
|
`.${PREFIX5}-chip__custom-field`
|
|
3044
3045
|
);
|
|
3046
|
+
const getNormalizedSelected = () => {
|
|
3047
|
+
if (!selectedValue) return [];
|
|
3048
|
+
return isMultiple ? selectedValue.split(",").map((s) => s.trim()).filter(Boolean) : [selectedValue];
|
|
3049
|
+
};
|
|
3045
3050
|
const updateUI = () => {
|
|
3046
|
-
|
|
3051
|
+
const normSelected = getNormalizedSelected();
|
|
3052
|
+
const getInitialFocusIndex = () => {
|
|
3053
|
+
if (normSelected.length > 0) {
|
|
3054
|
+
const standardValues = Array.from(items).filter((item) => item.textContent.trim() !== customizationLabel).map((item) => item.getAttribute("data-value"));
|
|
3055
|
+
const hasCustomVal = normSelected.some(
|
|
3056
|
+
(val) => !standardValues.includes(val) && val !== ""
|
|
3057
|
+
);
|
|
3058
|
+
if (hasCustomVal && showCustomization) {
|
|
3059
|
+
return items.length - 1;
|
|
3060
|
+
}
|
|
3061
|
+
const firstSelectedIndex = Array.from(items).findIndex(
|
|
3062
|
+
(opt) => normSelected.includes(opt.getAttribute("data-value"))
|
|
3063
|
+
);
|
|
3064
|
+
if (firstSelectedIndex !== -1) return firstSelectedIndex;
|
|
3065
|
+
}
|
|
3066
|
+
return 0;
|
|
3067
|
+
};
|
|
3068
|
+
const focusedIndex = getInitialFocusIndex();
|
|
3069
|
+
items.forEach((item, index2) => {
|
|
3047
3070
|
const itemValue = item.getAttribute("data-value");
|
|
3048
|
-
const isSelected = itemValue ===
|
|
3071
|
+
const isSelected = normSelected.includes(itemValue) || showCustomization && item.textContent.trim() === customizationLabel && normSelected.some(
|
|
3072
|
+
(val) => !Array.from(items).filter((i) => i.textContent.trim() !== customizationLabel).map((i) => i.getAttribute("data-value")).includes(val) && val !== ""
|
|
3073
|
+
);
|
|
3049
3074
|
if (isSelected) {
|
|
3050
3075
|
item.classList.add(`${PREFIX5}-chip__item--selected`);
|
|
3051
3076
|
} else {
|
|
3052
3077
|
item.classList.remove(`${PREFIX5}-chip__item--selected`);
|
|
3053
3078
|
}
|
|
3079
|
+
item.setAttribute("tabindex", index2 === focusedIndex ? "0" : "-1");
|
|
3054
3080
|
});
|
|
3055
3081
|
if (showCustomization) {
|
|
3056
|
-
const
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
});
|
|
3082
|
+
const standardValues = Array.from(items).filter((item) => item.textContent.trim() !== customizationLabel).map((item) => item.getAttribute("data-value"));
|
|
3083
|
+
const customValues = normSelected.filter(
|
|
3084
|
+
(val) => !standardValues.includes(val) && val !== ""
|
|
3085
|
+
);
|
|
3086
|
+
const isStandard = customValues.length === 0;
|
|
3087
|
+
const primaryCustomValue = customValues[customValues.length - 1] || "";
|
|
3063
3088
|
const toggleBtn = Array.from(items).find(
|
|
3064
3089
|
(i) => i.textContent.trim() === customizationLabel
|
|
3065
3090
|
);
|
|
3066
|
-
const showInput = toggleBtn &&
|
|
3091
|
+
const showInput = toggleBtn && normSelected.includes(toggleBtn.getAttribute("data-value")) || !isStandard && normSelected.length > 0;
|
|
3067
3092
|
if (showInput) {
|
|
3068
3093
|
if (!customFieldContainer) {
|
|
3069
3094
|
customFieldContainer = document.createElement("div");
|
|
@@ -3077,7 +3102,7 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3077
3102
|
customFieldContainer.innerHTML = `
|
|
3078
3103
|
<div class="${PREFIX5}-text-field ${PREFIX5}-text-field--size-medium ${PREFIX5}-text-field--variant-outline ${PREFIX5}-chip__input">
|
|
3079
3104
|
<div class="${PREFIX5}-text-field__wrapper">
|
|
3080
|
-
<input type="text" class="${PREFIX5}-text-field__input" placeholder="Masukkan data yang Anda inginkan" value="${!isStandard ?
|
|
3105
|
+
<input type="text" class="${PREFIX5}-text-field__input" placeholder="Masukkan data yang Anda inginkan" value="${!isStandard ? primaryCustomValue : ""}" />
|
|
3081
3106
|
</div>
|
|
3082
3107
|
</div>
|
|
3083
3108
|
`;
|
|
@@ -3085,21 +3110,21 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3085
3110
|
input.addEventListener("blur", (e) => {
|
|
3086
3111
|
const val = e.target.value;
|
|
3087
3112
|
if (val.trim()) {
|
|
3088
|
-
handleSelect(val);
|
|
3089
|
-
} else {
|
|
3090
|
-
handleSelect("");
|
|
3113
|
+
handleSelect(val.trim());
|
|
3091
3114
|
}
|
|
3092
3115
|
});
|
|
3093
3116
|
input.addEventListener("keydown", (e) => {
|
|
3094
3117
|
if (e.key === "Enter") {
|
|
3095
|
-
|
|
3118
|
+
if (e.target.value.trim()) {
|
|
3119
|
+
handleSelect(e.target.value.trim());
|
|
3120
|
+
}
|
|
3096
3121
|
e.target.blur();
|
|
3097
3122
|
}
|
|
3098
3123
|
});
|
|
3099
3124
|
} else {
|
|
3100
3125
|
const inputEl = customFieldContainer.querySelector("input");
|
|
3101
3126
|
if (inputEl && document.activeElement !== inputEl) {
|
|
3102
|
-
inputEl.value = !isStandard ?
|
|
3127
|
+
inputEl.value = !isStandard ? primaryCustomValue : "";
|
|
3103
3128
|
}
|
|
3104
3129
|
}
|
|
3105
3130
|
customFieldContainer.style.display = "block";
|
|
@@ -3111,17 +3136,41 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3111
3136
|
}
|
|
3112
3137
|
};
|
|
3113
3138
|
const handleSelect = (val) => {
|
|
3114
|
-
|
|
3115
|
-
|
|
3139
|
+
if (!val) return;
|
|
3140
|
+
let finalVal = val;
|
|
3141
|
+
if (isMultiple) {
|
|
3142
|
+
const normSelected = getNormalizedSelected();
|
|
3143
|
+
let newSelected;
|
|
3144
|
+
if (normSelected.includes(val)) {
|
|
3145
|
+
newSelected = normSelected.filter((v) => v !== val);
|
|
3146
|
+
} else {
|
|
3147
|
+
newSelected = [...normSelected, val];
|
|
3148
|
+
}
|
|
3149
|
+
finalVal = newSelected;
|
|
3150
|
+
selectedValue = newSelected.join(",");
|
|
3151
|
+
} else {
|
|
3152
|
+
selectedValue = val;
|
|
3153
|
+
}
|
|
3154
|
+
container.setAttribute("data-selected", selectedValue);
|
|
3116
3155
|
updateUI();
|
|
3117
3156
|
container.dispatchEvent(
|
|
3118
3157
|
new CustomEvent("chip:select", {
|
|
3119
|
-
detail: { value:
|
|
3158
|
+
detail: { value: finalVal },
|
|
3120
3159
|
bubbles: true
|
|
3121
3160
|
})
|
|
3122
3161
|
);
|
|
3123
3162
|
};
|
|
3124
|
-
|
|
3163
|
+
let currentFocusedIndex = -1;
|
|
3164
|
+
const setItemFocus = (index2) => {
|
|
3165
|
+
items.forEach((item, i) => {
|
|
3166
|
+
item.setAttribute("tabindex", i === index2 ? "0" : "-1");
|
|
3167
|
+
});
|
|
3168
|
+
if (items[index2]) {
|
|
3169
|
+
items[index2].focus();
|
|
3170
|
+
currentFocusedIndex = index2;
|
|
3171
|
+
}
|
|
3172
|
+
};
|
|
3173
|
+
items.forEach((item, index2) => {
|
|
3125
3174
|
item.addEventListener("click", (e) => {
|
|
3126
3175
|
const val = item.getAttribute("data-value");
|
|
3127
3176
|
const label = item.textContent.trim();
|
|
@@ -3131,6 +3180,39 @@ function initChip(rootSelector = `.${PREFIX5}-chip`) {
|
|
|
3131
3180
|
handleSelect(val);
|
|
3132
3181
|
}
|
|
3133
3182
|
});
|
|
3183
|
+
item.addEventListener("focus", () => {
|
|
3184
|
+
currentFocusedIndex = index2;
|
|
3185
|
+
});
|
|
3186
|
+
item.addEventListener("keydown", (e) => {
|
|
3187
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
3188
|
+
e.preventDefault();
|
|
3189
|
+
const nextIndex = (index2 + 1) % items.length;
|
|
3190
|
+
setItemFocus(nextIndex);
|
|
3191
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
3192
|
+
e.preventDefault();
|
|
3193
|
+
const prevIndex = (index2 - 1 + items.length) % items.length;
|
|
3194
|
+
setItemFocus(prevIndex);
|
|
3195
|
+
}
|
|
3196
|
+
if (e.key === " " || e.key === "Enter") {
|
|
3197
|
+
e.preventDefault();
|
|
3198
|
+
const val = item.getAttribute("data-value");
|
|
3199
|
+
const label = item.textContent.trim();
|
|
3200
|
+
if (showCustomization && label === customizationLabel) {
|
|
3201
|
+
handleSelect(val);
|
|
3202
|
+
setTimeout(() => {
|
|
3203
|
+
const customFieldContainer2 = container.querySelector(
|
|
3204
|
+
`.${PREFIX5}-chip__custom-field`
|
|
3205
|
+
);
|
|
3206
|
+
if (customFieldContainer2) {
|
|
3207
|
+
const inputEl = customFieldContainer2.querySelector("input");
|
|
3208
|
+
if (inputEl) inputEl.focus();
|
|
3209
|
+
}
|
|
3210
|
+
}, 50);
|
|
3211
|
+
} else {
|
|
3212
|
+
handleSelect(val);
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
});
|
|
3134
3216
|
});
|
|
3135
3217
|
updateUI();
|
|
3136
3218
|
container.__inaChipInitialized = true;
|
|
@@ -4055,6 +4137,330 @@ function initTable(selectorOrElement, options2 = {}) {
|
|
|
4055
4137
|
return instances.length === 1 ? instances[0] : instances;
|
|
4056
4138
|
}
|
|
4057
4139
|
|
|
4140
|
+
// src/js/components/stateful/month-picker.js
|
|
4141
|
+
var MONTHS_SHORT_ID = [
|
|
4142
|
+
"Jan",
|
|
4143
|
+
"Feb",
|
|
4144
|
+
"Mar",
|
|
4145
|
+
"Apr",
|
|
4146
|
+
"Mei",
|
|
4147
|
+
"Jun",
|
|
4148
|
+
"Jul",
|
|
4149
|
+
"Agu",
|
|
4150
|
+
"Sep",
|
|
4151
|
+
"Okt",
|
|
4152
|
+
"Nov",
|
|
4153
|
+
"Des"
|
|
4154
|
+
];
|
|
4155
|
+
function initMonthPicker(rootSelector = `.${PREFIX}-month-picker`) {
|
|
4156
|
+
const pickers = document.querySelectorAll(rootSelector);
|
|
4157
|
+
pickers.forEach((container) => {
|
|
4158
|
+
if (container.dataset.initialized === "true") return;
|
|
4159
|
+
container.dataset.initialized = "true";
|
|
4160
|
+
let currentMonthIdx = parseInt(container.dataset.value || "0", 10);
|
|
4161
|
+
const disabled = container.hasAttribute("disabled");
|
|
4162
|
+
const readonly = container.hasAttribute("readonly");
|
|
4163
|
+
const trigger = container.querySelector(`.${PREFIX}-month-picker__trigger`);
|
|
4164
|
+
const panel = container.querySelector(`.${PREFIX}-month-picker__panel`);
|
|
4165
|
+
const grid = container.querySelector(`.${PREFIX}-month-picker__grid`);
|
|
4166
|
+
const options2 = grid ? Array.from(
|
|
4167
|
+
grid.querySelectorAll(`.${PREFIX}-month-picker__month-option`)
|
|
4168
|
+
) : [];
|
|
4169
|
+
if (!trigger || !panel || !grid || options2.length === 0) return;
|
|
4170
|
+
let isPickerOpen = false;
|
|
4171
|
+
const updateText = () => {
|
|
4172
|
+
const textEl = trigger.querySelector(
|
|
4173
|
+
`.${PREFIX}-month-picker__trigger-text`
|
|
4174
|
+
);
|
|
4175
|
+
if (textEl) textEl.textContent = MONTHS_SHORT_ID[currentMonthIdx];
|
|
4176
|
+
options2.forEach((opt, idx) => {
|
|
4177
|
+
if (idx === currentMonthIdx) {
|
|
4178
|
+
opt.classList.add(`${PREFIX}-month-picker__month-option--selected`);
|
|
4179
|
+
opt.setAttribute("aria-selected", "true");
|
|
4180
|
+
opt.tabIndex = 0;
|
|
4181
|
+
} else {
|
|
4182
|
+
opt.classList.remove(
|
|
4183
|
+
`${PREFIX}-month-picker__month-option--selected`
|
|
4184
|
+
);
|
|
4185
|
+
opt.setAttribute("aria-selected", "false");
|
|
4186
|
+
opt.tabIndex = -1;
|
|
4187
|
+
}
|
|
4188
|
+
});
|
|
4189
|
+
};
|
|
4190
|
+
const togglePicker = (show) => {
|
|
4191
|
+
if (disabled || readonly) return;
|
|
4192
|
+
isPickerOpen = show;
|
|
4193
|
+
if (show) {
|
|
4194
|
+
panel.classList.add(`${PREFIX}-month-picker__panel--open`);
|
|
4195
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
4196
|
+
setTimeout(() => {
|
|
4197
|
+
const selectedOpt = options2.find((o) => o.tabIndex === 0);
|
|
4198
|
+
if (selectedOpt) selectedOpt.focus();
|
|
4199
|
+
}, 0);
|
|
4200
|
+
} else {
|
|
4201
|
+
panel.classList.remove(`${PREFIX}-month-picker__panel--open`);
|
|
4202
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
4203
|
+
}
|
|
4204
|
+
};
|
|
4205
|
+
updateText();
|
|
4206
|
+
trigger.addEventListener("click", (e) => {
|
|
4207
|
+
e.stopPropagation();
|
|
4208
|
+
e.preventDefault();
|
|
4209
|
+
togglePicker(!isPickerOpen);
|
|
4210
|
+
});
|
|
4211
|
+
trigger.addEventListener("keydown", (e) => {
|
|
4212
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4213
|
+
e.preventDefault();
|
|
4214
|
+
e.stopPropagation();
|
|
4215
|
+
togglePicker(!isPickerOpen);
|
|
4216
|
+
}
|
|
4217
|
+
});
|
|
4218
|
+
document.addEventListener("click", (e) => {
|
|
4219
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
4220
|
+
});
|
|
4221
|
+
options2.forEach((btn, idx) => {
|
|
4222
|
+
btn.setAttribute("role", "option");
|
|
4223
|
+
btn.addEventListener("click", (e) => {
|
|
4224
|
+
if (disabled || readonly) return;
|
|
4225
|
+
e.stopPropagation();
|
|
4226
|
+
e.preventDefault();
|
|
4227
|
+
currentMonthIdx = idx;
|
|
4228
|
+
updateText();
|
|
4229
|
+
togglePicker(false);
|
|
4230
|
+
trigger.focus();
|
|
4231
|
+
container.dispatchEvent(
|
|
4232
|
+
new CustomEvent("change", {
|
|
4233
|
+
detail: { value: currentMonthIdx },
|
|
4234
|
+
bubbles: true,
|
|
4235
|
+
composed: true
|
|
4236
|
+
})
|
|
4237
|
+
);
|
|
4238
|
+
});
|
|
4239
|
+
btn.addEventListener("keydown", (e) => {
|
|
4240
|
+
if (disabled || readonly) return;
|
|
4241
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4242
|
+
e.preventDefault();
|
|
4243
|
+
e.stopPropagation();
|
|
4244
|
+
currentMonthIdx = idx;
|
|
4245
|
+
updateText();
|
|
4246
|
+
togglePicker(false);
|
|
4247
|
+
trigger.focus();
|
|
4248
|
+
container.dispatchEvent(
|
|
4249
|
+
new CustomEvent("change", {
|
|
4250
|
+
detail: { value: currentMonthIdx },
|
|
4251
|
+
bubbles: true,
|
|
4252
|
+
composed: true
|
|
4253
|
+
})
|
|
4254
|
+
);
|
|
4255
|
+
} else if (["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"].includes(e.key)) {
|
|
4256
|
+
e.preventDefault();
|
|
4257
|
+
e.stopPropagation();
|
|
4258
|
+
let nextIndex = idx;
|
|
4259
|
+
if (e.key === "ArrowRight") nextIndex += 1;
|
|
4260
|
+
else if (e.key === "ArrowLeft") nextIndex -= 1;
|
|
4261
|
+
else if (e.key === "ArrowDown")
|
|
4262
|
+
nextIndex += 3;
|
|
4263
|
+
else if (e.key === "ArrowUp") nextIndex -= 3;
|
|
4264
|
+
if (options2[nextIndex]) {
|
|
4265
|
+
options2[nextIndex].focus();
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
});
|
|
4269
|
+
});
|
|
4270
|
+
});
|
|
4271
|
+
}
|
|
4272
|
+
|
|
4273
|
+
// src/js/components/stateful/year-picker.js
|
|
4274
|
+
function initYearPicker(rootSelector = `.${PREFIX}-year-picker`) {
|
|
4275
|
+
const pickers = document.querySelectorAll(rootSelector);
|
|
4276
|
+
pickers.forEach((container) => {
|
|
4277
|
+
if (container.dataset.initialized === "true") return;
|
|
4278
|
+
container.dataset.initialized = "true";
|
|
4279
|
+
let currentYearVal = parseInt(
|
|
4280
|
+
container.dataset.value || (/* @__PURE__ */ new Date()).getFullYear().toString(),
|
|
4281
|
+
10
|
|
4282
|
+
);
|
|
4283
|
+
const disabled = container.hasAttribute("disabled");
|
|
4284
|
+
const readonly = container.hasAttribute("readonly");
|
|
4285
|
+
const maxYear = container.dataset.max ? parseInt(container.dataset.max, 10) : 2100;
|
|
4286
|
+
const minYear = container.dataset.min ? parseInt(container.dataset.min, 10) : 1900;
|
|
4287
|
+
let isPickerOpen = false;
|
|
4288
|
+
let decadeSize = 20;
|
|
4289
|
+
const trigger = container.querySelector(`.${PREFIX}-year-picker__trigger`);
|
|
4290
|
+
const panel = container.querySelector(`.${PREFIX}-year-picker__panel`);
|
|
4291
|
+
const grid = container.querySelector(`.${PREFIX}-year-picker__grid`);
|
|
4292
|
+
const prevBtn = container.querySelector(
|
|
4293
|
+
`.${PREFIX}-year-picker__nav-button[aria-label="Previous decade"]`
|
|
4294
|
+
);
|
|
4295
|
+
const nextBtn = container.querySelector(
|
|
4296
|
+
`.${PREFIX}-year-picker__nav-button[aria-label="Next decade"]`
|
|
4297
|
+
);
|
|
4298
|
+
const rangeText = container.querySelector(
|
|
4299
|
+
`.${PREFIX}-year-picker__decade-range`
|
|
4300
|
+
);
|
|
4301
|
+
if (!trigger || !panel || !grid) return;
|
|
4302
|
+
let decadeStart = Math.floor(currentYearVal / decadeSize) * decadeSize;
|
|
4303
|
+
const renderGrid = () => {
|
|
4304
|
+
grid.innerHTML = "";
|
|
4305
|
+
if (rangeText) {
|
|
4306
|
+
rangeText.textContent = `${decadeStart} - ${decadeStart + decadeSize - 1}`;
|
|
4307
|
+
}
|
|
4308
|
+
if (prevBtn) {
|
|
4309
|
+
prevBtn.disabled = disabled || readonly || decadeStart <= minYear;
|
|
4310
|
+
}
|
|
4311
|
+
if (nextBtn) {
|
|
4312
|
+
nextBtn.disabled = disabled || readonly || decadeStart + decadeSize > maxYear;
|
|
4313
|
+
}
|
|
4314
|
+
for (let y = decadeStart; y < decadeStart + decadeSize; y++) {
|
|
4315
|
+
const btn = document.createElement("button");
|
|
4316
|
+
btn.type = "button";
|
|
4317
|
+
btn.className = `${PREFIX}-year-picker__year-option`;
|
|
4318
|
+
if (y === currentYearVal) {
|
|
4319
|
+
btn.classList.add(`${PREFIX}-year-picker__year-option--selected`);
|
|
4320
|
+
btn.setAttribute("aria-selected", "true");
|
|
4321
|
+
btn.tabIndex = 0;
|
|
4322
|
+
} else {
|
|
4323
|
+
btn.setAttribute("aria-selected", "false");
|
|
4324
|
+
btn.tabIndex = -1;
|
|
4325
|
+
}
|
|
4326
|
+
if (y < minYear || y > maxYear) {
|
|
4327
|
+
btn.disabled = true;
|
|
4328
|
+
btn.classList.add(`${PREFIX}-year-picker__year-option--disabled`);
|
|
4329
|
+
}
|
|
4330
|
+
btn.textContent = y.toString();
|
|
4331
|
+
btn.setAttribute("role", "option");
|
|
4332
|
+
btn.addEventListener("click", (e) => {
|
|
4333
|
+
if (disabled || readonly || btn.disabled) return;
|
|
4334
|
+
e.stopPropagation();
|
|
4335
|
+
currentYearVal = y;
|
|
4336
|
+
updateText();
|
|
4337
|
+
togglePicker(false);
|
|
4338
|
+
trigger.focus();
|
|
4339
|
+
container.dispatchEvent(
|
|
4340
|
+
new CustomEvent("change", {
|
|
4341
|
+
detail: { value: currentYearVal },
|
|
4342
|
+
bubbles: true,
|
|
4343
|
+
composed: true
|
|
4344
|
+
})
|
|
4345
|
+
);
|
|
4346
|
+
});
|
|
4347
|
+
btn.addEventListener("keydown", (e) => {
|
|
4348
|
+
if (disabled || readonly || btn.disabled) return;
|
|
4349
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4350
|
+
e.preventDefault();
|
|
4351
|
+
e.stopPropagation();
|
|
4352
|
+
currentYearVal = y;
|
|
4353
|
+
updateText();
|
|
4354
|
+
togglePicker(false);
|
|
4355
|
+
trigger.focus();
|
|
4356
|
+
container.dispatchEvent(
|
|
4357
|
+
new CustomEvent("change", {
|
|
4358
|
+
detail: { value: currentYearVal },
|
|
4359
|
+
bubbles: true,
|
|
4360
|
+
composed: true
|
|
4361
|
+
})
|
|
4362
|
+
);
|
|
4363
|
+
} else if (["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"].includes(e.key)) {
|
|
4364
|
+
e.preventDefault();
|
|
4365
|
+
e.stopPropagation();
|
|
4366
|
+
const options2 = Array.from(
|
|
4367
|
+
grid.querySelectorAll(
|
|
4368
|
+
`.${PREFIX}-year-picker__year-option:not(:disabled)`
|
|
4369
|
+
)
|
|
4370
|
+
);
|
|
4371
|
+
const currentIndex = options2.indexOf(btn);
|
|
4372
|
+
if (currentIndex === -1) return;
|
|
4373
|
+
let nextIndex = currentIndex;
|
|
4374
|
+
if (e.key === "ArrowRight") nextIndex += 1;
|
|
4375
|
+
else if (e.key === "ArrowLeft") nextIndex -= 1;
|
|
4376
|
+
else if (e.key === "ArrowDown")
|
|
4377
|
+
nextIndex += 4;
|
|
4378
|
+
else if (e.key === "ArrowUp") nextIndex -= 4;
|
|
4379
|
+
if (options2[nextIndex]) {
|
|
4380
|
+
options2[nextIndex].focus();
|
|
4381
|
+
} else {
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
});
|
|
4385
|
+
grid.appendChild(btn);
|
|
4386
|
+
}
|
|
4387
|
+
};
|
|
4388
|
+
const updateText = () => {
|
|
4389
|
+
const textEl = trigger.querySelector(
|
|
4390
|
+
`.${PREFIX}-year-picker__trigger-text`
|
|
4391
|
+
);
|
|
4392
|
+
if (textEl) textEl.textContent = currentYearVal.toString();
|
|
4393
|
+
};
|
|
4394
|
+
const togglePicker = (show) => {
|
|
4395
|
+
if (disabled || readonly) return;
|
|
4396
|
+
isPickerOpen = show;
|
|
4397
|
+
if (show) {
|
|
4398
|
+
decadeStart = Math.floor(currentYearVal / decadeSize) * decadeSize;
|
|
4399
|
+
renderGrid();
|
|
4400
|
+
panel.classList.add(`${PREFIX}-year-picker__panel--open`);
|
|
4401
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
4402
|
+
setTimeout(() => {
|
|
4403
|
+
const selectedOpt = grid.querySelector(
|
|
4404
|
+
`.${PREFIX}-year-picker__year-option--selected`
|
|
4405
|
+
);
|
|
4406
|
+
if (selectedOpt) selectedOpt.focus();
|
|
4407
|
+
else if (grid.firstElementChild) grid.firstElementChild.focus();
|
|
4408
|
+
}, 0);
|
|
4409
|
+
} else {
|
|
4410
|
+
panel.classList.remove(`${PREFIX}-year-picker__panel--open`);
|
|
4411
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
4412
|
+
}
|
|
4413
|
+
};
|
|
4414
|
+
updateText();
|
|
4415
|
+
renderGrid();
|
|
4416
|
+
trigger.addEventListener("click", (e) => {
|
|
4417
|
+
e.stopPropagation();
|
|
4418
|
+
e.preventDefault();
|
|
4419
|
+
togglePicker(!isPickerOpen);
|
|
4420
|
+
});
|
|
4421
|
+
trigger.addEventListener("keydown", (e) => {
|
|
4422
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4423
|
+
e.preventDefault();
|
|
4424
|
+
e.stopPropagation();
|
|
4425
|
+
togglePicker(!isPickerOpen);
|
|
4426
|
+
}
|
|
4427
|
+
});
|
|
4428
|
+
document.addEventListener("click", (e) => {
|
|
4429
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
4430
|
+
});
|
|
4431
|
+
if (prevBtn) {
|
|
4432
|
+
prevBtn.addEventListener("click", (e) => {
|
|
4433
|
+
e.stopPropagation();
|
|
4434
|
+
decadeStart -= decadeSize;
|
|
4435
|
+
renderGrid();
|
|
4436
|
+
});
|
|
4437
|
+
prevBtn.addEventListener("keydown", (e) => {
|
|
4438
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4439
|
+
e.preventDefault();
|
|
4440
|
+
e.stopPropagation();
|
|
4441
|
+
decadeStart -= decadeSize;
|
|
4442
|
+
renderGrid();
|
|
4443
|
+
}
|
|
4444
|
+
});
|
|
4445
|
+
}
|
|
4446
|
+
if (nextBtn) {
|
|
4447
|
+
nextBtn.addEventListener("click", (e) => {
|
|
4448
|
+
e.stopPropagation();
|
|
4449
|
+
decadeStart += decadeSize;
|
|
4450
|
+
renderGrid();
|
|
4451
|
+
});
|
|
4452
|
+
nextBtn.addEventListener("keydown", (e) => {
|
|
4453
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
4454
|
+
e.preventDefault();
|
|
4455
|
+
e.stopPropagation();
|
|
4456
|
+
decadeStart += decadeSize;
|
|
4457
|
+
renderGrid();
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
});
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4058
4464
|
// src/js/components/stateless/toast.js
|
|
4059
4465
|
var ICONS3 = {
|
|
4060
4466
|
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>`,
|
|
@@ -4197,6 +4603,8 @@ function initAll() {
|
|
|
4197
4603
|
initTabVertical();
|
|
4198
4604
|
initTabHorizontal();
|
|
4199
4605
|
initTable();
|
|
4606
|
+
initMonthPicker();
|
|
4607
|
+
initYearPicker();
|
|
4200
4608
|
}
|
|
4201
4609
|
export {
|
|
4202
4610
|
DatePicker,
|