newspack-components 2.0.3 → 2.2.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 (315) hide show
  1. package/copy-styles.js +1 -1
  2. package/dist/cjs/accordion/index.js +46 -0
  3. package/dist/cjs/accordion/style.scss +27 -0
  4. package/dist/cjs/action-card/index.js +72 -40
  5. package/dist/cjs/action-card/style.scss +143 -41
  6. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  7. package/dist/cjs/autocomplete-tokenfield/style.scss +6 -6
  8. package/dist/cjs/autocomplete-with-suggestions/index.js +33 -53
  9. package/dist/cjs/autocomplete-with-suggestions/style.scss +27 -27
  10. package/dist/cjs/button/index.js +1 -20
  11. package/dist/cjs/button/style.scss +3 -344
  12. package/dist/cjs/button-card/index.js +11 -15
  13. package/dist/cjs/button-card/style.scss +65 -35
  14. package/dist/cjs/card/index.js +4 -9
  15. package/dist/cjs/card/style.scss +47 -63
  16. package/dist/cjs/category-autocomplete/index.js +66 -47
  17. package/dist/cjs/category-autocomplete/style.scss +20 -24
  18. package/dist/cjs/color-picker/index.js +16 -48
  19. package/dist/cjs/color-picker/style.scss +20 -163
  20. package/dist/cjs/consts.js +5 -3
  21. package/dist/cjs/custom-select-control/index.js +1 -9
  22. package/dist/cjs/custom-select-control/style.scss +14 -45
  23. package/dist/cjs/date-range-picker/index.js +1 -10
  24. package/dist/cjs/date-range-picker/style.scss +12 -12
  25. package/dist/cjs/footer/index.js +24 -22
  26. package/dist/cjs/footer/style.scss +13 -14
  27. package/dist/cjs/form-token-field/index.js +3 -11
  28. package/dist/cjs/form-token-field/style.scss +9 -105
  29. package/dist/cjs/global-notices/index.js +3 -9
  30. package/dist/cjs/grid/index.js +1 -8
  31. package/dist/cjs/grid/style.scss +19 -6
  32. package/dist/cjs/handoff/index.js +15 -24
  33. package/dist/cjs/handoff-message/index.js +50 -0
  34. package/dist/cjs/hooks/index.js +1 -7
  35. package/dist/cjs/hooks/useObjectState.js +7 -13
  36. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  37. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  38. package/dist/cjs/hooks/usePrompt.js +1 -13
  39. package/dist/cjs/image-upload/index.js +22 -20
  40. package/dist/cjs/image-upload/index.test.js +0 -5
  41. package/dist/cjs/image-upload/style.scss +12 -17
  42. package/dist/cjs/index.js +31 -93
  43. package/dist/cjs/info-button/index.js +3 -11
  44. package/dist/cjs/info-button/style.scss +1 -3
  45. package/dist/cjs/modal/index.js +1 -12
  46. package/dist/cjs/modal/style.scss +20 -132
  47. package/dist/cjs/newspack-icon/index.js +5 -11
  48. package/dist/cjs/newspack-icon/style.scss +17 -2
  49. package/dist/cjs/newspack-logo/index.js +1 -9
  50. package/dist/cjs/newspack-logo/style.scss +3 -3
  51. package/dist/cjs/notice/index.js +8 -16
  52. package/dist/cjs/notice/style.scss +60 -19
  53. package/dist/cjs/patrons-logo/index.js +3 -11
  54. package/dist/cjs/plugin-installer/index.js +37 -37
  55. package/dist/cjs/plugin-installer/style.scss +5 -5
  56. package/dist/cjs/plugin-settings/SettingsSection.js +71 -59
  57. package/dist/cjs/plugin-settings/index.js +71 -50
  58. package/dist/cjs/plugin-settings/style.scss +7 -0
  59. package/dist/cjs/plugin-toggle/index.js +60 -32
  60. package/dist/cjs/plugin-toggle/style.scss +2 -2
  61. package/dist/cjs/popover/index.js +1 -11
  62. package/dist/cjs/popover/style.scss +20 -17
  63. package/dist/cjs/position-control/index.js +113 -0
  64. package/dist/cjs/position-control/style.scss +66 -0
  65. package/dist/cjs/progress-bar/index.js +2 -9
  66. package/dist/cjs/progress-bar/index.test.js +2 -7
  67. package/dist/cjs/progress-bar/style.scss +4 -4
  68. package/dist/cjs/proxied-imports/router.js +0 -3
  69. package/dist/cjs/radio-control/index.js +1 -11
  70. package/dist/cjs/radio-control/style.scss +10 -11
  71. package/dist/cjs/section-header/index.js +47 -19
  72. package/dist/cjs/section-header/style.scss +22 -1
  73. package/dist/cjs/select-control/ButtonGroupControl.js +11 -20
  74. package/dist/cjs/select-control/GroupedSelectControl.js +42 -45
  75. package/dist/cjs/select-control/index.js +6 -14
  76. package/dist/cjs/select-control/style.scss +47 -88
  77. package/dist/cjs/settings/MinMaxSetting.js +6 -8
  78. package/dist/cjs/settings/SettingsCard.js +9 -8
  79. package/dist/cjs/settings/SettingsSection.js +5 -8
  80. package/dist/cjs/settings/index.js +0 -6
  81. package/dist/cjs/settings/style.scss +32 -4
  82. package/dist/cjs/steps-list/index.js +52 -0
  83. package/dist/cjs/steps-list/style.scss +11 -0
  84. package/dist/cjs/steps-list-item/index.js +56 -0
  85. package/dist/cjs/steps-list-item/style.scss +47 -0
  86. package/dist/cjs/style-card/index.js +15 -18
  87. package/dist/cjs/style-card/style.scss +19 -18
  88. package/dist/cjs/style.scss +43 -0
  89. package/dist/cjs/tabbed-navigation/index.js +27 -31
  90. package/dist/cjs/tabbed-navigation/style.scss +58 -37
  91. package/dist/cjs/text-control/index.js +6 -19
  92. package/dist/cjs/text-control/style.scss +0 -126
  93. package/dist/cjs/utils/index.js +10 -5
  94. package/dist/cjs/waiting/index.js +9 -33
  95. package/dist/cjs/waiting/style.scss +9 -20
  96. package/dist/cjs/web-preview/index.js +30 -57
  97. package/dist/cjs/web-preview/style.scss +41 -34
  98. package/dist/cjs/with-wizard/index.js +55 -33
  99. package/dist/cjs/with-wizard/style.scss +77 -124
  100. package/dist/cjs/with-wizard-screen/index.js +28 -38
  101. package/dist/cjs/with-wizard-screen/style.scss +75 -125
  102. package/dist/cjs/wizard/components/WizardError.js +74 -0
  103. package/dist/cjs/wizard/index.js +131 -0
  104. package/dist/cjs/wizard/store/index.js +165 -0
  105. package/dist/cjs/wizard/store/utils.js +26 -0
  106. package/dist/cjs/wizard/style.scss +148 -0
  107. package/dist/esm/accordion/index.js +38 -0
  108. package/dist/esm/accordion/style.scss +27 -0
  109. package/dist/esm/action-card/index.js +75 -37
  110. package/dist/esm/action-card/style.scss +143 -41
  111. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  112. package/dist/esm/autocomplete-tokenfield/style.scss +6 -6
  113. package/dist/esm/autocomplete-with-suggestions/index.js +31 -43
  114. package/dist/esm/autocomplete-with-suggestions/style.scss +27 -27
  115. package/dist/esm/button/index.js +2 -14
  116. package/dist/esm/button/style.scss +3 -344
  117. package/dist/esm/button-card/index.js +12 -11
  118. package/dist/esm/button-card/style.scss +65 -35
  119. package/dist/esm/card/index.js +5 -6
  120. package/dist/esm/card/style.scss +47 -63
  121. package/dist/esm/category-autocomplete/index.js +68 -41
  122. package/dist/esm/category-autocomplete/style.scss +20 -24
  123. package/dist/esm/color-picker/index.js +17 -38
  124. package/dist/esm/color-picker/style.scss +20 -163
  125. package/dist/esm/consts.js +3 -2
  126. package/dist/esm/custom-select-control/index.js +2 -5
  127. package/dist/esm/custom-select-control/style.scss +14 -45
  128. package/dist/esm/date-range-picker/index.js +1 -3
  129. package/dist/esm/date-range-picker/style.scss +12 -12
  130. package/dist/esm/footer/index.js +22 -16
  131. package/dist/esm/footer/style.scss +13 -14
  132. package/dist/esm/form-token-field/index.js +4 -7
  133. package/dist/esm/form-token-field/style.scss +9 -105
  134. package/dist/esm/global-notices/index.js +3 -7
  135. package/dist/esm/grid/index.js +2 -5
  136. package/dist/esm/grid/style.scss +19 -6
  137. package/dist/esm/handoff/index.js +10 -21
  138. package/dist/esm/handoff-message/index.js +45 -0
  139. package/dist/esm/hooks/index.js +0 -2
  140. package/dist/esm/hooks/useObjectState.js +3 -8
  141. package/dist/esm/hooks/useObjectState.test.js +0 -3
  142. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  143. package/dist/esm/hooks/usePrompt.js +1 -8
  144. package/dist/esm/image-upload/index.js +18 -17
  145. package/dist/esm/image-upload/style.scss +12 -17
  146. package/dist/esm/index.js +7 -8
  147. package/dist/esm/info-button/index.js +4 -6
  148. package/dist/esm/info-button/style.scss +1 -3
  149. package/dist/esm/modal/index.js +2 -8
  150. package/dist/esm/modal/style.scss +20 -132
  151. package/dist/esm/newspack-icon/index.js +6 -7
  152. package/dist/esm/newspack-icon/style.scss +17 -2
  153. package/dist/esm/newspack-logo/index.js +2 -5
  154. package/dist/esm/newspack-logo/style.scss +3 -3
  155. package/dist/esm/notice/index.js +11 -10
  156. package/dist/esm/notice/style.scss +60 -19
  157. package/dist/esm/patrons-logo/index.js +3 -5
  158. package/dist/esm/plugin-installer/index.js +37 -40
  159. package/dist/esm/plugin-installer/style.scss +5 -5
  160. package/dist/esm/plugin-settings/SettingsSection.js +71 -56
  161. package/dist/esm/plugin-settings/index.js +70 -52
  162. package/dist/esm/plugin-settings/style.scss +7 -0
  163. package/dist/esm/plugin-toggle/index.js +59 -34
  164. package/dist/esm/plugin-toggle/style.scss +2 -2
  165. package/dist/esm/popover/index.js +3 -6
  166. package/dist/esm/popover/style.scss +20 -17
  167. package/dist/esm/position-control/index.js +109 -0
  168. package/dist/esm/position-control/style.scss +66 -0
  169. package/dist/esm/progress-bar/index.js +2 -7
  170. package/dist/esm/progress-bar/index.test.js +2 -1
  171. package/dist/esm/progress-bar/style.scss +4 -4
  172. package/dist/esm/proxied-imports/router.js +1 -0
  173. package/dist/esm/radio-control/index.js +3 -6
  174. package/dist/esm/radio-control/style.scss +10 -11
  175. package/dist/esm/section-header/index.js +47 -16
  176. package/dist/esm/section-header/style.scss +22 -1
  177. package/dist/esm/select-control/ButtonGroupControl.js +12 -14
  178. package/dist/esm/select-control/GroupedSelectControl.js +38 -36
  179. package/dist/esm/select-control/index.js +7 -8
  180. package/dist/esm/select-control/style.scss +47 -88
  181. package/dist/esm/settings/MinMaxSetting.js +4 -5
  182. package/dist/esm/settings/SettingsCard.js +9 -5
  183. package/dist/esm/settings/SettingsSection.js +5 -7
  184. package/dist/esm/settings/style.scss +32 -4
  185. package/dist/esm/steps-list/index.js +43 -0
  186. package/dist/esm/steps-list/style.scss +11 -0
  187. package/dist/esm/steps-list-item/index.js +48 -0
  188. package/dist/esm/steps-list-item/style.scss +47 -0
  189. package/dist/esm/style-card/index.js +13 -13
  190. package/dist/esm/style-card/style.scss +19 -18
  191. package/dist/esm/style.scss +43 -0
  192. package/dist/esm/tabbed-navigation/index.js +30 -28
  193. package/dist/esm/tabbed-navigation/style.scss +58 -37
  194. package/dist/esm/text-control/index.js +2 -12
  195. package/dist/esm/text-control/style.scss +0 -126
  196. package/dist/esm/utils/index.js +9 -3
  197. package/dist/esm/waiting/index.js +11 -27
  198. package/dist/esm/waiting/style.scss +9 -20
  199. package/dist/esm/web-preview/index.js +21 -49
  200. package/dist/esm/web-preview/style.scss +41 -34
  201. package/dist/esm/with-wizard/index.js +53 -36
  202. package/dist/esm/with-wizard/style.scss +77 -124
  203. package/dist/esm/with-wizard-screen/index.js +26 -32
  204. package/dist/esm/with-wizard-screen/style.scss +75 -125
  205. package/dist/esm/wizard/components/WizardError.js +69 -0
  206. package/dist/esm/wizard/index.js +126 -0
  207. package/dist/esm/wizard/store/index.js +155 -0
  208. package/dist/esm/wizard/store/utils.js +17 -0
  209. package/dist/esm/wizard/style.scss +148 -0
  210. package/package.json +4 -4
  211. package/src/accordion/index.js +32 -0
  212. package/src/accordion/style.scss +27 -0
  213. package/src/action-card/index.js +70 -25
  214. package/src/action-card/style.scss +143 -41
  215. package/src/autocomplete-tokenfield/index.js +1 -1
  216. package/src/autocomplete-tokenfield/style.scss +6 -6
  217. package/src/autocomplete-with-suggestions/index.js +4 -2
  218. package/src/autocomplete-with-suggestions/style.scss +27 -27
  219. package/src/button/index.js +2 -9
  220. package/src/button/style.scss +3 -344
  221. package/src/button-card/index.js +19 -5
  222. package/src/button-card/style.scss +65 -35
  223. package/src/card/index.js +4 -0
  224. package/src/card/style.scss +47 -63
  225. package/src/category-autocomplete/index.js +53 -18
  226. package/src/category-autocomplete/style.scss +20 -24
  227. package/src/color-picker/index.js +16 -22
  228. package/src/color-picker/style.scss +20 -163
  229. package/src/consts.js +2 -1
  230. package/src/custom-select-control/style.scss +14 -45
  231. package/src/date-range-picker/style.scss +12 -12
  232. package/src/footer/index.js +20 -9
  233. package/src/footer/style.scss +13 -14
  234. package/src/form-token-field/index.js +3 -8
  235. package/src/form-token-field/style.scss +9 -105
  236. package/src/global-notices/index.js +1 -1
  237. package/src/grid/style.scss +19 -6
  238. package/src/handoff/index.js +10 -15
  239. package/src/handoff-message/index.js +39 -0
  240. package/src/hooks/useObjectState.js +2 -1
  241. package/src/image-upload/index.js +9 -3
  242. package/src/image-upload/style.scss +12 -17
  243. package/src/index.js +7 -7
  244. package/src/info-button/style.scss +1 -3
  245. package/src/modal/index.js +2 -5
  246. package/src/modal/style.scss +20 -132
  247. package/src/newspack-icon/index.js +7 -2
  248. package/src/newspack-icon/style.scss +17 -2
  249. package/src/newspack-logo/style.scss +3 -3
  250. package/src/notice/index.js +9 -1
  251. package/src/notice/style.scss +60 -19
  252. package/src/plugin-installer/index.js +17 -4
  253. package/src/plugin-installer/style.scss +5 -5
  254. package/src/plugin-settings/SettingsSection.js +59 -27
  255. package/src/plugin-settings/index.js +29 -8
  256. package/src/plugin-settings/style.scss +7 -0
  257. package/src/plugin-toggle/index.js +37 -12
  258. package/src/plugin-toggle/style.scss +2 -2
  259. package/src/popover/style.scss +20 -17
  260. package/src/position-control/index.js +122 -0
  261. package/src/position-control/style.scss +66 -0
  262. package/src/progress-bar/style.scss +4 -4
  263. package/src/radio-control/style.scss +10 -11
  264. package/src/section-header/index.js +41 -5
  265. package/src/section-header/style.scss +22 -1
  266. package/src/select-control/ButtonGroupControl.js +15 -5
  267. package/src/select-control/GroupedSelectControl.js +28 -25
  268. package/src/select-control/index.js +6 -3
  269. package/src/select-control/style.scss +47 -88
  270. package/src/settings/MinMaxSetting.js +2 -1
  271. package/src/settings/SettingsCard.js +9 -7
  272. package/src/settings/SettingsSection.js +4 -4
  273. package/src/settings/style.scss +32 -4
  274. package/src/steps-list/index.js +39 -0
  275. package/src/steps-list/style.scss +11 -0
  276. package/src/steps-list-item/index.js +40 -0
  277. package/src/steps-list-item/style.scss +47 -0
  278. package/src/style-card/index.js +16 -27
  279. package/src/style-card/style.scss +19 -18
  280. package/src/style.scss +43 -0
  281. package/src/tabbed-navigation/index.js +20 -24
  282. package/src/tabbed-navigation/style.scss +58 -37
  283. package/src/text-control/index.js +1 -2
  284. package/src/text-control/style.scss +0 -126
  285. package/src/utils/index.js +9 -0
  286. package/src/waiting/index.js +7 -18
  287. package/src/waiting/style.scss +9 -20
  288. package/src/web-preview/index.js +13 -34
  289. package/src/web-preview/style.scss +41 -34
  290. package/src/with-wizard/index.js +7 -5
  291. package/src/with-wizard/style.scss +77 -124
  292. package/src/with-wizard-screen/index.js +17 -17
  293. package/src/with-wizard-screen/style.scss +75 -125
  294. package/src/wizard/components/WizardError.js +57 -0
  295. package/src/wizard/index.js +145 -0
  296. package/src/wizard/store/index.js +132 -0
  297. package/src/wizard/store/utils.js +16 -0
  298. package/dist/cjs/wizard-pagination/index.js +0 -71
  299. package/dist/cjs/wizard-pagination/style.scss +0 -74
  300. package/dist/esm/wizard-pagination/index.js +0 -57
  301. package/dist/esm/wizard-pagination/style.scss +0 -74
  302. package/src/button-group/index.js +0 -35
  303. package/src/button-group/style.scss +0 -73
  304. package/src/checkbox-control/index.js +0 -38
  305. package/src/checkbox-control/style.scss +0 -78
  306. package/src/preview-box/index.js +0 -18
  307. package/src/preview-box/style.scss +0 -18
  308. package/src/textarea-control/index.js +0 -32
  309. package/src/textarea-control/style.scss +0 -76
  310. package/src/toggle-control/index.js +0 -38
  311. package/src/toggle-control/style.scss +0 -74
  312. package/src/toggle-group/index.js +0 -43
  313. package/src/toggle-group/style.scss +0 -28
  314. package/src/wizard-pagination/index.js +0 -59
  315. package/src/wizard-pagination/style.scss +0 -74
