newspack-components 4.8.0 → 4.9.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.
- package/CHANGELOG.md +10 -0
- package/DEVELOPMENT.md +18 -17
- package/dist/cjs/action-card/index.js +85 -18
- package/dist/cjs/action-card/index.test.js +192 -5
- package/dist/cjs/action-card/style.scss +3 -9
- package/dist/cjs/card-feature/index.js +28 -3
- package/dist/cjs/card-feature/index.test.js +100 -45
- package/dist/cjs/card-feature/style.scss +1 -5
- package/dist/cjs/debug-badge/index.js +44 -0
- package/dist/cjs/debug-badge/index.test.js +50 -0
- package/dist/cjs/debug-badge/style.scss +26 -0
- package/dist/cjs/empty-state/index.test.js +37 -24
- package/dist/cjs/empty-state/root.js +2 -1
- package/dist/cjs/footer/index.js +52 -16
- package/dist/cjs/footer/index.test.js +208 -0
- package/dist/cjs/footer/style.scss +17 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integration-icon/index.js +4 -4
- package/dist/cjs/integration-icon/style.scss +18 -2
- package/dist/cjs/integration-icons/active-campaign.js +4 -7
- package/dist/cjs/integration-icons/beehiiv.js +19 -0
- package/dist/cjs/integration-icons/gravity-forms.js +19 -0
- package/dist/cjs/integration-icons/index.js +26 -6
- package/dist/cjs/integration-icons/salesforce.js +5 -3
- package/dist/cjs/notice/index.js +1 -4
- package/dist/cjs/notice/style.scss +0 -19
- package/dist/cjs/plugin-toggle/index.js +1 -1
- package/dist/cjs/with-wizard-screen/index.js +1 -3
- package/dist/cjs/with-wizard-screen/index.test.js +0 -3
- package/dist/cjs/wizard/breadcrumbs-select.js +17 -4
- package/dist/cjs/wizard/breadcrumbs-select.test.js +17 -0
- package/dist/cjs/wizard/index.js +50 -13
- package/dist/cjs/wizard/index.test.js +304 -5
- package/dist/cjs/wizard/store/index.js +2 -0
- package/dist/esm/action-card/index.js +86 -21
- package/dist/esm/action-card/index.test.js +192 -1
- package/dist/esm/action-card/style.scss +3 -9
- package/dist/esm/card-feature/index.js +29 -4
- package/dist/esm/card-feature/index.test.js +100 -45
- package/dist/esm/card-feature/style.scss +1 -5
- package/dist/esm/debug-badge/index.js +39 -0
- package/dist/esm/debug-badge/index.test.js +46 -0
- package/dist/esm/debug-badge/style.scss +26 -0
- package/dist/esm/empty-state/index.test.js +37 -24
- package/dist/esm/empty-state/root.js +2 -1
- package/dist/esm/footer/index.js +52 -17
- package/dist/esm/footer/index.test.js +210 -0
- package/dist/esm/footer/style.scss +17 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/integration-icon/index.js +5 -5
- package/dist/esm/integration-icon/style.scss +18 -2
- package/dist/esm/integration-icons/active-campaign.js +5 -8
- package/dist/esm/integration-icons/beehiiv.js +13 -0
- package/dist/esm/integration-icons/gravity-forms.js +13 -0
- package/dist/esm/integration-icons/index.js +15 -4
- package/dist/esm/integration-icons/salesforce.js +5 -3
- package/dist/esm/notice/index.js +2 -5
- package/dist/esm/notice/style.scss +0 -19
- package/dist/esm/plugin-toggle/index.js +1 -1
- package/dist/esm/with-wizard-screen/index.js +2 -4
- package/dist/esm/with-wizard-screen/index.test.js +0 -3
- package/dist/esm/wizard/breadcrumbs-select.js +16 -3
- package/dist/esm/wizard/breadcrumbs-select.test.js +18 -1
- package/dist/esm/wizard/index.js +53 -16
- package/dist/esm/wizard/index.test.js +304 -5
- package/dist/esm/wizard/store/index.js +2 -0
- package/package.json +1 -1
- package/src/action-card/action-card.d.ts +3 -2
- package/src/action-card/index.js +81 -8
- package/src/action-card/index.test.js +159 -0
- package/src/action-card/style.scss +3 -9
- package/src/card-feature/README.md +10 -11
- package/src/card-feature/index.test.js +45 -15
- package/src/card-feature/index.tsx +43 -24
- package/src/card-feature/style.scss +1 -5
- package/src/debug-badge/index.js +36 -0
- package/src/debug-badge/index.test.js +39 -0
- package/src/debug-badge/style.scss +26 -0
- package/src/empty-state/README.md +11 -10
- package/src/empty-state/index.test.js +10 -0
- package/src/empty-state/root.tsx +2 -1
- package/src/empty-state/types.ts +1 -1
- package/src/footer/index.js +47 -2
- package/src/footer/index.test.js +114 -0
- package/src/footer/style.scss +17 -1
- package/src/index.js +1 -0
- package/src/integration-icon/index.tsx +5 -5
- package/src/integration-icon/style.scss +18 -2
- package/src/integration-icons/active-campaign.js +1 -5
- package/src/integration-icons/beehiiv.js +10 -0
- package/src/integration-icons/gravity-forms.js +10 -0
- package/src/integration-icons/index.js +14 -3
- package/src/integration-icons/salesforce.js +3 -3
- package/src/notice/index.js +2 -17
- package/src/notice/style.scss +0 -19
- package/src/plugin-toggle/index.js +1 -1
- package/src/with-wizard-screen/index.js +2 -2
- package/src/with-wizard-screen/index.test.js +0 -2
- package/src/wizard/breadcrumbs-select.js +12 -4
- package/src/wizard/breadcrumbs-select.test.js +15 -1
- package/src/wizard/index.js +45 -14
- package/src/wizard/index.test.js +169 -3
- package/src/wizard/store/index.js +2 -0
|
@@ -91,7 +91,8 @@ describe('CardFeature', function () {
|
|
|
91
91
|
it('names the feature in the configure state too', function () {
|
|
92
92
|
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
93
93
|
title: "Content Gifting",
|
|
94
|
-
enabled: true
|
|
94
|
+
enabled: true,
|
|
95
|
+
onConfigure: function onConfigure() {}
|
|
95
96
|
}));
|
|
96
97
|
expect(_react.screen.getByRole('button', {
|
|
97
98
|
name: 'Configure Content Gifting'
|
|
@@ -160,6 +161,72 @@ describe('CardFeature', function () {
|
|
|
160
161
|
expect(onConfigure).toHaveBeenCalledTimes(1);
|
|
161
162
|
expect(onEnable).not.toHaveBeenCalled();
|
|
162
163
|
});
|
|
164
|
+
|
|
165
|
+
// A button reading Configure with nothing behind it would click to nowhere.
|
|
166
|
+
it('drops the primary button once enabled when there is nothing to configure', function () {
|
|
167
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
168
|
+
title: "Content gifting",
|
|
169
|
+
enabled: true,
|
|
170
|
+
onEnable: jest.fn(),
|
|
171
|
+
moreControls: [{
|
|
172
|
+
title: 'Disable',
|
|
173
|
+
onClick: jest.fn()
|
|
174
|
+
}]
|
|
175
|
+
}));
|
|
176
|
+
expect(_react.screen.queryByRole('button', {
|
|
177
|
+
name: /Configure/
|
|
178
|
+
})).toBeNull();
|
|
179
|
+
expect(moreMenu()).toBeInTheDocument();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Enabling removes the button that was just used; without a hand-off,
|
|
183
|
+
// keyboard focus falls to the page.
|
|
184
|
+
it('hands focus to the More menu when enabling removes the focused button', function () {
|
|
185
|
+
var props = {
|
|
186
|
+
title: 'Content gifting',
|
|
187
|
+
onEnable: jest.fn(),
|
|
188
|
+
moreControls: [{
|
|
189
|
+
title: 'Disable',
|
|
190
|
+
onClick: jest.fn()
|
|
191
|
+
}]
|
|
192
|
+
};
|
|
193
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], _objectSpread({}, props))),
|
|
194
|
+
rerender = _render2.rerender;
|
|
195
|
+
primaryButton().focus();
|
|
196
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], _objectSpread(_objectSpread({}, props), {}, {
|
|
197
|
+
enabled: true
|
|
198
|
+
})));
|
|
199
|
+
expect(moreMenu()).toHaveFocus();
|
|
200
|
+
});
|
|
201
|
+
it('leaves focus alone when the removed button did not have it', function () {
|
|
202
|
+
var props = {
|
|
203
|
+
title: 'Content gifting',
|
|
204
|
+
onEnable: jest.fn(),
|
|
205
|
+
moreControls: [{
|
|
206
|
+
title: 'Disable',
|
|
207
|
+
onClick: jest.fn()
|
|
208
|
+
}]
|
|
209
|
+
};
|
|
210
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
211
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], _objectSpread({}, props)), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
212
|
+
children: "Elsewhere"
|
|
213
|
+
})]
|
|
214
|
+
})),
|
|
215
|
+
rerender = _render3.rerender;
|
|
216
|
+
_react.screen.getByRole('button', {
|
|
217
|
+
name: 'Elsewhere'
|
|
218
|
+
}).focus();
|
|
219
|
+
rerender(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
220
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], _objectSpread(_objectSpread({}, props), {}, {
|
|
221
|
+
enabled: true
|
|
222
|
+
})), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
223
|
+
children: "Elsewhere"
|
|
224
|
+
})]
|
|
225
|
+
}));
|
|
226
|
+
expect(_react.screen.getByRole('button', {
|
|
227
|
+
name: 'Elsewhere'
|
|
228
|
+
})).toHaveFocus();
|
|
229
|
+
});
|
|
163
230
|
it('still routes to onEnable when enabled with an unmet requirement, since the button reads Enable', function () {
|
|
164
231
|
var onEnable = jest.fn();
|
|
165
232
|
var onConfigure = jest.fn();
|
|
@@ -217,18 +284,19 @@ describe('CardFeature', function () {
|
|
|
217
284
|
it('leaves the enabled badge unlinked, since it explains nothing about the button', function () {
|
|
218
285
|
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
219
286
|
title: "Content gifting",
|
|
220
|
-
enabled: true
|
|
287
|
+
enabled: true,
|
|
288
|
+
onConfigure: function onConfigure() {}
|
|
221
289
|
}));
|
|
222
290
|
expect(primaryButton()).not.toHaveAttribute('aria-describedby');
|
|
223
291
|
});
|
|
224
292
|
it('disables the button while an action is in flight, even with an actionable requirement', function () {
|
|
225
293
|
var onEnable = jest.fn();
|
|
226
|
-
var
|
|
294
|
+
var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
227
295
|
title: "Content gifting",
|
|
228
296
|
busy: true,
|
|
229
297
|
onEnable: onEnable
|
|
230
298
|
})),
|
|
231
|
-
rerender =
|
|
299
|
+
rerender = _render4.rerender;
|
|
232
300
|
expect(primaryButton()).toHaveAttribute('aria-disabled', 'true');
|
|
233
301
|
_react.fireEvent.click(primaryButton());
|
|
234
302
|
expect(onEnable).not.toHaveBeenCalled();
|
|
@@ -242,12 +310,12 @@ describe('CardFeature', function () {
|
|
|
242
310
|
expect(primaryButton()).toHaveAttribute('aria-disabled', 'true');
|
|
243
311
|
});
|
|
244
312
|
it('accepts custom labels for both states', function () {
|
|
245
|
-
var
|
|
313
|
+
var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
246
314
|
title: "Apple News",
|
|
247
315
|
enableLabel: "Connect",
|
|
248
316
|
configureLabel: "Manage connection"
|
|
249
317
|
})),
|
|
250
|
-
rerender =
|
|
318
|
+
rerender = _render5.rerender;
|
|
251
319
|
expect(_react.screen.getByRole('button', {
|
|
252
320
|
name: 'Connect Apple News'
|
|
253
321
|
})).toBeInTheDocument();
|
|
@@ -255,7 +323,8 @@ describe('CardFeature', function () {
|
|
|
255
323
|
title: "Apple News",
|
|
256
324
|
enabled: true,
|
|
257
325
|
enableLabel: "Connect",
|
|
258
|
-
configureLabel: "Manage connection"
|
|
326
|
+
configureLabel: "Manage connection",
|
|
327
|
+
onConfigure: function onConfigure() {}
|
|
259
328
|
}));
|
|
260
329
|
expect(_react.screen.getByRole('button', {
|
|
261
330
|
name: 'Manage connection Apple News'
|
|
@@ -264,10 +333,10 @@ describe('CardFeature', function () {
|
|
|
264
333
|
});
|
|
265
334
|
describe('badge', function () {
|
|
266
335
|
it('shows nothing when off, and the enabled badge when on', function () {
|
|
267
|
-
var
|
|
336
|
+
var _render6 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
268
337
|
title: "Content gifting"
|
|
269
338
|
})),
|
|
270
|
-
rerender =
|
|
339
|
+
rerender = _render6.rerender;
|
|
271
340
|
expect(_react.screen.queryByText('Enabled')).not.toBeInTheDocument();
|
|
272
341
|
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
273
342
|
title: "Content gifting",
|
|
@@ -302,11 +371,11 @@ describe('CardFeature', function () {
|
|
|
302
371
|
onClick: jest.fn()
|
|
303
372
|
}];
|
|
304
373
|
it('appears only when enabled and controls are supplied', function () {
|
|
305
|
-
var
|
|
374
|
+
var _render7 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
306
375
|
title: "Content gifting",
|
|
307
376
|
moreControls: controls
|
|
308
377
|
})),
|
|
309
|
-
rerender =
|
|
378
|
+
rerender = _render7.rerender;
|
|
310
379
|
expect(moreMenu()).not.toBeInTheDocument();
|
|
311
380
|
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
312
381
|
title: "Content gifting",
|
|
@@ -321,14 +390,14 @@ describe('CardFeature', function () {
|
|
|
321
390
|
expect(moreMenu()).toBeInTheDocument();
|
|
322
391
|
});
|
|
323
392
|
it('stays available on an actionable requirement and hides on a locked one', function () {
|
|
324
|
-
var
|
|
393
|
+
var _render8 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
325
394
|
title: "Content gifting",
|
|
326
395
|
enabled: true,
|
|
327
396
|
requirements: "Requires metering",
|
|
328
397
|
requirementsActionable: true,
|
|
329
398
|
moreControls: controls
|
|
330
399
|
})),
|
|
331
|
-
rerender =
|
|
400
|
+
rerender = _render8.rerender;
|
|
332
401
|
expect(moreMenu()).toBeInTheDocument();
|
|
333
402
|
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
334
403
|
title: "Content gifting",
|
|
@@ -341,88 +410,74 @@ describe('CardFeature', function () {
|
|
|
341
410
|
});
|
|
342
411
|
describe('icon', function () {
|
|
343
412
|
it('renders a ready element as-is, without the descriptor container', function () {
|
|
344
|
-
var
|
|
413
|
+
var _render9 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
345
414
|
title: "Content gifting",
|
|
346
415
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
347
416
|
"data-testid": "ready-icon"
|
|
348
417
|
})
|
|
349
418
|
})),
|
|
350
|
-
container =
|
|
419
|
+
container = _render9.container;
|
|
351
420
|
expect(_react.screen.getByTestId('ready-icon')).toBeInTheDocument();
|
|
352
421
|
expect(container.querySelector('.newspack-card-feature__icon')).toBeNull();
|
|
353
422
|
});
|
|
354
|
-
it('applies the descriptor colours inline and rounds
|
|
355
|
-
var
|
|
423
|
+
it('applies the descriptor colours inline and rounds a backed icon', function () {
|
|
424
|
+
var _render0 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
356
425
|
title: "Content gifting",
|
|
357
426
|
icon: {
|
|
358
427
|
node: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
359
428
|
"data-testid": "descriptor-icon"
|
|
360
429
|
}),
|
|
361
430
|
fill: '#003da5',
|
|
362
|
-
backgroundColor: '#dfe7f4'
|
|
363
|
-
radius: 'full'
|
|
431
|
+
backgroundColor: '#dfe7f4'
|
|
364
432
|
}
|
|
365
433
|
})),
|
|
366
|
-
container =
|
|
434
|
+
container = _render0.container;
|
|
367
435
|
var iconContainer = container.querySelector('.newspack-card-feature__icon');
|
|
368
436
|
expect(_react.screen.getByTestId('descriptor-icon')).toBeInTheDocument();
|
|
369
|
-
expect(iconContainer).toHaveClass('newspack-card-feature__icon--
|
|
437
|
+
expect(iconContainer).toHaveClass('newspack-card-feature__icon--has-background');
|
|
370
438
|
expect(iconContainer).toHaveStyle({
|
|
371
439
|
backgroundColor: '#dfe7f4',
|
|
372
440
|
color: '#003da5'
|
|
373
441
|
});
|
|
374
442
|
});
|
|
375
443
|
it('hides the descriptor container from assistive tech, since the title already names the feature', function () {
|
|
376
|
-
var
|
|
444
|
+
var _render1 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
377
445
|
title: "Content gifting",
|
|
378
446
|
icon: {
|
|
379
447
|
node: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {})
|
|
380
448
|
}
|
|
381
449
|
})),
|
|
382
|
-
container =
|
|
450
|
+
container = _render1.container;
|
|
383
451
|
expect(container.querySelector('.newspack-card-feature__icon')).toHaveAttribute('aria-hidden', 'true');
|
|
384
452
|
});
|
|
385
|
-
it('
|
|
386
|
-
var
|
|
387
|
-
title: "Content gifting",
|
|
388
|
-
icon: {
|
|
389
|
-
node: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {}),
|
|
390
|
-
backgroundColor: '#dfe7f4'
|
|
391
|
-
}
|
|
392
|
-
})),
|
|
393
|
-
container = _render0.container;
|
|
394
|
-
var iconContainer = container.querySelector('.newspack-card-feature__icon');
|
|
395
|
-
expect(iconContainer).toHaveClass('newspack-card-feature__icon--radius-small');
|
|
396
|
-
expect(iconContainer).not.toHaveClass('newspack-card-feature__icon--radius-full');
|
|
397
|
-
});
|
|
398
|
-
it('leaves an unbacked descriptor icon without a radius class', function () {
|
|
399
|
-
var _render1 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
453
|
+
it('leaves an unbacked descriptor icon without the background class', function () {
|
|
454
|
+
var _render10 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
400
455
|
title: "Content gifting",
|
|
401
456
|
icon: {
|
|
402
457
|
node: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {}),
|
|
403
458
|
fill: '#003da5'
|
|
404
459
|
}
|
|
405
460
|
})),
|
|
406
|
-
container =
|
|
461
|
+
container = _render10.container;
|
|
407
462
|
var iconContainer = container.querySelector('.newspack-card-feature__icon');
|
|
408
|
-
expect(iconContainer).not.toHaveClass('newspack-card-feature__icon--
|
|
463
|
+
expect(iconContainer).not.toHaveClass('newspack-card-feature__icon--has-background');
|
|
409
464
|
});
|
|
410
465
|
});
|
|
411
466
|
it('passes className through to the card element', function () {
|
|
412
|
-
var
|
|
467
|
+
var _render11 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
413
468
|
title: "Content gifting",
|
|
414
469
|
className: "newspack-subscribers__card"
|
|
415
470
|
})),
|
|
416
|
-
container =
|
|
471
|
+
container = _render11.container;
|
|
417
472
|
expect(container.querySelector('.newspack-card-feature')).toHaveClass('newspack-subscribers__card');
|
|
418
473
|
});
|
|
419
474
|
it('marks the card as muted only when requirements are set', function () {
|
|
420
|
-
var
|
|
475
|
+
var _render12 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
421
476
|
title: "Content gifting",
|
|
422
477
|
enabled: true
|
|
423
478
|
})),
|
|
424
|
-
container =
|
|
425
|
-
rerender =
|
|
479
|
+
container = _render12.container,
|
|
480
|
+
rerender = _render12.rerender;
|
|
426
481
|
expect(container.querySelector('.newspack-card-feature--muted')).toBeNull();
|
|
427
482
|
rerender(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index["default"], {
|
|
428
483
|
title: "Content gifting",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _i18n = require("@wordpress/i18n");
|
|
8
|
+
var _icons = require("@wordpress/icons");
|
|
9
|
+
require("./style.scss");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
/**
|
|
12
|
+
* Debug Badge
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Debug Badge component.
|
|
25
|
+
*
|
|
26
|
+
* Gates itself on `window.newspack_aux_data.is_debug_mode`, so consumers render
|
|
27
|
+
* it unconditionally and it stays absent outside debug mode.
|
|
28
|
+
*
|
|
29
|
+
* @return {JSX.Element|null} Debug Badge component, or nothing outside debug mode.
|
|
30
|
+
*/var DebugBadge = function DebugBadge() {
|
|
31
|
+
var _window$newspack_aux_;
|
|
32
|
+
if (!((_window$newspack_aux_ = window.newspack_aux_data) !== null && _window$newspack_aux_ !== void 0 && _window$newspack_aux_.is_debug_mode)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
36
|
+
className: "newspack-debug-badge",
|
|
37
|
+
role: "img",
|
|
38
|
+
"aria-label": (0, _i18n.__)('Debug mode', 'newspack-plugin'),
|
|
39
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
|
|
40
|
+
icon: _icons.bug
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var _default = exports["default"] = DebugBadge;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _ = _interopRequireDefault(require("."));
|
|
6
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
7
|
+
/**
|
|
8
|
+
* External dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
describe('DebugBadge', function () {
|
|
16
|
+
afterEach(function () {
|
|
17
|
+
delete window.newspack_aux_data;
|
|
18
|
+
});
|
|
19
|
+
it('renders the badge and its glyph in debug mode', function () {
|
|
20
|
+
window.newspack_aux_data = {
|
|
21
|
+
is_debug_mode: true
|
|
22
|
+
};
|
|
23
|
+
var _render = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {})),
|
|
24
|
+
container = _render.container;
|
|
25
|
+
expect(container.querySelector('.newspack-debug-badge')).toBeInTheDocument();
|
|
26
|
+
expect(container.querySelector('.newspack-debug-badge > svg')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
it('names itself for assistive tech', function () {
|
|
29
|
+
window.newspack_aux_data = {
|
|
30
|
+
is_debug_mode: true
|
|
31
|
+
};
|
|
32
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {}));
|
|
33
|
+
expect(_react.screen.getByRole('img', {
|
|
34
|
+
name: 'Debug mode'
|
|
35
|
+
})).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
it('renders nothing outside debug mode', function () {
|
|
38
|
+
window.newspack_aux_data = {
|
|
39
|
+
is_debug_mode: false
|
|
40
|
+
};
|
|
41
|
+
var _render2 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {})),
|
|
42
|
+
container = _render2.container;
|
|
43
|
+
expect(container).toBeEmptyDOMElement();
|
|
44
|
+
});
|
|
45
|
+
it('renders nothing when the global is absent', function () {
|
|
46
|
+
var _render3 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"], {})),
|
|
47
|
+
container = _render3.container;
|
|
48
|
+
expect(container).toBeEmptyDOMElement();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debug Badge
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@use "~@wordpress/base-styles/colors" as wp-colors;
|
|
6
|
+
@use "~@wordpress/base-styles/variables" as wp-vars;
|
|
7
|
+
@use "../../../colors/colors.module" as np-colors;
|
|
8
|
+
|
|
9
|
+
.newspack-debug-badge {
|
|
10
|
+
background: np-colors.$primary-600;
|
|
11
|
+
border-radius: wp-vars.$radius-round;
|
|
12
|
+
bottom: 0;
|
|
13
|
+
box-shadow: var(--wpds-elevation-sm, #{wp-vars.$elevation-small});
|
|
14
|
+
display: grid;
|
|
15
|
+
height: wp-vars.$button-size;
|
|
16
|
+
margin: 0 wp-vars.$grid-unit-30 wp-vars.$grid-unit-30;
|
|
17
|
+
place-items: center;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
position: fixed;
|
|
20
|
+
width: wp-vars.$button-size;
|
|
21
|
+
z-index: 9997;
|
|
22
|
+
|
|
23
|
+
> svg {
|
|
24
|
+
fill: wp-colors.$white;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -53,17 +53,30 @@ describe('EmptyState.Root', function () {
|
|
|
53
53
|
gap: 'var(--wpds-dimension-gap-2xl, 32px)'
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
+
it('tightens the stack gap when small', function () {
|
|
57
|
+
var _render4 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
58
|
+
size: "small",
|
|
59
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
60
|
+
children: "body"
|
|
61
|
+
})
|
|
62
|
+
})),
|
|
63
|
+
container = _render4.container;
|
|
64
|
+
var stack = container.querySelector('.newspack-empty-state').firstElementChild;
|
|
65
|
+
expect(stack).toHaveStyle({
|
|
66
|
+
gap: 'var(--wpds-dimension-gap-xl, 24px)'
|
|
67
|
+
});
|
|
68
|
+
});
|
|
56
69
|
|
|
57
70
|
// Consumers key `:has()` selectors off this class, so losing it changes their
|
|
58
71
|
// layout without failing anything.
|
|
59
72
|
it('merges className onto the grid', function () {
|
|
60
|
-
var
|
|
73
|
+
var _render5 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
61
74
|
className: "consumer-empty-state",
|
|
62
75
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
63
76
|
children: "body"
|
|
64
77
|
})
|
|
65
78
|
})),
|
|
66
|
-
container =
|
|
79
|
+
container = _render5.container;
|
|
67
80
|
expect(container.querySelector('.newspack-empty-state')).toHaveClass('consumer-empty-state');
|
|
68
81
|
});
|
|
69
82
|
|
|
@@ -80,13 +93,13 @@ describe('EmptyState.Root', function () {
|
|
|
80
93
|
});
|
|
81
94
|
describe('EmptyState.Header', function () {
|
|
82
95
|
it('renders the title and description in the header', function () {
|
|
83
|
-
var
|
|
96
|
+
var _render6 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
84
97
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
85
98
|
title: "Get started with newsletters",
|
|
86
99
|
description: "Compose and send."
|
|
87
100
|
})
|
|
88
101
|
})),
|
|
89
|
-
container =
|
|
102
|
+
container = _render6.container;
|
|
90
103
|
expect(container.querySelector('.newspack-empty-state__title')).toHaveTextContent('Get started with newsletters');
|
|
91
104
|
expect(container.querySelector('.newspack-empty-state__description')).toHaveTextContent('Compose and send.');
|
|
92
105
|
});
|
|
@@ -94,13 +107,13 @@ describe('EmptyState.Header', function () {
|
|
|
94
107
|
// Spacing comes from the stacks, so a margin creeping back onto the heading or
|
|
95
108
|
// paragraph would silently widen every gap.
|
|
96
109
|
it('spaces the header from its stacks rather than from margins', function () {
|
|
97
|
-
var
|
|
110
|
+
var _render7 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
98
111
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
99
112
|
title: "Get started with newsletters",
|
|
100
113
|
description: "Compose and send."
|
|
101
114
|
})
|
|
102
115
|
})),
|
|
103
|
-
container =
|
|
116
|
+
container = _render7.container;
|
|
104
117
|
var header = container.querySelector('.newspack-empty-state__header');
|
|
105
118
|
expect(header).toHaveStyle({
|
|
106
119
|
flexDirection: 'column',
|
|
@@ -114,33 +127,33 @@ describe('EmptyState.Header', function () {
|
|
|
114
127
|
});
|
|
115
128
|
});
|
|
116
129
|
it('wraps the icon in the disc', function () {
|
|
117
|
-
var
|
|
130
|
+
var _render8 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
118
131
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
119
132
|
title: "Get started with newsletters",
|
|
120
133
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {})
|
|
121
134
|
})
|
|
122
135
|
})),
|
|
123
|
-
container =
|
|
136
|
+
container = _render8.container;
|
|
124
137
|
expect(container.querySelector('.newspack-empty-state__icon svg')).toBeInTheDocument();
|
|
125
138
|
});
|
|
126
139
|
it('omits the description and the icon when they are not given', function () {
|
|
127
|
-
var
|
|
140
|
+
var _render9 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
128
141
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
129
142
|
title: "Get started with newsletters"
|
|
130
143
|
})
|
|
131
144
|
})),
|
|
132
|
-
container =
|
|
145
|
+
container = _render9.container;
|
|
133
146
|
expect(container.querySelector('.newspack-empty-state__description')).not.toBeInTheDocument();
|
|
134
147
|
expect(container.querySelector('.newspack-empty-state__icon')).not.toBeInTheDocument();
|
|
135
148
|
});
|
|
136
149
|
it('renders an h2 and a 48px icon at the default size', function () {
|
|
137
|
-
var
|
|
150
|
+
var _render0 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
138
151
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
139
152
|
title: "Get started with newsletters",
|
|
140
153
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {})
|
|
141
154
|
})
|
|
142
155
|
})),
|
|
143
|
-
container =
|
|
156
|
+
container = _render0.container;
|
|
144
157
|
expect(_react.screen.getByRole('heading', {
|
|
145
158
|
level: 2,
|
|
146
159
|
name: 'Get started with newsletters'
|
|
@@ -149,14 +162,14 @@ describe('EmptyState.Header', function () {
|
|
|
149
162
|
expect(container.querySelector('.newspack-empty-state__icon svg')).toHaveAttribute('width', '48');
|
|
150
163
|
});
|
|
151
164
|
it('drops to an h3, the small modifier and a 24px icon when the root is small', function () {
|
|
152
|
-
var
|
|
165
|
+
var _render1 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
153
166
|
size: "small",
|
|
154
167
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
155
168
|
title: "No products match this rule",
|
|
156
169
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {})
|
|
157
170
|
})
|
|
158
171
|
})),
|
|
159
|
-
container =
|
|
172
|
+
container = _render1.container;
|
|
160
173
|
expect(container.querySelector('.newspack-empty-state__header--small')).toBeInTheDocument();
|
|
161
174
|
expect(_react.screen.getByRole('heading', {
|
|
162
175
|
level: 3,
|
|
@@ -181,13 +194,13 @@ describe('EmptyState.Header', function () {
|
|
|
181
194
|
})).toBeInTheDocument();
|
|
182
195
|
});
|
|
183
196
|
it('carries its own class hook alongside any className', function () {
|
|
184
|
-
var
|
|
197
|
+
var _render10 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
185
198
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
186
199
|
title: "Get started with newsletters",
|
|
187
200
|
className: "consumer-header"
|
|
188
201
|
})
|
|
189
202
|
})),
|
|
190
|
-
container =
|
|
203
|
+
container = _render10.container;
|
|
191
204
|
var header = container.querySelector('.newspack-empty-state__header');
|
|
192
205
|
expect(header).toBeInTheDocument();
|
|
193
206
|
expect(header).toHaveClass('consumer-header');
|
|
@@ -211,11 +224,11 @@ describe('EmptyState.Header', function () {
|
|
|
211
224
|
var previous = process.env.NODE_ENV;
|
|
212
225
|
process.env.NODE_ENV = 'production';
|
|
213
226
|
try {
|
|
214
|
-
var
|
|
227
|
+
var _render11 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Header, {
|
|
215
228
|
title: "Orphan",
|
|
216
229
|
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {})
|
|
217
230
|
})),
|
|
218
|
-
container =
|
|
231
|
+
container = _render11.container;
|
|
219
232
|
expect(_react.screen.getByRole('heading', {
|
|
220
233
|
level: 2,
|
|
221
234
|
name: 'Orphan'
|
|
@@ -229,7 +242,7 @@ describe('EmptyState.Header', function () {
|
|
|
229
242
|
});
|
|
230
243
|
describe('EmptyState.Actions', function () {
|
|
231
244
|
it('renders its children in a centred row', function () {
|
|
232
|
-
var
|
|
245
|
+
var _render12 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
233
246
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Actions, {
|
|
234
247
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
235
248
|
type: "button",
|
|
@@ -237,7 +250,7 @@ describe('EmptyState.Actions', function () {
|
|
|
237
250
|
})
|
|
238
251
|
})
|
|
239
252
|
})),
|
|
240
|
-
container =
|
|
253
|
+
container = _render12.container;
|
|
241
254
|
expect(container.querySelector('.newspack-empty-state__actions')).toBeInTheDocument();
|
|
242
255
|
expect(container.querySelector('.newspack-empty-state__actions')).toHaveStyle({
|
|
243
256
|
justifyContent: 'center',
|
|
@@ -248,7 +261,7 @@ describe('EmptyState.Actions', function () {
|
|
|
248
261
|
})).toBeInTheDocument();
|
|
249
262
|
});
|
|
250
263
|
it('stacks into a column while keeping the hook class', function () {
|
|
251
|
-
var
|
|
264
|
+
var _render13 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Root, {
|
|
252
265
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_["default"].Actions, {
|
|
253
266
|
orientation: "column",
|
|
254
267
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
@@ -260,7 +273,7 @@ describe('EmptyState.Actions', function () {
|
|
|
260
273
|
})]
|
|
261
274
|
})
|
|
262
275
|
})),
|
|
263
|
-
container =
|
|
276
|
+
container = _render13.container;
|
|
264
277
|
var actions = container.querySelector('.newspack-empty-state__actions');
|
|
265
278
|
expect(actions).toBeInTheDocument();
|
|
266
279
|
expect(actions).toHaveStyle({
|
|
@@ -291,10 +304,10 @@ describe('EmptyState.Actions', function () {
|
|
|
291
304
|
var previous = process.env.NODE_ENV;
|
|
292
305
|
process.env.NODE_ENV = 'production';
|
|
293
306
|
try {
|
|
294
|
-
var
|
|
307
|
+
var _render14 = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_["default"].Actions, {
|
|
295
308
|
children: "x"
|
|
296
309
|
})),
|
|
297
|
-
container =
|
|
310
|
+
container = _render14.container;
|
|
298
311
|
expect(container.querySelector('.newspack-empty-state__actions')).toBeInTheDocument();
|
|
299
312
|
} finally {
|
|
300
313
|
process.env.NODE_ENV = previous;
|
|
@@ -37,6 +37,7 @@ var Root = function Root(_ref) {
|
|
|
37
37
|
size: size
|
|
38
38
|
};
|
|
39
39
|
}, [size]);
|
|
40
|
+
var isSmall = size === 'small';
|
|
40
41
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.EmptyStateContext.Provider, {
|
|
41
42
|
value: context,
|
|
42
43
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_grid["default"], {
|
|
@@ -46,7 +47,7 @@ var Root = function Root(_ref) {
|
|
|
46
47
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ui.Stack, _objectSpread(_objectSpread({
|
|
47
48
|
className: "newspack-empty-state__stack",
|
|
48
49
|
direction: "column",
|
|
49
|
-
gap:
|
|
50
|
+
gap: isSmall ? 'xl' : '2xl'
|
|
50
51
|
}, gridColumn), {}, {
|
|
51
52
|
children: children
|
|
52
53
|
}))
|