-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDoAndDontList.tsx
More file actions
42 lines (35 loc) · 1.48 KB
/
DoAndDontList.tsx
File metadata and controls
42 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use client';
import classNames from 'classnames';
import { type ComponentPropsWithoutRef, forwardRef } from 'react';
import { Heading, type HeadingProps } from '#components/typography/Heading.js';
import { DoAndDontListContext, type DoAndDontListType } from './DoAndDontListContext.js';
import { DoAndDontListItem } from './components/index.js';
export interface DoAndDontListProps
extends ComponentPropsWithoutRef<'div'>, Pick<HeadingProps, 'headingLevel'> {
listType: DoAndDontListType;
heading?: string;
}
const DoAndDontListComponent = forwardRef<HTMLDivElement, DoAndDontListProps>(
({ className, listType, children, heading, headingLevel = 'h3', ...rest }, forwardedRef) => (
<div className={classNames('nhsuk-do-dont-list', className)} ref={forwardedRef} {...rest}>
<Heading className="nhsuk-do-dont-list__label" headingLevel={headingLevel}>
{heading || (listType === 'do' ? 'Do' : "Don't")}
</Heading>
{/* eslint-disable-next-line jsx-a11y/no-redundant-roles */}
<ul
className={classNames(
'nhsuk-list',
{ 'nhsuk-list--tick': listType === 'do' },
{ 'nhsuk-list--cross': listType === 'dont' },
)}
role="list"
>
<DoAndDontListContext.Provider value={listType}>{children}</DoAndDontListContext.Provider>
</ul>
</div>
),
);
DoAndDontListComponent.displayName = 'DoAndDontList';
export const DoAndDontList = Object.assign(DoAndDontListComponent, {
Item: DoAndDontListItem,
});