newspack-components 4.6.2 → 4.7.0-alpha.1

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 (148) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/colors/colors.module.scss +13 -7
  3. package/dist/cjs/autocomplete-tokenfield/style.scss +4 -2
  4. package/dist/cjs/breadcrumbs/format-count.js +33 -0
  5. package/dist/cjs/breadcrumbs/index.js +78 -20
  6. package/dist/cjs/breadcrumbs/index.test.js +110 -0
  7. package/dist/cjs/breadcrumbs/style.scss +6 -0
  8. package/dist/cjs/button/index.js +41 -17
  9. package/dist/cjs/button/index.test.js +273 -0
  10. package/dist/cjs/card/core-card.js +9 -4
  11. package/dist/cjs/card/core-card.test.js +29 -0
  12. package/dist/cjs/card/index.js +4 -2
  13. package/dist/cjs/card/style-core.scss +59 -0
  14. package/dist/cjs/card-feature/index.js +7 -1
  15. package/dist/cjs/card-feature/index.test.js +92 -0
  16. package/dist/cjs/color-picker/index.js +1 -1
  17. package/dist/cjs/confirm-dialog/index.js +26 -9
  18. package/dist/cjs/confirm-dialog/index.test.js +176 -0
  19. package/dist/cjs/dataviews/index.js +11 -2
  20. package/dist/cjs/divider/index.js +13 -0
  21. package/dist/cjs/drawer/action.js +74 -0
  22. package/dist/cjs/drawer/body.js +79 -0
  23. package/dist/cjs/drawer/close-icon.js +45 -0
  24. package/dist/cjs/drawer/content.js +72 -0
  25. package/dist/cjs/drawer/context.js +23 -0
  26. package/dist/cjs/drawer/context.test.js +43 -0
  27. package/dist/cjs/drawer/divider.js +24 -0
  28. package/dist/cjs/drawer/footer.js +26 -0
  29. package/dist/cjs/drawer/header.js +26 -0
  30. package/dist/cjs/drawer/index.js +42 -0
  31. package/dist/cjs/drawer/index.test.js +1287 -0
  32. package/dist/cjs/drawer/root.js +350 -0
  33. package/dist/cjs/drawer/slots.test.js +422 -0
  34. package/dist/cjs/drawer/style.scss +205 -0
  35. package/dist/cjs/drawer/title.js +54 -0
  36. package/dist/cjs/drawer/types.js +5 -0
  37. package/dist/cjs/drawer/use-exit-animation.js +59 -0
  38. package/dist/cjs/hooks/use-confirm-dialog.js +15 -3
  39. package/dist/cjs/hooks/use-unsaved-changes-dialog.js +19 -4
  40. package/dist/cjs/index.js +28 -1
  41. package/dist/cjs/page/index.js +1 -1
  42. package/dist/cjs/page-control/index.js +82 -0
  43. package/dist/cjs/plugin-settings/SettingsSection.js +7 -1
  44. package/dist/cjs/section-header/index.js +5 -2
  45. package/dist/cjs/section-header/style.scss +25 -12
  46. package/dist/cjs/table-card/index.js +67 -0
  47. package/dist/cjs/table-card/index.test.js +153 -0
  48. package/dist/cjs/with-wizard-screen/style.scss +8 -0
  49. package/dist/cjs/wizard/index.js +102 -38
  50. package/dist/esm/autocomplete-tokenfield/style.scss +4 -2
  51. package/dist/esm/breadcrumbs/format-count.js +27 -0
  52. package/dist/esm/breadcrumbs/index.js +81 -20
  53. package/dist/esm/breadcrumbs/index.test.js +110 -0
  54. package/dist/esm/breadcrumbs/style.scss +6 -0
  55. package/dist/esm/button/index.js +42 -18
  56. package/dist/esm/button/index.test.js +273 -0
  57. package/dist/esm/card/core-card.js +9 -4
  58. package/dist/esm/card/core-card.test.js +29 -0
  59. package/dist/esm/card/index.js +4 -2
  60. package/dist/esm/card/style-core.scss +59 -0
  61. package/dist/esm/card-feature/index.js +8 -2
  62. package/dist/esm/card-feature/index.test.js +96 -0
  63. package/dist/esm/color-picker/index.js +1 -1
  64. package/dist/esm/confirm-dialog/index.js +26 -9
  65. package/dist/esm/confirm-dialog/index.test.js +176 -0
  66. package/dist/esm/dataviews/index.js +11 -2
  67. package/dist/esm/divider/index.js +14 -0
  68. package/dist/esm/drawer/action.js +68 -0
  69. package/dist/esm/drawer/body.js +70 -0
  70. package/dist/esm/drawer/close-icon.js +37 -0
  71. package/dist/esm/drawer/content.js +63 -0
  72. package/dist/esm/drawer/context.js +17 -0
  73. package/dist/esm/drawer/context.test.js +40 -0
  74. package/dist/esm/drawer/divider.js +16 -0
  75. package/dist/esm/drawer/footer.js +18 -0
  76. package/dist/esm/drawer/header.js +18 -0
  77. package/dist/esm/drawer/index.js +35 -0
  78. package/dist/esm/drawer/index.test.js +1285 -0
  79. package/dist/esm/drawer/root.js +342 -0
  80. package/dist/esm/drawer/slots.test.js +422 -0
  81. package/dist/esm/drawer/style.scss +205 -0
  82. package/dist/esm/drawer/title.js +46 -0
  83. package/dist/esm/drawer/types.js +1 -0
  84. package/dist/esm/drawer/use-exit-animation.js +52 -0
  85. package/dist/esm/hooks/use-confirm-dialog.js +15 -3
  86. package/dist/esm/hooks/use-unsaved-changes-dialog.js +20 -5
  87. package/dist/esm/index.js +4 -0
  88. package/dist/esm/page/index.js +1 -1
  89. package/dist/esm/page-control/index.js +82 -0
  90. package/dist/esm/plugin-settings/SettingsSection.js +8 -2
  91. package/dist/esm/section-header/index.js +5 -2
  92. package/dist/esm/section-header/style.scss +25 -12
  93. package/dist/esm/table-card/index.js +60 -0
  94. package/dist/esm/table-card/index.test.js +150 -0
  95. package/dist/esm/with-wizard-screen/style.scss +8 -0
  96. package/dist/esm/wizard/index.js +104 -38
  97. package/package.json +2 -2
  98. package/src/autocomplete-tokenfield/style.scss +4 -2
  99. package/src/breadcrumbs/format-count.js +27 -0
  100. package/src/breadcrumbs/index.js +68 -8
  101. package/src/breadcrumbs/index.test.js +57 -0
  102. package/src/breadcrumbs/style.scss +6 -0
  103. package/src/button/index.test.js +143 -0
  104. package/src/button/index.tsx +32 -7
  105. package/src/card/core-card.js +15 -2
  106. package/src/card/core-card.test.js +19 -0
  107. package/src/card/index.js +3 -0
  108. package/src/card/style-core.scss +59 -0
  109. package/src/card-feature/README.md +4 -0
  110. package/src/card-feature/index.test.js +65 -0
  111. package/src/card-feature/index.tsx +13 -2
  112. package/src/color-picker/index.js +1 -1
  113. package/src/confirm-dialog/README.md +3 -2
  114. package/src/confirm-dialog/index.test.js +146 -0
  115. package/src/confirm-dialog/index.tsx +23 -9
  116. package/src/dataviews/index.tsx +11 -2
  117. package/src/divider/index.js +13 -0
  118. package/src/drawer/README.md +454 -0
  119. package/src/drawer/action.tsx +67 -0
  120. package/src/drawer/body.tsx +60 -0
  121. package/src/drawer/close-icon.tsx +37 -0
  122. package/src/drawer/content.tsx +54 -0
  123. package/src/drawer/context.test.js +31 -0
  124. package/src/drawer/context.ts +25 -0
  125. package/src/drawer/divider.tsx +13 -0
  126. package/src/drawer/footer.tsx +15 -0
  127. package/src/drawer/header.tsx +15 -0
  128. package/src/drawer/index.test.js +1012 -0
  129. package/src/drawer/index.tsx +33 -0
  130. package/src/drawer/root.tsx +328 -0
  131. package/src/drawer/slots.test.js +314 -0
  132. package/src/drawer/style.scss +205 -0
  133. package/src/drawer/title.tsx +40 -0
  134. package/src/drawer/types.ts +79 -0
  135. package/src/drawer/use-exit-animation.ts +46 -0
  136. package/src/hooks/use-confirm-dialog.tsx +14 -3
  137. package/src/hooks/use-unsaved-changes-dialog.tsx +17 -5
  138. package/src/index.js +4 -0
  139. package/src/page/index.js +1 -1
  140. package/src/page-control/index.js +63 -0
  141. package/src/plugin-settings/SettingsSection.js +8 -2
  142. package/src/section-header/index.js +5 -2
  143. package/src/section-header/style.scss +25 -12
  144. package/src/table-card/README.md +100 -0
  145. package/src/table-card/index.test.js +112 -0
  146. package/src/table-card/index.tsx +56 -0
  147. package/src/with-wizard-screen/style.scss +8 -0
  148. package/src/wizard/index.js +95 -34
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
5
+ var _react = require("@testing-library/react");
6
+ var _reactRouterDom = require("react-router-dom");
7
+ var _ = _interopRequireDefault(require("./"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
10
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); } /**
11
+ * External dependencies.
12
+ */ /**
13
+ * Internal dependencies.
14
+ */
15
+ var HistoryGrabber = function HistoryGrabber(_ref) {
16
+ var historyRef = _ref.historyRef;
17
+ historyRef.current = (0, _reactRouterDom.useHistory)();
18
+ return null;
19
+ };
20
+ var clickButton = /*#__PURE__*/function () {
21
+ var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee2() {
22
+ return _regenerator().w(function (_context2) {
23
+ while (1) switch (_context2.n) {
24
+ case 0:
25
+ _context2.n = 1;
26
+ return (0, _react.act)(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee() {
27
+ return _regenerator().w(function (_context) {
28
+ while (1) switch (_context.n) {
29
+ case 0:
30
+ _react.screen.getByRole('button', {
31
+ name: 'Save'
32
+ }).click();
33
+ case 1:
34
+ return _context.a(2);
35
+ }
36
+ }, _callee);
37
+ })));
38
+ case 1:
39
+ return _context2.a(2);
40
+ }
41
+ }, _callee2);
42
+ }));
43
+ return function clickButton() {
44
+ return _ref2.apply(this, arguments);
45
+ };
46
+ }();
47
+ describe('Button href with onClick', function () {
48
+ it('awaits the onClick, then pushes the route', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee3() {
49
+ var historyRef, onClick;
50
+ return _regenerator().w(function (_context3) {
51
+ while (1) switch (_context3.n) {
52
+ case 0:
53
+ historyRef = {
54
+ current: null
55
+ };
56
+ onClick = jest.fn().mockResolvedValue(undefined);
57
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactRouterDom.MemoryRouter, {
58
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HistoryGrabber, {
59
+ historyRef: historyRef
60
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
61
+ href: "#/next",
62
+ onClick: onClick,
63
+ children: "Save"
64
+ })]
65
+ }));
66
+ _context3.n = 1;
67
+ return clickButton();
68
+ case 1:
69
+ expect(onClick).toHaveBeenCalled();
70
+ // The leading '#' is stripped so the router sees a route, not a fragment.
71
+ expect(historyRef.current.location.pathname).toBe('/next');
72
+ case 2:
73
+ return _context3.a(2);
74
+ }
75
+ }, _callee3);
76
+ })));
77
+ });
78
+
79
+ // `useHistory` returns undefined outside a wizard, leaving no route table for the
80
+ // href to name.
81
+ describe('Button href with onClick outside a router', function () {
82
+ // jsdom's real location logs "Not implemented: navigation" rather than
83
+ // navigating, so swap in a plain object to assert against and put the
84
+ // original back afterwards.
85
+ var withStubbedLocation = /*#__PURE__*/function () {
86
+ var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee4(fn) {
87
+ var original;
88
+ return _regenerator().w(function (_context4) {
89
+ while (1) switch (_context4.p = _context4.n) {
90
+ case 0:
91
+ original = window.location;
92
+ delete window.location;
93
+ window.location = {
94
+ href: ''
95
+ };
96
+ _context4.p = 1;
97
+ _context4.n = 2;
98
+ return fn();
99
+ case 2:
100
+ return _context4.a(2, _context4.v);
101
+ case 3:
102
+ _context4.p = 3;
103
+ window.location = original;
104
+ return _context4.f(3);
105
+ case 4:
106
+ return _context4.a(2);
107
+ }
108
+ }, _callee4, null, [[1,, 3, 4]]);
109
+ }));
110
+ return function withStubbedLocation(_x) {
111
+ return _ref5.apply(this, arguments);
112
+ };
113
+ }();
114
+ it('awaits the onClick, then navigates to the href', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee6() {
115
+ var onClick;
116
+ return _regenerator().w(function (_context6) {
117
+ while (1) switch (_context6.n) {
118
+ case 0:
119
+ onClick = jest.fn().mockResolvedValue(undefined);
120
+ _context6.n = 1;
121
+ return withStubbedLocation(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee5() {
122
+ return _regenerator().w(function (_context5) {
123
+ while (1) switch (_context5.n) {
124
+ case 0:
125
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
126
+ href: "/wp-admin/admin.php?page=next",
127
+ onClick: onClick,
128
+ children: "Save"
129
+ }));
130
+ _context5.n = 1;
131
+ return clickButton();
132
+ case 1:
133
+ expect(onClick).toHaveBeenCalled();
134
+ expect(window.location.href).toBe('/wp-admin/admin.php?page=next');
135
+ case 2:
136
+ return _context5.a(2);
137
+ }
138
+ }, _callee5);
139
+ })));
140
+ case 1:
141
+ return _context6.a(2);
142
+ }
143
+ }, _callee6);
144
+ })));
145
+ it('hands the click event to a combined href and onClick handler', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee8() {
146
+ var onClick;
147
+ return _regenerator().w(function (_context8) {
148
+ while (1) switch (_context8.n) {
149
+ case 0:
150
+ onClick = jest.fn();
151
+ _context8.n = 1;
152
+ return withStubbedLocation(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee7() {
153
+ return _regenerator().w(function (_context7) {
154
+ while (1) switch (_context7.n) {
155
+ case 0:
156
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
157
+ href: "/wp-admin/admin.php?page=next",
158
+ onClick: onClick,
159
+ children: "Save"
160
+ }));
161
+ _context7.n = 1;
162
+ return clickButton();
163
+ case 1:
164
+ expect(onClick).toHaveBeenCalledWith(expect.objectContaining({
165
+ type: 'click'
166
+ }));
167
+ case 2:
168
+ return _context7.a(2);
169
+ }
170
+ }, _callee7);
171
+ })));
172
+ case 1:
173
+ return _context8.a(2);
174
+ }
175
+ }, _callee8);
176
+ })));
177
+ it('runs an onClick with no href without touching navigation', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee0() {
178
+ var onClick;
179
+ return _regenerator().w(function (_context0) {
180
+ while (1) switch (_context0.n) {
181
+ case 0:
182
+ onClick = jest.fn();
183
+ _context0.n = 1;
184
+ return withStubbedLocation(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee9() {
185
+ return _regenerator().w(function (_context9) {
186
+ while (1) switch (_context9.n) {
187
+ case 0:
188
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
189
+ onClick: onClick,
190
+ children: "Save"
191
+ }));
192
+ _context9.n = 1;
193
+ return clickButton();
194
+ case 1:
195
+ expect(onClick).toHaveBeenCalled();
196
+ expect(window.location.href).toBe('');
197
+ case 2:
198
+ return _context9.a(2);
199
+ }
200
+ }, _callee9);
201
+ })));
202
+ case 1:
203
+ return _context0.a(2);
204
+ }
205
+ }, _callee0);
206
+ })));
207
+ it('drops a javascript: href and still runs the onClick', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee10() {
208
+ var warn, onClick;
209
+ return _regenerator().w(function (_context10) {
210
+ while (1) switch (_context10.n) {
211
+ case 0:
212
+ warn = jest.spyOn(console, 'warn').mockImplementation(function () {});
213
+ onClick = jest.fn().mockResolvedValue(undefined);
214
+ _context10.n = 1;
215
+ return withStubbedLocation(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee1() {
216
+ return _regenerator().w(function (_context1) {
217
+ while (1) switch (_context1.n) {
218
+ case 0:
219
+ // eslint-disable-next-line no-script-url
220
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
221
+ href: "javascript:alert(1)",
222
+ onClick: onClick,
223
+ children: "Save"
224
+ }));
225
+ _context1.n = 1;
226
+ return clickButton();
227
+ case 1:
228
+ expect(onClick).toHaveBeenCalled();
229
+ expect(window.location.href).toBe('');
230
+ case 2:
231
+ return _context1.a(2);
232
+ }
233
+ }, _callee1);
234
+ })));
235
+ case 1:
236
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('javascript:'));
237
+ warn.mockRestore();
238
+ case 2:
239
+ return _context10.a(2);
240
+ }
241
+ }, _callee10);
242
+ })));
243
+ });
244
+ describe('Button with a javascript: href alone', function () {
245
+ var link = function link() {
246
+ return _react.screen.getByText('Save').closest('a');
247
+ };
248
+ it('renders no link', function () {
249
+ var warn = jest.spyOn(console, 'warn').mockImplementation(function () {});
250
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
251
+ href: "JavaScript:alert(1)",
252
+ children: "Save"
253
+ }));
254
+ expect(link()).toBeNull();
255
+ warn.mockRestore();
256
+ });
257
+ it('sees through interleaved control characters', function () {
258
+ var warn = jest.spyOn(console, 'warn').mockImplementation(function () {});
259
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
260
+ href: 'java\nscript:alert(1)',
261
+ children: "Save"
262
+ }));
263
+ expect(link()).toBeNull();
264
+ warn.mockRestore();
265
+ });
266
+ it('leaves an ordinary href alone', function () {
267
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {
268
+ href: "/wp-admin/admin.php?page=next",
269
+ children: "Save"
270
+ }));
271
+ expect(link()).toHaveAttribute('href', '/wp-admin/admin.php?page=next');
272
+ });
273
+ });
@@ -13,7 +13,7 @@ var _icons = require("@wordpress/icons");
13
13
  require("./style-core.scss");
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
- var _excluded = ["actions", "actionType", "as", "buttonsCard", "className", "footer", "header", "headerAction", "headerStyle", "childrenStyle", "footerStyle", "disabled", "icon", "iconElement", "iconBackgroundColor", "isActive", "isDraggable", "isFirstTarget", "isLastTarget", "isNarrow", "isSmall", "dragIndex", "onDragCallback", "onToggle", "onHeaderClick", "noBorder", "noMargin", "children", "hasGreyHeader", "hasHeaderBorder"];
16
+ var _excluded = ["actions", "actionType", "as", "buttonsCard", "className", "footer", "header", "headerAction", "headerStyle", "childrenStyle", "footerStyle", "disabled", "icon", "iconElement", "iconBackgroundColor", "isActive", "isDraggable", "isFirstTarget", "isLastTarget", "isNarrow", "isSelectable", "isSmall", "isVertical", "size", "dragIndex", "onDragCallback", "onToggle", "onHeaderClick", "noBorder", "noMargin", "children", "hasGreyHeader", "hasHeaderBorder"];
17
17
  /**
18
18
  * Card using WP Core's Card component.
19
19
  * https://wordpress.github.io/gutenberg/?path=/docs/components-card--docs
@@ -50,7 +50,10 @@ var CoreCard = function CoreCard(_ref) {
50
50
  isFirstTarget = _ref.isFirstTarget,
51
51
  isLastTarget = _ref.isLastTarget,
52
52
  isNarrow = _ref.isNarrow,
53
+ isSelectable = _ref.isSelectable,
53
54
  isSmall = _ref.isSmall,
55
+ isVertical = _ref.isVertical,
56
+ size = _ref.size,
54
57
  dragIndex = _ref.dragIndex,
55
58
  _ref$onDragCallback = _ref.onDragCallback,
56
59
  onDragCallback = _ref$onDragCallback === void 0 ? function () {} : _ref$onDragCallback,
@@ -65,8 +68,9 @@ var CoreCard = function CoreCard(_ref) {
65
68
  _ref$hasHeaderBorder = _ref.hasHeaderBorder,
66
69
  hasHeaderBorder = _ref$hasHeaderBorder === void 0 ? true : _ref$hasHeaderBorder,
67
70
  otherProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
68
- var classes = (0, _classnames["default"])('newspack-card--core', className, (buttonsCard || as === 'a') && 'newspack-card--core__buttons-card', (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && 'newspack-card--core__header--has-actions', isDraggable && 'newspack-card--core__is-draggable', isNarrow && 'newspack-card--core__is-narrow', isSmall && 'newspack-card--core__is-small', (icon || iconElement) && 'newspack-card--core__has-icon', iconBackgroundColor && 'newspack-card--core__has-icon-background-color', isActive && 'newspack-card--core__is-active', disabled && 'newspack-card--core__is-disabled', children && 'newspack-card--core__has-children', noMargin && 'newspack-card--core__no-margin', hasGreyHeader && 'newspack-card--core__has-grey-header');
69
- var sizeProps = isSmall ? 'small' : otherProps.size;
71
+ var bodySize = isSmall ? undefined : size;
72
+ var classes = (0, _classnames["default"])('newspack-card--core', className, (buttonsCard || as === 'a') && 'newspack-card--core__buttons-card', (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && 'newspack-card--core__header--has-actions', isDraggable && 'newspack-card--core__is-draggable', isNarrow && 'newspack-card--core__is-narrow', isSmall && 'newspack-card--core__is-small', isSelectable && 'newspack-card--core__is-selectable', bodySize === 'large' && 'newspack-card--core__is-large', isVertical && 'newspack-card--core__is-vertical', (icon || iconElement) && 'newspack-card--core__has-icon', iconBackgroundColor && 'newspack-card--core__has-icon-background-color', isActive && 'newspack-card--core__is-active', disabled && 'newspack-card--core__is-disabled', children && 'newspack-card--core__has-children', noMargin && 'newspack-card--core__no-margin', hasGreyHeader && 'newspack-card--core__has-grey-header');
73
+ var sizeProps = isSmall ? 'small' : size;
70
74
  if (buttonsCard || as === 'a') {
71
75
  if (!isSmall) {
72
76
  sizeProps = 'large';
@@ -85,7 +89,8 @@ var CoreCard = function CoreCard(_ref) {
85
89
  var headerIsButton = !!onHeaderClick && !hasInteractiveHeaderChildren;
86
90
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Card, _objectSpread(_objectSpread({
87
91
  as: as,
88
- className: classes
92
+ className: classes,
93
+ size: bodySize
89
94
  }, otherProps), {}, {
90
95
  children: [(header || icon || iconElement) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.CardHeader, {
91
96
  as: headerIsButton ? 'button' : undefined,
@@ -66,4 +66,33 @@ describe('CoreCard', function () {
66
66
  container = _render5.container;
67
67
  expect(getHeader(container).tagName).not.toBe('BUTTON');
68
68
  });
69
+ it('gives the body large padding when size is large', function () {
70
+ var _render6 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_coreCard["default"], {
71
+ size: "large"
72
+ })),
73
+ container = _render6.container;
74
+ expect(container.querySelector('.newspack-card--core__is-large')).not.toBeNull();
75
+ });
76
+ it('lets isSmall win over a large size', function () {
77
+ var _render7 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_coreCard["default"], {
78
+ size: "large",
79
+ isSmall: true
80
+ })),
81
+ container = _render7.container;
82
+ expect(container.querySelector('.newspack-card--core__is-large')).toBeNull();
83
+ expect(container.querySelector('.newspack-card--core__is-small')).not.toBeNull();
84
+ });
85
+ it('marks the card vertical only when isVertical is passed', function () {
86
+ var _render8 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_coreCard["default"], {
87
+ header: "Settings"
88
+ })),
89
+ plain = _render8.container;
90
+ expect(plain.querySelector('.newspack-card--core__is-vertical')).toBeNull();
91
+ var _render9 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_coreCard["default"], {
92
+ header: "Settings",
93
+ isVertical: true
94
+ })),
95
+ vertical = _render9.container;
96
+ expect(vertical.querySelector('.newspack-card--core__is-vertical')).not.toBeNull();
97
+ });
69
98
  });
@@ -17,7 +17,7 @@ var _coreCard = _interopRequireDefault(require("./core-card"));
17
17
  require("./style.scss");
18
18
  var _classnames = _interopRequireDefault(require("classnames"));
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
- var _excluded = ["buttonsCard", "className", "headerActions", "isNarrow", "isMedium", "isSmall", "isWhite", "noBorder", "__experimentalCoreCard", "__experimentalCoreProps"];
20
+ var _excluded = ["buttonsCard", "className", "headerActions", "isNarrow", "isMedium", "isSmall", "isWhite", "noBorder", "size", "__experimentalCoreCard", "__experimentalCoreProps"];
21
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
23
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
@@ -52,6 +52,7 @@ var Card = /*#__PURE__*/function (_Component) {
52
52
  isSmall = _this$props.isSmall,
53
53
  isWhite = _this$props.isWhite,
54
54
  noBorder = _this$props.noBorder,
55
+ size = _this$props.size,
55
56
  __experimentalCoreCard = _this$props.__experimentalCoreCard,
56
57
  _this$props$__experim = _this$props.__experimentalCoreProps,
57
58
  __experimentalCoreProps = _this$props$__experim === void 0 ? {
@@ -77,7 +78,8 @@ var Card = /*#__PURE__*/function (_Component) {
77
78
  isNarrow: isNarrow,
78
79
  isSmall: isSmall,
79
80
  isWhite: isWhite,
80
- noBorder: noBorder
81
+ noBorder: noBorder,
82
+ size: size
81
83
  }, otherProps), __experimentalCoreProps);
