Files
formipay/node_modules/@wordpress/components/build-module/notice/index.js
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
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>
2026-04-18 17:02:14 +07:00

133 lines
3.5 KiB
JavaScript

import { createElement } from "react";
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { RawHTML, useEffect, renderToString } from '@wordpress/element';
import { speak } from '@wordpress/a11y';
import { close } from '@wordpress/icons';
/**
* Internal dependencies
*/
import Button from '../button';
import { VisuallyHidden } from '../visually-hidden';
const noop = () => {};
/**
* Custom hook which announces the message with the given politeness, if a
* valid message is provided.
*/
function useSpokenMessage(message, politeness) {
const spokenMessage = typeof message === 'string' ? message : renderToString(message);
useEffect(() => {
if (spokenMessage) {
speak(spokenMessage, politeness);
}
}, [spokenMessage, politeness]);
}
function getDefaultPoliteness(status) {
switch (status) {
case 'success':
case 'warning':
case 'info':
return 'polite';
// The default will also catch the 'error' status.
default:
return 'assertive';
}
}
function getStatusLabel(status) {
switch (status) {
case 'warning':
return __('Warning notice');
case 'info':
return __('Information notice');
case 'error':
return __('Error notice');
// The default will also catch the 'success' status.
default:
return __('Notice');
}
}
/**
* `Notice` is a component used to communicate feedback to the user.
*
*```jsx
* import { Notice } from `@wordpress/components`;
*
* const MyNotice = () => (
* <Notice status="error">An unknown error occurred.</Notice>
* );
* ```
*/
function Notice({
className,
status = 'info',
children,
spokenMessage = children,
onRemove = noop,
isDismissible = true,
actions = [],
politeness = getDefaultPoliteness(status),
__unstableHTML,
// onDismiss is a callback executed when the notice is dismissed.
// It is distinct from onRemove, which _looks_ like a callback but is
// actually the function to call to remove the notice from the UI.
onDismiss = noop
}) {
useSpokenMessage(spokenMessage, politeness);
const classes = classnames(className, 'components-notice', 'is-' + status, {
'is-dismissible': isDismissible
});
if (__unstableHTML && typeof children === 'string') {
children = createElement(RawHTML, null, children);
}
const onDismissNotice = () => {
onDismiss();
onRemove();
};
return createElement("div", {
className: classes
}, createElement(VisuallyHidden, null, getStatusLabel(status)), createElement("div", {
className: "components-notice__content"
}, children, createElement("div", {
className: "components-notice__actions"
}, actions.map(({
className: buttonCustomClasses,
label,
isPrimary,
variant,
noDefaultClasses = false,
onClick,
url
}, index) => {
let computedVariant = variant;
if (variant !== 'primary' && !noDefaultClasses) {
computedVariant = !url ? 'secondary' : 'link';
}
if (typeof computedVariant === 'undefined' && isPrimary) {
computedVariant = 'primary';
}
return createElement(Button, {
key: index,
href: url,
variant: computedVariant,
onClick: url ? undefined : onClick,
className: classnames('components-notice__action', buttonCustomClasses)
}, label);
}))), isDismissible && createElement(Button, {
className: "components-notice__dismiss",
icon: close,
label: __('Close'),
onClick: onDismissNotice
}));
}
export default Notice;
//# sourceMappingURL=index.js.map