lizaui 8.2.9 → 8.3.9
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/button/index.cjs.js +1 -1
- package/dist/button/index.es.js +1 -1
- package/dist/calendar/index.cjs.js +2 -2
- package/dist/calendar/index.cjs.js.map +1 -1
- package/dist/calendar/index.es.js +9 -9
- package/dist/checkbox/index.cjs.js +1 -1
- package/dist/checkbox/index.es.js +1 -1
- package/dist/chip/index.cjs.js +1 -1
- package/dist/chip/index.cjs.js.map +1 -1
- package/dist/chip/index.es.js +2 -2
- package/dist/chunks/bundle-mjs-2oQ8XDAz.js +2748 -0
- package/dist/chunks/bundle-mjs-2oQ8XDAz.js.map +1 -0
- package/dist/chunks/bundle-mjs-8z5d_e-8.js +2 -0
- package/dist/chunks/bundle-mjs-8z5d_e-8.js.map +1 -0
- package/dist/chunks/{button-CSuKvE1x.js → button-DJYse8Dw.js} +3 -3
- package/dist/chunks/{button-CSuKvE1x.js.map → button-DJYse8Dw.js.map} +1 -1
- package/dist/chunks/button-DaAJ3J_i.js +2 -0
- package/dist/chunks/{button-OdZ6El_t.js.map → button-DaAJ3J_i.js.map} +1 -1
- package/dist/chunks/{checkbox-BhW9i0pm.js → checkbox-BvvZL9H4.js} +3 -3
- package/dist/chunks/{checkbox-BhW9i0pm.js.map → checkbox-BvvZL9H4.js.map} +1 -1
- package/dist/chunks/checkbox-w969v4lK.js +2 -0
- package/dist/chunks/{checkbox-CWDPVAn2.js.map → checkbox-w969v4lK.js.map} +1 -1
- package/dist/chunks/clsx-C11secjj.js +2 -0
- package/dist/chunks/clsx-C11secjj.js.map +1 -0
- package/dist/chunks/clsx-OuTLNxxd.js +17 -0
- package/dist/chunks/clsx-OuTLNxxd.js.map +1 -0
- package/dist/chunks/{index-BOQuZ0gG.js → index-D29mdTf5.js} +2 -2
- package/dist/chunks/{index-BOQuZ0gG.js.map → index-D29mdTf5.js.map} +1 -1
- package/dist/chunks/index-nwdlcB7h.js +2 -0
- package/dist/chunks/{index-BxK4T-v8.js.map → index-nwdlcB7h.js.map} +1 -1
- package/dist/chunks/label-error-B8Rq-HGY.js +2 -0
- package/dist/chunks/{label-error-Ax74Uy3M.js.map → label-error-B8Rq-HGY.js.map} +1 -1
- package/dist/chunks/label-error-BOE4Qj5S.js +10 -0
- package/dist/chunks/{label-error-DGQqDKTV.js.map → label-error-BOE4Qj5S.js.map} +1 -1
- package/dist/chunks/{scroll-area-zt_z9PRo.js → scroll-area-1okMO4N6.js} +3 -3
- package/dist/chunks/{scroll-area-zt_z9PRo.js.map → scroll-area-1okMO4N6.js.map} +1 -1
- package/dist/chunks/{scroll-area-C8l3z7wv.js → scroll-area-BwqigcJy.js} +2 -2
- package/dist/chunks/{scroll-area-C8l3z7wv.js.map → scroll-area-BwqigcJy.js.map} +1 -1
- package/dist/chunks/{select-qaP_vaF3.js → select-B6a8A7js.js} +3 -3
- package/dist/chunks/{select-qaP_vaF3.js.map → select-B6a8A7js.js.map} +1 -1
- package/dist/chunks/{select-CC7ump6t.js → select-CFefk2Xz.js} +2 -2
- package/dist/chunks/{select-CC7ump6t.js.map → select-CFefk2Xz.js.map} +1 -1
- package/dist/chunks/{textarea-BIy5pTb5.js → textarea-BPsle-xc.js} +8 -8
- package/dist/chunks/{textarea-BIy5pTb5.js.map → textarea-BPsle-xc.js.map} +1 -1
- package/dist/chunks/{textarea-Cklud2kp.js → textarea-C2i9A3jn.js} +3 -3
- package/dist/chunks/{textarea-Cklud2kp.js.map → textarea-C2i9A3jn.js.map} +1 -1
- package/dist/chunks/tooltip-BPp8Maa7.js +2 -0
- package/dist/chunks/{tooltip-DGFz59KW.js.map → tooltip-BPp8Maa7.js.map} +1 -1
- package/dist/chunks/{tooltip-B-5G3VVC.js → tooltip-Bf9DqrJk.js} +3 -3
- package/dist/chunks/{tooltip-B-5G3VVC.js.map → tooltip-Bf9DqrJk.js.map} +1 -1
- package/dist/chunks/tv-CGkrzbji.js +2 -0
- package/dist/chunks/tv-CGkrzbji.js.map +1 -0
- package/dist/chunks/tv-DQO4decF.js +268 -0
- package/dist/chunks/tv-DQO4decF.js.map +1 -0
- package/dist/chunks/utils-CvyT6Z0O.js +9 -0
- package/dist/chunks/{utils-B6yFEsav.js.map → utils-CvyT6Z0O.js.map} +1 -1
- package/dist/chunks/utils-CxdrMFeI.js +2 -0
- package/dist/chunks/{utils-IjLH3w2e.js.map → utils-CxdrMFeI.js.map} +1 -1
- package/dist/chunks/v4-BysszJq8.js +31 -0
- package/dist/chunks/v4-BysszJq8.js.map +1 -0
- package/dist/chunks/v4-CqdK_b8Y.js +2 -0
- package/dist/chunks/v4-CqdK_b8Y.js.map +1 -0
- package/dist/divider/index.cjs.js +1 -1
- package/dist/divider/index.es.js +1 -1
- package/dist/modal/index.cjs.js +1 -1
- package/dist/modal/index.es.js +3 -3
- package/dist/pagination/index.cjs.js +1 -1
- package/dist/pagination/index.cjs.js.map +1 -1
- package/dist/pagination/index.es.js +18 -18
- package/dist/phone-input/index.cjs.js +1 -1
- package/dist/phone-input/index.cjs.js.map +1 -1
- package/dist/phone-input/index.es.js +56 -57
- package/dist/phone-input/index.es.js.map +1 -1
- package/dist/select-input/index.cjs.js +2 -2
- package/dist/select-input/index.cjs.js.map +1 -1
- package/dist/select-input/index.es.js +5 -5
- package/dist/table/index.cjs.js +1 -1
- package/dist/table/index.cjs.js.map +1 -1
- package/dist/table/index.es.js +9 -9
- package/dist/time-input/index.cjs.js +2 -2
- package/dist/time-input/index.cjs.js.map +1 -1
- package/dist/time-input/index.es.js +5 -5
- package/dist/tooltip/index.cjs.js +1 -1
- package/dist/tooltip/index.es.js +1 -1
- package/dist/ui/index.cjs.js +1 -1
- package/dist/ui/index.es.js +10 -10
- package/package.json +1 -1
- package/dist/chunks/button-OdZ6El_t.js +0 -2
- package/dist/chunks/checkbox-CWDPVAn2.js +0 -2
- package/dist/chunks/index-BxK4T-v8.js +0 -2
- package/dist/chunks/label-error-Ax74Uy3M.js +0 -2
- package/dist/chunks/label-error-DGQqDKTV.js +0 -10
- package/dist/chunks/tooltip-DGFz59KW.js +0 -2
- package/dist/chunks/tv-3Bk5oRI_.js +0 -39
- package/dist/chunks/tv-3Bk5oRI_.js.map +0 -1
- package/dist/chunks/tv-CLzaSzqw.js +0 -2
- package/dist/chunks/tv-CLzaSzqw.js.map +0 -1
- package/dist/chunks/utils-B6yFEsav.js +0 -9
- package/dist/chunks/utils-IjLH3w2e.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/components/pagination/pagination-item.tsx","../../src/components/pagination/function/index.ts","../../src/components/pagination/pagination.tsx","../../src/components/pagination/hook/use-pagination.tsx"],"sourcesContent":["import { twMerge } from \"tailwind-merge\";\nimport { type PaginationItemProps } from \"./interface/pagination.interface\";\nimport clsx from \"clsx\";\n\nexport const PaginationItem = ({ className, color = \"primary\", active, children, text, onClick }: PaginationItemProps) => {\n\tconst bgClass = clsx(\n\t\t{\n\t\t\t\"bg-primary\": color === \"primary\" && active,\n\t\t\t\"bg-success\": color === \"success\" && active,\n\t\t\t\"bg-danger\": color === \"danger\" && active,\n\t\t\t\"bg-warning\": color === \"warning\" && active,\n\t\t\t\"bg-default\": color === \"default\" && active,\n \"dark:hover:bg-default-200 dark:hover:text-default-800\": !active,\n\t\t},\n\t);\n\tconst colorClass = twMerge(\n\t\tclsx(\"text-sm\", {\n\t\t\t\"group-hover:text-primary-500 dark:group-hover:text-default-800\": color === \"primary\" && !active,\n\t\t\t\"group-hover:text-success-500 dark:group-hover:text-default-800\": color === \"success\" && !active,\n\t\t\t\"group-hover:text-danger-500 dark:group-hover:text-default-800\": color === \"danger\" && !active,\n\t\t\t\"group-hover:text-warning-500 dark:group-hover:text-default-800\": color === \"warning\" && !active,\n\t\t\t\"group-hover:text-default-500 dark:group-hover:text-default-800\": color === \"default\" && !active,\n\n\t\t\t\"text-default-foreground\": active && color === \"default\",\n\t\t\t\"text-primary-foreground\": active && color === \"primary\",\n\t\t\t\"text-success-foreground\": active && color === \"success\",\n\t\t\t\"text-danger-foreground\": active && color === \"danger\",\n\t\t\t\"text-warning-foreground\": active && color === \"warning\",\n\t\t}),\n\t);\n\n\treturn (\n\t\t<div className={twMerge(\"w-[33px] h-[32px] flex items-center justify-center group \", bgClass, className)} onClick={onClick}>\n\t\t\t{children || <p className={colorClass}>{text}</p>}\n\t\t</div>\n\t);\n};\n","import { type PaginationValueProps } from \"../interface/pagination-share.interface\";\n\nexport const FormatPagePagination = ({\n\tpage,\n\ttotal,\n\tsiblings = 1,\n}: PaginationValueProps) => {\n\tconst totalPageNoInArray = 7 + siblings;\n\n\tif (totalPageNoInArray >= total) {\n\t\treturn Array.from({ length: total }, (_, i) => i + 1);\n\t}\n\n\tconst leftSiblingsIndex = Math.max(page - siblings, 1);\n\tconst rightSiblingsIndex = Math.min(page + siblings, total);\n\n\tconst showLeftDots = leftSiblingsIndex > 2;\n\tconst showRightDots = rightSiblingsIndex < total - 2;\n\n\tif (!showLeftDots && showRightDots) {\n\t\tconst leftItemsCount = 3 + 2 * siblings;\n\t\tconst leftRange = Array.from({ length: leftItemsCount }, (_, i) => i + 1);\n\t\treturn [...leftRange, \"...\", total];\n\t} else if (showLeftDots && !showRightDots) {\n\t\tconst rightItemsCount = 3 + 2 * siblings;\n\t\tconst rightRange = Array.from(\n\t\t\t{ length: rightItemsCount },\n\t\t\t(_, i) => total - rightItemsCount + i + 1\n\t\t);\n\t\treturn [1, \"...\", ...rightRange];\n\t} else {\n\t\tconst middleRange = Array.from(\n\t\t\t{ length: rightSiblingsIndex - leftSiblingsIndex + 1 },\n\t\t\t(_, i) => leftSiblingsIndex + i\n\t\t);\n\t\treturn [1, \"...\", ...middleRange, \"...\", total];\n\t}\n};\n\nexport const FormatLimitPagination = (data: number[]) => {\n\treturn data.map((el) => {\n\t\treturn {\n\t\t\tid: el,\n\t\t\tname: el,\n\t\t};\n\t});\n};\n","import { twMerge } from \"tailwind-merge\";\nimport { IoIosArrowBack } from \"react-icons/io\";\nimport { PaginationItem } from \"./pagination-item\";\nimport { type PaginationProps } from \"./interface/pagination.interface\";\nimport { FormatLimitPagination, FormatPagePagination } from \"./function\";\nimport clsx from \"clsx\";\nimport { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from \"../ui\";\n\nexport const Pagination = ({\n\tclassName,\n\tcolor = \"primary\",\n\n\ttotal,\n\tlimit = 20,\n\tpage = 1,\n\tsiblings = 1,\n\tisLimitSelect = true,\n\tdataLimit = [10, 15, 20, 50, 100, 200],\n\tonChange,\n\ttranslate = {\n\t\tselectLimit: \"Limites\",\n\t\trowPerPage: \"Filas por pagina\",\n\t\tof: \"de\",\n\t},\n}: PaginationProps) => {\n\tconst totalPagination = Math.ceil(total / limit);\n\n\tconst dataPageFormat = FormatPagePagination({\n\t\tlimit,\n\t\tpage,\n\t\tsiblings,\n\t\ttotal: totalPagination,\n\t});\n\tconst dataLimitFormat = FormatLimitPagination(dataLimit);\n\n\tconst handleChange = (value: number | string | null) => {\n\t\tif (value === \"...\") return;\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: Number(value),\n\t\t\t});\n\t};\n\n\tconst handlePrev = () => {\n\t\tif (page === 1) return;\n\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: page - 1,\n\t\t\t});\n\t};\n\n\tconst handleNext = () => {\n\t\tif (page === totalPagination || totalPagination === 0) return;\n\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: page + 1,\n\t\t\t});\n\t};\n\n\tconst handleChangeSelect = (value: string) => {\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tpage,\n\t\t\t\tlimit: value ? Number(value) : 20,\n\t\t\t});\n\t};\n\n\treturn (\n\t\t<div className={twMerge(\"flex justify-between gap-x-2 items-center\", className)}>\n\t\t\t{isLimitSelect ? (\n\t\t\t\t<div className=\"flex items-center gap-x-2.5\">\n\t\t\t\t\t<div>\n\t\t\t\t\t\t<span className=\"text-sm text-default-500\">{translate?.rowPerPage || \"Filas por pagina\"}:</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<Select value={limit?.toString()} onValueChange={handleChangeSelect}>\n\t\t\t\t\t\t<SelectTrigger className=\"min-w-20\">\n\t\t\t\t\t\t\t<SelectValue placeholder=\"Select limit\" />\n\t\t\t\t\t\t</SelectTrigger>\n\t\t\t\t\t\t<SelectContent>\n\t\t\t\t\t\t\t<SelectGroup>\n\t\t\t\t\t\t\t\t<SelectLabel>{translate?.selectLimit || \"Limites\"}</SelectLabel>\n\t\t\t\t\t\t\t\t{dataLimitFormat.map((item) => (\n\t\t\t\t\t\t\t\t\t<SelectItem key={item.id} value={item.id?.toString()}>\n\t\t\t\t\t\t\t\t\t\t{item.name}\n\t\t\t\t\t\t\t\t\t</SelectItem>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</SelectGroup>\n\t\t\t\t\t\t</SelectContent>\n\t\t\t\t\t</Select>\n\n\t\t\t\t\t<div className=\"text-sm text-default-500\">\n\t\t\t\t\t\t<span className=\"text-default-500\">{`${page} - ${limit}`}</span> {translate?.of || \"de\"}{\" \"}\n\t\t\t\t\t\t<span className=\"text-default-500\">{total}</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\n\t\t\t{totalPagination > 1 && (\n\t\t\t\t<div className=\"flex flex-nowrap h-fit max-w-fit relative items-center overflow-visible gap-0 border border-divider rounded-lg cursor-pointer dark:bg-default-100\">\n\t\t\t\t\t<PaginationItem className={clsx(page === 1 && \"cursor-no-drop\", \"rounded-tl-lg rounded-bl-lg \")} onClick={handlePrev}>\n\t\t\t\t\t\t<IoIosArrowBack className={twMerge(\"fill-default-500\", clsx(page === 1 && \"fill-default-300\"))} />\n\t\t\t\t\t</PaginationItem>\n\n\t\t\t\t\t{dataPageFormat.map((el, i) => (\n\t\t\t\t\t\t<PaginationItem\n\t\t\t\t\t\t\tkey={i}\n\t\t\t\t\t\t\ttext={el}\n\t\t\t\t\t\t\tactive={page === el}\n\t\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\t\tonClick={() => handleChange(el)}\n\t\t\t\t\t\t\tclassName=\"border-l border-divider \"\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\n\t\t\t\t\t<PaginationItem\n\t\t\t\t\t\tclassName={clsx(\n\t\t\t\t\t\t\t\"border-l border-divider rounded-tr-lg rounded-br-lg \",\n\t\t\t\t\t\t\t(page === totalPagination || totalPagination === 0) && \"cursor-no-drop\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tonClick={handleNext}\n\t\t\t\t\t>\n\t\t\t\t\t\t<IoIosArrowBack\n\t\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\t\"fill-default-500 transform rotate-180 \",\n\t\t\t\t\t\t\t\tclsx((page === totalPagination || totalPagination === 0) && \"fill-default-300\"),\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PaginationItem>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n","import { useCallback, useState } from \"react\";\nimport { type PaginationHookProps, type UsePaginationProps } from \"../interface/pagination.interface\";\nimport { type PaginationSetValueProps } from \"../interface/pagination-share.interface\";\n\nexport const usePagination = ({ initialPage = 1, initialLimit = 20 }: UsePaginationProps): PaginationHookProps => {\n\tconst [pageCurrent, setPageCurrent] = useState<number>(initialPage);\n\tconst [limitCurrent, setLimitCurrent] = useState<number>(initialLimit);\n\n\tconst handleSetPagination = useCallback(\n\t\t({ page, limit }: PaginationSetValueProps) => {\n\t\t\tif (page !== pageCurrent) setPageCurrent(page);\n\t\t\tif (limit !== limitCurrent) setLimitCurrent(limit);\n\t\t},\n\t\t[limitCurrent, pageCurrent],\n\t);\n\n\treturn {\n\t\thandleSetPagination,\n\t\tpage: pageCurrent,\n\t\tlimit: limitCurrent,\n\t};\n};\n"],"names":["PaginationItem","className","color","active","children","text","onClick","bgClass","clsx","colorClass","twMerge","jsx","FormatPagePagination","page","total","siblings","_","i","leftSiblingsIndex","rightSiblingsIndex","showLeftDots","showRightDots","leftItemsCount","rightItemsCount","FormatLimitPagination","data","el","Pagination","limit","isLimitSelect","dataLimit","onChange","translate","totalPagination","dataPageFormat","dataLimitFormat","handleChange","value","handlePrev","handleNext","handleChangeSelect","jsxs","Select","SelectTrigger","SelectValue","SelectContent","SelectGroup","SelectLabel","item","SelectItem","IoIosArrowBack","usePagination","initialPage","initialLimit","pageCurrent","setPageCurrent","useState","limitCurrent","setLimitCurrent","useCallback"],"mappings":"iXAIO,MAAMA,EAAiB,CAAC,CAAE,UAAAC,EAAW,MAAAC,EAAQ,UAAW,OAAAC,EAAQ,SAAAC,EAAU,KAAAC,EAAM,QAAAC,KAAmC,CACzH,MAAMC,EAAUC,EACf,CACC,aAAcN,IAAU,WAAaC,EACrC,aAAcD,IAAU,WAAaC,EACrC,YAAaD,IAAU,UAAYC,EACnC,aAAcD,IAAU,WAAaC,EACrC,aAAcD,IAAU,WAAaC,EAC5B,wDAA0D,CAACA,CAAA,CACrE,EAEKM,EAAaC,EAAAA,QAClBF,EAAK,UAAW,CACf,iEAAkEN,IAAU,WAAa,CAACC,EAC1F,iEAAkED,IAAU,WAAa,CAACC,EAC1F,gEAAiED,IAAU,UAAY,CAACC,EACxF,iEAAkED,IAAU,WAAa,CAACC,EAC1F,iEAAkED,IAAU,WAAa,CAACC,EAE1F,0BAA2BA,GAAUD,IAAU,UAC/C,0BAA2BC,GAAUD,IAAU,UAC/C,0BAA2BC,GAAUD,IAAU,UAC/C,yBAA0BC,GAAUD,IAAU,SAC9C,0BAA2BC,GAAUD,IAAU,SAAA,CAC/C,CAAA,EAGF,OACCS,EAAAA,kBAAAA,IAAC,MAAA,CAAI,UAAWD,EAAAA,QAAQ,4DAA6DH,EAASN,CAAS,EAAG,QAAAK,EACxG,YAAYK,EAAAA,kBAAAA,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AA,CACD,CAAA,CACD,CAAA,EAEF,CAEF,ECtIakB,EAAgB,CAAC,CAAE,YAAAC,EAAc,EAAG,aAAAC,EAAe,MAAkD,CACjH,KAAM,CAACC,EAAaC,CAAc,EAAIC,EAAAA,SAAiBJ,CAAW,EAC5D,CAACK,EAAcC,CAAe,EAAIF,EAAAA,SAAiBH,CAAY,EAUrE,MAAO,CACN,oBAT2BM,EAAAA,YAC3B,CAAC,CAAE,KAAA9C,EAAM,MAAAe,KAAqC,CACzCf,IAASyC,GAAaC,EAAe1C,CAAI,EACzCe,IAAU6B,GAAcC,EAAgB9B,CAAK,CAClD,EACA,CAAC6B,EAAcH,CAAW,CAAA,EAK1B,KAAMA,EACN,MAAOG,CAAA,CAET"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/components/pagination/pagination-item.tsx","../../src/components/pagination/function/index.ts","../../src/components/pagination/pagination.tsx","../../src/components/pagination/hook/use-pagination.tsx"],"sourcesContent":["import { twMerge } from \"tailwind-merge\";\nimport { type PaginationItemProps } from \"./interface/pagination.interface\";\nimport clsx from \"clsx\";\n\nexport const PaginationItem = ({ className, color = \"primary\", active, children, text, onClick }: PaginationItemProps) => {\n\tconst bgClass = clsx(\n\t\t{\n\t\t\t\"bg-primary\": color === \"primary\" && active,\n\t\t\t\"bg-success\": color === \"success\" && active,\n\t\t\t\"bg-danger\": color === \"danger\" && active,\n\t\t\t\"bg-warning\": color === \"warning\" && active,\n\t\t\t\"bg-default\": color === \"default\" && active,\n \"dark:hover:bg-default-200 dark:hover:text-default-800\": !active,\n\t\t},\n\t);\n\tconst colorClass = twMerge(\n\t\tclsx(\"text-sm\", {\n\t\t\t\"group-hover:text-primary-500 dark:group-hover:text-default-800\": color === \"primary\" && !active,\n\t\t\t\"group-hover:text-success-500 dark:group-hover:text-default-800\": color === \"success\" && !active,\n\t\t\t\"group-hover:text-danger-500 dark:group-hover:text-default-800\": color === \"danger\" && !active,\n\t\t\t\"group-hover:text-warning-500 dark:group-hover:text-default-800\": color === \"warning\" && !active,\n\t\t\t\"group-hover:text-default-500 dark:group-hover:text-default-800\": color === \"default\" && !active,\n\n\t\t\t\"text-default-foreground\": active && color === \"default\",\n\t\t\t\"text-primary-foreground\": active && color === \"primary\",\n\t\t\t\"text-success-foreground\": active && color === \"success\",\n\t\t\t\"text-danger-foreground\": active && color === \"danger\",\n\t\t\t\"text-warning-foreground\": active && color === \"warning\",\n\t\t}),\n\t);\n\n\treturn (\n\t\t<div className={twMerge(\"w-[33px] h-[32px] flex items-center justify-center group \", bgClass, className)} onClick={onClick}>\n\t\t\t{children || <p className={colorClass}>{text}</p>}\n\t\t</div>\n\t);\n};\n","import { type PaginationValueProps } from \"../interface/pagination-share.interface\";\n\nexport const FormatPagePagination = ({\n\tpage,\n\ttotal,\n\tsiblings = 1,\n}: PaginationValueProps) => {\n\tconst totalPageNoInArray = 7 + siblings;\n\n\tif (totalPageNoInArray >= total) {\n\t\treturn Array.from({ length: total }, (_, i) => i + 1);\n\t}\n\n\tconst leftSiblingsIndex = Math.max(page - siblings, 1);\n\tconst rightSiblingsIndex = Math.min(page + siblings, total);\n\n\tconst showLeftDots = leftSiblingsIndex > 2;\n\tconst showRightDots = rightSiblingsIndex < total - 2;\n\n\tif (!showLeftDots && showRightDots) {\n\t\tconst leftItemsCount = 3 + 2 * siblings;\n\t\tconst leftRange = Array.from({ length: leftItemsCount }, (_, i) => i + 1);\n\t\treturn [...leftRange, \"...\", total];\n\t} else if (showLeftDots && !showRightDots) {\n\t\tconst rightItemsCount = 3 + 2 * siblings;\n\t\tconst rightRange = Array.from(\n\t\t\t{ length: rightItemsCount },\n\t\t\t(_, i) => total - rightItemsCount + i + 1\n\t\t);\n\t\treturn [1, \"...\", ...rightRange];\n\t} else {\n\t\tconst middleRange = Array.from(\n\t\t\t{ length: rightSiblingsIndex - leftSiblingsIndex + 1 },\n\t\t\t(_, i) => leftSiblingsIndex + i\n\t\t);\n\t\treturn [1, \"...\", ...middleRange, \"...\", total];\n\t}\n};\n\nexport const FormatLimitPagination = (data: number[]) => {\n\treturn data.map((el) => {\n\t\treturn {\n\t\t\tid: el,\n\t\t\tname: el,\n\t\t};\n\t});\n};\n","import { twMerge } from \"tailwind-merge\";\nimport { IoIosArrowBack } from \"react-icons/io\";\nimport { PaginationItem } from \"./pagination-item\";\nimport { type PaginationProps } from \"./interface/pagination.interface\";\nimport { FormatLimitPagination, FormatPagePagination } from \"./function\";\nimport clsx from \"clsx\";\nimport { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from \"../ui\";\n\nexport const Pagination = ({\n\tclassName,\n\tcolor = \"primary\",\n\n\ttotal,\n\tlimit = 20,\n\tpage = 1,\n\tsiblings = 1,\n\tisLimitSelect = true,\n\tdataLimit = [10, 15, 20, 50, 100, 200],\n\tonChange,\n\ttranslate = {\n\t\tselectLimit: \"Limites\",\n\t\trowPerPage: \"Filas por pagina\",\n\t\tof: \"de\",\n\t},\n}: PaginationProps) => {\n\tconst totalPagination = Math.ceil(total / limit);\n\n\tconst dataPageFormat = FormatPagePagination({\n\t\tlimit,\n\t\tpage,\n\t\tsiblings,\n\t\ttotal: totalPagination,\n\t});\n\tconst dataLimitFormat = FormatLimitPagination(dataLimit);\n\n\tconst handleChange = (value: number | string | null) => {\n\t\tif (value === \"...\") return;\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: Number(value),\n\t\t\t});\n\t};\n\n\tconst handlePrev = () => {\n\t\tif (page === 1) return;\n\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: page - 1,\n\t\t\t});\n\t};\n\n\tconst handleNext = () => {\n\t\tif (page === totalPagination || totalPagination === 0) return;\n\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tlimit,\n\t\t\t\tpage: page + 1,\n\t\t\t});\n\t};\n\n\tconst handleChangeSelect = (value: string) => {\n\t\tif (onChange)\n\t\t\tonChange({\n\t\t\t\tpage,\n\t\t\t\tlimit: value ? Number(value) : 20,\n\t\t\t});\n\t};\n\n\treturn (\n\t\t<div className={twMerge(\"flex justify-between gap-x-2 items-center\", className)}>\n\t\t\t{isLimitSelect ? (\n\t\t\t\t<div className=\"flex items-center gap-x-2.5\">\n\t\t\t\t\t<div>\n\t\t\t\t\t\t<span className=\"text-sm text-default-500\">{translate?.rowPerPage || \"Filas por pagina\"}:</span>\n\t\t\t\t\t</div>\n\n\t\t\t\t\t<Select value={limit?.toString()} onValueChange={handleChangeSelect}>\n\t\t\t\t\t\t<SelectTrigger className=\"min-w-20\">\n\t\t\t\t\t\t\t<SelectValue placeholder=\"Select limit\" />\n\t\t\t\t\t\t</SelectTrigger>\n\t\t\t\t\t\t<SelectContent>\n\t\t\t\t\t\t\t<SelectGroup>\n\t\t\t\t\t\t\t\t<SelectLabel>{translate?.selectLimit || \"Limites\"}</SelectLabel>\n\t\t\t\t\t\t\t\t{dataLimitFormat.map((item) => (\n\t\t\t\t\t\t\t\t\t<SelectItem key={item.id} value={item.id?.toString()}>\n\t\t\t\t\t\t\t\t\t\t{item.name}\n\t\t\t\t\t\t\t\t\t</SelectItem>\n\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t</SelectGroup>\n\t\t\t\t\t\t</SelectContent>\n\t\t\t\t\t</Select>\n\n\t\t\t\t\t<div className=\"text-sm text-default-500\">\n\t\t\t\t\t\t<span className=\"text-default-500\">{`${page} - ${limit}`}</span> {translate?.of || \"de\"}{\" \"}\n\t\t\t\t\t\t<span className=\"text-default-500\">{total}</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t) : null}\n\n\t\t\t{totalPagination > 1 && (\n\t\t\t\t<div className=\"flex flex-nowrap h-fit max-w-fit relative items-center overflow-visible gap-0 border border-divider rounded-lg cursor-pointer dark:bg-default-100\">\n\t\t\t\t\t<PaginationItem className={clsx(page === 1 && \"cursor-no-drop\", \"rounded-tl-lg rounded-bl-lg \")} onClick={handlePrev}>\n\t\t\t\t\t\t<IoIosArrowBack className={twMerge(\"fill-default-500\", clsx(page === 1 && \"fill-default-300\"))} />\n\t\t\t\t\t</PaginationItem>\n\n\t\t\t\t\t{dataPageFormat.map((el, i) => (\n\t\t\t\t\t\t<PaginationItem\n\t\t\t\t\t\t\tkey={i}\n\t\t\t\t\t\t\ttext={el}\n\t\t\t\t\t\t\tactive={page === el}\n\t\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\t\tonClick={() => handleChange(el)}\n\t\t\t\t\t\t\tclassName=\"border-l border-divider \"\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\n\t\t\t\t\t<PaginationItem\n\t\t\t\t\t\tclassName={clsx(\n\t\t\t\t\t\t\t\"border-l border-divider rounded-tr-lg rounded-br-lg \",\n\t\t\t\t\t\t\t(page === totalPagination || totalPagination === 0) && \"cursor-no-drop\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tonClick={handleNext}\n\t\t\t\t\t>\n\t\t\t\t\t\t<IoIosArrowBack\n\t\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\t\"fill-default-500 transform rotate-180 \",\n\t\t\t\t\t\t\t\tclsx((page === totalPagination || totalPagination === 0) && \"fill-default-300\"),\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PaginationItem>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n","import { useCallback, useState } from \"react\";\nimport { type PaginationHookProps, type UsePaginationProps } from \"../interface/pagination.interface\";\nimport { type PaginationSetValueProps } from \"../interface/pagination-share.interface\";\n\nexport const usePagination = ({ initialPage = 1, initialLimit = 20 }: UsePaginationProps): PaginationHookProps => {\n\tconst [pageCurrent, setPageCurrent] = useState<number>(initialPage);\n\tconst [limitCurrent, setLimitCurrent] = useState<number>(initialLimit);\n\n\tconst handleSetPagination = useCallback(\n\t\t({ page, limit }: PaginationSetValueProps) => {\n\t\t\tif (page !== pageCurrent) setPageCurrent(page);\n\t\t\tif (limit !== limitCurrent) setLimitCurrent(limit);\n\t\t},\n\t\t[limitCurrent, pageCurrent],\n\t);\n\n\treturn {\n\t\thandleSetPagination,\n\t\tpage: pageCurrent,\n\t\tlimit: limitCurrent,\n\t};\n};\n"],"names":["PaginationItem","className","color","active","children","text","onClick","bgClass","clsx","colorClass","twMerge","jsx","FormatPagePagination","page","total","siblings","_","i","leftSiblingsIndex","rightSiblingsIndex","showLeftDots","showRightDots","leftItemsCount","rightItemsCount","FormatLimitPagination","data","el","Pagination","limit","isLimitSelect","dataLimit","onChange","translate","totalPagination","dataPageFormat","dataLimitFormat","handleChange","value","handlePrev","handleNext","handleChangeSelect","jsxs","Select","SelectTrigger","SelectValue","SelectContent","SelectGroup","SelectLabel","item","SelectItem","IoIosArrowBack","usePagination","initialPage","initialLimit","pageCurrent","setPageCurrent","useState","limitCurrent","setLimitCurrent","useCallback"],"mappings":"yZAIO,MAAMA,EAAiB,CAAC,CAAE,UAAAC,EAAW,MAAAC,EAAQ,UAAW,OAAAC,EAAQ,SAAAC,EAAU,KAAAC,EAAM,QAAAC,KAAmC,CACzH,MAAMC,EAAUC,EAAAA,KACf,CACC,aAAcN,IAAU,WAAaC,EACrC,aAAcD,IAAU,WAAaC,EACrC,YAAaD,IAAU,UAAYC,EACnC,aAAcD,IAAU,WAAaC,EACrC,aAAcD,IAAU,WAAaC,EAC5B,wDAA0D,CAACA,CAAA,CACrE,EAEKM,EAAaC,EAAAA,QAClBF,EAAAA,KAAK,UAAW,CACf,iEAAkEN,IAAU,WAAa,CAACC,EAC1F,iEAAkED,IAAU,WAAa,CAACC,EAC1F,gEAAiED,IAAU,UAAY,CAACC,EACxF,iEAAkED,IAAU,WAAa,CAACC,EAC1F,iEAAkED,IAAU,WAAa,CAACC,EAE1F,0BAA2BA,GAAUD,IAAU,UAC/C,0BAA2BC,GAAUD,IAAU,UAC/C,0BAA2BC,GAAUD,IAAU,UAC/C,yBAA0BC,GAAUD,IAAU,SAC9C,0BAA2B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B,IAAM,gBAAA,EAExD,QAASM,EAET,SAAA5B,EAAAA,kBAAAA,IAACuC,EAAAA,eAAA,CACA,UAAWxC,EAAAA,QACV,yCACAF,EAAAA,MAAMK,IAASoB,GAAmBA,IAAoB,IAAM,kBAAkB,CAAA,CAC/E,CAAA,CACD,CAAA,CACD,CAAA,CACD,CAAA,EAEF,CAEF,ECtIakB,EAAgB,CAAC,CAAE,YAAAC,EAAc,EAAG,aAAAC,EAAe,MAAkD,CACjH,KAAM,CAACC,EAAaC,CAAc,EAAIC,EAAAA,SAAiBJ,CAAW,EAC5D,CAACK,EAAcC,CAAe,EAAIF,EAAAA,SAAiBH,CAAY,EAUrE,MAAO,CACN,oBAT2BM,EAAAA,YAC3B,CAAC,CAAE,KAAA9C,EAAM,MAAAe,KAAqC,CACzCf,IAASyC,GAAaC,EAAe1C,CAAI,EACzCe,IAAU6B,GAAcC,EAAgB9B,CAAK,CAClD,EACA,CAAC6B,EAAcH,CAAW,CAAA,EAK1B,KAAMA,EACN,MAAOG,CAAA,CAET"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { j as s } from "../chunks/jsx-runtime-Cl_4eDuT.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as x } from "../chunks/bundle-mjs-2oQ8XDAz.js";
|
|
3
3
|
import { I as p } from "../chunks/index-DK44x_HP.js";
|
|
4
4
|
import { useState as j, useCallback as k } from "react";
|
|
5
|
-
import f from "clsx";
|
|
6
|
-
import "../chunks/textarea-
|
|
7
|
-
import { S as v, a as I, b as C, c as L, d as R, e as A, f as F } from "../chunks/select-
|
|
8
|
-
import "../chunks/button-
|
|
5
|
+
import { c as f } from "../chunks/clsx-OuTLNxxd.js";
|
|
6
|
+
import "../chunks/textarea-BPsle-xc.js";
|
|
7
|
+
import { S as v, a as I, b as C, c as L, d as R, e as A, f as F } from "../chunks/select-B6a8A7js.js";
|
|
8
|
+
import "../chunks/button-DJYse8Dw.js";
|
|
9
9
|
const h = ({ className: o, color: e = "primary", active: r, children: i, text: t, onClick: u }) => {
|
|
10
|
-
const
|
|
10
|
+
const m = f(
|
|
11
11
|
{
|
|
12
12
|
"bg-primary": e === "primary" && r,
|
|
13
13
|
"bg-success": e === "success" && r,
|
|
@@ -30,19 +30,19 @@ const h = ({ className: o, color: e = "primary", active: r, children: i, text: t
|
|
|
30
30
|
"text-warning-foreground": r && e === "warning"
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
-
return /* @__PURE__ */ s.jsx("div", { className: x("w-[33px] h-[32px] flex items-center justify-center group ",
|
|
33
|
+
return /* @__PURE__ */ s.jsx("div", { className: x("w-[33px] h-[32px] flex items-center justify-center group ", m, o), onClick: u, children: i || /* @__PURE__ */ s.jsx("p", { className: l, children: t }) });
|
|
34
34
|
}, M = ({
|
|
35
35
|
page: o,
|
|
36
36
|
total: e,
|
|
37
37
|
siblings: r = 1
|
|
38
38
|
}) => {
|
|
39
39
|
if (7 + r >= e)
|
|
40
|
-
return Array.from({ length: e }, (a,
|
|
41
|
-
const t = Math.max(o - r, 1), u = Math.min(o + r, e),
|
|
42
|
-
if (!
|
|
40
|
+
return Array.from({ length: e }, (a, c) => c + 1);
|
|
41
|
+
const t = Math.max(o - r, 1), u = Math.min(o + r, e), m = t > 2, l = u < e - 2;
|
|
42
|
+
if (!m && l) {
|
|
43
43
|
const a = 3 + 2 * r;
|
|
44
44
|
return [...Array.from({ length: a }, (d, g) => g + 1), "...", e];
|
|
45
|
-
} else if (
|
|
45
|
+
} else if (m && !l) {
|
|
46
46
|
const a = 3 + 2 * r;
|
|
47
47
|
return [1, "...", ...Array.from(
|
|
48
48
|
{ length: a },
|
|
@@ -51,7 +51,7 @@ const h = ({ className: o, color: e = "primary", active: r, children: i, text: t
|
|
|
51
51
|
} else
|
|
52
52
|
return [1, "...", ...Array.from(
|
|
53
53
|
{ length: u - t + 1 },
|
|
54
|
-
(
|
|
54
|
+
(c, d) => t + d
|
|
55
55
|
), "...", e];
|
|
56
56
|
}, _ = (o) => o.map((e) => ({
|
|
57
57
|
id: e,
|
|
@@ -63,10 +63,10 @@ const h = ({ className: o, color: e = "primary", active: r, children: i, text: t
|
|
|
63
63
|
limit: i = 20,
|
|
64
64
|
page: t = 1,
|
|
65
65
|
siblings: u = 1,
|
|
66
|
-
isLimitSelect:
|
|
66
|
+
isLimitSelect: m = !0,
|
|
67
67
|
dataLimit: l = [10, 15, 20, 50, 100, 200],
|
|
68
68
|
onChange: a,
|
|
69
|
-
translate:
|
|
69
|
+
translate: c = {
|
|
70
70
|
selectLimit: "Limites",
|
|
71
71
|
rowPerPage: "Filas por pagina",
|
|
72
72
|
of: "de"
|
|
@@ -98,22 +98,22 @@ const h = ({ className: o, color: e = "primary", active: r, children: i, text: t
|
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
return /* @__PURE__ */ s.jsxs("div", { className: x("flex justify-between gap-x-2 items-center", o), children: [
|
|
101
|
-
|
|
101
|
+
m ? /* @__PURE__ */ s.jsxs("div", { className: "flex items-center gap-x-2.5", children: [
|
|
102
102
|
/* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("span", { className: "text-sm text-default-500", children: [
|
|
103
|
-
|
|
103
|
+
c?.rowPerPage || "Filas por pagina",
|
|
104
104
|
":"
|
|
105
105
|
] }) }),
|
|
106
106
|
/* @__PURE__ */ s.jsxs(v, { value: i?.toString(), onValueChange: S, children: [
|
|
107
107
|
/* @__PURE__ */ s.jsx(I, { className: "min-w-20", children: /* @__PURE__ */ s.jsx(C, { placeholder: "Select limit" }) }),
|
|
108
108
|
/* @__PURE__ */ s.jsx(L, { children: /* @__PURE__ */ s.jsxs(R, { children: [
|
|
109
|
-
/* @__PURE__ */ s.jsx(A, { children:
|
|
109
|
+
/* @__PURE__ */ s.jsx(A, { children: c?.selectLimit || "Limites" }),
|
|
110
110
|
b.map((n) => /* @__PURE__ */ s.jsx(F, { value: n.id?.toString(), children: n.name }, n.id))
|
|
111
111
|
] }) })
|
|
112
112
|
] }),
|
|
113
113
|
/* @__PURE__ */ s.jsxs("div", { className: "text-sm text-default-500", children: [
|
|
114
114
|
/* @__PURE__ */ s.jsx("span", { className: "text-default-500", children: `${t} - ${i}` }),
|
|
115
115
|
" ",
|
|
116
|
-
|
|
116
|
+
c?.of || "de",
|
|
117
117
|
" ",
|
|
118
118
|
/* @__PURE__ */ s.jsx("span", { className: "text-default-500", children: r })
|
|
119
119
|
] })
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../chunks/jsx-runtime-BjzqJBtL.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../chunks/jsx-runtime-BjzqJBtL.js"),o=require("react"),a=require("libphonenumber-js"),p=require("../chunks/bundle-mjs-8z5d_e-8.js"),re=require("../chunks/utils-CxdrMFeI.js");require("../chunks/textarea-C2i9A3jn.js");const ae=require("../chunks/label-error-B8Rq-HGY.js"),z=require("../chunks/scroll-area-BwqigcJy.js");require("../chunks/button-DaAJ3J_i.js");const E=require("framer-motion"),F=require("../chunks/index-BydcKEwP.js"),C={PE:{name:"Perú",flag:"🇵🇪"},US:{name:"Estados Unidos",flag:"🇺🇸"},MX:{name:"México",flag:"🇲🇽"},AR:{name:"Argentina",flag:"🇦🇷"},CO:{name:"Colombia",flag:"🇨🇴"},CL:{name:"Chile",flag:"🇨🇱"},BR:{name:"Brasil",flag:"🇧🇷"},BO:{name:"Bolivia",flag:"🇧🇴"},VE:{name:"Venezuela",flag:"🇻🇪"}},ie=({id:Y,name:$,label:q="Teléfono",placeholder:U="Ingrese un número de teléfono",required:J=!1,className:W="",classNameContainer:X="",onCountryChange:G,onPhoneChange:I,touched:R,onBlur:H,error:x,value:u,defaultCountry:g="PE",disabled:h=!1})=>{const[r,M]=o.useState({code:g,name:C[g].name,flag:C[g].flag,callingCode:`+${a.getCountryCallingCode(g)}`}),[j,y]=o.useState(!1),[b,d]=o.useState(""),[K,i]=o.useState(""),[Q,m]=o.useState(!1),[l,Z]=o.useState([]),[f,P]=o.useState(""),[_,N]=o.useState([]),S=o.useRef(null),T=o.useRef(null),A=o.useRef(null),ee=o.useId(),L=Y||ee,O=u!==void 0;o.useEffect(()=>{const e=Object.keys(C).map(n=>{const s=C[n];return{code:n,name:s.name,flag:s.flag,callingCode:`+${a.getCountryCallingCode(n)}`}});Z(e),N(e)},[]),o.useEffect(()=>{const e=n=>{S.current&&!S.current.contains(n.target)&&y(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),o.useEffect(()=>{if(!O||l.length===0)return;if(u===""||u==null){d(""),i(""),m(!1);return}const e=String(u);let n=l.find(s=>e.startsWith(s.callingCode));if(n||(n=r),n){r.code!==n.code&&M(n);const s=e.replace(n.callingCode,"").replace(/[^\d]/g,"");d(s);const c=new a.AsYouType(n.code).input(s);i(c);const v=a.isValidPhoneNumber(e);m(v)}else d(""),i(""),m(!1)},[u,l,O,r]);const te=(e,n)=>{const s=e.replace(/[^\d]/g,"");if(n?.nativeEvent instanceof InputEvent&&n.nativeEvent.inputType==="deleteContentBackward"&&s.length<4){d(s),i(s);return}const c=new a.AsYouType(r.code).input(s);d(s),i(c);const v=r.callingCode+s,D=a.isValidPhoneNumber(v);m(D),I?.(v,D)},se=e=>{if(M(e),y(!1),P(""),b){const s=new a.AsYouType(e.code).input(b);i(s);const w=e.callingCode+b,c=a.isValidPhoneNumber(w);m(c),I?.(w,c)}G?.(e),setTimeout(()=>T.current?.focus(),100)},ne=()=>{y(!j),j||setTimeout(()=>A.current?.focus(),100)};o.useEffect(()=>{if(!f.trim())N(l);else{const e=f.toLowerCase(),n=l.filter(s=>s.name.toLowerCase().includes(e)||s.callingCode.includes(f)||s.code.toLowerCase().includes(e));N(n)}},[f,l]);const oe=R,k=x,B=oe&&k,V=!h&&!!x&&R;return t.jsxRuntimeExports.jsxs("div",{className:p.twMerge("w-full relative flex flex-col",X),children:[q&&t.jsxRuntimeExports.jsxs("label",{htmlFor:L,className:re.cn("form-control-label block font-normal text-sm text-foreground mb-1",{"text-danger":B}),children:[q," ",J&&t.jsxRuntimeExports.jsx("span",{className:"text-danger",children:"*"})]}),t.jsxRuntimeExports.jsxs("div",{className:p.twMerge("flex w-full min-w-0 transition-[color,box-shadow] outline-none rounded-md h-input-default","bg-white border border-input","disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",B?"border-danger aria-invalid:ring-danger/20":"focus-within:border-primary focus-within:ring-primary/20","focus-within:ring-[3px]"),"aria-invalid":V?"true":"false",children:[t.jsxRuntimeExports.jsxs("div",{className:"relative",ref:S,children:[t.jsxRuntimeExports.jsxs("button",{type:"button",onClick:ne,className:p.twMerge("flex items-center gap-2 px-3 border-r border-input h-input-default","hover:bg-muted/20 focus:outline-none rounded-l-md"),children:[t.jsxRuntimeExports.jsx("span",{className:"text-lg",children:r.flag}),t.jsxRuntimeExports.jsx("span",{className:"text-sm font-medium text-foreground",children:r.callingCode}),t.jsxRuntimeExports.jsx(F.ChevronDown,{className:`w-4 h-4 text-muted-foreground transition-transform ${j?"rotate-180":""}`})]}),t.jsxRuntimeExports.jsx(E.AnimatePresence,{children:j&&t.jsxRuntimeExports.jsx(E.LazyMotion,{features:E.domAnimation,children:t.jsxRuntimeExports.jsxs(E.m.div,{initial:{opacity:0,y:-8,scale:.98},animate:{opacity:1,y:0,scale:1,transition:{type:"spring",stiffness:420,damping:28}},exit:{opacity:0,y:-6,scale:.98,transition:{duration:.15,ease:"easeOut"}},style:{transformOrigin:"top center"},className:"absolute top-full left-0 z-50 w-60 mt-1 bg-white border border-input rounded-md shadow-lg max-h-60 overflow-hidden",children:[t.jsxRuntimeExports.jsx("div",{className:"sticky top-0 bg-white border-b border-input p-3",children:t.jsxRuntimeExports.jsxs("div",{className:"relative",children:[t.jsxRuntimeExports.jsx(z.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),t.jsxRuntimeExports.jsx("input",{ref:A,type:"text",value:f,onChange:e=>P(e.target.value),placeholder:"Buscar país o código",className:"w-full pl-10 pr-3 py-2 h-9 border border-input rounded-md text-sm focus:outline-none focus:border-primary focus:ring-[3px] focus:ring-primary/20"})]})}),t.jsxRuntimeExports.jsx(z.ScrollArea,{className:"max-h-48 overflow-y-auto pb-5",children:_.map(e=>t.jsxRuntimeExports.jsxs("button",{type:"button",onClick:()=>se(e),className:p.twMerge("w-full flex items-center gap-3 px-3 py-1 text-sm transition",r.code===e.code?"bg-primary/5 border-l-2 border-primary":"hover:bg-muted/20"),children:[t.jsxRuntimeExports.jsx("span",{className:"text-lg",children:e.flag}),t.jsxRuntimeExports.jsx("span",{className:"flex-1 text-left",children:e.name}),t.jsxRuntimeExports.jsx("span",{className:"text-muted-foreground",children:e.callingCode}),r.code===e.code&&t.jsxRuntimeExports.jsx(F.Check,{className:"w-4 h-4 text-primary"})]},e.code))})]},"country-dropdown")})})]}),t.jsxRuntimeExports.jsx("input",{ref:T,id:L,type:"tel",name:$,value:K,onChange:e=>te(e.target.value,e),onBlur:H,placeholder:U,disabled:h,...h?{}:{"aria-invalid":V},className:p.twMerge("flex-1 px-3 py-1 h-input-default border-0 rounded-r-md bg-transparent focus:outline-none text-foreground text-sm",W),autoComplete:"tel"})]}),!h&&x&&R&&t.jsxRuntimeExports.jsx(ae.LabelError,{text:x||k||""})]})};exports.PhoneInput=ie;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/components/phone-input/phone-input.tsx"],"sourcesContent":["import type React from \"react\";\nimport { useState, useEffect, useRef, useId } from \"react\";\nimport { getCountryCallingCode, AsYouType, isValidPhoneNumber } from \"libphonenumber-js\";\nimport { ChevronDown, Check, Search } from \"lucide-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { cn } from \"@/lib/utils\";\nimport { LabelError, ScrollArea } from \"../ui\";\nimport { AnimatePresence } from \"framer-motion\";\nimport { LazyMotion, m, domAnimation } from \"framer-motion\";\n\nconst countryData = {\n\tPE: { name: \"Perú\", flag: \"🇵🇪\" },\n\tUS: { name: \"Estados Unidos\", flag: \"🇺🇸\" },\n\tMX: { name: \"México\", flag: \"🇲🇽\" },\n\tAR: { name: \"Argentina\", flag: \"🇦🇷\" },\n\tCO: { name: \"Colombia\", flag: \"🇨🇴\" },\n\tCL: { name: \"Chile\", flag: \"🇨🇱\" },\n\tBR: { name: \"Brasil\", flag: \"🇧🇷\" },\n\tBO: { name: \"Bolivia\", flag: \"🇧🇴\" },\n\tVE: { name: \"Venezuela\", flag: \"🇻🇪\" },\n};\n\ninterface Country {\n\tcode: string;\n\tname: string;\n\tflag: string;\n\tcallingCode: string;\n}\n\ninterface PhoneInputProps {\n\tid?: string;\n\tname: string;\n\tlabel?: string;\n\tplaceholder?: string;\n\trequired?: boolean;\n\tclassName?: string;\n\tonCountryChange?: (country: Country) => void;\n\tonPhoneChange?: (phone: string, isValid: boolean) => void;\n\ttouched?: boolean;\n\tvalues?: any;\n\tonBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;\n\terror?: string;\n\tvalue?: string; // para standalone\n\tdefaultCountry?: string;\n\tdisabled?: boolean;\n\tclassNameContainer?: string;\n}\n\nexport const PhoneInput: React.FC<PhoneInputProps> = ({\n\tid,\n\tname,\n\tlabel = \"Teléfono\",\n\tplaceholder = \"Ingrese un número de teléfono\",\n\trequired = false,\n\tclassName = \"\",\n\tclassNameContainer = \"\",\n\tonCountryChange,\n\tonPhoneChange,\n\ttouched: externalTouched,\n\tonBlur: externalOnBlur,\n\terror: externalError,\n\tvalue: externalValue,\n\tdefaultCountry = \"PE\",\n\tdisabled = false,\n}) => {\n\tconst [selectedCountry, setSelectedCountry] = useState<Country>({\n\t\tcode: defaultCountry,\n\t\tname: countryData[defaultCountry as keyof typeof countryData].name,\n\t\tflag: countryData[defaultCountry as keyof typeof countryData].flag,\n\t\tcallingCode: `+${getCountryCallingCode(defaultCountry as keyof typeof countryData)}`,\n\t});\n\n\tconst [isDropdownOpen, setIsDropdownOpen] = useState(false);\n\tconst [phoneValue, setPhoneValue] = useState(\"\");\n\tconst [formattedValue, setFormattedValue] = useState(\"\");\n\tconst [isValid, setIsValid] = useState(false);\n\tconst [countries, setCountries] = useState<Country[]>([]);\n\tconst [searchTerm, setSearchTerm] = useState(\"\");\n\tconst [filteredCountries, setFilteredCountries] = useState<Country[]>([]);\n\n\tconst dropdownRef = useRef<HTMLDivElement>(null);\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst searchInputRef = useRef<HTMLInputElement>(null);\n\n\tconst inputId = useId();\n\tconst resolvedId = id || inputId;\n\tconst isControlled = externalValue !== undefined;\n\n\t// Inicializar países en el orden definido en countryData\n\tuseEffect(() => {\n\t\tconst availableCountries = Object.keys(countryData).map((countryCode) => {\n\t\t\tconst data = countryData[countryCode as keyof typeof countryData];\n\t\t\treturn {\n\t\t\t\tcode: countryCode,\n\t\t\t\tname: data.name,\n\t\t\t\tflag: data.flag,\n\t\t\t\tcallingCode: `+${getCountryCallingCode(countryCode as keyof typeof countryData)}`,\n\t\t\t};\n\t\t});\n\t\tsetCountries(availableCountries);\n\t\tsetFilteredCountries(availableCountries);\n\t}, []);\n\n\t// Manejo de click fuera para cerrar dropdown\n\tuseEffect(() => {\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {\n\t\t\t\tsetIsDropdownOpen(false);\n\t\t\t}\n\t\t};\n\t\tdocument.addEventListener(\"mousedown\", handleClickOutside);\n\t\treturn () => document.removeEventListener(\"mousedown\", handleClickOutside);\n\t}, []);\n\n\t// Sincronizar externalValue con estados internos (incluye reset con \"\")\n\tuseEffect(() => {\n\t\tif (!isControlled || countries.length === 0) return;\n\n\t\t// Si el valor externo es vacío o null, limpiar estados\n\t\tif (externalValue === \"\" || externalValue == null) {\n\t\t\tsetPhoneValue(\"\");\n\t\t\tsetFormattedValue(\"\");\n\t\t\tsetIsValid(false);\n\t\t\treturn;\n\t\t}\n\n\t\tconst value = String(externalValue);\n\t\tlet country = countries.find((c) => value.startsWith(c.callingCode));\n\n\t\t// Si no se detecta país por código, mantener el seleccionado actual\n\t\tif (!country) {\n\t\t\tcountry = selectedCountry;\n\t\t}\n\n\t\tif (country) {\n\t\t\t// Actualizar país si cambió\n\t\t\tif (selectedCountry.code !== country.code) {\n\t\t\t\tsetSelectedCountry(country);\n\t\t\t}\n\n\t\t\tconst raw = value.replace(country.callingCode, \"\").replace(/[^\\d]/g, \"\");\n\t\t\tsetPhoneValue(raw);\n\n\t\t\tconst formatter = new AsYouType(country.code as keyof typeof countryData);\n\t\t\tconst formatted = formatter.input(raw);\n\t\t\tsetFormattedValue(formatted);\n\n\t\t\tconst valid = isValidPhoneNumber(value);\n\t\t\tsetIsValid(valid);\n\t\t} else {\n\t\t\t// Fallback: no país detectado, limpiar formato pero conservar value crudo\n\t\t\tsetPhoneValue(\"\");\n\t\t\tsetFormattedValue(\"\");\n\t\t\tsetIsValid(false);\n\t\t}\n\t}, [externalValue, countries, isControlled, selectedCountry]);\n\n\t// Formatear número al escribir\n\tconst handlePhoneChange = (value: string, event?: React.ChangeEvent<HTMLInputElement>) => {\n\t\tconst cleanValue = value.replace(/[^\\d]/g, \"\");\n\n\t\tif (event?.nativeEvent instanceof InputEvent && event.nativeEvent.inputType === \"deleteContentBackward\" && cleanValue.length < 4) {\n\t\t\tsetPhoneValue(cleanValue);\n\t\t\tsetFormattedValue(cleanValue); // mostrar sin formato\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = new AsYouType(selectedCountry.code as keyof typeof countryData);\n\t\tconst formatted = formatter.input(cleanValue);\n\n\t\tsetPhoneValue(cleanValue);\n\t\tsetFormattedValue(formatted);\n\n\t\tconst fullNumber = selectedCountry.callingCode + cleanValue;\n\t\tconst valid = isValidPhoneNumber(fullNumber);\n\t\tsetIsValid(valid);\n\n\t\tonPhoneChange?.(fullNumber, valid);\n\t};\n\n\t// Seleccionar país\n\tconst handleCountrySelect = (country: Country) => {\n\t\tsetSelectedCountry(country);\n\t\tsetIsDropdownOpen(false);\n\t\tsetSearchTerm(\"\");\n\n\t\tif (phoneValue) {\n\t\t\tconst formatter = new AsYouType(country.code as keyof typeof countryData);\n\t\t\tconst formatted = formatter.input(phoneValue);\n\t\t\tsetFormattedValue(formatted);\n\n\t\t\tconst fullNumber = country.callingCode + phoneValue;\n\t\t\tconst valid = isValidPhoneNumber(fullNumber);\n\t\t\tsetIsValid(valid);\n\n\t\t\tonPhoneChange?.(fullNumber, valid);\n\t\t}\n\n\t\tonCountryChange?.(country);\n\t\tsetTimeout(() => inputRef.current?.focus(), 100);\n\t};\n\n\tconst handleDropdownToggle = () => {\n\t\tsetIsDropdownOpen(!isDropdownOpen);\n\t\tif (!isDropdownOpen) {\n\t\t\tsetTimeout(() => searchInputRef.current?.focus(), 100);\n\t\t}\n\t};\n\n\t// Filtrar países en búsqueda\n\tuseEffect(() => {\n\t\tif (!searchTerm.trim()) {\n\t\t\tsetFilteredCountries(countries);\n\t\t} else {\n\t\t\tconst searchLower = searchTerm.toLowerCase();\n\t\t\tconst filtered = countries.filter(\n\t\t\t\t(country) =>\n\t\t\t\t\tcountry.name.toLowerCase().includes(searchLower) ||\n\t\t\t\t\tcountry.callingCode.includes(searchTerm) ||\n\t\t\t\t\tcountry.code.toLowerCase().includes(searchLower),\n\t\t\t);\n\t\t\tsetFilteredCountries(filtered);\n\t\t}\n\t}, [searchTerm, countries]);\n\n\tconst isTouched = externalTouched;\n\tconst currentError = externalError;\n\tconst hasError = isTouched && currentError;\n\n\tconst isInvalid = !disabled && !!externalError && externalTouched;\n\n\treturn (\n\t\t<div className={twMerge(\"w-full relative flex flex-col\", classNameContainer)}>\n\t\t\t{label && (\n\t\t\t\t<label\n\t\t\t\t\thtmlFor={resolvedId}\n\t\t\t\t\tclassName={cn(\"form-control-label block font-normal text-sm text-foreground mb-1\", {\n\t\t\t\t\t\t\"text-danger\": hasError,\n\t\t\t\t\t})}\n\t\t\t\t>\n\t\t\t\t\t{label} {required && <span className=\"text-danger\">*</span>}\n\t\t\t\t</label>\n\t\t\t)}\n\n\t\t\t<div\n\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\"flex w-full min-w-0 transition-[color,box-shadow] outline-none rounded-md h-input-default\",\n\t\t\t\t\t\"bg-white border border-input\",\n\t\t\t\t\t\"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50\",\n\t\t\t\t\thasError\n\t\t\t\t\t\t? \"border-danger aria-invalid:ring-danger/20\"\n\t\t\t\t\t\t: isValid && phoneValue\n\t\t\t\t\t\t? \"focus-within:border-primary focus-within:ring-primary/20\"\n\t\t\t\t\t\t: \"focus-within:border-primary focus-within:ring-primary/20\",\n\t\t\t\t\t\"focus-within:ring-[3px]\",\n\t\t\t\t)}\n\t\t\t\taria-invalid={isInvalid ? \"true\" : \"false\"}\n\t\t\t>\n\t\t\t\t{/* Country selector */}\n\t\t\t\t<div className=\"relative\" ref={dropdownRef}>\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tonClick={handleDropdownToggle}\n\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\"flex items-center gap-2 px-3 border-r border-input h-input-default\",\n\t\t\t\t\t\t\t\"hover:bg-muted/20 focus:outline-none rounded-l-md\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"text-lg\">{selectedCountry.flag}</span>\n\t\t\t\t\t\t<span className=\"text-sm font-medium text-foreground\">{selectedCountry.callingCode}</span>\n\t\t\t\t\t\t<ChevronDown className={`w-4 h-4 text-muted-foreground transition-transform ${isDropdownOpen ? \"rotate-180\" : \"\"}`} />\n\t\t\t\t\t</button>\n\n\t\t\t\t\t<AnimatePresence>\n\t\t\t\t\t\t{isDropdownOpen && (\n\t\t\t\t\t\t\t<LazyMotion features={domAnimation}>\n\t\t\t\t\t\t\t\t<m.div\n\t\t\t\t\t\t\t\t\tkey=\"country-dropdown\"\n\t\t\t\t\t\t\t\t\tinitial={{ opacity: 0, y: -8, scale: 0.98 }}\n\t\t\t\t\t\t\t\t\tanimate={{ opacity: 1, y: 0, scale: 1, transition: { type: \"spring\", stiffness: 420, damping: 28 } }}\n\t\t\t\t\t\t\t\t\texit={{ opacity: 0, y: -6, scale: 0.98, transition: { duration: 0.15, ease: \"easeOut\" } }}\n\t\t\t\t\t\t\t\t\tstyle={{ transformOrigin: \"top center\" }}\n\t\t\t\t\t\t\t\t\tclassName=\"absolute top-full left-0 z-50 w-60 mt-1 bg-white border border-input rounded-md shadow-lg max-h-60 overflow-hidden\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<div className=\"sticky top-0 bg-white border-b border-input p-3\">\n\t\t\t\t\t\t\t\t\t\t<div className=\"relative\">\n\t\t\t\t\t\t\t\t\t\t\t<Search className=\"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground\" />\n\t\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\t\tref={searchInputRef}\n\t\t\t\t\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\t\t\t\t\tvalue={searchTerm}\n\t\t\t\t\t\t\t\t\t\t\t\tonChange={(e) => setSearchTerm(e.target.value)}\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholder=\"Buscar país o código\"\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"w-full pl-10 pr-3 py-2 h-9 border border-input rounded-md text-sm focus:outline-none focus:border-primary focus:ring-[3px] focus:ring-primary/20\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t<ScrollArea className=\"max-h-48 overflow-y-auto pb-5\">\n\t\t\t\t\t\t\t\t\t\t{filteredCountries.map((country) => (\n\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\tkey={country.code}\n\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => handleCountrySelect(country)}\n\t\t\t\t\t\t\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"w-full flex items-center gap-3 px-3 py-1 text-sm transition\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tselectedCountry.code === country.code\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? \"bg-primary/5 border-l-2 border-primary\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: \"hover:bg-muted/20\",\n\t\t\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"text-lg\">{country.flag}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"flex-1 text-left\">{country.name}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"text-muted-foreground\">{country.callingCode}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t{selectedCountry.code === country.code && <Check className=\"w-4 h-4 text-primary\" />}\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</ScrollArea>\n\t\t\t\t\t\t\t\t</m.div>\n\t\t\t\t\t\t\t</LazyMotion>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</AnimatePresence>\n\t\t\t\t</div>\n\n\t\t\t\t{/* Phone input */}\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\tid={resolvedId}\n\t\t\t\t\ttype=\"tel\"\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={formattedValue}\n\t\t\t\t\tonChange={(e) => handlePhoneChange(e.target.value, e)}\n\t\t\t\t\tonBlur={externalOnBlur}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t{...(!disabled ? { \"aria-invalid\": isInvalid } : {})}\n\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\"flex-1 px-3 py-1 h-input-default border-0 rounded-r-md bg-transparent focus:outline-none text-foreground text-sm\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\tautoComplete=\"tel\"\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t{!disabled && externalError && externalTouched && <LabelError text={externalError || currentError || \"\"} />}\n\t\t</div>\n\t);\n};\n"],"names":["countryData","PhoneInput","id","name","label","placeholder","required","className","classNameContainer","onCountryChange","onPhoneChange","externalTouched","externalOnBlur","externalError","externalValue","defaultCountry","disabled","selectedCountry","setSelectedCountry","useState","getCountryCallingCode","isDropdownOpen","setIsDropdownOpen","phoneValue","setPhoneValue","formattedValue","setFormattedValue","isValid","setIsValid","countries","setCountries","searchTerm","setSearchTerm","filteredCountries","setFilteredCountries","dropdownRef","useRef","inputRef","searchInputRef","inputId","useId","resolvedId","isControlled","useEffect","availableCountries","countryCode","data","handleClickOutside","event","value","country","c","raw","formatted","AsYouType","valid","isValidPhoneNumber","handlePhoneChange","cleanValue","fullNumber","handleCountrySelect","handleDropdownToggle","searchLower","filtered","isTouched","currentError","hasError","isInvalid","twMerge","jsxs","cn","jsx","ChevronDown","AnimatePresence","LazyMotion","domAnimation","m","Search","ScrollArea","Check","LabelError"],"mappings":"ohBAUMA,EAAc,CACnB,GAAI,CAAE,KAAM,OAAQ,KAAM,MAAA,EAC1B,GAAI,CAAE,KAAM,iBAAkB,KAAM,MAAA,EACpC,GAAI,CAAE,KAAM,SAAU,KAAM,MAAA,EAC5B,GAAI,CAAE,KAAM,YAAa,KAAM,MAAA,EAC/B,GAAI,CAAE,KAAM,WAAY,KAAM,MAAA,EAC9B,GAAI,CAAE,KAAM,QAAS,KAAM,MAAA,EAC3B,GAAI,CAAE,KAAM,SAAU,KAAM,MAAA,EAC5B,GAAI,CA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AAQ,IAAA,CAed,CAAA,CACF,CAAA,CAAA,EAvCI,kBAAA,EAyCN,CAAA,CAEF,CAAA,EACD,EAGAqB,EAAAA,kBAAAA,IAAC,QAAA,CACA,IAAKlC,EACL,GAAII,EACJ,KAAK,MACL,KAAAtC,EACA,MAAOsB,EACP,SAAW,GAAMgC,GAAkB,EAAE,OAAO,MAAO,CAAC,EACpD,OAAQ7C,EACR,YAAAP,EACA,SAAAW,EACC,GAAKA,EAA2C,CAAA,EAAhC,CAAE,eAAgBmD,CAAA,EACnC,UAAWC,EAAAA,QACV,mHACA7D,CAAA,EAED,aAAa,KAAA,CAAA,CACd,CAAA,CAAA,EAGA,CAACS,GAAYH,GAAiBF,2BAAoBqE,cAAA,CAAW,KAAMnE,GAAiBoD,GAAgB,EAAA,CAAI,CAAA,EAC1G,CAEF"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/components/phone-input/phone-input.tsx"],"sourcesContent":["import type React from \"react\";\nimport { useState, useEffect, useRef, useId } from \"react\";\nimport { getCountryCallingCode, AsYouType, isValidPhoneNumber } from \"libphonenumber-js\";\nimport { ChevronDown, Check, Search } from \"lucide-react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { cn } from \"@/lib/utils\";\nimport { LabelError, ScrollArea } from \"../ui\";\nimport { AnimatePresence } from \"framer-motion\";\nimport { LazyMotion, m, domAnimation } from \"framer-motion\";\n\nconst countryData = {\n\tPE: { name: \"Perú\", flag: \"🇵🇪\" },\n\tUS: { name: \"Estados Unidos\", flag: \"🇺🇸\" },\n\tMX: { name: \"México\", flag: \"🇲🇽\" },\n\tAR: { name: \"Argentina\", flag: \"🇦🇷\" },\n\tCO: { name: \"Colombia\", flag: \"🇨🇴\" },\n\tCL: { name: \"Chile\", flag: \"🇨🇱\" },\n\tBR: { name: \"Brasil\", flag: \"🇧🇷\" },\n\tBO: { name: \"Bolivia\", flag: \"🇧🇴\" },\n\tVE: { name: \"Venezuela\", flag: \"🇻🇪\" },\n};\n\ninterface Country {\n\tcode: string;\n\tname: string;\n\tflag: string;\n\tcallingCode: string;\n}\n\ninterface PhoneInputProps {\n\tid?: string;\n\tname: string;\n\tlabel?: string;\n\tplaceholder?: string;\n\trequired?: boolean;\n\tclassName?: string;\n\tonCountryChange?: (country: Country) => void;\n\tonPhoneChange?: (phone: string, isValid: boolean) => void;\n\ttouched?: boolean;\n\tvalues?: any;\n\tonBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;\n\terror?: string;\n\tvalue?: string; // para standalone\n\tdefaultCountry?: string;\n\tdisabled?: boolean;\n\tclassNameContainer?: string;\n}\n\nexport const PhoneInput: React.FC<PhoneInputProps> = ({\n\tid,\n\tname,\n\tlabel = \"Teléfono\",\n\tplaceholder = \"Ingrese un número de teléfono\",\n\trequired = false,\n\tclassName = \"\",\n\tclassNameContainer = \"\",\n\tonCountryChange,\n\tonPhoneChange,\n\ttouched: externalTouched,\n\tonBlur: externalOnBlur,\n\terror: externalError,\n\tvalue: externalValue,\n\tdefaultCountry = \"PE\",\n\tdisabled = false,\n}) => {\n\tconst [selectedCountry, setSelectedCountry] = useState<Country>({\n\t\tcode: defaultCountry,\n\t\tname: countryData[defaultCountry as keyof typeof countryData].name,\n\t\tflag: countryData[defaultCountry as keyof typeof countryData].flag,\n\t\tcallingCode: `+${getCountryCallingCode(defaultCountry as keyof typeof countryData)}`,\n\t});\n\n\tconst [isDropdownOpen, setIsDropdownOpen] = useState(false);\n\tconst [phoneValue, setPhoneValue] = useState(\"\");\n\tconst [formattedValue, setFormattedValue] = useState(\"\");\n\tconst [isValid, setIsValid] = useState(false);\n\tconst [countries, setCountries] = useState<Country[]>([]);\n\tconst [searchTerm, setSearchTerm] = useState(\"\");\n\tconst [filteredCountries, setFilteredCountries] = useState<Country[]>([]);\n\n\tconst dropdownRef = useRef<HTMLDivElement>(null);\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\tconst searchInputRef = useRef<HTMLInputElement>(null);\n\n\tconst inputId = useId();\n\tconst resolvedId = id || inputId;\n\tconst isControlled = externalValue !== undefined;\n\n\t// Inicializar países en el orden definido en countryData\n\tuseEffect(() => {\n\t\tconst availableCountries = Object.keys(countryData).map((countryCode) => {\n\t\t\tconst data = countryData[countryCode as keyof typeof countryData];\n\t\t\treturn {\n\t\t\t\tcode: countryCode,\n\t\t\t\tname: data.name,\n\t\t\t\tflag: data.flag,\n\t\t\t\tcallingCode: `+${getCountryCallingCode(countryCode as keyof typeof countryData)}`,\n\t\t\t};\n\t\t});\n\t\tsetCountries(availableCountries);\n\t\tsetFilteredCountries(availableCountries);\n\t}, []);\n\n\t// Manejo de click fuera para cerrar dropdown\n\tuseEffect(() => {\n\t\tconst handleClickOutside = (event: MouseEvent) => {\n\t\t\tif (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {\n\t\t\t\tsetIsDropdownOpen(false);\n\t\t\t}\n\t\t};\n\t\tdocument.addEventListener(\"mousedown\", handleClickOutside);\n\t\treturn () => document.removeEventListener(\"mousedown\", handleClickOutside);\n\t}, []);\n\n\t// Sincronizar externalValue con estados internos (incluye reset con \"\")\n\tuseEffect(() => {\n\t\tif (!isControlled || countries.length === 0) return;\n\n\t\t// Si el valor externo es vacío o null, limpiar estados\n\t\tif (externalValue === \"\" || externalValue == null) {\n\t\t\tsetPhoneValue(\"\");\n\t\t\tsetFormattedValue(\"\");\n\t\t\tsetIsValid(false);\n\t\t\treturn;\n\t\t}\n\n\t\tconst value = String(externalValue);\n\t\tlet country = countries.find((c) => value.startsWith(c.callingCode));\n\n\t\t// Si no se detecta país por código, mantener el seleccionado actual\n\t\tif (!country) {\n\t\t\tcountry = selectedCountry;\n\t\t}\n\n\t\tif (country) {\n\t\t\t// Actualizar país si cambió\n\t\t\tif (selectedCountry.code !== country.code) {\n\t\t\t\tsetSelectedCountry(country);\n\t\t\t}\n\n\t\t\tconst raw = value.replace(country.callingCode, \"\").replace(/[^\\d]/g, \"\");\n\t\t\tsetPhoneValue(raw);\n\n\t\t\tconst formatter = new AsYouType(country.code as keyof typeof countryData);\n\t\t\tconst formatted = formatter.input(raw);\n\t\t\tsetFormattedValue(formatted);\n\n\t\t\tconst valid = isValidPhoneNumber(value);\n\t\t\tsetIsValid(valid);\n\t\t} else {\n\t\t\t// Fallback: no país detectado, limpiar formato pero conservar value crudo\n\t\t\tsetPhoneValue(\"\");\n\t\t\tsetFormattedValue(\"\");\n\t\t\tsetIsValid(false);\n\t\t}\n\t}, [externalValue, countries, isControlled, selectedCountry]);\n\n\t// Formatear número al escribir\n\tconst handlePhoneChange = (value: string, event?: React.ChangeEvent<HTMLInputElement>) => {\n\t\tconst cleanValue = value.replace(/[^\\d]/g, \"\");\n\n\t\tif (event?.nativeEvent instanceof InputEvent && event.nativeEvent.inputType === \"deleteContentBackward\" && cleanValue.length < 4) {\n\t\t\tsetPhoneValue(cleanValue);\n\t\t\tsetFormattedValue(cleanValue); // mostrar sin formato\n\t\t\treturn;\n\t\t}\n\t\tconst formatter = new AsYouType(selectedCountry.code as keyof typeof countryData);\n\t\tconst formatted = formatter.input(cleanValue);\n\n\t\tsetPhoneValue(cleanValue);\n\t\tsetFormattedValue(formatted);\n\n\t\tconst fullNumber = selectedCountry.callingCode + cleanValue;\n\t\tconst valid = isValidPhoneNumber(fullNumber);\n\t\tsetIsValid(valid);\n\n\t\tonPhoneChange?.(fullNumber, valid);\n\t};\n\n\t// Seleccionar país\n\tconst handleCountrySelect = (country: Country) => {\n\t\tsetSelectedCountry(country);\n\t\tsetIsDropdownOpen(false);\n\t\tsetSearchTerm(\"\");\n\n\t\tif (phoneValue) {\n\t\t\tconst formatter = new AsYouType(country.code as keyof typeof countryData);\n\t\t\tconst formatted = formatter.input(phoneValue);\n\t\t\tsetFormattedValue(formatted);\n\n\t\t\tconst fullNumber = country.callingCode + phoneValue;\n\t\t\tconst valid = isValidPhoneNumber(fullNumber);\n\t\t\tsetIsValid(valid);\n\n\t\t\tonPhoneChange?.(fullNumber, valid);\n\t\t}\n\n\t\tonCountryChange?.(country);\n\t\tsetTimeout(() => inputRef.current?.focus(), 100);\n\t};\n\n\tconst handleDropdownToggle = () => {\n\t\tsetIsDropdownOpen(!isDropdownOpen);\n\t\tif (!isDropdownOpen) {\n\t\t\tsetTimeout(() => searchInputRef.current?.focus(), 100);\n\t\t}\n\t};\n\n\t// Filtrar países en búsqueda\n\tuseEffect(() => {\n\t\tif (!searchTerm.trim()) {\n\t\t\tsetFilteredCountries(countries);\n\t\t} else {\n\t\t\tconst searchLower = searchTerm.toLowerCase();\n\t\t\tconst filtered = countries.filter(\n\t\t\t\t(country) =>\n\t\t\t\t\tcountry.name.toLowerCase().includes(searchLower) ||\n\t\t\t\t\tcountry.callingCode.includes(searchTerm) ||\n\t\t\t\t\tcountry.code.toLowerCase().includes(searchLower),\n\t\t\t);\n\t\t\tsetFilteredCountries(filtered);\n\t\t}\n\t}, [searchTerm, countries]);\n\n\tconst isTouched = externalTouched;\n\tconst currentError = externalError;\n\tconst hasError = isTouched && currentError;\n\n\tconst isInvalid = !disabled && !!externalError && externalTouched;\n\n\treturn (\n\t\t<div className={twMerge(\"w-full relative flex flex-col\", classNameContainer)}>\n\t\t\t{label && (\n\t\t\t\t<label\n\t\t\t\t\thtmlFor={resolvedId}\n\t\t\t\t\tclassName={cn(\"form-control-label block font-normal text-sm text-foreground mb-1\", {\n\t\t\t\t\t\t\"text-danger\": hasError,\n\t\t\t\t\t})}\n\t\t\t\t>\n\t\t\t\t\t{label} {required && <span className=\"text-danger\">*</span>}\n\t\t\t\t</label>\n\t\t\t)}\n\n\t\t\t<div\n\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\"flex w-full min-w-0 transition-[color,box-shadow] outline-none rounded-md h-input-default\",\n\t\t\t\t\t\"bg-white border border-input\",\n\t\t\t\t\t\"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50\",\n\t\t\t\t\thasError\n\t\t\t\t\t\t? \"border-danger aria-invalid:ring-danger/20\"\n\t\t\t\t\t\t: isValid && phoneValue\n\t\t\t\t\t\t? \"focus-within:border-primary focus-within:ring-primary/20\"\n\t\t\t\t\t\t: \"focus-within:border-primary focus-within:ring-primary/20\",\n\t\t\t\t\t\"focus-within:ring-[3px]\",\n\t\t\t\t)}\n\t\t\t\taria-invalid={isInvalid ? \"true\" : \"false\"}\n\t\t\t>\n\t\t\t\t{/* Country selector */}\n\t\t\t\t<div className=\"relative\" ref={dropdownRef}>\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tonClick={handleDropdownToggle}\n\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\"flex items-center gap-2 px-3 border-r border-input h-input-default\",\n\t\t\t\t\t\t\t\"hover:bg-muted/20 focus:outline-none rounded-l-md\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"text-lg\">{selectedCountry.flag}</span>\n\t\t\t\t\t\t<span className=\"text-sm font-medium text-foreground\">{selectedCountry.callingCode}</span>\n\t\t\t\t\t\t<ChevronDown className={`w-4 h-4 text-muted-foreground transition-transform ${isDropdownOpen ? \"rotate-180\" : \"\"}`} />\n\t\t\t\t\t</button>\n\n\t\t\t\t\t<AnimatePresence>\n\t\t\t\t\t\t{isDropdownOpen && (\n\t\t\t\t\t\t\t<LazyMotion features={domAnimation}>\n\t\t\t\t\t\t\t\t<m.div\n\t\t\t\t\t\t\t\t\tkey=\"country-dropdown\"\n\t\t\t\t\t\t\t\t\tinitial={{ opacity: 0, y: -8, scale: 0.98 }}\n\t\t\t\t\t\t\t\t\tanimate={{ opacity: 1, y: 0, scale: 1, transition: { type: \"spring\", stiffness: 420, damping: 28 } }}\n\t\t\t\t\t\t\t\t\texit={{ opacity: 0, y: -6, scale: 0.98, transition: { duration: 0.15, ease: \"easeOut\" } }}\n\t\t\t\t\t\t\t\t\tstyle={{ transformOrigin: \"top center\" }}\n\t\t\t\t\t\t\t\t\tclassName=\"absolute top-full left-0 z-50 w-60 mt-1 bg-white border border-input rounded-md shadow-lg max-h-60 overflow-hidden\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<div className=\"sticky top-0 bg-white border-b border-input p-3\">\n\t\t\t\t\t\t\t\t\t\t<div className=\"relative\">\n\t\t\t\t\t\t\t\t\t\t\t<Search className=\"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground\" />\n\t\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\t\tref={searchInputRef}\n\t\t\t\t\t\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\t\t\t\t\t\tvalue={searchTerm}\n\t\t\t\t\t\t\t\t\t\t\t\tonChange={(e) => setSearchTerm(e.target.value)}\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholder=\"Buscar país o código\"\n\t\t\t\t\t\t\t\t\t\t\t\tclassName=\"w-full pl-10 pr-3 py-2 h-9 border border-input rounded-md text-sm focus:outline-none focus:border-primary focus:ring-[3px] focus:ring-primary/20\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t<ScrollArea className=\"max-h-48 overflow-y-auto pb-5\">\n\t\t\t\t\t\t\t\t\t\t{filteredCountries.map((country) => (\n\t\t\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\t\t\tkey={country.code}\n\t\t\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => handleCountrySelect(country)}\n\t\t\t\t\t\t\t\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"w-full flex items-center gap-3 px-3 py-1 text-sm transition\",\n\t\t\t\t\t\t\t\t\t\t\t\t\tselectedCountry.code === country.code\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? \"bg-primary/5 border-l-2 border-primary\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: \"hover:bg-muted/20\",\n\t\t\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"text-lg\">{country.flag}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"flex-1 text-left\">{country.name}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t<span className=\"text-muted-foreground\">{country.callingCode}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t{selectedCountry.code === country.code && <Check className=\"w-4 h-4 text-primary\" />}\n\t\t\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</ScrollArea>\n\t\t\t\t\t\t\t\t</m.div>\n\t\t\t\t\t\t\t</LazyMotion>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</AnimatePresence>\n\t\t\t\t</div>\n\n\t\t\t\t{/* Phone input */}\n\t\t\t\t<input\n\t\t\t\t\tref={inputRef}\n\t\t\t\t\tid={resolvedId}\n\t\t\t\t\ttype=\"tel\"\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={formattedValue}\n\t\t\t\t\tonChange={(e) => handlePhoneChange(e.target.value, e)}\n\t\t\t\t\tonBlur={externalOnBlur}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t{...(!disabled ? { \"aria-invalid\": isInvalid } : {})}\n\t\t\t\t\tclassName={twMerge(\n\t\t\t\t\t\t\"flex-1 px-3 py-1 h-input-default border-0 rounded-r-md bg-transparent focus:outline-none text-foreground text-sm\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\tautoComplete=\"tel\"\n\t\t\t\t/>\n\t\t\t</div>\n\n\t\t\t{!disabled && externalError && externalTouched && <LabelError text={externalError || currentError || \"\"} />}\n\t\t</div>\n\t);\n};\n"],"names":["countryData","PhoneInput","id","name","label","placeholder","required","className","classNameContainer","onCountryChange","onPhoneChange","externalTouched","externalOnBlur","externalError","externalValue","defaultCountry","disabled","selectedCountry","setSelectedCountry","useState","getCountryCallingCode","isDropdownOpen","setIsDropdownOpen","phoneValue","setPhoneValue","formattedValue","setFormattedValue","isValid","setIsValid","countries","setCountries","searchTerm","setSearchTerm","filteredCountries","setFilteredCountries","dropdownRef","useRef","inputRef","searchInputRef","inputId","useId","resolvedId","isControlled","useEffect","availableCountries","countryCode","data","handleClickOutside","event","value","country","c","raw","formatted","AsYouType","valid","isValidPhoneNumber","handlePhoneChange","cleanValue","fullNumber","handleCountrySelect","handleDropdownToggle","searchLower","filtered","isTouched","currentError","hasError","isInvalid","twMerge","jsxs","cn","jsx","ChevronDown","AnimatePresence","LazyMotion","domAnimation","m","Search","ScrollArea","Check","LabelError"],"mappings":"ghBAUMA,EAAc,CACnB,GAAI,CAAE,KAAM,OAAQ,KAAM,MAAA,EAC1B,GAAI,CAAE,KAAM,iBAAkB,KAAM,MAAA,EACpC,GAAI,CAAE,KAAM,SAAU,KAAM,MAAA,EAC5B,GAAI,CAAE,KAAM,YAAa,KAAM,MAAA,EAC/B,GAAI,CAAE,KAAM,WAAY,KAAM,MAAA,EAC9B,GAAI,CAAE,KAAM,QAAS,KAAM,MAAA,EAC3B,GAAI,CAAE,KAAM,SAAU,KAAM,MAAA,EAC5B,GAAI,CAAE,KAAM,UAAW,KAAM,MAAA,EAC7B,GAAI,CAAE,KAAM,YAAa,KAAM,MAAA,CAChC,EA4BaC,GAAwC,CAAC,CACrD,GAAAC,EACA,KAAAC,EACA,MAAAC,EAAQ,WACR,YAAAC,EAAc,gCACd,SAAAC,EAAW,GACX,UAAAC,EAAY,GACZ,mBAAAC,EAAqB,GACrB,gBAAAC,EACA,cAAAC,EACA,QAASC,EACT,OAAQC,EACR,MAAOC,EACP,MAAOC,EACP,eAAAC,EAAiB,KACjB,SAAAC,EAAW,EACZ,IAAM,CACL,KAAM,CAACC,EAAiBC,CAAkB,EAAIC,WAAkB,CAC/D,KAAMJ,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EAGA,CAACS,GAAYH,GAAiBF,2BAAoBqE,cAAA,CAAW,KAAMnE,GAAiBoD,GAAgB,EAAA,CAAI,CAAA,EAC1G,CAEF"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { j as t } from "../chunks/jsx-runtime-Cl_4eDuT.js";
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as r, useRef as L, useId as ae, useEffect as C } from "react";
|
|
3
3
|
import { getCountryCallingCode as U, AsYouType as S, isValidPhoneNumber as k } from "libphonenumber-js";
|
|
4
|
-
import {
|
|
5
|
-
import { c as
|
|
6
|
-
import "../chunks/textarea-
|
|
7
|
-
import { L as
|
|
8
|
-
import "
|
|
9
|
-
import
|
|
10
|
-
import "../chunks/button-CSuKvE1x.js";
|
|
4
|
+
import { t as u } from "../chunks/bundle-mjs-2oQ8XDAz.js";
|
|
5
|
+
import { c as le } from "../chunks/utils-CvyT6Z0O.js";
|
|
6
|
+
import "../chunks/textarea-BPsle-xc.js";
|
|
7
|
+
import { L as ie } from "../chunks/label-error-BOE4Qj5S.js";
|
|
8
|
+
import { S as ce, a as de } from "../chunks/scroll-area-1okMO4N6.js";
|
|
9
|
+
import "../chunks/button-DJYse8Dw.js";
|
|
11
10
|
import { AnimatePresence as me, LazyMotion as fe, domAnimation as ue, m as pe } from "framer-motion";
|
|
12
11
|
import { C as ge, a as he } from "../chunks/index-VJ2Qvmen.js";
|
|
13
12
|
const j = {
|
|
@@ -20,7 +19,7 @@ const j = {
|
|
|
20
19
|
BR: { name: "Brasil", flag: "🇧🇷" },
|
|
21
20
|
BO: { name: "Bolivia", flag: "🇧🇴" },
|
|
22
21
|
VE: { name: "Venezuela", flag: "🇻🇪" }
|
|
23
|
-
},
|
|
22
|
+
}, Se = ({
|
|
24
23
|
id: W,
|
|
25
24
|
name: X,
|
|
26
25
|
label: B = "Teléfono",
|
|
@@ -37,85 +36,85 @@ const j = {
|
|
|
37
36
|
defaultCountry: g = "PE",
|
|
38
37
|
disabled: h = !1
|
|
39
38
|
}) => {
|
|
40
|
-
const [
|
|
39
|
+
const [s, P] = r({
|
|
41
40
|
code: g,
|
|
42
41
|
name: j[g].name,
|
|
43
42
|
flag: j[g].flag,
|
|
44
43
|
callingCode: `+${U(g)}`
|
|
45
|
-
}), [x, y] =
|
|
44
|
+
}), [x, y] = r(!1), [b, d] = r(""), [Q, a] = r(""), [Z, m] = r(!1), [l, _] = r([]), [f, R] = r(""), [ee, E] = r([]), I = L(null), T = L(null), A = L(null), te = ae(), V = W || te, D = c !== void 0;
|
|
46
45
|
C(() => {
|
|
47
|
-
const e = Object.keys(j).map((
|
|
48
|
-
const
|
|
46
|
+
const e = Object.keys(j).map((o) => {
|
|
47
|
+
const n = j[o];
|
|
49
48
|
return {
|
|
50
|
-
code:
|
|
51
|
-
name:
|
|
52
|
-
flag:
|
|
53
|
-
callingCode: `+${U(
|
|
49
|
+
code: o,
|
|
50
|
+
name: n.name,
|
|
51
|
+
flag: n.flag,
|
|
52
|
+
callingCode: `+${U(o)}`
|
|
54
53
|
};
|
|
55
54
|
});
|
|
56
55
|
_(e), E(e);
|
|
57
56
|
}, []), C(() => {
|
|
58
|
-
const e = (
|
|
59
|
-
I.current && !I.current.contains(
|
|
57
|
+
const e = (o) => {
|
|
58
|
+
I.current && !I.current.contains(o.target) && y(!1);
|
|
60
59
|
};
|
|
61
60
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
62
61
|
}, []), C(() => {
|
|
63
|
-
if (!D ||
|
|
62
|
+
if (!D || l.length === 0) return;
|
|
64
63
|
if (c === "" || c == null) {
|
|
65
64
|
d(""), a(""), m(!1);
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
67
|
const e = String(c);
|
|
69
|
-
let
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
d(
|
|
74
|
-
const
|
|
75
|
-
a(
|
|
68
|
+
let o = l.find((n) => e.startsWith(n.callingCode));
|
|
69
|
+
if (o || (o = s), o) {
|
|
70
|
+
s.code !== o.code && P(o);
|
|
71
|
+
const n = e.replace(o.callingCode, "").replace(/[^\d]/g, "");
|
|
72
|
+
d(n);
|
|
73
|
+
const i = new S(o.code).input(n);
|
|
74
|
+
a(i);
|
|
76
75
|
const v = k(e);
|
|
77
76
|
m(v);
|
|
78
77
|
} else
|
|
79
78
|
d(""), a(""), m(!1);
|
|
80
|
-
}, [c,
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
d(
|
|
79
|
+
}, [c, l, D, s]);
|
|
80
|
+
const ne = (e, o) => {
|
|
81
|
+
const n = e.replace(/[^\d]/g, "");
|
|
82
|
+
if (o?.nativeEvent instanceof InputEvent && o.nativeEvent.inputType === "deleteContentBackward" && n.length < 4) {
|
|
83
|
+
d(n), a(n);
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
|
-
const
|
|
88
|
-
d(
|
|
89
|
-
const v =
|
|
86
|
+
const i = new S(s.code).input(n);
|
|
87
|
+
d(n), a(i);
|
|
88
|
+
const v = s.callingCode + n, $ = k(v);
|
|
90
89
|
m($), O?.(v, $);
|
|
91
|
-
},
|
|
90
|
+
}, oe = (e) => {
|
|
92
91
|
if (P(e), y(!1), R(""), b) {
|
|
93
|
-
const
|
|
94
|
-
a(
|
|
95
|
-
const w = e.callingCode + b,
|
|
96
|
-
m(
|
|
92
|
+
const n = new S(e.code).input(b);
|
|
93
|
+
a(n);
|
|
94
|
+
const w = e.callingCode + b, i = k(w);
|
|
95
|
+
m(i), O?.(w, i);
|
|
97
96
|
}
|
|
98
97
|
J?.(e), setTimeout(() => T.current?.focus(), 100);
|
|
99
|
-
},
|
|
98
|
+
}, se = () => {
|
|
100
99
|
y(!x), x || setTimeout(() => A.current?.focus(), 100);
|
|
101
100
|
};
|
|
102
101
|
C(() => {
|
|
103
102
|
if (!f.trim())
|
|
104
|
-
E(
|
|
103
|
+
E(l);
|
|
105
104
|
else {
|
|
106
|
-
const e = f.toLowerCase(),
|
|
107
|
-
(
|
|
105
|
+
const e = f.toLowerCase(), o = l.filter(
|
|
106
|
+
(n) => n.name.toLowerCase().includes(e) || n.callingCode.includes(f) || n.code.toLowerCase().includes(e)
|
|
108
107
|
);
|
|
109
|
-
E(
|
|
108
|
+
E(o);
|
|
110
109
|
}
|
|
111
|
-
}, [f,
|
|
112
|
-
const
|
|
110
|
+
}, [f, l]);
|
|
111
|
+
const re = N, M = p, z = re && M, F = !h && !!p && N;
|
|
113
112
|
return /* @__PURE__ */ t.jsxs("div", { className: u("w-full relative flex flex-col", H), children: [
|
|
114
113
|
B && /* @__PURE__ */ t.jsxs(
|
|
115
114
|
"label",
|
|
116
115
|
{
|
|
117
116
|
htmlFor: V,
|
|
118
|
-
className:
|
|
117
|
+
className: le("form-control-label block font-normal text-sm text-foreground mb-1", {
|
|
119
118
|
"text-danger": z
|
|
120
119
|
}),
|
|
121
120
|
children: [
|
|
@@ -142,14 +141,14 @@ const j = {
|
|
|
142
141
|
"button",
|
|
143
142
|
{
|
|
144
143
|
type: "button",
|
|
145
|
-
onClick:
|
|
144
|
+
onClick: se,
|
|
146
145
|
className: u(
|
|
147
146
|
"flex items-center gap-2 px-3 border-r border-input h-input-default",
|
|
148
147
|
"hover:bg-muted/20 focus:outline-none rounded-l-md"
|
|
149
148
|
),
|
|
150
149
|
children: [
|
|
151
|
-
/* @__PURE__ */ t.jsx("span", { className: "text-lg", children:
|
|
152
|
-
/* @__PURE__ */ t.jsx("span", { className: "text-sm font-medium text-foreground", children:
|
|
150
|
+
/* @__PURE__ */ t.jsx("span", { className: "text-lg", children: s.flag }),
|
|
151
|
+
/* @__PURE__ */ t.jsx("span", { className: "text-sm font-medium text-foreground", children: s.callingCode }),
|
|
153
152
|
/* @__PURE__ */ t.jsx(ge, { className: `w-4 h-4 text-muted-foreground transition-transform ${x ? "rotate-180" : ""}` })
|
|
154
153
|
]
|
|
155
154
|
}
|
|
@@ -181,16 +180,16 @@ const j = {
|
|
|
181
180
|
"button",
|
|
182
181
|
{
|
|
183
182
|
type: "button",
|
|
184
|
-
onClick: () =>
|
|
183
|
+
onClick: () => oe(e),
|
|
185
184
|
className: u(
|
|
186
185
|
"w-full flex items-center gap-3 px-3 py-1 text-sm transition",
|
|
187
|
-
|
|
186
|
+
s.code === e.code ? "bg-primary/5 border-l-2 border-primary" : "hover:bg-muted/20"
|
|
188
187
|
),
|
|
189
188
|
children: [
|
|
190
189
|
/* @__PURE__ */ t.jsx("span", { className: "text-lg", children: e.flag }),
|
|
191
190
|
/* @__PURE__ */ t.jsx("span", { className: "flex-1 text-left", children: e.name }),
|
|
192
191
|
/* @__PURE__ */ t.jsx("span", { className: "text-muted-foreground", children: e.callingCode }),
|
|
193
|
-
|
|
192
|
+
s.code === e.code && /* @__PURE__ */ t.jsx(he, { className: "w-4 h-4 text-primary" })
|
|
194
193
|
]
|
|
195
194
|
},
|
|
196
195
|
e.code
|
|
@@ -208,7 +207,7 @@ const j = {
|
|
|
208
207
|
type: "tel",
|
|
209
208
|
name: X,
|
|
210
209
|
value: Q,
|
|
211
|
-
onChange: (e) =>
|
|
210
|
+
onChange: (e) => ne(e.target.value, e),
|
|
212
211
|
onBlur: K,
|
|
213
212
|
placeholder: Y,
|
|
214
213
|
disabled: h,
|
|
@@ -223,10 +222,10 @@ const j = {
|
|
|
223
222
|
]
|
|
224
223
|
}
|
|
225
224
|
),
|
|
226
|
-
!h && p && N && /* @__PURE__ */ t.jsx(
|
|
225
|
+
!h && p && N && /* @__PURE__ */ t.jsx(ie, { text: p || M || "" })
|
|
227
226
|
] });
|
|
228
227
|
};
|
|
229
228
|
export {
|
|
230
|
-
|
|
229
|
+
Se as PhoneInput
|
|
231
230
|
};
|
|
232
231
|
//# sourceMappingURL=index.es.js.map
|