newspack-components 2.0.3 → 2.1.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 (248) hide show
  1. package/copy-styles.js +1 -1
  2. package/dist/cjs/action-card/index.js +29 -20
  3. package/dist/cjs/action-card/style.scss +52 -27
  4. package/dist/cjs/autocomplete-tokenfield/style.scss +4 -4
  5. package/dist/cjs/autocomplete-with-suggestions/index.js +3 -2
  6. package/dist/cjs/autocomplete-with-suggestions/style.scss +19 -20
  7. package/dist/cjs/button/index.js +2 -13
  8. package/dist/cjs/button/style.scss +3 -344
  9. package/dist/cjs/button-card/index.js +11 -6
  10. package/dist/cjs/button-card/style.scss +60 -30
  11. package/dist/cjs/card/index.js +3 -1
  12. package/dist/cjs/card/style.scss +29 -62
  13. package/dist/cjs/category-autocomplete/index.js +52 -13
  14. package/dist/cjs/category-autocomplete/style.scss +20 -22
  15. package/dist/cjs/color-picker/index.js +17 -35
  16. package/dist/cjs/color-picker/style.scss +20 -160
  17. package/dist/cjs/custom-select-control/style.scss +12 -42
  18. package/dist/cjs/footer/index.js +21 -7
  19. package/dist/cjs/footer/style.scss +9 -10
  20. package/dist/cjs/form-token-field/index.js +2 -2
  21. package/dist/cjs/form-token-field/style.scss +8 -103
  22. package/dist/cjs/global-notices/index.js +2 -1
  23. package/dist/cjs/grid/style.scss +14 -1
  24. package/dist/cjs/handoff/index.js +7 -7
  25. package/dist/cjs/image-upload/index.js +1 -1
  26. package/dist/cjs/image-upload/style.scss +10 -11
  27. package/dist/cjs/index.js +7 -53
  28. package/dist/cjs/modal/index.js +0 -3
  29. package/dist/cjs/modal/style.scss +19 -131
  30. package/dist/cjs/newspack-icon/index.js +4 -2
  31. package/dist/cjs/newspack-icon/style.scss +15 -0
  32. package/dist/cjs/notice/index.js +8 -9
  33. package/dist/cjs/notice/style.scss +38 -10
  34. package/dist/cjs/plugin-installer/index.js +1 -1
  35. package/dist/cjs/plugin-settings/SettingsSection.js +74 -43
  36. package/dist/cjs/plugin-settings/index.js +34 -30
  37. package/dist/cjs/plugin-settings/style.scss +7 -0
  38. package/dist/cjs/plugin-toggle/index.js +22 -1
  39. package/dist/cjs/popover/style.scss +2 -2
  40. package/dist/cjs/radio-control/style.scss +1 -2
  41. package/dist/cjs/section-header/index.js +18 -5
  42. package/dist/cjs/section-header/style.scss +22 -1
  43. package/dist/cjs/select-control/ButtonGroupControl.js +8 -8
  44. package/dist/cjs/select-control/GroupedSelectControl.js +33 -30
  45. package/dist/cjs/select-control/index.js +1 -2
  46. package/dist/cjs/select-control/style.scss +46 -87
  47. package/dist/cjs/settings/MinMaxSetting.js +4 -2
  48. package/dist/cjs/settings/SettingsCard.js +6 -1
  49. package/dist/cjs/settings/SettingsSection.js +4 -4
  50. package/dist/cjs/settings/style.scss +32 -4
  51. package/dist/cjs/style-card/index.js +10 -6
  52. package/dist/cjs/style-card/style.scss +12 -8
  53. package/dist/cjs/style.scss +44 -0
  54. package/dist/cjs/tabbed-navigation/index.js +13 -20
  55. package/dist/cjs/tabbed-navigation/style.scss +56 -34
  56. package/dist/cjs/text-control/index.js +0 -3
  57. package/dist/cjs/text-control/style.scss +0 -126
  58. package/dist/cjs/waiting/index.js +9 -25
  59. package/dist/cjs/waiting/style.scss +9 -20
  60. package/dist/cjs/web-preview/index.js +18 -30
  61. package/dist/cjs/web-preview/style.scss +33 -26
  62. package/dist/cjs/with-wizard/index.js +4 -2
  63. package/dist/cjs/with-wizard/style.scss +44 -89
  64. package/dist/cjs/with-wizard-screen/index.js +17 -21
  65. package/dist/cjs/with-wizard-screen/style.scss +74 -121
  66. package/dist/cjs/wizard/components/WizardError.js +86 -0
  67. package/dist/cjs/wizard/index.js +145 -0
  68. package/dist/cjs/wizard/store/index.js +178 -0
  69. package/dist/cjs/wizard/store/utils.js +31 -0
  70. package/dist/esm/action-card/index.js +30 -21
  71. package/dist/esm/action-card/style.scss +52 -27
  72. package/dist/esm/autocomplete-tokenfield/style.scss +4 -4
  73. package/dist/esm/autocomplete-with-suggestions/index.js +3 -2
  74. package/dist/esm/autocomplete-with-suggestions/style.scss +19 -20
  75. package/dist/esm/button/index.js +2 -12
  76. package/dist/esm/button/style.scss +3 -344
  77. package/dist/esm/button-card/index.js +10 -6
  78. package/dist/esm/button-card/style.scss +60 -30
  79. package/dist/esm/card/index.js +3 -1
  80. package/dist/esm/card/style.scss +29 -62
  81. package/dist/esm/category-autocomplete/index.js +54 -14
  82. package/dist/esm/category-autocomplete/style.scss +20 -22
  83. package/dist/esm/color-picker/index.js +15 -34
  84. package/dist/esm/color-picker/style.scss +20 -160
  85. package/dist/esm/custom-select-control/style.scss +12 -42
  86. package/dist/esm/footer/index.js +21 -7
  87. package/dist/esm/footer/style.scss +9 -10
  88. package/dist/esm/form-token-field/index.js +2 -2
  89. package/dist/esm/form-token-field/style.scss +8 -103
  90. package/dist/esm/global-notices/index.js +2 -1
  91. package/dist/esm/grid/style.scss +14 -1
  92. package/dist/esm/handoff/index.js +7 -7
  93. package/dist/esm/image-upload/index.js +1 -1
  94. package/dist/esm/image-upload/style.scss +10 -11
  95. package/dist/esm/index.js +3 -8
  96. package/dist/esm/modal/index.js +0 -3
  97. package/dist/esm/modal/style.scss +19 -131
  98. package/dist/esm/newspack-icon/index.js +4 -2
  99. package/dist/esm/newspack-icon/style.scss +15 -0
  100. package/dist/esm/notice/index.js +8 -3
  101. package/dist/esm/notice/style.scss +38 -10
  102. package/dist/esm/plugin-installer/index.js +2 -1
  103. package/dist/esm/plugin-settings/SettingsSection.js +72 -44
  104. package/dist/esm/plugin-settings/index.js +34 -30
  105. package/dist/esm/plugin-settings/style.scss +7 -0
  106. package/dist/esm/plugin-toggle/index.js +23 -1
  107. package/dist/esm/popover/style.scss +2 -2
  108. package/dist/esm/radio-control/style.scss +1 -2
  109. package/dist/esm/section-header/index.js +17 -5
  110. package/dist/esm/section-header/style.scss +22 -1
  111. package/dist/esm/select-control/ButtonGroupControl.js +8 -8
  112. package/dist/esm/select-control/GroupedSelectControl.js +33 -30
  113. package/dist/esm/select-control/index.js +1 -2
  114. package/dist/esm/select-control/style.scss +46 -87
  115. package/dist/esm/settings/MinMaxSetting.js +3 -2
  116. package/dist/esm/settings/SettingsCard.js +6 -1
  117. package/dist/esm/settings/SettingsSection.js +5 -5
  118. package/dist/esm/settings/style.scss +32 -4
  119. package/dist/esm/style-card/index.js +11 -8
  120. package/dist/esm/style-card/style.scss +12 -8
  121. package/dist/esm/style.scss +44 -0
  122. package/dist/esm/tabbed-navigation/index.js +14 -22
  123. package/dist/esm/tabbed-navigation/style.scss +56 -34
  124. package/dist/esm/text-control/index.js +0 -3
  125. package/dist/esm/text-control/style.scss +0 -126
  126. package/dist/esm/waiting/index.js +9 -22
  127. package/dist/esm/waiting/style.scss +9 -20
  128. package/dist/esm/web-preview/index.js +12 -25
  129. package/dist/esm/web-preview/style.scss +33 -26
  130. package/dist/esm/with-wizard/index.js +4 -2
  131. package/dist/esm/with-wizard/style.scss +44 -89
  132. package/dist/esm/with-wizard-screen/index.js +18 -22
  133. package/dist/esm/with-wizard-screen/style.scss +74 -121
  134. package/dist/esm/wizard/components/WizardError.js +78 -0
  135. package/dist/esm/wizard/index.js +128 -0
  136. package/dist/esm/wizard/store/index.js +161 -0
  137. package/dist/esm/wizard/store/utils.js +17 -0
  138. package/package.json +1 -1
  139. package/shared/scss/_colors.scss +15 -0
  140. package/src/action-card/index.js +28 -18
  141. package/src/action-card/style.scss +52 -27
  142. package/src/autocomplete-tokenfield/style.scss +4 -4
  143. package/src/autocomplete-with-suggestions/index.js +4 -2
  144. package/src/autocomplete-with-suggestions/style.scss +19 -20
  145. package/src/button/index.js +2 -9
  146. package/src/button/style.scss +3 -344
  147. package/src/button-card/index.js +19 -5
  148. package/src/button-card/style.scss +60 -30
  149. package/src/card/index.js +4 -0
  150. package/src/card/style.scss +29 -62
  151. package/src/category-autocomplete/index.js +51 -18
  152. package/src/category-autocomplete/style.scss +20 -22
  153. package/src/color-picker/index.js +16 -22
  154. package/src/color-picker/style.scss +20 -160
  155. package/src/custom-select-control/style.scss +12 -42
  156. package/src/footer/index.js +19 -8
  157. package/src/footer/style.scss +9 -10
  158. package/src/form-token-field/index.js +1 -1
  159. package/src/form-token-field/style.scss +8 -103
  160. package/src/global-notices/index.js +1 -1
  161. package/src/grid/style.scss +14 -1
  162. package/src/handoff/index.js +7 -7
  163. package/src/image-upload/style.scss +10 -11
  164. package/src/index.js +3 -7
  165. package/src/modal/index.js +2 -5
  166. package/src/modal/style.scss +19 -131
  167. package/src/newspack-icon/index.js +7 -2
  168. package/src/newspack-icon/style.scss +15 -0
  169. package/src/notice/index.js +7 -1
  170. package/src/notice/style.scss +38 -10
  171. package/src/plugin-installer/index.js +2 -2
  172. package/src/plugin-settings/SettingsSection.js +64 -26
  173. package/src/plugin-settings/index.js +23 -7
  174. package/src/plugin-settings/style.scss +7 -0
  175. package/src/plugin-toggle/index.js +35 -9
  176. package/src/popover/style.scss +2 -2
  177. package/src/radio-control/style.scss +1 -2
  178. package/src/section-header/index.js +25 -6
  179. package/src/section-header/style.scss +22 -1
  180. package/src/select-control/ButtonGroupControl.js +13 -6
  181. package/src/select-control/GroupedSelectControl.js +26 -24
  182. package/src/select-control/index.js +1 -2
  183. package/src/select-control/style.scss +46 -87
  184. package/src/settings/MinMaxSetting.js +2 -1
  185. package/src/settings/SettingsCard.js +9 -7
  186. package/src/settings/SettingsSection.js +4 -4
  187. package/src/settings/style.scss +32 -4
  188. package/src/style-card/index.js +14 -16
  189. package/src/style-card/style.scss +12 -8
  190. package/src/style.scss +44 -0
  191. package/src/tabbed-navigation/index.js +12 -24
  192. package/src/tabbed-navigation/style.scss +56 -34
  193. package/src/text-control/index.js +1 -2
  194. package/src/text-control/style.scss +0 -126
  195. package/src/waiting/index.js +7 -18
  196. package/src/waiting/style.scss +9 -20
  197. package/src/web-preview/index.js +12 -33
  198. package/src/web-preview/style.scss +33 -26
  199. package/src/with-wizard/index.js +7 -5
  200. package/src/with-wizard/style.scss +44 -89
  201. package/src/with-wizard-screen/index.js +14 -17
  202. package/src/with-wizard-screen/style.scss +74 -121
  203. package/src/wizard/components/WizardError.js +57 -0
  204. package/src/wizard/index.js +133 -0
  205. package/src/wizard/store/index.js +126 -0
  206. package/src/wizard/store/utils.js +16 -0
  207. package/dist/cjs/button-group/index.js +0 -57
  208. package/dist/cjs/button-group/style.scss +0 -73
  209. package/dist/cjs/checkbox-control/index.js +0 -63
  210. package/dist/cjs/checkbox-control/style.scss +0 -78
  211. package/dist/cjs/preview-box/index.js +0 -36
  212. package/dist/cjs/preview-box/style.scss +0 -18
  213. package/dist/cjs/textarea-control/index.js +0 -54
  214. package/dist/cjs/textarea-control/style.scss +0 -76
  215. package/dist/cjs/toggle-control/index.js +0 -58
  216. package/dist/cjs/toggle-control/style.scss +0 -74
  217. package/dist/cjs/toggle-group/index.js +0 -71
  218. package/dist/cjs/toggle-group/style.scss +0 -28
  219. package/dist/cjs/wizard-pagination/index.js +0 -71
  220. package/dist/cjs/wizard-pagination/style.scss +0 -74
  221. package/dist/esm/button-group/index.js +0 -43
  222. package/dist/esm/button-group/style.scss +0 -73
  223. package/dist/esm/checkbox-control/index.js +0 -49
  224. package/dist/esm/checkbox-control/style.scss +0 -78
  225. package/dist/esm/preview-box/index.js +0 -30
  226. package/dist/esm/preview-box/style.scss +0 -18
  227. package/dist/esm/textarea-control/index.js +0 -40
  228. package/dist/esm/textarea-control/style.scss +0 -76
  229. package/dist/esm/toggle-control/index.js +0 -44
  230. package/dist/esm/toggle-control/style.scss +0 -74
  231. package/dist/esm/toggle-group/index.js +0 -58
  232. package/dist/esm/toggle-group/style.scss +0 -28
  233. package/dist/esm/wizard-pagination/index.js +0 -57
  234. package/dist/esm/wizard-pagination/style.scss +0 -74
  235. package/src/button-group/index.js +0 -35
  236. package/src/button-group/style.scss +0 -73
  237. package/src/checkbox-control/index.js +0 -38
  238. package/src/checkbox-control/style.scss +0 -78
  239. package/src/preview-box/index.js +0 -18
  240. package/src/preview-box/style.scss +0 -18
  241. package/src/textarea-control/index.js +0 -32
  242. package/src/textarea-control/style.scss +0 -76
  243. package/src/toggle-control/index.js +0 -38
  244. package/src/toggle-control/style.scss +0 -74
  245. package/src/toggle-group/index.js +0 -43
  246. package/src/toggle-group/style.scss +0 -28
  247. package/src/wizard-pagination/index.js +0 -59
  248. package/src/wizard-pagination/style.scss +0 -74
