@wordpress/components 33.1.1-next.v.202605131032.0 → 35.0.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 (287) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/build/autocomplete/index.cjs +5 -4
  3. package/build/autocomplete/index.cjs.map +3 -3
  4. package/build/box-control/index.cjs +0 -6
  5. package/build/box-control/index.cjs.map +2 -2
  6. package/build/box-control/utils.cjs +0 -38
  7. package/build/box-control/utils.cjs.map +3 -3
  8. package/build/custom-gradient-picker/gradient-bar/index.cjs.map +2 -2
  9. package/build/draggable/index.cjs +101 -7
  10. package/build/draggable/index.cjs.map +3 -3
  11. package/build/form-token-field/index.cjs +41 -7
  12. package/build/form-token-field/index.cjs.map +2 -2
  13. package/build/index.cjs +0 -17
  14. package/build/index.cjs.map +2 -2
  15. package/build/notice/index.cjs +33 -35
  16. package/build/notice/index.cjs.map +2 -2
  17. package/build/popover/index.cjs +12 -0
  18. package/build/popover/index.cjs.map +2 -2
  19. package/build/tabs/styles.cjs +5 -5
  20. package/build/tabs/styles.cjs.map +2 -2
  21. package/build-module/autocomplete/index.mjs +6 -5
  22. package/build-module/autocomplete/index.mjs.map +2 -2
  23. package/build-module/box-control/index.mjs +0 -2
  24. package/build-module/box-control/index.mjs.map +2 -2
  25. package/build-module/box-control/utils.mjs +0 -27
  26. package/build-module/box-control/utils.mjs.map +2 -2
  27. package/build-module/custom-gradient-picker/gradient-bar/index.mjs.map +2 -2
  28. package/build-module/draggable/index.mjs +101 -7
  29. package/build-module/draggable/index.mjs.map +3 -3
  30. package/build-module/form-token-field/index.mjs +41 -7
  31. package/build-module/form-token-field/index.mjs.map +2 -2
  32. package/build-module/index.mjs +87 -99
  33. package/build-module/index.mjs.map +2 -2
  34. package/build-module/notice/index.mjs +34 -36
  35. package/build-module/notice/index.mjs.map +2 -2
  36. package/build-module/popover/index.mjs +12 -0
  37. package/build-module/popover/index.mjs.map +2 -2
  38. package/build-module/tabs/styles.mjs +5 -5
  39. package/build-module/tabs/styles.mjs.map +2 -2
  40. package/build-style/style-rtl.css +64 -66
  41. package/build-style/style.css +64 -66
  42. package/build-types/autocomplete/index.d.ts.map +1 -1
  43. package/build-types/badge/stories/e2e/index.story.d.ts +7 -0
  44. package/build-types/badge/stories/e2e/index.story.d.ts.map +1 -0
  45. package/build-types/box-control/index.d.ts +0 -1
  46. package/build-types/box-control/index.d.ts.map +1 -1
  47. package/build-types/box-control/styles/box-control-styles.d.ts +1 -2
  48. package/build-types/box-control/styles/box-control-styles.d.ts.map +1 -1
  49. package/build-types/box-control/utils.d.ts +0 -13
  50. package/build-types/box-control/utils.d.ts.map +1 -1
  51. package/build-types/button/stories/e2e/index.story.d.ts +1 -0
  52. package/build-types/button/stories/e2e/index.story.d.ts.map +1 -1
  53. package/build-types/color-picker/styles.d.ts +1 -2
  54. package/build-types/color-picker/styles.d.ts.map +1 -1
  55. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
  56. package/build-types/draggable/index.d.ts.map +1 -1
  57. package/build-types/draggable/stories/index.story.d.ts +4 -5
  58. package/build-types/draggable/stories/index.story.d.ts.map +1 -1
  59. package/build-types/draggable/types.d.ts +4 -0
  60. package/build-types/draggable/types.d.ts.map +1 -1
  61. package/build-types/form-token-field/index.d.ts.map +1 -1
  62. package/build-types/icon/stories/index.story.d.ts +0 -6
  63. package/build-types/icon/stories/index.story.d.ts.map +1 -1
  64. package/build-types/index.d.ts +1 -6
  65. package/build-types/index.d.ts.map +1 -1
  66. package/build-types/notice/index.d.ts.map +1 -1
  67. package/build-types/notice/types.d.ts +1 -2
  68. package/build-types/notice/types.d.ts.map +1 -1
  69. package/build-types/popover/index.d.ts.map +1 -1
  70. package/build-types/range-control/index.d.ts +1 -2
  71. package/build-types/range-control/index.d.ts.map +1 -1
  72. package/build-types/range-control/stories/index.story.d.ts.map +1 -1
  73. package/build-types/range-control/types.d.ts +0 -4
  74. package/build-types/range-control/types.d.ts.map +1 -1
  75. package/build-types/tab-panel/stories/index.story.d.ts +0 -6
  76. package/build-types/tab-panel/stories/index.story.d.ts.map +1 -1
  77. package/build-types/tabs/stories/index.story.d.ts +0 -6
  78. package/build-types/tabs/stories/index.story.d.ts.map +1 -1
  79. package/build-types/tabs/styles.d.ts.map +1 -1
  80. package/build-types/validated-form-controls/components/range-control.d.ts +1 -2
  81. package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -1
  82. package/package.json +24 -22
  83. package/src/autocomplete/index.tsx +25 -7
  84. package/src/badge/stories/e2e/index.story.tsx +21 -0
  85. package/src/box-control/index.tsx +0 -1
  86. package/src/box-control/utils.ts +0 -43
  87. package/src/button/stories/e2e/index.story.tsx +11 -0
  88. package/src/custom-gradient-picker/gradient-bar/index.tsx +1 -1
  89. package/src/draggable/index.tsx +32 -10
  90. package/src/draggable/stories/index.story.tsx +11 -6
  91. package/src/draggable/style.module.scss +29 -0
  92. package/src/draggable/types.ts +4 -0
  93. package/src/form-token-field/index.tsx +84 -8
  94. package/src/form-token-field/test/index.tsx +189 -0
  95. package/src/icon/stories/index.story.tsx +2 -14
  96. package/src/index.ts +0 -6
  97. package/src/menu/test/index.tsx +9 -4
  98. package/src/modal/style.scss +2 -1
  99. package/src/notice/README.md +1 -2
  100. package/src/notice/index.tsx +57 -64
  101. package/src/notice/style.scss +49 -41
  102. package/src/notice/test/__snapshots__/index.tsx.snap +23 -23
  103. package/src/notice/test/index.tsx +5 -5
  104. package/src/notice/types.ts +1 -2
  105. package/src/popover/index.tsx +28 -0
  106. package/src/popover/test/index.tsx +138 -1
  107. package/src/range-control/stories/index.story.tsx +0 -1
  108. package/src/range-control/types.ts +0 -4
  109. package/src/style.scss +0 -1
  110. package/src/tab-panel/stories/index.story.tsx +2 -13
  111. package/src/tab-panel/style.scss +36 -14
  112. package/src/tabs/stories/index.story.tsx +2 -13
  113. package/src/tabs/styles.ts +3 -8
  114. package/build/navigation/back-button/index.cjs +0 -86
  115. package/build/navigation/back-button/index.cjs.map +0 -7
  116. package/build/navigation/constants.cjs +0 -34
  117. package/build/navigation/constants.cjs.map +0 -7
  118. package/build/navigation/context.cjs +0 -58
  119. package/build/navigation/context.cjs.map +0 -7
  120. package/build/navigation/group/context.cjs +0 -38
  121. package/build/navigation/group/context.cjs.map +0 -7
  122. package/build/navigation/group/index.cjs +0 -88
  123. package/build/navigation/group/index.cjs.map +0 -7
  124. package/build/navigation/index.cjs +0 -113
  125. package/build/navigation/index.cjs.map +0 -7
  126. package/build/navigation/item/base-content.cjs +0 -44
  127. package/build/navigation/item/base-content.cjs.map +0 -7
  128. package/build/navigation/item/base.cjs +0 -66
  129. package/build/navigation/item/base.cjs.map +0 -7
  130. package/build/navigation/item/index.cjs +0 -119
  131. package/build/navigation/item/index.cjs.map +0 -7
  132. package/build/navigation/item/use-navigation-tree-item.cjs +0 -64
  133. package/build/navigation/item/use-navigation-tree-item.cjs.map +0 -7
  134. package/build/navigation/menu/context.cjs +0 -39
  135. package/build/navigation/menu/context.cjs.map +0 -7
  136. package/build/navigation/menu/index.cjs +0 -114
  137. package/build/navigation/menu/index.cjs.map +0 -7
  138. package/build/navigation/menu/menu-title-search.cjs +0 -111
  139. package/build/navigation/menu/menu-title-search.cjs.map +0 -7
  140. package/build/navigation/menu/menu-title.cjs +0 -104
  141. package/build/navigation/menu/menu-title.cjs.map +0 -7
  142. package/build/navigation/menu/search-no-results-found.cjs +0 -48
  143. package/build/navigation/menu/search-no-results-found.cjs.map +0 -7
  144. package/build/navigation/menu/use-navigation-tree-menu.cjs +0 -51
  145. package/build/navigation/menu/use-navigation-tree-menu.cjs.map +0 -7
  146. package/build/navigation/styles/navigation-styles.cjs +0 -170
  147. package/build/navigation/styles/navigation-styles.cjs.map +0 -7
  148. package/build/navigation/types.cjs +0 -19
  149. package/build/navigation/types.cjs.map +0 -7
  150. package/build/navigation/use-create-navigation-tree.cjs +0 -103
  151. package/build/navigation/use-create-navigation-tree.cjs.map +0 -7
  152. package/build/navigation/use-navigation-tree-nodes.cjs +0 -60
  153. package/build/navigation/use-navigation-tree-nodes.cjs.map +0 -7
  154. package/build/navigation/utils.cjs +0 -45
  155. package/build/navigation/utils.cjs.map +0 -7
  156. package/build-module/navigation/back-button/index.mjs +0 -51
  157. package/build-module/navigation/back-button/index.mjs.map +0 -7
  158. package/build-module/navigation/constants.mjs +0 -8
  159. package/build-module/navigation/constants.mjs.map +0 -7
  160. package/build-module/navigation/context.mjs +0 -32
  161. package/build-module/navigation/context.mjs.map +0 -7
  162. package/build-module/navigation/group/context.mjs +0 -12
  163. package/build-module/navigation/group/context.mjs.map +0 -7
  164. package/build-module/navigation/group/index.mjs +0 -53
  165. package/build-module/navigation/group/index.mjs.map +0 -7
  166. package/build-module/navigation/index.mjs +0 -78
  167. package/build-module/navigation/index.mjs.map +0 -7
  168. package/build-module/navigation/item/base-content.mjs +0 -23
  169. package/build-module/navigation/item/base-content.mjs.map +0 -7
  170. package/build-module/navigation/item/base.mjs +0 -35
  171. package/build-module/navigation/item/base.mjs.map +0 -7
  172. package/build-module/navigation/item/index.mjs +0 -84
  173. package/build-module/navigation/item/index.mjs.map +0 -7
  174. package/build-module/navigation/item/use-navigation-tree-item.mjs +0 -39
  175. package/build-module/navigation/item/use-navigation-tree-item.mjs.map +0 -7
  176. package/build-module/navigation/menu/context.mjs +0 -13
  177. package/build-module/navigation/menu/context.mjs.map +0 -7
  178. package/build-module/navigation/menu/index.mjs +0 -79
  179. package/build-module/navigation/menu/index.mjs.map +0 -7
  180. package/build-module/navigation/menu/menu-title-search.mjs +0 -80
  181. package/build-module/navigation/menu/menu-title-search.mjs.map +0 -7
  182. package/build-module/navigation/menu/menu-title.mjs +0 -73
  183. package/build-module/navigation/menu/menu-title.mjs.map +0 -7
  184. package/build-module/navigation/menu/search-no-results-found.mjs +0 -27
  185. package/build-module/navigation/menu/search-no-results-found.mjs.map +0 -7
  186. package/build-module/navigation/menu/use-navigation-tree-menu.mjs +0 -26
  187. package/build-module/navigation/menu/use-navigation-tree-menu.mjs.map +0 -7
  188. package/build-module/navigation/styles/navigation-styles.mjs +0 -124
  189. package/build-module/navigation/styles/navigation-styles.mjs.map +0 -7
  190. package/build-module/navigation/types.mjs +0 -1
  191. package/build-module/navigation/types.mjs.map +0 -7
  192. package/build-module/navigation/use-create-navigation-tree.mjs +0 -78
  193. package/build-module/navigation/use-create-navigation-tree.mjs.map +0 -7
  194. package/build-module/navigation/use-navigation-tree-nodes.mjs +0 -35
  195. package/build-module/navigation/use-navigation-tree-nodes.mjs.map +0 -7
  196. package/build-module/navigation/utils.mjs +0 -9
  197. package/build-module/navigation/utils.mjs.map +0 -7
  198. package/build-types/navigation/back-button/index.d.ts +0 -7
  199. package/build-types/navigation/back-button/index.d.ts.map +0 -1
  200. package/build-types/navigation/constants.d.ts +0 -3
  201. package/build-types/navigation/constants.d.ts.map +0 -1
  202. package/build-types/navigation/context.d.ts +0 -4
  203. package/build-types/navigation/context.d.ts.map +0 -1
  204. package/build-types/navigation/group/context.d.ts +0 -7
  205. package/build-types/navigation/group/context.d.ts.map +0 -1
  206. package/build-types/navigation/group/index.d.ts +0 -7
  207. package/build-types/navigation/group/index.d.ts.map +0 -1
  208. package/build-types/navigation/index.d.ts +0 -46
  209. package/build-types/navigation/index.d.ts.map +0 -1
  210. package/build-types/navigation/item/base-content.d.ts +0 -3
  211. package/build-types/navigation/item/base-content.d.ts.map +0 -1
  212. package/build-types/navigation/item/base.d.ts +0 -3
  213. package/build-types/navigation/item/base.d.ts.map +0 -1
  214. package/build-types/navigation/item/index.d.ts +0 -7
  215. package/build-types/navigation/item/index.d.ts.map +0 -1
  216. package/build-types/navigation/item/use-navigation-tree-item.d.ts +0 -3
  217. package/build-types/navigation/item/use-navigation-tree-item.d.ts.map +0 -1
  218. package/build-types/navigation/menu/context.d.ts +0 -7
  219. package/build-types/navigation/menu/context.d.ts.map +0 -1
  220. package/build-types/navigation/menu/index.d.ts +0 -7
  221. package/build-types/navigation/menu/index.d.ts.map +0 -1
  222. package/build-types/navigation/menu/menu-title-search.d.ts +0 -3
  223. package/build-types/navigation/menu/menu-title-search.d.ts.map +0 -1
  224. package/build-types/navigation/menu/menu-title.d.ts +0 -3
  225. package/build-types/navigation/menu/menu-title.d.ts.map +0 -1
  226. package/build-types/navigation/menu/search-no-results-found.d.ts +0 -3
  227. package/build-types/navigation/menu/search-no-results-found.d.ts.map +0 -1
  228. package/build-types/navigation/menu/use-navigation-tree-menu.d.ts +0 -3
  229. package/build-types/navigation/menu/use-navigation-tree-menu.d.ts.map +0 -1
  230. package/build-types/navigation/stories/index.story.d.ts +0 -23
  231. package/build-types/navigation/stories/index.story.d.ts.map +0 -1
  232. package/build-types/navigation/stories/utils/controlled-state.d.ts +0 -7
  233. package/build-types/navigation/stories/utils/controlled-state.d.ts.map +0 -1
  234. package/build-types/navigation/stories/utils/default.d.ts +0 -10
  235. package/build-types/navigation/stories/utils/default.d.ts.map +0 -1
  236. package/build-types/navigation/stories/utils/group.d.ts +0 -10
  237. package/build-types/navigation/stories/utils/group.d.ts.map +0 -1
  238. package/build-types/navigation/stories/utils/hide-if-empty.d.ts +0 -10
  239. package/build-types/navigation/stories/utils/hide-if-empty.d.ts.map +0 -1
  240. package/build-types/navigation/stories/utils/more-examples.d.ts +0 -10
  241. package/build-types/navigation/stories/utils/more-examples.d.ts.map +0 -1
  242. package/build-types/navigation/stories/utils/search.d.ts +0 -10
  243. package/build-types/navigation/stories/utils/search.d.ts.map +0 -1
  244. package/build-types/navigation/styles/navigation-styles.d.ts +0 -55
  245. package/build-types/navigation/styles/navigation-styles.d.ts.map +0 -1
  246. package/build-types/navigation/test/index.d.ts +0 -2
  247. package/build-types/navigation/test/index.d.ts.map +0 -1
  248. package/build-types/navigation/types.d.ts +0 -266
  249. package/build-types/navigation/types.d.ts.map +0 -1
  250. package/build-types/navigation/use-create-navigation-tree.d.ts +0 -15
  251. package/build-types/navigation/use-create-navigation-tree.d.ts.map +0 -1
  252. package/build-types/navigation/use-navigation-tree-nodes.d.ts +0 -10
  253. package/build-types/navigation/use-navigation-tree-nodes.d.ts.map +0 -1
  254. package/build-types/navigation/utils.d.ts +0 -3
  255. package/build-types/navigation/utils.d.ts.map +0 -1
  256. package/src/draggable/style.scss +0 -21
  257. package/src/navigation/README.md +0 -267
  258. package/src/navigation/back-button/index.tsx +0 -73
  259. package/src/navigation/constants.tsx +0 -2
  260. package/src/navigation/context.tsx +0 -40
  261. package/src/navigation/group/context.tsx +0 -16
  262. package/src/navigation/group/index.tsx +0 -73
  263. package/src/navigation/index.tsx +0 -152
  264. package/src/navigation/item/base-content.tsx +0 -31
  265. package/src/navigation/item/base.tsx +0 -42
  266. package/src/navigation/item/index.tsx +0 -112
  267. package/src/navigation/item/use-navigation-tree-item.tsx +0 -47
  268. package/src/navigation/menu/context.tsx +0 -20
  269. package/src/navigation/menu/index.tsx +0 -105
  270. package/src/navigation/menu/menu-title-search.tsx +0 -99
  271. package/src/navigation/menu/menu-title.tsx +0 -100
  272. package/src/navigation/menu/search-no-results-found.tsx +0 -34
  273. package/src/navigation/menu/use-navigation-tree-menu.tsx +0 -29
  274. package/src/navigation/stories/index.story.tsx +0 -62
  275. package/src/navigation/stories/style.css +0 -25
  276. package/src/navigation/stories/utils/controlled-state.tsx +0 -149
  277. package/src/navigation/stories/utils/default.tsx +0 -92
  278. package/src/navigation/stories/utils/group.tsx +0 -61
  279. package/src/navigation/stories/utils/hide-if-empty.tsx +0 -66
  280. package/src/navigation/stories/utils/more-examples.tsx +0 -162
  281. package/src/navigation/stories/utils/search.tsx +0 -91
  282. package/src/navigation/styles/navigation-styles.tsx +0 -197
  283. package/src/navigation/test/index.tsx +0 -347
  284. package/src/navigation/types.ts +0 -325
  285. package/src/navigation/use-create-navigation-tree.tsx +0 -110
  286. package/src/navigation/use-navigation-tree-nodes.tsx +0 -31
  287. package/src/navigation/utils.tsx +0 -11
