UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

29 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useValidations = exports.ValidationsProvider = exports.ValidationsContext = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const checkRegex_1 = require("../../utils/validations/checkRegex"); exports.ValidationsContext = (0, react_1.createContext)(null); const ValidationsProvider = ({ children, value, }) => { return (0, jsx_runtime_1.jsx)(exports.ValidationsContext.Provider, { value: value, children: children }); }; exports.ValidationsProvider = ValidationsProvider; const useValidations = () => { const context = (0, react_1.useContext)(exports.ValidationsContext); const validationValue = (key, value) => { const validation = context?.regex?.[context?.country || '']?.[key] || context?.regex?.[key]; if (!validation) { throw Error('Function does not exist'); } if (typeof validation === 'function') { return validation(value); } return (0, checkRegex_1.checkRegex)(validation, value); }; return { validationValue, }; }; exports.useValidations = useValidations; //# sourceMappingURL=validationsProvider.js.map