@yeverlibs/ds 1.1.30 → 1.1.32

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.d.mts CHANGED
@@ -580,9 +580,10 @@ type CounterInputProps$2<T extends FieldValues = FieldValues> = {
580
580
  id?: string
581
581
  defaultValue?: string | number
582
582
  name?: Path<T>
583
+ minValue?: number
583
584
  } & React.InputHTMLAttributes<HTMLInputElement>
584
585
 
585
- declare const Counter: <T extends FieldValues = FieldValues>({ label, hasDisabled, redeemablePoints, tooltip, full, type, wrapperClassName, methods, onChange, id, ...rest }: CounterInputProps$2<T>) => react_jsx_runtime.JSX.Element;
586
+ declare const Counter: <T extends FieldValues = FieldValues>({ label, hasDisabled, redeemablePoints, tooltip, full, type, wrapperClassName, methods, onChange, id, minValue, ...rest }: CounterInputProps$2<T>) => react_jsx_runtime.JSX.Element;
586
587
 
587
588
  type CurrencyInputProps<T extends FieldValues = FieldValues> = {
588
589
  label?: string
@@ -662,7 +663,6 @@ declare const FormWrapper: <T extends FieldValues>({ children, onSubmit, default
662
663
 
663
664
  type InputProps$1 = {
664
665
  $charactersLimit?: number
665
- $showCharactersLimit?: boolean
666
666
  $iconName?: IconName
667
667
  $labelText?: string
668
668
  $iconDirection?: 'left' | 'right'
@@ -718,9 +718,9 @@ type SelectProps = {
718
718
  label?: string
719
719
  placeholder?: string
720
720
  options: SelectOption[]
721
- onSelect: (option: SelectOption | null) => void
721
+ onSelect: (option: SelectOption) => void
722
722
  className?: string
723
- value?: SelectOption | null
723
+ value?: SelectOption
724
724
  tooltip?: string
725
725
  isClearable?: boolean
726
726
  }
@@ -794,10 +794,10 @@ type CounterInputProps$1 = {
794
794
  form: UseFormReturn
795
795
  } & React.InputHTMLAttributes<HTMLInputElement>
796
796
 
797
- declare const formatTime$1: (time: string | number) => string;
798
-
799
797
  declare const TimerCounter: React.FC<CounterInputProps$1>;
800
798
 
799
+ declare const formatTime$1: (time: string | number) => string;
800
+
801
801
  type CounterInputProps = {
802
802
  label?: string
803
803
  tooltip?: string
package/dist/index.d.ts CHANGED
@@ -580,9 +580,10 @@ type CounterInputProps$2<T extends FieldValues = FieldValues> = {
580
580
  id?: string
581
581
  defaultValue?: string | number
582
582
  name?: Path<T>
583
+ minValue?: number
583
584
  } & React.InputHTMLAttributes<HTMLInputElement>
584
585
 
585
- declare const Counter: <T extends FieldValues = FieldValues>({ label, hasDisabled, redeemablePoints, tooltip, full, type, wrapperClassName, methods, onChange, id, ...rest }: CounterInputProps$2<T>) => react_jsx_runtime.JSX.Element;
586
+ declare const Counter: <T extends FieldValues = FieldValues>({ label, hasDisabled, redeemablePoints, tooltip, full, type, wrapperClassName, methods, onChange, id, minValue, ...rest }: CounterInputProps$2<T>) => react_jsx_runtime.JSX.Element;
586
587
 
587
588
  type CurrencyInputProps<T extends FieldValues = FieldValues> = {
588
589
  label?: string
@@ -662,7 +663,6 @@ declare const FormWrapper: <T extends FieldValues>({ children, onSubmit, default
662
663
 
663
664
  type InputProps$1 = {
664
665
  $charactersLimit?: number
665
- $showCharactersLimit?: boolean
666
666
  $iconName?: IconName
667
667
  $labelText?: string
668
668
  $iconDirection?: 'left' | 'right'
@@ -718,9 +718,9 @@ type SelectProps = {
718
718
  label?: string
719
719
  placeholder?: string
720
720
  options: SelectOption[]
721
- onSelect: (option: SelectOption | null) => void
721
+ onSelect: (option: SelectOption) => void
722
722
  className?: string
723
- value?: SelectOption | null
723
+ value?: SelectOption
724
724
  tooltip?: string
725
725
  isClearable?: boolean
726
726
  }
@@ -794,10 +794,10 @@ type CounterInputProps$1 = {
794
794
  form: UseFormReturn
795
795
  } & React.InputHTMLAttributes<HTMLInputElement>
796
796
 
797
- declare const formatTime$1: (time: string | number) => string;
798
-
799
797
  declare const TimerCounter: React.FC<CounterInputProps$1>;
800
798
 
799
+ declare const formatTime$1: (time: string | number) => string;
800
+
801
801
  type CounterInputProps = {
802
802
  label?: string
803
803
  tooltip?: string
package/dist/index.js CHANGED
@@ -14,8 +14,8 @@ var locale$1 = require('date-fns/locale');
14
14
  var reactHookForm = require('react-hook-form');
15
15
  var Link2 = require('next/link');
16
16
  var framerMotion = require('framer-motion');
17
- var sonner = require('sonner');
18
17
  var Cookies = require('js-cookie');
18
+ var sonner = require('sonner');
19
19
  var currency = require('currency.js');
20
20
 
21
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -8976,7 +8976,6 @@ var Input = React107.forwardRef(
8976
8976
  $errorMessage,
8977
8977
  type = "text",
8978
8978
  $charactersLimit,
8979
- $showCharactersLimit = true,
8980
8979
  $description,
8981
8980
  isNotProvided = false,
8982
8981
  wrapperClassName,
@@ -9031,7 +9030,7 @@ var Input = React107.forwardRef(
9031
9030
  ]
9032
9031
  }
9033
9032
  ),
9034
- $charactersLimit && $showCharactersLimit && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-600", children: [
9033
+ $charactersLimit && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-600", children: [
9035
9034
  value.length,
9036
9035
  " de ",
9037
9036
  $charactersLimit,
@@ -9051,48 +9050,17 @@ var Input = React107.forwardRef(
9051
9050
  maxLength: $charactersLimit,
9052
9051
  value,
9053
9052
  onChange: (e14) => {
9054
- let inputValue = e14.target.value;
9055
- if (type === "number") {
9056
- inputValue = inputValue.replace(/[^0-9]/g, "");
9057
- }
9053
+ const inputValue = e14.target.value;
9058
9054
  const newValue = $formatValue ? $formatValue(inputValue) : inputValue;
9059
- const finalValue = $charactersLimit ? newValue.slice(0, $charactersLimit) : newValue;
9060
- setValue(finalValue);
9055
+ setValue(newValue);
9061
9056
  onChange?.({
9062
9057
  ...e14,
9063
9058
  target: {
9064
9059
  ...e14.target,
9065
- value: finalValue
9060
+ value: newValue
9066
9061
  }
9067
9062
  });
9068
9063
  },
9069
- onKeyDown: (e14) => {
9070
- if (type === "number") {
9071
- const allowedKeys = [
9072
- "Backspace",
9073
- "Delete",
9074
- "Tab",
9075
- "Escape",
9076
- "Enter",
9077
- "ArrowLeft",
9078
- "ArrowRight",
9079
- "ArrowUp",
9080
- "ArrowDown",
9081
- "Home",
9082
- "End"
9083
- ];
9084
- const isAllowedKey = allowedKeys.includes(e14.key);
9085
- const isNumberKey = /^[0-9]$/.test(e14.key);
9086
- const isCtrlA = e14.ctrlKey && e14.key === "a";
9087
- const isCtrlC = e14.ctrlKey && e14.key === "c";
9088
- const isCtrlV = e14.ctrlKey && e14.key === "v";
9089
- const isCtrlX = e14.ctrlKey && e14.key === "x";
9090
- if (!isAllowedKey && !isNumberKey && !isCtrlA && !isCtrlC && !isCtrlV && !isCtrlX) {
9091
- e14.preventDefault();
9092
- }
9093
- }
9094
- rest.onKeyDown?.(e14);
9095
- },
9096
9064
  $inputClassName,
9097
9065
  ...rest
9098
9066
  }
@@ -9113,49 +9081,18 @@ var Input = React107.forwardRef(
9113
9081
  maxLength: $charactersLimit,
9114
9082
  value: field.value || "",
9115
9083
  onChange: (e14) => {
9116
- let inputValue = e14.target.value;
9117
- if (type === "number") {
9118
- inputValue = inputValue.replace(/[^0-9]/g, "");
9119
- }
9084
+ const inputValue = e14.target.value;
9120
9085
  const newValue = $formatValue ? $formatValue(inputValue) : inputValue;
9121
- const finalValue = $charactersLimit ? newValue.slice(0, $charactersLimit) : newValue;
9122
- setValue(finalValue);
9123
- field.onChange(finalValue);
9086
+ setValue(newValue);
9087
+ field.onChange(newValue);
9124
9088
  onChange?.({
9125
9089
  ...e14,
9126
9090
  target: {
9127
9091
  ...e14.target,
9128
- value: finalValue
9092
+ value: newValue
9129
9093
  }
9130
9094
  });
9131
9095
  },
9132
- onKeyDown: (e14) => {
9133
- if (type === "number") {
9134
- const allowedKeys = [
9135
- "Backspace",
9136
- "Delete",
9137
- "Tab",
9138
- "Escape",
9139
- "Enter",
9140
- "ArrowLeft",
9141
- "ArrowRight",
9142
- "ArrowUp",
9143
- "ArrowDown",
9144
- "Home",
9145
- "End"
9146
- ];
9147
- const isAllowedKey = allowedKeys.includes(e14.key);
9148
- const isNumberKey = /^[0-9]$/.test(e14.key);
9149
- const isCtrlA = e14.ctrlKey && e14.key === "a";
9150
- const isCtrlC = e14.ctrlKey && e14.key === "c";
9151
- const isCtrlV = e14.ctrlKey && e14.key === "v";
9152
- const isCtrlX = e14.ctrlKey && e14.key === "x";
9153
- if (!isAllowedKey && !isNumberKey && !isCtrlA && !isCtrlC && !isCtrlV && !isCtrlX) {
9154
- e14.preventDefault();
9155
- }
9156
- }
9157
- rest.onKeyDown?.(e14);
9158
- },
9159
9096
  $inputClassName,
9160
9097
  ...rest
9161
9098
  }
@@ -11320,24 +11257,27 @@ var Counter = ({
11320
11257
  methods,
11321
11258
  onChange,
11322
11259
  id,
11260
+ minValue = 0,
11323
11261
  ...rest
11324
11262
  }) => {
11325
11263
  const form = reactHookForm.useForm();
11326
11264
  const { setValue, getValues, control } = methods || form;
11327
11265
  const fieldName = rest.name || "counter";
11328
- const defaultValue = rest.defaultValue ? Number(rest.defaultValue) : 0;
11266
+ const defaultValue = rest.defaultValue ? Math.max(Number(rest.defaultValue), minValue) : minValue;
11329
11267
  const handleIncrement = () => {
11330
11268
  if (!hasDisabled) {
11331
- const currentValue = getValues(fieldName) || 0;
11332
- const newValue = Number(currentValue) + 1;
11269
+ const currentValue = getValues(fieldName);
11270
+ const numericValue = currentValue !== void 0 && currentValue !== null ? Number(currentValue) : minValue;
11271
+ const newValue = Math.max(numericValue, minValue) + 1;
11333
11272
  setValue(fieldName, newValue);
11334
11273
  onChange?.(newValue);
11335
11274
  }
11336
11275
  };
11337
11276
  const handleDecrement = () => {
11338
11277
  if (!hasDisabled) {
11339
- const currentValue = getValues(fieldName) || 0;
11340
- const newValue = Number(currentValue) > 0 ? Number(currentValue) - 1 : 0;
11278
+ const currentValue = getValues(fieldName);
11279
+ const numericValue = currentValue !== void 0 && currentValue !== null ? Number(currentValue) : minValue;
11280
+ const newValue = Math.max(numericValue, minValue) > minValue ? Math.max(numericValue, minValue) - 1 : minValue;
11341
11281
  setValue(fieldName, newValue);
11342
11282
  onChange?.(newValue);
11343
11283
  }
@@ -11385,11 +11325,11 @@ var Counter = ({
11385
11325
  ...fieldWithoutDefaultValue,
11386
11326
  id: fieldName,
11387
11327
  type: "number",
11388
- min: 1,
11389
- value: field.value || 1,
11328
+ min: minValue,
11329
+ value: field.value !== void 0 && field.value !== null ? Math.max(Number(field.value), minValue) : minValue,
11390
11330
  onChange: (e14) => {
11391
11331
  const newValue = Number(e14.target.value);
11392
- if (newValue >= 0) {
11332
+ if (newValue >= minValue) {
11393
11333
  field.onChange(newValue);
11394
11334
  onChange?.(newValue);
11395
11335
  }
@@ -11748,7 +11688,9 @@ var CustomSelect = ({
11748
11688
  isClearable = true
11749
11689
  }) => {
11750
11690
  const handleChange = (option) => {
11751
- onSelect(option);
11691
+ if (option) {
11692
+ onSelect(option);
11693
+ }
11752
11694
  };
11753
11695
  const formatOptionLabel = (option) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center", children: [
11754
11696
  option.icon && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative mr-2 flex h-[24px] max-h-[24px] w-[24px] max-w-[24px] items-center justify-center rounded border border-gray-300", children: /* @__PURE__ */ jsxRuntime.jsx(Image3__default.default, { src: option.icon, alt: option.label, fill: true, className: "p-1", quality: 100 }) }),
@@ -12081,8 +12023,6 @@ var TimeInput = ({
12081
12023
  ] })
12082
12024
  ] });
12083
12025
  };
12084
-
12085
- // src/_design-system/helpers/formatTime.ts
12086
12026
  var formatTime = (time2) => {
12087
12027
  let timeInSeconds = 0;
12088
12028
  if (typeof time2 === "string") {
@@ -12231,7 +12171,26 @@ var TimerCounter = ({
12231
12171
  description && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-700", children: description })
12232
12172
  ] });
12233
12173
  };
12174
+
12175
+ // src/_design-system/helpers/formatTime.ts
12234
12176
  var formatTime2 = (time2) => {
12177
+ let timeInSeconds = 0;
12178
+ if (typeof time2 === "string") {
12179
+ if (time2.includes(":")) {
12180
+ const [hours3, minutes3, seconds4] = time2.split(":").map(Number);
12181
+ timeInSeconds = hours3 * 3600 + minutes3 * 60 + seconds4;
12182
+ } else {
12183
+ timeInSeconds = parseInt(time2, 10) || 0;
12184
+ }
12185
+ } else {
12186
+ timeInSeconds = time2 || 0;
12187
+ }
12188
+ const hours2 = Math.floor(timeInSeconds / 3600);
12189
+ const minutes2 = Math.floor(timeInSeconds % 3600 / 60);
12190
+ const seconds3 = timeInSeconds % 60;
12191
+ return `${hours2.toString().padStart(2, "0")}:${minutes2.toString().padStart(2, "0")}:${seconds3.toString().padStart(2, "0")}`;
12192
+ };
12193
+ var formatTime3 = (time2) => {
12235
12194
  let timeInSeconds = 0;
12236
12195
  if (typeof time2 === "string") {
12237
12196
  if (time2.includes(":")) {
@@ -12261,7 +12220,7 @@ var TimerCounterWithoutSeconds = ({
12261
12220
  const fieldName = rest.name || "timer";
12262
12221
  const { control, setValue, watch } = form;
12263
12222
  const rawValue = watch(fieldName, defaultValue || "00:00");
12264
- const displayValue = typeof rawValue === "number" ? formatTime2(rawValue) : rawValue || "00:00";
12223
+ const displayValue = typeof rawValue === "number" ? formatTime3(rawValue) : rawValue || "00:00";
12265
12224
  const parseTime = (timeString) => {
12266
12225
  if (!timeString) return 0;
12267
12226
  const [hours2, minutes2] = timeString.split(":").map(Number);
@@ -12275,7 +12234,7 @@ var TimerCounterWithoutSeconds = ({
12275
12234
  setValue(fieldName, "00:00", { shouldValidate: true, shouldDirty: true, shouldTouch: true });
12276
12235
  return;
12277
12236
  }
12278
- setValue(fieldName, formatTime2(newSeconds), { shouldValidate: true, shouldDirty: true, shouldTouch: true });
12237
+ setValue(fieldName, formatTime3(newSeconds), { shouldValidate: true, shouldDirty: true, shouldTouch: true });
12279
12238
  }
12280
12239
  };
12281
12240
  const handleDecrement = () => {
@@ -12283,7 +12242,7 @@ var TimerCounterWithoutSeconds = ({
12283
12242
  const currentSeconds = parseTime(displayValue);
12284
12243
  if (currentSeconds <= 0) return;
12285
12244
  const newSeconds = Math.max(0, currentSeconds - 3600);
12286
- setValue(fieldName, formatTime2(newSeconds), { shouldValidate: true, shouldDirty: true, shouldTouch: true });
12245
+ setValue(fieldName, formatTime3(newSeconds), { shouldValidate: true, shouldDirty: true, shouldTouch: true });
12287
12246
  }
12288
12247
  };
12289
12248
  const handleChanges = (e14) => {
@@ -12401,6 +12360,7 @@ function FileUploadComponent({
12401
12360
  }) {
12402
12361
  const [filePreview, setFilePreview] = React107.useState(initialImage || null);
12403
12362
  const [fileSize, setFileSize] = React107.useState(null);
12363
+ const [errorMessage, setErrorMessage] = React107.useState(null);
12404
12364
  const form = reactHookForm.useForm();
12405
12365
  const { control } = methods || form;
12406
12366
  const fieldValue = methods?.watch(name || "file");
@@ -12415,8 +12375,8 @@ function FileUploadComponent({
12415
12375
  const isImagePreview = React107.useCallback((preview) => {
12416
12376
  if (!preview || typeof preview !== "string") return false;
12417
12377
  if (preview.startsWith("data:image/")) return true;
12418
- if (preview.startsWith("http") && preview.match(/\.(jpg|jpeg|png|gif|webp|svg|bmp|tiff)/i)) return true;
12419
- if (preview.match(/\.(jpg|jpeg|png|gif|webp|svg|bmp|tiff)$/i)) return true;
12378
+ if (preview.startsWith("http") && preview.match(/\.(jpg|jpeg|png|gif|webp|svg|avif|bmp|tiff)/i)) return true;
12379
+ if (preview.match(/\.(jpg|jpeg|png|gif|webp|svg|avif|bmp|tiff)$/i)) return true;
12420
12380
  return false;
12421
12381
  }, []);
12422
12382
  React107.useEffect(() => {
@@ -12433,13 +12393,14 @@ function FileUploadComponent({
12433
12393
  const handleFileChange = React107.useCallback(
12434
12394
  (file, onChange) => {
12435
12395
  if (!acceptedTypes.includes(file.type)) {
12436
- sonner.toast.error("Tipo de arquivo n\xE3o suportado.");
12396
+ setErrorMessage("Tipo de arquivo n\xE3o suportado.");
12437
12397
  return;
12438
12398
  }
12439
12399
  if (file.size > maxSize) {
12440
- sonner.toast.error("Arquivo excede o tamanho m\xE1ximo permitido.");
12400
+ setErrorMessage("Arquivo excede o tamanho m\xE1ximo permitido.");
12441
12401
  return;
12442
12402
  }
12403
+ setErrorMessage(null);
12443
12404
  if (file.type === "application/pdf" || file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
12444
12405
  setFilePreview(file.name);
12445
12406
  setFileSize(file.size);
@@ -12465,6 +12426,7 @@ function FileUploadComponent({
12465
12426
  (onChange) => {
12466
12427
  setFilePreview(null);
12467
12428
  setFileSize(null);
12429
+ setErrorMessage(null);
12468
12430
  onChange(null);
12469
12431
  externalOnChange?.(null);
12470
12432
  const fileInput = document.getElementById(`${name}-input`);
@@ -12486,14 +12448,10 @@ function FileUploadComponent({
12486
12448
  const handleInputChange = React107.useCallback(
12487
12449
  (e14, onChange) => {
12488
12450
  if (e14.target.files && e14.target.files[0]) {
12489
- if (!acceptedTypes.includes(e14.target.files[0].type)) {
12490
- sonner.toast.error("Tipo de arquivo n\xE3o suportado.");
12491
- return;
12492
- }
12493
12451
  handleFileChange(e14.target.files[0], onChange);
12494
12452
  }
12495
12453
  },
12496
- [acceptedTypes, handleFileChange]
12454
+ [handleFileChange]
12497
12455
  );
12498
12456
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-col gap-4", children: [
12499
12457
  $labelText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
@@ -12623,6 +12581,7 @@ function FileUploadComponent({
12623
12581
  maxSizeFormatted,
12624
12582
  " por arquivo."
12625
12583
  ] }),
12584
+ errorMessage && /* @__PURE__ */ jsxRuntime.jsx(Text, { $as: "small", className: "text-xs text-red-500", children: errorMessage }),
12626
12585
  fieldState.error && /* @__PURE__ */ jsxRuntime.jsx(Text, { $as: "small", className: "text-xs text-red-500", children: fieldState.error.message })
12627
12586
  ] })
12628
12587
  }
@@ -26787,8 +26746,8 @@ exports.formatNumberToCurrency = formatNumberToCurrency;
26787
26746
  exports.formatPhone = formatPhone;
26788
26747
  exports.formatPostalCode = formatPostalCode;
26789
26748
  exports.formatRawDigitsToCurrency = formatRawDigitsToCurrency;
26790
- exports.formatTime = formatTime;
26791
- exports.formatTimeWithoutSeconds = formatTime2;
26749
+ exports.formatTime = formatTime2;
26750
+ exports.formatTimeWithoutSeconds = formatTime3;
26792
26751
  exports.getDates = getDates;
26793
26752
  exports.handleFormSubmission = handleFormSubmission;
26794
26753
  exports.iconList = iconList;