newspack-components 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,7 +81,8 @@ class ActionCard extends _element.Component {
81
81
  hasGreyHeader,
82
82
  hasWhiteHeader,
83
83
  isPending,
84
- expandable = false
84
+ expandable = false,
85
+ isButtonEnabled = false
85
86
  } = this.props;
86
87
  const {
87
88
  expanded
@@ -163,7 +164,7 @@ class ActionCard extends _element.Component {
163
164
  isLink: true,
164
165
  children: actionText
165
166
  }) : onClick || hasInternalLink ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
166
- disabled: disabled,
167
+ disabled: disabled && !isButtonEnabled,
167
168
  isLink: true,
168
169
  href: href,
169
170
  onClick: onClick,
@@ -50,7 +50,7 @@ const TestComponent = () => {
50
50
  describe('useObjectState', () => {
51
51
  const getState = () => JSON.parse(_react2.screen.getByPlaceholderText('state').getAttribute('value'));
52
52
  beforeEach(() => {
53
- (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {}));
53
+ (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {}));
54
54
  });
55
55
  it('updates arrays', () => {
56
56
  expect(getState()).toStrictEqual(INIT_STATE);
@@ -16,7 +16,7 @@ describe('ImageUpload', () => {
16
16
  it('should render an add image button', () => {
17
17
  const {
18
18
  getByText
19
- } = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {}));
19
+ } = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {}));
20
20
  expect(getByText('Upload')).toBeInTheDocument();
21
21
  });
22
22
  it('should render replace and remove buttons if there is an image provided', () => {
@@ -27,7 +27,7 @@ describe('ImageUpload', () => {
27
27
  const {
28
28
  getByText,
29
29
  getByTestId
30
- } = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
30
+ } = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
31
31
  image: image
32
32
  }));
33
33
  expect(getByText('Remove')).toBeInTheDocument();
@@ -26,22 +26,17 @@ var _jsxRuntime = require("react/jsx-runtime");
26
26
  * External dependencies.
27
27
  */
28
28
 
29
- class Modal extends _element.Component {
30
- /**
31
- * Render.
32
- */
33
- render() {
34
- const {
35
- className,
36
- isWide,
37
- isNarrow,
38
- ...otherProps
39
- } = this.props;
40
- const classes = (0, _classnames.default)('newspack-modal', isWide && 'newspack-modal--wide', isNarrow && 'newspack-modal--narrow', className);
41
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
42
- className: classes,
43
- ...otherProps
44
- });
45
- }
29
+ function Modal({
30
+ className,
31
+ isWide,
32
+ isNarrow,
33
+ ...otherProps
34
+ }, ref) {
35
+ const classes = (0, _classnames.default)('newspack-modal', isWide && 'newspack-modal--wide', isNarrow && 'newspack-modal--narrow', className);
36
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
37
+ className: classes,
38
+ ...otherProps,
39
+ ref: ref
40
+ });
46
41
  }
