newspack-components 2.1.0 → 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 (293) hide show
  1. package/dist/cjs/accordion/index.js +46 -0
  2. package/dist/cjs/accordion/style.scss +27 -0
  3. package/dist/cjs/action-card/index.js +48 -25
  4. package/dist/cjs/action-card/style.scss +100 -23
  5. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  6. package/dist/cjs/autocomplete-tokenfield/style.scss +2 -2
  7. package/dist/cjs/autocomplete-with-suggestions/index.js +30 -51
  8. package/dist/cjs/autocomplete-with-suggestions/style.scss +16 -15
  9. package/dist/cjs/button/index.js +5 -13
  10. package/dist/cjs/button-card/index.js +1 -10
  11. package/dist/cjs/button-card/style.scss +13 -13
  12. package/dist/cjs/button-group/index.js +57 -0
  13. package/dist/cjs/button-group/style.scss +73 -0
  14. package/dist/cjs/card/index.js +1 -8
  15. package/dist/cjs/card/style.scss +25 -8
  16. package/dist/cjs/category-autocomplete/index.js +18 -38
  17. package/dist/cjs/category-autocomplete/style.scss +0 -2
  18. package/dist/cjs/checkbox-control/index.js +63 -0
  19. package/dist/cjs/checkbox-control/style.scss +78 -0
  20. package/dist/cjs/color-picker/index.js +1 -15
  21. package/dist/cjs/color-picker/style.scss +0 -3
  22. package/dist/cjs/consts.js +5 -3
  23. package/dist/cjs/custom-select-control/index.js +1 -9
  24. package/dist/cjs/custom-select-control/style.scss +6 -7
  25. package/dist/cjs/date-range-picker/index.js +1 -10
  26. package/dist/cjs/date-range-picker/style.scss +12 -12
  27. package/dist/cjs/footer/index.js +5 -17
  28. package/dist/cjs/footer/style.scss +5 -5
  29. package/dist/cjs/form-token-field/index.js +1 -9
  30. package/dist/cjs/form-token-field/style.scss +2 -3
  31. package/dist/cjs/global-notices/index.js +1 -8
  32. package/dist/cjs/grid/index.js +1 -8
  33. package/dist/cjs/grid/style.scss +5 -5
  34. package/dist/cjs/handoff/index.js +8 -17
  35. package/dist/cjs/handoff-message/index.js +50 -0
  36. package/dist/cjs/hooks/index.js +1 -7
  37. package/dist/cjs/hooks/useObjectState.js +7 -13
  38. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  39. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  40. package/dist/cjs/hooks/usePrompt.js +1 -13
  41. package/dist/cjs/image-upload/index.js +21 -19
  42. package/dist/cjs/image-upload/index.test.js +0 -5
  43. package/dist/cjs/image-upload/style.scss +5 -9
  44. package/dist/cjs/index.js +28 -44
  45. package/dist/cjs/info-button/index.js +3 -11
  46. package/dist/cjs/info-button/style.scss +1 -3
  47. package/dist/cjs/modal/index.js +1 -9
  48. package/dist/cjs/modal/style.scss +8 -8
  49. package/dist/cjs/newspack-icon/index.js +1 -9
  50. package/dist/cjs/newspack-icon/style.scss +4 -4
  51. package/dist/cjs/newspack-logo/index.js +1 -9
  52. package/dist/cjs/newspack-logo/style.scss +3 -3
  53. package/dist/cjs/notice/index.js +8 -15
  54. package/dist/cjs/notice/style.scss +28 -15
  55. package/dist/cjs/patrons-logo/index.js +3 -11
  56. package/dist/cjs/plugin-installer/index.js +36 -36
  57. package/dist/cjs/plugin-installer/style.scss +5 -5
  58. package/dist/cjs/plugin-settings/SettingsSection.js +9 -28
  59. package/dist/cjs/plugin-settings/index.js +39 -22
  60. package/dist/cjs/plugin-toggle/index.js +40 -33
  61. package/dist/cjs/plugin-toggle/style.scss +2 -2
  62. package/dist/cjs/popover/index.js +1 -11
  63. package/dist/cjs/popover/style.scss +19 -16
  64. package/dist/cjs/position-control/index.js +113 -0
  65. package/dist/cjs/position-control/style.scss +66 -0
  66. package/dist/cjs/preview-box/index.js +36 -0
  67. package/dist/cjs/preview-box/style.scss +18 -0
  68. package/dist/cjs/progress-bar/index.js +2 -9
  69. package/dist/cjs/progress-bar/index.test.js +2 -7
  70. package/dist/cjs/progress-bar/style.scss +4 -4
  71. package/dist/cjs/proxied-imports/router.js +0 -3
  72. package/dist/cjs/radio-control/index.js +1 -11
  73. package/dist/cjs/radio-control/style.scss +9 -9
  74. package/dist/cjs/section-header/index.js +44 -29
  75. package/dist/cjs/section-header/style.scss +2 -2
  76. package/dist/cjs/select-control/ButtonGroupControl.js +4 -13
  77. package/dist/cjs/select-control/GroupedSelectControl.js +9 -15
  78. package/dist/cjs/select-control/index.js +5 -12
  79. package/dist/cjs/select-control/style.scss +2 -2
  80. package/dist/cjs/settings/MinMaxSetting.js +3 -7
  81. package/dist/cjs/settings/SettingsCard.js +3 -7
  82. package/dist/cjs/settings/SettingsSection.js +1 -4
  83. package/dist/cjs/settings/index.js +0 -6
  84. package/dist/cjs/settings/style.scss +1 -1
  85. package/dist/cjs/steps-list/index.js +52 -0
  86. package/dist/cjs/steps-list/style.scss +11 -0
  87. package/dist/cjs/steps-list-item/index.js +56 -0
  88. package/dist/cjs/steps-list-item/style.scss +47 -0
  89. package/dist/cjs/style-card/index.js +6 -13
  90. package/dist/cjs/style-card/style.scss +9 -12
  91. package/dist/cjs/style.scss +5 -6
  92. package/dist/cjs/tabbed-navigation/index.js +19 -16
  93. package/dist/cjs/tabbed-navigation/style.scss +3 -4
  94. package/dist/cjs/text-control/index.js +6 -16
  95. package/dist/cjs/textarea-control/index.js +54 -0
  96. package/dist/cjs/textarea-control/style.scss +76 -0
  97. package/dist/cjs/toggle-control/index.js +58 -0
  98. package/dist/cjs/toggle-control/style.scss +74 -0
  99. package/dist/cjs/toggle-group/index.js +71 -0
  100. package/dist/cjs/toggle-group/style.scss +28 -0
  101. package/dist/cjs/utils/index.js +10 -5
  102. package/dist/cjs/waiting/index.js +1 -9
  103. package/dist/cjs/web-preview/index.js +13 -28
  104. package/dist/cjs/web-preview/style.scss +14 -14
  105. package/dist/cjs/with-wizard/index.js +51 -31
  106. package/dist/cjs/with-wizard/style.scss +35 -37
  107. package/dist/cjs/with-wizard-screen/index.js +11 -17
  108. package/dist/cjs/with-wizard-screen/style.scss +14 -17
  109. package/dist/cjs/wizard/components/WizardError.js +3 -15
  110. package/dist/cjs/wizard/index.js +10 -24
  111. package/dist/cjs/wizard/store/index.js +42 -55
  112. package/dist/cjs/wizard/store/utils.js +1 -6
  113. package/dist/cjs/wizard/style.scss +148 -0
  114. package/dist/esm/accordion/index.js +38 -0
  115. package/dist/esm/accordion/style.scss +27 -0
  116. package/dist/esm/action-card/index.js +50 -21
  117. package/dist/esm/action-card/style.scss +100 -23
  118. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  119. package/dist/esm/autocomplete-tokenfield/style.scss +2 -2
  120. package/dist/esm/autocomplete-with-suggestions/index.js +28 -41
  121. package/dist/esm/autocomplete-with-suggestions/style.scss +16 -15
  122. package/dist/esm/button/index.js +5 -7
  123. package/dist/esm/button-card/index.js +2 -5
  124. package/dist/esm/button-card/style.scss +13 -13
  125. package/dist/esm/button-group/index.js +43 -0
  126. package/dist/esm/button-group/style.scss +73 -0
  127. package/dist/esm/card/index.js +2 -5
  128. package/dist/esm/card/style.scss +25 -8
  129. package/dist/esm/category-autocomplete/index.js +17 -30
  130. package/dist/esm/category-autocomplete/style.scss +0 -2
  131. package/dist/esm/checkbox-control/index.js +49 -0
  132. package/dist/esm/checkbox-control/style.scss +78 -0
  133. package/dist/esm/color-picker/index.js +2 -4
  134. package/dist/esm/color-picker/style.scss +0 -3
  135. package/dist/esm/consts.js +3 -2
  136. package/dist/esm/custom-select-control/index.js +2 -5
  137. package/dist/esm/custom-select-control/style.scss +6 -7
  138. package/dist/esm/date-range-picker/index.js +1 -3
  139. package/dist/esm/date-range-picker/style.scss +12 -12
  140. package/dist/esm/footer/index.js +3 -11
  141. package/dist/esm/footer/style.scss +5 -5
  142. package/dist/esm/form-token-field/index.js +2 -5
  143. package/dist/esm/form-token-field/style.scss +2 -3
  144. package/dist/esm/global-notices/index.js +1 -6
  145. package/dist/esm/grid/index.js +2 -5
  146. package/dist/esm/grid/style.scss +5 -5
  147. package/dist/esm/handoff/index.js +3 -14
  148. package/dist/esm/handoff-message/index.js +45 -0
  149. package/dist/esm/hooks/index.js +0 -2
  150. package/dist/esm/hooks/useObjectState.js +3 -8
  151. package/dist/esm/hooks/useObjectState.test.js +0 -3
  152. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  153. package/dist/esm/hooks/usePrompt.js +1 -8
  154. package/dist/esm/image-upload/index.js +17 -16
  155. package/dist/esm/image-upload/style.scss +5 -9
  156. package/dist/esm/index.js +4 -0
  157. package/dist/esm/info-button/index.js +4 -6
  158. package/dist/esm/info-button/style.scss +1 -3
  159. package/dist/esm/modal/index.js +2 -5
  160. package/dist/esm/modal/style.scss +8 -8
  161. package/dist/esm/newspack-icon/index.js +2 -5
  162. package/dist/esm/newspack-icon/style.scss +4 -4
  163. package/dist/esm/newspack-logo/index.js +2 -5
  164. package/dist/esm/newspack-logo/style.scss +3 -3
  165. package/dist/esm/notice/index.js +4 -8
  166. package/dist/esm/notice/style.scss +28 -15
  167. package/dist/esm/patrons-logo/index.js +3 -5
  168. package/dist/esm/plugin-installer/index.js +35 -39
  169. package/dist/esm/plugin-installer/style.scss +5 -5
  170. package/dist/esm/plugin-settings/SettingsSection.js +8 -21
  171. package/dist/esm/plugin-settings/index.js +38 -24
  172. package/dist/esm/plugin-toggle/index.js +39 -36
  173. package/dist/esm/plugin-toggle/style.scss +2 -2
  174. package/dist/esm/popover/index.js +3 -6
  175. package/dist/esm/popover/style.scss +19 -16
  176. package/dist/esm/position-control/index.js +109 -0
  177. package/dist/esm/position-control/style.scss +66 -0
  178. package/dist/esm/preview-box/index.js +30 -0
  179. package/dist/esm/preview-box/style.scss +18 -0
  180. package/dist/esm/progress-bar/index.js +2 -7
  181. package/dist/esm/progress-bar/index.test.js +2 -1
  182. package/dist/esm/progress-bar/style.scss +4 -4
  183. package/dist/esm/proxied-imports/router.js +1 -0
  184. package/dist/esm/radio-control/index.js +3 -6
  185. package/dist/esm/radio-control/style.scss +9 -9
  186. package/dist/esm/section-header/index.js +44 -25
  187. package/dist/esm/section-header/style.scss +2 -2
  188. package/dist/esm/select-control/ButtonGroupControl.js +5 -7
  189. package/dist/esm/select-control/GroupedSelectControl.js +5 -6
  190. package/dist/esm/select-control/index.js +6 -6
  191. package/dist/esm/select-control/style.scss +2 -2
  192. package/dist/esm/settings/MinMaxSetting.js +1 -3
  193. package/dist/esm/settings/SettingsCard.js +3 -4
  194. package/dist/esm/settings/SettingsSection.js +0 -2
  195. package/dist/esm/settings/style.scss +1 -1
  196. package/dist/esm/steps-list/index.js +43 -0
  197. package/dist/esm/steps-list/style.scss +11 -0
  198. package/dist/esm/steps-list-item/index.js +48 -0
  199. package/dist/esm/steps-list-item/style.scss +47 -0
  200. package/dist/esm/style-card/index.js +2 -5
  201. package/dist/esm/style-card/style.scss +9 -12
  202. package/dist/esm/style.scss +5 -6
  203. package/dist/esm/tabbed-navigation/index.js +20 -10
  204. package/dist/esm/tabbed-navigation/style.scss +3 -4
  205. package/dist/esm/text-control/index.js +2 -9
  206. package/dist/esm/textarea-control/index.js +40 -0
  207. package/dist/esm/textarea-control/style.scss +76 -0
  208. package/dist/esm/toggle-control/index.js +44 -0
  209. package/dist/esm/toggle-control/style.scss +74 -0
  210. package/dist/esm/toggle-group/index.js +58 -0
  211. package/dist/esm/toggle-group/style.scss +28 -0
  212. package/dist/esm/utils/index.js +9 -3
  213. package/dist/esm/waiting/index.js +2 -5
  214. package/dist/esm/web-preview/index.js +9 -24
  215. package/dist/esm/web-preview/style.scss +14 -14
  216. package/dist/esm/with-wizard/index.js +49 -34
  217. package/dist/esm/with-wizard/style.scss +35 -37
  218. package/dist/esm/with-wizard-screen/index.js +9 -11
  219. package/dist/esm/with-wizard-screen/style.scss +14 -17
  220. package/dist/esm/wizard/components/WizardError.js +1 -10
  221. package/dist/esm/wizard/index.js +10 -12
  222. package/dist/esm/wizard/store/index.js +40 -46
  223. package/dist/esm/wizard/store/utils.js +1 -1
  224. package/dist/esm/wizard/style.scss +148 -0
  225. package/package.json +4 -4
  226. package/shared/scss/_colors.scss +0 -15
  227. package/src/accordion/index.js +32 -0
  228. package/src/accordion/style.scss +27 -0
  229. package/src/action-card/index.js +43 -8
  230. package/src/action-card/style.scss +100 -23
  231. package/src/autocomplete-tokenfield/index.js +1 -1
  232. package/src/autocomplete-tokenfield/style.scss +2 -2
  233. package/src/autocomplete-with-suggestions/style.scss +16 -15
  234. package/src/button-card/style.scss +13 -13
  235. package/src/card/style.scss +25 -8
  236. package/src/category-autocomplete/index.js +3 -1
  237. package/src/category-autocomplete/style.scss +0 -2
  238. package/src/color-picker/style.scss +0 -3
  239. package/src/consts.js +2 -1
  240. package/src/custom-select-control/style.scss +6 -7
  241. package/src/date-range-picker/style.scss +12 -12
  242. package/src/footer/index.js +2 -2
  243. package/src/footer/style.scss +5 -5
  244. package/src/form-token-field/index.js +2 -7
  245. package/src/form-token-field/style.scss +2 -3
  246. package/src/grid/style.scss +5 -5
  247. package/src/handoff/index.js +3 -8
  248. package/src/handoff-message/index.js +39 -0
  249. package/src/hooks/useObjectState.js +2 -1
  250. package/src/image-upload/index.js +9 -3
  251. package/src/image-upload/style.scss +5 -9
  252. package/src/index.js +4 -0
  253. package/src/info-button/style.scss +1 -3
  254. package/src/modal/style.scss +8 -8
  255. package/src/newspack-icon/style.scss +4 -4
  256. package/src/newspack-logo/style.scss +3 -3
  257. package/src/notice/index.js +2 -0
  258. package/src/notice/style.scss +28 -15
  259. package/src/plugin-installer/index.js +15 -2
  260. package/src/plugin-installer/style.scss +5 -5
  261. package/src/plugin-settings/SettingsSection.js +7 -13
  262. package/src/plugin-settings/index.js +7 -2
  263. package/src/plugin-toggle/index.js +2 -3
  264. package/src/plugin-toggle/style.scss +2 -2
  265. package/src/popover/style.scss +19 -16
  266. package/src/position-control/index.js +122 -0
  267. package/src/position-control/style.scss +66 -0
  268. package/src/progress-bar/style.scss +4 -4
  269. package/src/radio-control/style.scss +9 -9
  270. package/src/section-header/index.js +32 -15
  271. package/src/section-header/style.scss +2 -2
  272. package/src/select-control/ButtonGroupControl.js +3 -0
  273. package/src/select-control/GroupedSelectControl.js +2 -1
  274. package/src/select-control/index.js +6 -2
  275. package/src/select-control/style.scss +2 -2
  276. package/src/settings/style.scss +1 -1
  277. package/src/steps-list/index.js +39 -0
  278. package/src/steps-list/style.scss +11 -0
  279. package/src/steps-list-item/index.js +40 -0
  280. package/src/steps-list-item/style.scss +47 -0
  281. package/src/style-card/index.js +2 -11
  282. package/src/style-card/style.scss +9 -12
  283. package/src/style.scss +5 -6
  284. package/src/tabbed-navigation/index.js +12 -4
  285. package/src/tabbed-navigation/style.scss +3 -4
  286. package/src/utils/index.js +9 -0
  287. package/src/web-preview/index.js +1 -1
  288. package/src/web-preview/style.scss +14 -14
  289. package/src/with-wizard/style.scss +35 -37
  290. package/src/with-wizard-screen/index.js +4 -1
  291. package/src/with-wizard-screen/style.scss +14 -17
  292. package/src/wizard/index.js +15 -3
  293. package/src/wizard/store/index.js +8 -2
