@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
24 lines • 940 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext } from 'react';
import { checkRegex } from '../../utils/validations/checkRegex';
export const ValidationsContext = createContext(null);
export const ValidationsProvider = ({ children, value, }) => {
return _jsx(ValidationsContext.Provider, { value: value, children: children });
};
export const useValidations = () => {
const context = useContext(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 checkRegex(validation, value);
};
return {
validationValue,
};
};
//# sourceMappingURL=validationsProvider.js.map