Skip to content

Commit 7565cc4

Browse files
Use named exports and package imports
1 parent af5bf75 commit 7565cc4

File tree

257 files changed

+1173
-1055
lines changed

Some content is hidden

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

257 files changed

+1173
-1055
lines changed

babel.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ module.exports = {
3434
env: {
3535
test: {
3636
browserslistEnv: 'node',
37+
plugins: [
38+
// Override package.json "imports" for Jest to use sources
39+
// otherwise a build step to output `./dist` is necessary
40+
[
41+
'module-resolver',
42+
{
43+
alias: {
44+
'#components': './src/components',
45+
'#patterns': './src/patterns',
46+
'#util': './src/util',
47+
'nhsuk-react-components': './src/index.ts',
48+
},
49+
},
50+
],
51+
],
3752
},
3853
},
3954
};

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
"dist"
1010
],
1111
"sideEffects": false,
12+
"imports": {
13+
"#components/*": {
14+
"import": "./dist/esm/components/*",
15+
"require": "./dist/cjs/components/*"
16+
},
17+
"#patterns/*": {
18+
"import": "./dist/esm/patterns/*",
19+
"require": "./dist/cjs/patterns/*"
20+
},
21+
"#patterns": {
22+
"import": "./dist/esm/patterns/index.js",
23+
"require": "./dist/cjs/patterns/index.js"
24+
},
25+
"#util/*": {
26+
"import": "./dist/esm/util/*",
27+
"require": "./dist/cjs/util/*"
28+
}
29+
},
1230
"exports": {
1331
".": {
1432
"import": {
@@ -68,6 +86,7 @@
6886
"@typescript-eslint/eslint-plugin": "^7.1.0",
6987
"@typescript-eslint/parser": "^7.1.0",
7088
"babel-jest": "^29.7.0",
89+
"babel-plugin-module-resolver": "^5.0.2",
7190
"chromatic": "^6.17.3",
7291
"eslint": "^8.57.0",
7392
"eslint-config-airbnb": "^19.0.4",

src/__tests__/index.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as index from '../index';
1+
import * as index from '..';
22

33
describe('Index', () => {
44
it('contains all expected elements', () => {
@@ -15,26 +15,34 @@ describe('Index', () => {
1515
'Breadcrumb',
1616
'Button',
1717
'Card',
18+
'CardContext',
1819
'CharacterCount',
1920
'Checkboxes',
21+
'CheckboxesContext',
2022
'ChevronRightCircleIcon',
2123
'Clearfix',
2224
'Col',
2325
'Container',
2426
'ContentsList',
2527
'CrossIcon',
2628
'DateInput',
29+
'DateInputContext',
2730
'Details',
2831
'DoAndDontList',
2932
'ErrorMessage',
3033
'ErrorSummary',
3134
'Fieldset',
3235
'Footer',
3336
'Form',
37+
'FormContext',
3438
'FormGroup',
39+
'FormGroupContext',
3540
'Header',
41+
'HeaderContext',
42+
'HeadingLevel',
3643
'Hero',
3744
'HintText',
45+
'Icon',
3846
'Images',
3947
'InsetText',
4048
'Label',
@@ -43,6 +51,7 @@ describe('Index', () => {
4351
'NavAZ',
4452
'Pagination',
4553
'Radios',
54+
'RadiosContext',
4655
'ReadingWidth',
4756
'ReviewDate',
4857
'Row',
@@ -51,6 +60,9 @@ describe('Index', () => {
5160
'SkipLink',
5261
'SummaryList',
5362
'Table',
63+
'TableContext',
64+
'TableSection',
65+
'TableSectionContext',
5466
'Tabs',
5567
'Tag',
5668
'Textarea',

src/components/content-presentation/details/Details.tsx

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

44
export interface DetailsProps extends ComponentPropsWithoutRef<'details'> {
55
expander?: boolean;
@@ -40,7 +40,7 @@ DetailsSummary.displayName = 'Details.Summary';
4040
DetailsText.displayName = 'Details.Text';
4141
ExpanderGroup.displayName = 'Details.ExpanderGroup';
4242

43-
export default Object.assign(DetailsComponent, {
43+
export const Details = Object.assign(DetailsComponent, {
4444
Summary: DetailsSummary,
4545
Text: DetailsText,
4646
ExpanderGroup,

src/components/content-presentation/details/__tests__/Details.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { createRef } from 'react';
21
import { render } from '@testing-library/react';
3-
import { renderClient, renderServer } from '@util/components';
4-
import Details from '../';
2+
import React, { createRef } from 'react';
3+
import { Details } from '..';
4+
import { renderClient, renderServer } from '#util/components';
55

66
describe('Details', () => {
77
it('matches snapshot', async () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './Details';
1+
export * from './Details';

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import classNames from 'classnames';
12
import React, {
2-
ComponentPropsWithoutRef,
3-
FC,
43
createContext,
5-
useContext,
6-
ReactNode,
74
forwardRef,
5+
useContext,
6+
type ComponentPropsWithoutRef,
7+
type FC,
8+
type ReactNode,
89
} from 'react';
9-
import classNames from 'classnames';
10-
import { Tick, Cross } from '@components/content-presentation/icons';
11-
import HeadingLevel, { HeadingLevelProps } from '@components/utils/HeadingLevel';
10+
import { CrossIcon, TickIcon } from '#components/content-presentation';
11+
import { HeadingLevel, type HeadingLevelProps } from '#components/utils';
1212

1313
type ListType = 'do' | 'dont';
1414

@@ -53,12 +53,12 @@ const DoAndDontItem: FC<DoAndDontItemProps> = ({ prefixText, listItemType, child
5353
<li {...rest}>
5454
{(listItemType || listItem) === 'do' ? (
5555
<>
56-
<Tick />
56+
<TickIcon />
5757
{actualPrefix}
5858
</>
5959
) : (
6060
<>
61-
<Cross />
61+
<CrossIcon />
6262
{actualPrefix}
6363
</>
6464
)}
@@ -70,6 +70,6 @@ const DoAndDontItem: FC<DoAndDontItemProps> = ({ prefixText, listItemType, child
7070
DoAndDontListComponent.displayName = 'DoAndDontList';
7171
DoAndDontItem.displayName = 'DoAndDontList.Item';
7272

73-
export default Object.assign(DoAndDontListComponent, {
73+
export const DoAndDontList = Object.assign(DoAndDontListComponent, {
7474
Item: DoAndDontItem,
7575
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { createRef } from 'react';
21
import { render } from '@testing-library/react';
3-
import DoAndDontList from '../';
4-
import { renderClient, renderServer } from '@util/components';
2+
import React, { createRef } from 'react';
3+
import { DoAndDontList } from '..';
4+
import { renderClient, renderServer } from '#util/components';
55

66
describe('DoAndDontList', () => {
77
describe('list type "do"', () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './DoAndDontList';
1+
export * from './DoAndDontList';

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { ComponentPropsWithoutRef, FC, forwardRef } from 'react';
21
import classNames from 'classnames';
3-
import { Container, Row, Col } from '../../layout';
4-
import HeadingLevel, { HeadingLevelProps } from '@components/utils/HeadingLevel';
2+
import React, { forwardRef, type ComponentPropsWithoutRef, type FC } from 'react';
3+
import { Col, Container, Row } from '#components/layout';
4+
import { HeadingLevel, type HeadingLevelProps } from '#components/utils';
55

66
export interface HeroContentProps extends ComponentPropsWithoutRef<'div'> {
77
hasImage: boolean;
@@ -73,7 +73,7 @@ HeroComponent.displayName = 'Hero';
7373
HeroHeading.displayName = 'Hero.Heading';
7474
HeroText.displayName = 'Hero.Text';
7575

76-
export default Object.assign(HeroComponent, {
76+
export const Hero = Object.assign(HeroComponent, {
7777
Heading: HeroHeading,
7878
Text: HeroText,
7979
});

0 commit comments

Comments
 (0)