newspack-components 2.0.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/copy-styles.js +1 -1
  2. package/dist/cjs/accordion/index.js +46 -0
  3. package/dist/cjs/accordion/style.scss +27 -0
  4. package/dist/cjs/action-card/index.js +72 -40
  5. package/dist/cjs/action-card/style.scss +143 -41
  6. package/dist/cjs/autocomplete-tokenfield/index.js +13 -41
  7. package/dist/cjs/autocomplete-tokenfield/style.scss +6 -6
  8. package/dist/cjs/autocomplete-with-suggestions/index.js +33 -53
  9. package/dist/cjs/autocomplete-with-suggestions/style.scss +27 -27
  10. package/dist/cjs/button/index.js +1 -20
  11. package/dist/cjs/button/style.scss +3 -344
  12. package/dist/cjs/button-card/index.js +11 -15
  13. package/dist/cjs/button-card/style.scss +65 -35
  14. package/dist/cjs/card/index.js +4 -9
  15. package/dist/cjs/card/style.scss +47 -63
  16. package/dist/cjs/category-autocomplete/index.js +66 -47
  17. package/dist/cjs/category-autocomplete/style.scss +20 -24
  18. package/dist/cjs/color-picker/index.js +16 -48
  19. package/dist/cjs/color-picker/style.scss +20 -163
  20. package/dist/cjs/consts.js +5 -3
  21. package/dist/cjs/custom-select-control/index.js +1 -9
  22. package/dist/cjs/custom-select-control/style.scss +14 -45
  23. package/dist/cjs/date-range-picker/index.js +1 -10
  24. package/dist/cjs/date-range-picker/style.scss +12 -12
  25. package/dist/cjs/footer/index.js +24 -22
  26. package/dist/cjs/footer/style.scss +13 -14
  27. package/dist/cjs/form-token-field/index.js +3 -11
  28. package/dist/cjs/form-token-field/style.scss +9 -105
  29. package/dist/cjs/global-notices/index.js +3 -9
  30. package/dist/cjs/grid/index.js +1 -8
  31. package/dist/cjs/grid/style.scss +19 -6
  32. package/dist/cjs/handoff/index.js +15 -24
  33. package/dist/cjs/handoff-message/index.js +50 -0
  34. package/dist/cjs/hooks/index.js +1 -7
  35. package/dist/cjs/hooks/useObjectState.js +7 -13
  36. package/dist/cjs/hooks/useObjectState.test.js +0 -14
  37. package/dist/cjs/hooks/useOnClickOutside.js +3 -6
  38. package/dist/cjs/hooks/usePrompt.js +1 -13
  39. package/dist/cjs/image-upload/index.js +22 -20
  40. package/dist/cjs/image-upload/index.test.js +0 -5
  41. package/dist/cjs/image-upload/style.scss +12 -17
  42. package/dist/cjs/index.js +31 -93
  43. package/dist/cjs/info-button/index.js +3 -11
  44. package/dist/cjs/info-button/style.scss +1 -3
  45. package/dist/cjs/modal/index.js +1 -12
  46. package/dist/cjs/modal/style.scss +20 -132
  47. package/dist/cjs/newspack-icon/index.js +5 -11
  48. package/dist/cjs/newspack-icon/style.scss +17 -2
  49. package/dist/cjs/newspack-logo/index.js +1 -9
  50. package/dist/cjs/newspack-logo/style.scss +3 -3
  51. package/dist/cjs/notice/index.js +8 -16
  52. package/dist/cjs/notice/style.scss +60 -19
  53. package/dist/cjs/patrons-logo/index.js +3 -11
  54. package/dist/cjs/plugin-installer/index.js +37 -37
  55. package/dist/cjs/plugin-installer/style.scss +5 -5
  56. package/dist/cjs/plugin-settings/SettingsSection.js +71 -59
  57. package/dist/cjs/plugin-settings/index.js +71 -50
  58. package/dist/cjs/plugin-settings/style.scss +7 -0
  59. package/dist/cjs/plugin-toggle/index.js +60 -32
  60. package/dist/cjs/plugin-toggle/style.scss +2 -2
  61. package/dist/cjs/popover/index.js +1 -11
  62. package/dist/cjs/popover/style.scss +20 -17
  63. package/dist/cjs/position-control/index.js +113 -0
  64. package/dist/cjs/position-control/style.scss +66 -0
  65. package/dist/cjs/progress-bar/index.js +2 -9
  66. package/dist/cjs/progress-bar/index.test.js +2 -7
  67. package/dist/cjs/progress-bar/style.scss +4 -4
  68. package/dist/cjs/proxied-imports/router.js +0 -3
  69. package/dist/cjs/radio-control/index.js +1 -11
  70. package/dist/cjs/radio-control/style.scss +10 -11
  71. package/dist/cjs/section-header/index.js +47 -19
  72. package/dist/cjs/section-header/style.scss +22 -1
  73. package/dist/cjs/select-control/ButtonGroupControl.js +11 -20
  74. package/dist/cjs/select-control/GroupedSelectControl.js +42 -45
  75. package/dist/cjs/select-control/index.js +6 -14
  76. package/dist/cjs/select-control/style.scss +47 -88
  77. package/dist/cjs/settings/MinMaxSetting.js +6 -8
  78. package/dist/cjs/settings/SettingsCard.js +9 -8
  79. package/dist/cjs/settings/SettingsSection.js +5 -8
  80. package/dist/cjs/settings/index.js +0 -6
  81. package/dist/cjs/settings/style.scss +32 -4
  82. package/dist/cjs/steps-list/index.js +52 -0
  83. package/dist/cjs/steps-list/style.scss +11 -0
  84. package/dist/cjs/steps-list-item/index.js +56 -0
  85. package/dist/cjs/steps-list-item/style.scss +47 -0
  86. package/dist/cjs/style-card/index.js +15 -18
  87. package/dist/cjs/style-card/style.scss +19 -18
  88. package/dist/cjs/style.scss +43 -0
  89. package/dist/cjs/tabbed-navigation/index.js +27 -31
  90. package/dist/cjs/tabbed-navigation/style.scss +58 -37
  91. package/dist/cjs/text-control/index.js +6 -19
  92. package/dist/cjs/text-control/style.scss +0 -126
  93. package/dist/cjs/utils/index.js +10 -5
  94. package/dist/cjs/waiting/index.js +9 -33
  95. package/dist/cjs/waiting/style.scss +9 -20
  96. package/dist/cjs/web-preview/index.js +30 -57
  97. package/dist/cjs/web-preview/style.scss +41 -34
  98. package/dist/cjs/with-wizard/index.js +55 -33
  99. package/dist/cjs/with-wizard/style.scss +77 -124
  100. package/dist/cjs/with-wizard-screen/index.js +28 -38
  101. package/dist/cjs/with-wizard-screen/style.scss +75 -125
  102. package/dist/cjs/wizard/components/WizardError.js +74 -0
  103. package/dist/cjs/wizard/index.js +131 -0
  104. package/dist/cjs/wizard/store/index.js +165 -0
  105. package/dist/cjs/wizard/store/utils.js +26 -0
  106. package/dist/cjs/wizard/style.scss +148 -0
  107. package/dist/esm/accordion/index.js +38 -0
  108. package/dist/esm/accordion/style.scss +27 -0
  109. package/dist/esm/action-card/index.js +75 -37
  110. package/dist/esm/action-card/style.scss +143 -41
  111. package/dist/esm/autocomplete-tokenfield/index.js +14 -37
  112. package/dist/esm/autocomplete-tokenfield/style.scss +6 -6
  113. package/dist/esm/autocomplete-with-suggestions/index.js +31 -43
  114. package/dist/esm/autocomplete-with-suggestions/style.scss +27 -27
  115. package/dist/esm/button/index.js +2 -14
  116. package/dist/esm/button/style.scss +3 -344
  117. package/dist/esm/button-card/index.js +12 -11
  118. package/dist/esm/button-card/style.scss +65 -35
  119. package/dist/esm/card/index.js +5 -6
  120. package/dist/esm/card/style.scss +47 -63
  121. package/dist/esm/category-autocomplete/index.js +68 -41
  122. package/dist/esm/category-autocomplete/style.scss +20 -24
  123. package/dist/esm/color-picker/index.js +17 -38
  124. package/dist/esm/color-picker/style.scss +20 -163
  125. package/dist/esm/consts.js +3 -2
  126. package/dist/esm/custom-select-control/index.js +2 -5
  127. package/dist/esm/custom-select-control/style.scss +14 -45
  128. package/dist/esm/date-range-picker/index.js +1 -3
  129. package/dist/esm/date-range-picker/style.scss +12 -12
  130. package/dist/esm/footer/index.js +22 -16
  131. package/dist/esm/footer/style.scss +13 -14
  132. package/dist/esm/form-token-field/index.js +4 -7
  133. package/dist/esm/form-token-field/style.scss +9 -105
  134. package/dist/esm/global-notices/index.js +3 -7
  135. package/dist/esm/grid/index.js +2 -5
  136. package/dist/esm/grid/style.scss +19 -6
  137. package/dist/esm/handoff/index.js +10 -21
  138. package/dist/esm/handoff-message/index.js +45 -0
  139. package/dist/esm/hooks/index.js +0 -2
  140. package/dist/esm/hooks/useObjectState.js +3 -8
  141. package/dist/esm/hooks/useObjectState.test.js +0 -3
  142. package/dist/esm/hooks/useOnClickOutside.js +2 -5
  143. package/dist/esm/hooks/usePrompt.js +1 -8
  144. package/dist/esm/image-upload/index.js +18 -17
  145. package/dist/esm/image-upload/style.scss +12 -17
  146. package/dist/esm/index.js +7 -8
  147. package/dist/esm/info-button/index.js +4 -6
  148. package/dist/esm/info-button/style.scss +1 -3
  149. package/dist/esm/modal/index.js +2 -8
  150. package/dist/esm/modal/style.scss +20 -132
  151. package/dist/esm/newspack-icon/index.js +6 -7
  152. package/dist/esm/newspack-icon/style.scss +17 -2
  153. package/dist/esm/newspack-logo/index.js +2 -5
  154. package/dist/esm/newspack-logo/style.scss +3 -3
  155. package/dist/esm/notice/index.js +11 -10
  156. package/dist/esm/notice/style.scss +60 -19
  157. package/dist/esm/patrons-logo/index.js +3 -5
  158. package/dist/esm/plugin-installer/index.js +37 -40
  159. package/dist/esm/plugin-installer/style.scss +5 -5
  160. package/dist/esm/plugin-settings/SettingsSection.js +71 -56
  161. package/dist/esm/plugin-settings/index.js +70 -52
  162. package/dist/esm/plugin-settings/style.scss +7 -0
  163. package/dist/esm/plugin-toggle/index.js +59 -34
  164. package/dist/esm/plugin-toggle/style.scss +2 -2
  165. package/dist/esm/popover/index.js +3 -6
  166. package/dist/esm/popover/style.scss +20 -17
  167. package/dist/esm/position-control/index.js +109 -0
  168. package/dist/esm/position-control/style.scss +66 -0
  169. package/dist/esm/progress-bar/index.js +2 -7
  170. package/dist/esm/progress-bar/index.test.js +2 -1
  171. package/dist/esm/progress-bar/style.scss +4 -4
  172. package/dist/esm/proxied-imports/router.js +1 -0
  173. package/dist/esm/radio-control/index.js +3 -6
  174. package/dist/esm/radio-control/style.scss +10 -11
  175. package/dist/esm/section-header/index.js +47 -16
  176. package/dist/esm/section-header/style.scss +22 -1
  177. package/dist/esm/select-control/ButtonGroupControl.js +12 -14
  178. package/dist/esm/select-control/GroupedSelectControl.js +38 -36
  179. package/dist/esm/select-control/index.js +7 -8
  180. package/dist/esm/select-control/style.scss +47 -88
  181. package/dist/esm/settings/MinMaxSetting.js +4 -5
  182. package/dist/esm/settings/SettingsCard.js +9 -5
  183. package/dist/esm/settings/SettingsSection.js +5 -7
  184. package/dist/esm/settings/style.scss +32 -4
  185. package/dist/esm/steps-list/index.js +43 -0
  186. package/dist/esm/steps-list/style.scss +11 -0
  187. package/dist/esm/steps-list-item/index.js +48 -0
  188. package/dist/esm/steps-list-item/style.scss +47 -0
  189. package/dist/esm/style-card/index.js +13 -13
  190. package/dist/esm/style-card/style.scss +19 -18
  191. package/dist/esm/style.scss +43 -0
  192. package/dist/esm/tabbed-navigation/index.js +30 -28
  193. package/dist/esm/tabbed-navigation/style.scss +58 -37
  194. package/dist/esm/text-control/index.js +2 -12
  195. package/dist/esm/text-control/style.scss +0 -126
  196. package/dist/esm/utils/index.js +9 -3
  197. package/dist/esm/waiting/index.js +11 -27
  198. package/dist/esm/waiting/style.scss +9 -20
  199. package/dist/esm/web-preview/index.js +21 -49
  200. package/dist/esm/web-preview/style.scss +41 -34
  201. package/dist/esm/with-wizard/index.js +53 -36
  202. package/dist/esm/with-wizard/style.scss +77 -124
  203. package/dist/esm/with-wizard-screen/index.js +26 -32
  204. package/dist/esm/with-wizard-screen/style.scss +75 -125
  205. package/dist/esm/wizard/components/WizardError.js +69 -0
  206. package/dist/esm/wizard/index.js +126 -0
  207. package/dist/esm/wizard/store/index.js +155 -0
  208. package/dist/esm/wizard/store/utils.js +17 -0
  209. package/dist/esm/wizard/style.scss +148 -0
  210. package/package.json +4 -4
  211. package/src/accordion/index.js +32 -0
  212. package/src/accordion/style.scss +27 -0
  213. package/src/action-card/index.js +70 -25
  214. package/src/action-card/style.scss +143 -41
  215. package/src/autocomplete-tokenfield/index.js +1 -1
  216. package/src/autocomplete-tokenfield/style.scss +6 -6
  217. package/src/autocomplete-with-suggestions/index.js +4 -2
  218. package/src/autocomplete-with-suggestions/style.scss +27 -27
  219. package/src/button/index.js +2 -9
  220. package/src/button/style.scss +3 -344
  221. package/src/button-card/index.js +19 -5
  222. package/src/button-card/style.scss +65 -35
  223. package/src/card/index.js +4 -0
  224. package/src/card/style.scss +47 -63
  225. package/src/category-autocomplete/index.js +53 -18
  226. package/src/category-autocomplete/style.scss +20 -24
  227. package/src/color-picker/index.js +16 -22
  228. package/src/color-picker/style.scss +20 -163
  229. package/src/consts.js +2 -1
  230. package/src/custom-select-control/style.scss +14 -45
  231. package/src/date-range-picker/style.scss +12 -12
  232. package/src/footer/index.js +20 -9
  233. package/src/footer/style.scss +13 -14
  234. package/src/form-token-field/index.js +3 -8
  235. package/src/form-token-field/style.scss +9 -105
  236. package/src/global-notices/index.js +1 -1
  237. package/src/grid/style.scss +19 -6
  238. package/src/handoff/index.js +10 -15
  239. package/src/handoff-message/index.js +39 -0
  240. package/src/hooks/useObjectState.js +2 -1
  241. package/src/image-upload/index.js +9 -3
  242. package/src/image-upload/style.scss +12 -17
  243. package/src/index.js +7 -7
  244. package/src/info-button/style.scss +1 -3
  245. package/src/modal/index.js +2 -5
  246. package/src/modal/style.scss +20 -132
  247. package/src/newspack-icon/index.js +7 -2
  248. package/src/newspack-icon/style.scss +17 -2
  249. package/src/newspack-logo/style.scss +3 -3
  250. package/src/notice/index.js +9 -1
  251. package/src/notice/style.scss +60 -19
  252. package/src/plugin-installer/index.js +17 -4
  253. package/src/plugin-installer/style.scss +5 -5
  254. package/src/plugin-settings/SettingsSection.js +59 -27
  255. package/src/plugin-settings/index.js +29 -8
  256. package/src/plugin-settings/style.scss +7 -0
  257. package/src/plugin-toggle/index.js +37 -12
  258. package/src/plugin-toggle/style.scss +2 -2
  259. package/src/popover/style.scss +20 -17
  260. package/src/position-control/index.js +122 -0
  261. package/src/position-control/style.scss +66 -0
  262. package/src/progress-bar/style.scss +4 -4
  263. package/src/radio-control/style.scss +10 -11
  264. package/src/section-header/index.js +41 -5
  265. package/src/section-header/style.scss +22 -1
  266. package/src/select-control/ButtonGroupControl.js +15 -5
  267. package/src/select-control/GroupedSelectControl.js +28 -25
  268. package/src/select-control/index.js +6 -3
  269. package/src/select-control/style.scss +47 -88
  270. package/src/settings/MinMaxSetting.js +2 -1
  271. package/src/settings/SettingsCard.js +9 -7
  272. package/src/settings/SettingsSection.js +4 -4
  273. package/src/settings/style.scss +32 -4
  274. package/src/steps-list/index.js +39 -0
  275. package/src/steps-list/style.scss +11 -0
  276. package/src/steps-list-item/index.js +40 -0
  277. package/src/steps-list-item/style.scss +47 -0
  278. package/src/style-card/index.js +16 -27
  279. package/src/style-card/style.scss +19 -18
  280. package/src/style.scss +43 -0
  281. package/src/tabbed-navigation/index.js +20 -24
  282. package/src/tabbed-navigation/style.scss +58 -37
  283. package/src/text-control/index.js +1 -2
  284. package/src/text-control/style.scss +0 -126
  285. package/src/utils/index.js +9 -0
  286. package/src/waiting/index.js +7 -18
  287. package/src/waiting/style.scss +9 -20
  288. package/src/web-preview/index.js +13 -34
  289. package/src/web-preview/style.scss +41 -34
  290. package/src/with-wizard/index.js +7 -5
  291. package/src/with-wizard/style.scss +77 -124
  292. package/src/with-wizard-screen/index.js +17 -17
  293. package/src/with-wizard-screen/style.scss +75 -125
  294. package/src/wizard/components/WizardError.js +57 -0
  295. package/src/wizard/index.js +145 -0
  296. package/src/wizard/store/index.js +132 -0
  297. package/src/wizard/store/utils.js +16 -0
  298. package/dist/cjs/wizard-pagination/index.js +0 -71
  299. package/dist/cjs/wizard-pagination/style.scss +0 -74
  300. package/dist/esm/wizard-pagination/index.js +0 -57
  301. package/dist/esm/wizard-pagination/style.scss +0 -74
  302. package/src/button-group/index.js +0 -35
  303. package/src/button-group/style.scss +0 -73
  304. package/src/checkbox-control/index.js +0 -38
  305. package/src/checkbox-control/style.scss +0 -78
  306. package/src/preview-box/index.js +0 -18
  307. package/src/preview-box/style.scss +0 -18
  308. package/src/textarea-control/index.js +0 -32
  309. package/src/textarea-control/style.scss +0 -76
  310. package/src/toggle-control/index.js +0 -38
  311. package/src/toggle-control/style.scss +0 -74
  312. package/src/toggle-group/index.js +0 -43
  313. package/src/toggle-group/style.scss +0 -28
  314. package/src/wizard-pagination/index.js +0 -59
  315. package/src/wizard-pagination/style.scss +0 -74