@@ -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,8 +132,9 @@ 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),
@@ -149,22 +143,22 @@ const AutocompleteWithSuggestions = _ref => {
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",
@@ -208,14 +204,14 @@ const AutocompleteWithSuggestions = _ref => {
208
204
  }, selection.value))]
209
205
  });
210
206
  };
207
+
211
208
  /**
212
209
  * Render post type select dropdown.
213
210
  */
214
-
215
-
216
211
  const renderPostTypeSelect = () => {
217
212
  return _jsx(SelectControl, {
218
- label: sprintf( // Translators: %s: The name of the type.
213
+ label: sprintf(
214
+ // Translators: %s: The name of the type.
219
215
  __('%s type', 'newspack'), postTypeLabel.charAt(0).toUpperCase() + postTypeLabel.slice(1)),
220
216
  value: postTypeToSearch,
221
217
  options: postTypes.map(postTypeOption => ({
@@ -225,13 +221,12 @@ const AutocompleteWithSuggestions = _ref => {
225
221
  onChange: _postType => setPostTypeToSearch(_postType)
226
222
  });
227
223
  };
224
+
228
225
  /**
229
226
  * Render a single suggestion object that can be clicked to select it immediately.
230
227
  *
231
228
  * @param {Object} suggestion Suggestion object with value and label keys.
232
229
  */
233
-
234
-
235
230
  const renderSuggestion = suggestion => {
236
231
  if (multiSelect) {
237
232
  const selections = selectedPost ? [...selectedItems, selectedPost] : [...selectedItems];
@@ -242,18 +237,16 @@ const AutocompleteWithSuggestions = _ref => {
242
237
  label: suggestion.label
243
238
  }, suggestion.value);
244
239
  }
245
-
246
240
  return _jsx(Button, {
247
241
  isLink: true,
248
242
  onClick: () => handleOnChange([suggestion]),
249
243
  children: suggestion.label
250
244
  }, suggestion.value);
251
245
  };
246
+
252
247
  /**
253
248
  * Render a list of suggestions that can be clicked to select instead of searching by title.
254
249
  */
255
-
256
-
257
250
  const renderSuggestions = () => {
258
251
  if (isLoading) {
259
252
  return _jsx("div", {
@@ -261,18 +254,14 @@ const AutocompleteWithSuggestions = _ref => {
261
254
  children: _jsx(Spinner, {})
262
255
  });
263
256
  }
264
-
265
257
  if (0 === suggestions.length) {
266
258
  return null;
267
259
  }
268
-
269
260
  const className = multiSelect ? 'newspack-autocomplete-with-suggestions__search-suggestions-multiselect' : 'newspack-autocomplete-with-suggestions__search-suggestions';
270
261
  return _jsxs(_Fragment, {
271
262
  children: [!hideHelp && _jsx("p", {
272
263
  className: "newspack-autocomplete-with-suggestions__label",
273
- children:
274
- /* Translators: %s: the name of a post type. */
275
- 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)
276
265
  }), _jsxs("div", {
277
266
  className: className,
278
267
  children: [suggestions.map(renderSuggestion), suggestions.length < (maxItemsToSuggest || maxSuggestions) && _jsx(Button, {
@@ -284,7 +273,6 @@ const AutocompleteWithSuggestions = _ref => {
284
273
  })]
285
274
  });
286
275
  };
287
-
288
276
  return _jsxs("div", {
289
277
  className: classNames.join(' '),
290
278
  children: [0 < selectedItems.length && renderSelections(), 1 < postTypes.length && renderPostTypeSelect(), _jsx(AutocompleteTokenField, {
@@ -298,5 +286,4 @@ const AutocompleteWithSuggestions = _ref => {
298
286
  }), renderSuggestions()]
299
287
  });
300
288
  };
301
-
302
289
  export default AutocompleteWithSuggestions;
@@ -2,7 +2,7 @@
2
2
  * Styles for AutocompleteWithSuggestions component.
3
3
  */
4
4
 
5
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-autocomplete-with-suggestions {
8
8
  width: 100%;
@@ -27,19 +27,19 @@
27
27
  }
28
28
 
29
29
  .components-input-control__backdrop {
30
- border-color: $gray-700 !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-700;
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;
@@ -56,15 +56,16 @@
56
56
 
57
57
  .newspack-autocomplete-tokenfield__help {
58
58
  font-size: inherit;
59
+ margin-bottom: 8px !important;
59
60
  }
60
61
 
61
62
  .components-form-token-field {
62
63
  &__input-container {
63
- border-color: $gray-700;
64
+ border-color: wp-colors.$gray-700;
64
65
  }
65
66
 
66
67
  &__suggestions-list {
67
- border-top-color: $gray-700;
68
+ border-top-color: wp-colors.$gray-700;
68
69
  margin: 4px -4px -2px;
69
70
  }
70
71
 
@@ -79,7 +80,7 @@
79
80
  }
80
81
 
81
82
  &__selected-items {
82
- border-bottom: 1px solid $gray-700;
83
+ border-bottom: 1px solid wp-colors.$gray-700;
83
84
  display: flex;
84
85
  flex-wrap: wrap;
85
86
  gap: 8px;
@@ -93,9 +94,9 @@
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: $gray-900;
99
+ color: wp-colors.$gray-900;
99
100
  font-size: 13px;
100
101
  height: auto;
101
102
  margin: 0;
@@ -116,7 +117,7 @@
116
117
  &__search-suggestions,
117
118
  &__search-suggestions-multiselect {
118
119
  border-radius: 2px;
119
- border: 1px solid $gray-700;
120
+ border: 1px solid wp-colors.$gray-700;
120
121
  max-height: 178px;
121
122
  overflow-x: visible;
122
123
  overflow-y: auto;
@@ -128,14 +129,14 @@
128
129
  margin: auto;
129
130
 
130
131
  &.is-link {
131
- color: $gray-900;
132
+ color: wp-colors.$gray-900;
132
133
  padding: 8px;
133
134
  text-decoration: none;
134
135
  width: 100%;
135
136
 
136
137
  &:active:not( :disabled ),
137
138
  &:hover:not( :disabled ) {
138
- background: $gray-900;
139
+ background: wp-colors.$gray-900;
139
140
  background: var( --wp-admin-theme-color );
140
141
  color: white;
141
142
  }
@@ -150,7 +151,7 @@
150
151
 
151
152
  &__search-suggestions {
152
153
  border-radius: 2px;
153
- border: 1px solid $gray-700;
154
+ border: 1px solid wp-colors.$gray-700;
154
155
  padding: 0;
155
156
 
156
157
  .components-button {
@@ -158,7 +159,7 @@
158
159
 
159
160
  &:focus:not( :disabled ) {
160
161
  border-radius: 0;
161
- box-shadow: inset 0 0 0 1.5px $gray-900;
162
+ box-shadow: inset 0 0 0 1.5px wp-colors.$gray-900;
162
163
  box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) var( --wp-admin-theme-color );
163
164
  }
164
165
 
@@ -7,17 +7,16 @@
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
16
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
17
17
  const {
18
18
  useHistory
19
19
  } = Router;
20
-
21
20
  const Button = _ref => {
22
21
  let {
23
22
  href,
@@ -25,8 +24,9 @@ const Button = _ref => {
25
24
  ...otherProps
26
25
  } = _ref;
27
26
  const history = useHistory();
28
- const [isAwaitingOnClick, setIsAwaitingOnClick] = useState(false); // If both onClick and href are present, await the onClick action an then redirect.
27
+ const [isAwaitingOnClick, setIsAwaitingOnClick] = useState(false);
29
28
 
29
+ // If both onClick and href are present, await the onClick action an then redirect.
30
30
  if (href && onClick) {
31
31
  otherProps.onClick = async () => {
32
32
  setIsAwaitingOnClick(true);
@@ -38,13 +38,11 @@ const Button = _ref => {
38
38
  otherProps.href = href;
39
39
  otherProps.onClick = onClick;
40
40
  }
41
-
42
41
  if (isAwaitingOnClick) {
43
42
  otherProps.disabled = true;
44
43
  }
45
-
46
- return _jsx(BaseComponent, { ...otherProps
44
+ return _jsx(BaseComponent, {
45
+ ...otherProps
47
46
  });
48
47
  };
49
-
50
48
  export default Button;
@@ -7,20 +7,19 @@
7
7
  */
8
8
  import { Component } from '@wordpress/element';
9
9
  import { Icon, chevronRight } from '@wordpress/icons';
10
+
10
11
  /**
11
12
  * Internal dependencies
12
13
  */
13
-
14
14
  import { Grid } from '../';
15
15
  import './style.scss';
16
+
16
17
  /**
17
18
  * External dependencies
18
19
  */
19
-
20
20
  import classnames from 'classnames';
21
21
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
22
22
  import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
23
-
24
23
  class ButtonCard extends Component {
25
24
  /**
26
25
  * Render
@@ -62,7 +61,5 @@ class ButtonCard extends Component {
62
61
  })]
63
62
  });
64
63
  }
65
-
66
64
  }
67
-
68
65
  export default ButtonCard;
@@ -2,12 +2,12 @@
2
2
  * Button Card
3
3
  */
4
4
 
5
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-button-card {
8
8
  background: white;
9
9
  border-radius: 2px;
10
- border: 1px solid $gray-300;
10
+ border: 1px solid wp-colors.$gray-300;
11
11
  box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) transparent;
12
12
  cursor: pointer;
13
13
  display: block;
@@ -51,11 +51,11 @@
51
51
  }
52
52
 
53
53
  .newspack-grid h3 {
54
- color: $gray-900;
54
+ color: wp-colors.$gray-900;
55
55
  }
56
56
 
57
57
  p {
58
- color: $gray-700;
58
+ color: wp-colors.$gray-700;
59
59
  }
60
60
 
61
61
  // Grouped
@@ -90,7 +90,7 @@
90
90
  &:active,
91
91
  &:hover {
92
92
  svg {
93
- fill: currentColor;
93
+ fill: currentcolor;
94
94
  }
95
95
  }
96
96
 
@@ -144,31 +144,31 @@
144
144
 
145
145
  &.is-destructive {
146
146
  .title {
147
- color: $alert-red;
147
+ color: wp-colors.$alert-red;
148
148
  }
149
149
 
150
150
  &.has-chevron,
151
151
  &.has-icon {
152
152
  svg {
153
- fill: $alert-red;
153
+ fill: wp-colors.$alert-red;
154
154
  }
155
155
  }
156
156
 
157
157
  &:focus,
158
158
  &.is-pressed {
159
- border-color: $alert-red;
160
- box-shadow: inset 0 0 0 1px $alert-red !important;
159
+ border-color: wp-colors.$alert-red;
160
+ box-shadow: inset 0 0 0 1px wp-colors.$alert-red !important;
161
161
  }
162
162
 
163
163
  &.is-pressed:focus-visible {
164
- box-shadow: inset 0 0 0 1px $alert-red, 0 0 0 1px white,
165
- 0 0 0 var( --wp-admin-border-width-focus ) $alert-red !important;
164
+ box-shadow: inset 0 0 0 1px wp-colors.$alert-red, 0 0 0 1px white,
165
+ 0 0 0 var( --wp-admin-border-width-focus ) wp-colors.$alert-red !important;
166
166
  }
167
167
 
168
168
  &:active,
169
169
  &:hover {
170
- background-color: $gray-100;
171
- border-color: $alert-red;
170
+ background-color: wp-colors.$gray-100;
171
+ border-color: wp-colors.$alert-red;
172
172
  }
173
173
  }
174
174
  }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { Component } from '@wordpress/element';
5
+ import { ButtonGroup as BaseComponent } from '@wordpress/components';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import './style.scss';
11
+ /**
12
+ * External dependencies
13
+ */
14
+
15
+ import classnames from 'classnames';
16
+ /**
17
+ * Button Group.
18
+ */
19
+
20
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
21
+
22
+ class ButtonGroup extends Component {
23
+ /**
24
+ * Render.
25
+ */
26
+ render() {
27
+ const {
28
+ className,
29
+ noMargin,
30
+ ...otherProps
31
+ } = this.props;
32
+ const classes = classnames('newspack-button-group', {
33
+ 'newspack-button-group--no-margin': noMargin
34
+ }, className);
35
+ return _jsx(BaseComponent, {
36
+ className: classes,
37
+ ...otherProps
38
+ });
39
+ }
40
+
41
+ }
42
+
43
+ export default ButtonGroup;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Button Group
3
+ */
4
+
5
+ @import '../../../shared/scss/colors';
6
+ @import '~@wordpress/base-styles/colors';
7
+
8
+ .newspack-button-group {
9
+ display: block;
10
+ &:not( .newspack-button-group--no-margin ) {
11
+ margin: 32px 0;
12
+ }
13
+
14
+ .newspack-button {
15
+ padding: 11px 17px !important;
16
+ &:active,
17
+ &:focus,
18
+ &:hover,
19
+ &.is-pressed {
20
+ position: relative;
21
+ }
22
+
23
+ &.is-pressed {
24
+ position: relative;
25
+ z-index: 2;
26
+ background-color: white !important;
27
+ color: $gray-900 !important;
28
+ border: none !important;
29
+ &:focus {
30
+ box-shadow: 0 0 0 1px white, 0 0 0 2px $primary-500 !important;
31
+ }
32
+ &:active,
33
+ &:hover {
34
+ background: $gray-100 !important;
35
+ color: $primary-500 !important;
36
+ }
37
+ &::after {
38
+ content: '';
39
+ position: absolute;
40
+ top: 0;
41
+ left: 0;
42
+ width: calc( 100% - 6px );
43
+ height: calc( 100% - 6px );
44
+ border: 3px solid $primary-500;
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ body[class*='admin-color-'] {
51
+ .newspack-button-group {
52
+ .newspack-button {
53
+ border-radius: 0;
54
+ box-shadow: none;
55
+
56
+ &:first-child {
57
+ &,
58
+ &::after {
59
+ border-bottom-left-radius: 3px;
60
+ border-top-left-radius: 3px;
61
+ }
62
+ }
63
+
64
+ &:last-child {
65
+ &,
66
+ &::after {
67
+ border-bottom-right-radius: 3px;
68
+ border-top-right-radius: 3px;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
@@ -6,18 +6,17 @@
6
6
  * WordPress dependencies
7
7
  */
8
8
  import { Component } from '@wordpress/element';
9
+
9
10
  /**
10
11
  * Internal dependencies
11
12
  */
12
-
13
13
  import './style.scss';
14
+
14
15
  /**
15
16
  * External dependencies
16
17
  */
17
-
18
18
  import classNames from 'classnames';
19
19
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
20
-
21
20
  class Card extends Component {
22
21
  /**
23
22
  * Render
@@ -40,7 +39,5 @@ class Card extends Component {
40
39
  ...otherProps
41
40
  });
42
41
  }
43
-
44
42
  }
45
-
46
43
  export default Card;