@@ -7,18 +7,17 @@ import { decodeEntities } from '@wordpress/html-entities';
7
7
  import { useEffect, useState } from '@wordpress/element';
8
8
  import { __ as alias__, _x as alias_x, sprintf } from '@wordpress/i18n';
9
9
  const __ = alias__,
10
- _x = alias_x;
10
+ _x = alias_x;
11
11
  import { addQueryArgs } from '@wordpress/url';
12
+
12
13
  /**
13
14
  * External dependencies.
14
15
  */
15
-
16
16
  import { AutocompleteTokenField } from '../';
17
17
  import './style.scss';
18
18
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
19
19
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
20
20
  import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
21
-
22
21
  const AutocompleteWithSuggestions = _ref => {
23
22
  let {
24
23
  fetchSavedPosts = false,
@@ -51,7 +50,6 @@ const AutocompleteWithSuggestions = _ref => {
51
50
  selectedPost = 0,
52
51
  // Legacy prop when single-select was the only option.
53
52
  suggestionsToFetch = 10 // Number of suggestions to fetch per query.
54
-
55
53
  } = _ref;
56
54
  const [isLoading, setIsLoading] = useState(true);
57
55
  const [isLoadingMore, setIsLoadingMore] = useState(false);
@@ -59,20 +57,17 @@ const AutocompleteWithSuggestions = _ref => {
59
57
  const [maxSuggestions, setMaxSuggestions] = useState(0);
60
58
  const [postTypeToSearch, setPostTypeToSearch] = useState(postTypes[0].slug);
61
59
  const classNames = ['newspack-autocomplete-with-suggestions'];
62
-
63
60
  if (hideHelp) {
64
61
  classNames.push('hide-help');
65
62
  }
63
+
66
64
  /**
67
65
  * Fetch recent posts to show as suggestions.
68
66
  */
69
-
70
-
71
67
  useEffect(() => {
72
68
  if (onPostTypeChange) {
73
69
  onPostTypeChange(postTypeToSearch);
74
70
  }
75
-
76
71
  setIsLoading(true);
77
72
  handleFetchSuggestions(null, 0, postTypeToSearch).then(_suggestions => {
78
73
  if (0 < _suggestions.length) {
@@ -80,10 +75,10 @@ const AutocompleteWithSuggestions = _ref => {
80
75
  }
81
76
  }).finally(() => setIsLoading(false));
82
77
  }, [postTypeToSearch]);
78
+
83
79
  /**
84
80
  * Fetch more suggestions.
85
81
  */
86
-
87
82
  useEffect(() => {
88
83
  if (isLoadingMore) {
89
84
  handleFetchSuggestions(null, suggestions.length, postTypeToSearch).then(_suggestions => {
@@ -93,17 +88,16 @@ const AutocompleteWithSuggestions = _ref => {
93
88
  }).finally(() => setIsLoadingMore(false));
94
89
  }
95
90
  }, [isLoadingMore]);
91
+
96
92
  /**
97
93
  * If passed a `fetchSavedPosts` prop, use that, otherwise, build it based on the selected post type.
98
94
  */
99
-
100
95
  const handleFetchSaved = fetchSavedPosts ? fetchSavedPosts : async function () {
101
96
  let postIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
102
97
  let searchSlug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
103
98
  const postTypeSlug = searchSlug || postTypeToSearch;
104
99
  const endpoint = 'post' === postTypeSlug || 'page' === postTypeSlug ? postTypeSlug + 's' // Default post type endpoints are plural.
105
100
  : postTypeSlug; // Custom post type endpoints are singular.
106
-
107
101
  const posts = await apiFetch({
108
102
  path: addQueryArgs('/wp/v2/' + endpoint, {
109
103
  per_page: 100,
@@ -116,10 +110,10 @@ const AutocompleteWithSuggestions = _ref => {
116
110
  label: decodeEntities(post.title) || __('(no title)', 'newspack')
117
111
  }));
118
112
  };
113
+
119
114
  /**
120
115
  * If passed a `fetchSuggestions` prop, use that, otherwise, build it based on the selected post type.
121
116
  */
122
-
123
117
  const handleFetchSuggestions = fetchSuggestions ? fetchSuggestions : async function () {
124
118
  let search = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
125
119
  let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -127,7 +121,6 @@ const AutocompleteWithSuggestions = _ref => {
127
121
  const postTypeSlug = searchSlug || postTypeToSearch;
128
122
  const endpoint = 'post' === postTypeSlug || 'page' === postTypeSlug ? postTypeSlug + 's' // Default post type endpoints are plural.
129
123
  : postTypeSlug; // Custom post type endpoints are singular.
130
-
131
124
  const response = await apiFetch({
132
125
  parse: false,
133
126
  path: addQueryArgs('/wp/v2/' + endpoint, {
@@ -139,32 +132,33 @@ const AutocompleteWithSuggestions = _ref => {
139
132
  });
140
133
  const total = parseInt(response.headers.get('x-wp-total') || 0);
141
134
  const posts = await response.json();
142
- setMaxSuggestions(total); // Format suggestions for FormTokenField display.
135
+ setMaxSuggestions(total);
143
136
 
137
+ // Format suggestions for FormTokenField display.
144
138
  return posts.reduce((acc, post) => {
145
139
  acc.push({
146
140
  value: parseInt(post.id),
147
- label: decodeEntities(post === null || post === void 0 ? void 0 : post.title.rendered) || __('(no title)', 'newspack')
141
+ label: decodeEntities(post?.title.rendered) || __('(no title)', 'newspack')
148
142
  });
149
143
  return acc;
150
144
  }, []);
151
145
  };
146
+
152
147
  /**
153
148
  * Intercept onChange callback so we can decide whether to allow multiple selections.
154
149
  */
155
-
156
150
  const handleOnChange = _selections => {
157
151
  // If only allowing one selection, just return the one selected item.
158
152
  if (!multiSelect) {
159
153
  return onChange(_selections);
160
- } // Handle legacy `selectedPost` prop.
161
-
154
+ }
162
155
 
163
- const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems]; // Loop through new selections to determine whether to add or remove them.
156
+ // Handle legacy `selectedPost` prop.
157
+ const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
164
158
 
159
+ // Loop through new selections to determine whether to add or remove them.
165
160
  _selections.forEach(_selection => {
166
161
  const existingSelection = selections.findIndex(selection => parseInt(selection.value) === parseInt(_selection.value));
167
-
168
162
  if (-1 < existingSelection) {
169
163
  // If the selection is already selected, remove it.
170
164
  selections.splice(existingSelection, 1);
@@ -172,23 +166,25 @@ const AutocompleteWithSuggestions = _ref => {
172
166
  // Otherwise, add it.
173
167
  selections.push(_selection);
174
168
  }
175
- }); // Include currently selected post type in selection results.
176
-
169
+ });
177
170
 
178
- onChange(selections.map(selection => ({ ...selection,
171
+ // Include currently selected post type in selection results.
172
+ onChange(selections.map(selection => ({
173
+ ...selection,
179
174
  postType: postTypeToSearch
180
175
  })));
181
176
  };
177
+
182
178
  /**
183
179
  * Render selected item(s) for this component. Clicking on a selection deselects it.
184
180
  */
185
-
186
-
187
181
  const renderSelections = () => {
188
182
  // Handle legacy `selectedPost` prop.
189
183
  const selections = selectedPost ? [...selectedItems, selectedPost] : selectedItems;
190
- const selectedMessage = multiSelect ? sprintf( // Translators: %1: the length of selections. %2: the selection leabel.
191
- __('%1$s %2$s selected', 'newspack'), selections.length, selections.length > 1 ? postTypeLabelPlural : postTypeLabel) : // Translators: %s: The label for the selection.
184
+ const selectedMessage = multiSelect ? sprintf(
185
+ // Translators: %1: the length of selections. %2: the selection leabel.
186
+ __('%1$s %2$s selected', 'newspack'), selections.length, selections.length > 1 ? postTypeLabelPlural : postTypeLabel) :
187
+ // Translators: %s: The label for the selection.
192
188
  sprintf(__('Selected %s', 'newspack'), postTypeLabel);
193
189
  return _jsxs("div", {
194
190
  className: "newspack-autocomplete-with-suggestions__selected-items",
@@ -197,6 +193,7 @@ const AutocompleteWithSuggestions = _ref => {
197
193
  children: [selectedMessage, 1 < selections.length && _x(' – ', 'separator character', 'newspack'), 1 < selections.length && _jsx(Button, {
198
194
  onClick: () => onChange([]),
199
195
  isLink: true,
196
+ isDestructive: true,
200
197
  children: __('Clear all', 'newspack')
201
198
  })]
202
199
  }), selections.map(selection => _jsx(Button, {
@@ -207,14 +204,14 @@ const AutocompleteWithSuggestions = _ref => {
207
204
  }, selection.value))]
208
205
  });
209
206
  };
207
+
210
208
  /**
211
209
  * Render post type select dropdown.
212
210
  */
213
-
214
-
215
211
  const renderPostTypeSelect = () => {
216
212
  return _jsx(SelectControl, {
217
- label: sprintf( // Translators: %s: The name of the type.
213
+ label: sprintf(
214
+ // Translators: %s: The name of the type.
218
215
  __('%s type', 'newspack'), postTypeLabel.charAt(0).toUpperCase() + postTypeLabel.slice(1)),
219
216
  value: postTypeToSearch,
220
217
  options: postTypes.map(postTypeOption => ({
@@ -224,35 +221,32 @@ const AutocompleteWithSuggestions = _ref => {
224
221
  onChange: _postType => setPostTypeToSearch(_postType)
225
222
  });
226
223
  };
224
+
227
225
  /**
228
226
  * Render a single suggestion object that can be clicked to select it immediately.
229
227
  *
230
228
  * @param {Object} suggestion Suggestion object with value and label keys.
231
229
  */
232
-
233
-
234
230
  const renderSuggestion = suggestion => {
235
231
  if (multiSelect) {
236
232
  const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
237
- const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value));
233
+ const isSelected = !!selections.find(_selection => parseInt(_selection.value) === parseInt(suggestion.value) && _selection.label === suggestion.label);
238
234
  return _jsx(CheckboxControl, {
239
235
  checked: isSelected,
240
236
  onChange: () => handleOnChange([suggestion]),
241
237
  label: suggestion.label
242
238
  }, suggestion.value);
243
239
  }
244
-
245
240
  return _jsx(Button, {
246
241
  isLink: true,
247
242
  onClick: () => handleOnChange([suggestion]),
248
243
  children: suggestion.label
249
244
  }, suggestion.value);
250
245
  };
246
+
251
247
  /**
252
248
  * Render a list of suggestions that can be clicked to select instead of searching by title.
253
249
  */
254
-
255
-
256
250
  const renderSuggestions = () => {
257
251
  if (isLoading) {
258
252
  return _jsx("div", {
@@ -260,18 +254,14 @@ const AutocompleteWithSuggestions = _ref => {
260
254
  children: _jsx(Spinner, {})
261
255
  });
262
256
  }
263
-
264
257
  if (0 === suggestions.length) {
265
258
  return null;
266
259
  }
267
-
268
260
  const className = multiSelect ? 'newspack-autocomplete-with-suggestions__search-suggestions-multiselect' : 'newspack-autocomplete-with-suggestions__search-suggestions';
269
261
  return _jsxs(_Fragment, {
270
262
  children: [!hideHelp && _jsx("p", {
271
263
  className: "newspack-autocomplete-with-suggestions__label",
272
- children:
273
- /* Translators: %s: the name of a post type. */
274
- sprintf(__('Or, select a recent %s:', 'newspack'), postTypeLabel)
264
+ children: /* Translators: %s: the name of a post type. */sprintf(__('Or, select a recent %s:', 'newspack'), postTypeLabel)
275
265
  }), _jsxs("div", {
276
266
  className: className,
277
267
  children: [suggestions.map(renderSuggestion), suggestions.length < (maxItemsToSuggest || maxSuggestions) && _jsx(Button, {
@@ -283,7 +273,6 @@ const AutocompleteWithSuggestions = _ref => {
283
273
  })]
284
274
  });
285
275
  };
286
-
287
276
  return _jsxs("div", {
288
277
  className: classNames.join(' '),
289
278
  children: [0 < selectedItems.length && renderSelections(), 1 < postTypes.length && renderPostTypeSelect(), _jsx(AutocompleteTokenField, {
@@ -297,5 +286,4 @@ const AutocompleteWithSuggestions = _ref => {
297
286
  }), renderSuggestions()]
298
287
  });
299
288
  };
300
-
301
289
  export default AutocompleteWithSuggestions;
@@ -2,8 +2,7 @@
2
2
  * Styles for AutocompleteWithSuggestions component.
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
6
 
8
7
  .newspack-autocomplete-with-suggestions {
9
8
  width: 100%;
@@ -18,8 +17,9 @@
18
17
  }
19
18
 
20
19
  .components-spinner {
20
+ margin: 8px;
21
21
  right: 0;
22
- top: 2em;
22
+ top: calc( 1.4em + 8px );
23
23
  }
24
24
 
25
25
  .components-select-control__input {
@@ -27,19 +27,19 @@
27
27
  }
28
28
 
29
29
  .components-input-control__backdrop {
30
- border-color: $gray-900 !important;
30
+ border-color: wp-colors.$gray-700 !important;
31
31
  }
32
32
 
33
33
  .newspack-autocomplete-with-suggestions__label,
34
34
  .components-form-token-field__label,
35
35
  .components-input-control__label,
36
36
  .components-checkbox-control__label {
37
- color: $gray-900 !important;
37
+ color: wp-colors.$gray-900 !important;
38
38
  }
39
39
 
40
40
  &__suggestions-spinner {
41
- background: $gray-100;
42
- border: 1px solid $gray-900;
41
+ background: wp-colors.$gray-100;
42
+ border: 1px solid wp-colors.$gray-700;
43
43
  border-radius: 2px;
44
44
  cursor: progress;
45
45
  margin: 16px 0;
@@ -49,21 +49,23 @@
49
49
  display: block;
50
50
  margin: 0 auto;
51
51
  position: relative;
52
+ right: auto;
52
53
  top: 0;
53
54
  }
54
55
  }
55
56
 
56
57
  .newspack-autocomplete-tokenfield__help {
57
58
  font-size: inherit;
59
+ margin-bottom: 8px !important;
58
60
  }
59
61
 
60
62
  .components-form-token-field {
61
63
  &__input-container {
62
- border-color: $gray-900;
64
+ border-color: wp-colors.$gray-700;
63
65
  }
64
66
 
65
67
  &__suggestions-list {
66
- border-top-color: $gray-900;
68
+ border-top-color: wp-colors.$gray-700;
67
69
  margin: 4px -4px -2px;
68
70
  }
69
71
 
@@ -74,32 +76,30 @@
74
76
 
75
77
  p.newspack-autocomplete-with-suggestions__label {
76
78
  font-size: inherit;
77
- margin-bottom: 4px;
79
+ margin: 0 0 8px;
78
80
  }
79
81
 
80
82
  &__selected-items {
81
- border-bottom: 1px solid $gray-300;
83
+ border-bottom: 1px solid wp-colors.$gray-700;
84
+ display: flex;
85
+ flex-wrap: wrap;
86
+ gap: 8px;
82
87
  margin-bottom: 16px;
83
88
  padding-bottom: 12px;
84
89
 
85
- .newspack-autocomplete-with-suggestions__label {
86
- font-weight: bold;
87
-
88
- .components-button.is-link {
89
- color: $alert-red;
90
- font-weight: normal;
91
- }
90
+ p.newspack-autocomplete-with-suggestions__label {
91
+ flex: 0 0 100%;
92
+ margin: 0;
92
93
  }
93
94
  }
94
95
 
95
96
  &__selected-item-button.components-button.is-tertiary {
96
- background-color: $gray-300;
97
+ background-color: wp-colors.$gray-300;
97
98
  border-radius: 2px;
98
- color: #1e1e1e;
99
+ color: wp-colors.$gray-900;
99
100
  font-size: 13px;
100
101
  height: auto;
101
- margin-bottom: 4px;
102
- margin-right: 4px;
102
+ margin: 0;
103
103
  padding-left: 8px;
104
104
  padding-right: 8px;
105
105
 
@@ -117,7 +117,7 @@
117
117
  &__search-suggestions,
118
118
  &__search-suggestions-multiselect {
119
119
  border-radius: 2px;
120
- border: 1px solid $gray-900;
120
+ border: 1px solid wp-colors.$gray-700;
121
121
  max-height: 178px;
122
122
  overflow-x: visible;
123
123
  overflow-y: auto;
@@ -129,14 +129,14 @@
129
129
  margin: auto;
130
130
 
131
131
  &.is-link {
132
- color: $gray-900;
132
+ color: wp-colors.$gray-900;
133
133
  padding: 8px;
134
134
  text-decoration: none;
135
135
  width: 100%;
136
136
 
137
137
  &:active:not( :disabled ),
138
138
  &:hover:not( :disabled ) {
139
- background: $gray-900;
139
+ background: wp-colors.$gray-900;
140
140
  background: var( --wp-admin-theme-color );
141
141
  color: white;
142
142
  }
@@ -151,7 +151,7 @@
151
151
 
152
152
  &__search-suggestions {
153
153
  border-radius: 2px;
154
- border: 1px solid $gray-900;
154
+ border: 1px solid wp-colors.$gray-700;
155
155
  padding: 0;
156
156
 
157
157
  .components-button {
@@ -159,7 +159,7 @@
159
159
 
160
160
  &:focus:not( :disabled ) {
161
161
  border-radius: 0;
162
- box-shadow: inset 0 0 0 1.5px $gray-900;
162
+ box-shadow: inset 0 0 0 1.5px wp-colors.$gray-900;
163
163
  box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) var( --wp-admin-theme-color );
164
164
  }
165
165
 
@@ -7,34 +7,26 @@
7
7
  */
8
8
  import { Button as BaseComponent } from '@wordpress/components';
9
9
  import { useState } from '@wordpress/element';
10
+
10
11
  /**
11
12
  * Internal dependencies
12
13
  */
13
-
14
14
  import Router from '../proxied-imports/router';
15
15
  import './style.scss';
16
- /**
17
- * External dependencies
18
- */
19
-
20
- import classnames from 'classnames';
21
16
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
22
17
  const {
23
18
  useHistory
24
19
  } = Router;
25
-
26
20
  const Button = _ref => {
27
21
  let {
28
- className,
29
- isQuaternary,
30
22
  href,
31
23
  onClick,
32
24
  ...otherProps
33
25
  } = _ref;
34
26
  const history = useHistory();
35
27
  const [isAwaitingOnClick, setIsAwaitingOnClick] = useState(false);
36
- const classes = classnames('newspack-button', isQuaternary && 'is-quaternary', className); // If both onClick and href are present, await the onClick action an then redirect.
37
28
 
29
+ // If both onClick and href are present, await the onClick action an then redirect.
38
30
  if (href && onClick) {
39
31
  otherProps.onClick = async () => {
40
32
  setIsAwaitingOnClick(true);
@@ -46,15 +38,11 @@ const Button = _ref => {
46
38
  otherProps.href = href;
47
39
  otherProps.onClick = onClick;
48
40
  }
49
-
50
41
  if (isAwaitingOnClick) {
51
42
  otherProps.disabled = true;
52
43
  }
53
-
54
44
  return _jsx(BaseComponent, {
55
- className: classes,
56
45
  ...otherProps
57
46
  });
58
47
  };
59
-
60
48
  export default Button;