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>
111 lines
3.1 KiB
JavaScript
111 lines
3.1 KiB
JavaScript
import { createElement } from "react";
|
|
/**
|
|
* External dependencies
|
|
*/
|
|
import classnames from 'classnames';
|
|
|
|
/**
|
|
* WordPress dependencies
|
|
*/
|
|
import { useReducedMotion, useMergeRefs } from '@wordpress/compose';
|
|
import { forwardRef, useRef } from '@wordpress/element';
|
|
import { chevronUp, chevronDown } from '@wordpress/icons';
|
|
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
|
|
import Button from '../button';
|
|
import Icon from '../icon';
|
|
import { useControlledState, useUpdateEffect } from '../utils';
|
|
const noop = () => {};
|
|
export function UnforwardedPanelBody(props, ref) {
|
|
const {
|
|
buttonProps = {},
|
|
children,
|
|
className,
|
|
icon,
|
|
initialOpen,
|
|
onToggle = noop,
|
|
opened,
|
|
title,
|
|
scrollAfterOpen = true
|
|
} = props;
|
|
const [isOpened, setIsOpened] = useControlledState(opened, {
|
|
initial: initialOpen === undefined ? true : initialOpen,
|
|
fallback: false
|
|
});
|
|
const nodeRef = useRef(null);
|
|
|
|
// Defaults to 'smooth' scrolling
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
|
const scrollBehavior = useReducedMotion() ? 'auto' : 'smooth';
|
|
const handleOnToggle = event => {
|
|
event.preventDefault();
|
|
const next = !isOpened;
|
|
setIsOpened(next);
|
|
onToggle(next);
|
|
};
|
|
|
|
// Ref is used so that the effect does not re-run upon scrollAfterOpen changing value.
|
|
const scrollAfterOpenRef = useRef();
|
|
scrollAfterOpenRef.current = scrollAfterOpen;
|
|
// Runs after initial render.
|
|
useUpdateEffect(() => {
|
|
if (isOpened && scrollAfterOpenRef.current && nodeRef.current?.scrollIntoView) {
|
|
/*
|
|
* Scrolls the content into view when visible.
|
|
* This improves the UX when there are multiple stacking <PanelBody />
|
|
* components in a scrollable container.
|
|
*/
|
|
nodeRef.current.scrollIntoView({
|
|
inline: 'nearest',
|
|
block: 'nearest',
|
|
behavior: scrollBehavior
|
|
});
|
|
}
|
|
}, [isOpened, scrollBehavior]);
|
|
const classes = classnames('components-panel__body', className, {
|
|
'is-opened': isOpened
|
|
});
|
|
return createElement("div", {
|
|
className: classes,
|
|
ref: useMergeRefs([nodeRef, ref])
|
|
}, createElement(PanelBodyTitle, {
|
|
icon: icon,
|
|
isOpened: Boolean(isOpened),
|
|
onClick: handleOnToggle,
|
|
title: title,
|
|
...buttonProps
|
|
}), typeof children === 'function' ? children({
|
|
opened: Boolean(isOpened)
|
|
}) : isOpened && children);
|
|
}
|
|
const PanelBodyTitle = forwardRef(({
|
|
isOpened,
|
|
icon,
|
|
title,
|
|
...props
|
|
}, ref) => {
|
|
if (!title) return null;
|
|
return createElement("h2", {
|
|
className: "components-panel__body-title"
|
|
}, createElement(Button, {
|
|
className: "components-panel__body-toggle",
|
|
"aria-expanded": isOpened,
|
|
ref: ref,
|
|
...props
|
|
}, createElement("span", {
|
|
"aria-hidden": "true"
|
|
}, createElement(Icon, {
|
|
className: "components-panel__arrow",
|
|
icon: isOpened ? chevronUp : chevronDown
|
|
})), title, icon && createElement(Icon, {
|
|
icon: icon,
|
|
className: "components-panel__icon",
|
|
size: 20
|
|
})));
|
|
});
|
|
export const PanelBody = forwardRef(UnforwardedPanelBody);
|
|
export default PanelBody;
|
|
//# sourceMappingURL=body.js.map
|