Skip to content

Commit

Permalink
Migrate components to patterns, rework components removed from NHSUK …
Browse files Browse the repository at this point in the history
…frontend
  • Loading branch information
jakeb-nhs committed Mar 25, 2024
1 parent d2b7f4b commit 0af2c84
Show file tree
Hide file tree
Showing 30 changed files with 758 additions and 675 deletions.
36 changes: 36 additions & 0 deletions docs/upgrade-to-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,42 @@ Should become this:
It is now required that a `js-enabled` class is added to a parent element if JavaScript is enabled (we suggest using `body`). E.g. `<body class="js-enabled">`.
This is to facilitate a differentiation in styling to the header depending on whether JavaScript is enabled or disabled.

### Care Card is now a variant of Card

CareCard has been removed as a standalone component and the Card component has been refactored to provide this functionality. This is achieved via the `cardType` prop.

Notice also that the `immediate` type of card is unsupported - this has been replaced with `emergency`.

Before, using the CareCard, you may have markup that looks like this:

```
<CareCard type='immediate'>
<CareCard.Heading>Call 999 if:</CareCard.Heading>
<CareCard.Content>
<div>Your care card contents</div>
</CareCard.Content>
</CareCard>
```

Now, it should look like this:

```
<Card cardType='emergency'>
<Card.Heading>Call 999 if:</CareCard.Heading>
<Card.Content>
<div>Your care card contents</div>
</Card.Content>
</Card>
```

### NavAZ and ListPanel

Due to these components being [removed from the nhsuk-frontend library](https://github.com/nhsuk/nhsuk-frontend/blob/main/CHANGELOG.md#600---29-november-2021), refactoring has taken place to ensure they still adhere to the NHS digital service manual.

The `NavAZ` component is still available, however the `ListPanel` component has now been renamed to `Panel`. To combine multiple panels you would simply render them as siblings - there is no need to wrap them in a list.

An additional storybook story has been added to give a full example of an A-Z page, combining both of these components. This helps to bring this library into alignment with the [NHS digital service manual listing](https://service-manual.nhs.uk/design-system/patterns/a-to-z-page) for this pattern.

## New features

### Text input prefixes + suffixes
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ describe('Index', () => {
'InsetText',
'Label',
'LedeText',
'ListPanel',
'MinusIcon',
'NavAZ',
'Pagination',
'Panel',
'PlusIcon',
'Radios',
'ReadingWidth',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import CharacterCount, { CharacterCountType } from '../CharacterCount';
import { Label, HintText, Textarea } from '../../../..';
import Label from '@components/form-elements/label/Label';
import HintText from '@components/form-elements/hint-text/HintText';
import Textarea from '@components/form-elements/textarea/Textarea';

describe('Character Count', () => {
it('Matches snapshot', () => {
Expand Down
95 changes: 0 additions & 95 deletions src/components/list-panel/ListPanel.tsx

This file was deleted.

64 changes: 0 additions & 64 deletions src/components/list-panel/__tests__/ListPanel.test.tsx

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/list-panel/index.ts

This file was deleted.

50 changes: 30 additions & 20 deletions src/components/navigation/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CardHeading from './components/CardHeading';
import CardGroup from './components/CardGroup';
import CardGroupItem from './components/CardGroupItem';
import { CardType } from '@util/types/NHSUKTypes';
import { cardTypeIsCareCard } from '@util/types/TypeGuards';

interface CardProps extends HTMLProps<HTMLDivElement> {
clickable?: boolean;
Expand All @@ -25,26 +26,35 @@ interface ICard extends React.FC<CardProps> {
GroupItem: typeof CardGroupItem;
}

const Card: ICard = ({ className, clickable, children, cardType, ...rest }) => (
<div
className={classNames(
'nhsuk-card',
{ 'nhsuk-card--clickable': clickable },
{ 'nhsuk-card--feature': cardType === 'feature' },
{ 'nhsuk-card--secondary': cardType === 'secondary' },
className,
)}
{...rest}
>
<CardContext.Provider
value={{
cardType,
}}
>
{children}
</CardContext.Provider>
</div>
);
const Card: ICard = ({ className, clickable, children, cardType, ...rest }) => {
let cardClassNames = classNames(
'nhsuk-card',
{ 'nhsuk-card--clickable': clickable },
{ 'nhsuk-card--feature': cardType === 'feature' },
{ 'nhsuk-card--secondary': cardType === 'secondary' },
className,
);

if (cardTypeIsCareCard(cardType)) {
cardClassNames = classNames(
cardClassNames,
'nhsuk-card--care',
`nhsuk-card--care--${cardType}`,
);
}

return (
<div className={cardClassNames} {...rest}>
<CardContext.Provider
value={{
cardType,
}}
>
{children}
</CardContext.Provider>
</div>
);
};

Card.Heading = CardHeading;
Card.Description = CardDescription;
Expand Down
Loading

0 comments on commit 0af2c84

Please sign in to comment.