-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathPanel.tsx
More file actions
39 lines (32 loc) · 1.1 KB
/
Panel.tsx
File metadata and controls
39 lines (32 loc) · 1.1 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
import classNames from 'classnames';
import { Children, type ComponentPropsWithoutRef, forwardRef } from 'react';
import { childIsOfComponentType } from '#util/types/TypeGuards.js';
import { PanelTitle } from './components/index.js';
export interface PanelProps extends ComponentPropsWithoutRef<'div'> {
interruption?: boolean;
}
const PanelComponent = forwardRef<HTMLDivElement, PanelProps>(
({ children, className, interruption, ...rest }, forwardedRef) => {
const items = Children.toArray(children);
const title = items.find((child) => childIsOfComponentType(child, PanelTitle));
const bodyItems = items.filter((child) => child !== title);
return (
<div
className={classNames(
'nhsuk-panel',
{ 'nhsuk-panel--interruption': interruption },
className,
)}
ref={forwardedRef}
{...rest}
>
{title}
{bodyItems ? <div className="nhsuk-panel__body">{bodyItems}</div> : null}
</div>
);
},
);
PanelComponent.displayName = 'Panel';
export const Panel = Object.assign(PanelComponent, {
Title: PanelTitle,
});