@@ -0,0 +1,78 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { __ as alias__ } from '@wordpress/i18n';
5
+ const __ = alias__;
6
+ import { useSelect } from '@wordpress/data';
7
+ /**
8
+ * Internal dependencies.
9
+ */
10
+
11
+ import { Button, Card, Modal, Notice } from '../..';
12
+ import { WIZARD_STORE_NAMESPACE } from '../store';
13
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
14
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
15
+
16
+ const parseError = _ref => {
17
+ let {
18
+ data,
19
+ message,
20
+ code
21
+ } = _ref;
22
+ let level = 'fatal';
23
+
24
+ if (!!data && 'level' in data) {
25
+ level = data.level;
26
+ } else if ('rest_invalid_param' === code) {
27
+ level = 'notice';
28
+ }
29
+
30
+ return {
31
+ message,
32
+ level
33
+ };
34
+ };
35
+
36
+ const WizardError = () => {
37
+ const error = useSelect(select => select(WIZARD_STORE_NAMESPACE).getError());
38
+
39
+ if (!error) {
40
+ return null;
41
+ }
42
+
43
+ const {
44
+ level,
45
+ message
46
+ } = parseError(error);
47
+
48
+ if ('fatal' === level) {
49
+ const fallbackURL = typeof newspack_urls !== 'undefined' && newspack_urls.dashboard;
50
+ return _jsxs(Modal, {
51
+ title: __('Unrecoverable error'),
52
+ onRequestClose: fallbackURL ? () => window.location = fallbackURL : undefined,
53
+ children: [_jsx(Notice, {
54
+ noticeText: message,
55
+ isError: true,
56
+ rawHTML: true
57
+ }), fallbackURL && _jsx(Card, {
58
+ buttonsCard: true,
59
+ noBorder: true,
60
+ className: "justify-end",
61
+ children: _jsx(Button, {
62
+ isPrimary: true,
63
+ href: fallbackURL,
64
+ children: __('Return to Dashboard', 'newspack')
65
+ })
66
+ })]
67
+ });
68
+ }
69
+
70
+ return _jsx(Notice, {
71
+ isError: true,
72
+ className: "newspack-wizard__above-header",
73
+ noticeText: message,
74
+ rawHTML: true
75
+ });
76
+ };
77
+
78
+ export default WizardError;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * External dependencies.
3
+ */
4
+ import classnames from 'classnames';
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+
9
+ import { useSelect } from '@wordpress/data';
10
+ import { useState } from '@wordpress/element';
11
+ import { __ as alias__ } from '@wordpress/i18n';
12
+ const __ = alias__;
13
+ import { category } from '@wordpress/icons';
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+
18
+ import { Footer, Notice, Button, NewspackIcon, TabbedNavigation, PluginInstaller } from '../';
19
+ import Router from '../proxied-imports/router';
20
+ import registerStore, { WIZARD_STORE_NAMESPACE } from './store';
21
+ import { useWizardData } from './store/utils';
22
+ import WizardError from './components/WizardError';
23
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
25
+ import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
26
+ registerStore();
27
+ const {
28
+ HashRouter,
29
+ Redirect,
30
+ Route,
31
+ Switch
32
+ } = Router;
33
+
34
+ const Wizard = _ref => {
35
+ let {
36
+ sections = [],
37
+ apiSlug,
38
+ headerText,
39
+ subHeaderText,
40
+ hasSimpleFooter,
41
+ className,
42
+ renderAboveSections,
43
+ requiredPlugins = []
44
+ } = _ref;
45
+ const isLoading = useSelect(select => select(WIZARD_STORE_NAMESPACE).isLoading());
46
+ const isQuietLoading = useSelect(select => select(WIZARD_STORE_NAMESPACE).isQuietLoading()); // Trigger initial data fetch. Some sections might not use the wizard data,
47
+ // but for consistency, fetching is triggered regardless of the section.
48
+
49
+ useSelect(select => select(WIZARD_STORE_NAMESPACE).getWizardAPIData(apiSlug));
50
+ let displayedSections = sections.filter(section => !section.isHidden);
51
+ const [pluginRequirementsSatisfied, setPluginRequirementsSatisfied] = useState(requiredPlugins.length === 0);
52
+
53
+ if (!pluginRequirementsSatisfied) {
54
+ headerText = requiredPlugins.length > 1 ? __('Required plugins', 'newspack') : __('Required plugin', 'newspack');
55
+ displayedSections = [{
56
+ path: '/',
57
+ render: () => _jsx(PluginInstaller, {
58
+ plugins: requiredPlugins,
59
+ onStatus: _ref2 => {
60
+ let {
61
+ complete
62
+ } = _ref2;
63
+ return setPluginRequirementsSatisfied(complete);
64
+ }
65
+ })
66
+ }];
67
+ }
68
+
69
+ return _jsxs(_Fragment, {
70
+ children: [_jsx(WizardError, {}), _jsx("div", {
71
+ className: classnames(isLoading ? 'newspack-wizard__is-loading' : 'newspack-wizard__is-loaded', {
72
+ 'newspack-wizard__is-loading-quiet': isQuietLoading
73
+ }),
74
+ children: _jsxs(HashRouter, {
75
+ hashType: "slash",
76
+ children: [newspack_aux_data.is_debug_mode && _jsx(Notice, {
77
+ debugMode: true
78
+ }), _jsx("div", {
79
+ className: "bg-white",
80
+ children: _jsx("div", {
81
+ className: "newspack-wizard__header__inner",
82
+ children: _jsxs("div", {
83
+ className: "newspack-wizard__title",
84
+ children: [_jsx(Button, {
85
+ isLink: true,
86
+ href: newspack_urls.dashboard,
87
+ label: __('Return to Dashboard', 'newspack'),
88
+ showTooltip: true,
89
+ icon: category,
90
+ iconSize: 36,
91
+ children: _jsx(NewspackIcon, {
92
+ size: 36
93
+ })
94
+ }), _jsxs("div", {
95
+ children: [headerText && _jsx("h2", {
96
+ children: headerText
97
+ }), subHeaderText && _jsx("span", {
98
+ children: subHeaderText
99
+ })]
100
+ })]
101
+ })
102
+ })
103
+ }), displayedSections.length > 1 && _jsx(TabbedNavigation, {
104
+ items: displayedSections
105
+ }), _jsxs(Switch, {
106
+ children: [displayedSections.map((section, index) => {
107
+ const SectionComponent = section.render;
108
+ return _jsx(Route, {
109
+ path: section.path,
110
+ children: _jsxs("div", {
111
+ className: classnames('newspack-wizard newspack-wizard__content', className),
112
+ children: ['function' === typeof renderAboveSections ? renderAboveSections() : null, _jsx(SectionComponent, {})]
113
+ })
114
+ }, index);
115
+ }), _jsx(Redirect, {
116
+ to: displayedSections[0].path
117
+ })]
118
+ })]
119
+ })
120
+ }), !isLoading && _jsx(Footer, {
121
+ simple: hasSimpleFooter
122
+ })]
123
+ });
124
+ };
125
+
126
+ Wizard.useWizardData = useWizardData;
127
+ Wizard.STORE_NAMESPACE = WIZARD_STORE_NAMESPACE;
128
+ export default Wizard;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * External dependencies.
3
+ */
4
+ import { set, get, isEmpty } from 'lodash';
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+
9
+ import apiFetch from '@wordpress/api-fetch';
10
+ import { createReduxStore, register, dispatch, select } from '@wordpress/data';
11
+ import { createAction } from './utils.js';
12
+ export const WIZARD_STORE_NAMESPACE = 'newspack/wizards';
13
+ const DEFAULT_STATE = {
14
+ isLoading: true,
15
+ isQuietLoading: false,
16
+ apiData: {},
17
+ error: null
18
+ };
19
+ /**
20
+ * wordpress/data does not trigger a component re-render
21
+ * on deep state change (via lodash's set function)
22
+ * unless the state was cloned first.
23
+ */
24
+
25
+ const clone = objectToClone => JSON.parse(JSON.stringify(objectToClone));
26
+
27
+ const reducer = function () {
28
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
29
+ let {
30
+ type,
31
+ payload = {}
32
+ } = arguments.length > 1 ? arguments[1] : undefined;
33
+
34
+ switch (type) {
35
+ case 'START_LOADING_DATA':
36
+ if (payload.isQuietLoading) {
37
+ return { ...state,
38
+ isQuietLoading: true
39
+ };
40
+ }
41
+
42
+ return { ...state,
43
+ isLoading: true
44
+ };
45
+
46
+ case 'FINISH_LOADING_DATA':
47
+ return { ...state,
48
+ isLoading: false,
49
+ isQuietLoading: false
50
+ };
51
+
52
+ case 'SET_API_DATA':
53
+ return set(clone(state), ['apiData', payload.slug], payload.data);
54
+
55
+ case 'UPDATE_WIZARD_SETTINGS':
56
+ return set(clone(state), ['apiData', payload.slug, ...payload.path], payload.value);
57
+
58
+ case 'SET_ERROR':
59
+ return { ...state,
60
+ error: payload
61
+ };
62
+
63
+ default:
64
+ return state;
65
+ }
66
+ };
67
+
68
+ const actions = {
69
+ // Regular actions.
70
+ startLoadingData: createAction('START_LOADING_DATA'),
71
+ finishLoadingData: createAction('FINISH_LOADING_DATA'),
72
+ fetchFromAPI: createAction('FETCH_FROM_API'),
73
+ setAPIDataForWizard: createAction('SET_API_DATA'),
74
+ updateWizardSettings: createAction('UPDATE_WIZARD_SETTINGS'),
75
+ setError: createAction('SET_ERROR'),
76
+
77
+ // Async actions. These will not show up in Redux devtools.
78
+ *saveWizardSettings(_ref) {
79
+ let {
80
+ slug,
81
+ section = '',
82
+ payloadPath = false,
83
+ updatePayload = null
84
+ } = _ref;
85
+
86
+ // Optionally data can be updated before saving - an immediate update case
87
+ // (without an explicit "save" action).
88
+ if (updatePayload) {
89
+ yield actions.updateWizardSettings({
90
+ slug,
91
+ ...updatePayload
92
+ });
93
+ }
94
+
95
+ const wizardState = select(WIZARD_STORE_NAMESPACE).getWizardAPIData(slug);
96
+ const updatedData = yield actions.fetchFromAPI({
97
+ path: `/newspack/v1/wizard/${slug}/${section}`,
98
+ method: 'POST',
99
+ data: payloadPath ? get(wizardState, payloadPath) : wizardState,
100
+ isQuietFetch: true
101
+ });
102
+
103
+ if (!isEmpty(updatedData)) {
104
+ return actions.setAPIDataForWizard({
105
+ slug,
106
+ data: updatedData
107
+ });
108
+ }
109
+ },
110
+
111
+ *wizardApiFetch(fetchConfig) {
112
+ // Just a proxy to fetchFromAPI, but it has to be a generator.
113
+ const result = yield actions.fetchFromAPI(fetchConfig);
114
+ return result;
115
+ }
116
+
117
+ };
118
+ const selectors = {
119
+ isLoading: state => state.isLoading,
120
+ isQuietLoading: state => state.isQuietLoading,
121
+ getWizardAPIData: (state, slug) => state.apiData[slug] || {},
122
+ getError: state => state.error
123
+ };
124
+ const store = createReduxStore(WIZARD_STORE_NAMESPACE, {
125
+ reducer,
126
+ actions,
127
+ selectors,
128
+ controls: {
129
+ FETCH_FROM_API: action => {
130
+ dispatch(WIZARD_STORE_NAMESPACE).startLoadingData({
131
+ isQuietLoading: Boolean(action.payload.isQuietFetch)
132
+ });
133
+ return apiFetch(action.payload).catch(error => {
134
+ dispatch(WIZARD_STORE_NAMESPACE).setError(error);
135
+ return {
136
+ error
137
+ };
138
+ }).finally(result => {
139
+ dispatch(WIZARD_STORE_NAMESPACE).finishLoadingData();
140
+ return result;
141
+ });
142
+ }
143
+ },
144
+ resolvers: {
145
+ *getWizardAPIData(slug) {
146
+ if (slug) {
147
+ const data = yield actions.fetchFromAPI({
148
+ path: `/newspack/v1/wizard/${slug}`
149
+ });
150
+ return actions.setAPIDataForWizard({
151
+ slug,
152
+ data
153
+ });
154
+ }
155
+
156
+ return actions.finishLoadingData();
157
+ }
158
+
159
+ }
160
+ });
161
+ export default (() => register(store));
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+
9
+ import { WIZARD_STORE_NAMESPACE } from '.';
10
+ export const createAction = type => payload => ({
11
+ type,
12
+ payload
13
+ });
14
+ export const useWizardData = function (wizardName) {
15
+ let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16
+ return useSelect(select => select(WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || defaultValue;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newspack-components",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Newspack design system components",
5
5
  "author": "Automattic",
6
6
  "license": "GPL-2.0-or-later",
@@ -1,3 +1,4 @@
1
+ // HEX
1
2
  $primary-000: #f5fdff;
2
3
  $primary-050: #d6f6ff;
3
4
  $primary-100: #b4e4ff;
@@ -10,3 +11,17 @@ $primary-700: #1522af;
10
11
  $primary-800: #0b0b8d;
11
12
  $primary-900: #0d046e;
12
13
  $primary-950: #0e0052;
14
+
15
+ // RGB
16
+ $primary-000--rgb: 245, 253, 255;
17
+ $primary-050--rgb: 214, 246, 255;
18
+ $primary-100--rgb: 180, 228, 255;
19
+ $primary-200--rgb: 147, 204, 253;
20
+ $primary-300--rgb: 114, 175, 251;
21
+ $primary-400--rgb: 82, 141, 252;
22
+ $primary-500--rgb: 51, 102, 255;
23
+ $primary-600--rgb: 34, 64, 213;
24
+ $primary-700--rgb: 21, 34, 175;
25
+ $primary-800--rgb: 11, 11, 141;
26
+ $primary-900--rgb: 13, 4, 110;
27
+ $primary-950--rgb: 14, 0, 82;
@@ -6,13 +6,13 @@
6
6
  * WordPress dependencies
7
7
  */
8
8
  import { Component } from '@wordpress/element';
9
- import { ExternalLink } from '@wordpress/components';
9
+ import { ExternalLink, ToggleControl } from '@wordpress/components';
10
10
  import { Icon, check } from '@wordpress/icons';
11
11
 
12
12
  /**
13
13
  * Internal dependencies
14
14
  */
15
- import { Button, Card, Handoff, Notice, ToggleControl, Waiting } from '../';
15
+ import { Button, Card, Grid, Handoff, Notice, Waiting } from '../';
16
16
  import './style.scss';
17
17
 
18
18
  /**
@@ -46,8 +46,10 @@ class ActionCard extends Component {
46
46
  actionContent,
47
47
  actionText,
48
48
  secondaryActionText,
49
+ secondaryDestructive,
49
50
  image,
50
51
  imageLink,
52
+ indent,
51
53
  isSmall,
52
54
  isMedium,
53
55
  simple,
@@ -58,6 +60,7 @@ class ActionCard extends Component {
58
60
  toggleChecked,
59
61
  toggleOnChange,
60
62
  hasGreyHeader,
63
+ isPending,
61
64
  } = this.props;
62
65
  const hasChildren = notification || children;
63
66
  const classes = classnames(
@@ -65,6 +68,7 @@ class ActionCard extends Component {
65
68
  simple && 'newspack-card--is-clickable',
66
69
  hasGreyHeader && 'newspack-card--has-grey-header',
67
70
  hasChildren && 'newspack-card--has-children',
71
+ indent && 'newspack-card--indent',
68
72
  isSmall && 'is-small',
69
73
  isMedium && 'is-medium',
70
74
  className
@@ -102,7 +106,8 @@ class ActionCard extends Component {
102
106
  className={ classnames(
103
107
  'newspack-checkbox-icon',
104
108
  'is-primary',
105
- 'checked' === checkbox && 'newspack-checkbox-icon--checked'
109
+ 'checked' === checkbox && 'newspack-checkbox-icon--checked',
110
+ isPending && 'newspack-checkbox-icon--pending'
106
111
  ) }
107
112
  >
108
113
  { 'checked' === checkbox && <Icon icon={ check } /> }
@@ -110,21 +115,25 @@ class ActionCard extends Component {
110
115
  </div>
111
116
  ) }
112
117
  <div className="newspack-action-card__region newspack-action-card__region-center">
113
- <h2>
114
- <span className="newspack-action-card__title" { ...titleProps }>
115
- { titleLink ? <a href={ titleLink }>{ title }</a> : title }
116
- </span>
117
- { badges?.length &&
118
- badges.map( ( badgeText, i ) => (
119
- <span key={ `badge-${ i }` } className="newspack-action-card__badge">
120
- { badgeText }
121
- </span>
122
- ) ) }
123
- </h2>
124
- <p>
125
- { typeof description === 'string' && description }
126
- { typeof description === 'function' && description() }
127
- </p>
118
+ <Grid columns={ 1 } gutter={ 8 } noMargin>
119
+ <h2>
120
+ <span className="newspack-action-card__title" { ...titleProps }>
121
+ { titleLink ? <a href={ titleLink }>{ title }</a> : title }
122
+ </span>
123
+ { badges?.length &&
124
+ badges.map( ( badgeText, i ) => (
125
+ <span key={ `badge-${ i }` } className="newspack-action-card__badge">
126
+ { badgeText }
127
+ </span>
128
+ ) ) }
129
+ </h2>
130
+ { description && (
131
+ <p>
132
+ { typeof description === 'string' && description }
133
+ { typeof description === 'function' && description() }
134
+ </p>
135
+ ) }
136
+ </Grid>
128
137
  </div>
129
138
  { ( actionText || isDisplayingSecondaryAction || actionContent ) && (
130
139
  <div className="newspack-action-card__region newspack-action-card__region-right">
@@ -160,6 +169,7 @@ class ActionCard extends Component {
160
169
  isLink
161
170
  onClick={ onSecondaryActionClick }
162
171
  className="newspack-action-card__secondary_button"
172
+ isDestructive={ secondaryDestructive }
163
173
  >
164
174
  { secondaryActionText }
165
175
  </Button>
@@ -3,7 +3,6 @@
3
3
  */
4
4
 
5
5
  @import '~@wordpress/base-styles/colors';
6
- @import '../../../shared/scss/colors';
7
6
 
8
7
  .newspack-card.newspack-action-card {
9
8
  padding: 0;
@@ -34,7 +33,7 @@
34
33
  }
35
34
 
36
35
  &.newspack-card__is-primary {
37
- box-shadow: inset 4px 0 0 $primary-500;
36
+ box-shadow: inset 4px 0 0 var( --wp-admin-theme-color );
38
37
  }
39
38
 
40
39
  &.newspack-card__is-secondary {
@@ -150,20 +149,49 @@
150
149
 
151
150
  &.newspack-card--has-grey-header {
152
151
  overflow: hidden;
152
+
153
153
  &.newspack-card--has-children {
154
154
  .newspack-action-card__region-top {
155
155
  border-bottom: 1px solid $gray-300;
156
156
  }
157
157
  }
158
+
158
159
  .newspack-action-card__region-top {
159
- background-color: $gray-100;
160
+ background-color: rgba( black, 0.025 );
161
+ }
162
+
163
+ .newspack-action-card__region-center {
164
+ p {
165
+ color: darken( $gray-700, 0.75% );
166
+ }
167
+ }
168
+ }
169
+
170
+ // Indent
171
+
172
+ &.newspack-card--indent {
173
+ margin-left: 56px;
174
+ position: relative;
175
+
176
+ &::before {
177
+ border: 0 solid $gray-300;
178
+ border-left-width: 1px;
179
+ border-bottom-width: 1px;
180
+ border-radius: 0 0 0 2px;
181
+ bottom: 50%;
182
+ content: '';
183
+ display: block;
184
+ left: -28px;
185
+ position: absolute;
186
+ right: 100%;
187
+ top: -17px;
160
188
  }
161
189
  }
162
190
 
163
191
  // Typography
164
192
 
165
193
  h2,
166
- p {
194
+ p:not( [class*='components-base-control'] ) {
167
195
  margin: 0;
168
196
  max-width: 100%;
169
197
  width: 100%;
@@ -186,7 +214,7 @@
186
214
  &:active,
187
215
  &:focus,
188
216
  &:hover {
189
- color: $primary-500;
217
+ color: var( --wp-admin-theme-color );
190
218
  }
191
219
  }
192
220
  }
@@ -270,6 +298,14 @@
270
298
  align-items: flex-start;
271
299
  flex: 1 1 auto;
272
300
  flex-wrap: wrap;
301
+
302
+ .newspack-grid {
303
+ width: 100%;
304
+ }
305
+
306
+ p {
307
+ color: $gray-700;
308
+ }
273
309
  }
274
310
 
275
311
  .newspack-action-card__region-right {
@@ -289,6 +325,10 @@
289
325
  > * {
290
326
  text-align: inherit;
291
327
  }
328
+
329
+ .newspack-action-card__secondary_button {
330
+ margin-top: 8px;
331
+ }
292
332
  }
293
333
 
294
334
  // Waiting
@@ -326,34 +366,19 @@
326
366
  margin: 0;
327
367
  }
328
368
 
329
- // Buttons
330
-
331
- .newspack-button {
332
- &.newspack-action-card__secondary_button {
333
- &.is-link {
334
- color: $alert-red;
335
-
336
- &:active,
337
- &:focus,
338
- &:hover {
339
- color: darken( $alert-red, 20% );
340
- }
341
- }
342
- }
343
- }
344
-
345
369
  // Badge
346
370
 
347
371
  .newspack-action-card__badge {
348
- border: 1px solid $gray-300;
349
- border-radius: 12px;
372
+ background: $gray-100;
373
+ border-radius: 2px;
374
+ color: $gray-900;
350
375
  display: block;
351
376
  flex: 0 0 auto;
352
- font-size: 12px;
377
+ font-size: 10px;
353
378
  font-weight: bold;
354
- line-height: 16px;
355
- margin: 3px 8px 3px 0;
356
- padding: 0 8px;
379
+ line-height: 1.4;
380
+ margin: 0 8px 0 0;
381
+ padding: 2px 8px;
357
382
  text-transform: uppercase;
358
383
 
359
384
  + .newspack-action-card__badge {
@@ -2,16 +2,16 @@
2
2
  * Autocomplete Token Field
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
5
  @import '~@wordpress/base-styles/colors';
7
6
 
8
7
  .newspack-autocomplete-tokenfield {
9
8
  position: relative;
10
9
 
11
10
  .components-spinner {
11
+ margin: 8px;
12
12
  position: absolute;
13
- right: 1rem;
14
- top: 1rem;
13
+ right: 0;
14
+ top: calc( 1.4em + 8px );
15
15
  }
16
16
 
17
17
  /* Workaround for hard-coded help text in FormTokenField. */
@@ -38,6 +38,6 @@
38
38
  }
39
39
 
40
40
  .components-button:focus:not( :disabled ) {
41
- box-shadow: inset 0 0 0 2px $primary-500;
41
+ box-shadow: inset 0 0 0 var( --wp-admin-border-width-focus ) var( --wp-admin-theme-color );
42
42
  }
43
43
  }