82
84
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_coreCard["default"], _objectSpread({}, props));
83
85
  }
@@ -59,6 +59,19 @@
59
59
  }
60
60
  }
61
61
  }
62
+ &__is-vertical {
63
+ .newspack-card--core__header {
64
+ align-items: flex-start;
65
+ flex-direction: column;
66
+ height: 100%;
67
+ justify-content: flex-start;
68
+ }
69
+ .newspack-card--core__header-content {
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: wp-vars.$grid-unit-10;
73
+ }
74
+ }
62
75
  &__no-margin .components-card__body {
63
76
  padding: 0 !important;
64
77
  }
@@ -202,6 +215,48 @@
202
215
  }
203
216
  }
204
217
  }
218
+ &__is-selectable {
219
+ appearance: none;
220
+ border: 0;
221
+ color: inherit;
222
+ cursor: pointer;
223
+ font: inherit;
224
+ margin: 0;
225
+ padding: 0;
226
+ text-align: inherit;
227
+
228
+ &:hover {
229
+ box-shadow: var(--wp-admin-theme-color) 0 0 0 1px;
230
+
231
+ .newspack-card--core__header,
232
+ .newspack-card--core__header h1,
233
+ .newspack-card--core__header h2,
234
+ .newspack-card--core__header h3,
235
+ .newspack-card--core__header h4,
236
+ .newspack-card--core__header h5,
237
+ .newspack-card--core__header h6 {
238
+ color: var(--wp-admin-theme-color);
239
+ }
240
+ }
241
+
242
+ &:focus-visible {
243
+ box-shadow: inset 0 0 0 2px var(--wp-admin-theme-color);
244
+ outline: 2px solid transparent;
245
+ }
246
+
247
+ @media ( prefers-contrast: more ) {
248
+ &.newspack-card--core__is-active {
249
+ box-shadow: var(--wp-admin-theme-color) 0 0 0 2px;
250
+ }
251
+ }
252
+
253
+ @media ( forced-colors: active ) {
254
+ &.newspack-card--core__is-active {
255
+ outline: 3px solid CanvasText;
256
+ outline-offset: -3px;
257
+ }
258
+ }
259
+ }
205
260
  &__is-active:not(.newspack-card--core__is-draggable) {
206
261
  border-color: var(--wp-admin-theme-color);
207
262
  box-shadow: var(--wp-admin-theme-color) 0 0 0 1px;
@@ -298,6 +353,10 @@
298
353
  .newspack-card--core__is-small & {
299
354
  padding: 16px;
300
355
  }
356
+
357
+ .newspack-card--core__is-large & {
358
+ padding: wp-vars.$grid-unit-60;
359
+ }
301
360
  .newspack-card--core__no-margin & {
302
361
  padding: 0;
303
362
  }
@@ -74,6 +74,9 @@ var CardFeature = function CardFeature(_ref) {
74
74
  }
75
75
  var isConfigureState = enabled && !requirements;
76
76
  var buttonLabel = isConfigureState ? configureLabel !== null && configureLabel !== void 0 ? configureLabel : (0, _i18n.__)('Configure', 'newspack-plugin') : enableLabel !== null && enableLabel !== void 0 ? enableLabel : (0, _i18n.__)('Enable', 'newspack-plugin');
77
+ var buttonAccessibleLabel = (0, _i18n.sprintf)(
78
+ // translators: %1$s: the button's visible action label, e.g. "Enable". %2$s: the feature's name. The visible label must stay first (WCAG 2.5.3).
79
+ (0, _i18n._x)('%1$s %2$s', 'accessible button name: visible action label, then feature name', 'newspack-plugin'), buttonLabel, title);
77
80
  var showMoreControls = enabled && !!(moreControls !== null && moreControls !== void 0 && moreControls.length) && (!requirements || requirementsActionable);
78
81
  var handleButtonClick = function handleButtonClick() {
79
82
  if (isConfigureState) {
@@ -132,10 +135,13 @@ var CardFeature = function CardFeature(_ref) {
132
135
  isBusy: busy,
133
136
  onClick: handleButtonClick,
134
137
  size: "compact",
138
+ "aria-label": buttonAccessibleLabel,
135
139
  children: buttonLabel
136
140
  }), showMoreControls && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
137
141
  icon: _icons.moreVertical,
138
- label: (0, _i18n.__)('More', 'newspack-plugin'),
142
+ label: (0, _i18n.sprintf)(
143
+ // translators: %s: the feature's name.
144
+ (0, _i18n.__)('More options for %s', 'newspack-plugin'), title),
139
145
  controls: moreControls,
140
146
  toggleProps: {
141
147
  size: 'compact'
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
5
+ var _react = require("@testing-library/react");
6
+ var _i18n = require("@wordpress/i18n");
7
+ var _index = _interopRequireDefault(require("./index"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
11
+ * External dependencies.
12
+ */ /**
13
+ * WordPress dependencies.
14
+ */ /**
15
+ * Internal dependencies.
16
+ */ // The spy lives in the factory: @wordpress/components calls _x while it loads,
17
+ // before a module-scope const would be initialized.
18
+ jest.mock('@wordpress/i18n', function () {
19
+ var actual = jest.requireActual('@wordpress/i18n');
20
+ return _objectSpread(_objectSpread({}, actual), {}, {
21
+ _x: jest.fn(function (text) {
22
+ return text;
23
+ })
24
+ });
25
+ });
26
+ describe('CardFeature', function () {
27
+ beforeEach(function () {
28
+ _i18n._x.mockClear();
29
+ });
30
+ it('names the feature in the primary button, keeping the visible label first', function () {
31
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
32
+ title: "Metered Countdown"
33
+ }));
34
+ var button = _react.screen.getByRole('button', {
35
+ name: 'Enable Metered Countdown'
36
+ });
37
+ expect(button).toHaveTextContent('Enable');
38
+ expect(button.getAttribute('aria-label').startsWith(button.textContent)).toBe(true);
39
+ });
40
+ it('carries a custom label into the accessible name', function () {
41
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
42
+ title: "Subscription retention",
43
+ enableLabel: "Change"
44
+ }));
45
+ expect(_react.screen.getByRole('button', {
46
+ name: 'Change Subscription retention'
47
+ })).toHaveTextContent('Change');
48
+ });
49
+ it('names the feature in the configure state too', function () {
50
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
51
+ title: "Content Gifting",
52
+ enabled: true
53
+ }));
54
+ expect(_react.screen.getByRole('button', {
55
+ name: 'Configure Content Gifting'
56
+ })).toBeInTheDocument();
57
+ });
58
+ it('names the feature in the More menu', function () {
59
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
60
+ title: "Content Gifting",
61
+ enabled: true,
62
+ moreControls: [{
63
+ title: 'Disable',
64
+ onClick: function onClick() {}
65
+ }]
66
+ }));
67
+ expect(_react.screen.getByRole('button', {
68
+ name: 'More options for Content Gifting'
69
+ })).toBeInTheDocument();
70
+ });
71
+ it('gives the accessible-name order its own catalogue entry', function () {
72
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
73
+ title: "Metered Countdown"
74
+ }));
75
+ expect(_i18n._x).toHaveBeenCalledWith('%1$s %2$s', 'accessible button name: visible action label, then feature name', 'newspack-plugin');
76
+ });
77
+ it('distinguishes two cards that share a button label', function () {
78
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
79
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
80
+ title: "Metered Countdown"
81
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
82
+ title: "Content Gifting"
83
+ })]
84
+ }));
85
+ expect(_react.screen.getByRole('button', {
86
+ name: 'Enable Metered Countdown'
87
+ })).toBeInTheDocument();
88
+ expect(_react.screen.getByRole('button', {
89
+ name: 'Enable Content Gifting'
90
+ })).toBeInTheDocument();
91
+ });
92
+ });
@@ -36,7 +36,7 @@ var InteractiveDiv = _utils["default"].InteractiveDiv;
36
36
  *
