@wordpress/components 28.8.3 → 28.9.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 (329) hide show
  1. package/CHANGELOG.md +27 -3
  2. package/build/autocomplete/index.js +4 -1
  3. package/build/autocomplete/index.js.map +1 -1
  4. package/build/border-box-control/border-box-control/component.js +3 -14
  5. package/build/border-box-control/border-box-control/component.js.map +1 -1
  6. package/build/border-control/border-control/component.js +1 -2
  7. package/build/border-control/border-control/component.js.map +1 -1
  8. package/build/border-control/border-control-dropdown/component.js +2 -14
  9. package/build/border-control/border-control-dropdown/component.js.map +1 -1
  10. package/build/border-control/styles.js +13 -13
  11. package/build/border-control/styles.js.map +1 -1
  12. package/build/border-control/types.js.map +1 -1
  13. package/build/box-control/index.js +4 -4
  14. package/build/box-control/index.js.map +1 -1
  15. package/build/box-control/types.js.map +1 -1
  16. package/build/composite/group-label.js +7 -1
  17. package/build/composite/group-label.js.map +1 -1
  18. package/build/composite/group.js +7 -1
  19. package/build/composite/group.js.map +1 -1
  20. package/build/composite/hover.js +8 -2
  21. package/build/composite/hover.js.map +1 -1
  22. package/build/composite/index.js +5 -1
  23. package/build/composite/index.js.map +1 -1
  24. package/build/composite/item.js +16 -1
  25. package/build/composite/item.js.map +1 -1
  26. package/build/composite/row.js +7 -1
  27. package/build/composite/row.js.map +1 -1
  28. package/build/composite/typeahead.js +8 -2
  29. package/build/composite/typeahead.js.map +1 -1
  30. package/build/date-time/date/index.js +4 -2
  31. package/build/date-time/date/index.js.map +1 -1
  32. package/build/index.js +36 -5
  33. package/build/index.js.map +1 -1
  34. package/build/navigator/index.js +128 -32
  35. package/build/navigator/index.js.map +1 -1
  36. package/build/navigator/legacy.js +179 -0
  37. package/build/navigator/legacy.js.map +1 -0
  38. package/build/navigator/{navigator-provider → navigator}/component.js +5 -40
  39. package/build/navigator/navigator/component.js.map +1 -0
  40. package/build/navigator/navigator-back-button/component.js +2 -38
  41. package/build/navigator/navigator-back-button/component.js.map +1 -1
  42. package/build/navigator/navigator-back-button/hook.js +1 -1
  43. package/build/navigator/navigator-back-button/hook.js.map +1 -1
  44. package/build/navigator/navigator-button/component.js +2 -37
  45. package/build/navigator/navigator-button/component.js.map +1 -1
  46. package/build/navigator/navigator-button/hook.js +1 -1
  47. package/build/navigator/navigator-button/hook.js.map +1 -1
  48. package/build/navigator/navigator-screen/component.js +40 -62
  49. package/build/navigator/navigator-screen/component.js.map +1 -1
  50. package/build/navigator/navigator-screen/use-screen-animate-presence.js +114 -0
  51. package/build/navigator/navigator-screen/use-screen-animate-presence.js.map +1 -0
  52. package/build/navigator/navigator-to-parent-button/component.js +3 -7
  53. package/build/navigator/navigator-to-parent-button/component.js.map +1 -1
  54. package/build/navigator/styles.js +78 -35
  55. package/build/navigator/styles.js.map +1 -1
  56. package/build/navigator/types.js.map +1 -1
  57. package/build/navigator/use-navigator.js +4 -1
  58. package/build/navigator/use-navigator.js.map +1 -1
  59. package/build/search-control/index.js +5 -2
  60. package/build/search-control/index.js.map +1 -1
  61. package/build/tabs/styles.js +3 -3
  62. package/build/tabs/styles.js.map +1 -1
  63. package/build/tabs/tablist.js +61 -28
  64. package/build/tabs/tablist.js.map +1 -1
  65. package/build/tabs/use-track-overflow.js +73 -0
  66. package/build/tabs/use-track-overflow.js.map +1 -0
  67. package/build/toggle-group-control/toggle-group-control/as-button-group.js +4 -2
  68. package/build/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
  69. package/build/toggle-group-control/toggle-group-control/as-radio-group.js +9 -3
  70. package/build/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
  71. package/build/toggle-group-control/toggle-group-control/component.js +73 -8
  72. package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
  73. package/build/toggle-group-control/toggle-group-control/styles.js +7 -7
  74. package/build/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  75. package/build/toggle-group-control/toggle-group-control-option-base/component.js +10 -19
  76. package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
  77. package/build/toggle-group-control/toggle-group-control-option-base/styles.js +8 -9
  78. package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  79. package/build/toggle-group-control/types.js.map +1 -1
  80. package/build/utils/element-rect.js +22 -13
  81. package/build/utils/element-rect.js.map +1 -1
  82. package/build/utils/hooks/use-on-value-update.js +3 -7
  83. package/build/utils/hooks/use-on-value-update.js.map +1 -1
  84. package/build-module/autocomplete/index.js +4 -1
  85. package/build-module/autocomplete/index.js.map +1 -1
  86. package/build-module/border-box-control/border-box-control/component.js +3 -14
  87. package/build-module/border-box-control/border-box-control/component.js.map +1 -1
  88. package/build-module/border-control/border-control/component.js +1 -2
  89. package/build-module/border-control/border-control/component.js.map +1 -1
  90. package/build-module/border-control/border-control-dropdown/component.js +2 -14
  91. package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
  92. package/build-module/border-control/styles.js +13 -13
  93. package/build-module/border-control/styles.js.map +1 -1
  94. package/build-module/border-control/types.js.map +1 -1
  95. package/build-module/box-control/index.js +4 -4
  96. package/build-module/box-control/index.js.map +1 -1
  97. package/build-module/box-control/types.js.map +1 -1
  98. package/build-module/composite/group-label.js +7 -1
  99. package/build-module/composite/group-label.js.map +1 -1
  100. package/build-module/composite/group.js +7 -1
  101. package/build-module/composite/group.js.map +1 -1
  102. package/build-module/composite/hover.js +8 -2
  103. package/build-module/composite/hover.js.map +1 -1
  104. package/build-module/composite/index.js +5 -1
  105. package/build-module/composite/index.js.map +1 -1
  106. package/build-module/composite/item.js +16 -1
  107. package/build-module/composite/item.js.map +1 -1
  108. package/build-module/composite/row.js +7 -1
  109. package/build-module/composite/row.js.map +1 -1
  110. package/build-module/composite/typeahead.js +8 -2
  111. package/build-module/composite/typeahead.js.map +1 -1
  112. package/build-module/date-time/date/index.js +4 -2
  113. package/build-module/date-time/date/index.js.map +1 -1
  114. package/build-module/index.js +14 -4
  115. package/build-module/index.js.map +1 -1
  116. package/build-module/navigator/index.js +130 -5
  117. package/build-module/navigator/index.js.map +1 -1
  118. package/build-module/navigator/legacy.js +167 -0
  119. package/build-module/navigator/legacy.js.map +1 -0
  120. package/build-module/navigator/{navigator-provider → navigator}/component.js +4 -39
  121. package/build-module/navigator/navigator/component.js.map +1 -0
  122. package/build-module/navigator/navigator-back-button/component.js +1 -37
  123. package/build-module/navigator/navigator-back-button/component.js.map +1 -1
  124. package/build-module/navigator/navigator-back-button/hook.js +1 -1
  125. package/build-module/navigator/navigator-back-button/hook.js.map +1 -1
  126. package/build-module/navigator/navigator-button/component.js +1 -36
  127. package/build-module/navigator/navigator-button/component.js.map +1 -1
  128. package/build-module/navigator/navigator-button/hook.js +1 -1
  129. package/build-module/navigator/navigator-button/hook.js.map +1 -1
  130. package/build-module/navigator/navigator-screen/component.js +39 -61
  131. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  132. package/build-module/navigator/navigator-screen/use-screen-animate-presence.js +106 -0
  133. package/build-module/navigator/navigator-screen/use-screen-animate-presence.js.map +1 -0
  134. package/build-module/navigator/navigator-to-parent-button/component.js +2 -6
  135. package/build-module/navigator/navigator-to-parent-button/component.js.map +1 -1
  136. package/build-module/navigator/styles.js +77 -33
  137. package/build-module/navigator/styles.js.map +1 -1
  138. package/build-module/navigator/types.js.map +1 -1
  139. package/build-module/navigator/use-navigator.js +4 -1
  140. package/build-module/navigator/use-navigator.js.map +1 -1
  141. package/build-module/search-control/index.js +5 -2
  142. package/build-module/search-control/index.js.map +1 -1
  143. package/build-module/tabs/styles.js +3 -3
  144. package/build-module/tabs/styles.js.map +1 -1
  145. package/build-module/tabs/tablist.js +62 -29
  146. package/build-module/tabs/tablist.js.map +1 -1
  147. package/build-module/tabs/use-track-overflow.js +67 -0
  148. package/build-module/tabs/use-track-overflow.js.map +1 -0
  149. package/build-module/toggle-group-control/toggle-group-control/as-button-group.js +4 -2
  150. package/build-module/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
  151. package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js +9 -3
  152. package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
  153. package/build-module/toggle-group-control/toggle-group-control/component.js +76 -10
  154. package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
  155. package/build-module/toggle-group-control/toggle-group-control/styles.js +7 -7
  156. package/build-module/toggle-group-control/toggle-group-control/styles.js.map +1 -1
  157. package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +12 -22
  158. package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
  159. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +7 -8
  160. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  161. package/build-module/toggle-group-control/types.js.map +1 -1
  162. package/build-module/utils/element-rect.js +22 -12
  163. package/build-module/utils/element-rect.js.map +1 -1
  164. package/build-module/utils/hooks/use-on-value-update.js +3 -6
  165. package/build-module/utils/hooks/use-on-value-update.js.map +1 -1
  166. package/build-style/style-rtl.css +26 -13
  167. package/build-style/style.css +26 -13
  168. package/build-types/autocomplete/index.d.ts.map +1 -1
  169. package/build-types/border-box-control/border-box-control/component.d.ts +5 -15
  170. package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
  171. package/build-types/border-box-control/border-box-control-split-controls/component.d.ts +2 -1
  172. package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
  173. package/build-types/border-box-control/stories/index.story.d.ts +3 -2
  174. package/build-types/border-box-control/stories/index.story.d.ts.map +1 -1
  175. package/build-types/border-control/border-control/component.d.ts +3 -2
  176. package/build-types/border-control/border-control/component.d.ts.map +1 -1
  177. package/build-types/border-control/border-control-dropdown/component.d.ts +2 -1
  178. package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
  179. package/build-types/border-control/border-control-style-picker/component.d.ts.map +1 -1
  180. package/build-types/border-control/stories/index.story.d.ts +15 -30
  181. package/build-types/border-control/stories/index.story.d.ts.map +1 -1
  182. package/build-types/border-control/styles.d.ts.map +1 -1
  183. package/build-types/border-control/types.d.ts +12 -7
  184. package/build-types/border-control/types.d.ts.map +1 -1
  185. package/build-types/box-control/index.d.ts +4 -4
  186. package/build-types/box-control/stories/index.story.d.ts.map +1 -1
  187. package/build-types/box-control/types.d.ts +3 -3
  188. package/build-types/composite/group-label.d.ts.map +1 -1
  189. package/build-types/composite/index.d.ts.map +1 -1
  190. package/build-types/composite/item.d.ts.map +1 -1
  191. package/build-types/composite/stories/index.story.d.ts +22 -0
  192. package/build-types/composite/stories/index.story.d.ts.map +1 -1
  193. package/build-types/composite/test/index.d.ts +2 -0
  194. package/build-types/composite/test/index.d.ts.map +1 -0
  195. package/build-types/date-time/date/index.d.ts.map +1 -1
  196. package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
  197. package/build-types/dropdown-menu/stories/index.story.d.ts.map +1 -1
  198. package/build-types/index.d.ts +23 -4
  199. package/build-types/index.d.ts.map +1 -1
  200. package/build-types/navigator/index.d.ts +171 -5
  201. package/build-types/navigator/index.d.ts.map +1 -1
  202. package/build-types/navigator/legacy.d.ts +226 -0
  203. package/build-types/navigator/legacy.d.ts.map +1 -0
  204. package/build-types/navigator/navigator/component.d.ts +3 -0
  205. package/build-types/navigator/navigator/component.d.ts.map +1 -0
  206. package/build-types/navigator/navigator-back-button/component.d.ts +0 -35
  207. package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
  208. package/build-types/navigator/navigator-button/component.d.ts +0 -34
  209. package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
  210. package/build-types/navigator/navigator-screen/component.d.ts +0 -35
  211. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  212. package/build-types/navigator/navigator-screen/use-screen-animate-presence.d.ts +16 -0
  213. package/build-types/navigator/navigator-screen/use-screen-animate-presence.d.ts.map +1 -0
  214. package/build-types/navigator/navigator-to-parent-button/component.d.ts +0 -4
  215. package/build-types/navigator/navigator-to-parent-button/component.d.ts.map +1 -1
  216. package/build-types/navigator/stories/index.story.d.ts +5 -5
  217. package/build-types/navigator/stories/index.story.d.ts.map +1 -1
  218. package/build-types/navigator/styles.d.ts +20 -7
  219. package/build-types/navigator/styles.d.ts.map +1 -1
  220. package/build-types/navigator/types.d.ts +19 -1
  221. package/build-types/navigator/types.d.ts.map +1 -1
  222. package/build-types/navigator/use-navigator.d.ts +4 -1
  223. package/build-types/navigator/use-navigator.d.ts.map +1 -1
  224. package/build-types/select-control/stories/index.story.d.ts +7 -0
  225. package/build-types/select-control/stories/index.story.d.ts.map +1 -1
  226. package/build-types/tabs/stories/index.story.d.ts +2 -1
  227. package/build-types/tabs/stories/index.story.d.ts.map +1 -1
  228. package/build-types/tabs/styles.d.ts.map +1 -1
  229. package/build-types/tabs/tablist.d.ts.map +1 -1
  230. package/build-types/tabs/use-track-overflow.d.ts +17 -0
  231. package/build-types/tabs/use-track-overflow.d.ts.map +1 -0
  232. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +2 -2
  233. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts.map +1 -1
  234. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +2 -2
  235. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts.map +1 -1
  236. package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
  237. package/build-types/toggle-group-control/toggle-group-control/styles.d.ts.map +1 -1
  238. package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
  239. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts +0 -1
  240. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  241. package/build-types/toggle-group-control/types.d.ts +2 -1
  242. package/build-types/toggle-group-control/types.d.ts.map +1 -1
  243. package/build-types/utils/element-rect.d.ts +8 -0
  244. package/build-types/utils/element-rect.d.ts.map +1 -1
  245. package/build-types/utils/hooks/use-on-value-update.d.ts.map +1 -1
  246. package/package.json +19 -19
  247. package/src/autocomplete/index.tsx +4 -1
  248. package/src/border-box-control/border-box-control/README.md +22 -26
  249. package/src/border-box-control/border-box-control/component.tsx +3 -14
  250. package/src/border-box-control/stories/index.story.tsx +2 -1
  251. package/src/border-control/border-control/README.md +26 -36
  252. package/src/border-control/border-control/component.tsx +1 -2
  253. package/src/border-control/border-control-dropdown/component.tsx +1 -15
  254. package/src/border-control/stories/index.story.tsx +4 -10
  255. package/src/border-control/styles.ts +0 -1
  256. package/src/border-control/test/index.js +2 -15
  257. package/src/border-control/types.ts +12 -7
  258. package/src/box-control/README.md +9 -12
  259. package/src/box-control/index.tsx +4 -4
  260. package/src/box-control/stories/index.story.tsx +1 -1
  261. package/src/box-control/types.ts +3 -3
  262. package/src/composite/group-label.tsx +7 -5
  263. package/src/composite/group.tsx +7 -7
  264. package/src/composite/hover.tsx +7 -7
  265. package/src/composite/index.tsx +6 -1
  266. package/src/composite/item.tsx +19 -1
  267. package/src/composite/legacy/test/index.tsx +22 -21
  268. package/src/composite/row.tsx +7 -7
  269. package/src/composite/stories/index.story.tsx +42 -0
  270. package/src/composite/test/index.tsx +123 -0
  271. package/src/composite/typeahead.tsx +7 -7
  272. package/src/date-time/date/index.tsx +2 -0
  273. package/src/dropdown/stories/index.story.tsx +1 -0
  274. package/src/dropdown/style.scss +10 -13
  275. package/src/dropdown-menu/stories/index.story.tsx +3 -0
  276. package/src/index.ts +19 -1
  277. package/src/menu-group/style.scss +4 -1
  278. package/src/menu-items-choice/style.scss +2 -0
  279. package/src/navigator/README.md +176 -0
  280. package/src/navigator/index.tsx +131 -0
  281. package/src/navigator/legacy.ts +169 -0
  282. package/src/navigator/{navigator-provider → navigator}/component.tsx +6 -44
  283. package/src/navigator/navigator-back-button/component.tsx +1 -37
  284. package/src/navigator/navigator-back-button/hook.ts +1 -1
  285. package/src/navigator/navigator-button/component.tsx +1 -36
  286. package/src/navigator/navigator-button/hook.ts +1 -1
  287. package/src/navigator/navigator-screen/component.tsx +48 -76
  288. package/src/navigator/navigator-screen/use-screen-animate-presence.ts +177 -0
  289. package/src/navigator/navigator-to-parent-button/component.tsx +2 -7
  290. package/src/navigator/stories/index.story.tsx +55 -54
  291. package/src/navigator/styles.ts +112 -41
  292. package/src/navigator/test/index.tsx +47 -47
  293. package/src/navigator/types.ts +19 -1
  294. package/src/navigator/use-navigator.ts +4 -1
  295. package/src/search-control/index.tsx +2 -2
  296. package/src/select-control/stories/index.story.tsx +14 -1
  297. package/src/tabs/stories/index.story.tsx +106 -0
  298. package/src/tabs/styles.ts +54 -20
  299. package/src/tabs/tablist.tsx +60 -26
  300. package/src/tabs/use-track-overflow.ts +76 -0
  301. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +208 -44
  302. package/src/toggle-group-control/toggle-group-control/as-button-group.tsx +18 -10
  303. package/src/toggle-group-control/toggle-group-control/as-radio-group.tsx +21 -9
  304. package/src/toggle-group-control/toggle-group-control/component.tsx +114 -6
  305. package/src/toggle-group-control/toggle-group-control/styles.ts +41 -0
  306. package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +10 -27
  307. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +0 -11
  308. package/src/toggle-group-control/types.ts +3 -1
  309. package/src/tools-panel/tools-panel/README.md +10 -10
  310. package/src/utils/element-rect.ts +32 -15
  311. package/src/utils/hooks/use-on-value-update.ts +3 -6
  312. package/tsconfig.tsbuildinfo +1 -1
  313. package/build/navigator/navigator-provider/component.js.map +0 -1
  314. package/build/utils/hooks/use-event.js +0 -41
  315. package/build/utils/hooks/use-event.js.map +0 -1
  316. package/build-module/navigator/navigator-provider/component.js.map +0 -1
  317. package/build-module/utils/hooks/use-event.js +0 -35
  318. package/build-module/utils/hooks/use-event.js.map +0 -1
  319. package/build-types/navigator/navigator-provider/component.d.ts +0 -37
  320. package/build-types/navigator/navigator-provider/component.d.ts.map +0 -1
  321. package/build-types/utils/hooks/use-event.d.ts +0 -20
  322. package/build-types/utils/hooks/use-event.d.ts.map +0 -1
  323. package/src/navigator/index.ts +0 -6
  324. package/src/navigator/navigator-back-button/README.md +0 -15
  325. package/src/navigator/navigator-button/README.md +0 -38
  326. package/src/navigator/navigator-provider/README.md +0 -94
  327. package/src/navigator/navigator-screen/README.md +0 -33
  328. package/src/navigator/navigator-to-parent-button/README.md +0 -17
  329. package/src/utils/hooks/use-event.ts +0 -38
