jclib-ui 1.0.99 → 1.0.101

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param {import('reactstrap').InputProps & import('react-number-format').NumberFormatProps} props
4
+ * @returns {JSX.Element}
5
+ */
6
+ export default function InputCpfCnpj(props: import('reactstrap').InputProps & import('react-number-format').NumberFormatProps): JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import { default as InputCep } from './InputCep';
2
2
  import { default as InputFone } from './InputFone';
3
3
  import { FormatValor, FormatQuant, FormatPercent, FormatData } from './Formats';
4
+ import { default as InputCpfCnpj } from './inputCpfCnpj';
4
5
  export function InputValor({ name, onChange, onClick, allowNegative, ...rest }: {
5
6
  [x: string]: any;
6
7
  name: any;
@@ -45,4 +46,4 @@ export function InputFinder({ title, onFind, children, ...rest }: {
45
46
  onFind: any;
46
47
  children: any;
47
48
  }): import("react/jsx-runtime").JSX.Element;
48
- export { InputCep, InputFone, FormatValor, FormatQuant, FormatPercent, FormatData };
49
+ export { InputCep, InputFone, FormatValor, FormatQuant, FormatPercent, FormatData, InputCpfCnpj };
@@ -0,0 +1,3 @@
1
+ export function isInvalidCpf(value: any): boolean;
2
+ export function isInvalidCnpj(value: any): boolean;
3
+ export function isInvalidCpfCnpj(value: any): boolean;
@@ -1,6 +1,6 @@
1
1
  import * as t from "react";
2
2
  import t__default, { createContext, useState, useCallback, useEffect, useContext, useRef, useLayoutEffect, useMemo } from "react";
3
- import { isDarkMode, random, isMobile, isDesktop, getDateTimeStr, getHash, formatValor } from "jcinfo-utils";
3
+ import { isDarkMode, random, isMobile, isDesktop, getDateTimeStr, getHash, formatValor, validarCPF, validarCNPJ } from "jcinfo-utils";
4
4
  import { useDragControls, motion } from "framer-motion";
5
5
  import styled from "styled-components";
6
6
  import { Dropdown, DropdownMenu, DropdownItem, DropdownToggle, Button, InputGroup, Input as Input$1 } from "reactstrap";
@@ -18439,6 +18439,80 @@ function InputFone({ name, value, onChange, ...rest }) {
18439
18439
  }
18440
18440
  );
18441
18441
  }
18442
+ function isInvalidCpf(value) {
18443
+ const cpfEscapado = "00000000000";
18444
+ const valorLimpo = String(value).replace(/\D/g, "");
18445
+ let result = false;
18446
+ if (!validarCPF(valorLimpo)) {
18447
+ result = true;
18448
+ }
18449
+ if (valorLimpo == cpfEscapado) {
18450
+ result = false;
18451
+ }
18452
+ if (value == "") {
18453
+ result = false;
18454
+ }
18455
+ return result;
18456
+ }
18457
+ function isInvalidCnpj(value) {
18458
+ const cpnjEscapado = "00000000000000";
18459
+ const valorLimpo = String(value).replace(/\D/g, "");
18460
+ let result = false;
18461
+ if (!validarCNPJ(valorLimpo)) {
18462
+ result = true;
18463
+ }
18464
+ if (valorLimpo == cpnjEscapado) {
18465
+ result = false;
18466
+ }
18467
+ if (value == "") {
18468
+ result = false;
18469
+ }
18470
+ return result;
18471
+ }
18472
+ function isInvalidCpfCnpj(value) {
18473
+ const valorLimpo = String(value).replace(/\D/g, "");
18474
+ let result = false;
18475
+ if (valorLimpo.length <= 11 && isInvalidCpf(value)) {
18476
+ result = true;
18477
+ }
18478
+ if (valorLimpo.length > 11 && isInvalidCnpj(value)) {
18479
+ result = true;
18480
+ }
18481
+ if (value == "") {
18482
+ result = false;
18483
+ }
18484
+ return result;
18485
+ }
18486
+ const cCpfMask = "###.###.###-#####";
18487
+ const cCnpjMask = "##.###.###/####-##";
18488
+ function InputCpfCnpj(props) {
18489
+ const [cpfCnpjMask, setCpfCnpjMask] = useState(getMarcara(props.value));
18490
+ useEffect(() => {
18491
+ setCpfCnpjMask(getMarcara(props.value));
18492
+ }, [props.value]);
18493
+ function getMarcara(initValue) {
18494
+ let value = initValue;
18495
+ value = value.replace(/\D/g, "");
18496
+ if (value.length > 11) {
18497
+ return cCnpjMask;
18498
+ } else {
18499
+ return cCpfMask;
18500
+ }
18501
+ }
18502
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
18503
+ Input$1,
18504
+ {
18505
+ tag: NumberFormat,
18506
+ mask: "",
18507
+ format: cpfCnpjMask,
18508
+ onKeyUp: (e) => {
18509
+ setCpfCnpjMask(getMarcara(e.target.value));
18510
+ },
18511
+ invalid: isInvalidCpfCnpj(props.value),
18512
+ ...props
18513
+ }
18514
+ );
18515
+ }
18442
18516
  function handleChangeLocal(values, name, onChange) {
18443
18517
  const getNumberConvert = (value) => {
18444
18518
  if (!value || value === void 0 || value === null || isNaN(value)) {
@@ -18570,26 +18644,28 @@ const InputHora = (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(
18570
18644
  }
18571
18645
  );
18572
18646
  const InputCpf = (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(
18573
- NumberFormat,
18647
+ Input$1,
18574
18648
  {
18649
+ tag: NumberFormat,
18575
18650
  name: props.name,
18576
18651
  format: "###.###.###-##",
18577
18652
  mask: "_",
18578
18653
  value: props.value,
18579
18654
  onChange: props.onChange,
18580
- className: "form-control",
18655
+ invalid: isInvalidCpf(props.value),
18581
18656
  ...props
18582
18657
  }
18583
18658
  );
18584
18659
  const InputCnpj = (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(
18585
- NumberFormat,
18660
+ Input$1,
18586
18661
  {
18662
+ tag: NumberFormat,
18587
18663
  name: props.name,
18588
18664
  format: "##.###.###/####-##",
18589
18665
  mask: "_",
18590
18666
  value: props.value,
18591
18667
  onChange: props.onChange,
18592
- className: "form-control",
18668
+ invalid: isInvalidCnpj(props.value),
18593
18669
  ...props
18594
18670
  }
18595
18671
  );
@@ -20553,6 +20629,7 @@ export {
20553
20629
  InputCodigo,
20554
20630
  InputColor,
20555
20631
  InputCpf,
20632
+ InputCpfCnpj,
20556
20633
  InputEstado,
20557
20634
  InputFinder$1 as InputFinder,
20558
20635
  InputFone,