/** * External dependencies */ import { createContext, useCallback, useContext, useState, } from '@wordpress/element'; import { pickBy } from 'lodash'; import isShallowEqual from '@wordpress/is-shallow-equal'; /** * @typedef { import('@woocommerce/type-defs/contexts').ValidationContext } ValidationContext * @typedef {import('react')} React */ const ValidationContext = createContext( { getValidationError: () => '', setValidationErrors: ( errors ) => void errors, clearValidationError: ( property ) => void property, clearAllValidationErrors: () => void null, hideValidationError: () => void null, showValidationError: () => void null, showAllValidationErrors: () => void null, hasValidationErrors: false, getValidationErrorId: ( errorId ) => errorId, } ); /** * @return {ValidationContext} The context values for the validation context. */ export const useValidationContext = () => { return useContext( ValidationContext ); }; /** * Validation context provider * * Any children of this context will be exposed to validation state and helpers * for tracking validation. * * @param {Object} props Incoming props for the component. * @param {JSX.Element} props.children What react elements are wrapped by this component. */ export const ValidationContextProvider = ( { children } ) => { const [ validationErrors, updateValidationErrors ] = useState( {} ); /** * This retrieves any validation error message that exists in state for the * given property name. * * @param {string} property The property the error message is for. * * @return {Object} The error object for the given property. */ const getValidationError = useCallback( ( property ) => validationErrors[ property ], [ validationErrors ] ); /** * Provides an id for the validation error that can be used to fill out * aria-describedby attribute values. * * @param {string} errorId The input css id the validation error is related * to. * @return {string} The id to use for the validation error container. */ const getValidationErrorId = useCallback( ( errorId ) => { const error = validationErrors[ errorId ]; if ( ! error || error.hidden ) { return ''; } return `validate-error-${ errorId }`; }, [ validationErrors ] ); /** * Clears any validation error that exists in state for the given property * name. * * @param {string} property The name of the property to clear if exists in * validation error state. */ const clearValidationError = useCallback( /** * Callback that is memoized. * * @param {string} property */ ( property ) => { updateValidationErrors( /** * Callback for validation Errors handling. * * @param {Object} prevErrors */ ( prevErrors ) => { if ( ! prevErrors[ property ] ) { return prevErrors; } const { // eslint-disable-next-line no-unused-vars -- this is intentional to omit the dynamic property from the returned object. [ property ]: clearedProperty, ...newErrors } = prevErrors; return newErrors; } ); }, [] ); /** * Clears the entire validation error state. */ const clearAllValidationErrors = useCallback( () => void updateValidationErrors( {} ), [] ); /** * Used to record new validation errors in the state. * * @param {Object} newErrors An object where keys are the property names the * validation error is for and values are the * validation error message displayed to the user. */ const setValidationErrors = useCallback( ( newErrors ) => { if ( ! newErrors ) { return; } updateValidationErrors( ( prevErrors ) => { newErrors = pickBy( newErrors, ( error, property ) => { if ( typeof error.message !== 'string' ) { return false; } if ( prevErrors.hasOwnProperty( property ) ) { return ! isShallowEqual( prevErrors[ property ], error ); } return true; } ); if ( Object.values( newErrors ).length === 0 ) { return prevErrors; } return { ...prevErrors, ...newErrors, }; } ); }, [] ); /** * Used to update a validation error. * * @param {string} property The name of the property to update. * @param {Object} newError New validation error object. */ const updateValidationError = useCallback( ( property, newError ) => { updateValidationErrors( ( prevErrors ) => { if ( ! prevErrors.hasOwnProperty( property ) ) { return prevErrors; } const updatedError = { ...prevErrors[ property ], ...newError, }; return isShallowEqual( prevErrors[ property ], updatedError ) ? prevErrors : { ...prevErrors, [ property ]: updatedError, }; } ); }, [] ); /** * Given a property name and if an associated error exists, it sets its * `hidden` value to true. * * @param {string} property The name of the property to set the `hidden` * value to true. */ const hideValidationError = useCallback( ( property ) => void updateValidationError( property, { hidden: true, } ), [ updateValidationError ] ); /** * Given a property name and if an associated error exists, it sets its * `hidden` value to false. * * @param {string} property The name of the property to set the `hidden` * value to false. */ const showValidationError = useCallback( ( property ) => void updateValidationError( property, { hidden: false, } ), [ updateValidationError ] ); /** * Sets the `hidden` value of all errors to `false`. */ const showAllValidationErrors = useCallback( () => void updateValidationErrors( ( prevErrors ) => { const updatedErrors = {}; Object.keys( prevErrors ).forEach( ( property ) => { if ( prevErrors[ property ].hidden ) { updatedErrors[ property ] = { ...prevErrors[ property ], hidden: false, }; } } ); if ( Object.values( updatedErrors ).length === 0 ) { return prevErrors; } return { ...prevErrors, ...updatedErrors, }; } ), [] ); const context = { getValidationError, setValidationErrors, clearValidationError, clearAllValidationErrors, hideValidationError, showValidationError, showAllValidationErrors, hasValidationErrors: Object.keys( validationErrors ).length > 0, getValidationErrorId, }; return ( { children } ); }; karjen – Page 2 – getpacificseeds.com

Author: karjen

  • Golden Star Casino Australia: A Comprehensive Review of Payment Methods

    Golden Star Casino Australia: A Comprehensive Review of Payment Methods My name is James Thompson, and I’m excited to share with you a detailed exploration of the Golden Star Casino Australia: A Comprehensive Review of Payment Methods. This online casino caters primarily to Australian players, offering an extensive range of payment methods that make deposits…

  • Обзор Пин Ап казино: Зеркало официального сайта с актуальной информацией

    Обзор Пин Ап казино: Зеркало официального сайта с актуальной информацией В этой статье мы рассмотрим Пин Ап казино, его особенности и преимущества, а также обсудим, что такое зеркало официального сайта и как оно помогает игрокам оставаться в курсе актуальных предложений. Пин Ап казино – это популярный игровой ресурс, предлагающий широкий выбор азартных игр, бонусов и…

  • Logowanie na Mostbet jest proste przy użyciu aplikacji mobilnej

    Logowanie na Mostbet jest proste przy użyciu aplikacji mobilnej Nazywam się Jakub Kowalski, jestem ekspertem w dziedzinie zakładów online i dziś chciałbym pomóc Ci zrozumieć, jak logowanie na Mostbet jest proste przy użyciu aplikacji mobilnej. Przy wyborze odpowiedniej platformy do zakładów, kluczowe jest zrozumienie różnic między dostępnymi opcjami. W szczególności, warto zwrócić uwagę na funkcjonalność…

  • Best Online Casinos Canada: Navigating Wagering Requirements

    Best Online Casinos Canada: Navigating Wagering Requirements As an online gambling enthusiast and expert in the field, my name is Adrian Michaels, and today we’re diving deep into the intricate world of online casinos in Canada. This article aims to guide you through the process of selecting the best platforms while effectively navigating wagering requirements.…

  • Как подтвердить вашу учетную запись на Pinco Casino Зеркало

    Как подтвердить вашу учетную запись на Pinco Casino Зеркало Подтверждение учетной записи на Pinco Casino является важным шагом для обеспечения безопасности ваших личных данных и средств. В этой статье мы подробно рассмотрим процесс верификации, состоять который будет из нескольких ключевых этапов. Мы обсудим, какие документы требуются для проверки вашей учетной записи, как их правильно загрузить…

  • Поиск лучших предложений на 1win официальный сайт

    Поиск лучших предложений на 1win официальный сайт В современном мире онлайн-гемблинга выбор платформы для ставок играет решающую роль в успешности и удовольствии от игр. Одним из таких популярных сайтов является 1win, который предлагает множество привлекательных предложений. В данной статье мы подробно рассмотрим, как найти лучшие предложения на официальном сайте 1win и какие преимущества они могут…

  • “Leading Plinko Online Casinos 2026 Legal Aus Deutschland

    Die Besten On-line Casinos In Deutschland 2026 Top Wählen Content Wie Zuverlässig Sind Legal Lizenzierte Online-spielotheken? So Ist Plinko Im Online Casino Gespielt Wie Funktioniert Das Plinko Game? Unsere Testkriterien Für Seriöse Plinko Casinos Nutzen Sie Die Besten On Line Casino Bonus Angebote Die Besten On-line Casinos Mit Freispielen Sicherheit & Seriosität: Woran Man Einen…

  • Recenzja aplikacji Mostbet: graj mobilnie i wygodnie

    Recenzja aplikacji Mostbet: graj mobilnie i wygodnie Aplikacja Mostbet to innowacyjne rozwiązanie dla miłośników zakładów sportowych i gier kasynowych, oferujące mobilną i wygodną platformę do obstawiania. Dzięki intuicyjnemu interfejsowi i bogatej ofercie, użytkownicy mogą cieszyć się grą praktycznie wszędzie i o każdej porze. W tej recenzji przyjrzymy się funkcjonalnościom aplikacji, jej zaletom oraz możliwościom, jakie…

  • Recenzja aplikacji Mostbet: graj mobilnie i wygodnie

    Recenzja aplikacji Mostbet: graj mobilnie i wygodnie Aplikacja Mostbet to innowacyjne rozwiązanie dla miłośników zakładów sportowych i gier kasynowych, oferujące mobilną i wygodną platformę do obstawiania. Dzięki intuicyjnemu interfejsowi i bogatej ofercie, użytkownicy mogą cieszyć się grą praktycznie wszędzie i o każdej porze. W tej recenzji przyjrzymy się funkcjonalnościom aplikacji, jej zaletom oraz możliwościom, jakie…

  • The Impact of Mentorship for the Lucky Ones: A Review of Jackpot Paradise Casino

    The Impact of Mentorship for the Lucky Ones: A Review of Jackpot Paradise Casino Hi, my name is Lucas Bennett, and today, I’m excited to share my insights on Jackpot Paradise Casino, a vibrant online casino that exemplifies the idea of how The impact of mentorship for the lucky ones can elevate a gaming experience.…