37
37
  * @param {Object} props - Component props.
38
38
  * @param {JSX.Element|string} props.label - Label for the color picker.
39
- * @param {JSX.Element|string} props.help - Help text for the color picker.
39
+ * @param {JSX.Element|string} [props.help] - Help text for the color picker.
40
40
  * @param {string} [props.color] - Default color.
41
41
  * @param {Function} props.onChange - Function to call when the color changes.
42
42
  * @param {string} [props.className] - Additional class name.
@@ -79,21 +79,26 @@ function ConfirmDialog(_ref, ref) {
79
79
  }, [onConfirm, pendingNavigation]);
80
80
  var handleOnCancel = (0, _element.useCallback)(function () {
81
81
  setShowDialog(false);
82
+ var hadPendingNavigation = !!pendingNavigation.current;
82
83
  pendingNavigation.current = null;
83
84
  // A POP may have moved the URL to the target before it was blocked; put
84
85
  // it back so the address bar matches the page the user chose to stay on.
85
- bypassBlock.current = true;
86
- try {
87
- history.replace(history.location);
88
- } finally {
89
- bypassBlock.current = false;
86
+ // Only when this instance blocked it: v5 keeps one prompt slot, so an
87
+ // unprompted replace is caught by whichever dialog did install a blocker.
88
+ if (hadPendingNavigation && history) {
89
+ bypassBlock.current = true;
90
+ try {
91
+ history.replace(history.location);
92
+ } finally {
93
+ bypassBlock.current = false;
94
+ }
90
95
  }
91
96
  onCancel();
92
97
  }, [onCancel, history]);
93
98
 
94
99
  // Block navigation when there are unsaved changes.
95
100
  (0, _element.useEffect)(function () {
96
- if (!when) {
101
+ if (!when || !history) {
97
102
  return;
98
103
  }
99
104
  var unblock = history.block(function (location, action) {
@@ -124,10 +129,22 @@ function ConfirmDialog(_ref, ref) {
124
129
  return unblock;
125
130
  }, [when, history]);
126
131
 
127
- // Show the dialog imperatively without blocking navigation.
132
+ // During render: a commit later the dialog would still hold focus while the
133
+ // caller unmounted. The blocker above raises it without touching `isOpen`.
134
+ var _useState3 = (0, _element.useState)(isOpen),
135
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
136
+ wasOpen = _useState4[0],
137
+ setWasOpen = _useState4[1];
138
+ if (wasOpen !== isOpen) {
139
+ setWasOpen(isOpen);
140
+ setShowDialog(isOpen);
141
+ }
142
+
143
+ // A withdrawn prompt releases what the blocker held, as confirm and cancel do.
144
+ // After the commit, so a discarded render cannot drop a live one.
128
145
  (0, _element.useEffect)(function () {
129
- if (isOpen) {
130
- setShowDialog(true);
146
+ if (!isOpen) {
147
+ pendingNavigation.current = null;
131
148
  }
132
149
  }, [isOpen]);
133
150
  if (!showDialog) {