-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathDetails.tsx
More file actions
48 lines (41 loc) · 1.53 KB
/
Details.tsx
File metadata and controls
48 lines (41 loc) · 1.53 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
43
44
45
46
47
48
import classNames from 'classnames';
import { type ComponentPropsWithoutRef, type FC, forwardRef } from 'react';
export interface DetailsProps extends ComponentPropsWithoutRef<'details'> {
expander?: boolean;
}
const DetailsComponent = forwardRef<HTMLDetailsElement, DetailsProps>(
({ className, expander, ...rest }, forwardedRef) => (
<details
className={classNames('nhsuk-details', { 'nhsuk-expander': expander }, className)}
ref={forwardedRef}
{...rest}
/>
),
);
export const DetailsSummary = forwardRef<HTMLElement, ComponentPropsWithoutRef<'div'>>(
({ children, className, ...rest }, forwardedRef) => (
<summary
className={classNames('nhsuk-details__summary', className)}
ref={forwardedRef}
{...rest}
>
<span className="nhsuk-details__summary-text">{children}</span>
</summary>
),
);
export const DetailsText: FC<ComponentPropsWithoutRef<'div'>> = ({ className, ...rest }) => (
<div className={classNames('nhsuk-details__text', className)} {...rest} />
);
export const DetailsExpanderGroup: FC<ComponentPropsWithoutRef<'div'>> = ({
className,
...rest
}) => <div className={classNames('nhsuk-expander-group', className)} {...rest} />;
DetailsComponent.displayName = 'Details';
DetailsSummary.displayName = 'Details.Summary';
DetailsText.displayName = 'Details.Text';
DetailsExpanderGroup.displayName = 'Details.ExpanderGroup';
export const Details = Object.assign(DetailsComponent, {
Summary: DetailsSummary,
Text: DetailsText,
ExpanderGroup: DetailsExpanderGroup,
});