@@ -1,99 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useEffect, useRef } from '@wordpress/element';
5
- import { __, _n, sprintf } from '@wordpress/i18n';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import withSpokenMessages from '../../higher-order/with-spoken-messages';
11
- import { useNavigationMenuContext } from './context';
12
- import { useNavigationContext } from '../context';
13
- import { SEARCH_FOCUS_DELAY } from '../constants';
14
-
15
- import type { NavigationMenuTitleSearchProps } from '../types';
16
- import SearchControl from '../../search-control';
17
- import { MenuTitleSearchControlWrapper } from '../styles/navigation-styles';
18
-
19
- function MenuTitleSearch( {
20
- debouncedSpeak,
21
- onCloseSearch,
22
- onSearch,
23
- search,
24
- title,
25
- }: NavigationMenuTitleSearchProps ) {
26
- const {
27
- navigationTree: { items },
28
- } = useNavigationContext();
29
- const { menu } = useNavigationMenuContext();
30
- const inputRef = useRef< HTMLInputElement >( null );
31
-
32
- // Wait for the slide-in animation to complete before autofocusing the input.
33
- // This prevents scrolling to the input during the animation.
34
- useEffect( () => {
35
- const delayedFocus = setTimeout( () => {
36
- inputRef.current?.focus();
37
- }, SEARCH_FOCUS_DELAY );
38
-
39
- return () => {
40
- clearTimeout( delayedFocus );
41
- };
42
- }, [] );
43
-
44
- useEffect( () => {
45
- if ( ! search ) {
46
- return;
47
- }
48
-
49
- const count = Object.values( items ).filter(
50
- ( item ) => item._isVisible
51
- ).length;
52
- const resultsFoundMessage = sprintf(
53
- /* translators: %d: number of results. */
54
- _n( '%d result found.', '%d results found.', count ),
55
- count
56
- );
57
- debouncedSpeak( resultsFoundMessage );
58
- // Not adding deps for now, as it would require either a larger refactor.
59
- // See https://github.com/WordPress/gutenberg/pull/44090
60
- }, [ items, search ] );
61
-
62
- const onClose = () => {
63
- onSearch?.( '' );
64
- onCloseSearch();
65
- };
66
-
67
- const onKeyDown: React.KeyboardEventHandler< HTMLInputElement > = (
68
- event
69
- ) => {
70
- if ( event.code === 'Escape' && ! event.defaultPrevented ) {
71
- event.preventDefault();
72
- onClose();
73
- }
74
- };
75
-
76
- const inputId = `components-navigation__menu-title-search-${ menu }`;
77
- const placeholder = sprintf(
78
- /* translators: placeholder for menu search box. %s: menu title */
79
- __( 'Search %s' ),
80
- title?.toLowerCase() || ''
81
- ).trim();
82
-
83
- return (
84
- <MenuTitleSearchControlWrapper>
85
- <SearchControl
86
- className="components-navigation__menu-search-input"
87
- id={ inputId }
88
- onChange={ ( value ) => onSearch?.( value ) }
89
- onKeyDown={ onKeyDown }
90
- placeholder={ placeholder }
91
- onClose={ onClose }
92
- ref={ inputRef }
93
- value={ search }
94
- />
95
- </MenuTitleSearchControlWrapper>
96
- );
97
- }
98
-
99
- export default withSpokenMessages( MenuTitleSearch );
@@ -1,100 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef, useState } from '@wordpress/element';
5
- import { __, sprintf } from '@wordpress/i18n';
6
- import { Icon, search as searchIcon } from '@wordpress/icons';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { getAnimateClassName } from '../../animate';
12
- import Button from '../../button';
13
- import MenuTitleSearch from './menu-title-search';
14
- import {
15
- GroupTitleUI,
16
- MenuTitleActionsUI,
17
- MenuTitleUI,
18
- } from '../styles/navigation-styles';
19
- import { useNavigationMenuContext } from './context';
20
- import { SEARCH_FOCUS_DELAY } from '../constants';
21
-
22
- import type { NavigationMenuTitleProps } from '../types';
23
-
24
- export default function NavigationMenuTitle( {
25
- hasSearch,
26
- onSearch,
27
- search,
28
- title,
29
- titleAction,
30
- }: NavigationMenuTitleProps ) {
31
- const [ isSearching, setIsSearching ] = useState( false );
32
- const { menu } = useNavigationMenuContext();
33
- const searchButtonRef = useRef< HTMLElement >( null );
34
-
35
- if ( ! title ) {
36
- return null;
37
- }
38
-
39
- const onCloseSearch = () => {
40
- setIsSearching( false );
41
-
42
- // Wait for the slide-in animation to complete before focusing the search button.
43
- // eslint-disable-next-line @wordpress/react-no-unsafe-timeout
44
- setTimeout( () => {
45
- searchButtonRef.current?.focus();
46
- }, SEARCH_FOCUS_DELAY );
47
- };
48
-
49
- const menuTitleId = `components-navigation__menu-title-${ menu }`;
50
- /* translators: search button label for menu search box. %s: menu title */
51
- const searchButtonLabel = sprintf( __( 'Search in %s' ), title );
52
-
53
- return (
54
- <MenuTitleUI className="components-navigation__menu-title">
55
- { ! isSearching && (
56
- <GroupTitleUI
57
- as="h2"
58
- className="components-navigation__menu-title-heading"
59
- level={ 3 }
60
- >
61
- <span id={ menuTitleId }>{ title }</span>
62
-
63
- { ( hasSearch || titleAction ) && (
64
- <MenuTitleActionsUI>
65
- { titleAction }
66
-
67
- { hasSearch && (
68
- <Button
69
- size="small"
70
- variant="tertiary"
71
- label={ searchButtonLabel }
72
- onClick={ () => setIsSearching( true ) }
73
- ref={ searchButtonRef }
74
- >
75
- <Icon icon={ searchIcon } />
76
- </Button>
77
- ) }
78
- </MenuTitleActionsUI>
79
- ) }
80
- </GroupTitleUI>
81
- ) }
82
-
83
- { isSearching && (
84
- <div
85
- className={ getAnimateClassName( {
86
- type: 'slide-in',
87
- origin: 'left',
88
- } ) }
89
- >
90
- <MenuTitleSearch
91
- onCloseSearch={ onCloseSearch }
92
- onSearch={ onSearch }
93
- search={ search }
94
- title={ title }
95
- />
96
- </div>
97
- ) }
98
- </MenuTitleUI>
99
- );
100
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { useNavigationContext } from '../context';
10
- import { ItemBaseUI, ItemUI } from '../styles/navigation-styles';
11
-
12
- import type { NavigationSearchNoResultsFoundProps } from '../types';
13
-
14
- export default function NavigationSearchNoResultsFound( {
15
- search,
16
- }: NavigationSearchNoResultsFoundProps ) {
17
- const {
18
- navigationTree: { items },
19
- } = useNavigationContext();
20
-
21
- const resultsCount = Object.values( items ).filter(
22
- ( item ) => item._isVisible
23
- ).length;
24
-
25
- if ( ! search || !! resultsCount ) {
26
- return null;
27
- }
28
-
29
- return (
30
- <ItemBaseUI>
31
- <ItemUI>{ __( 'No results found.' ) } </ItemUI>
32
- </ItemBaseUI>
33
- );
34
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useEffect } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { useNavigationContext } from '../context';
10
- import { ROOT_MENU } from '../constants';
11
-
12
- import type { NavigationMenuProps } from '../types';
13
-
14
- export const useNavigationTreeMenu = ( props: NavigationMenuProps ) => {
15
- const {
16
- navigationTree: { addMenu, removeMenu },
17
- } = useNavigationContext();
18
-
19
- const key = props.menu || ROOT_MENU;
20
- useEffect( () => {
21
- addMenu( key, { ...props, menu: key } );
22
-
23
- return () => {
24
- removeMenu( key );
25
- };
26
- // Not adding deps for now, as it would require either a larger refactor
27
- // See https://github.com/WordPress/gutenberg/pull/44090
28
- }, [] );
29
- };
@@ -1,62 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { Meta } from '@storybook/react-vite';
5
- import { fn } from 'storybook/test';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { Navigation } from '..';
11
- import { NavigationBackButton } from '../back-button';
12
- import { NavigationGroup } from '../group';
13
- import { NavigationItem } from '../item';
14
- import { NavigationMenu } from '../menu';
15
- import { DefaultStory } from './utils/default';
16
- import { GroupStory } from './utils/group';
17
- import { ControlledStateStory } from './utils/controlled-state';
18
- import { SearchStory } from './utils/search';
19
- import { MoreExamplesStory } from './utils/more-examples';
20
- import { HideIfEmptyStory } from './utils/hide-if-empty';
21
- import './style.css';
22
-
23
- /**
24
- * Render a navigation list with optional groupings and hierarchy.
25
- *
26
- * This component is deprecated. Consider using `Navigator` instead.
27
- */
28
- const meta: Meta< typeof Navigation > = {
29
- title: 'Components/Deprecated/Navigation',
30
- id: 'components-navigation',
31
- component: Navigation,
32
- subcomponents: {
33
- NavigationBackButton,
34
- NavigationGroup,
35
- NavigationItem,
36
- NavigationMenu,
37
- },
38
- argTypes: {
39
- activeItem: { control: false },
40
- activeMenu: { control: false },
41
- children: { control: false },
42
- onActivateMenu: { control: false },
43
- },
44
- args: {
45
- onActivateMenu: fn(),
46
- },
47
- parameters: {
48
- controls: {
49
- expanded: true,
50
- },
51
- docs: { canvas: { sourceState: 'shown' } },
52
- },
53
- };
54
-
55
- export default meta;
56
-
57
- export const _default = DefaultStory.bind( {} );
58
- export const ControlledState = ControlledStateStory.bind( {} );
59
- export const Groups = GroupStory.bind( {} );
60
- export const Search = SearchStory.bind( {} );
61
- export const MoreExamples = MoreExamplesStory.bind( {} );
62
- export const HideIfEmpty = HideIfEmptyStory.bind( {} );
@@ -1,25 +0,0 @@
1
- .navigation-story {
2
- max-width: 300px;
3
- }
4
-
5
- .navigation-story__aside {
6
- margin: 48px 0 0 24px;
7
- }
8
-
9
- .navigation-story__wordpress-icon {
10
- align-items: center;
11
- display: inline-flex;
12
- }
13
- .navigation-story__wordpress-icon svg {
14
- fill: #949494;
15
- margin-right: 8px;
16
- }
17
-
18
- :root[dir="rtl"] .navigation-story__wordpress-icon svg {
19
- fill: #949494;
20
- margin-right: 0;
21
- margin-left: 8px;
22
- }
23
- .navigation-story__wordpress-icon:hover svg {
24
- fill: #ddd;
25
- }
@@ -1,149 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { StoryFn } from '@storybook/react-vite';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import Button from '../../../button';
15
- import { Navigation } from '../..';
16
- import { NavigationItem } from '../../item';
17
- import { NavigationMenu } from '../../menu';
18
-
19
- export const ControlledStateStory: StoryFn< typeof Navigation > = ( {
20
- className,
21
- ...props
22
- } ) => {
23
- const [ activeItem, setActiveItem ] = useState( 'item-1' );
24
- const [ activeMenu, setActiveMenu ] = useState( 'root' );
25
-
26
- // Mock navigation link.
27
- const MockLink = ( {
28
- href,
29
- children,
30
- }: {
31
- href: string;
32
- children: React.ReactNode;
33
- } ) => (
34
- <Button
35
- __next40pxDefaultSize
36
- href={ href }
37
- // Since we're not actually navigating pages, simulate it with onClick.
38
- onClick={
39
- ( ( event ) => {
40
- event.preventDefault();
41
- const item = href.replace( 'https://example.com/', '' );
42
- setActiveItem( item );
43
- } ) as React.MouseEventHandler< HTMLAnchorElement >
44
- }
45
- >
46
- { children }
47
- </Button>
48
- );
49
-
50
- return (
51
- <>
52
- <Navigation
53
- { ...props }
54
- activeItem={ activeItem }
55
- activeMenu={ activeMenu }
56
- className={ [ 'navigation-story', className ]
57
- .filter( Boolean )
58
- .join( ' ' ) }
59
- onActivateMenu={ setActiveMenu }
60
- >
61
- <NavigationMenu title="Home">
62
- <NavigationItem item="item-1" title="Item 1">
63
- <MockLink href="https://example.com/item-1">
64
- Item 1
65
- </MockLink>
66
- </NavigationItem>
67
- <NavigationItem item="item-2">
68
- <MockLink href="https://example.com/item-2">
69
- Item 2
70
- </MockLink>
71
- </NavigationItem>
72
- <NavigationItem
73
- item="item-sub-menu"
74
- navigateToMenu="sub-menu"
75
- title="Sub-Menu"
76
- />
77
- </NavigationMenu>
78
- <NavigationMenu
79
- menu="sub-menu"
80
- parentMenu="root"
81
- title="Sub-Menu"
82
- >
83
- <NavigationItem
84
- item="child-1"
85
- onClick={ () => setActiveItem( 'child-1' ) }
86
- title="Child 1"
87
- />
88
- <NavigationItem
89
- item="child-2"
90
- onClick={ () => setActiveItem( 'child-2' ) }
91
- title="Child 2"
92
- />
93
- <NavigationItem
94
- item="child-nested-sub-menu"
95
- navigateToMenu="nested-sub-menu"
96
- title="Nested Sub-Menu"
97
- />
98
- </NavigationMenu>
99
- <NavigationMenu
100
- menu="nested-sub-menu"
101
- parentMenu="sub-menu"
102
- title="Nested Sub-Menu"
103
- >
104
- <NavigationItem
105
- item="sub-child-1"
106
- onClick={ () => setActiveItem( 'sub-child-1' ) }
107
- title="Sub-Child 1"
108
- />
109
- <NavigationItem
110
- item="sub-child-2"
111
- onClick={ () => setActiveItem( 'sub-child-2' ) }
112
- title="Sub-Child 2"
113
- />
114
- </NavigationMenu>
115
- </Navigation>
116
-
117
- <div className="navigation-story__aside">
118
- <p>
119
- Menu <code>{ activeMenu }</code> is active.
120
- <br />
121
- Item <code>{ activeItem }</code> is active.
122
- </p>
123
- <p>
124
- <Button
125
- __next40pxDefaultSize
126
- variant="secondary"
127
- onClick={ () => {
128
- setActiveMenu( 'nested-sub-menu' );
129
- } }
130
- >
131
- Open the Nested Sub-Menu menu
132
- </Button>
133
- </p>
134
- <p>
135
- <Button
136
- __next40pxDefaultSize
137
- variant="secondary"
138
- onClick={ () => {
139
- setActiveItem( 'child-2' );
140
- setActiveMenu( 'sub-menu' );
141
- } }
142
- >
143
- Navigate to Child 2 item
144
- </Button>
145
- </p>
146
- </div>
147
- </>
148
- );
149
- };
@@ -1,92 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { StoryFn } from '@storybook/react-vite';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import { Navigation } from '../..';
15
- import { NavigationItem } from '../../item';
16
- import { NavigationMenu } from '../../menu';
17
-
18
- export const DefaultStory: StoryFn< typeof Navigation > = ( {
19
- className,
20
- ...props
21
- } ) => {
22
- const [ activeItem, setActiveItem ] = useState( 'item-1' );
23
-
24
- return (
25
- <Navigation
26
- { ...props }
27
- activeItem={ activeItem }
28
- className={ [ 'navigation-story', className ]
29
- .filter( Boolean )
30
- .join( ' ' ) }
31
- >
32
- <NavigationMenu title="Home">
33
- <NavigationItem
34
- item="item-1"
35
- onClick={ () => setActiveItem( 'item-1' ) }
36
- title="Item 1"
37
- />
38
- <NavigationItem
39
- item="item-2"
40
- onClick={ () => setActiveItem( 'item-2' ) }
41
- title="Item 2"
42
- />
43
- <NavigationItem>
44
- <a
45
- className="components-button"
46
- href="http://www.example.com"
47
- >
48
- External Link
49
- </a>
50
- </NavigationItem>
51
- <NavigationItem
52
- item="item-sub-menu"
53
- navigateToMenu="sub-menu"
54
- title="Sub-Menu"
55
- />
56
- </NavigationMenu>
57
- <NavigationMenu menu="sub-menu" parentMenu="root" title="Sub-Menu">
58
- <NavigationItem
59
- item="child-1"
60
- onClick={ () => setActiveItem( 'child-1' ) }
61
- title="Child 1"
62
- />
63
- <NavigationItem
64
- item="child-2"
65
- onClick={ () => setActiveItem( 'child-2' ) }
66
- title="Child 2"
67
- />
68
- <NavigationItem
69
- item="child-nested-sub-menu"
70
- navigateToMenu="nested-sub-menu"
71
- title="Nested Sub-Menu"
72
- />
73
- </NavigationMenu>
74
- <NavigationMenu
75
- menu="nested-sub-menu"
76
- parentMenu="sub-menu"
77
- title="Nested Sub-Menu"
78
- >
79
- <NavigationItem
80
- item="sub-child-1"
81
- onClick={ () => setActiveItem( 'sub-child-1' ) }
82
- title="Sub-Child 1"
83
- />
84
- <NavigationItem
85
- item="sub-child-2"
86
- onClick={ () => setActiveItem( 'sub-child-2' ) }
87
- title="Sub-Child 2"
88
- />
89
- </NavigationMenu>
90
- </Navigation>
91
- );
92
- };
@@ -1,61 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { StoryFn } from '@storybook/react-vite';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import { Navigation } from '../..';
15
- import { NavigationItem } from '../../item';
16
- import { NavigationMenu } from '../../menu';
17
- import { NavigationGroup } from '../../group';
18
-
19
- export const GroupStory: StoryFn< typeof Navigation > = ( {
20
- className,
21
- ...props
22
- } ) => {
23
- const [ activeItem, setActiveItem ] = useState( 'item-1' );
24
-
25
- return (
26
- <Navigation
27
- { ...props }
28
- activeItem={ activeItem }
29
- className={ [ 'navigation-story', className ]
30
- .filter( Boolean )
31
- .join( ' ' ) }
32
- >
33
- <NavigationMenu title="Home">
34
- <NavigationGroup title="Group 1">
35
- <NavigationItem
36
- item="item-1"
37
- onClick={ () => setActiveItem( 'item-1' ) }
38
- title="Item 1"
39
- />
40
- <NavigationItem
41
- item="item-2"
42
- onClick={ () => setActiveItem( 'item-2' ) }
43
- title="Item 2"
44
- />
45
- </NavigationGroup>
46
- <NavigationGroup title="Group 2">
47
- <NavigationItem
48
- item="item-3"
49
- onClick={ () => setActiveItem( 'item-3' ) }
50
- title="Item 3"
51
- />
52
- <NavigationItem
53
- item="item-4"
54
- onClick={ () => setActiveItem( 'item-4' ) }
55
- title="Item 4"
56
- />
57
- </NavigationGroup>
58
- </NavigationMenu>
59
- </Navigation>
60
- );
61
- };