@@ -0,0 +1,176 @@
1
+ # `Navigator`
2
+
3
+ `Navigator` is a collection components that allow rendering nested views/panels/menus (via the `Navigator.Screen` component) and navigate between them (via the `Navigator.Button` and `Navigator.BackButton` components).
4
+
5
+ ## Usage
6
+
7
+ ```jsx
8
+ import { Navigator } from '@wordpress/components';
9
+
10
+ const MyNavigation = () => (
11
+ <Navigator initialPath="/">
12
+ <Navigator.Screen path="/">
13
+ <p>This is the home screen.</p>
14
+ <Navigator.Button path="/child">
15
+ Navigate to child screen.
16
+ </Navigator.Button>
17
+ </Navigator.Screen>
18
+ <Navigator.Screen path="/child">
19
+ <p>This is the child screen.</p>
20
+ <Navigator.BackButton>Go back</Navigator.BackButton>
21
+ </Navigator.Screen>
22
+ </Navigator>
23
+ );
24
+ ```
25
+
26
+ ### Hierarchical `path`s
27
+
28
+ `Navigator` assumes that screens are organized hierarchically according to their `path`, which should follow a URL-like scheme where each path segment starts with and is separated by the `/` character.
29
+
30
+ `Navigator` will treat "back" navigations as going to the parent screen — it is, therefore, the responsibility of the consumer of the component to create the correct screen hierarchy.
31
+
32
+ For example:
33
+
34
+ - `/` is the root of all paths. There should always be a screen with `path="/"`;
35
+ - `/parent/child` is a child of `/parent`;
36
+ - `/parent/child/grand-child` is a child of `/parent/child`;
37
+ - `/parent/:param` is a child of `/parent` as well;
38
+ - if the current screen has a `path="/parent/child/grand-child"`, when going "back" `Navigator` will try to recursively navigate the path hierarchy until a matching screen (or the root `/`) is found.
39
+
40
+ ### Height and animations
41
+
42
+ Due to how `Navigator.Screen` animations work, it is recommended that the `Navigator` component is assigned a `height` to prevent some potential UI jumps while moving across screens.
43
+
44
+ ### Individual components
45
+
46
+ `Navigator` is comprised of four individual components:
47
+
48
+ - `Navigator`: a wrapper component and context provider. It holds the main logic for hiding and showing screens.
49
+ - `Navigator.Screen`: represents a single view/screen/panel;
50
+ - `Navigator.Button`: renders a button that allows navigating to a different `Navigator.Screen`;
51
+ - `Navigator.BackButton`: renders a button that allows navigating to the parent `Navigator.Screen` (see the section above about hierarchical paths).
52
+
53
+ For advanced usages, consumers can use the `useNavigator` hook.
54
+
55
+ #### `Navigator`
56
+
57
+ ##### Props
58
+
59
+ ###### `initialPath`: `string`
60
+
61
+ The initial active path.
62
+
63
+ - Required: Yes
64
+
65
+ ###### `children`: `string`
66
+
67
+ The children elements.
68
+
69
+ - Required: Yes
70
+
71
+ #### `Navigator.Screen`
72
+
73
+ ##### Props
74
+
75
+ ###### `path`: `string`
76
+
77
+ The screen's path, matched against the current path stored in the navigator.
78
+
79
+ `Navigator` assumes that screens are organized hierarchically according to their `path`, which should follow a URL-like scheme where each path segment starts with and is separated by the `/` character.
80
+
81
+ `Navigator` will treat "back" navigations as going to the parent screen — it is, therefore, the responsibility of the consumer of the component to create the correct screen hierarchy.
82
+
83
+ For example:
84
+
85
+ - `/` is the root of all paths. There should always be a screen with `path="/"`.
86
+ - `/parent/child` is a child of `/parent`.
87
+ - `/parent/child/grand-child` is a child of `/parent/child`.
88
+ - `/parent/:param` is a child of `/parent` as well.
89
+ - if the current screen has a `path` with value `/parent/child/grand-child`, when going "back" `Navigator` will try to recursively navigate the path hierarchy until a matching screen (or the root `/`) is found.
90
+
91
+ - Required: Yes
92
+
93
+ ###### `children`: `string`
94
+
95
+ The children elements.
96
+
97
+ - Required: Yes
98
+
99
+ #### `Navigator.Button`
100
+
101
+ ##### Props
102
+
103
+ ###### `path`: `string`
104
+
105
+ The path of the screen to navigate to. The value of this prop needs to be [a valid value for an HTML attribute](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2).
106
+
107
+ - Required: Yes
108
+
109
+ ###### `attributeName`: `string`
110
+
111
+ The HTML attribute used to identify the `Navigator.Button`, which is used by `Navigator` to restore focus.
112
+
113
+ - Required: No
114
+ - Default: `id`
115
+
116
+ ###### `children`: `string`
117
+
118
+ The children elements.
119
+
120
+ - Required: No
121
+
122
+ ###### Inherited props
123
+
124
+ `Navigator.Button` also inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href` and `target`.
125
+
126
+ #### `Navigator.BackButton`
127
+
128
+ ##### Props
129
+
130
+ ###### `children`: `string`
131
+
132
+ The children elements.
133
+
134
+ - Required: No
135
+
136
+ ###### Inherited props
137
+
138
+ `Navigator.BackButton` also inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href` and `target`.
139
+
140
+ #### `useNavigator`
141
+
142
+ You can retrieve a `navigator` instance by using the `useNavigator` hook.
143
+
144
+ ##### Props
145
+
146
+ The `navigator` instance has a few properties:
147
+
148
+ ###### `goTo`: `( path: string, options: NavigateOptions ) => void`
149
+
150
+ The `goTo` function allows navigating to a given path. The second argument can augment the navigation operations with different options.
151
+
152
+ The available options are:
153
+
154
+ - `focusTargetSelector`: `string`. An optional property used to specify the CSS selector used to restore focus on the matching element when navigating back;
155
+ - `isBack`: `boolean`. An optional property used to specify whether the navigation should be considered as backwards (thus enabling focus restoration when possible, and causing the animation to be backwards too);
156
+ - `skipFocus`: `boolean`. An optional property used to opt out of `Navigator`'s focus management, useful when the consumer of the component wants to manage focus themselves;
157
+
158
+ ###### `goBack`: `( path: string, options: NavigateOptions ) => void`
159
+
160
+ The `goBack` function allows navigating to the parent screen. Parent/child navigation only works if the paths you define are hierarchical (see note above).
161
+
162
+ When a match is not found, the function will try to recursively navigate the path hierarchy until a matching screen (or the root `/`) is found.
163
+
164
+ The available options are the same as for the `goTo` method, except for the `isBack` property, which is not available for the `goBack` method.
165
+
166
+ ###### `location`: `NavigatorLocation`
167
+
168
+ The `location` object represents the current location, and has a few properties:
169
+
170
+ - `path`: `string`. The path associated to the location.
171
+ - `isBack`: `boolean`. A flag that is `true` when the current location was reached by navigating backwards.
172
+ - `isInitial`: `boolean`. A flag that is `true` only for the initial location.
173
+
174
+ ###### `params`: `Record< string, string | string[] >`
175
+
176
+ The parsed record of parameters from the current location. For example if the current screen path is `/product/:productId` and the location is `/product/123`, then `params` will be `{ productId: '123' }`.
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { Navigator as TopLevelNavigator } from './navigator/component';
5
+ import { NavigatorScreen } from './navigator-screen/component';
6
+ import { NavigatorButton } from './navigator-button/component';
7
+ import { NavigatorBackButton } from './navigator-back-button/component';
8
+ export { useNavigator } from './use-navigator';
9
+
10
+ /**
11
+ * The `Navigator` component allows rendering nested views/panels/menus
12
+ * (via the `Navigator.Screen` component) and navigate between them
13
+ * (via the `Navigator.Button` and `Navigator.BackButton` components).
14
+ *
15
+ * ```jsx
16
+ * import { Navigator } from '@wordpress/components';
17
+ *
18
+ * const MyNavigation = () => (
19
+ * <Navigator initialPath="/">
20
+ * <Navigator.Screen path="/">
21
+ * <p>This is the home screen.</p>
22
+ * <Navigator.Button path="/child">
23
+ * Navigate to child screen.
24
+ * </Navigator.Button>
25
+ * </Navigator.Screen>
26
+ *
27
+ * <Navigator.Screen path="/child">
28
+ * <p>This is the child screen.</p>
29
+ * <Navigator.BackButton>
30
+ * Go back
31
+ * </Navigator.BackButton>
32
+ * </Navigator.Screen>
33
+ * </Navigator>
34
+ * );
35
+ * ```
36
+ */
37
+ export const Navigator = Object.assign( TopLevelNavigator, {
38
+ /**
39
+ * The `Navigator.Screen` component represents a single view/screen/panel and
40
+ * should be used in combination with the `Navigator`, the `Navigator.Button`
41
+ * and the `Navigator.BackButton` components.
42
+ *
43
+ * @example
44
+ * ```jsx
45
+ * import { Navigator } from '@wordpress/components';
46
+ *
47
+ * const MyNavigation = () => (
48
+ * <Navigator initialPath="/">
49
+ * <Navigator.Screen path="/">
50
+ * <p>This is the home screen.</p>
51
+ * <Navigator.Button path="/child">
52
+ * Navigate to child screen.
53
+ * </Navigator.Button>
54
+ * </Navigator.Screen>
55
+ *
56
+ * <Navigator.Screen path="/child">
57
+ * <p>This is the child screen.</p>
58
+ * <Navigator.BackButton>
59
+ * Go back
60
+ * </Navigator.BackButton>
61
+ * </Navigator.Screen>
62
+ * </Navigator>
63
+ * );
64
+ * ```
65
+ */
66
+ Screen: Object.assign( NavigatorScreen, {
67
+ displayName: 'Navigator.Screen',
68
+ } ),
69
+ /**
70
+ * The `Navigator.Button` component can be used to navigate to a screen and
71
+ * should be used in combination with the `Navigator`, the `Navigator.Screen`
72
+ * and the `Navigator.BackButton` components.
73
+ *
74
+ * @example
75
+ * ```jsx
76
+ * import { Navigator } from '@wordpress/components';
77
+ *
78
+ * const MyNavigation = () => (
79
+ * <Navigator initialPath="/">
80
+ * <Navigator.Screen path="/">
81
+ * <p>This is the home screen.</p>
82
+ * <Navigator.Button path="/child">
83
+ * Navigate to child screen.
84
+ * </Navigator.Button>
85
+ * </Navigator.Screen>
86
+ *
87
+ * <Navigator.Screen path="/child">
88
+ * <p>This is the child screen.</p>
89
+ * <Navigator.BackButton>
90
+ * Go back
91
+ * </Navigator.BackButton>
92
+ * </Navigator.Screen>
93
+ * </Navigator>
94
+ * );
95
+ * ```
96
+ */
97
+ Button: Object.assign( NavigatorButton, {
98
+ displayName: 'Navigator.Button',
99
+ } ),
100
+ /**
101
+ * The `Navigator.BackButton` component can be used to navigate to a screen and
102
+ * should be used in combination with the `Navigator`, the `Navigator.Screen`
103
+ * and the `Navigator.Button` components.
104
+ *
105
+ * @example
106
+ * ```jsx
107
+ * import { Navigator } from '@wordpress/components';
108
+ *
109
+ * const MyNavigation = () => (
110
+ * <Navigator initialPath="/">
111
+ * <Navigator.Screen path="/">
112
+ * <p>This is the home screen.</p>
113
+ * <Navigator.Button path="/child">
114
+ * Navigate to child screen.
115
+ * </Navigator.Button>
116
+ * </Navigator.Screen>
117
+ *
118
+ * <Navigator.Screen path="/child">
119
+ * <p>This is the child screen.</p>
120
+ * <Navigator.BackButton>
121
+ * Go back
122
+ * </Navigator.BackButton>
123
+ * </Navigator.Screen>
124
+ * </Navigator>
125
+ * );
126
+ * ```
127
+ */
128
+ BackButton: Object.assign( NavigatorBackButton, {
129
+ displayName: 'Navigator.BackButton',
130
+ } ),
131
+ } );
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { Navigator as InternalNavigator } from './navigator/component';
5
+ import { NavigatorScreen as InternalNavigatorScreen } from './navigator-screen/component';
6
+ import { NavigatorButton as InternalNavigatorButton } from './navigator-button/component';
7
+ import { NavigatorBackButton as InternalNavigatorBackButton } from './navigator-back-button/component';
8
+ import { NavigatorToParentButton as InternalNavigatorToParentButton } from './navigator-to-parent-button/component';
9
+ export { useNavigator } from './use-navigator';
10
+
11
+ /**
12
+ * The `NavigatorProvider` component allows rendering nested views/panels/menus
13
+ * (via the `NavigatorScreen` component and navigate between them
14
+ * (via the `NavigatorButton` and `NavigatorBackButton` components).
15
+ *
16
+ * ```jsx
17
+ * import {
18
+ * __experimentalNavigatorProvider as NavigatorProvider,
19
+ * __experimentalNavigatorScreen as NavigatorScreen,
20
+ * __experimentalNavigatorButton as NavigatorButton,
21
+ * __experimentalNavigatorBackButton as NavigatorBackButton,
22
+ * } from '@wordpress/components';
23
+ *
24
+ * const MyNavigation = () => (
25
+ * <NavigatorProvider initialPath="/">
26
+ * <NavigatorScreen path="/">
27
+ * <p>This is the home screen.</p>
28
+ * <NavigatorButton path="/child">
29
+ * Navigate to child screen.
30
+ * </NavigatorButton>
31
+ * </NavigatorScreen>
32
+ *
33
+ * <NavigatorScreen path="/child">
34
+ * <p>This is the child screen.</p>
35
+ * <NavigatorBackButton>
36
+ * Go back
37
+ * </NavigatorBackButton>
38
+ * </NavigatorScreen>
39
+ * </NavigatorProvider>
40
+ * );
41
+ * ```
42
+ */
43
+ export const NavigatorProvider = Object.assign( InternalNavigator, {
44
+ displayName: 'NavigatorProvider',
45
+ } );
46
+
47
+ /**
48
+ * The `NavigatorScreen` component represents a single view/screen/panel and
49
+ * should be used in combination with the `NavigatorProvider`, the
50
+ * `NavigatorButton` and the `NavigatorBackButton` components.
51
+ *
52
+ * @example
53
+ * ```jsx
54
+ * import {
55
+ * __experimentalNavigatorProvider as NavigatorProvider,
56
+ * __experimentalNavigatorScreen as NavigatorScreen,
57
+ * __experimentalNavigatorButton as NavigatorButton,
58
+ * __experimentalNavigatorBackButton as NavigatorBackButton,
59
+ * } from '@wordpress/components';
60
+ *
61
+ * const MyNavigation = () => (
62
+ * <NavigatorProvider initialPath="/">
63
+ * <NavigatorScreen path="/">
64
+ * <p>This is the home screen.</p>
65
+ * <NavigatorButton path="/child">
66
+ * Navigate to child screen.
67
+ * </NavigatorButton>
68
+ * </NavigatorScreen>
69
+ *
70
+ * <NavigatorScreen path="/child">
71
+ * <p>This is the child screen.</p>
72
+ * <NavigatorBackButton>
73
+ * Go back
74
+ * </NavigatorBackButton>
75
+ * </NavigatorScreen>
76
+ * </NavigatorProvider>
77
+ * );
78
+ * ```
79
+ */
80
+ export const NavigatorScreen = Object.assign( InternalNavigatorScreen, {
81
+ displayName: 'NavigatorScreen',
82
+ } );
83
+
84
+ /**
85
+ * The `NavigatorButton` component can be used to navigate to a screen and should
86
+ * be used in combination with the `NavigatorProvider`, the `NavigatorScreen`
87
+ * and the `NavigatorBackButton` components.
88
+ *
89
+ * @example
90
+ * ```jsx
91
+ * import {
92
+ * __experimentalNavigatorProvider as NavigatorProvider,
93
+ * __experimentalNavigatorScreen as NavigatorScreen,
94
+ * __experimentalNavigatorButton as NavigatorButton,
95
+ * __experimentalNavigatorBackButton as NavigatorBackButton,
96
+ * } from '@wordpress/components';
97
+ *
98
+ * const MyNavigation = () => (
99
+ * <NavigatorProvider initialPath="/">
100
+ * <NavigatorScreen path="/">
101
+ * <p>This is the home screen.</p>
102
+ * <NavigatorButton path="/child">
103
+ * Navigate to child screen.
104
+ * </NavigatorButton>
105
+ * </NavigatorScreen>
106
+ *
107
+ * <NavigatorScreen path="/child">
108
+ * <p>This is the child screen.</p>
109
+ * <NavigatorBackButton>
110
+ * Go back
111
+ * </NavigatorBackButton>
112
+ * </NavigatorScreen>
113
+ * </NavigatorProvider>
114
+ * );
115
+ * ```
116
+ */
117
+ export const NavigatorButton = Object.assign( InternalNavigatorButton, {
118
+ displayName: 'NavigatorButton',
119
+ } );
120
+
121
+ /**
122
+ * The `NavigatorBackButton` component can be used to navigate to a screen and
123
+ * should be used in combination with the `NavigatorProvider`, the
124
+ * `NavigatorScreen` and the `NavigatorButton` components.
125
+ *
126
+ * @example
127
+ * ```jsx
128
+ * import {
129
+ * __experimentalNavigatorProvider as NavigatorProvider,
130
+ * __experimentalNavigatorScreen as NavigatorScreen,
131
+ * __experimentalNavigatorButton as NavigatorButton,
132
+ * __experimentalNavigatorBackButton as NavigatorBackButton,
133
+ * } from '@wordpress/components';
134
+ *
135
+ * const MyNavigation = () => (
136
+ * <NavigatorProvider initialPath="/">
137
+ * <NavigatorScreen path="/">
138
+ * <p>This is the home screen.</p>
139
+ * <NavigatorButton path="/child">
140
+ * Navigate to child screen.
141
+ * </NavigatorButton>
142
+ * </NavigatorScreen>
143
+ *
144
+ * <NavigatorScreen path="/child">
145
+ * <p>This is the child screen.</p>
146
+ * <NavigatorBackButton>
147
+ * Go back (to parent)
148
+ * </NavigatorBackButton>
149
+ * </NavigatorScreen>
150
+ * </NavigatorProvider>
151
+ * );
152
+ * ```
153
+ */
154
+ export const NavigatorBackButton = Object.assign( InternalNavigatorBackButton, {
155
+ displayName: 'NavigatorBackButton',
156
+ } );
157
+
158
+ /**
159
+ * _Note: this component is deprecated. Please use the `NavigatorBackButton`
160
+ * component instead._
161
+ *
162
+ * @deprecated
163
+ */
164
+ export const NavigatorToParentButton = Object.assign(
165
+ InternalNavigatorToParentButton,
166
+ {
167
+ displayName: 'NavigatorToParentButton',
168
+ }
169
+ );
@@ -21,7 +21,7 @@ import { View } from '../../view';
21
21
  import { NavigatorContext } from '../context';
