@wordpress/components 30.2.1-next.0f6f9d12c.0 → 30.2.2-next.e256d081a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/build/context/context-connect.js.map +1 -1
  3. package/build/menu-item/index.js +1 -0
  4. package/build/menu-item/index.js.map +1 -1
  5. package/build/tabs/styles.js +5 -5
  6. package/build/tabs/styles.js.map +1 -1
  7. package/build/utils/font-size.js.map +1 -1
  8. package/build/utils/get-valid-children.js.map +1 -1
  9. package/build/validated-form-controls/components/checkbox-control.js +5 -3
  10. package/build/validated-form-controls/components/checkbox-control.js.map +1 -1
  11. package/build/validated-form-controls/components/combobox-control.js +5 -3
  12. package/build/validated-form-controls/components/combobox-control.js.map +1 -1
  13. package/build/validated-form-controls/components/custom-select-control.js +5 -3
  14. package/build/validated-form-controls/components/custom-select-control.js.map +1 -1
  15. package/build/validated-form-controls/components/input-control.js +5 -3
  16. package/build/validated-form-controls/components/input-control.js.map +1 -1
  17. package/build/validated-form-controls/components/number-control.js +5 -3
  18. package/build/validated-form-controls/components/number-control.js.map +1 -1
  19. package/build/validated-form-controls/components/radio-control.js +5 -3
  20. package/build/validated-form-controls/components/radio-control.js.map +1 -1
  21. package/build/validated-form-controls/components/range-control.js +5 -3
  22. package/build/validated-form-controls/components/range-control.js.map +1 -1
  23. package/build/validated-form-controls/components/select-control.js +5 -3
  24. package/build/validated-form-controls/components/select-control.js.map +1 -1
  25. package/build/validated-form-controls/components/text-control.js +5 -3
  26. package/build/validated-form-controls/components/text-control.js.map +1 -1
  27. package/build/validated-form-controls/components/textarea-control.js +5 -3
  28. package/build/validated-form-controls/components/textarea-control.js.map +1 -1
  29. package/build/validated-form-controls/components/toggle-control.js +5 -3
  30. package/build/validated-form-controls/components/toggle-control.js.map +1 -1
  31. package/build/validated-form-controls/components/toggle-group-control.js +5 -3
  32. package/build/validated-form-controls/components/toggle-group-control.js.map +1 -1
  33. package/build/validated-form-controls/components/types.js.map +1 -1
  34. package/build/validated-form-controls/control-with-error.js +70 -35
  35. package/build/validated-form-controls/control-with-error.js.map +1 -1
  36. package/build/validated-form-controls/validity-indicator.js +45 -0
  37. package/build/validated-form-controls/validity-indicator.js.map +1 -0
  38. package/build-module/context/context-connect.js.map +1 -1
  39. package/build-module/menu-item/index.js +1 -0
  40. package/build-module/menu-item/index.js.map +1 -1
  41. package/build-module/tabs/styles.js +6 -6
  42. package/build-module/tabs/styles.js.map +1 -1
  43. package/build-module/utils/font-size.js.map +1 -1
  44. package/build-module/utils/get-valid-children.js.map +1 -1
  45. package/build-module/validated-form-controls/components/checkbox-control.js +5 -3
  46. package/build-module/validated-form-controls/components/checkbox-control.js.map +1 -1
  47. package/build-module/validated-form-controls/components/combobox-control.js +5 -3
  48. package/build-module/validated-form-controls/components/combobox-control.js.map +1 -1
  49. package/build-module/validated-form-controls/components/custom-select-control.js +5 -3
  50. package/build-module/validated-form-controls/components/custom-select-control.js.map +1 -1
  51. package/build-module/validated-form-controls/components/input-control.js +5 -3
  52. package/build-module/validated-form-controls/components/input-control.js.map +1 -1
  53. package/build-module/validated-form-controls/components/number-control.js +5 -3
  54. package/build-module/validated-form-controls/components/number-control.js.map +1 -1
  55. package/build-module/validated-form-controls/components/radio-control.js +5 -3
  56. package/build-module/validated-form-controls/components/radio-control.js.map +1 -1
  57. package/build-module/validated-form-controls/components/range-control.js +5 -3
  58. package/build-module/validated-form-controls/components/range-control.js.map +1 -1
  59. package/build-module/validated-form-controls/components/select-control.js +5 -3
  60. package/build-module/validated-form-controls/components/select-control.js.map +1 -1
  61. package/build-module/validated-form-controls/components/text-control.js +5 -3
  62. package/build-module/validated-form-controls/components/text-control.js.map +1 -1
  63. package/build-module/validated-form-controls/components/textarea-control.js +5 -3
  64. package/build-module/validated-form-controls/components/textarea-control.js.map +1 -1
  65. package/build-module/validated-form-controls/components/toggle-control.js +5 -3
  66. package/build-module/validated-form-controls/components/toggle-control.js.map +1 -1
  67. package/build-module/validated-form-controls/components/toggle-group-control.js +5 -3
  68. package/build-module/validated-form-controls/components/toggle-group-control.js.map +1 -1
  69. package/build-module/validated-form-controls/components/types.js.map +1 -1
  70. package/build-module/validated-form-controls/control-with-error.js +70 -34
  71. package/build-module/validated-form-controls/control-with-error.js.map +1 -1
  72. package/build-module/validated-form-controls/validity-indicator.js +37 -0
  73. package/build-module/validated-form-controls/validity-indicator.js.map +1 -0
  74. package/build-style/style-rtl.css +34 -22
  75. package/build-style/style.css +34 -22
  76. package/build-types/context/context-connect.d.ts +2 -2
  77. package/build-types/context/context-connect.d.ts.map +1 -1
  78. package/build-types/menu-item/index.d.ts.map +1 -1
  79. package/build-types/tabs/styles.d.ts.map +1 -1
  80. package/build-types/utils/font-size.d.ts +2 -2
  81. package/build-types/utils/font-size.d.ts.map +1 -1
  82. package/build-types/utils/get-valid-children.d.ts +2 -2
  83. package/build-types/utils/get-valid-children.d.ts.map +1 -1
  84. package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -1
  85. package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -1
  86. package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -1
  87. package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -1
  88. package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -1
  89. package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -1
  90. package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -1
  91. package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -1
  92. package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -1
  93. package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -1
  94. package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -1
  95. package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -1
  96. package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -1
  97. package/build-types/validated-form-controls/components/stories/overview.story.d.ts +13 -0
  98. package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -1
  99. package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -1
  100. package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -1
  101. package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -1
  102. package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -1
  103. package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -1
  104. package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -1
  105. package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -1
  106. package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -1
  107. package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -1
  108. package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -1
  109. package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -1
  110. package/build-types/validated-form-controls/components/types.d.ts +21 -10
  111. package/build-types/validated-form-controls/components/types.d.ts.map +1 -1
  112. package/build-types/validated-form-controls/control-with-error.d.ts +4 -5
  113. package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
  114. package/build-types/validated-form-controls/test/control-with-error.d.ts +2 -0
  115. package/build-types/validated-form-controls/test/control-with-error.d.ts.map +1 -0
  116. package/build-types/validated-form-controls/validity-indicator.d.ts +5 -0
  117. package/build-types/validated-form-controls/validity-indicator.d.ts.map +1 -0
  118. package/package.json +19 -19
  119. package/src/calendar/style.scss +22 -22
  120. package/src/context/context-connect.ts +2 -2
  121. package/src/menu-item/index.tsx +1 -0
  122. package/src/tabs/styles.ts +2 -1
  123. package/src/tools-panel/stories/index.story.tsx +3 -3
  124. package/src/utils/font-size.ts +2 -2
  125. package/src/utils/get-valid-children.ts +4 -2
  126. package/src/utils/theme-variables.scss +1 -0
  127. package/src/validated-form-controls/components/checkbox-control.tsx +5 -3
  128. package/src/validated-form-controls/components/combobox-control.tsx +5 -3
  129. package/src/validated-form-controls/components/custom-select-control.tsx +5 -3
  130. package/src/validated-form-controls/components/input-control.tsx +5 -3
  131. package/src/validated-form-controls/components/number-control.tsx +5 -3
  132. package/src/validated-form-controls/components/radio-control.tsx +5 -3
  133. package/src/validated-form-controls/components/range-control.tsx +5 -3
  134. package/src/validated-form-controls/components/select-control.tsx +5 -3
  135. package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +17 -6
  136. package/src/validated-form-controls/components/stories/combobox-control.story.tsx +17 -6
  137. package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +17 -6
  138. package/src/validated-form-controls/components/stories/input-control.story.tsx +51 -18
  139. package/src/validated-form-controls/components/stories/number-control.story.tsx +17 -6
  140. package/src/validated-form-controls/components/stories/overview.mdx +1 -1
  141. package/src/validated-form-controls/components/stories/overview.story.tsx +207 -17
  142. package/src/validated-form-controls/components/stories/radio-control.story.tsx +17 -6
  143. package/src/validated-form-controls/components/stories/range-control.story.tsx +17 -6
  144. package/src/validated-form-controls/components/stories/select-control.story.tsx +17 -6
  145. package/src/validated-form-controls/components/stories/text-control.story.tsx +17 -6
  146. package/src/validated-form-controls/components/stories/textarea-control.story.tsx +17 -6
  147. package/src/validated-form-controls/components/stories/toggle-control.story.tsx +17 -6
  148. package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +17 -6
  149. package/src/validated-form-controls/components/text-control.tsx +5 -3
  150. package/src/validated-form-controls/components/textarea-control.tsx +5 -3
  151. package/src/validated-form-controls/components/toggle-control.tsx +5 -3
  152. package/src/validated-form-controls/components/toggle-group-control.tsx +5 -3
  153. package/src/validated-form-controls/components/types.ts +21 -12
  154. package/src/validated-form-controls/control-with-error.tsx +93 -41
  155. package/src/validated-form-controls/style.scss +19 -5
  156. package/src/validated-form-controls/test/control-with-error.tsx +224 -0
  157. package/src/validated-form-controls/validity-indicator.tsx +48 -0
  158. package/tsconfig.tsbuildinfo +1 -1
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.ControlWithError = void 0;
7
+ var _compose = require("@wordpress/compose");
8
8
  var _i18n = require("@wordpress/i18n");
