eai-frontend-components 2.0.19 → 2.0.21

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.js CHANGED
@@ -698,30 +698,114 @@ const HoverCardTrigger = HoverCardPrimitive__namespace.Trigger;
698
698
  const HoverCardContent = React__namespace.forwardRef(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (jsxRuntime.jsx(HoverCardPrimitive__namespace.Content, { ref: ref, align: align, sideOffset: sideOffset, className: cn('z-50 w-auto mr-20 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-2', className), ...props })));
699
699
  HoverCardContent.displayName = HoverCardPrimitive__namespace.Content.displayName;
700
700
 
701
+ /**
702
+ * Modify function for phone number input mask.
703
+ * Automatically adjusts between landline and mobile phone formats.
704
+ *
705
+ * @param value - Current input value
706
+ * @param data - New input data
707
+ * @param selectionStart - Cursor start position
708
+ * @param selectionEnd - Cursor end position
709
+ * @returns Mask configuration object
710
+ */
701
711
  const modifyPhone = ({ value, data, selectionStart, selectionEnd }) => {
702
712
  const _value = value.slice(0, selectionStart) + (data ?? '') + value.slice(selectionEnd);
703
713
  _value ? _value.replace(/[\D]+/g, '').length : 0;
704
714
  return maskPhone(_value);
705
715
  };
716
+ /**
717
+ * Creates a phone number mask based on the input length.
718
+ * - Landline: (XX) XXXX-XXXX
719
+ * - Mobile: (XX) X XXXX-XXXX
720
+ *
721
+ * @param value - Phone number string (can be null)
722
+ * @returns Mask configuration object with pattern and replacement rules
723
+ *
724
+ * @example
725
+ * ```tsx
726
+ * const mask = maskPhone('11987654321');
727
+ * // Returns: { mask: '(__) _ ____-____', replacement: { _: /\d/ } }
728
+ * ```
729
+ */
706
730
  function maskPhone(value) {
707
731
  const len = value ? value.replace(/[\D]+/g, '').length : 0;
708
732
  if (len > 10)
709
733
  return { mask: '(__) _ ____-____', replacement: { _: /\d/ } };
710
734
  return { mask: '(__) ____-_____', replacement: { _: /\d/ } };
711
735
  }
736
+ /**
737
+ * Modify function for CPF/CNPJ input mask.
738
+ * Automatically switches between CPF and CNPJ formats based on input length.
739
+ *
740
+ * @param value - Current input value
741
+ * @param data - New input data
742
+ * @param selectionStart - Cursor start position
743
+ * @param selectionEnd - Cursor end position
744
+ * @returns Mask configuration object
745
+ */
712
746
  const modifyCpfCnpj = ({ value, data, selectionStart, selectionEnd }) => {
713
747
  const _value = value.slice(0, selectionStart) + (data ?? '') + value.slice(selectionEnd);
714
748
  _value ? _value.replace(/[\D]+/g, '').length : 0;
715
749
  return maskCpfCnpj(_value);
716
750
  };
751
+ /**
752
+ * Creates a CPF or CNPJ mask based on the input length.
753
+ * - CPF: XXX.XXX.XXX-XX (up to 11 digits)
754
+ * - CNPJ: XX.XXX.XXX/XXXX-XX (12+ digits)
755
+ *
756
+ * @param value - CPF/CNPJ string (can be null)
757
+ * @returns Mask configuration object with pattern and replacement rules
758
+ *
759
+ * @example
760
+ * ```tsx
761
+ * const cpfMask = maskCpfCnpj('12345678901');
762
+ * // Returns: { mask: '___.___.___-___', replacement: { _: /\d/ } }
763
+ *
764
+ * const cnpjMask = maskCpfCnpj('12345678000195');
765
+ * // Returns: { mask: '__.___.___/____-__', replacement: { _: /\d/ } }
766
+ * ```
767
+ */
717
768
  function maskCpfCnpj(value) {
718
769
  const len = value ? value.replace(/[\D]+/g, '').length : 0;
719
770
  if (len > 11)
720
771
  return { mask: '__.___.___/____-__', replacement: { _: /\d/ } };
721
772
  return { mask: '___.___.___-___', replacement: { _: /\d/ } };
722
773
  }
774
+ /**
775
+ * Removes all non-numeric characters from a string.
776
+ * Useful for extracting only digits from masked inputs.
777
+ *
778
+ * @param value - String with potential mask characters
779
+ * @returns String containing only numeric characters
780
+ *
781
+ * @example
782
+ * ```tsx
783
+ * const cleaned = removeMaskNumber('(11) 9 8765-4321');
784
+ * // Returns: '11987654321'
785
+ *
786
+ * const cleanCpf = removeMaskNumber('123.456.789-01');
787
+ * // Returns: '12345678901'
788
+ * ```
789
+ */
790
+ const removeMaskNumber = (value) => {
791
+ return value?.replace(/\D/g, '');
792
+ };
723
793
 
