Server IP : 104.21.14.103 / Your IP : 3.145.32.73 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/components/view-switcher/ |
Upload File : |
/** * External dependencies */ import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { ButtonGroup, Button } from '@wordpress/components'; import { useState, Fragment } from '@wordpress/element'; import { withInstanceId } from '@wordpress/compose'; /** * Internal dependencies */ import './editor.scss'; const ViewSwitcher = ( { className, label = __( 'View', 'woocommerce' ), views, defaultView, instanceId, render, } ) => { const [ currentView, setCurrentView ] = useState( defaultView ); const classes = classnames( className, 'wc-block-view-switch-control' ); const htmlId = 'wc-block-view-switch-control-' + instanceId; return ( <Fragment> <div className={ classes }> <label htmlFor={ htmlId } className="wc-block-view-switch-control__label" > { label + ': ' } </label> <ButtonGroup id={ htmlId }> { views.map( ( view ) => ( <Button key={ view.value } isPrimary={ currentView === view.value } isLarge aria-pressed={ currentView === view.value } onMouseDown={ () => { if ( currentView !== view.value ) { setCurrentView( view.value ); } } } onClick={ () => { if ( currentView !== view.value ) { setCurrentView( view.value ); } } } > { view.name } </Button> ) ) } </ButtonGroup> </div> { render( currentView ) } </Fragment> ); }; ViewSwitcher.propTypes = { /** * Custom class name to add to component. */ className: PropTypes.string, /** * List of views. */ views: PropTypes.arrayOf( PropTypes.shape( { name: PropTypes.string.isRequired, value: PropTypes.string.isRequired, } ) ).isRequired, /** * The default selected view. */ defaultView: PropTypes.string.isRequired, /** * Render prop for selected views. */ render: PropTypes.func.isRequired, // from withInstanceId instanceId: PropTypes.number.isRequired, }; export default withInstanceId( ViewSwitcher );