22
22
  import * as styles from '../styles';
23
23
  import type {
24
- NavigatorProviderProps,
24
+ NavigatorProps,
25
25
  NavigatorLocation,
26
26
  NavigatorContext as NavigatorContextType,
27
27
  NavigateOptions,
@@ -213,8 +213,8 @@ function routerReducer(
213
213
  };
214
214
  }
215
215
 
216
- function UnconnectedNavigatorProvider(
217
- props: WordPressComponentProps< NavigatorProviderProps, 'div' >,
216
+ function UnconnectedNavigator(
217
+ props: WordPressComponentProps< NavigatorProps, 'div' >,
218
218
  forwardedRef: ForwardedRef< any >
219
219
  ) {
220
220
  const {
@@ -222,7 +222,7 @@ function UnconnectedNavigatorProvider(
222
222
  children,
223
223
  className,
224
224
  ...otherProps
225
- } = useContextSystem( props, 'NavigatorProvider' );
225
+ } = useContextSystem( props, 'Navigator' );
226
226
 
227
227
  const [ routerState, dispatch ] = useReducer(
228
228
  routerReducer,
@@ -275,7 +275,7 @@ function UnconnectedNavigatorProvider(
275
275
 
276
276
  const cx = useCx();
277
277
  const classes = useMemo(
278
- () => cx( styles.navigatorProviderWrapper, className ),
278
+ () => cx( styles.navigatorWrapper, className ),
279
279
  [ className, cx ]
280
280
  );
281
281
 
@@ -288,42 +288,4 @@ function UnconnectedNavigatorProvider(
288
288
  );
289
289
  }
290
290
 
291
- /**
292
- * The `NavigatorProvider` component allows rendering nested views/panels/menus
293
- * (via the `NavigatorScreen` component and navigate between these different
294
- * view (via the `NavigatorButton` and `NavigatorBackButton` components or the
295
- * `useNavigator` hook).
296
- *
297
- * ```jsx
298
- * import {
299
- * __experimentalNavigatorProvider as NavigatorProvider,
300
- * __experimentalNavigatorScreen as NavigatorScreen,
301
- * __experimentalNavigatorButton as NavigatorButton,
302
- * __experimentalNavigatorBackButton as NavigatorBackButton,
303
- * } from '@wordpress/components';
304
- *
305
- * const MyNavigation = () => (
306
- * <NavigatorProvider initialPath="/">
307
- * <NavigatorScreen path="/">
308
- * <p>This is the home screen.</p>
309
- * <NavigatorButton path="/child">
310
- * Navigate to child screen.
311
- * </NavigatorButton>
312
- * </NavigatorScreen>
313
- *
314
- * <NavigatorScreen path="/child">
315
- * <p>This is the child screen.</p>
316
- * <NavigatorBackButton>
317
- * Go back
318
- * </NavigatorBackButton>
319
- * </NavigatorScreen>
320
- * </NavigatorProvider>
321
- * );
322
- * ```
323
- */
324
- export const NavigatorProvider = contextConnect(
325
- UnconnectedNavigatorProvider,
326
- 'NavigatorProvider'
327
- );
328
-
329
- export default NavigatorProvider;
291
+ export const Navigator = contextConnect( UnconnectedNavigator, 'Navigator' );
@@ -21,43 +21,7 @@ function UnconnectedNavigatorBackButton(
21
21
  return <View ref={ forwardedRef } { ...navigatorBackButtonProps } />;
22
22
  }
23
23
 
24
- /**
25
- * The `NavigatorBackButton` component can be used to navigate to a screen and
26
- * should be used in combination with the `NavigatorProvider`, the
27
- * `NavigatorScreen` and the `NavigatorButton` components (or the `useNavigator`
28
- * hook).
29
- *
30
- * @example
31
- * ```jsx
32
- * import {
33
- * __experimentalNavigatorProvider as NavigatorProvider,
34
- * __experimentalNavigatorScreen as NavigatorScreen,
35
- * __experimentalNavigatorButton as NavigatorButton,
36
- * __experimentalNavigatorBackButton as NavigatorBackButton,
37
- * } from '@wordpress/components';
38
- *
39
- * const MyNavigation = () => (
40
- * <NavigatorProvider initialPath="/">
41
- * <NavigatorScreen path="/">
42
- * <p>This is the home screen.</p>
43
- * <NavigatorButton path="/child">
44
- * Navigate to child screen.
45
- * </NavigatorButton>
46
- * </NavigatorScreen>
47
- *
48
- * <NavigatorScreen path="/child">
49
- * <p>This is the child screen.</p>
50
- * <NavigatorBackButton>
51
- * Go back (to parent)
52
- * </NavigatorBackButton>
53
- * </NavigatorScreen>
54
- * </NavigatorProvider>
55
- * );
56
- * ```
57
- */
58
24
  export const NavigatorBackButton = contextConnect(
59
25
  UnconnectedNavigatorBackButton,
60
- 'NavigatorBackButton'
26
+ 'Navigator.BackButton'
61
27
  );
62
-
63
- export default NavigatorBackButton;
@@ -20,7 +20,7 @@ export function useNavigatorBackButton(
20
20
  as = Button,
21
21
 
22
22
  ...otherProps
23
- } = useContextSystem( props, 'NavigatorBackButton' );
23
+ } = useContextSystem( props, 'Navigator.BackButton' );
24
24
 
25
25
  const { goBack } = useNavigator();
26
26
  const handleClick: React.MouseEventHandler< HTMLButtonElement > =
@@ -21,42 +21,7 @@ function UnconnectedNavigatorButton(
21
21
  return <View ref={ forwardedRef } { ...navigatorButtonProps } />;
22
22
  }
23
23
 
24
- /**
25
- * The `NavigatorButton` component can be used to navigate to a screen and should
26
- * be used in combination with the `NavigatorProvider`, the `NavigatorScreen`
27
- * and the `NavigatorBackButton` components (or the `useNavigator` hook).
28
- *
29
- * @example
30
- * ```jsx
31
- * import {
32
- * __experimentalNavigatorProvider as NavigatorProvider,
33
- * __experimentalNavigatorScreen as NavigatorScreen,
34
- * __experimentalNavigatorButton as NavigatorButton,
35
- * __experimentalNavigatorBackButton as NavigatorBackButton,
36
- * } from '@wordpress/components';
37
- *
38
- * const MyNavigation = () => (
39
- * <NavigatorProvider initialPath="/">
40
- * <NavigatorScreen path="/">
41
- * <p>This is the home screen.</p>
42
- * <NavigatorButton path="/child">
43
- * Navigate to child screen.
44
- * </NavigatorButton>
45
- * </NavigatorScreen>
46
- *
47
- * <NavigatorScreen path="/child">
48
- * <p>This is the child screen.</p>
49
- * <NavigatorBackButton>
50
- * Go back
51
- * </NavigatorBackButton>
52
- * </NavigatorScreen>
53
- * </NavigatorProvider>
54
- * );
55
- * ```
56
- */
57
24
  export const NavigatorButton = contextConnect(
58
25
  UnconnectedNavigatorButton,
59
- 'NavigatorButton'
26
+ 'Navigator.Button'
60
27
  );
61
-
62
- export default NavigatorButton;
@@ -25,7 +25,7 @@ export function useNavigatorButton(
25
25
  as = Button,
26
26
  attributeName = 'id',
27
27
  ...otherProps
28
- } = useContextSystem( props, 'NavigatorButton' );
28
+ } = useContextSystem( props, 'Navigator.Button' );
29
29
 
30
30
  const escapedPath = escapeAttribute( path );
31
31