Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nhsuk-frontend-react): add missing summary-list variant #176

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-items-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nhsuk-frontend-react": patch
---

fix(nhsuk-frontend-react): add missing summary-list variant
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import React from 'react';
import { it, expect } from 'vitest';
import { render } from '@testing-library/react';
import { composeStory } from '@storybook/react';
import meta, { Default as DefaultStory } from './SummaryList.stories';
import meta, {
Default as DefaultStory,
NoBorder as NoBorderStory,
} from './SummaryList.stories';

const Default = composeStory(DefaultStory, meta);
const NoBorder = composeStory(NoBorderStory, meta);

it('should render the SummaryList component', () => {
const { container } = render(<Default />);
Expand All @@ -14,3 +18,15 @@ it('should render the SummaryList component', () => {
container.querySelectorAll('a > .nhsuk-u-visually-hidden'),
).toHaveLength(4);
});

it('should render the SummaryList component with no border', () => {
const { container } = render(<NoBorder />);

expect(
container.querySelectorAll('.nhsuk-summary-list--no-border'),
).toHaveLength(1);
expect(container).toMatchSnapshot();
expect(
container.querySelectorAll('a > .nhsuk-u-visually-hidden'),
).toHaveLength(4);
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,57 @@ export const Default: Story = {
</SummaryList>
),
};

export const NoBorder: Story = {
args: {
variant: 'no-border',
},
render: (args) => (
<SummaryList {...args}>
<SummaryList.Row>
<SummaryList.Key>Name</SummaryList.Key>
<SummaryList.Value>John Smith</SummaryList.Value>
<SummaryList.Actions>
<SummaryList.ActionLink visuallyHiddenText="name" href="#">
Change
</SummaryList.ActionLink>
</SummaryList.Actions>
</SummaryList.Row>
<SummaryList.Row>
<SummaryList.Key>Date of birth </SummaryList.Key>
<SummaryList.Value>1 January 1990</SummaryList.Value>
<SummaryList.Actions>
<SummaryList.ActionLink visuallyHiddenText="date of birth" href="#">
Change
</SummaryList.ActionLink>
</SummaryList.Actions>
</SummaryList.Row>
<SummaryList.Row>
<SummaryList.Key>Address</SummaryList.Key>
<SummaryList.Value>
1 Smith Street, Smithville, <br />
Smithfield, <br />
Smithshire, <br />
SM1 1SM
</SummaryList.Value>
<SummaryList.Actions>
<SummaryList.ActionLink visuallyHiddenText="address" href="#">
Change
</SummaryList.ActionLink>
</SummaryList.Actions>
</SummaryList.Row>
<SummaryList.Row>
<SummaryList.Key>Contact details</SummaryList.Key>
<SummaryList.Value>
07000 000000 <br />
[email protected]
</SummaryList.Value>
<SummaryList.Actions>
<SummaryList.ActionLink visuallyHiddenText="contact details" href="#">
Change
</SummaryList.ActionLink>
</SummaryList.Actions>
</SummaryList.Row>
</SummaryList>
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { AsElementProps, ElementProps } from '@/types/shared';
import clsx from 'clsx';
import React from 'react';

export type SummaryListProps = ElementProps<'dl'>;
export type SummaryListProps = {
/**
* The variant of the summary list
* @default 'default'
*/
variant?: 'default' | 'no-border';
} & ElementProps<'dl'>;

type SummaryListFactory = Factory<{
props: SummaryListProps;
Expand All @@ -24,10 +30,14 @@ type SummaryListFactory = Factory<{
}>;

const SummaryList = factory<SummaryListFactory>(
({ className, ...props }, ref) => {
({ className, variant, ...props }, ref) => {
return (
<dl
className={clsx('nhsuk-summary-list', className)}
className={clsx(
'nhsuk-summary-list',
{ 'nhsuk-summary-list--no-border': variant === 'no-border' },
className,
)}
{...props}
ref={ref}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,136 @@ exports[`should render the SummaryList component 1`] = `
</dl>
</div>
`;

exports[`should render the SummaryList component with no border 1`] = `
<div>
<dl
class="nhsuk-summary-list nhsuk-summary-list--no-border"
>
<div
class="nhsuk-summary-list__row"
>
<dt
class="nhsuk-summary-list__key"
>
Name
</dt>
<dd
class="nhsuk-summary-list__value"
>
John Smith
</dd>
<dd
class="nhsuk-summary-list__actions"
>
<a
href="#"
>
Change
<span
class="nhsuk-u-visually-hidden"
>

name
</span>
</a>
</dd>
</div>
<div
class="nhsuk-summary-list__row"
>
<dt
class="nhsuk-summary-list__key"
>
Date of birth
</dt>
<dd
class="nhsuk-summary-list__value"
>
1 January 1990
</dd>
<dd
class="nhsuk-summary-list__actions"
>
<a
href="#"
>
Change
<span
class="nhsuk-u-visually-hidden"
>

date of birth
</span>
</a>
</dd>
</div>
<div
class="nhsuk-summary-list__row"
>
<dt
class="nhsuk-summary-list__key"
>
Address
</dt>
<dd
class="nhsuk-summary-list__value"
>
1 Smith Street, Smithville,
<br />
Smithfield,
<br />
Smithshire,
<br />
SM1 1SM
</dd>
<dd
class="nhsuk-summary-list__actions"
>
<a
href="#"
>
Change
<span
class="nhsuk-u-visually-hidden"
>

address
</span>
</a>
</dd>
</div>
<div
class="nhsuk-summary-list__row"
>
<dt
class="nhsuk-summary-list__key"
>
Contact details
</dt>
<dd
class="nhsuk-summary-list__value"
>
07000 000000
<br />
[email protected]
</dd>
<dd
class="nhsuk-summary-list__actions"
>
<a
href="#"
>
Change
<span
class="nhsuk-u-visually-hidden"
>

contact details
</span>
</a>
</dd>
</div>
</dl>
</div>
`;
Loading