@@ -5,16 +5,22 @@
5
5
  /**
6
6
  * WordPress dependencies
7
7
  */
8
- import { Fragment } from '@wordpress/element';
8
+ import { Fragment, useState } from '@wordpress/element';
9
+ import { applyFilters } from '@wordpress/hooks';
9
10
  import { __ } from '@wordpress/i18n';
11
+ import { CheckboxControl } from '@wordpress/components';
10
12
 
11
13
  /**
12
14
  * Internal dependencies
13
15
  */
14
- import { ActionCard, Grid, Button, TextControl, CheckboxControl, SelectControl } from '../';
16
+ import { ActionCard, Button, Grid, Notice, SelectControl, TextControl } from '../';
17
+ import './style.scss';
15
18
 
19
+ const isSelectControl = setting => {
20
+ return Array.isArray( setting.options ) && setting.options.length;
21
+ };
16
22
  const getControlComponent = setting => {
17
- if ( Array.isArray( setting.options ) && setting.options.length ) {
23
+ if ( isSelectControl( setting ) ) {
18
24
  return SelectControl;
19
25
  }
20
26
  switch ( setting.type ) {
@@ -35,20 +41,20 @@ const getControlType = setting => {
35
41
  case 'string':
36
42
  case 'text':
37
43
  return 'text';
44
+ case 'password':
45
+ return 'password';
46
+ case 'boolean':
47
+ case 'checkbox':
48
+ return 'checkbox';
38
49
  default:
39
50
  return null;
40
51
  }
41
52
  };
42
53
 
43
- const SettingsSection = ( {
44
- active,
45
- title,
46
- description,
47
- fields,
48
- disabled,
49
- onChange,
50
- onUpdate,
51
- } ) => {
54
+ const SettingsSection = props => {
55
+ const [ saveDisabled, setSaveDisabled ] = useState( true );
56
+ const { error, sectionKey, active, title, description, fields, disabled, onChange, onUpdate } =
57
+ props;
52
58
  const getControlProps = setting => ( {
53
59
  disabled,
54
60
  name: `${ setting.section }_${ setting.key }`,
@@ -58,14 +64,29 @@ const SettingsSection = ( {
58
64
  options:
59
65
  setting.options?.map( option => ( {
60
66
  value: option.value,
61
- label: option.name,
67
+ label: option.name || option.label,
62
68
  } ) ) || null,
63
69
  value: setting.value,
70
+ multiple: isSelectControl( setting ) && setting.multiple ? true : null,
64
71
  checked: setting.type === 'boolean' ? !! setting.value : null,
65
72
  onChange: value => {
66
73
  onChange( setting.key, value );
74
+ setSaveDisabled( false );
67
75
  },
68
76
  } );
77
+ const createFilter = ( name, defaultComponent = null ) => {
78
+ return applyFilters(
79
+ `newspack.settingSection.${ sectionKey }.${ name }`,
80
+ defaultComponent,
81
+ props
82
+ );
83
+ };
84
+ let columns = 2;
85
+ if ( fields.length % 3 === 0 ) {
86
+ columns = 3;
87
+ } else if ( fields.length === 1 ) {
88
+ columns = 1;
89
+ }
69
90
  return (
70
91
  <ActionCard
71
92
  isMedium
@@ -73,28 +94,39 @@ const SettingsSection = ( {
73
94
  title={ title }
74
95
  description={ description }
75
96
  toggleChecked={ active }
76
- hasGreyHeader={ true }
97
+ hasGreyHeader={ active || null === active }
77
98
  toggleOnChange={ active !== null ? value => onUpdate( { active: value } ) : null }
99
+ actionContent={
100
+ ( active || null === active ) &&
101
+ createFilter(
102
+ 'buttons',
103
+ <Button
104
+ variant="primary"
105
+ disabled={ disabled || saveDisabled }
106
+ onClick={ () => {
107
+ onUpdate();
108
+ setSaveDisabled( true );
109
+ } }
110
+ >
111
+ { __( 'Save Settings', 'newspack' ) }
112
+ </Button>
113
+ )
114
+ }
78
115
  >
79
116
  { ( active || active === null ) && (
80
117
  <Fragment>
81
- <Grid columns={ fields.length % 3 === 0 ? 3 : 2 } gutter={ 32 }>
118
+ { error?.message && <Notice noticeText={ error.message } isError /> }
119
+ { createFilter( 'beforeControls' ) }
120
+ <Grid columns={ columns } gutter={ 32 }>
82
121
  { fields.map( setting => {
83
122
  const Control = getControlComponent( setting ); // eslint-disable-line @wordpress/no-unused-vars-before-return, no-unused-vars
84
- return <Control key={ setting.key } { ...getControlProps( setting ) } />;
123
+ return applyFilters(
124
+ `newspack.settingsSection.${ sectionKey }.control`,
125
+ <Control key={ setting.key } { ...getControlProps( setting ) } />,
126
+ { sectionKey, setting, onChange }
127
+ );
85
128
  } ) }
86
129
  </Grid>
87
- <div className="newspack-buttons-card" style={ { margin: '32px 0 0' } }>
88
- <Button
89
- isPrimary
90
- disabled={ disabled }
91
- onClick={ () => {
92
- onUpdate();
93
- } }
94
- >
95
- { __( 'Save settings', 'newspack' ) }
96
- </Button>
97
- </div>
98
130
  </Fragment>
99
131
  ) }
100
132
  </ActionCard>
@@ -27,11 +27,18 @@ class PluginSettings extends Component {
27
27
  }
28
28
 
29
29
  fetchSettings = () => {
30
- const { pluginSlug } = this.props;
30
+ const { afterFetch, pluginSlug, isWizard } = this.props;
31
31
  this.setState( { inFlight: true } );
32
- apiFetch( { path: `/${ pluginSlug }/v1/settings` } )
32
+ apiFetch( {
33
+ path: isWizard
34
+ ? `/newspack/v1/wizard/${ pluginSlug }/settings`
35
+ : `/${ pluginSlug }/v1/settings`,
36
+ } )
33
37
  .then( settings => {
34
38
  this.setState( { settings, error: null } );
39
+ if ( 'function' === typeof afterFetch ) {
40
+ afterFetch( settings );
41
+ }
35
42
  } )
36
43
  .catch( error => {
37
44
  this.setState( { error } );
@@ -70,10 +77,12 @@ class PluginSettings extends Component {
70
77
  };
71
78
 
72
79
  handleSectionUpdate = sectionKey => data => {
73
- const { pluginSlug } = this.props;
80
+ const { afterUpdate, pluginSlug, isWizard } = this.props;
74
81
  this.setState( { inFlight: true } );
75
82
  apiFetch( {
76
- path: `/${ pluginSlug }/v1/settings`,
83
+ path: isWizard
84
+ ? `/newspack/v1/wizard/${ pluginSlug }/settings`
85
+ : `/${ pluginSlug }/v1/settings`,
77
86
  method: 'POST',
78
87
  data: {
79
88
  section: sectionKey,
@@ -81,7 +90,16 @@ class PluginSettings extends Component {
81
90
  },
82
91
  } )
83
92
  .then( settings => {
84
- this.setState( { settings, error: null } );
93
+ this.setState( {
94
+ settings: {
95
+ ...this.state.settings,
96
+ [ sectionKey ]: settings[ sectionKey ],
97
+ },
98
+ error: null,
99
+ } );
100
+ if ( 'function' === typeof afterUpdate ) {
101
+ afterUpdate( settings );
102
+ }
85
103
  } )
86
104
  .catch( error => {
87
105
  this.setState( { error } );
@@ -154,14 +172,14 @@ class PluginSettings extends Component {
154
172
  * Render.
155
173
  */
156
174
  render() {
157
- const { title, description } = this.props;
175
+ const { title, description, hasGreyHeader, children } = this.props;
158
176
  const { settings, inFlight, error } = this.state;
159
177
  return (
160
178
  <Fragment>
161
- <SectionHeader title={ title } description={ description } />
179
+ { title && <SectionHeader title={ title } description={ description } /> }
162
180
  { error && <Notice isError noticeText={ error.message } /> }
163
181
  <div
164
- className={ classnames( {
182
+ className={ classnames( 'newspack-plugin-settings', {
165
183
  'newspack-wizard-section__is-loading': inFlight && ! Object.keys( settings ).length,
166
184
  } ) }
167
185
  >
@@ -169,14 +187,17 @@ class PluginSettings extends Component {
169
187
  <SettingsSection
170
188
  key={ sectionKey }
171
189
  disabled={ inFlight }
190
+ sectionKey={ sectionKey }
172
191
  title={ this.getSectionTitle( sectionKey ) }
173
192
  description={ this.getSectionDescription( sectionKey ) }
174
193
  active={ this.isSectionActive( sectionKey ) }
175
194
  fields={ this.getSectionFields( sectionKey ) }
176
195
  onChange={ this.handleSettingChange( sectionKey ) }
177
196
  onUpdate={ this.handleSectionUpdate( sectionKey ) }
197
+ hasGreyHeader={ hasGreyHeader }
178
198
  />
179
199
  ) ) }
200
+ { children }
180
201
  </div>
181
202
  </Fragment>
182
203
  );
@@ -0,0 +1,7 @@
1
+ .newspack-card:not( .newspack-settings__no-border ) {
2
+ .newspack-action-card__region-children {
3
+ > .newspack-grid {
4
+ margin: 32px 0 0 !important;
5
+ }
6
+ }
7
+ }
@@ -51,15 +51,27 @@ class PluginToggle extends Component {
51
51
  pluginInfo: { ...pluginInfo, [ plugin ]: { ...pluginInfo[ plugin ], inFlight: action } },
52
52
  },
53
53
  () => {
54
- apiFetch( params ).then( response => {
55
- const { shouldRefreshAfterUpdate } = plugins[ plugin ];
56
- this.setState(
57
- ( { pluginInfo: currentPluginInfo } ) => ( {
58
- pluginInfo: { ...currentPluginInfo, [ plugin ]: response },
59
- } ),
60
- () => shouldRefreshAfterUpdate && location.reload()
61
- );
62
- } );
54
+ apiFetch( params )
55
+ .then( response => {
56
+ const { shouldRefreshAfterUpdate } = plugins[ plugin ];
57
+ this.setState(
58
+ ( { pluginInfo: currentPluginInfo } ) => ( {
59
+ pluginInfo: { ...currentPluginInfo, [ plugin ]: response },
60
+ } ),
61
+ () => shouldRefreshAfterUpdate && location.reload()
62
+ );
63
+ } )
64
+ .catch( e => {
65
+ this.setState( {
66
+ pluginInfo: {
67
+ ...pluginInfo,
68
+ [ plugin ]: {
69
+ ...pluginInfo[ plugin ],
70
+ error: e.message || __( 'There was an error managing this plugin.', 'newspack' ),
71
+ },
72
+ },
73
+ } );
74
+ } );
63
75
  }
64
76
  );
65
77
  };
@@ -74,6 +86,7 @@ class PluginToggle extends Component {
74
86
  const { name, description, href, slug, editPath } = plugin;
75
87
  const pluginStatus = this.isPluginInstalledAndActive( plugin );
76
88
  const handoff = ! href && pluginStatus && editPath ? slug : null;
89
+ const error = this.errorForPlugin( plugin );
77
90
  return (
78
91
  <ActionCard
79
92
  key={ index }
@@ -86,6 +99,9 @@ class PluginToggle extends Component {
86
99
  toggle
87
100
  toggleChecked={ this.isPluginInstalledAndActive( plugin ) }
88
101
  toggleOnChange={ value => this.managePlugin( slug, value ) }
102
+ notification={ error }
103
+ notificationHTML={ error }
104
+ notificationLevel="error"
89
105
  />
90
106
  );
91
107
  } );
@@ -101,9 +117,8 @@ class PluginToggle extends Component {
101
117
  ? Object.keys( pluginsFromAPI[ pluginSlug ] ).reduce(
102
118
  ( accumulator, key ) => ( {
103
119
  ...accumulator,
104
- [ key.charAt( 0 ).toLowerCase() + key.slice( 1 ) ]: pluginsFromAPI[ pluginSlug ][
105
- key
106
- ],
120
+ [ key.charAt( 0 ).toLowerCase() + key.slice( 1 ) ]:
121
+ pluginsFromAPI[ pluginSlug ][ key ],
107
122
  } ),
108
123
  {}
109
124
  )
@@ -160,6 +175,16 @@ class PluginToggle extends Component {
160
175
  }
161
176
  };
162
177
 
178
+ /**
179
+ * Get error message for this plugin.
180
+ */
181
+ errorForPlugin = plugin => {
182
+ const { slug } = plugin;
183
+ const { pluginInfo } = this.state;
184
+
185
+ return pluginInfo[ slug ]?.error || null;
186
+ };
187
+
163
188
  /**
164
189
  * Get installation/activation status for a plugin.
165
190
  */
@@ -2,7 +2,7 @@
2
2
  * Plugin Toggle
3
3
  */
4
4
 
5
- @import '~@wordpress/base-styles/colors';
5
+ @use '~@wordpress/base-styles/colors' as wp-colors;
6
6
 
7
7
  .newspack-action-card {
8
8
  &.in-flight,
@@ -11,7 +11,7 @@
11
11
 
12
12
  .newspack-action-card__region-right {
13
13
  .newspack-button {
14
- color: $gray-700;
14
+ color: wp-colors.$gray-700;
15
15
  pointer-events: none;
16
16
  text-decoration: none;
17
17
  }
@@ -2,48 +2,47 @@
2
2
  * Popover
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '../../../shared/scss/colors';
6
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
7
 
8
8
  .newspack-popover {
9
9
  .components-popover__content {
10
- border: 1px solid $gray-300;
11
- border-radius: 3px;
12
- box-shadow: 0 4px 8px rgba( black, 0.08 );
13
10
  min-width: 238px;
14
11
 
15
12
  .newspack-button {
16
- color: $gray-700;
13
+ color: wp-colors.$gray-700;
17
14
  display: flex;
18
15
  font-weight: normal;
19
16
  padding: 6px 8px;
20
17
 
21
18
  &:hover {
19
+ color: colors.$primary-500;
20
+
22
21
  .components-menu-items__item-icon {
23
- fill: currentColor;
22
+ fill: currentcolor;
24
23
  }
25
24
  }
26
25
 
27
26
  &:focus:not( :disabled ) {
28
- box-shadow: inset 0 0 0 2px $primary-500;
27
+ box-shadow: inset 0 0 0 2px colors.$primary-500;
29
28
  position: relative;
30
29
  z-index: 1;
31
30
  }
32
31
 
33
32
  &.is-link {
34
- border-radius: 3px;
33
+ border-radius: 2px;
35
34
  padding: 6px 8px;
36
35
  text-decoration: none;
37
36
 
38
37
  &:not( .is-destructive ) {
39
- color: $gray-700;
38
+ color: wp-colors.$gray-700;
40
39
 
41
40
  &:active,
42
41
  &:active:enabled,
43
42
  &:focus,
44
43
  &:focus:enabled &:hover,
45
- &:not( :disabled ):not( [aria-disabled='true'] ):not( .is-default ):hover {
46
- color: $primary-500;
44
+ &:not( :disabled, [aria-disabled='true'], .is-default ):hover {
45
+ color: colors.$primary-500;
47
46
  }
48
47
  }
49
48
 
@@ -53,8 +52,12 @@
53
52
  }
54
53
  }
55
54
 
55
+ &.is-destructive:not( :focus ) {
56
+ box-shadow: none !important;
57
+ }
58
+
56
59
  .components-menu-items__item-icon {
57
- fill: $gray-900;
60
+ fill: wp-colors.$gray-900;
58
61
  }
59
62
 
60
63
  .components-menu-item__item {
@@ -64,7 +67,7 @@
64
67
  }
65
68
 
66
69
  .components-menu-group__label {
67
- color: $gray-900;
70
+ color: wp-colors.$gray-900;
68
71
  font-size: 12px;
69
72
  font-weight: bold;
70
73
  line-height: 16px;
@@ -86,8 +89,8 @@
86
89
  min-height: 36px;
87
90
 
88
91
  &:focus ~ div.components-input-control__backdrop {
89
- border-color: $primary-500;
90
- box-shadow: inset 0 0 0 1px $primary-500;
92
+ border-color: colors.$primary-500;
93
+ box-shadow: inset 0 0 0 1px colors.$primary-500;
91
94
  }
92
95
  }
93
96
 
@@ -129,7 +132,7 @@
129
132
  }
130
133
 
131
134
  &:not( .is-without-arrow )::before {
132
- border-color: $gray-300;
135
+ border-color: wp-colors.$gray-300;
133
136
  }
134
137
 
135
138
  &.is-from-bottom {
@@ -0,0 +1,122 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { ButtonGroup, Button } from '@wordpress/components';
6
+
7
+ /**
8
+ * External dependencies
9
+ */
10
+ import classnames from 'classnames';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import './style.scss';
16
+
17
+ export default function PositionControl( {
18
+ allowedPositions,
19
+ value,
20
+ label,
21
+ help,
22
+ onChange,
23
+ size,
24
+ ...props
25
+ } ) {
26
+ /**
27
+ * Set layout options
28
+ */
29
+ const options =
30
+ size === 'full-width'
31
+ ? [
32
+ {
33
+ value: 'top',
34
+ /* translators: Overlay Position */
35
+ label: __( 'Top', 'newspack' ),
36
+ },
37
+ {
38
+ value: 'center',
39
+ /* translators: Overlay Position */
40
+ label: __( 'Center', 'newspack' ),
41
+ },
42
+ {
43
+ value: 'bottom',
44
+ /* translators: Overlay Position */
45
+ label: __( 'Bottom', 'newspack' ),
46
+ },
47
+ ]
48
+ : [
49
+ {
50
+ value: 'top_left',
51
+ /* translators: Overlay Position */
52
+ label: __( 'Top Left', 'newspack' ),
53
+ },
54
+ {
55
+ value: 'top',
56
+ /* translators: Overlay Position */
57
+ label: __( 'Top Center', 'newspack' ),
58
+ },
59
+ {
60
+ value: 'top_right',
61
+ /* translators: Overlay Position */
62
+ label: __( 'Top Right', 'newspack' ),
63
+ },
64
+ {
65
+ value: 'center_left',
66
+ /* translators: Overlay Position */
67
+ label: __( 'Center Left', 'newspack' ),
68
+ },
69
+ {
70
+ value: 'center',
71
+ /* translators: Overlay Position */
72
+ label: __( 'Center', 'newspack' ),
73
+ },
74
+ {
75
+ value: 'center_right',
76
+ /* translators: Overlay Position */
77
+ label: __( 'Center Right', 'newspack' ),
78
+ },
79
+ {
80
+ value: 'bottom_left',
81
+ /* translators: Overlay Position */
82
+ label: __( 'Bottom Left', 'newspack' ),
83
+ },
84
+ {
85
+ value: 'bottom',
86
+ /* translators: Overlay Position */
87
+ label: __( 'Bottom Center', 'newspack' ),
88
+ },
89
+ {
90
+ value: 'bottom_right',
91
+ /* translators: Overlay Position */
92
+ label: __( 'Bottom Right', 'newspack' ),
93
+ },
94
+ ];
95
+ return (
96
+ <div className={ classnames( 'newspack-position-placement-control', 'size-' + size ) }>
97
+ <p className="components-base-control__label">{ label }</p>
98
+ <ButtonGroup aria-label={ __( 'Select Position', 'newspack' ) } { ...props }>
99
+ { options.map( ( option, index ) => {
100
+ return (
101
+ <div
102
+ key={ `newspack-position-placement-item-${ index }` }
103
+ className={ option.value === value ? 'is-selected' : null }
104
+ >
105
+ <Button
106
+ isSmall
107
+ title={ option.label }
108
+ aria-label={ option.label }
109
+ isPrimary={ option.value === value }
110
+ onClick={ () => {
111
+ onChange( option.value );
112
+ } }
113
+ disabled={ allowedPositions?.length && ! allowedPositions.includes( option.value ) }
114
+ />
115
+ </div>
116
+ );
117
+ } ) }
118
+ </ButtonGroup>
119
+ <p className="components-base-control__help">{ help }</p>
120
+ </div>
121
+ );
122
+ }
@@ -0,0 +1,66 @@
1
+ @use '~@wordpress/base-styles/colors' as wp-colors;
2
+
3
+ .newspack-position-placement-control {
4
+ margin-bottom: 1em;
5
+
6
+ .components-base-control__label {
7
+ margin-bottom: 8px;
8
+ margin-top: 1em;
9
+ }
10
+
11
+ .components-button-group {
12
+ display: grid;
13
+ grid-template-columns: repeat( 3, 1fr );
14
+ grid-template-rows: repeat( 3, 1fr );
15
+
16
+ div {
17
+ padding: 1px;
18
+ }
19
+
20
+ .components-button {
21
+ border-radius: 0 !important;
22
+ height: 100%;
23
+ padding: 20px;
24
+ width: 100%;
25
+ }
26
+
27
+ div:nth-of-type( 1 ) .components-button {
28
+ border-radius: 4px 0 0 !important;
29
+ }
30
+
31
+ div:nth-of-type( 3 ) .components-button {
32
+ border-radius: 0 4px 0 0 !important;
33
+ }
34
+
35
+ div:nth-last-of-type( 1 ) .components-button {
36
+ border-radius: 0 0 4px !important;
37
+ }
38
+
39
+ div:nth-last-of-type( 3 ) .components-button {
40
+ border-radius: 0 0 0 4px !important;
41
+ }
42
+ }
43
+
44
+ &.size-full-width .components-button-group {
45
+ grid-template-columns: 1fr;
46
+
47
+ div:first-of-type .components-button {
48
+ border-radius: 4px 4px 0 0 !important;
49
+ }
50
+
51
+ div:nth-of-type( 2 ) .components-button {
52
+ border-radius: 0 !important;
53
+ }
54
+
55
+ div:last-of-type .components-button {
56
+ border-radius: 0 0 4px 4px !important;
57
+ }
58
+ }
59
+
60
+ .components-base-control__help {
61
+ color: wp-colors.$gray-700;
62
+ font-size: 12px;
63
+ font-style: normal;
64
+ margin-top: 8px;
65
+ }
66
+ }
@@ -2,8 +2,8 @@
2
2
  * Progress Bar
3
3
  */
4
4
 
5
- @import '../../../shared/scss/colors';
6
- @import '~@wordpress/base-styles/colors';
5
+ @use '../../../shared/scss/colors';
6
+ @use '~@wordpress/base-styles/colors' as wp-colors;
7
7
 
8
8
  .newspack-progress-bar {
9
9
  margin: 32px 0;
@@ -26,7 +26,7 @@
26
26
  }
27
27
 
28
28
  &__container {
29
- background-color: $gray-100;
29
+ background-color: wp-colors.$gray-100;
30
30
  border-radius: 4px;
31
31
  height: 8px;
32
32
  overflow: hidden;
@@ -35,7 +35,7 @@
35
35
  }
36
36
 
37
37
  &__bar {
38
- background-color: $primary-500;
38
+ background-color: colors.$primary-500;
39
39
  height: 8px;
40
40
  transition: width 125ms ease-in-out;
41
41
  }