9
- var _icons = require("@wordpress/icons");
10
9
  var _element = require("@wordpress/element");
11
10
  var _withIgnoreImeEvents = require("../utils/with-ignore-ime-events");
12
- var _icon = _interopRequireDefault(require("../icon"));
11
+ var _validityIndicator = require("./validity-indicator");
13
12
  var _jsxRuntime = require("react/jsx-runtime");
14
13
  /**
15
14
  * WordPress dependencies
16
15
  */
17
16
 
18
- /**
19
- * External dependencies
20
- */
21
-
22
17
  /**
23
18
  * Internal dependencies
24
19
  */
@@ -49,12 +44,15 @@ function appendRequiredIndicator(label, required, markWhenOptional) {
49
44
  function UnforwardedControlWithError({
50
45
  required,
51
46
  markWhenOptional,
52
- customValidator,
47
+ onValidate,
48
+ customValidity,
53
49
  getValidityTarget,
54
50
  children
55
51
  }, forwardedRef) {
56
52
  const [errorMessage, setErrorMessage] = (0, _element.useState)();
53
+ const [statusMessage, setStatusMessage] = (0, _element.useState)();
57
54
  const [isTouched, setIsTouched] = (0, _element.useState)(false);
55
+ const previousCustomValidityType = (0, _compose.usePrevious)(customValidity?.type);
58
56
 
59
57
  // Ensure that error messages are visible after user attemps to submit a form
60
58
  // with multiple invalid fields.
@@ -66,27 +64,66 @@ function UnforwardedControlWithError({
66
64
  validityTarget?.removeEventListener('invalid', showValidationMessage);
67
65
  };
68
66
  });
69
- const validate = () => {
70
- const message = customValidator?.();
67
+ (0, _element.useEffect)(() => {
68
+ if (!isTouched) {
69
+ return;
70
+ }
71
71
  const validityTarget = getValidityTarget();
72
- validityTarget?.setCustomValidity(message !== null && message !== void 0 ? message : '');
73
- setErrorMessage(validityTarget?.validationMessage);
74
- };
72
+ if (!customValidity?.type) {
73
+ validityTarget?.setCustomValidity('');
74
+ setErrorMessage(validityTarget?.validationMessage);
75
+ setStatusMessage(undefined);
76
+ return;
77
+ }
78
+ switch (customValidity.type) {
79
+ case 'validating':
80
+ {
81
+ // Wait before showing a validating state.
82
+ const timer = setTimeout(() => {
83
+ validityTarget?.setCustomValidity('');
84
+ setErrorMessage(undefined);
85
+ setStatusMessage({
86
+ type: 'validating',
87
+ message: customValidity.message
88
+ });
89
+ }, 1000);
90
+ return () => clearTimeout(timer);
91
+ }
92
+ case 'valid':
93
+ {
94
+ // Ensures that we wait for any async responses before showing
95
+ // a synchronously valid state.
96
+ if (previousCustomValidityType === 'valid') {
97
+ break;
98
+ }
99
+ validityTarget?.setCustomValidity('');
100
+ setErrorMessage(validityTarget?.validationMessage);
101
+ setStatusMessage({
102
+ type: 'valid',
103
+ message: customValidity.message
104
+ });
105
+ break;
106
+ }
107
+ case 'invalid':
108
+ {
109
+ var _customValidity$messa;
110
+ validityTarget?.setCustomValidity((_customValidity$messa = customValidity.message) !== null && _customValidity$messa !== void 0 ? _customValidity$messa : '');
111
+ setErrorMessage(validityTarget?.validationMessage);
112
+ setStatusMessage(undefined);
113
+ break;
114
+ }
115
+ }
116
+ }, [isTouched, customValidity?.type, customValidity?.message, getValidityTarget, previousCustomValidityType]);
75
117
  const onBlur = event => {
118
+ if (isTouched) {
119
+ return;
120
+ }
121
+
76
122
  // Only consider "blurred from the component" if focus has fully left the wrapping div.
77
123
  // This prevents unnecessary blurs from components with multiple focusable elements.
78
124
  if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
79
125
  setIsTouched(true);
80
- const validityTarget = getValidityTarget();
81
-
82
- // Prevents a double flash of the native error tooltip when the control is already showing one.
83
- if (!validityTarget?.validity.valid) {
84
- if (!errorMessage) {
85
- setErrorMessage(validityTarget?.validationMessage);
86
- }
87
- return;
88
- }
89
- validate();
126
+ onValidate?.();
90
127
  }
91
128
  };
92
129
  const onChange = (...args) => {
@@ -95,14 +132,14 @@ function UnforwardedControlWithError({
95
132
  // Only validate incrementally if the field has blurred at least once,
96
133
  // or currently has an error message.
97
134
  if (isTouched || errorMessage) {
98
- validate();
135
+ onValidate?.();
99
136
  }
100
137
  };
101
138
  const onKeyDown = event => {
102
139
  // Ensures that custom validators are triggered when the user submits by pressing Enter,
103
140
  // without ever blurring the control.
104
141
  if (event.key === 'Enter') {
105
- validate();
142
+ onValidate?.();
106
143
  }
107
144
  };
108
145
  return (
@@ -118,17 +155,15 @@ function UnforwardedControlWithError({
118
155
  label: appendRequiredIndicator(children.props.label, required, markWhenOptional),
119
156
  onChange,
120
157
  required
121
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
158
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
122
159
  "aria-live": "polite",
123
- children: errorMessage && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
124
- className: "components-validated-control__error",
125
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.default, {
126
- className: "components-validated-control__error-icon",
127
- icon: _icons.error,
128
- size: 16,
129
- fill: "currentColor"
130
- }), errorMessage]
131
- })
160
+ children: [errorMessage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_validityIndicator.ValidityIndicator, {
161
+ type: "invalid",
162
+ message: errorMessage
163
+ }), !errorMessage && statusMessage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_validityIndicator.ValidityIndicator, {
164
+ type: statusMessage.type,
165
+ message: statusMessage.message
166
+ })]
132
167
  })]
