@idds/react 1.1.95 → 1.1.96

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.es.js CHANGED
@@ -3610,8 +3610,18 @@ function Pagination({
3610
3610
  if (totalPages <= 0) return null;
3611
3611
  function renderPageNumbers() {
3612
3612
  const pages = [];
3613
- const start = Math.max(1, currentPage - 1);
3614
- const end = Math.min(totalPages, currentPage + 1);
3613
+ let start;
3614
+ let end;
3615
+ if (currentPage === 1) {
3616
+ start = 1;
3617
+ end = Math.min(3, totalPages);
3618
+ } else if (currentPage === totalPages) {
3619
+ start = Math.max(1, totalPages - 2);
3620
+ end = totalPages;
3621
+ } else {
3622
+ start = currentPage - 1;
3623
+ end = currentPage + 1;
3624
+ }
3615
3625
  for (let i2 = start; i2 <= end; i2++) {
3616
3626
  pages.push(renderPageButton(i2));
3617
3627
  }
@@ -5195,6 +5205,163 @@ function TextArea({
5195
5205
  ] })
5196
5206
  ] });
5197
5207
  }
5208
+ function OneTimePassword({
5209
+ value = "",
5210
+ onChange,
5211
+ length = 6,
5212
+ title,
5213
+ description,
5214
+ helperText,
5215
+ error = false,
5216
+ disabled = false,
5217
+ readonly = false,
5218
+ className = "",
5219
+ onComplete,
5220
+ autoFocus = false
5221
+ }) {
5222
+ const inputRefs = useRef([]);
5223
+ useEffect(() => {
5224
+ inputRefs.current = inputRefs.current.slice(0, length);
5225
+ }, [length]);
5226
+ useEffect(() => {
5227
+ if (autoFocus && inputRefs.current[0] && !disabled && !readonly) {
5228
+ inputRefs.current[0].focus();
5229
+ }
5230
+ }, [autoFocus, disabled, readonly]);
5231
+ useEffect(() => {
5232
+ const currentValue = value || "";
5233
+ if (currentValue.length < length && currentValue.length > 0) {
5234
+ const nextIndex = currentValue.length;
5235
+ if (inputRefs.current[nextIndex] && !disabled && !readonly) {
5236
+ inputRefs.current[nextIndex].focus();
5237
+ }
5238
+ }
5239
+ }, [value, length, disabled, readonly]);
5240
+ useEffect(() => {
5241
+ if (value && value.length === length && onComplete) {
5242
+ onComplete(value);
5243
+ }
5244
+ }, [value, length, onComplete]);
5245
+ const handleChange = (index, e) => {
5246
+ const inputValue = e.target.value;
5247
+ if (inputValue && !/^\d$/.test(inputValue)) {
5248
+ return;
5249
+ }
5250
+ const newValue = value.split("");
5251
+ newValue[index] = inputValue;
5252
+ const updatedValue = newValue.join("").slice(0, length);
5253
+ onChange(updatedValue);
5254
+ if (inputValue && index < length - 1) {
5255
+ const nextIndex = index + 1;
5256
+ if (inputRefs.current[nextIndex]) {
5257
+ inputRefs.current[nextIndex].focus();
5258
+ }
5259
+ }
5260
+ };
5261
+ const handleKeyDown = (index, e) => {
5262
+ var _a, _b;
5263
+ if (e.key === "Backspace") {
5264
+ const currentValue = value || "";
5265
+ if (!currentValue[index] && index > 0) {
5266
+ const prevIndex = index - 1;
5267
+ if (inputRefs.current[prevIndex]) {
5268
+ inputRefs.current[prevIndex].focus();
5269
+ const newValue = value.split("");
5270
+ newValue[prevIndex] = "";
5271
+ onChange(newValue.join(""));
5272
+ }
5273
+ } else {
5274
+ const newValue = value.split("");
5275
+ newValue[index] = "";
5276
+ onChange(newValue.join(""));
5277
+ }
5278
+ }
5279
+ if (e.key === "ArrowLeft" && index > 0) {
5280
+ e.preventDefault();
5281
+ (_a = inputRefs.current[index - 1]) == null ? void 0 : _a.focus();
5282
+ }
5283
+ if (e.key === "ArrowRight" && index < length - 1) {
5284
+ e.preventDefault();
5285
+ (_b = inputRefs.current[index + 1]) == null ? void 0 : _b.focus();
5286
+ }
5287
+ if ((e.ctrlKey || e.metaKey) && e.key === "v") {
5288
+ e.preventDefault();
5289
+ navigator.clipboard.readText().then((text) => {
5290
+ const digits = text.replace(/\D/g, "").slice(0, length);
5291
+ if (digits) {
5292
+ onChange(digits);
5293
+ const focusIndex = Math.min(digits.length - 1, length - 1);
5294
+ if (inputRefs.current[focusIndex]) {
5295
+ inputRefs.current[focusIndex].focus();
5296
+ }
5297
+ }
5298
+ });
5299
+ }
5300
+ };
5301
+ const handleFocus = (index) => {
5302
+ if (inputRefs.current[index]) {
5303
+ inputRefs.current[index].select();
5304
+ }
5305
+ };
5306
+ const handleBlur = () => {
5307
+ };
5308
+ const handlePaste = (e) => {
5309
+ e.preventDefault();
5310
+ const pastedText = e.clipboardData.getData("text");
5311
+ const digits = pastedText.replace(/\D/g, "").slice(0, length);
5312
+ if (digits) {
5313
+ onChange(digits);
5314
+ const focusIndex = Math.min(digits.length - 1, length - 1);
5315
+ setTimeout(() => {
5316
+ if (inputRefs.current[focusIndex]) {
5317
+ inputRefs.current[focusIndex].focus();
5318
+ }
5319
+ }, 0);
5320
+ }
5321
+ };
5322
+ return /* @__PURE__ */ jsxs("div", { className: clsx("ina-one-time-password", className), children: [
5323
+ title && /* @__PURE__ */ jsx("div", { className: "ina-one-time-password__title", children: title }),
5324
+ description && /* @__PURE__ */ jsx("div", { className: "ina-one-time-password__description", children: description }),
5325
+ /* @__PURE__ */ jsx("div", { className: "ina-one-time-password__container", children: Array.from({ length }).map((_, index) => {
5326
+ const digitValue = value[index] || "";
5327
+ return /* @__PURE__ */ jsx(
5328
+ "input",
5329
+ {
5330
+ ref: (el) => {
5331
+ inputRefs.current[index] = el;
5332
+ },
5333
+ type: "text",
5334
+ inputMode: "numeric",
5335
+ maxLength: 1,
5336
+ value: digitValue,
5337
+ onChange: (e) => handleChange(index, e),
5338
+ onKeyDown: (e) => handleKeyDown(index, e),
5339
+ onFocus: () => handleFocus(index),
5340
+ onBlur: handleBlur,
5341
+ onPaste: handlePaste,
5342
+ disabled,
5343
+ readOnly: readonly,
5344
+ className: clsx(
5345
+ "ina-one-time-password__input",
5346
+ error && "ina-one-time-password__input--error"
5347
+ ),
5348
+ "aria-label": `Digit ${index + 1} of ${length}`
5349
+ },
5350
+ index
5351
+ );
5352
+ }) }),
5353
+ helperText && /* @__PURE__ */ jsx(
5354
+ "div",
5355
+ {
5356
+ className: clsx(
5357
+ "ina-one-time-password__helper-text",
5358
+ error && "ina-one-time-password__helper-text--error"
5359
+ ),
5360
+ children: helperText
5361
+ }
5362
+ )
5363
+ ] });
5364
+ }
5198
5365
  const TimePicker = forwardRef(
5199
5366
  ({
5200
5367
  defaultValue = "",
@@ -8787,11 +8954,28 @@ function DatePicker({
8787
8954
  );
8788
8955
  }
8789
8956
  if (endDate) {
8790
- targetNextMonth = new Date(
8957
+ const endMonth = new Date(
8791
8958
  endDate.getFullYear(),
8792
8959
  endDate.getMonth(),
8793
8960
  1
8794
8961
  );
8962
+ if (targetMonth && targetMonth.getFullYear() === endMonth.getFullYear() && targetMonth.getMonth() === endMonth.getMonth()) {
8963
+ targetNextMonth = new Date(targetMonth);
8964
+ targetNextMonth.setMonth(targetNextMonth.getMonth() + 1);
8965
+ } else {
8966
+ targetNextMonth = endMonth;
8967
+ }
8968
+ }
8969
+ } else if (mode === "range" && parsedDates.length === 1) {
8970
+ const startDate = parsedDates[0];
8971
+ if (startDate) {
8972
+ targetMonth = new Date(
8973
+ startDate.getFullYear(),
8974
+ startDate.getMonth(),
8975
+ 1
8976
+ );
8977
+ targetNextMonth = new Date(targetMonth);
8978
+ targetNextMonth.setMonth(targetNextMonth.getMonth() + 1);
8795
8979
  }
8796
8980
  } else if (parsedDates.length > 0) {
8797
8981
  const targetDate = parsedDates[0];
@@ -8818,8 +9002,8 @@ function DatePicker({
8818
9002
  setNextMonth(nextMonthDate);
8819
9003
  } else if (mode === "range") {
8820
9004
  const parsedDates2 = parseSelectedDates();
8821
- const hasOnlyStartDate = parsedDates2.length === 1;
8822
- if (!hasOnlyStartDate) {
9005
+ const hasNoDates = parsedDates2.length === 0;
9006
+ if (hasNoDates) {
8823
9007
  const nextMonthDate = new Date(targetMonth);
8824
9008
  nextMonthDate.setMonth(nextMonthDate.getMonth() + 1);
8825
9009
  setNextMonth(nextMonthDate);
@@ -9405,7 +9589,7 @@ function DatePicker({
9405
9589
  dayNames.map((day) => /* @__PURE__ */ jsx("div", { className: "ina-date-picker__day-header", children: day }, day)),
9406
9590
  currentDays.map((day) => {
9407
9591
  const styling = getDateStyling(day);
9408
- return /* @__PURE__ */ jsx(
9592
+ return /* @__PURE__ */ jsxs(
9409
9593
  "button",
9410
9594
  {
9411
9595
  type: "button",
@@ -9414,7 +9598,10 @@ function DatePicker({
9414
9598
  onMouseLeave: () => setHoveredDate(null),
9415
9599
  disabled: styling.isDisabled,
9416
9600
  className: styling.className + (!styling.isSelected && !styling.isInRange && !styling.isHovered && !styling.isHoveredEnd && !styling.isDisabled ? " ina-date-picker__day--hover" : ""),
9417
- children: day.date.getDate()
9601
+ children: [
9602
+ day.date.getDate(),
9603
+ day.isToday && /* @__PURE__ */ jsx("span", { className: "ina-date-picker__today-label", children: "Hari ini" })
9604
+ ]
9418
9605
  },
9419
9606
  `${day.date.getFullYear()}-${day.date.getMonth()}-${day.date.getDate()}`
9420
9607
  );
@@ -9725,7 +9912,7 @@ function TabHorizontal({
9725
9912
  value,
9726
9913
  defaultValue,
9727
9914
  onChange,
9728
- size = "md",
9915
+ size = "sm",
9729
9916
  variant = "outline",
9730
9917
  fullWidth = false,
9731
9918
  useBrandColor = false,
@@ -9802,7 +9989,7 @@ function TabVertical({
9802
9989
  value,
9803
9990
  defaultValue,
9804
9991
  onChange,
9805
- size = "md",
9992
+ size = "sm",
9806
9993
  variant = "outline",
9807
9994
  useBrandColor = false,
9808
9995
  disabled = false,
@@ -9993,6 +10180,7 @@ export {
9993
10180
  Modal,
9994
10181
  MonthPicker,
9995
10182
  MultipleChoiceGrid,
10183
+ OneTimePassword,
9996
10184
  Pagination,
9997
10185
  PasswordInput,
9998
10186
  PhoneInput,