Skip to content

Commit 4fd6b8e

Browse files
Update types from HTMLProps to ComponentProps
1 parent a864dd4 commit 4fd6b8e

File tree

76 files changed

+460
-504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+460
-504
lines changed
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33

4-
interface DetailsProps extends HTMLProps<HTMLDetailsElement> {
4+
interface DetailsProps extends ComponentPropsWithoutRef<'details'> {
55
expander?: boolean;
66
}
77

8-
interface DetailsComponent extends FC<DetailsProps> {
9-
Summary: FC<HTMLProps<HTMLDivElement>>;
10-
Text: FC<HTMLProps<HTMLDivElement>>;
11-
ExpanderGroup: FC<HTMLProps<HTMLDivElement>>;
12-
}
13-
14-
const DetailsComponent: DetailsComponent = ({ className, expander, ...rest }) => (
8+
const DetailsComponent: FC<DetailsProps> = ({ className, expander, ...rest }) => (
159
<details
1610
className={classNames('nhsuk-details', { 'nhsuk-expander': expander }, className)}
1711
{...rest}
1812
/>
1913
);
2014

21-
const DetailsSummary: FC<HTMLProps<HTMLDivElement>> = ({ className, children, ...rest }) => (
15+
const DetailsSummary: FC<ComponentPropsWithoutRef<'div'>> = ({ className, children, ...rest }) => (
2216
<summary className={classNames('nhsuk-details__summary', className)} {...rest}>
2317
<span className="nhsuk-details__summary-text">{children}</span>
2418
</summary>
2519
);
2620

27-
const DetailsText: FC<HTMLProps<HTMLDivElement>> = ({ className, ...rest }) => (
21+
const DetailsText: FC<ComponentPropsWithoutRef<'div'>> = ({ className, ...rest }) => (
2822
<div className={classNames('nhsuk-details__text', className)} {...rest} />
2923
);
3024

31-
const ExpanderGroup: FC<HTMLProps<HTMLDivElement>> = ({ className, ...rest }) => (
25+
const ExpanderGroup: FC<ComponentPropsWithoutRef<'div'>> = ({ className, ...rest }) => (
3226
<div className={classNames('nhsuk-expander-group', className)} {...rest} />
3327
);
3428

@@ -37,8 +31,8 @@ DetailsSummary.displayName = 'Details.Summary';
3731
DetailsText.displayName = 'Details.Text';
3832
ExpanderGroup.displayName = 'Details.ExpanderGroup';
3933

40-
DetailsComponent.Summary = DetailsSummary;
41-
DetailsComponent.Text = DetailsText;
42-
DetailsComponent.ExpanderGroup = ExpanderGroup;
43-
44-
export default DetailsComponent;
34+
export default Object.assign(DetailsComponent, {
35+
Summary: DetailsSummary,
36+
Text: DetailsText,
37+
ExpanderGroup: ExpanderGroup,
38+
});

src/components/content-presentation/do-and-dont-list/DoAndDontList.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
'use client';
2-
import React, { FC, HTMLProps, createContext, useContext, ReactNode } from 'react';
2+
import React, { ComponentPropsWithoutRef, FC, createContext, useContext, ReactNode } from 'react';
33
import classNames from 'classnames';
44
import { Tick, Cross } from '@components/content-presentation/icons';
5-
import HeadingLevel, { HeadingLevelType } from '@components/utils/HeadingLevel';
5+
import HeadingLevel, { HeadingLevelProps } from '@components/utils/HeadingLevel';
66

77
type ListType = 'do' | 'dont';
88

9-
interface DoAndDontListProps extends HTMLProps<HTMLDivElement> {
9+
interface DoAndDontListProps
10+
extends ComponentPropsWithoutRef<'div'>,
11+
Pick<HeadingLevelProps, 'headingLevel'> {
1012
listType: ListType;
1113
heading?: string;
12-
headingLevel?: HeadingLevelType;
13-
}
14-
15-
interface DoAndDontListComponent extends FC<DoAndDontListProps> {
16-
Item: FC<DoAndDontItemProps>;
1714
}
1815

1916
const DoAndDontListContext = createContext<ListType>('do');
2017

21-
const DoAndDontListComponent: DoAndDontListComponent = ({
18+
const DoAndDontListComponent: FC<DoAndDontListProps> = ({
2219
className,
2320
listType,
2421
children,
@@ -44,7 +41,7 @@ const DoAndDontListComponent: DoAndDontListComponent = ({
4441
);
4542
};
4643

47-
interface DoAndDontItemProps extends HTMLProps<HTMLLIElement> {
44+
interface DoAndDontItemProps extends ComponentPropsWithoutRef<'li'> {
4845
listItemType?: ListType;
4946
prefixText?: ReactNode;
5047
}
@@ -74,6 +71,6 @@ const DoAndDontItem: FC<DoAndDontItemProps> = ({ prefixText, listItemType, child
7471
DoAndDontListComponent.displayName = 'DoAndDontList';
7572
DoAndDontItem.displayName = 'DoAndDontList.Item';
7673

77-
DoAndDontListComponent.Item = DoAndDontItem;
78-
79-
export default DoAndDontListComponent;
74+
export default Object.assign(DoAndDontListComponent, {
75+
Item: DoAndDontItem,
76+
});

src/components/content-presentation/hero/Hero.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33
import { Container, Row, Col } from '../../layout';
4-
import HeadingLevel, { HeadingLevelType } from '@components/utils/HeadingLevel';
4+
import HeadingLevel, { HeadingLevelProps } from '@components/utils/HeadingLevel';
55

6-
interface HeroContentProps extends HTMLProps<HTMLDivElement> {
6+
interface HeroContentProps extends ComponentPropsWithoutRef<'div'> {
77
hasImage: boolean;
88
}
99

@@ -29,32 +29,23 @@ const HeroContent: FC<HeroContentProps> = ({ children, hasImage }) => {
2929
);
3030
};
3131

32-
interface HeroHeadingProps extends HTMLProps<HTMLHeadingElement> {
33-
headingLevel?: HeadingLevelType;
34-
}
35-
36-
const HeroHeading: FC<HeroHeadingProps> = ({ className, headingLevel = 'h1', ...rest }) => (
32+
const HeroHeading: FC<HeadingLevelProps> = ({ className, headingLevel = 'h1', ...rest }) => (
3733
<HeadingLevel
3834
className={classNames('nhsuk-u-margin-bottom-3', className)}
3935
headingLevel={headingLevel}
4036
{...rest}
4137
/>
4238
);
4339

44-
const HeroText: FC<HTMLProps<HTMLParagraphElement>> = ({ className, ...rest }) => (
40+
const HeroText: FC<ComponentPropsWithoutRef<'p'>> = ({ className, ...rest }) => (
4541
<p className={classNames('nhsuk-body-l nhsuk-u-margin-bottom-0', className)} {...rest} />
4642
);
4743

48-
interface HeroProps extends HTMLProps<HTMLDivElement> {
44+
interface HeroProps extends ComponentPropsWithoutRef<'div'> {
4945
imageSrc?: string;
5046
}
5147

52-
interface HeroComponent extends FC<HeroProps> {
53-
Heading: FC<HeroHeadingProps>;
54-
Text: FC<HTMLProps<HTMLParagraphElement>>;
55-
}
56-
57-
const HeroComponent: HeroComponent = ({ className, children, imageSrc, ...rest }) => (
48+
const HeroComponent: FC<HeroProps> = ({ className, children, imageSrc, ...rest }) => (
5849
<section
5950
className={classNames(
6051
'nhsuk-hero',
@@ -79,7 +70,7 @@ HeroComponent.displayName = 'Hero';
7970
HeroHeading.displayName = 'Hero.Heading';
8071
HeroText.displayName = 'Hero.Text';
8172

82-
HeroComponent.Heading = HeroHeading;
83-
HeroComponent.Text = HeroText;
84-
85-
export default HeroComponent;
73+
export default Object.assign(HeroComponent, {
74+
Heading: HeroHeading,
75+
Text: HeroText,
76+
});

src/components/content-presentation/icons/BaseIcon.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33

4-
export interface BaseIconSVGProps extends HTMLProps<SVGSVGElement> {
5-
crossOrigin?: '' | 'anonymous' | 'use-credentials';
4+
export interface BaseIconSVGProps extends ComponentPropsWithoutRef<'svg'> {
5+
title?: string;
66
modifier?:
77
| 'arrow-left'
88
| 'arrow-right'

src/components/content-presentation/icons/__tests__/Icons.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as Icons from '../';
55
describe('Icons', () => {
66
it('all icons match snapshots', () => {
77
Object.entries(Icons).forEach((icon) => {
8-
const [name, Component] = icon;
9-
const Icon = Component as React.FC<React.HTMLProps<SVGSVGElement>>;
8+
const [name, Icon] = icon;
9+
1010
const { container } = render(<Icon />);
1111

1212
expect(container).toMatchSnapshot(name);

src/components/content-presentation/images/Images.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33

4-
interface ImageProps extends HTMLProps<HTMLImageElement> {
5-
// Overriding the default crossOrigin the default is crossOrigin: string | undefined
6-
// which causes a typescript "incompatible types" error.
7-
crossOrigin?: 'anonymous' | 'use-credentials' | undefined;
4+
interface ImageProps extends ComponentPropsWithoutRef<'img'> {
85
caption?: string;
96
}
107

src/components/content-presentation/inset-text/InsetText.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33

4-
const InsetTextComponent: FC<HTMLProps<HTMLDivElement>> = ({ className, children, ...rest }) => (
4+
const InsetTextComponent: FC<ComponentPropsWithoutRef<'div'>> = ({
5+
className,
6+
children,
7+
...rest
8+
}) => (
59
<div className={classNames('nhsuk-inset-text', className)} {...rest}>
610
<span className="nhsuk-u-visually-hidden">Information: </span>
711
{children}
Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
import React, { FC, HTMLProps } from 'react';
1+
import React, { ComponentPropsWithoutRef, FC } from 'react';
22
import classNames from 'classnames';
33

4-
const SummaryListRow: FC<HTMLProps<HTMLDivElement>> = ({ className, ...rest }) => (
4+
const SummaryListRow: FC<ComponentPropsWithoutRef<'div'>> = ({ className, ...rest }) => (
55
<div className={classNames('nhsuk-summary-list__row', className)} {...rest} />
66
);
77

8-
const SummaryListKey: FC<HTMLProps<HTMLDListElement>> = ({ className, ...rest }) => (
8+
const SummaryListKey: FC<ComponentPropsWithoutRef<'dt'>> = ({ className, ...rest }) => (
99
<dt className={classNames('nhsuk-summary-list__key', className)} {...rest} />
1010
);
1111

12-
const SummaryListValue: FC<HTMLProps<HTMLDListElement>> = ({ className, ...rest }) => (
12+
const SummaryListValue: FC<ComponentPropsWithoutRef<'dd'>> = ({ className, ...rest }) => (
1313
<dd className={classNames('nhsuk-summary-list__value', className)} {...rest} />
1414
);
1515

16-
const SummaryListActions: FC<HTMLProps<HTMLDListElement>> = ({ className, ...rest }) => (
16+
const SummaryListActions: FC<ComponentPropsWithoutRef<'dd'>> = ({ className, ...rest }) => (
1717
<dd className={classNames('nhsuk-summary-list__actions', className)} {...rest} />
1818
);
1919

20-
interface SummaryListProps extends HTMLProps<HTMLDListElement> {
20+
interface SummaryListProps extends ComponentPropsWithoutRef<'dl'> {
2121
noBorder?: boolean;
2222
}
2323

24-
interface SummaryListComponent extends FC<SummaryListProps> {
25-
Row: FC<HTMLProps<HTMLDivElement>>;
26-
Key: FC<HTMLProps<HTMLDListElement>>;
27-
Value: FC<HTMLProps<HTMLDListElement>>;
28-
Actions: FC<HTMLProps<HTMLDListElement>>;
29-
}
30-
31-
const SummaryListComponent: SummaryListComponent = ({ className, noBorder, ...rest }) => (
24+
const SummaryListComponent: FC<SummaryListProps> = ({ className, noBorder, ...rest }) => (
3225
<dl
3326
className={classNames(
3427
'nhsuk-summary-list',
@@ -45,9 +38,9 @@ SummaryListKey.displayName = 'SummaryList.Key';
4538
SummaryListValue.displayName = 'SummaryList.Value';
4639
SummaryListActions.displayName = 'SummaryList.Actions';
4740

48-
SummaryListComponent.Row = SummaryListRow;
49-
SummaryListComponent.Key = SummaryListKey;
50-
SummaryListComponent.Value = SummaryListValue;
51-
SummaryListComponent.Actions = SummaryListActions;
52-
53-
export default SummaryListComponent;
41+
export default Object.assign(SummaryListComponent, {
42+
Row: SummaryListRow,
43+
Key: SummaryListKey,
44+
Value: SummaryListValue,
45+
Actions: SummaryListActions,
46+
});
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
import React, { ComponentProps, FC, HTMLProps, ReactNode, useMemo, useState } from 'react';
1+
import React, {
2+
ComponentPropsWithRef,
3+
ComponentPropsWithoutRef,
4+
FC,
5+
ReactNode,
6+
useMemo,
7+
useState,
8+
} from 'react';
29
import classNames from 'classnames';
310
import TableBody from './components/TableBody';
411
import TableCaption from './components/TableCaption';
5-
import TableCell, { TableCellProps } from './components/TableCell';
12+
import TableCell from './components/TableCell';
613
import TableContainer from './components/TableContainer';
714
import TableHead from './components/TableHead';
815
import TableRow from './components/TableRow';
9-
import TablePanel, { TablePanelProps } from './components/TablePanel';
16+
import TablePanel from './components/TablePanel';
1017
import TableContext, { ITableContext } from './TableContext';
1118

12-
interface TableProps extends HTMLProps<HTMLTableElement> {
19+
interface TableProps extends ComponentPropsWithoutRef<'table'> {
1320
responsive?: boolean;
1421
caption?: ReactNode;
15-
captionProps?: ComponentProps<typeof TableCaption>;
22+
captionProps?: ComponentPropsWithRef<'caption'>;
1623
}
1724

18-
interface TableComponent extends FC<TableProps> {
19-
Body: FC<HTMLProps<HTMLTableSectionElement>>;
20-
Cell: FC<TableCellProps>;
21-
Container: FC<HTMLProps<HTMLDivElement>>;
22-
Head: FC<HTMLProps<HTMLTableSectionElement>>;
23-
Panel: FC<TablePanelProps>;
24-
Row: FC<HTMLProps<HTMLTableRowElement>>;
25-
}
26-
27-
const TableComponent = ({
25+
const TableComponent: FC<TableProps> = ({
2826
caption,
2927
captionProps,
3028
children,
3129
className,
3230
responsive = false,
3331
...rest
34-
}: TableProps) => {
32+
}) => {
3533
const [headings, setHeadings] = useState<string[]>([]);
3634

3735
const contextValue: ITableContext = useMemo(() => {
@@ -61,11 +59,11 @@ const TableComponent = ({
6159

6260
TableComponent.displayName = 'Table';
6361

64-
TableComponent.Container = TableContainer;
65-
TableComponent.Panel = TablePanel;
66-
TableComponent.Head = TableHead;
67-
TableComponent.Body = TableBody;
68-
TableComponent.Row = TableRow;
69-
TableComponent.Cell = TableCell;
70-
71-
export default TableComponent;
62+
export default Object.assign(TableComponent, {
63+
Container: TableContainer,
64+
Panel: TablePanel,
65+
Head: TableHead,
66+
Body: TableBody,
67+
Row: TableRow,
68+
Cell: TableCell,
69+
});
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import classNames from 'classnames';
2-
import React, { FC, HTMLProps } from 'react';
2+
import React, { ComponentPropsWithoutRef, FC } from 'react';
33
import TableSectionContext, { TableSection } from '../TableSectionContext';
44

5-
const TableBody: FC<HTMLProps<HTMLTableSectionElement>> = ({ className, children, ...rest }) => (
5+
const TableBody: FC<ComponentPropsWithoutRef<'tbody'>> = ({ children, className, ...rest }) => (
66
<tbody className={classNames('nhsuk-table__body', className)} {...rest}>
77
<TableSectionContext.Provider value={TableSection.BODY}>
88
{children}
99
</TableSectionContext.Provider>
1010
</tbody>
1111
);
12+
1213
TableBody.displayName = 'Table.Body';
1314

1415
export default TableBody;

0 commit comments

Comments
 (0)