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

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 (217) hide show
  1. package/babel.config.cjs.js +26 -0
  2. package/babel.config.js +1 -0
  3. package/copy-styles.js +10 -2
  4. package/dist/esm/accordion/index.js +42 -0
  5. package/dist/esm/accordion/style.scss +31 -0
  6. package/dist/esm/action-card/index.js +218 -0
  7. package/dist/esm/action-card/style.scss +483 -0
  8. package/dist/esm/autocomplete-tokenfield/index.js +261 -0
  9. package/dist/esm/autocomplete-tokenfield/style.scss +49 -0
  10. package/dist/esm/autocomplete-with-suggestions/index.js +274 -0
  11. package/dist/esm/autocomplete-with-suggestions/style.scss +163 -0
  12. package/dist/esm/button/style.scss +11 -0
  13. package/dist/esm/button-card/index.js +64 -0
  14. package/dist/esm/button-card/style.scss +180 -0
  15. package/dist/esm/card/index.js +43 -0
  16. package/dist/esm/card/style.scss +168 -0
  17. package/dist/esm/category-autocomplete/index.js +183 -0
  18. package/dist/esm/category-autocomplete/style.scss +34 -0
  19. package/dist/esm/color-picker/index.js +59 -0
  20. package/dist/esm/color-picker/style.scss +37 -0
  21. package/dist/esm/consts.js +1 -0
  22. package/dist/esm/custom-select-control/index.js +37 -0
  23. package/dist/esm/custom-select-control/style.scss +93 -0
  24. package/dist/esm/date-range-picker/index.js +31 -0
  25. package/dist/esm/date-range-picker/style.scss +148 -0
  26. package/dist/esm/footer/index.js +99 -0
  27. package/dist/esm/footer/style.scss +82 -0
  28. package/dist/esm/form-token-field/index.js +49 -0
  29. package/dist/esm/form-token-field/style.scss +37 -0
  30. package/dist/esm/global-notices/index.js +30 -0
  31. package/dist/esm/grid/style.scss +166 -0
  32. package/dist/esm/handoff/index.js +175 -0
  33. package/dist/esm/handoff-message/index.js +47 -0
  34. package/dist/esm/hooks/useObjectState.js +30 -0
  35. package/dist/esm/hooks/useObjectState.test.js +82 -0
  36. package/dist/esm/hooks/useOnClickOutside.js +31 -0
  37. package/dist/esm/image-upload/index.js +140 -0
  38. package/dist/esm/image-upload/index.test.js +34 -0
  39. package/dist/esm/image-upload/style.scss +103 -0
  40. package/dist/esm/index.js +47 -0
  41. package/dist/esm/info-button/index.js +42 -0
  42. package/dist/esm/info-button/style.scss +18 -0
  43. package/dist/esm/modal/index.js +39 -0
  44. package/dist/esm/modal/style.scss +56 -0
  45. package/dist/esm/newspack-icon/index.js +50 -0
  46. package/dist/esm/newspack-icon/style.scss +26 -0
  47. package/dist/esm/newspack-logo/index.js +46 -0
  48. package/dist/esm/newspack-logo/style.scss +30 -0
  49. package/dist/esm/notice/index.js +65 -0
  50. package/dist/esm/notice/style.scss +111 -0
  51. package/dist/esm/patrons-logo/index.js +70 -0
  52. package/dist/esm/plugin-installer/index.js +289 -0
  53. package/dist/esm/plugin-installer/style.scss +72 -0
  54. package/dist/esm/plugin-settings/SettingsSection.js +133 -0
  55. package/dist/esm/plugin-settings/index.js +220 -0
  56. package/dist/esm/plugin-settings/style.scss +7 -0
  57. package/dist/esm/plugin-toggle/index.js +216 -0
  58. package/dist/esm/plugin-toggle/style.scss +20 -0
  59. package/dist/esm/popover/index.js +41 -0
  60. package/dist/esm/popover/style.scss +161 -0
  61. package/dist/esm/position-control/index.js +106 -0
  62. package/dist/esm/position-control/style.scss +66 -0
  63. package/dist/esm/progress-bar/index.js +68 -0
  64. package/dist/esm/progress-bar/index.test.js +108 -0
  65. package/dist/esm/progress-bar/style.scss +42 -0
  66. package/dist/esm/proxied-imports/router.js +8 -0
  67. package/dist/esm/radio-control/index.js +37 -0
  68. package/dist/esm/radio-control/style.scss +92 -0
  69. package/dist/esm/section-header/index.js +67 -0
  70. package/dist/esm/section-header/style.scss +45 -0
  71. package/dist/esm/select-control/ButtonGroupControl.js +53 -0
  72. package/dist/esm/select-control/GroupedSelectControl.js +78 -0
  73. package/dist/esm/select-control/index.js +51 -0
  74. package/dist/esm/select-control/style.scss +108 -0
  75. package/dist/esm/settings/MinMaxSetting.js +53 -0
  76. package/dist/esm/settings/SettingsCard.js +38 -0
  77. package/dist/esm/settings/SettingsSection.js +26 -0
  78. package/dist/esm/settings/index.js +9 -0
  79. package/dist/esm/settings/style.scss +119 -0
  80. package/dist/esm/sortable-newsletter-list-control/index.js +127 -0
  81. package/dist/esm/sortable-newsletter-list-control/style.scss +45 -0
  82. package/dist/esm/steps-list/index.js +43 -0
  83. package/dist/esm/steps-list/style.scss +11 -0
  84. package/dist/esm/steps-list-item/index.js +47 -0
  85. package/dist/esm/steps-list-item/style.scss +47 -0
  86. package/dist/esm/style-card/index.js +74 -0
  87. package/dist/esm/style-card/style.scss +94 -0
  88. package/dist/esm/style.scss +55 -0
  89. package/dist/esm/tabbed-navigation/index.js +53 -0
  90. package/dist/esm/tabbed-navigation/style.scss +86 -0
  91. package/dist/esm/text-control/style.scss +32 -0
  92. package/dist/esm/utils/index.js +29 -0
  93. package/dist/esm/waiting/index.js +44 -0
  94. package/dist/esm/waiting/style.scss +27 -0
  95. package/dist/esm/web-preview/index.js +183 -0
  96. package/dist/esm/web-preview/style.scss +155 -0
  97. package/dist/esm/with-wizard/index.js +320 -0
  98. package/dist/esm/with-wizard/style.scss +282 -0
  99. package/dist/esm/with-wizard-screen/index.js +109 -0
  100. package/dist/esm/with-wizard-screen/style.scss +160 -0
  101. package/dist/esm/wizard/components/WizardError.js +66 -0
  102. package/dist/esm/wizard/index.js +119 -0
  103. package/dist/esm/wizard/store/index.js +155 -0
  104. package/dist/esm/wizard/store/utils.js +14 -0
  105. package/package.json +7 -4
  106. package/dist/button/index.js +0 -51
  107. package/dist/button/index.tsx +0 -48
  108. package/dist/grid/index.js +0 -44
  109. package/dist/grid/index.tsx +0 -34
  110. package/dist/hooks/index.js +0 -29
  111. package/dist/hooks/index.ts +0 -15
  112. package/dist/hooks/usePrompt.js +0 -47
  113. package/dist/hooks/usePrompt.ts +0 -46
  114. package/dist/plugin-toggle/README.md +0 -53
  115. package/dist/text-control/index.js +0 -76
  116. package/dist/text-control/index.tsx +0 -71
  117. /package/dist/{accordion → cjs/accordion}/index.js +0 -0
  118. /package/dist/{accordion → cjs/accordion}/style.scss +0 -0
  119. /package/dist/{action-card → cjs/action-card}/index.js +0 -0
  120. /package/dist/{action-card → cjs/action-card}/style.scss +0 -0
  121. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/index.js +0 -0
  122. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/style.scss +0 -0
  123. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/index.js +0 -0
  124. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/style.scss +0 -0
  125. /package/dist/{button → cjs/button}/style.scss +0 -0
  126. /package/dist/{button-card → cjs/button-card}/index.js +0 -0
  127. /package/dist/{button-card → cjs/button-card}/style.scss +0 -0
  128. /package/dist/{card → cjs/card}/index.js +0 -0
  129. /package/dist/{card → cjs/card}/style.scss +0 -0
  130. /package/dist/{category-autocomplete → cjs/category-autocomplete}/index.js +0 -0
  131. /package/dist/{category-autocomplete → cjs/category-autocomplete}/style.scss +0 -0
  132. /package/dist/{color-picker → cjs/color-picker}/index.js +0 -0
  133. /package/dist/{color-picker → cjs/color-picker}/style.scss +0 -0
  134. /package/dist/{consts.js → cjs/consts.js} +0 -0
  135. /package/dist/{custom-select-control → cjs/custom-select-control}/index.js +0 -0
  136. /package/dist/{custom-select-control → cjs/custom-select-control}/style.scss +0 -0
  137. /package/dist/{date-range-picker → cjs/date-range-picker}/index.js +0 -0
  138. /package/dist/{date-range-picker → cjs/date-range-picker}/style.scss +0 -0
  139. /package/dist/{footer → cjs/footer}/index.js +0 -0
  140. /package/dist/{footer → cjs/footer}/style.scss +0 -0
  141. /package/dist/{form-token-field → cjs/form-token-field}/index.js +0 -0
  142. /package/dist/{form-token-field → cjs/form-token-field}/style.scss +0 -0
  143. /package/dist/{global-notices → cjs/global-notices}/index.js +0 -0
  144. /package/dist/{grid → cjs/grid}/style.scss +0 -0
  145. /package/dist/{handoff → cjs/handoff}/index.js +0 -0
  146. /package/dist/{handoff-message → cjs/handoff-message}/index.js +0 -0
  147. /package/dist/{hooks → cjs/hooks}/useObjectState.js +0 -0
  148. /package/dist/{hooks → cjs/hooks}/useObjectState.test.js +0 -0
  149. /package/dist/{hooks → cjs/hooks}/useOnClickOutside.js +0 -0
  150. /package/dist/{image-upload → cjs/image-upload}/index.js +0 -0
  151. /package/dist/{image-upload → cjs/image-upload}/index.test.js +0 -0
  152. /package/dist/{image-upload → cjs/image-upload}/style.scss +0 -0
  153. /package/dist/{index.js → cjs/index.js} +0 -0
  154. /package/dist/{info-button → cjs/info-button}/index.js +0 -0
  155. /package/dist/{info-button → cjs/info-button}/style.scss +0 -0
  156. /package/dist/{modal → cjs/modal}/index.js +0 -0
  157. /package/dist/{modal → cjs/modal}/style.scss +0 -0
  158. /package/dist/{newspack-icon → cjs/newspack-icon}/index.js +0 -0
  159. /package/dist/{newspack-icon → cjs/newspack-icon}/style.scss +0 -0
  160. /package/dist/{newspack-logo → cjs/newspack-logo}/index.js +0 -0
  161. /package/dist/{newspack-logo → cjs/newspack-logo}/style.scss +0 -0
  162. /package/dist/{notice → cjs/notice}/index.js +0 -0
  163. /package/dist/{notice → cjs/notice}/style.scss +0 -0
  164. /package/dist/{patrons-logo → cjs/patrons-logo}/index.js +0 -0
  165. /package/dist/{plugin-installer → cjs/plugin-installer}/index.js +0 -0
  166. /package/dist/{plugin-installer → cjs/plugin-installer}/style.scss +0 -0
  167. /package/dist/{plugin-settings → cjs/plugin-settings}/SettingsSection.js +0 -0
  168. /package/dist/{plugin-settings → cjs/plugin-settings}/index.js +0 -0
  169. /package/dist/{plugin-settings → cjs/plugin-settings}/style.scss +0 -0
  170. /package/dist/{plugin-toggle → cjs/plugin-toggle}/index.js +0 -0
  171. /package/dist/{plugin-toggle → cjs/plugin-toggle}/style.scss +0 -0
  172. /package/dist/{popover → cjs/popover}/index.js +0 -0
  173. /package/dist/{popover → cjs/popover}/style.scss +0 -0
  174. /package/dist/{position-control → cjs/position-control}/index.js +0 -0
  175. /package/dist/{position-control → cjs/position-control}/style.scss +0 -0
  176. /package/dist/{progress-bar → cjs/progress-bar}/index.js +0 -0
  177. /package/dist/{progress-bar → cjs/progress-bar}/index.test.js +0 -0
  178. /package/dist/{progress-bar → cjs/progress-bar}/style.scss +0 -0
  179. /package/dist/{proxied-imports → cjs/proxied-imports}/router.js +0 -0
  180. /package/dist/{radio-control → cjs/radio-control}/index.js +0 -0
  181. /package/dist/{radio-control → cjs/radio-control}/style.scss +0 -0
  182. /package/dist/{section-header → cjs/section-header}/index.js +0 -0
  183. /package/dist/{section-header → cjs/section-header}/style.scss +0 -0
  184. /package/dist/{select-control → cjs/select-control}/ButtonGroupControl.js +0 -0
  185. /package/dist/{select-control → cjs/select-control}/GroupedSelectControl.js +0 -0
  186. /package/dist/{select-control → cjs/select-control}/index.js +0 -0
  187. /package/dist/{select-control → cjs/select-control}/style.scss +0 -0
  188. /package/dist/{settings → cjs/settings}/MinMaxSetting.js +0 -0
  189. /package/dist/{settings → cjs/settings}/SettingsCard.js +0 -0
  190. /package/dist/{settings → cjs/settings}/SettingsSection.js +0 -0
  191. /package/dist/{settings → cjs/settings}/index.js +0 -0
  192. /package/dist/{settings → cjs/settings}/style.scss +0 -0
  193. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/index.js +0 -0
  194. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/style.scss +0 -0
  195. /package/dist/{steps-list → cjs/steps-list}/index.js +0 -0
  196. /package/dist/{steps-list → cjs/steps-list}/style.scss +0 -0
  197. /package/dist/{steps-list-item → cjs/steps-list-item}/index.js +0 -0
  198. /package/dist/{steps-list-item → cjs/steps-list-item}/style.scss +0 -0
  199. /package/dist/{style-card → cjs/style-card}/index.js +0 -0
  200. /package/dist/{style-card → cjs/style-card}/style.scss +0 -0
  201. /package/dist/{style.scss → cjs/style.scss} +0 -0
  202. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/index.js +0 -0
  203. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/style.scss +0 -0
  204. /package/dist/{text-control → cjs/text-control}/style.scss +0 -0
  205. /package/dist/{utils → cjs/utils}/index.js +0 -0
  206. /package/dist/{waiting → cjs/waiting}/index.js +0 -0
  207. /package/dist/{waiting → cjs/waiting}/style.scss +0 -0
  208. /package/dist/{web-preview → cjs/web-preview}/index.js +0 -0
  209. /package/dist/{web-preview → cjs/web-preview}/style.scss +0 -0
  210. /package/dist/{with-wizard → cjs/with-wizard}/index.js +0 -0
  211. /package/dist/{with-wizard → cjs/with-wizard}/style.scss +0 -0
  212. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/index.js +0 -0
  213. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/style.scss +0 -0
  214. /package/dist/{wizard → cjs/wizard}/components/WizardError.js +0 -0
  215. /package/dist/{wizard → cjs/wizard}/index.js +0 -0
  216. /package/dist/{wizard → cjs/wizard}/store/index.js +0 -0
  217. /package/dist/{wizard → cjs/wizard}/store/utils.js +0 -0
