@hmlr/govuk-react-components-library 1.0.3 → 1.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.
package/.stylelintrc.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "extends": [
3
3
  "stylelint-config-standard",
4
4
  "stylelint-config-standard-scss",
5
- "stylelint-config-idiomatic-order"
5
+ "stylelint-config-recess-order"
6
6
  ],
7
7
  "plugins": ["stylelint-order"]
8
8
  }
package/README.md CHANGED
@@ -39,6 +39,7 @@ The Components includes:
39
39
  - [Details](./src/components/Details/Details.tsx)
40
40
  - [ErrorMessage](./src/components/ErrorMessage/ErrorMessage.tsx)
41
41
  - [ErrorSummary](./src/components/ErrorSummary/ErrorSummary.tsx) `👈🏽`
42
+ - [ExitThisPage](./src/components/ExitThisPage/ExitThisPage.tsx) `👈🏽`
42
43
  - [Fieldset](./src/components/Fieldset/Fieldset.tsx)
43
44
  - [FileUpload](./src/components/FileUpload/FileUpload.tsx)
44
45
  - [Footer](./src/components/Footer/Footer.tsx)
@@ -48,8 +49,9 @@ The Components includes:
48
49
  - [InsetText](./src/components/InsetText/InsetText.tsx)
49
50
  - [Label](./src/components/Label/Label.tsx)
50
51
  - [NotificationBanner](./src/components/NotificationBanner/NotificationBanner.tsx)