724
794
  // PHONE
795
+ /**
796
+ * Formats a phone number string with proper mask.
797
+ * Automatically detects landline vs mobile format.
798
+ *
799
+ * @param telefone - Raw phone number string
800
+ * @param removerCountryCode - Whether to remove country code (55) if present
801
+ * @returns Formatted phone number string
802
+ *
803
+ * @example
804
+ * ```tsx
805
+ * formatPhone('11987654321') // '(11) 9 8765-4321'
806
+ * formatPhone('1134567890') // '(11) 3456-7890'
807
+ * ```
808
+ */
725
809
  function formatPhone(telefone, removerCountryCode = true) {
726
810
  if (!telefone)
727
811
  return '';
@@ -733,6 +817,19 @@ function formatPhone(telefone, removerCountryCode = true) {
733
817
  return mask.format(numberPhone, maskPhone(numberPhone));
734
818
  }
735
819
  // CPF/CNPJ
820
+ /**
821
+ * Formats a CPF or CNPJ string with proper mask.
822
+ * Automatically detects CPF vs CNPJ format based on length.
823
+ *
824
+ * @param cpfCnpj - Raw CPF/CNPJ string
825
+ * @returns Formatted CPF/CNPJ string
826
+ *
827
+ * @example
828
+ * ```tsx
829
+ * formatCpfCnpj('12345678901') // '123.456.789-01'
830
+ * formatCpfCnpj('12345678000195') // '12.345.678/0001-95'
831
+ * ```
832
+ */
736
833
  function formatCpfCnpj(cpfCnpj) {
737
834
  if (!cpfCnpj)
738
835
  return '';
@@ -749,6 +846,19 @@ function getMonth(date) {
749
846
  function getYear(date) {
750
847
  return date.getFullYear().toString();
751
848
  }
849
+ /**
850
+ * Formats a date to Brazilian format (DD/MM/YYYY).
851
+ *
852
+ * @param date - Date string, Date object, or undefined
853
+ * @param separator - Date separator (default: '/')
854
+ * @returns Formatted date string in Brazilian format
855
+ *
856
+ * @example
857
+ * ```tsx
858
+ * formatDate('2023-12-25') // '25/12/2023'
859
+ * formatDate(new Date()) // '13/10/2025'
860
+ * ```
861
+ */
752
862
  const formatDate = (date, separator = '/') => {
753
863
  if (!date)
754
864
  return '';
@@ -820,6 +930,19 @@ const formatNumber = (value) => {
820
930
  });
821
931
  };
822
932
  // DECIMAL
933
+ /**
934
+ * Formats a number with Brazilian decimal format.
935
+ *
936
+ * @param value - Numeric value to format
937
+ * @param decimalPlaces - Number of decimal places (default: 2)
938
+ * @returns Formatted decimal string
939
+ *
940
+ * @example
941
+ * ```tsx
942
+ * formatDecimal(1234.56) // '1.234,56'
943
+ * formatDecimal(1000.1, 1) // '1.000,1'
944
+ * ```
945
+ */
823
946
  const formatDecimal = (value, decimalPlaces = 2) => {
824
947
  return value.toLocaleString('pt-BR', {
825
948
  style: 'decimal',
@@ -827,6 +950,87 @@ const formatDecimal = (value, decimalPlaces = 2) => {
827
950
  maximumFractionDigits: decimalPlaces,
828
951
  });
829
952
  };
953
+ // PERCENT
954
+ /**
955
+ * Formats a number as percentage with Brazilian decimal format.
956
+ *
957
+ * @param value - Numeric value to format
958
+ * @param decimalPlaces - Number of decimal places (default: 2)
959
+ * @returns Formatted percentage string
960
+ *
961
+ * @example
962
+ * ```tsx
963
+ * formatPercent(15.5) // '% 15,50'
964
+ * formatPercent(100, 0) // '% 100'
965
+ * ```
966
+ */
967
+ const formatPercent = (value, decimalPlaces = 2) => {
968
+ return `% ${formatDecimal(value, decimalPlaces)}`;
969
+ };
970
+ // CURRENCY
971
+ /**
972
+ * Formats a number as Brazilian currency (BRL).
973
+ *
974
+ * @param value - Numeric value to format
975
+ * @param decimalPlaces - Number of decimal places (default: 2)
976
+ * @returns Formatted currency string
977
+ *
978
+ * @example
979
+ * ```tsx
980
+ * formatCurrency(1234.56) // 'R$ 1.234,56'
981
+ * formatCurrency(1000, 0) // 'R$ 1.000'
982
+ * ```
983
+ */
984
+ const formatCurrency = (value, decimalPlaces = 2) => {
985
+ return value.toLocaleString('pt-BR', {
986
+ style: 'currency',
987
+ currency: 'BRL',
988
+ minimumFractionDigits: decimalPlaces,
989
+ maximumFractionDigits: decimalPlaces,
990
+ });
991
+ };
992
+ const isInvalidCurrencyValue = (rawValue) => {
993
+ if (!rawValue || rawValue.trim() === '')
994
+ return true;
995
+ const numericValue = stringToNumber(rawValue);
996
+ return Number.isNaN(numericValue) || numericValue <= 0;
997
+ };
998
+ // OTHERS
999
+ /**
1000
+ * Formats an MSISDN (mobile phone number) to display format.
1001
+ *
1002
+ * @param value - Raw MSISDN string
1003
+ * @returns Formatted MSISDN string
1004
+ *
1005
+ * @example
1006
+ * ```tsx
1007
+ * formatMsisdn('5511987654321') // '(11) 98765-4321'
1008
+ * ```
1009
+ */
1010
+ function formatMsisdn(value = '') {
1011
+ const msisdn = value.replace(/\D/g, '');
1012
+ return `(${msisdn.slice(2, 4)}) ${msisdn.slice(4, 9)}-${msisdn.slice(9)}`;
1013
+ }
1014
+ /**
1015
+ * Formats a CEP (Brazilian postal code) with proper mask.
1016
+ *
1017
+ * @param cep - Raw CEP string
1018
+ * @returns Formatted CEP string (XXXXX-XXX)
1019
+ *
1020
+ * @example
1021
+ * ```tsx
1022
+ * formatCEP('01234567') // '01234-567'
1023
+ * formatCEP('12345') // '12345'
1024
+ * ```
1025
+ */
1026
+ function formatCEP(cep) {
1027
+ if (!cep)
1028
+ return '';
1029
+ return cep
1030
+ .replace(/\D/g, '')
1031
+ .replace(/(\d{5})(\d)/, '$1-$2')
1032
+ .replace(/(-\d{3})\d+?$/, '$1');
1033
+ }
830
1034
 
831
1035
  function buildFormatLongFn(args) {
832
1036
  return (options = {}) => {
@@ -3653,20 +3857,28 @@ exports.formHelpText = formHelpText;
3653
3857
  exports.formLabel = formLabel;
3654
3858
  exports.formLabelAndSubLabel = formLabelAndSubLabel;
3655
3859
  exports.formMessage = formMessage;
3860
+ exports.formatCEP = formatCEP;
3656
3861
  exports.formatCpfCnpj = formatCpfCnpj;
3862
+ exports.formatCurrency = formatCurrency;
3657
3863
  exports.formatDate = formatDate;
3658
3864
  exports.formatDateCalendar = formatDateCalendar;
3659
3865
  exports.formatDateTime = formatDateTime;
3660
3866
  exports.formatDecimal = formatDecimal;
3867
+ exports.formatMsisdn = formatMsisdn;
3661
3868
  exports.formatNumber = formatNumber;
3869
+ exports.formatPercent = formatPercent;
3662
3870
  exports.formatPhone = formatPhone;
3663
3871
  exports.getFirstDayOf90DaysAgo = getFirstDayOf90DaysAgo;
3664
3872
  exports.getFirstDayOfCurrentMonth = getFirstDayOfCurrentMonth;
3665
3873
  exports.getTailwindColorShades = getTailwindColorShades;
3666
3874
  exports.invertDate = invertDate;
3875
+ exports.isInvalidCurrencyValue = isInvalidCurrencyValue;
3667
3876
  exports.isUUIDv4 = isUUIDv4;
3877
+ exports.maskCpfCnpj = maskCpfCnpj;
3878
+ exports.maskPhone = maskPhone;
3668
3879
  exports.modifyCpfCnpj = modifyCpfCnpj;
3669
3880
  exports.modifyPhone = modifyPhone;
3881
+ exports.removeMaskNumber = removeMaskNumber;
3670
3882
  exports.replaceThemeTailwindColors = replaceThemeTailwindColors;
3671
3883
  exports.roundNumber = roundNumber;
3672
3884
  exports.stringDateToDate = stringDateToDate;