newspack-components 3.0.0-alpha.1 → 3.0.0-alpha.2

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