51
- - [Pagination](./src/components/Pagination/Pagination.tsx)
52
+ - [Pagination](./src/components/Pagination/Pagination.tsx) — see [migration guide](#pagination-migration) if upgrading from v1.0.3 or earlier
52
53
  - [Panel](./src/components/Panel/Panel.tsx)
54
+ - [PasswordInput](./src/components/PasswordInput/PasswordInput.tsx) `👈🏽`
53
55
  - [PhaseBanner](./src/components/PhaseBanner/PhaseBanner.tsx)
54
56
  - [Radios](./src/components/Radios/Radios.tsx) `👈🏽`
55
57
  - [Select](./src/components/Select/Select.tsx)
@@ -95,8 +97,10 @@ There are some convenience functions that can be used to configure components wi
95
97
  - [ConfigureOverallButton](./src/components/Button/Button.config.tsx) - Sets overall behavior and configurations for all button or in a scope (document or specified element) as per [govuk-frontend button api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#button).
96
98
  - [ConfigureOverallCheckboxes](./src/components/Checkboxes/Checkboxes.config.tsx) - Sets overall behavior and configurations for all checkboxes or in a scope.
97
99
  - [ConfigureOverallErrorSummary](./src/components/ErrorSummary/ErrorSummary.config.tsx) - Sets overall behavior and configurations for all error summary or in a scope (document or specified element) as per [govuk-frontend error-summary api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#errorsummary).
100
+ - [ConfigureOverallExitThisPage](./src/components/ExitThisPage/ExitThisPage.config.ts) - Initialises the Exit This Page component or in a scope (document or specified element) as per [govuk-frontend exit-this-page api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#exit-this-page).
98
101
  - [ConfigureOverallHeader](./src/components/Header/Header.config.tsx) - Sets overall behavior and configurations for all Header or in a scope.
99
102
  - [ConfigureOverallRadios](./src/components/Radios/Radios.config.tsx) - Sets overall behavior and configurations for all Radios or in a scope.
103
+ - [ConfigureOverallPasswordInput](./src/components/PasswordInput/PasswordInput.config.ts) - Initialises the Password Input show/hide toggle or in a scope (document or specified element) as per [govuk-frontend password-input api reference](https://frontend.design-system.service.gov.uk/javascript-api-reference/#password-input).
100
104
  - [ConfigureOverallSkipLink](./src/components/SkipLink/SkipLink.config.tsx) - Sets overall behavior and configurations for all SkipLink or in a scope.
101
105
  - [ConfigureOverallTabs](./src/components/Tabs/Tabs.config.tsx) - Sets overall behavior and configurations for all Tabs or in a scope.
102
106
 
@@ -397,6 +401,215 @@ or in html
397
401
 
398
402
  </details>
399
403
 
404
+ ## Pagination migration
405
+
406
+ The `Pagination` component API changed in v1.1.0. The previous API was computation-driven — you supplied raw counts and the component calculated the page range internally. The new API is render-driven: you supply the exact items to display, mirroring the [GOV.UK Design System pagination fixture shape](https://design-system.service.gov.uk/components/pagination/). This means the rendered HTML matches the Design System exactly and consumers have full control over what is shown.
407
+
408
+ <details>
409
+ <summary>Basic numbered pagination</summary>
410
+
411
+ **Before (v1.0.3 and earlier)**
412
+
413
+ ```jsx
414
+ import { Pagination } from "@hmlr/govuk-react-components-library";
415
+
416
+ <Pagination
417
+ onPageChange={setPage}
418
+ currentPage={2}
419
+ totalCount={75}
420
+ pageSize={25}
421
+ />;
422
+ ```
423
+
424
+ **After (v1.1.0+)**
425
+
426
+ ```jsx
427
+ import { Pagination } from "@hmlr/govuk-react-components-library";
428
+
429
+ <Pagination
430
+ previous={{ href: "/page/1" }}
431
+ next={{ href: "/page/3" }}
432
+ items={[
433
+ { number: 1, href: "/page/1" },
434
+ { number: 2, href: "/page/2", current: true },
435
+ { number: 3, href: "/page/3" },
436
+ ]}
437
+ />;
438
+ ```
439
+
440
+ </details>
441
+
442
+ <details>
443
+ <summary>First page (no previous link)</summary>
444
+
445
+ **Before**
446
+
447
+ ```jsx
448
+ <Pagination
449
+ onPageChange={setPage}
450
+ currentPage={1}
451
+ totalCount={75}
452
+ pageSize={25}
453
+ />
454
+ ```
455
+
456
+ **After** — omit `previous`, the component renders no previous link
457
+
458
+ ```jsx
459
+ <Pagination
460
+ next={{ href: "/page/2" }}
461
+ items={[
462
+ { number: 1, href: "/page/1", current: true },
463
+ { number: 2, href: "/page/2" },
464
+ { number: 3, href: "/page/3" },
465
+ ]}
466
+ />
467
+ ```
468
+
469
+ </details>
470
+
471
+ <details>
472
+ <summary>Many pages with ellipsis</summary>
473
+
474
+ **Before**
475
+
476
+ ```jsx
477
+ <Pagination
478
+ onPageChange={setPage}
479
+ currentPage={10}
480
+ totalCount={400}
481
+ pageSize={10}
482
+ siblingCount={1}
483
+ />
484
+ ```
485
+
486
+ **After** — ellipsis positions are explicit via `{ ellipsis: true }` items
487
+
488
+ ```jsx
489
+ <Pagination
490
+ previous={{ href: "/page/9" }}
491
+ next={{ href: "/page/11" }}
492
+ items={[
493
+ { number: 1, href: "/page/1" },
494
+ { ellipsis: true },
495
+ { number: 9, href: "/page/9" },
496
+ { number: 10, href: "/page/10", current: true },
497
+ { number: 11, href: "/page/11" },
498
+ { ellipsis: true },
499
+ { number: 40, href: "/page/40" },
500
+ ]}
501
+ />
502
+ ```
503
+
504
+ </details>
505
+
506
+ <details>
507
+ <summary>Previous / next only with labels (block layout)</summary>
508
+
509
+ **Before**
510
+
511
+ ```jsx
512
+ <Pagination
513
+ onPageChange={setPage}
514
+ currentPage={2}
515
+ totalCount={50}
516
+ pageSize={25}
517
+ previousName="Previous page"
518
+ nextName="Next page"
519
+ previousChildren={
520
+ <span className="govuk-pagination__link-label">Paying VAT and duty</span>
521
+ }
522
+ nextChildren={
523
+ <span className="govuk-pagination__link-label">
524
+ Registering an imported vehicle
525
+ </span>
526
+ }
527
+ />
528
+ ```
529
+
530
+ **After** — omitting `items` automatically applies `govuk-pagination--block` layout
531
+
532
+ ```jsx
533
+ <Pagination
534
+ previous={{
535
+ href: "/page/1",
536
+ children: "Previous page",
537
+ labelText: "Paying VAT and duty",
538
+ }}
539
+ next={{
540
+ href: "/page/3",
541
+ children: "Next page",
542
+ labelText: "Registering an imported vehicle",
543
+ }}
544
+ />
545
+ ```
546
+
547
+ </details>
548
+
549
+ <details>
550
+ <summary>Computing items dynamically with UsePagination</summary>
551
+
552
+ If your page data is calculated at runtime, `UsePagination` is still available as a standalone hook. Call it yourself and map the result to the `items` format:
553
+
554
+ ```jsx
555
+ import {
556
+ Pagination,
557
+ UsePagination,
558
+ DOTS,
559
+ } from "@hmlr/govuk-react-components-library";
560
+
561
+ function SearchResults({ totalCount, pageSize, currentPage, onPageChange }) {
562
+ const totalPages = Math.ceil(totalCount / pageSize);
563
+
564
+ const items = UsePagination({
565
+ totalCount,
566
+ pageSize,
567
+ siblingCount: 1,
568
+ currentPage,
569
+ })?.map((entry) =>
570
+ entry === DOTS
571
+ ? { ellipsis: true }
572
+ : {
573
+ number: entry,
574
+ href: `/results?page=${entry}`,
575
+ current: entry === currentPage,
576
+ },
577
+ );
578
+
579
+ return (
580
+ <Pagination
581
+ previous={
582
+ currentPage > 1
583
+ ? { href: `/results?page=${currentPage - 1}` }
584
+ : undefined
585
+ }
586
+ next={
587
+ currentPage < totalPages
588
+ ? { href: `/results?page=${currentPage + 1}` }
589
+ : undefined
590
+ }
591
+ items={items}
592
+ />
593
+ );
594
+ }
595
+ ```
596
+
597
+ </details>
598
+
599
+ ### Removed props
600
+
601
+ | Removed prop | Replacement |
602
+ | ------------------ | ------------------------------------------------------------- |
603
+ | `onPageChange` | Handle navigation via `href` on `previous` / `next` / `items` |
604
+ | `currentPage` | Set `current: true` on the relevant item in `items` |
605
+ | `totalCount` | Not needed — pass items directly |
606
+ | `pageSize` | Not needed — pass items directly |
607
+ | `siblingCount` | Not needed — control ellipsis placement via `items` |
608
+ | `previousName` | `previous.children` |
609
+ | `nextName` | `next.children` |
610
+ | `previousChildren` | `previous.labelText` |
611
+ | `nextChildren` | `next.labelText` |
612
+
400
613
  ## Usage
401
614
 
402
615
  Use the above components like the Panel component:
@@ -646,6 +859,7 @@ git push --follow-tags origin main
646
859
  and publish as an npm package run
647
860
 
648
861
  ```bash
862
+ npm config set //registry.npmjs.org/:_authToken={$NPM_TOKEN}
649
863
  npm publish
650
864
  ```
651
865