47
- var _default = exports.default = Modal;
42
+ var _default = exports.default = (0, _element.forwardRef)(Modal);
@@ -11,7 +11,7 @@ describe('ProgressBar', () => {
11
11
  it('should render a progress indicator', () => {
12
12
  const {
13
13
  getByTestId
14
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
14
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
15
15
  completed: "1",
16
16
  total: "2"
17
17
  }));
@@ -22,7 +22,7 @@ describe('ProgressBar', () => {
22
22
  const label = 'test label';
23
23
  const {
24
24
  getByText
25
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
25
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
26
26
  completed: "1",
27
27
  total: "2",
28
28
  label: label
@@ -32,7 +32,7 @@ describe('ProgressBar', () => {
32
32
  it('should render progress as a fraction', () => {
33
33
  const {
34
34
  getByText
35
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
35
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
36
36
  completed: "1",
37
37
  total: "2",
38
38
  displayFraction: true
@@ -43,7 +43,7 @@ describe('ProgressBar', () => {
43
43
  const label = 'test label';
44
44
  const {
45
45
  getByText
46
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
46
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
47
47
  completed: "1",
48
48
  total: "2",
49
49
  label: label,
@@ -78,7 +78,7 @@ describe('ProgressBar', () => {
78
78
  it(`with expected progress of ${expectedWidth}`, () => {
79
79
  const {
80
80
  getByTestId
81
- } = (0, _react2.render)( /*#__PURE__*/(0, _react.createElement)(_.default, {
81
+ } = (0, _react2.render)(/*#__PURE__*/(0, _react.createElement)(_.default, {
82
82
  ...props,
83
83
  key: expectedWidth
84
84
  }));
@@ -90,7 +90,7 @@ describe('ProgressBar', () => {
90
90
  const {
91
91
  getByText,
92
92
  getByTestId
93
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
93
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
94
94
  completed: "cats",
95
95
  total: "dogs",
96
96
  displayFraction: true
@@ -102,7 +102,7 @@ describe('ProgressBar', () => {
102
102
  const {
103
103
  getByText,
104
104
  getByTestId
105
- } = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
105
+ } = (0, _react2.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {
106
106
  completed: "3",
107
107
  total: "-1",
108
108
  displayFraction: true
@@ -43,12 +43,15 @@
43
43
 
44
44
  input[type="radio"] {
45
45
  height: 24px;
46
- margin-right: 8px;
47
46
  width: 24px;
47
+ max-height: 24px;
48
+ max-width: 24px;
48
49
 
49
50
  @media screen and ( min-width: 782px ) {
50
51
  height: 20px;
51
52
  width: 20px;
53
+ max-height: 20px;
54
+ max-width: 20px;
52
55
  }
53
56
 
54
57
  &:checked {
@@ -84,7 +84,7 @@ class WebPreview extends _element.Component {
84
84
  }
85
85
  const classes = (0, _classnames.default)('newspack-web-preview', device, loaded && 'is-loaded');
86
86
  beforeLoad();
87
- return (0, _element.createPortal)( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
87
+ return (0, _element.createPortal)(/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
88
88
  className: classes,
89
89
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
90
90
  className: "newspack-web-preview__interior",
@@ -73,7 +73,8 @@ class ActionCard extends Component {
73
73
  hasGreyHeader,
74
74
  hasWhiteHeader,
75
75
  isPending,
76
- expandable = false
76
+ expandable = false,
77
+ isButtonEnabled = false
77
78
  } = this.props;
78
79
  const {
79
80
  expanded
@@ -155,7 +156,7 @@ class ActionCard extends Component {
155
156
  isLink: true,
156
157
  children: actionText
157
158
  }) : onClick || hasInternalLink ? /*#__PURE__*/_jsx(Button, {
158
- disabled: disabled,
159
+ disabled: disabled && !isButtonEnabled,
159
160
  isLink: true,
160
161
  href: href,
161
162
  onClick: onClick,
@@ -15,7 +15,7 @@ const mergeCustomizer = (objValue, srcValue) => {
15
15
  * A useState for an object.
16
16
  * Nested objects will be nested, but arrays replaced.
17
17
  */
18
- export default ((initial = {}) => {
18
+ export default (initial = {}) => {
19
19
  const [stateObject, setStateObject] = useState(initial);
20
20
  const runUpdate = update => setStateObject(_stateObject => mergeWith({}, _stateObject, update, mergeCustomizer));
21
21
  const updateStateObject = keyOrUpdate => {
@@ -27,4 +27,4 @@ export default ((initial = {}) => {
27
27
  runUpdate(keyOrUpdate);
28
28
  };
29
29
  return [stateObject, updateStateObject];
30
- });
30
+ };
@@ -47,7 +47,7 @@ const TestComponent = () => {
47
47
  describe('useObjectState', () => {
48
48
  const getState = () => JSON.parse(screen.getByPlaceholderText('state').getAttribute('value'));
49
49
  beforeEach(() => {
50
- render( /*#__PURE__*/_jsx(TestComponent, {}));
50
+ render(/*#__PURE__*/_jsx(TestComponent, {}));
51
51
  });
52
52
  it('updates arrays', () => {
53
53
  expect(getState()).toStrictEqual(INIT_STATE);
@@ -12,7 +12,7 @@ import Router from '../proxied-imports/router';
12
12
  const {
13
13
  useHistory
14
14
  } = Router;
15
- export default ((when, message) => {
15
+ export default (when, message) => {
16
16
  const history = useHistory();
17
17
  const self = useRef(null);
18
18
  const onWindowOrTabClose = event => {
@@ -37,4 +37,4 @@ export default ((when, message) => {
37
37
  };
38
38
  }, [message, when]);
39
39
  return self.current || (() => {});
40
- });
40
+ };
@@ -12,7 +12,7 @@ describe('ImageUpload', () => {
12
12
  it('should render an add image button', () => {
13
13
  const {
14
14
  getByText
15
- } = render( /*#__PURE__*/_jsx(ImageUpload, {}));
15
+ } = render(/*#__PURE__*/_jsx(ImageUpload, {}));
16
16
  expect(getByText('Upload')).toBeInTheDocument();
17
17
  });
18
18
  it('should render replace and remove buttons if there is an image provided', () => {
@@ -23,7 +23,7 @@ describe('ImageUpload', () => {
23
23
  const {
24
24
  getByText,
25
25
  getByTestId
26
- } = render( /*#__PURE__*/_jsx(ImageUpload, {
26
+ } = render(/*#__PURE__*/_jsx(ImageUpload, {
27
27
  image: image
28
28
  }));
29
29
  expect(getByText('Remove')).toBeInTheDocument();
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * WordPress dependencies.
7
7
  */
8
- import { Component } from '@wordpress/element';
8
+ import { forwardRef } from '@wordpress/element';
9
9
  import { Modal as BaseComponent } from '@wordpress/components';
10
10
 
11
11
  /**
@@ -18,22 +18,17 @@ import './style.scss';
18
18
  */
19
19
  import classnames from 'classnames';
20
20
  import { jsx as _jsx } from "react/jsx-runtime";
21
- class Modal extends Component {
22
- /**
23
- * Render.
24
- */
25
- render() {
26
- const {
27
- className,
28
- isWide,
29
- isNarrow,
30
- ...otherProps
31
- } = this.props;
32
- const classes = classnames('newspack-modal', isWide && 'newspack-modal--wide', isNarrow && 'newspack-modal--narrow', className);
33
- return /*#__PURE__*/_jsx(BaseComponent, {
34
- className: classes,
35
- ...otherProps
36
- });
37
- }
21
+ function Modal({
22
+ className,
23
+ isWide,
24
+ isNarrow,
25
+ ...otherProps
26
+ }, ref) {
27
+ const classes = classnames('newspack-modal', isWide && 'newspack-modal--wide', isNarrow && 'newspack-modal--narrow', className);
28
+ return /*#__PURE__*/_jsx(BaseComponent, {
29
+ className: classes,
30
+ ...otherProps,
31
+ ref: ref
32
+ });
38
33
  }
39
- export default Modal;
34
+ export default forwardRef(Modal);
@@ -6,7 +6,7 @@ describe('ProgressBar', () => {
6
6
  it('should render a progress indicator', () => {
7
7
  const {
8
8
  getByTestId
9
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
9
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
10
10
  completed: "1",
11
11
  total: "2"
12
12
  }));
@@ -17,7 +17,7 @@ describe('ProgressBar', () => {
17
17
  const label = 'test label';
18
18
  const {
19
19
  getByText
20
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
20
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
21
21
  completed: "1",
22
22
  total: "2",
23
23
  label: label
@@ -27,7 +27,7 @@ describe('ProgressBar', () => {
27
27
  it('should render progress as a fraction', () => {
28
28
  const {
29
29
  getByText
30
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
30
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
31
31
  completed: "1",
32
32
  total: "2",
33
33
  displayFraction: true
@@ -38,7 +38,7 @@ describe('ProgressBar', () => {
38
38
  const label = 'test label';
39
39
  const {
40
40
  getByText
41
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
41
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
42
42
  completed: "1",
43
43
  total: "2",
44
44
  label: label,
@@ -73,7 +73,7 @@ describe('ProgressBar', () => {
73
73
  it(`with expected progress of ${expectedWidth}`, () => {
74
74
  const {
75
75
  getByTestId
76
- } = render( /*#__PURE__*/_createElement(ProgressBar, {
76
+ } = render(/*#__PURE__*/_createElement(ProgressBar, {
77
77
  ...props,
78
78
  key: expectedWidth
79
79
  }));
@@ -85,7 +85,7 @@ describe('ProgressBar', () => {
85
85
  const {
86
86
  getByText,
87
87
  getByTestId
88
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
88
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
89
89
  completed: "cats",
90
90
  total: "dogs",
91
91
  displayFraction: true
@@ -97,7 +97,7 @@ describe('ProgressBar', () => {
97
97
  const {
98
98
  getByText,
99
99
  getByTestId
100
- } = render( /*#__PURE__*/_jsx(ProgressBar, {
100
+ } = render(/*#__PURE__*/_jsx(ProgressBar, {
101
101
  completed: "3",
102
102
  total: "-1",
103
103
  displayFraction: true
@@ -43,12 +43,15 @@
43
43
 
44
44
  input[type="radio"] {
45
45
  height: 24px;
46
- margin-right: 8px;
47
46
  width: 24px;
47
+ max-height: 24px;
48
+ max-width: 24px;
48
49
 
49
50
  @media screen and ( min-width: 782px ) {
50
51
  height: 20px;
51
52
  width: 20px;
53
+ max-height: 20px;
54
+ max-width: 20px;
52
55
  }
53
56
 
54
57
  &:checked {
@@ -76,7 +76,7 @@ class WebPreview extends Component {
76
76
  }
77
77
  const classes = classnames('newspack-web-preview', device, loaded && 'is-loaded');
78
78
  beforeLoad();
79
- return createPortal( /*#__PURE__*/_jsx("div", {
79
+ return createPortal(/*#__PURE__*/_jsx("div", {
80
80
  className: classes,
81
81
  children: /*#__PURE__*/_jsxs("div", {
82
82
  className: "newspack-web-preview__interior",
@@ -152,4 +152,4 @@ const store = createReduxStore(WIZARD_STORE_NAMESPACE, {
152
152
  }
153
153
  }
154
154
  });
155
- export default (() => register(store));
155
+ export default () => register(store);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newspack-components",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Newspack design system components",
5
5
  "author": "Automattic",
6
6
  "license": "GPL-2.0-or-later",
@@ -58,4 +58,4 @@
58
58
  "prepublishOnly": "npm run clean && npm run compile && node copy-styles.js",
59
59
  "postpublish": "npm run clean"
60
60
  }
61
- }
61
+ }
@@ -72,6 +72,7 @@ class ActionCard extends Component {
72
72
  hasWhiteHeader,
73
73
  isPending,
74
74
  expandable = false,
75
+ isButtonEnabled = false
75
76
  } = this.props;
76
77
 
77
78
  const { expanded } = this.state;
@@ -173,7 +174,7 @@ class ActionCard extends Component {
173
174
  </Handoff>
174
175
  ) : onClick || hasInternalLink ? (
175
176
  <Button
176
- disabled={ disabled }
177
+ disabled={ disabled && ! isButtonEnabled }
177
178
  isLink
178
179
  href={ href }
179
180
  onClick={ onClick }
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * WordPress dependencies.
7
7
  */
8
- import { Component } from '@wordpress/element';
8
+ import { forwardRef } from '@wordpress/element';
9
9
  import { Modal as BaseComponent } from '@wordpress/components';
10
10
 
11
11
  /**
@@ -18,21 +18,15 @@ import './style.scss';
18
18
  */
19
19
  import classnames from 'classnames';
20
20
 
21
- class Modal extends Component {
22
- /**
23
- * Render.
24
- */
25
- render() {
26
- const { className, isWide, isNarrow, ...otherProps } = this.props;
27
- const classes = classnames(
28
- 'newspack-modal',
29
- isWide && 'newspack-modal--wide',
30
- isNarrow && 'newspack-modal--narrow',
31
- className
32
- );
21
+ function Modal( { className, isWide, isNarrow, ...otherProps }, ref ) {
22
+ const classes = classnames(
23
+ 'newspack-modal',
24
+ isWide && 'newspack-modal--wide',
25
+ isNarrow && 'newspack-modal--narrow',
26
+ className
27
+ );
33
28
 
34
- return <BaseComponent className={ classes } { ...otherProps } />;
35
- }
36
- }
29
+ return <BaseComponent className={ classes } { ...otherProps } ref={ ref } />;
37
30
 
38
- export default Modal;
31
+ }
32
+ export default forwardRef( Modal );
@@ -43,12 +43,15 @@
43
43
 
44
44
  input[type="radio"] {
45
45
  height: 24px;
46
- margin-right: 8px;
47
46
  width: 24px;
47
+ max-height: 24px;
48
+ max-width: 24px;
48
49
 
49
50
  @media screen and ( min-width: 782px ) {
50
51
  height: 20px;
51
52
  width: 20px;
53
+ max-height: 20px;
54
+ max-width: 20px;
52
55
  }
53
56
 
54
57
  &:checked {