@@ -0,0 +1,106 @@
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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 = size === 'full-width' ? [{
30
+ value: 'top',
31
+ /* translators: Overlay Position */
32
+ label: __('Top', 'newspack-plugin')
33
+ }, {
34
+ value: 'center',
35
+ /* translators: Overlay Position */
36
+ label: __('Center', 'newspack-plugin')
37
+ }, {
38
+ value: 'bottom',
39
+ /* translators: Overlay Position */
40
+ label: __('Bottom', 'newspack-plugin')
41
+ }] : [{
42
+ value: 'top_left',
43
+ /* translators: Overlay Position */
44
+ label: __('Top Left', 'newspack-plugin')
45
+ }, {
46
+ value: 'top',
47
+ /* translators: Overlay Position */
48
+ label: __('Top Center', 'newspack-plugin')
49
+ }, {
50
+ value: 'top_right',
51
+ /* translators: Overlay Position */
52
+ label: __('Top Right', 'newspack-plugin')
53
+ }, {
54
+ value: 'center_left',
55
+ /* translators: Overlay Position */
56
+ label: __('Center Left', 'newspack-plugin')
57
+ }, {
58
+ value: 'center',
59
+ /* translators: Overlay Position */
60
+ label: __('Center', 'newspack-plugin')
61
+ }, {
62
+ value: 'center_right',
63
+ /* translators: Overlay Position */
64
+ label: __('Center Right', 'newspack-plugin')
65
+ }, {
66
+ value: 'bottom_left',
67
+ /* translators: Overlay Position */
68
+ label: __('Bottom Left', 'newspack-plugin')
69
+ }, {
70
+ value: 'bottom',
71
+ /* translators: Overlay Position */
72
+ label: __('Bottom Center', 'newspack-plugin')
73
+ }, {
74
+ value: 'bottom_right',
75
+ /* translators: Overlay Position */
76
+ label: __('Bottom Right', 'newspack-plugin')
77
+ }];
78
+ return /*#__PURE__*/_jsxs("div", {
79
+ className: classnames('newspack-position-placement-control', 'size-' + size),
80
+ children: [/*#__PURE__*/_jsx("p", {
81
+ className: "components-base-control__label",
82
+ children: label
83
+ }), /*#__PURE__*/_jsx(ButtonGroup, {
84
+ "aria-label": __('Select Position', 'newspack-plugin'),
85
+ ...props,
86
+ children: options.map((option, index) => {
87
+ return /*#__PURE__*/_jsx("div", {
88
+ className: option.value === value ? 'is-selected' : null,
89
+ children: /*#__PURE__*/_jsx(Button, {
90
+ isSmall: true,
91
+ title: option.label,
92
+ "aria-label": option.label,
93
+ isPrimary: option.value === value,
94
+ onClick: () => {
95
+ onChange(option.value);
96
+ },
97
+ disabled: allowedPositions?.length && !allowedPositions.includes(option.value)
98
+ })
99
+ }, `newspack-position-placement-item-${index}`);
100
+ })
101
+ }), /*#__PURE__*/_jsx("p", {
102
+ className: "components-base-control__help",
103
+ children: help
104
+ })]
105
+ });
106
+ }
@@ -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
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Progress Bar
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+ import { Component } from '@wordpress/element';
9
+
10
+ /**
11
+ * Internal dependencies.
12
+ */
13
+ import './style.scss';
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
+ class ProgressBar extends Component {
16
+ /**
17
+ * Get completion as a percentage.
18
+ *
19
+ * @param {number} completed The number of steps completed.
20
+ * @param {number} total The total number of steps.
21
+ * @return {number} completion percentage
22
+ */
23
+ getCompletionPercentage(completed, total) {
24
+ if (!total) {
25
+ return 100;
26
+ }
27
+ return Math.max(Math.min(Math.round(completed / total * 100), 100), 0);
28
+ }
29
+
30
+ /**
31
+ * Render.
32
+ */
33
+ render() {
34
+ const {
35
+ label,
36
+ completed,
37
+ total,
38
+ displayFraction
39
+ } = this.props;
40
+ const cleanTotal = Math.max(0, parseInt(total) || 0);
41
+ const cleanCompleted = Math.max(0, Math.min(parseInt(completed) || 0, parseInt(cleanTotal)));
42
+ const barStyle = {
43
+ width: this.getCompletionPercentage(cleanCompleted, cleanTotal) + '%'
44
+ };
45
+ return /*#__PURE__*/_jsxs("div", {
46
+ className: "newspack-progress-bar",
47
+ children: [(label || displayFraction) && /*#__PURE__*/_jsxs("div", {
48
+ className: "newspack-progress-bar__headings",
49
+ children: [label && /*#__PURE__*/_jsx("h2", {
50
+ children: label
51
+ }), displayFraction && /*#__PURE__*/_jsx("p", {
52
+ className: "is-dark",
53
+ children: /*#__PURE__*/_jsxs("strong", {
54
+ children: [cleanCompleted, "/", cleanTotal]
55
+ })
56
+ })]
57
+ }), /*#__PURE__*/_jsx("div", {
58
+ className: "newspack-progress-bar__container",
59
+ children: /*#__PURE__*/_jsx("div", {
60
+ className: "newspack-progress-bar__bar",
61
+ style: barStyle,
62
+ "data-testid": "progress-bar-indicator"
63
+ })
64
+ })]
65
+ });
66
+ }
67
+ }
68
+ export default ProgressBar;
@@ -0,0 +1,108 @@
1
+ import React, { createElement as _createElement } from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import ProgressBar from './';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ describe('ProgressBar', () => {
6
+ it('should render a progress indicator', () => {
7
+ const {
8
+ getByTestId
9
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
10
+ completed: "1",
11
+ total: "2"
12
+ }));
13
+ const indicator = getByTestId('progress-bar-indicator');
14
+ expect(indicator).toHaveAttribute('style', 'width: 50%;');
15
+ });
16
+ it('should render a label', () => {
17
+ const label = 'test label';
18
+ const {
19
+ getByText
20
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
21
+ completed: "1",
22
+ total: "2",
23
+ label: label
24
+ }));
25
+ expect(getByText(label)).toBeInTheDocument();
26
+ });
27
+ it('should render progress as a fraction', () => {
28
+ const {
29
+ getByText
30
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
31
+ completed: "1",
32
+ total: "2",
33
+ displayFraction: true
34
+ }));
35
+ expect(getByText('1/2')).toBeInTheDocument();
36
+ });
37
+ it('should render with both label and fraction', () => {
38
+ const label = 'test label';
39
+ const {
40
+ getByText
41
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
42
+ completed: "1",
43
+ total: "2",
44
+ label: label,
45
+ displayFraction: true
46
+ }));
47
+ expect(getByText(label)).toBeInTheDocument();
48
+ expect(getByText('1/2')).toBeInTheDocument();
49
+ });
50
+ describe('should calculate progress correctly', () => {
51
+ [{
52
+ props: {
53
+ completed: 1,
54
+ total: 2
55
+ },
56
+ expectedWidth: 50
57
+ }, {
58
+ props: {
59
+ completed: 2,
60
+ total: 3
61
+ },
62
+ expectedWidth: 67
63
+ }, {
64
+ props: {
65
+ completed: 6,
66
+ total: 3
67
+ },
68
+ expectedWidth: 100
69
+ }].forEach(({
70
+ props,
71
+ expectedWidth
72
+ }) => {
73
+ it(`with expected progress of ${expectedWidth}`, () => {
74
+ const {
75
+ getByTestId
76
+ } = render( /*#__PURE__*/_createElement(ProgressBar, {
77
+ ...props,
78
+ key: expectedWidth
79
+ }));
80
+ expect(getByTestId('progress-bar-indicator')).toHaveAttribute('style', `width: ${expectedWidth}%;`);
81
+ });
82
+ });
83
+ });
84
+ it('should handle non-numeric values in ProgressBar element', () => {
85
+ const {
86
+ getByText,
87
+ getByTestId
88
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
89
+ completed: "cats",
90
+ total: "dogs",
91
+ displayFraction: true
92
+ }));
93
+ expect(getByText('0/0')).toBeInTheDocument();
94
+ expect(getByTestId('progress-bar-indicator')).toHaveAttribute('style', 'width: 100%;');
95
+ });
96
+ it('should handle non-logical values in ProgressBar element', () => {
97
+ const {
98
+ getByText,
99
+ getByTestId
100
+ } = render( /*#__PURE__*/_jsx(ProgressBar, {
101
+ completed: "3",
102
+ total: "-1",
103
+ displayFraction: true
104
+ }));
105
+ expect(getByText('0/0')).toBeInTheDocument();
106
+ expect(getByTestId('progress-bar-indicator')).toHaveAttribute('style', 'width: 100%;');
107
+ });
108
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Progress Bar
3
+ */
4
+
5
+ @use "../../../shared/scss/colors";
6
+ @use "~@wordpress/base-styles/colors" as wp-colors;
7
+
8
+ .newspack-progress-bar {
9
+ margin: 32px 0;
10
+
11
+ & &__headings {
12
+ align-items: center;
13
+ display: flex;
14
+ justify-content: space-between;
15
+ margin-bottom: 8px;
16
+
17
+ h2,
18
+ p {
19
+ margin-bottom: 0;
20
+ margin-top: 0;
21
+ }
22
+
23
+ p {
24
+ margin-left: auto;
25
+ }
26
+ }
27
+
28
+ &__container {
29
+ background-color: wp-colors.$gray-100;
30
+ border-radius: 4px;
31
+ height: 8px;
32
+ overflow: hidden;
33
+ position: relative;
34
+ z-index: 1;
35
+ }
36
+
37
+ &__bar {
38
+ background-color: colors.$primary-500;
39
+ height: 8px;
40
+ transition: width 125ms ease-in-out;
41
+ }
42
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A proxy for react-router-dom.
3
+ * Ensures that both components and the plugin use the same instance of
4
+ * React Router, even if there are node_modules in components.
5
+ */
6
+
7
+ import * as ReactRouterDOM from 'react-router-dom';
8
+ export default ReactRouterDOM;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { RadioControl as BaseComponent } from '@wordpress/components';
5
+ import { Component } from '@wordpress/element';
6
+
7
+ /**
8
+ * Internal dependencies.
9
+ */
10
+ import './style.scss';
11
+
12
+ /**
13
+ * External dependencies.
14
+ */
15
+ import classnames from 'classnames';
16
+
17
+ /**
18
+ * Radio Control.
19
+ */
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ class RadioControl extends Component {
22
+ /**
23
+ * Render.
24
+ */
25
+ render() {
26
+ const {
27
+ className,
28
+ ...otherProps
29
+ } = this.props;
30
+ const classes = classnames('newspack-radio-control', className);
31
+ return /*#__PURE__*/_jsx(BaseComponent, {
32
+ className: classes,
33
+ ...otherProps
34
+ });
35
+ }
36
+ }
37
+ export default RadioControl;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Radio Control
3
+ */
4
+
5
+ @use "../../../shared/scss/colors";
6
+ @use "~@wordpress/base-styles/colors" as wp-colors;
7
+
8
+ .newspack-radio-control {
9
+ color: wp-colors.$gray-700;
10
+ font-size: 14px;
11
+ line-height: 24px;
12
+ margin: 32px 0;
13
+
14
+ label {
15
+ color: inherit;
16
+ font-size: 14px;
17
+ line-height: 24px;
18
+ margin: 0;
19
+ }
20
+
21
+ .components-base-control__label {
22
+ color: wp-colors.$gray-900;
23
+ font-weight: bold;
24
+ }
25
+
26
+ // Options
27
+
28
+ .components-radio-control__option {
29
+ align-items: center;
30
+ display: flex;
31
+ margin: 0 0 8px;
32
+
33
+ &:first-of-type {
34
+ margin-top: 8px;
35
+ }
36
+
37
+ &:last-child {
38
+ margin-bottom: 0;
39
+ }
40
+ }
41
+
42
+ // Radio
43
+
44
+ input[type="radio"] {
45
+ height: 24px;
46
+ margin-right: 8px;
47
+ width: 24px;
48
+
49
+ @media screen and ( min-width: 782px ) {
50
+ height: 20px;
51
+ width: 20px;
52
+ }
53
+
54
+ &:checked {
55
+ background-color: colors.$primary-500;
56
+ border-color: colors.$primary-500;
57
+
58
+ &::before {
59
+ border: none;
60
+ }
61
+ }
62
+
63
+ &:focus {
64
+ border-color: colors.$primary-500;
65
+ box-shadow: 0 0 0 2px white, 0 0 0 3.5px colors.$primary-500;
66
+ }
67
+ }
68
+
69
+ // Multiple Radio Controls
70
+
71
+ & + & {
72
+ margin-bottom: 32px;
73
+ margin-top: -16px;
74
+ }
75
+
76
+ // Multiple Controls
77
+
78
+ + .newspack-select-control,
79
+ + .newspack-text-control {
80
+ margin-bottom: 32px;
81
+ margin-top: -16px;
82
+ }
83
+
84
+ // Reset
85
+
86
+ .components-base-control__field,
87
+ .components-base-control__label,
88
+ .components-base-control__help {
89
+ display: block;
90
+ margin: 0;
91
+ }
92
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Section Header
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies
7
+ */
8
+ import { useEffect, useRef } from '@wordpress/element';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import { Grid } from '..';
14
+ import './style.scss';
15
+
16
+ /**
17
+ * External dependencies
18
+ */
19
+ import classnames from 'classnames';
20
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
+ const SectionHeader = ({
22
+ centered = false,
23
+ className = null,
24
+ description = '',
25
+ heading = 2,
26
+ isWhite = false,
27
+ noMargin = false,
28
+ title,
29
+ id = null
30
+ }) => {
31
+ // If id is in the URL as a scrollTo param, scroll to it on render.
32
+ const ref = useRef();
33
+ useEffect(() => {
34
+ const params = new Proxy(new URLSearchParams(window.location.search), {
35
+ get: (searchParams, prop) => searchParams.get(prop)
36
+ });
37
+ const scrollToId = params.scrollTo;
38
+ if (scrollToId && scrollToId === id) {
39
+ // Let parent scroll action run before running this.
40
+ window.setTimeout(() => ref.current.scrollIntoView({
41
+ behavior: 'smooth'
42
+ }), 250);
43
+ }
44
+ }, []);
45
+ const classes = classnames('newspack-section-header', centered && 'newspack-section-header--is-centered', isWhite && 'newspack-section-header--is-white', noMargin && 'newspack-section-header--no-margin', className);
46
+ const HeadingTag = `h${heading}`;
47
+ return /*#__PURE__*/_jsx("div", {
48
+ id: id,
49
+ className: "newspack-section-header__container",
50
+ ref: ref,
51
+ children: /*#__PURE__*/_jsxs(Grid, {
52
+ columns: 1,
53
+ gutter: 8,
54
+ className: classes,
55
+ children: [typeof title === 'string' && /*#__PURE__*/_jsx(HeadingTag, {
56
+ children: title
57
+ }), typeof title === 'function' && /*#__PURE__*/_jsx(HeadingTag, {
58
+ children: title()
59
+ }), description && typeof description === 'string' && /*#__PURE__*/_jsx("p", {
60
+ children: description
61
+ }), typeof description === 'function' && /*#__PURE__*/_jsx("p", {
62
+ children: description()
63
+ })]
64
+ })
65
+ });
66
+ };
67
+ export default SectionHeader;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Section Header
3
+ */
4
+
5
+ @use "~@wordpress/base-styles/colors" as wp-colors;
6
+
7
+ .newspack-section-header {
8
+ margin: 64px 0 32px;
9
+
10
+ &__container:not(:first-child) {
11
+ margin-top: 48px;
12
+ }
13
+
14
+ &--no-margin,
15
+ h1,
16
+ h2,
17
+ h3,
18
+ h4,
19
+ h5,
20
+ h6 {
21
+ margin: 0 !important;
22
+ }
23
+
24
+ &--is-centered {
25
+ text-align: center;
26
+ }
27
+
28
+ &:not( #{&}--no-margin ) + *:not( #{&} ) {
29
+ margin-top: -16px !important;
30
+ }
31
+
32
+ &#{&}--is-white {
33
+ > * {
34
+ color: white;
35
+ }
36
+ }
37
+
38
+ p {
39
+ color: wp-colors.$gray-700;
40
+ }
41
+
42
+ .newspack-wizard__content &:first-child {
43
+ margin-top: 32px;
44
+ }
45
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Icon } from '@wordpress/icons';
10
+ import { BaseControl, Button, ButtonGroup } from '@wordpress/components';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { hooks } from '..';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ const ButtonGroupControl = ({
18
+ buttonOptions,
19
+ buttonSmall,
20
+ className,
21
+ hideLabelFromVision,
22
+ label,
23
+ onChange,
24
+ value
25
+ }) => {
26
+ const id = hooks.useUniqueId('button-group');
27
+ return /*#__PURE__*/_jsx(BaseControl, {
28
+ label: label,
29
+ hideLabelFromVision: hideLabelFromVision,
30
+ id: id.current,
31
+ className: classnames(className, 'components-select-control'),
32
+ children: /*#__PURE__*/_jsx(ButtonGroup, {
33
+ children: buttonOptions.map(option => {
34
+ const isSelected = value === option.value;
35
+ let Label = () => option.label;
36
+ if (option.icon) {
37
+ // eslint-disable-next-line react/display-name
38
+ Label = () => /*#__PURE__*/_jsx(Icon, {
39
+ icon: option.icon
40
+ });
41
+ }
42
+ return /*#__PURE__*/_jsx(Button, {
43
+ variant: isSelected ? 'primary' : null,
44
+ isPressed: isSelected,
45
+ onClick: () => onChange(option.value),
46
+ isSmall: buttonSmall,
47
+ children: /*#__PURE__*/_jsx(Label, {})
48
+ }, option.value);
49
+ })
50
+ })
51
+ });
52
+ };
53
+ export default ButtonGroupControl;