mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🚚 Rename UI hook to make it more generic
This commit is contained in:
parent
e8379f09e8
commit
4ecd07b453
2 changed files with 12 additions and 3 deletions
|
@ -2,7 +2,7 @@ import { Icon } from '@wordpress/components';
|
|||
import { chevronDown, chevronUp } from '@wordpress/icons';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { useAccordionState } from '../../hooks/useAccordionState';
|
||||
import { useToggleState } from '../../hooks/useToggleState';
|
||||
import {
|
||||
Content,
|
||||
Description,
|
||||
|
@ -21,7 +21,7 @@ const Accordion = ( {
|
|||
children = null,
|
||||
className = '',
|
||||
} ) => {
|
||||
const { isOpen, toggleOpen } = useAccordionState( { id, initiallyOpen } );
|
||||
const { isOpen, toggleOpen } = useToggleState( { id, initiallyOpen } );
|
||||
const wrapperClasses = classNames( 'ppcp-r-accordion', className, {
|
||||
'ppcp--is-open': isOpen,
|
||||
} );
|
||||
|
|
|
@ -11,7 +11,16 @@ const determineInitialState = ( id, initiallyOpen ) => {
|
|||
return checkIfCurrentTab( id );
|
||||
};
|
||||
|
||||
export function useAccordionState( { id = '', initiallyOpen = null } ) {
|
||||
/**
|
||||
* Allows managing a toggle-able component, such as an accordion or a modal dialog.
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {string} props.id - Optional, if provided, the toggle can be opened via the URL.
|
||||
* @param {null|boolean} props.initiallyOpen - Optional. If provided, it defines the initial open state.
|
||||
* If omitted, the initial open state is determined by using the "id" logic (inspecting the URL).
|
||||
* @return {{isOpen: unknown, toggleOpen: (function(*): boolean)}} Hook object.
|
||||
*/
|
||||
export function useToggleState( { id = '', initiallyOpen = null } ) {
|
||||
const [ isOpen, setIsOpen ] = useState(
|
||||
determineInitialState( id, initiallyOpen )
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue