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

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 (227) 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/cjs/button/index.js +56 -0
  5. package/dist/cjs/grid/index.js +37 -0
  6. package/dist/cjs/hooks/index.js +25 -0
  7. package/dist/cjs/hooks/usePrompt.js +49 -0
  8. package/dist/cjs/text-control/index.js +64 -0
  9. package/dist/esm/accordion/index.js +42 -0
  10. package/dist/esm/accordion/style.scss +31 -0
  11. package/dist/esm/action-card/index.js +218 -0
  12. package/dist/esm/action-card/style.scss +483 -0
  13. package/dist/esm/autocomplete-tokenfield/index.js +261 -0
  14. package/dist/esm/autocomplete-tokenfield/style.scss +49 -0
  15. package/dist/esm/autocomplete-with-suggestions/index.js +274 -0
  16. package/dist/esm/autocomplete-with-suggestions/style.scss +163 -0
  17. package/dist/esm/button/index.js +48 -0
  18. package/dist/esm/button/style.scss +11 -0
  19. package/dist/esm/button-card/index.js +64 -0
  20. package/dist/esm/button-card/style.scss +180 -0
  21. package/dist/esm/card/index.js +43 -0
  22. package/dist/esm/card/style.scss +168 -0
  23. package/dist/esm/category-autocomplete/index.js +183 -0
  24. package/dist/esm/category-autocomplete/style.scss +34 -0
  25. package/dist/esm/color-picker/index.js +59 -0
  26. package/dist/esm/color-picker/style.scss +37 -0
  27. package/dist/esm/consts.js +1 -0
  28. package/dist/esm/custom-select-control/index.js +37 -0
  29. package/dist/esm/custom-select-control/style.scss +93 -0
  30. package/dist/esm/date-range-picker/index.js +31 -0
  31. package/dist/esm/date-range-picker/style.scss +148 -0
  32. package/dist/esm/footer/index.js +99 -0
  33. package/dist/esm/footer/style.scss +82 -0
  34. package/dist/esm/form-token-field/index.js +49 -0
  35. package/dist/esm/form-token-field/style.scss +37 -0
  36. package/dist/esm/global-notices/index.js +30 -0
  37. package/dist/esm/grid/index.js +29 -0
  38. package/dist/esm/grid/style.scss +166 -0
  39. package/dist/esm/handoff/index.js +175 -0
  40. package/dist/esm/handoff-message/index.js +47 -0
  41. package/dist/esm/hooks/index.js +17 -0
  42. package/dist/esm/hooks/useObjectState.js +30 -0
  43. package/dist/esm/hooks/useObjectState.test.js +82 -0
  44. package/dist/esm/hooks/useOnClickOutside.js +31 -0
  45. package/dist/esm/hooks/usePrompt.js +40 -0
  46. package/dist/esm/image-upload/index.js +140 -0
  47. package/dist/esm/image-upload/index.test.js +34 -0
  48. package/dist/esm/image-upload/style.scss +103 -0
  49. package/dist/esm/index.js +47 -0
  50. package/dist/esm/info-button/index.js +42 -0
  51. package/dist/esm/info-button/style.scss +18 -0
  52. package/dist/esm/modal/index.js +39 -0
  53. package/dist/esm/modal/style.scss +56 -0
  54. package/dist/esm/newspack-icon/index.js +50 -0
  55. package/dist/esm/newspack-icon/style.scss +26 -0
  56. package/dist/esm/newspack-logo/index.js +46 -0
  57. package/dist/esm/newspack-logo/style.scss +30 -0
  58. package/dist/esm/notice/index.js +65 -0
  59. package/dist/esm/notice/style.scss +111 -0
  60. package/dist/esm/patrons-logo/index.js +70 -0
  61. package/dist/esm/plugin-installer/index.js +289 -0
  62. package/dist/esm/plugin-installer/style.scss +72 -0
  63. package/dist/esm/plugin-settings/SettingsSection.js +133 -0
  64. package/dist/esm/plugin-settings/index.js +220 -0
  65. package/dist/esm/plugin-settings/style.scss +7 -0
  66. package/dist/esm/plugin-toggle/index.js +216 -0
  67. package/dist/esm/plugin-toggle/style.scss +20 -0
  68. package/dist/esm/popover/index.js +41 -0
  69. package/dist/esm/popover/style.scss +161 -0
  70. package/dist/esm/position-control/index.js +106 -0
  71. package/dist/esm/position-control/style.scss +66 -0
  72. package/dist/esm/progress-bar/index.js +68 -0
  73. package/dist/esm/progress-bar/index.test.js +108 -0
  74. package/dist/esm/progress-bar/style.scss +42 -0
  75. package/dist/esm/proxied-imports/router.js +8 -0
  76. package/dist/esm/radio-control/index.js +37 -0
  77. package/dist/esm/radio-control/style.scss +92 -0
  78. package/dist/esm/section-header/index.js +67 -0
  79. package/dist/esm/section-header/style.scss +45 -0
  80. package/dist/esm/select-control/ButtonGroupControl.js +53 -0
  81. package/dist/esm/select-control/GroupedSelectControl.js +78 -0
  82. package/dist/esm/select-control/index.js +51 -0
  83. package/dist/esm/select-control/style.scss +108 -0
  84. package/dist/esm/settings/MinMaxSetting.js +53 -0
  85. package/dist/esm/settings/SettingsCard.js +38 -0
  86. package/dist/esm/settings/SettingsSection.js +26 -0
  87. package/dist/esm/settings/index.js +9 -0
  88. package/dist/esm/settings/style.scss +119 -0
  89. package/dist/esm/sortable-newsletter-list-control/index.js +127 -0
  90. package/dist/esm/sortable-newsletter-list-control/style.scss +45 -0
  91. package/dist/esm/steps-list/index.js +43 -0
  92. package/dist/esm/steps-list/style.scss +11 -0
  93. package/dist/esm/steps-list-item/index.js +47 -0
  94. package/dist/esm/steps-list-item/style.scss +47 -0
  95. package/dist/esm/style-card/index.js +74 -0
  96. package/dist/esm/style-card/style.scss +94 -0
  97. package/dist/esm/style.scss +55 -0
  98. package/dist/esm/tabbed-navigation/index.js +53 -0
  99. package/dist/esm/tabbed-navigation/style.scss +86 -0
  100. package/dist/esm/text-control/index.js +56 -0
  101. package/dist/esm/text-control/style.scss +32 -0
  102. package/dist/esm/utils/index.js +29 -0
  103. package/dist/esm/waiting/index.js +44 -0
  104. package/dist/esm/waiting/style.scss +27 -0
  105. package/dist/esm/web-preview/index.js +183 -0
  106. package/dist/esm/web-preview/style.scss +155 -0
  107. package/dist/esm/with-wizard/index.js +320 -0
  108. package/dist/esm/with-wizard/style.scss +282 -0
  109. package/dist/esm/with-wizard-screen/index.js +109 -0
  110. package/dist/esm/with-wizard-screen/style.scss +160 -0
  111. package/dist/esm/wizard/components/WizardError.js +66 -0
  112. package/dist/esm/wizard/index.js +119 -0
  113. package/dist/esm/wizard/store/index.js +155 -0
  114. package/dist/esm/wizard/store/utils.js +14 -0
  115. package/package.json +8 -4
  116. package/dist/button/index.js +0 -51
  117. package/dist/button/index.tsx +0 -48
  118. package/dist/grid/index.js +0 -44
  119. package/dist/grid/index.tsx +0 -34
  120. package/dist/hooks/index.js +0 -29
  121. package/dist/hooks/index.ts +0 -15
  122. package/dist/hooks/usePrompt.js +0 -47
  123. package/dist/hooks/usePrompt.ts +0 -46
  124. package/dist/plugin-toggle/README.md +0 -53
  125. package/dist/text-control/index.js +0 -76
  126. package/dist/text-control/index.tsx +0 -71
  127. /package/dist/{accordion → cjs/accordion}/index.js +0 -0
  128. /package/dist/{accordion → cjs/accordion}/style.scss +0 -0
  129. /package/dist/{action-card → cjs/action-card}/index.js +0 -0
  130. /package/dist/{action-card → cjs/action-card}/style.scss +0 -0
  131. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/index.js +0 -0
  132. /package/dist/{autocomplete-tokenfield → cjs/autocomplete-tokenfield}/style.scss +0 -0
  133. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/index.js +0 -0
  134. /package/dist/{autocomplete-with-suggestions → cjs/autocomplete-with-suggestions}/style.scss +0 -0
  135. /package/dist/{button → cjs/button}/style.scss +0 -0
  136. /package/dist/{button-card → cjs/button-card}/index.js +0 -0
  137. /package/dist/{button-card → cjs/button-card}/style.scss +0 -0
  138. /package/dist/{card → cjs/card}/index.js +0 -0
  139. /package/dist/{card → cjs/card}/style.scss +0 -0
  140. /package/dist/{category-autocomplete → cjs/category-autocomplete}/index.js +0 -0
  141. /package/dist/{category-autocomplete → cjs/category-autocomplete}/style.scss +0 -0
  142. /package/dist/{color-picker → cjs/color-picker}/index.js +0 -0
  143. /package/dist/{color-picker → cjs/color-picker}/style.scss +0 -0
  144. /package/dist/{consts.js → cjs/consts.js} +0 -0
  145. /package/dist/{custom-select-control → cjs/custom-select-control}/index.js +0 -0
  146. /package/dist/{custom-select-control → cjs/custom-select-control}/style.scss +0 -0
  147. /package/dist/{date-range-picker → cjs/date-range-picker}/index.js +0 -0
  148. /package/dist/{date-range-picker → cjs/date-range-picker}/style.scss +0 -0
  149. /package/dist/{footer → cjs/footer}/index.js +0 -0
  150. /package/dist/{footer → cjs/footer}/style.scss +0 -0
  151. /package/dist/{form-token-field → cjs/form-token-field}/index.js +0 -0
  152. /package/dist/{form-token-field → cjs/form-token-field}/style.scss +0 -0
  153. /package/dist/{global-notices → cjs/global-notices}/index.js +0 -0
  154. /package/dist/{grid → cjs/grid}/style.scss +0 -0
  155. /package/dist/{handoff → cjs/handoff}/index.js +0 -0
  156. /package/dist/{handoff-message → cjs/handoff-message}/index.js +0 -0
  157. /package/dist/{hooks → cjs/hooks}/useObjectState.js +0 -0
  158. /package/dist/{hooks → cjs/hooks}/useObjectState.test.js +0 -0
  159. /package/dist/{hooks → cjs/hooks}/useOnClickOutside.js +0 -0
  160. /package/dist/{image-upload → cjs/image-upload}/index.js +0 -0
  161. /package/dist/{image-upload → cjs/image-upload}/index.test.js +0 -0
  162. /package/dist/{image-upload → cjs/image-upload}/style.scss +0 -0
  163. /package/dist/{index.js → cjs/index.js} +0 -0
  164. /package/dist/{info-button → cjs/info-button}/index.js +0 -0
  165. /package/dist/{info-button → cjs/info-button}/style.scss +0 -0
  166. /package/dist/{modal → cjs/modal}/index.js +0 -0
  167. /package/dist/{modal → cjs/modal}/style.scss +0 -0
  168. /package/dist/{newspack-icon → cjs/newspack-icon}/index.js +0 -0
  169. /package/dist/{newspack-icon → cjs/newspack-icon}/style.scss +0 -0
  170. /package/dist/{newspack-logo → cjs/newspack-logo}/index.js +0 -0
  171. /package/dist/{newspack-logo → cjs/newspack-logo}/style.scss +0 -0
  172. /package/dist/{notice → cjs/notice}/index.js +0 -0
  173. /package/dist/{notice → cjs/notice}/style.scss +0 -0
  174. /package/dist/{patrons-logo → cjs/patrons-logo}/index.js +0 -0
  175. /package/dist/{plugin-installer → cjs/plugin-installer}/index.js +0 -0
  176. /package/dist/{plugin-installer → cjs/plugin-installer}/style.scss +0 -0
  177. /package/dist/{plugin-settings → cjs/plugin-settings}/SettingsSection.js +0 -0
  178. /package/dist/{plugin-settings → cjs/plugin-settings}/index.js +0 -0
  179. /package/dist/{plugin-settings → cjs/plugin-settings}/style.scss +0 -0
  180. /package/dist/{plugin-toggle → cjs/plugin-toggle}/index.js +0 -0
  181. /package/dist/{plugin-toggle → cjs/plugin-toggle}/style.scss +0 -0
  182. /package/dist/{popover → cjs/popover}/index.js +0 -0
  183. /package/dist/{popover → cjs/popover}/style.scss +0 -0
  184. /package/dist/{position-control → cjs/position-control}/index.js +0 -0
  185. /package/dist/{position-control → cjs/position-control}/style.scss +0 -0
  186. /package/dist/{progress-bar → cjs/progress-bar}/index.js +0 -0
  187. /package/dist/{progress-bar → cjs/progress-bar}/index.test.js +0 -0
  188. /package/dist/{progress-bar → cjs/progress-bar}/style.scss +0 -0
  189. /package/dist/{proxied-imports → cjs/proxied-imports}/router.js +0 -0
  190. /package/dist/{radio-control → cjs/radio-control}/index.js +0 -0
  191. /package/dist/{radio-control → cjs/radio-control}/style.scss +0 -0
  192. /package/dist/{section-header → cjs/section-header}/index.js +0 -0
  193. /package/dist/{section-header → cjs/section-header}/style.scss +0 -0
  194. /package/dist/{select-control → cjs/select-control}/ButtonGroupControl.js +0 -0
  195. /package/dist/{select-control → cjs/select-control}/GroupedSelectControl.js +0 -0
  196. /package/dist/{select-control → cjs/select-control}/index.js +0 -0
  197. /package/dist/{select-control → cjs/select-control}/style.scss +0 -0
  198. /package/dist/{settings → cjs/settings}/MinMaxSetting.js +0 -0
  199. /package/dist/{settings → cjs/settings}/SettingsCard.js +0 -0
  200. /package/dist/{settings → cjs/settings}/SettingsSection.js +0 -0
  201. /package/dist/{settings → cjs/settings}/index.js +0 -0
  202. /package/dist/{settings → cjs/settings}/style.scss +0 -0
  203. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/index.js +0 -0
  204. /package/dist/{sortable-newsletter-list-control → cjs/sortable-newsletter-list-control}/style.scss +0 -0
  205. /package/dist/{steps-list → cjs/steps-list}/index.js +0 -0
  206. /package/dist/{steps-list → cjs/steps-list}/style.scss +0 -0
  207. /package/dist/{steps-list-item → cjs/steps-list-item}/index.js +0 -0
  208. /package/dist/{steps-list-item → cjs/steps-list-item}/style.scss +0 -0
  209. /package/dist/{style-card → cjs/style-card}/index.js +0 -0
  210. /package/dist/{style-card → cjs/style-card}/style.scss +0 -0
  211. /package/dist/{style.scss → cjs/style.scss} +0 -0
  212. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/index.js +0 -0
  213. /package/dist/{tabbed-navigation → cjs/tabbed-navigation}/style.scss +0 -0
  214. /package/dist/{text-control → cjs/text-control}/style.scss +0 -0
  215. /package/dist/{utils → cjs/utils}/index.js +0 -0
  216. /package/dist/{waiting → cjs/waiting}/index.js +0 -0
  217. /package/dist/{waiting → cjs/waiting}/style.scss +0 -0
  218. /package/dist/{web-preview → cjs/web-preview}/index.js +0 -0
  219. /package/dist/{web-preview → cjs/web-preview}/style.scss +0 -0
  220. /package/dist/{with-wizard → cjs/with-wizard}/index.js +0 -0
  221. /package/dist/{with-wizard → cjs/with-wizard}/style.scss +0 -0
  222. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/index.js +0 -0
  223. /package/dist/{with-wizard-screen → cjs/with-wizard-screen}/style.scss +0 -0
  224. /package/dist/{wizard → cjs/wizard}/components/WizardError.js +0 -0
  225. /package/dist/{wizard → cjs/wizard}/index.js +0 -0
  226. /package/dist/{wizard → cjs/wizard}/store/index.js +0 -0
  227. /package/dist/{wizard → cjs/wizard}/store/utils.js +0 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Text Control
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies
7
+ */
8
+ import { TextControl as BaseComponent } from '@wordpress/components';
9
+ import { useEffect, useRef } from '@wordpress/element';
10
+ import { __ } from '@wordpress/i18n';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import './style.scss';
16
+
17
+ /**
18
+ * External dependencies
19
+ */
20
+ import classNames from 'classnames';
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ const TextControl = ({
23
+ className = '',
24
+ required = false,
25
+ isWide = false,
26
+ withMargin = true,
27
+ ...otherProps
28
+ }) => {
29
+ const wrapperRef = useRef(null);
30
+ useEffect(() => {
31
+ if (wrapperRef.current === null) {
32
+ return;
33
+ }
34
+ const labelEl = wrapperRef.current.querySelector('label');
35
+ if (labelEl) {
36
+ labelEl.setAttribute('data-required-text', __('(required)', 'newspack-plugin'));
37
+ }
38
+ }, [wrapperRef.current]);
39
+ const classes = classNames('newspack-text-control', {
40
+ 'newspack-text-control--wide': isWide,
41
+ 'newspack-text-control--with-margin': withMargin
42
+ }, className);
43
+ return required ? /*#__PURE__*/_jsx("div", {
44
+ ref: wrapperRef,
45
+ className: "newspack-text-control--required",
46
+ children: /*#__PURE__*/_jsx(BaseComponent, {
47
+ className: classes,
48
+ required: required,
49
+ ...otherProps
50
+ })
51
+ }) : /*#__PURE__*/_jsx(BaseComponent, {
52
+ className: classes,
53
+ ...otherProps
54
+ });
55
+ };
56
+ export default TextControl;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Text Control
3
+ */
4
+
5
+ .newspack-text-control {
6
+ &--with-margin {
7
+ margin: 32px 0;
8
+ }
9
+
10
+ &--wide {
11
+ flex-wrap: wrap;
12
+ .components-base-control__field {
13
+ width: 100%;
14
+ }
15
+ }
16
+
17
+ &--required {
18
+ margin: 32px 0;
19
+
20
+ > * {
21
+ margin: 0;
22
+ }
23
+ }
24
+
25
+ // Code
26
+
27
+ &.code {
28
+ input {
29
+ font-family: Consolas, monaco, monospace;
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { ENTER } from '@wordpress/keycodes';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const InteractiveDiv = ({
7
+ style = {},
8
+ ...props
9
+ }) => /*#__PURE__*/_jsx("div", {
10
+ tabIndex: "0",
11
+ role: "button",
12
+ onKeyDown: event => ENTER === event.keyCode && props.onClick(),
13
+ style: {
14
+ cursor: 'pointer',
15
+ ...style
16
+ },
17
+ ...props
18
+ });
19
+ const confirmAction = message => {
20
+ // eslint-disable-next-line no-alert
21
+ if (confirm(message)) {
22
+ return true;
23
+ }
24
+ return false;
25
+ };
26
+ export default {
27
+ InteractiveDiv,
28
+ confirmAction
29
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Waiting
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+ import { Component } from '@wordpress/element';
9
+ import { Spinner } from '@wordpress/components';
10
+
11
+ /**
12
+ * Internal dependencies.
13
+ */
14
+ import './style.scss';
15
+
16
+ /**
17
+ * External dependencies.
18
+ */
19
+ import classnames from 'classnames';
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ class Waiting extends Component {
22
+ /**
23
+ * Render
24
+ */
25
+ render() {
26
+ const {
27
+ className,
28
+ isRight,
29
+ isLeft,
30
+ isCenter,
31
+ ...otherProps
32
+ } = this.props;
33
+ const classes = classnames('newspack-waiting', className, {
34
+ 'is-right': isRight,
35
+ 'is-left': isLeft,
36
+ 'is-center': isCenter
37
+ });
38
+ return /*#__PURE__*/_jsx(Spinner, {
39
+ className: classes,
40
+ ...otherProps
41
+ });
42
+ }
43
+ }
44
+ export default Waiting;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Waiting
3
+ */
4
+
5
+ .newspack-waiting.components-spinner {
6
+ flex: 0 0 auto;
7
+ margin: 0;
8
+
9
+ &.is-left {
10
+ margin-right: 8px;
11
+ }
12
+
13
+ &.is-right {
14
+ margin-right: 8px;
15
+ order: -1;
16
+
17
+ @media screen and ( min-width: 744px ) {
18
+ margin-left: 8px;
19
+ margin-right: 0;
20
+ order: 1;
21
+ }
22
+ }
23
+
24
+ &.is-center {
25
+ margin: auto;
26
+ }
27
+ }
@@ -0,0 +1,183 @@
1
+ /**
2
+ * WordPress dependencies.
3
+ */
4
+ import { Component, createRef, Fragment, createPortal } from '@wordpress/element';
5
+ import { __ } from '@wordpress/i18n';
6
+ import { closeSmall, desktop, mobile, tablet } from '@wordpress/icons';
7
+ import { Button, ButtonGroup } from '@wordpress/components';
8
+
9
+ /**
10
+ * Internal dependencies.
11
+ */
12
+ import { Waiting } from '../';
13
+ import './style.scss';
14
+
15
+ /**
16
+ * External dependencies.
17
+ */
18
+ import classnames from 'classnames';
19
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ const PORTAL_PARENT_ID = 'newspack-components-web-preview-wrapper';
21
+
22
+ /**
23
+ * Web Preview. A component to preview a website in an iframe, with device sizing options.
24
+ */
25
+ class WebPreview extends Component {
26
+ state = {
27
+ device: 'desktop',
28
+ loaded: false,
29
+ isPreviewVisible: false
30
+ };
31
+ constructor(props) {
32
+ super(props);
33
+ this.iframeRef = createRef();
34
+ }
35
+
36
+ /**
37
+ * If a div with id PORTAL_PARENT_ID exists, assign it to class field.
38
+ * If not, create it and append to the body.
39
+ */
40
+ componentDidMount() {
41
+ const existingDOMElement = document.getElementById(PORTAL_PARENT_ID);
42
+ this.modalDOMElement = existingDOMElement || document.createElement('div');
43
+ if (!existingDOMElement) {
44
+ this.modalDOMElement.id = PORTAL_PARENT_ID;
45
+ document.body.appendChild(this.modalDOMElement);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Add or remove applicable body classes
51
+ */
52
+ componentDidUpdate() {
53
+ if (this.state.isPreviewVisible === true) {
54
+ document.body.classList.add('newspack-web-preview--open');
55
+ } else {
56
+ document.body.classList.remove('newspack-web-preview--open');
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Create JSX for the modal
62
+ */
63
+ getWebPreviewModal = () => {
64
+ const {
65
+ beforeLoad = () => {},
66
+ onClose = () => {},
67
+ url
68
+ } = this.props;
69
+ const {
70
+ device,
71
+ loaded,
72
+ isPreviewVisible
73
+ } = this.state;
74
+ if (!this.modalDOMElement || !isPreviewVisible) {
75
+ return null;
76
+ }
77
+ const classes = classnames('newspack-web-preview', device, loaded && 'is-loaded');
78
+ beforeLoad();
79
+ return createPortal( /*#__PURE__*/_jsx("div", {
80
+ className: classes,
81
+ children: /*#__PURE__*/_jsxs("div", {
82
+ className: "newspack-web-preview__interior",
83
+ children: [/*#__PURE__*/_jsxs("div", {
84
+ className: "newspack-web-preview__toolbar",
85
+ children: [/*#__PURE__*/_jsx("div", {
86
+ className: "newspack-web-preview__toolbar-left",
87
+ children: /*#__PURE__*/_jsxs(ButtonGroup, {
88
+ children: [/*#__PURE__*/_jsx(Button, {
89
+ onClick: () => this.setState({
90
+ device: 'desktop'
91
+ }),
92
+ variant: 'desktop' === device && 'primary',
93
+ icon: desktop,
94
+ label: __('Preview Desktop Size', 'newspack-plugin')
95
+ }), /*#__PURE__*/_jsx(Button, {
96
+ onClick: () => this.setState({
97
+ device: 'tablet'
98
+ }),
99
+ variant: 'tablet' === device && 'primary',
100
+ icon: tablet,
101
+ label: __('Preview Tablet Size', 'newspack-plugin')
102
+ }), /*#__PURE__*/_jsx(Button, {
103
+ onClick: () => this.setState({
104
+ device: 'phone'
105
+ }),
106
+ variant: 'phone' === device && 'primary',
107
+ icon: mobile,
108
+ label: __('Preview Phone Size', 'newspack-plugin')
109
+ })]
110
+ })
111
+ }), /*#__PURE__*/_jsx("div", {
112
+ className: "newspack-web-preview__toolbar-right",
113
+ children: /*#__PURE__*/_jsx(Button, {
114
+ onClick: () => {
115
+ onClose();
116
+ this.setState({
117
+ isPreviewVisible: false,
118
+ loaded: false
119
+ });
120
+ },
121
+ icon: closeSmall,
122
+ label: __('Close Preview', 'newspack-plugin')
123
+ })
124
+ })]
125
+ }), /*#__PURE__*/_jsxs("div", {
126
+ className: "newspack-web-preview__content",
127
+ children: [!loaded && /*#__PURE__*/_jsxs("div", {
128
+ className: "newspack-web-preview__is-waiting",
129
+ children: [/*#__PURE__*/_jsx(Waiting, {
130
+ isLeft: true
131
+ }), __('Loading…', 'newspack-plugin')]
132
+ }), /*#__PURE__*/_jsx("iframe", {
133
+ ref: this.iframeRef,
134
+ title: "web-preview",
135
+ src: url,
136
+ onLoad: () => {
137
+ this.setState({
138
+ loaded: true
139
+ });
140
+ this.props.onLoad(this.iframeRef.current);
141
+ }
142
+ })]
143
+ })]
144
+ })
145
+ }), this.modalDOMElement);
146
+ };
147
+ showPreview = () => {
148
+ this.setState({
149
+ isPreviewVisible: true
150
+ });
151
+ };
152
+
153
+ /**
154
+ * Render.
155
+ */
156
+ render() {
157
+ const {
158
+ label,
159
+ variant,
160
+ /**
161
+ * Inversion of control - let the caller render
162
+ * the button that will trigger the modal
163
+ */
164
+ renderButton
165
+ } = this.props;
166
+ return /*#__PURE__*/_jsxs(Fragment, {
167
+ children: [renderButton ? renderButton({
168
+ showPreview: this.showPreview
169
+ }) : /*#__PURE__*/_jsx(Button, {
170
+ variant: variant,
171
+ onClick: this.showPreview,
172
+ tabIndex: "0",
173
+ children: label
174
+ }), this.getWebPreviewModal()]
175
+ });
176
+ }
177
+ }
178
+ WebPreview.defaultProps = {
179
+ url: '//newspack.com',
180
+ label: __('Preview', 'newspack-plugin'),
181
+ onLoad: () => {}
182
+ };
183
+ export default WebPreview;
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Web Preview
3
+ */
4
+
5
+ @use "../../../shared/scss/colors";
6
+ @use "~@wordpress/base-styles/colors" as wp-colors;
7
+
8
+ .newspack-web-preview {
9
+ // Color
10
+ --wp-admin-theme-color: #{colors.$primary-500};
11
+ --wp-admin-theme-color--rgb: #{colors.$primary-500--rgb};
12
+ --wp-admin-theme-color-darker-10: #{colors.$primary-600};
13
+ --wp-admin-theme-color-darker-10--rgb: #{colors.$primary-600--rgb};
14
+ --wp-admin-theme-color-darker-20: #{colors.$primary-700};
15
+ --wp-admin-theme-color-darker-20--rgb: #{colors.$primary-700--rgb};
16
+
17
+ background: rgba(black, 0.7);
18
+ box-sizing: border-box;
19
+ height: 100%;
20
+ left: 0;
21
+ margin: 0;
22
+ max-width: 100%;
23
+ padding: 32px;
24
+ position: fixed;
25
+ top: 0;
26
+ width: 100%;
27
+ z-index: 99999;
28
+
29
+ &.phone iframe {
30
+ max-width: 380px;
31
+ }
32
+
33
+ &.tablet iframe {
34
+ max-width: 768px;
35
+ }
36
+
37
+ &.is-loaded iframe {
38
+ opacity: 1;
39
+ }
40
+
41
+ &--open {
42
+ overflow: hidden;
43
+ }
44
+
45
+ &__interior {
46
+ animation: appear-animation 125ms ease-in-out;
47
+ animation-fill-mode: forwards;
48
+ background: white;
49
+ border-radius: 2px;
50
+ overflow: hidden;
51
+ height: 100%;
52
+ width: 100%;
53
+ }
54
+
55
+ &__content {
56
+ background: wp-colors.$gray-100;
57
+ height: calc(100% - 49px);
58
+ -webkit-overflow-scrolling: touch;
59
+ overflow-x: hidden;
60
+ width: 100%;
61
+
62
+ iframe {
63
+ background: #fff;
64
+ display: block;
65
+ height: 100%;
66
+ margin: 0 auto;
67
+ max-width: 100%;
68
+ opacity: 0;
69
+ outline: 1px solid wp-colors.$gray-300;
70
+ padding: 0;
71
+ pointer-events: all;
72
+ transition: max-width 125ms ease-in-out, opacity 250ms ease-in-out;
73
+ width: 100%;
74
+ }
75
+ }
76
+
77
+ &__is-waiting {
78
+ align-items: center;
79
+ display: flex;
80
+ left: 50%;
81
+ margin: -12px 0 0;
82
+ position: absolute;
83
+ top: 50%;
84
+ transform: translateX(-50%);
85
+ }
86
+
87
+ &__toolbar {
88
+ border-bottom: 1px solid wp-colors.$gray-300;
89
+ display: flex;
90
+ padding: 6px;
91
+
92
+ &-left {
93
+ flex: 0 0 auto;
94
+
95
+ .newspack-button-group {
96
+ display: flex;
97
+ margin: 0;
98
+ }
99
+
100
+ .newspack-button {
101
+ display: none;
102
+ padding: 0 !important;
103
+
104
+ &.is-selected {
105
+ background: colors.$primary-500;
106
+ color: white;
107
+
108
+ &:active,
109
+ &:focus,
110
+ &:hover {
111
+ box-shadow: none !important;
112
+ color: white;
113
+ outline: none;
114
+ }
115
+
116
+ &:focus {
117
+ box-shadow: inset 0 0 0 1px colors.$primary-500, inset 0 0 0 3px white !important;
118
+ }
119
+ }
120
+
121
+ @media screen and ( min-width: 528px ) {
122
+ &.is-phone,
123
+ &.is-tablet {
124
+ display: flex;
125
+ }
126
+ }
127
+
128
+ @media screen and ( min-width: 816px ) {
129
+ &.is-desktop {
130
+ display: flex;
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ &-right {
137
+ display: flex;
138
+ flex: 1;
139
+ justify-content: flex-end;
140
+ }
141
+
142
+ .newspack-button {
143
+ border-radius: 0 !important;
144
+ }
145
+ }
146
+ }
147
+
148
+ @keyframes appear-animation {
149
+ from {
150
+ margin-top: 32px;
151
+ }
152
+ to {
153
+ margin-top: 0;
154
+ }
155
+ }