woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodItemBlock.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

import { ToggleControl, Icon, Button } from '@wordpress/components';
import { cog } from '@wordpress/icons';
import { useEffect } from '@wordpress/element';
import { useActiveHighlight } from '../../../data/common/hooks';
import SettingsBlock from '../SettingsBlock';
import PaymentMethodIcon from '../PaymentMethodIcon';
const PaymentMethodItemBlock = ( {
2025-01-22 12:09:21 +01:00
paymentMethod,
onTriggerModal,
onSelect,
isSelected,
} ) => {
const { activeHighlight, setActiveHighlight } = useActiveHighlight();
const isHighlighted = activeHighlight === paymentMethod.id;
// Reset the active highlight after 2 seconds
useEffect( () => {
if ( isHighlighted ) {
const timer = setTimeout( () => {
setActiveHighlight( null );
}, 2000 );
return () => clearTimeout( timer );
}
}, [ isHighlighted, setActiveHighlight ] );
return (
<SettingsBlock
id={ paymentMethod.id }
className={ `ppcp--method-item ${
isHighlighted ? 'ppcp-highlight' : ''
}` }
separatorAndGap={ false }
>
<div className="ppcp--method-inner">
<div className="ppcp--method-title-wrapper">
{ paymentMethod?.icon && (
<PaymentMethodIcon
icons={ [ paymentMethod.icon ] }
type={ paymentMethod.icon }
/>
) }
<span className="ppcp--method-title">
2025-01-22 12:09:21 +01:00
{ paymentMethod.itemTitle }
</span>
2024-12-16 16:00:27 +01:00
</div>
<p className="ppcp--method-description">
2025-01-22 12:09:21 +01:00
{ paymentMethod.itemDescription }
</p>
<div className="ppcp--method-footer">
<ToggleControl
2025-01-28 12:53:33 +01:00
__nextHasNoMarginBottom
checked={ isSelected }
onChange={ onSelect }
/>
2025-01-22 12:09:21 +01:00
{ paymentMethod?.fields && onTriggerModal && (
2025-01-24 17:06:15 +01:00
<Button
className="ppcp--method-settings"
onClick={ onTriggerModal }
>
<Icon icon={ cog } />
2025-01-24 17:06:15 +01:00
</Button>
) }
</div>
</div>
</SettingsBlock>
);
};
export default PaymentMethodItemBlock;