133
168
  })
134
169
  );
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","_icons","_element","_withIgnoreImeEvents","_icon","_interopRequireDefault","_jsxRuntime","appendRequiredIndicator","label","required","markWhenOptional","jsxs","Fragment","children","__","UnforwardedControlWithError","customValidator","getValidityTarget","forwardedRef","errorMessage","setErrorMessage","useState","isTouched","setIsTouched","useEffect","validityTarget","showValidationMessage","validationMessage","addEventListener","removeEventListener","validate","message","setCustomValidity","onBlur","event","relatedTarget","currentTarget","contains","validity","valid","onChange","args","props","onKeyDown","key","className","ref","withIgnoreIMEEvents","cloneElement","jsx","default","icon","error","size","fill","ControlWithError","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/control-with-error.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { error } from '@wordpress/icons';\n\n/**\n * External dependencies\n */\nimport {\n\tcloneElement,\n\tforwardRef,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\n\nimport Icon from '../icon';\n\nfunction appendRequiredIndicator(\n\tlabel: React.ReactNode,\n\trequired: boolean | undefined,\n\tmarkWhenOptional: boolean | undefined\n) {\n\tif ( required && ! markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Required' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\tif ( ! required && markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Optional' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\treturn label;\n}\n\n/**\n * HTML elements that support the Constraint Validation API.\n *\n * Here, we exclude HTMLButtonElement because although it does technically support the API,\n * normal buttons are actually exempted from any validation.\n * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate\n */\ntype ValidityTarget =\n\t| HTMLFieldSetElement\n\t| HTMLInputElement\n\t| HTMLSelectElement\n\t| HTMLTextAreaElement;\n\nfunction UnforwardedControlWithError< C extends React.ReactElement >(\n\t{\n\t\trequired,\n\t\tmarkWhenOptional,\n\t\tcustomValidator,\n\t\tgetValidityTarget,\n\t\tchildren,\n\t}: {\n\t\t/**\n\t\t * Whether the control is required.\n\t\t */\n\t\trequired?: boolean;\n\t\t/**\n\t\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t\t */\n\t\tmarkWhenOptional?: boolean;\n\t\t/**\n\t\t * A function that returns a custom validity message when applicable.\n\t\t *\n\t\t * This message will be applied to the element returned by `getValidityTarget`.\n\t\t * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity\n\t\t */\n\t\tcustomValidator?: () => string | void;\n\t\t/**\n\t\t * A function that returns the actual element on which the validity data should be applied.\n\t\t */\n\t\tgetValidityTarget: () => ValidityTarget | null | undefined;\n\t\t/**\n\t\t * The control component to apply validation to.\n\t\t */\n\t\tchildren: C;\n\t},\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst [ errorMessage, setErrorMessage ] = useState< string | undefined >();\n\tconst [ isTouched, setIsTouched ] = useState( false );\n\n\t// Ensure that error messages are visible after user attemps to submit a form\n\t// with multiple invalid fields.\n\tuseEffect( () => {\n\t\tconst validityTarget = getValidityTarget();\n\t\tconst showValidationMessage = () =>\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\tvalidityTarget?.addEventListener( 'invalid', showValidationMessage );\n\n\t\treturn () => {\n\t\t\tvalidityTarget?.removeEventListener(\n\t\t\t\t'invalid',\n\t\t\t\tshowValidationMessage\n\t\t\t);\n\t\t};\n\t} );\n\n\tconst validate = () => {\n\t\tconst message = customValidator?.();\n\t\tconst validityTarget = getValidityTarget();\n\n\t\tvalidityTarget?.setCustomValidity( message ?? '' );\n\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t};\n\n\tconst onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t// Only consider \"blurred from the component\" if focus has fully left the wrapping div.\n\t\t// This prevents unnecessary blurs from components with multiple focusable elements.\n\t\tif (\n\t\t\t! event.relatedTarget ||\n\t\t\t! event.currentTarget.contains( event.relatedTarget )\n\t\t) {\n\t\t\tsetIsTouched( true );\n\n\t\t\tconst validityTarget = getValidityTarget();\n\n\t\t\t// Prevents a double flash of the native error tooltip when the control is already showing one.\n\t\t\tif ( ! validityTarget?.validity.valid ) {\n\t\t\t\tif ( ! errorMessage ) {\n\t\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onChange = ( ...args: unknown[] ) => {\n\t\tchildren.props.onChange?.( ...args );\n\n\t\t// Only validate incrementally if the field has blurred at least once,\n\t\t// or currently has an error message.\n\t\tif ( isTouched || errorMessage ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\tconst onKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t// Ensures that custom validators are triggered when the user submits by pressing Enter,\n\t\t// without ever blurring the control.\n\t\tif ( event.key === 'Enter' ) {\n\t\t\tvalidate();\n\t\t}\n\t};\n\n\treturn (\n\t\t// Disable reason: Just listening to a bubbled event, not for interaction.\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"components-validated-control\"\n\t\t\tref={ forwardedRef }\n\t\t\tonBlur={ onBlur }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( onKeyDown ) }\n\t\t>\n\t\t\t{ cloneElement( children, {\n\t\t\t\tlabel: appendRequiredIndicator(\n\t\t\t\t\tchildren.props.label,\n\t\t\t\t\trequired,\n\t\t\t\t\tmarkWhenOptional\n\t\t\t\t),\n\t\t\t\tonChange,\n\t\t\t\trequired,\n\t\t\t} ) }\n\t\t\t<div aria-live=\"polite\">\n\t\t\t\t{ errorMessage && (\n\t\t\t\t\t<p className=\"components-validated-control__error\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"components-validated-control__error-icon\"\n\t\t\t\t\t\t\ticon={ error }\n\t\t\t\t\t\t\tsize={ 16 }\n\t\t\t\t\t\t\tfill=\"currentColor\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t</p>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport const ControlWithError = forwardRef( Unforward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AS,GAAKT,KAA4C,IAAM;IACrE;IACA;IACA,IAAKA,KAAK,CAACU,GAAG,KAAK,OAAO,EAAG;MAC5Bd,QAAQ,CAAC,CAAC;IACX;EACD,CAAC;EAED;IAAA;IACC;IACA;IACA,IAAAxB,WAAA,CAAAK,IAAA;MACCkC,SAAS,EAAC,8BAA8B;MACxCC,GAAG,EAAG5B,YAAc;MACpBe,MAAM,EAAGA,MAAQ;MACjBU,SAAS,EAAG,IAAAI,wCAAmB,EAAEJ,SAAU,CAAG;MAAA9B,QAAA,GAE5C,IAAAmC,qBAAY,EAAEnC,QAAQ,EAAE;QACzBL,KAAK,EAAED,uBAAuB,CAC7BM,QAAQ,CAAC6B,KAAK,CAAClC,KAAK,EACpBC,QAAQ,EACRC,gBACD,CAAC;QACD8B,QAAQ;QACR/B;MACD,CAAE,CAAC,eACH,IAAAH,WAAA,CAAA2C,GAAA;QAAK,aAAU,QAAQ;QAAApC,QAAA,EACpBM,YAAY,iBACb,IAAAb,WAAA,CAAAK,IAAA;UAAGkC,SAAS,EAAC,qCAAqC;UAAAhC,QAAA,gBACjD,IAAAP,WAAA,CAAA2C,GAAA,EAAC7C,KAAA,CAAA8C,OAAI;YACJL,SAAS,EAAC,0CAA0C;YACpDM,IAAI,EAAGC,YAAO;YACdC,IAAI,EAAG,EAAI;YACXC,IAAI,EAAC;UAAc,CACnB,CAAC,EACAnC,YAAY;QAAA,CACZ;MACH,CACG,CAAC;IAAA,CACF;EAAC;AAER;AAEO,MAAMoC,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,IAAAE,mBAAU,EAAE1C,2BAA4B,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_compose","require","_i18n","_element","_withIgnoreImeEvents","_validityIndicator","_jsxRuntime","appendRequiredIndicator","label","required","markWhenOptional","jsxs","Fragment","children","__","UnforwardedControlWithError","onValidate","customValidity","getValidityTarget","forwardedRef","errorMessage","setErrorMessage","useState","statusMessage","setStatusMessage","isTouched","setIsTouched","previousCustomValidityType","usePrevious","type","useEffect","validityTarget","showValidationMessage","validationMessage","addEventListener","removeEventListener","setCustomValidity","undefined","timer","setTimeout","message","clearTimeout","_customValidity$messa","onBlur","event","relatedTarget","currentTarget","contains","onChange","args","props","onKeyDown","key","className","ref","withIgnoreIMEEvents","cloneElement","jsx","ValidityIndicator","ControlWithError","exports","forwardRef"],"sources":["@wordpress/components/src/validated-form-controls/control-with-error.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcloneElement,\n\tforwardRef,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';\nimport type { ValidatedControlProps } from './components/types';\nimport { ValidityIndicator } from './validity-indicator';\n\nfunction appendRequiredIndicator(\n\tlabel: React.ReactNode,\n\trequired: boolean | undefined,\n\tmarkWhenOptional: boolean | undefined\n) {\n\tif ( required && ! markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Required' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\tif ( ! required && markWhenOptional ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ label } { `(${ __( 'Optional' ) })` }\n\t\t\t</>\n\t\t);\n\t}\n\treturn label;\n}\n\n/**\n * HTML elements that support the Constraint Validation API.\n *\n * Here, we exclude HTMLButtonElement because although it does technically support the API,\n * normal buttons are actually exempted from any validation.\n * @see https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation\n * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement/willValidate\n */\ntype ValidityTarget =\n\t| HTMLFieldSetElement\n\t| HTMLInputElement\n\t| HTMLSelectElement\n\t| HTMLTextAreaElement;\n\nfunction UnforwardedControlWithError< C extends React.ReactElement >(\n\t{\n\t\trequired,\n\t\tmarkWhenOptional,\n\t\tonValidate,\n\t\tcustomValidity,\n\t\tgetValidityTarget,\n\t\tchildren,\n\t}: {\n\t\t/**\n\t\t * Whether the control is required.\n\t\t */\n\t\trequired?: boolean;\n\t\t/**\n\t\t * Label the control as \"optional\" when _not_ `required`, instead of the inverse.\n\t\t */\n\t\tmarkWhenOptional?: boolean;\n\t\t/**\n\t\t * The callback to run when the input should be validated.\n\t\t */\n\t\tonValidate?: () => void;\n\t\tcustomValidity?: ValidatedControlProps< unknown >[ 'customValidity' ];\n\t\t/**\n\t\t * A function that returns the actual element on which the validity data should be applied.\n\t\t */\n\t\tgetValidityTarget: () => ValidityTarget | null | undefined;\n\t\t/**\n\t\t * The control component to apply validation to.\n\t\t */\n\t\tchildren: C;\n\t},\n\tforwardedRef: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst [ errorMessage, setErrorMessage ] = useState< string | undefined >();\n\tconst [ statusMessage, setStatusMessage ] = useState<\n\t\t| {\n\t\t\t\ttype: 'validating' | 'valid';\n\t\t\t\tmessage?: string;\n\t\t }\n\t\t| undefined\n\t>();\n\tconst [ isTouched, setIsTouched ] = useState( false );\n\tconst previousCustomValidityType = usePrevious( customValidity?.type );\n\n\t// Ensure that error messages are visible after user attemps to submit a form\n\t// with multiple invalid fields.\n\tuseEffect( () => {\n\t\tconst validityTarget = getValidityTarget();\n\t\tconst showValidationMessage = () =>\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\tvalidityTarget?.addEventListener( 'invalid', showValidationMessage );\n\n\t\treturn () => {\n\t\t\tvalidityTarget?.removeEventListener(\n\t\t\t\t'invalid',\n\t\t\t\tshowValidationMessage\n\t\t\t);\n\t\t};\n\t} );\n\n\tuseEffect( (): ReturnType< React.EffectCallback > => {\n\t\tif ( ! isTouched ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst validityTarget = getValidityTarget();\n\n\t\tif ( ! customValidity?.type ) {\n\t\t\tvalidityTarget?.setCustomValidity( '' );\n\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\t\t\tsetStatusMessage( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( customValidity.type ) {\n\t\t\tcase 'validating': {\n\t\t\t\t// Wait before showing a validating state.\n\t\t\t\tconst timer = setTimeout( () => {\n\t\t\t\t\tvalidityTarget?.setCustomValidity( '' );\n\t\t\t\t\tsetErrorMessage( undefined );\n\n\t\t\t\t\tsetStatusMessage( {\n\t\t\t\t\t\ttype: 'validating',\n\t\t\t\t\t\tmessage: customValidity.message,\n\t\t\t\t\t} );\n\t\t\t\t}, 1000 );\n\n\t\t\t\treturn () => clearTimeout( timer );\n\t\t\t}\n\t\t\tcase 'valid': {\n\t\t\t\t// Ensures that we wait for any async responses before showing\n\t\t\t\t// a synchronously valid state.\n\t\t\t\tif ( previousCustomValidityType === 'valid' ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tvalidityTarget?.setCustomValidity( '' );\n\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\t\t\tsetStatusMessage( {\n\t\t\t\t\ttype: 'valid',\n\t\t\t\t\tmessage: customValidity.message,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'invalid': {\n\t\t\t\tvalidityTarget?.setCustomValidity(\n\t\t\t\t\tcustomValidity.message ?? ''\n\t\t\t\t);\n\t\t\t\tsetErrorMessage( validityTarget?.validationMessage );\n\n\t\t\t\tsetStatusMessage( undefined );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}, [\n\t\tisTouched,\n\t\tcustomValidity?.type,\n\t\tcustomValidity?.message,\n\t\tgetValidityTarget,\n\t\tpreviousCustomValidityType,\n\t] );\n\n\tconst onBlur = ( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\tif ( isTouched ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Only consider \"blurred from the component\" if focus has fully left the wrapping div.\n\t\t// This prevents unnecessary blurs from components with multiple focusable elements.\n\t\tif (\n\t\t\t! event.relatedTarget ||\n\t\t\t! event.currentTarget.contains( event.relatedTarget )\n\t\t) {\n\t\t\tsetIsTouched( true );\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\tconst onChange = ( ...args: unknown[] ) => {\n\t\tchildren.props.onChange?.( ...args );\n\n\t\t// Only validate incrementally if the field has blurred at least once,\n\t\t// or currently has an error message.\n\t\tif ( isTouched || errorMessage ) {\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\tconst onKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t// Ensures that custom validators are triggered when the user submits by pressing Enter,\n\t\t// without ever blurring the control.\n\t\tif ( event.key === 'Enter' ) {\n\t\t\tonValidate?.();\n\t\t}\n\t};\n\n\treturn (\n\t\t// Disable reason: Just listening to a bubbled event, not for interaction.\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName=\"components-validated-control\"\n\t\t\tref={ forwardedRef }\n\t\t\tonBlur={ onBlur }\n\t\t\tonKeyDown={ withIgnoreIMEEvents( onKeyDown ) }\n\t\t>\n\t\t\t{ cloneElement( children, {\n\t\t\t\tlabel: appendRequiredIndicator(\n\t\t\t\t\tchildren.props.label,\n\t\t\t\t\trequired,\n\t\t\t\t\tmarkWhenOptional\n\t\t\t\t),\n\t\t\t\tonChange,\n\t\t\t\trequired,\n\t\t\t} ) }\n\t\t\t<div aria-live=\"polite\">\n\t\t\t\t{ errorMessage && (\n\t\t\t\t\t<ValidityIndicator\n\t\t\t\t\t\ttype=\"invalid\"\n\t\t\t\t\t\tmessage={ errorMessage }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ! errorMessage && statusMessage && (\n\t\t\t\t\t<ValidityIndicator\n\t\t\t\t\t\ttype={ statusMessage.type }\n\t\t\t\t\t\tmessage={ statusMessage.message }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport const ControlWithError = forwardRef( UnforwardedContro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C,SAAS,EAAC,8BAA8B;MACxCC,GAAG,EAAGnC,YAAc;MACpBwB,MAAM,EAAGA,MAAQ;MACjBQ,SAAS,EAAG,IAAAI,wCAAmB,EAAEJ,SAAU,CAAG;MAAAtC,QAAA,GAE5C,IAAA2C,qBAAY,EAAE3C,QAAQ,EAAE;QACzBL,KAAK,EAAED,uBAAuB,CAC7BM,QAAQ,CAACqC,KAAK,CAAC1C,KAAK,EACpBC,QAAQ,EACRC,gBACD,CAAC;QACDsC,QAAQ;QACRvC;MACD,CAAE,CAAC,eACH,IAAAH,WAAA,CAAAK,IAAA;QAAK,aAAU,QAAQ;QAAAE,QAAA,GACpBO,YAAY,iBACb,IAAAd,WAAA,CAAAmD,GAAA,EAACpD,kBAAA,CAAAqD,iBAAiB;UACjB7B,IAAI,EAAC,SAAS;UACdW,OAAO,EAAGpB;QAAc,CACxB,CACD,EACC,CAAEA,YAAY,IAAIG,aAAa,iBAChC,IAAAjB,WAAA,CAAAmD,GAAA,EAACpD,kBAAA,CAAAqD,iBAAiB;UACjB7B,IAAI,EAAGN,aAAa,CAACM,IAAM;UAC3BW,OAAO,EAAGjB,aAAa,CAACiB;QAAS,CACjC,CACD;MAAA,CACG,CAAC;IAAA,CACF;EAAC;AAER;AAEO,MAAMmB,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,IAAAE,mBAAU,EAAE9C,2BAA4B,CAAC","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ValidityIndicator = ValidityIndicator;
8
+ var _clsx = _interopRequireDefault(require("clsx"));
9
+ var _icons = require("@wordpress/icons");
10
+ var _icon = _interopRequireDefault(require("../icon"));
11
+ var _spinner = _interopRequireDefault(require("../spinner"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /**
14
+ * External dependencies
15
+ */
16
+
17
+ /**
18
+ * WordPress dependencies
19
+ */
20
+
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+
25
+ function ValidityIndicator({
26
+ type,
27
+ message
28
+ }) {
29
+ const ICON = {
30
+ valid: _icons.published,
31
+ invalid: _icons.error
32
+ };
33
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
34
+ className: (0, _clsx.default)('components-validated-control__indicator', `is-${type}`),
35
+ children: [type === 'validating' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_spinner.default, {
36
+ className: "components-validated-control__indicator-spinner"
37
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.default, {
38
+ className: "components-validated-control__indicator-icon",
39
+ icon: ICON[type],
40
+ size: 16,
41
+ fill: "currentColor"
42
+ }), message]
43
+ });
44
+ }
45
+ //# sourceMappingURL=validity-indicator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_clsx","_interopRequireDefault","require","_icons","_icon","_spinner","_jsxRuntime","ValidityIndicator","type","message","ICON","valid","published","invalid","error","jsxs","className","clsx","children","jsx","default","icon","size","fill"],"sources":["@wordpress/components/src/validated-form-controls/validity-indicator.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { error, published } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport Icon from '../icon';\nimport Spinner from '../spinner';\n\nexport function ValidityIndicator( {\n\ttype,\n\tmessage,\n}: {\n\ttype: 'validating' | 'valid' | 'invalid';\n\tmessage?: string;\n} ) {\n\tconst ICON = {\n\t\tvalid: published,\n\t\tinvalid: error,\n\t};\n\treturn (\n\t\t<p\n\t\t\tclassName={ clsx(\n\t\t\t\t'components-validated-control__indicator',\n\t\t\t\t`is-${ type }`\n\t\t\t) }\n\t\t>\n\t\t\t{ type === 'validating' ? (\n\t\t\t\t<Spinner className=\"components-validated-control__indicator-spinner\" />\n\t\t\t) : (\n\t\t\t\t<Icon\n\t\t\t\t\tclassName=\"components-validated-control__indicator-icon\"\n\t\t\t\t\ticon={ ICON[ type ] }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t\tfill=\"currentColor\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ message }\n\t\t</p>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAiC,IAAAI,WAAA,GAAAJ,OAAA;AAdjC;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAIO,SAASK,iBAAiBA,CAAE;EAClCC,IAAI;EACJC;AAID,CAAC,EAAG;EACH,MAAMC,IAAI,GAAG;IACZC,KAAK,EAAEC,gBAAS;IAChBC,OAAO,EAAEC;EACV,CAAC;EACD,oBACC,IAAAR,WAAA,CAAAS,IAAA;IACCC,SAAS,EAAG,IAAAC,aAAI,EACf,yCAAyC,EACzC,MAAOT,IAAI,EACZ,CAAG;IAAAU,QAAA,GAEDV,IAAI,KAAK,YAAY,gBACtB,IAAAF,WAAA,CAAAa,GAAA,EAACd,QAAA,CAAAe,OAAO;MAACJ,SAAS,EAAC;IAAiD,CAAE,CAAC,gBAEvE,IAAAV,WAAA,CAAAa,GAAA,EAACf,KAAA,CAAAgB,OAAI;MACJJ,SAAS,EAAC,8CAA8C;MACxDK,IAAI,EAAGX,IAAI,CAAEF,IAAI,CAAI;MACrBc,IAAI,EAAG,EAAI;MACXC,IAAI,EAAC;IAAc,CACnB,CACD,EACCd,OAAO;EAAA,CACP,CAAC;AAEN","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","warn","CONNECT_STATIC_NAMESPACE","getStyledClassNameFromKey","contextConnect","Component","namespace","_contextConnect","forwardsRef","contextConnectWithoutRef","options","WrappedComponent","globalThis","SCRIPT_DEBUG","mergedNamespace","Array","isArray","Object","assign","Set","displayName","selector","getConnectNamespace","namespaces","type","hasConnectNamespace","match","includes","some","result"],"sources":["@wordpress/components/src/context/context-connect.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef, ReactChild, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\nimport warn from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { CONNECT_STATIC_NAMESPACE } from './constants';\nimport { getStyledClassNameFromKey } from './get-styled-class-name-from-key';\nimport type { WordPressComponentFromProps } from '.';\n\ntype AcceptsTwoArgs<\n\tF extends ( ...args: any ) => any,\n\tErrorMessage = never,\n> = Parameters< F >[ 'length' ] extends 2 ? {} : ErrorMessage;\n\ntype ContextConnectOptions = {\n\tforwardsRef?: boolean;\n};\n\n/**\n * Forwards ref (React.ForwardRef) and \"Connects\" (or registers) a component\n * within the Context system under a specified namespace.\n *\n * @param Component The component to register into the Context system.\n * @param namespace The namespace to register the component under.\n * @return The connected WordPressComponent\n */\nexport function contextConnect<\n\tC extends ( props: any, ref: ForwardedRef< any > ) => JSX.Element | null,\n>(\n\tComponent: C &\n\t\tAcceptsTwoArgs<\n\t\t\tC,\n\t\t\t'Warning: Your component function does not take a ref as the second argument. Did you mean to use `contextConnectWithoutRef`?'\n\t\t>,\n\tnamespace: string\n) {\n\treturn _contextConnect( Component, namespace, { forwardsRef: true } );\n}\n\n/**\n * \"Connects\" (or registers) a component within the Context system under a specified namespace.\n * Does not forward a ref.\n *\n * @param Component The component to register into the Context system.\n * @param namespace The namespace to register the component under.\n * @return The connected WordPressComponent\n */\nexport function contextConnectWithoutRef< P >(\n\tComponent: ( props: P ) => JSX.Element | null,\n\tnamespace: string\n) {\n\treturn _contextConnect( Component, namespace );\n}\n\n// This is an (experimental) evolution of the initial connect() HOC.\n// The hope is that we can improve render performance by removing functional\n// component wrappers.\nfunction _contextConnect<\n\tC extends ( props: any, ref: ForwardedRef< any > ) => JSX.Element | null,\n\tO extends ContextConnectOptions,\n>(\n\tComponent: C,\n\tnamespace: string,\n\toptions?: O\n): WordPressComponentFromProps<\n\tParameters< C >[ 0 ],\n\tO[ 'forwardsRef' ] extends true ? true : false\n> {\n\tconst WrappedComponent = options?.forwardsRef\n\t\t? forwardRef< any, Parameters< C >[ 0 ] >( Component )\n\t\t: Component;\n\n\tif ( typeof namespace === 'undefined' ) {\n\t\twarn( 'contextConnect: Please provide a namespace' );\n\t}\n\n\t// @ts-expect-error internal property\n\tlet mergedNamespace = WrappedComponent[ CONNECT_STATIC_NAMESPACE ] || [\n\t\tnamespace,\n\t];\n\n\t/**\n\t * Consolidate (merge) namespaces before attaching it to the WrappedComponent.\n\t */\n\tif ( Array.isArray( namespace ) ) {\n\t\tmergedNamespace = [ ...mergedNamespace, ...namespace ];\n\t}\n\tif ( typeof namespace === 'string' ) {\n\t\tmergedNamespace = [ ...mergedNamespace, namespace ];\n\t}\n\n\t// @ts-expect-error We can't rely on inferred types here because of the\n\t// `as` prop polymorphism we're handling in https://github.com/WordPress/gutenberg/blob/4f3a11243c365f94892e479bff0b922ccc4ccda3/packages/components/src/context/wordpress-component.ts#L32-L33\n\treturn Object.assign( WrappedComponent, {\n\t\t[ CONNECT_STATIC_NAMESPACE ]: [ ...new Set( mergedNamespace ) ],\n\t\tdisplayName: namespace,\n\t\tselector: `.${ getStyledClassNameFromKey( namespace ) }`,\n\t} );\n}\n\n/**\n * Attempts to retrieve the connected namespace from a component.\n *\n * @param Component The component to retrieve a namespace from.\n * @return The connected namespaces.\n */\nexport function getConnectNamespace(\n\tComponent: ReactChild | undefined | {}\n): string[] {\n\tif ( ! Component ) {\n\t\treturn [];\n\t}\n\n\tlet namespaces = [];\n\n\t// @ts-ignore internal property\n\tif ( Component[ CONNECT_STATIC_NAMESPACE ] ) {\n\t\t// @ts-ignore internal property\n\t\tnamespaces = Component[ CONNECT_STATIC_NAMESPACE ];\n\t}\n\n\t// @ts-ignore\n\tif ( Component.type && Component.type[ CONNECT_STATIC_NAMESPACE ] ) {\n\t\t// @ts-ignore\n\t\tnamespaces = Component.type[ CONNECT_STATIC_NAMESPACE ];\n\t}\n\n\treturn namespaces;\n}\n\n/**\n * Checks to see if a component is connected within the Context system.\n *\n * @param Component The component to retrieve a namespace from.\n * @param match The namespace to check.\n */\nexport function hasConnectNamespace(\n\tComponent: ReactNode,\n\tmatch: string[] | string\n): boolean {\n\tif ( ! Component ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof match === 'string' ) {\n\t\treturn getConnectNamespace( Component ).includes( match );\n\t}\n\tif ( Array.isArray( match ) ) {\n\t\treturn match.some( ( result ) =>\n\t\t\tgetConnectNamespace( Component ).includes( result )\n\t\t);\n\t}\n\n\treturn false;\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;AAC/C,OAAOC,IAAI,MAAM,oBAAoB;;AAErC;AACA;AACA;AACA,SAASC,wBAAwB,QAAQ,aAAa;AACtD,SAASC,yBAAyB,QAAQ,kCAAkC;AAY5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAG7BC,SAIE,EACFC,SAAiB,EAChB;EACD,OAAOC,eAAe,CAAEF,SAAS,EAAEC,SAAS,EAAE;IAAEE,WAAW,EAAE;EAAK,CAAE,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,wBAAwBA,CACvCJ,SAA6C,EAC7CC,SAAiB,EAChB;EACD,OAAOC,eAAe,CAAEF,SAAS,EAAEC,SAAU,CAAC;AAC/C;;AAEA;AACA;AACA;AACA,SAASC,eAAeA,CAIvBF,SAAY,EACZC,SAAiB,EACjBI,OAAW,EAIV;EACD,MAAMC,gBAAgB,GAAGD,OAAO,EAAEF,WAAW,GAC1CR,UAAU,CAA+BK,SAAU,CAAC,GACpDA,SAAS;EAEZ,IAAK,OAAOC,SAAS,KA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KAAwB,EACd;EACV,IAAK,CAAErB,SAAS,EAAG;IAClB,OAAO,KAAK;EACb;EAEA,IAAK,OAAOqB,KAAK,KAAK,QAAQ,EAAG;IAChC,OAAOJ,mBAAmB,CAAEjB,SAAU,CAAC,CAACsB,QAAQ,CAAED,KAAM,CAAC;EAC1D;EACA,IAAKX,KAAK,CAACC,OAAO,CAAEU,KAAM,CAAC,EAAG;IAC7B,OAAOA,KAAK,CAACE,IAAI,CAAIC,MAAM,IAC1BP,mBAAmB,CAAEjB,SAAU,CAAC,CAACsB,QAAQ,CAAEE,MAAO,CACnD,CAAC;EACF;EAEA,OAAO,KAAK;AACb","ignoreList":[]}
1
+ {"version":3,"names":["forwardRef","warn","CONNECT_STATIC_NAMESPACE","getStyledClassNameFromKey","contextConnect","Component","namespace","_contextConnect","forwardsRef","contextConnectWithoutRef","options","WrappedComponent","globalThis","SCRIPT_DEBUG","mergedNamespace","Array","isArray","Object","assign","Set","displayName","selector","getConnectNamespace","namespaces","type","hasConnectNamespace","match","includes","some","result"],"sources":["@wordpress/components/src/context/context-connect.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef, ReactElement, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\nimport warn from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport { CONNECT_STATIC_NAMESPACE } from './constants';\nimport { getStyledClassNameFromKey } from './get-styled-class-name-from-key';\nimport type { WordPressComponentFromProps } from '.';\n\ntype AcceptsTwoArgs<\n\tF extends ( ...args: any ) => any,\n\tErrorMessage = never,\n> = Parameters< F >[ 'length' ] extends 2 ? {} : ErrorMessage;\n\ntype ContextConnectOptions = {\n\tforwardsRef?: boolean;\n};\n\n/**\n * Forwards ref (React.ForwardRef) and \"Connects\" (or registers) a component\n * within the Context system under a specified namespace.\n *\n * @param Component The component to register into the Context system.\n * @param namespace The namespace to register the component under.\n * @return The connected WordPressComponent\n */\nexport function contextConnect<\n\tC extends ( props: any, ref: ForwardedRef< any > ) => JSX.Element | null,\n>(\n\tComponent: C &\n\t\tAcceptsTwoArgs<\n\t\t\tC,\n\t\t\t'Warning: Your component function does not take a ref as the second argument. Did you mean to use `contextConnectWithoutRef`?'\n\t\t>,\n\tnamespace: string\n) {\n\treturn _contextConnect( Component, namespace, { forwardsRef: true } );\n}\n\n/**\n * \"Connects\" (or registers) a component within the Context system under a specified namespace.\n * Does not forward a ref.\n *\n * @param Component The component to register into the Context system.\n * @param namespace The namespace to register the component under.\n * @return The connected WordPressComponent\n */\nexport function contextConnectWithoutRef< P >(\n\tComponent: ( props: P ) => JSX.Element | null,\n\tnamespace: string\n) {\n\treturn _contextConnect( Component, namespace );\n}\n\n// This is an (experimental) evolution of the initial connect() HOC.\n// The hope is that we can improve render performance by removing functional\n// component wrappers.\nfunction _contextConnect<\n\tC extends ( props: any, ref: ForwardedRef< any > ) => JSX.Element | null,\n\tO extends ContextConnectOptions,\n>(\n\tComponent: C,\n\tnamespace: string,\n\toptions?: O\n): WordPressComponentFromProps<\n\tParameters< C >[ 0 ],\n\tO[ 'forwardsRef' ] extends true ? true : false\n> {\n\tconst WrappedComponent = options?.forwardsRef\n\t\t? forwardRef< any, Parameters< C >[ 0 ] >( Component )\n\t\t: Component;\n\n\tif ( typeof namespace === 'undefined' ) {\n\t\twarn( 'contextConnect: Please provide a namespace' );\n\t}\n\n\t// @ts-expect-error internal property\n\tlet mergedNamespace = WrappedComponent[ CONNECT_STATIC_NAMESPACE ] || [\n\t\tnamespace,\n\t];\n\n\t/**\n\t * Consolidate (merge) namespaces before attaching it to the WrappedComponent.\n\t */\n\tif ( Array.isArray( namespace ) ) {\n\t\tmergedNamespace = [ ...mergedNamespace, ...namespace ];\n\t}\n\tif ( typeof namespace === 'string' ) {\n\t\tmergedNamespace = [ ...mergedNamespace, namespace ];\n\t}\n\n\t// @ts-expect-error We can't rely on inferred types here because of the\n\t// `as` prop polymorphism we're handling in https://github.com/WordPress/gutenberg/blob/4f3a11243c365f94892e479bff0b922ccc4ccda3/packages/components/src/context/wordpress-component.ts#L32-L33\n\treturn Object.assign( WrappedComponent, {\n\t\t[ CONNECT_STATIC_NAMESPACE ]: [ ...new Set( mergedNamespace ) ],\n\t\tdisplayName: namespace,\n\t\tselector: `.${ getStyledClassNameFromKey( namespace ) }`,\n\t} );\n}\n\n/**\n * Attempts to retrieve the connected namespace from a component.\n *\n * @param Component The component to retrieve a namespace from.\n * @return The connected namespaces.\n */\nexport function getConnectNamespace(\n\tComponent: ReactElement | number | string | undefined | {}\n): string[] {\n\tif ( ! Component ) {\n\t\treturn [];\n\t}\n\n\tlet namespaces = [];\n\n\t// @ts-ignore internal property\n\tif ( Component[ CONNECT_STATIC_NAMESPACE ] ) {\n\t\t// @ts-ignore internal property\n\t\tnamespaces = Component[ CONNECT_STATIC_NAMESPACE ];\n\t}\n\n\t// @ts-ignore\n\tif ( Component.type && Component.type[ CONNECT_STATIC_NAMESPACE ] ) {\n\t\t// @ts-ignore\n\t\tnamespaces = Component.type[ CONNECT_STATIC_NAMESPACE ];\n\t}\n\n\treturn namespaces;\n}\n\n/**\n * Checks to see if a component is connected within the Context system.\n *\n * @param Component The component to retrieve a namespace from.\n * @param match The namespace to check.\n */\nexport function hasConnectNamespace(\n\tComponent: ReactNode,\n\tmatch: string[] | string\n): boolean {\n\tif ( ! Component ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof match === 'string' ) {\n\t\treturn getConnectNamespace( Component ).includes( match );\n\t}\n\tif ( Array.isArray( match ) ) {\n\t\treturn match.some( ( result ) =>\n\t\t\tgetConnectNamespace( Component ).includes( result )\n\t\t);\n\t}\n\n\treturn false;\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;AAC/C,OAAOC,IAAI,MAAM,oBAAoB;;AAErC;AACA;AACA;AACA,SAASC,wBAAwB,QAAQ,aAAa;AACtD,SAASC,yBAAyB,QAAQ,kCAAkC;AAY5E;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A;AACA;AACA;AACA;AACA;AACA,OAAO,SAASgB,mBAAmBA,CAClCjB,SAA0D,EAC/C;EACX,IAAK,CAAEA,SAAS,EAAG;IAClB,OAAO,EAAE;EACV;EAEA,IAAIkB,UAAU,GAAG,EAAE;;EAEnB;EACA,IAAKlB,SAAS,CAAEH,wBAAwB,CAAE,EAAG;IAC5C;IACAqB,UAAU,GAAGlB,SAAS,CAAEH,wBAAwB,CAAE;EACnD;;EAEA;EACA,IAAKG,SAAS,CAACmB,IAAI,IAAInB,SAAS,CAACmB,IAAI,CAAEtB,wBAAwB,CAAE,EAAG;IACnE;IACAqB,UAAU,GAAGlB,SAAS,CAACmB,IAAI,CAAEtB,wBAAwB,CAAE;EACxD;EAEA,OAAOqB,UAAU;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,mBAAmBA,CAClCpB,SAAoB,EACpBqB,KAAwB,EACd;EACV,IAAK,CAAErB,SAAS,EAAG;IAClB,OAAO,KAAK;EACb;EAEA,IAAK,OAAOqB,KAAK,KAAK,QAAQ,EAAG;IAChC,OAAOJ,mBAAmB,CAAEjB,SAAU,CAAC,CAACsB,QAAQ,CAAED,KAAM,CAAC;EAC1D;EACA,IAAKX,KAAK,CAACC,OAAO,CAAEU,KAAM,CAAC,EAAG;IAC7B,OAAOA,KAAK,CAACE,IAAI,CAAIC,MAAM,IAC1BP,mBAAmB,CAAEjB,SAAU,CAAC,CAACsB,QAAQ,CAAEE,MAAO,CACnD,CAAC;EACF;EAEA,OAAO,KAAK;AACb","ignoreList":[]}
@@ -58,6 +58,7 @@ function UnforwardedMenuItem(props, ref) {
58
58
  role: role,
59
59
  icon: iconPosition === 'left' ? icon : undefined,
60
60
  className: className,
61
+ accessibleWhenDisabled: true,
61
62
  ...buttonProps,
62
63
  children: [/*#__PURE__*/_jsx("span", {
63
64
  className: "components-menu-item__item",
@@ -1 +1 @@
1
- {"version":3,"names":["clsx","cloneElement","forwardRef","Shortcut","Button","Icon","jsx","_jsx","jsxs","_jsxs","UnforwardedMenuItem","props","ref","children","info","className","icon","iconPosition","shortcut","isSelected","role","suffix","buttonProps","__next40pxDefaultSize","undefined","MenuItem"],"sources":["@wordpress/components/src/menu-item/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { cloneElement, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Shortcut from '../shortcut';\nimport Button from '../button';\nimport Icon from '../icon';\nimport type { WordPressComponentProps } from '../context';\nimport type { MenuItemProps } from './types';\n\nfunction UnforwardedMenuItem(\n\tprops: WordPressComponentProps< MenuItemProps, 'button', false >,\n\tref: ForwardedRef< HTMLButtonElement >\n) {\n\tlet {\n\t\tchildren,\n\t\tinfo,\n\t\tclassName,\n\t\ticon,\n\t\ticonPosition = 'right',\n\t\tshortcut,\n\t\tisSelected,\n\t\trole = 'menuitem',\n\t\tsuffix,\n\t\t...buttonProps\n\t} = props;\n\n\tclassName = clsx( 'components-menu-item__button', className );\n\n\tif ( info ) {\n\t\tchildren = (\n\t\t\t<span className=\"components-menu-item__info-wrapper\">\n\t\t\t\t<span className=\"components-menu-item__item\">{ children }</span>\n\t\t\t\t<span className=\"components-menu-item__info\">{ info }</span>\n\t\t\t</span>\n\t\t);\n\t}\n\n\tif ( icon && typeof icon !== 'string' ) {\n\t\ticon = cloneElement( icon, {\n\t\t\tclassName: clsx( 'components-menu-items__item-icon', {\n\t\t\t\t'has-icon-right': iconPosition === 'right',\n\t\t\t} ),\n\t\t} );\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tref={ ref }\n\t\t\t// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked\n\t\t\taria-checked={\n\t\t\t\trole === 'menuitemcheckbox' || role === 'menuitemradio'\n\t\t\t\t\t? isSelected\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\trole={ role }\n\t\t\ticon={ iconPosition === 'left' ? icon : undefined }\n\t\t\tclassName={ className }\n\t\t\t{ ...buttonProps }\n\t\t>\n\t\t\t<span className=\"components-menu-item__item\">{ children }</span>\n\t\t\t{ ! suffix && (\n\t\t\t\t<Shortcut\n\t\t\t\t\tclassName=\"components-menu-item__shortcut\"\n\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! suffix && icon && iconPosition === 'right' && (\n\t\t\t\t<Icon icon={ icon } />\n\t\t\t) }\n\t\t\t{ suffix }\n\t\t</Button>\n\t);\n}\n\n/**\n * MenuItem is a component which renders a button intended to be used in combination with the `DropdownMenu` component.\n *\n * ```jsx\n * import { MenuItem } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyMenuItem = () => {\n * \tconst [ isActive, setIsActive ] = useState( true );\n *\n * \treturn (\n * \t\t<MenuItem\n * \t\t\ticon={ isActive ? 'yes' : 'no' }\n * \t\t\tisSelected={ isActive }\n * \t\t\trole=\"menuitemcheckbox\"\n * \t\t\tonClick={ () => setIsActive( ( state ) => ! state ) }\n * \t\t>\n * \t\t\tToggle\n * \t\t</MenuItem>\n * \t);\n * };\n * ```\n */\nexport const MenuItem = forwardRef( UnforwardedMenuItem );\n\nexport default MenuItem;\n"],"mappings":"AAAA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,YAAY,EAAEC,UAAU,QAAQ,oBAAoB;;AAE7D;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,aAAa;AAClC,OAAOC,MAAM,MAAM,WAAW;AAC9B,OAAOC,IAAI,MAAM,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAI3B,SAASC,mBAAmBA,CAC3BC,KAAgE,EAChEC,GAAsC,EACrC;EACD,IAAI;IACHC,QAAQ;IACRC,IAAI;IACJC,SAAS;IACTC,IAAI;IACJC,Y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,YAAY,KAAK,OAAO,iBAC7CV,IAAA,CAACF,IAAI;MAACW,IAAI,EAAGA;IAAM,CAAE,CACrB,EACCK,MAAM;EAAA,CACD,CAAC;AAEX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,QAAQ,GAAGvB,UAAU,CAAEQ,mBAAoB,CAAC;AAEzD,eAAee,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["clsx","cloneElement","forwardRef","Shortcut","Button","Icon","jsx","_jsx","jsxs","_jsxs","UnforwardedMenuItem","props","ref","children","info","className","icon","iconPosition","shortcut","isSelected","role","suffix","buttonProps","__next40pxDefaultSize","undefined","accessibleWhenDisabled","MenuItem"],"sources":["@wordpress/components/src/menu-item/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { cloneElement, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Shortcut from '../shortcut';\nimport Button from '../button';\nimport Icon from '../icon';\nimport type { WordPressComponentProps } from '../context';\nimport type { MenuItemProps } from './types';\n\nfunction UnforwardedMenuItem(\n\tprops: WordPressComponentProps< MenuItemProps, 'button', false >,\n\tref: ForwardedRef< HTMLButtonElement >\n) {\n\tlet {\n\t\tchildren,\n\t\tinfo,\n\t\tclassName,\n\t\ticon,\n\t\ticonPosition = 'right',\n\t\tshortcut,\n\t\tisSelected,\n\t\trole = 'menuitem',\n\t\tsuffix,\n\t\t...buttonProps\n\t} = props;\n\n\tclassName = clsx( 'components-menu-item__button', className );\n\n\tif ( info ) {\n\t\tchildren = (\n\t\t\t<span className=\"components-menu-item__info-wrapper\">\n\t\t\t\t<span className=\"components-menu-item__item\">{ children }</span>\n\t\t\t\t<span className=\"components-menu-item__info\">{ info }</span>\n\t\t\t</span>\n\t\t);\n\t}\n\n\tif ( icon && typeof icon !== 'string' ) {\n\t\ticon = cloneElement( icon, {\n\t\t\tclassName: clsx( 'components-menu-items__item-icon', {\n\t\t\t\t'has-icon-right': iconPosition === 'right',\n\t\t\t} ),\n\t\t} );\n\t}\n\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tref={ ref }\n\t\t\t// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked\n\t\t\taria-checked={\n\t\t\t\trole === 'menuitemcheckbox' || role === 'menuitemradio'\n\t\t\t\t\t? isSelected\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\trole={ role }\n\t\t\ticon={ iconPosition === 'left' ? icon : undefined }\n\t\t\tclassName={ className }\n\t\t\taccessibleWhenDisabled\n\t\t\t{ ...buttonProps }\n\t\t>\n\t\t\t<span className=\"components-menu-item__item\">{ children }</span>\n\t\t\t{ ! suffix && (\n\t\t\t\t<Shortcut\n\t\t\t\t\tclassName=\"components-menu-item__shortcut\"\n\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! suffix && icon && iconPosition === 'right' && (\n\t\t\t\t<Icon icon={ icon } />\n\t\t\t) }\n\t\t\t{ suffix }\n\t\t</Button>\n\t);\n}\n\n/**\n * MenuItem is a component which renders a button intended to be used in combination with the `DropdownMenu` component.\n *\n * ```jsx\n * import { MenuItem } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyMenuItem = () => {\n * \tconst [ isActive, setIsActive ] = useState( true );\n *\n * \treturn (\n * \t\t<MenuItem\n * \t\t\ticon={ isActive ? 'yes' : 'no' }\n * \t\t\tisSelected={ isActive }\n * \t\t\trole=\"menuitemcheckbox\"\n * \t\t\tonClick={ () => setIsActive( ( state ) => ! state ) }\n * \t\t>\n * \t\t\tToggle\n * \t\t</MenuItem>\n * \t);\n * };\n * ```\n */\nexport const MenuItem = forwardRef( UnforwardedMenuItem );\n\nexport default MenuItem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