Add coexistence checks to all enqueue methods to prevent loading both React and Grid.js assets simultaneously. Changes: - ReactAdmin.php: Only enqueue React assets when ?react=1 - Init.php: Skip Grid.js when React active on admin pages - Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0 - Customer.php, Product.php, License.php: Add coexistence checks Now the toggle between Classic and React versions works correctly. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
144 lines
3.9 KiB
JavaScript
144 lines
3.9 KiB
JavaScript
import { createElement } from "react";
|
|
/**
|
|
* External dependencies
|
|
*/
|
|
import classnames from 'classnames';
|
|
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
import { useInstanceId } from '@wordpress/compose';
|
|
import { isRTL } from '@wordpress/i18n';
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
import { CircularOptionPickerContext } from './circular-option-picker-context';
|
|
import { Composite, useCompositeStore } from '../composite/v2';
|
|
import { Option } from './circular-option-picker-option';
|
|
import { OptionGroup } from './circular-option-picker-option-group';
|
|
import { ButtonAction, DropdownLinkAction } from './circular-option-picker-actions';
|
|
|
|
/**
|
|
*`CircularOptionPicker` is a component that displays a set of options as circular buttons.
|
|
*
|
|
* ```jsx
|
|
* import { CircularOptionPicker } from '../circular-option-picker';
|
|
* import { useState } from '@wordpress/element';
|
|
*
|
|
* const Example = () => {
|
|
* const [ currentColor, setCurrentColor ] = useState();
|
|
* const colors = [
|
|
* { color: '#f00', name: 'Red' },
|
|
* { color: '#0f0', name: 'Green' },
|
|
* { color: '#00f', name: 'Blue' },
|
|
* ];
|
|
* const colorOptions = (
|
|
* <>
|
|
* { colors.map( ( { color, name }, index ) => {
|
|
* return (
|
|
* <CircularOptionPicker.Option
|
|
* key={ `${ color }-${ index }` }
|
|
* tooltipText={ name }
|
|
* style={ { backgroundColor: color, color } }
|
|
* isSelected={ index === currentColor }
|
|
* onClick={ () => setCurrentColor( index ) }
|
|
* aria-label={ name }
|
|
* />
|
|
* );
|
|
* } ) }
|
|
* </>
|
|
* );
|
|
* return (
|
|
* <CircularOptionPicker
|
|
* options={ colorOptions }
|
|
* actions={
|
|
* <CircularOptionPicker.ButtonAction
|
|
* onClick={ () => setCurrentColor( undefined ) }
|
|
* >
|
|
* { 'Clear' }
|
|
* </CircularOptionPicker.ButtonAction>
|
|
* }
|
|
* />
|
|
* );
|
|
* };
|
|
* ```
|
|
*/
|
|
|
|
function ListboxCircularOptionPicker(props) {
|
|
const {
|
|
actions,
|
|
options,
|
|
baseId,
|
|
className,
|
|
loop = true,
|
|
children,
|
|
...additionalProps
|
|
} = props;
|
|
const compositeStore = useCompositeStore({
|
|
focusLoop: loop,
|
|
rtl: isRTL()
|
|
});
|
|
const compositeContext = {
|
|
baseId,
|
|
compositeStore
|
|
};
|
|
return createElement("div", {
|
|
className: className
|
|
}, createElement(CircularOptionPickerContext.Provider, {
|
|
value: compositeContext
|
|
}, createElement(Composite, {
|
|
...additionalProps,
|
|
id: baseId,
|
|
store: compositeStore,
|
|
role: 'listbox'
|
|
}, options), children, actions));
|
|
}
|
|
function ButtonsCircularOptionPicker(props) {
|
|
const {
|
|
actions,
|
|
options,
|
|
children,
|
|
baseId,
|
|
...additionalProps
|
|
} = props;
|
|
return createElement("div", {
|
|
...additionalProps,
|
|
id: baseId
|
|
}, createElement(CircularOptionPickerContext.Provider, {
|
|
value: {
|
|
baseId
|
|
}
|
|
}, options, children, actions));
|
|
}
|
|
function CircularOptionPicker(props) {
|
|
const {
|
|
asButtons,
|
|
actions: actionsProp,
|
|
options: optionsProp,
|
|
children,
|
|
className,
|
|
...additionalProps
|
|
} = props;
|
|
const baseId = useInstanceId(CircularOptionPicker, 'components-circular-option-picker', additionalProps.id);
|
|
const OptionPickerImplementation = asButtons ? ButtonsCircularOptionPicker : ListboxCircularOptionPicker;
|
|
const actions = actionsProp ? createElement("div", {
|
|
className: "components-circular-option-picker__custom-clear-wrapper"
|
|
}, actionsProp) : undefined;
|
|
const options = createElement("div", {
|
|
className: 'components-circular-option-picker__swatches'
|
|
}, optionsProp);
|
|
return createElement(OptionPickerImplementation, {
|
|
...additionalProps,
|
|
baseId: baseId,
|
|
className: classnames('components-circular-option-picker', className),
|
|
actions: actions,
|
|
options: options
|
|
}, children);
|
|
}
|
|
CircularOptionPicker.Option = Option;
|
|
CircularOptionPicker.OptionGroup = OptionGroup;
|
|
CircularOptionPicker.ButtonAction = ButtonAction;
|
|
CircularOptionPicker.DropdownLinkAction = DropdownLinkAction;
|
|
export default CircularOptionPicker;
|
|
//# sourceMappingURL=circular-option-picker.js.map
|