Skip to content

Commit aa5cb77

Browse files
authored
Merge pull request #74 from NHSDigital/feature/deprecatePanelAndPromo
NHS.UK 4 - Deprecate Panel and Promo components
2 parents d2ca132 + c80dd09 commit aa5cb77

File tree

27 files changed

+203
-68
lines changed

27 files changed

+203
-68
lines changed

.storybook/storybook.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
@import '../node_modules/nhsuk-frontend/dist/nhsuk.css';
1+
// Also import styles for deprecated Panel and Promo
2+
@import '../node_modules/nhsuk-frontend-legacy/packages/core/all.scss';
3+
@import '../node_modules/nhsuk-frontend-legacy/packages/components/panel/panel';
4+
@import '../node_modules/nhsuk-frontend-legacy/packages/components/promo/promo';
5+
6+
// Allow current nhsuk styles to override legacy
7+
@import '../node_modules/nhsuk-frontend/packages/nhsuk.scss';
28

39
.tag-wrapper {
410
display: flex;

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,18 @@ The `WarningCallout.Label` now has the hidden text `Important: ` before the labe
4949
## Hint component renders as div
5050

5151
The `Hint` component now renders as a `div` element rather than a `span`.
52+
53+
## Deprecation of Panel & Promo Components
54+
55+
The `Panel` and `Promo` components have been removed from `nhsuk-frontend` since version 4.0.0. As a result, we have deprecated these components. These components work exactly as they did before, with the only difference being a slightly different import.
56+
57+
```jsx
58+
// Old Imports
59+
import { Button, Panel, Promo } from "nhsuk-react-components";
60+
61+
// New Imports
62+
import { Button } from "nhsuk-react-components";
63+
import { Panel, Promo } from "nhsuk-react-components/deprecated";
64+
```
65+
66+
A warning is printed to the console in dev environments when using these components, as they are set to be removed in the next major release.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"jest": "^26.6.1",
4848
"jest-axe": "^3.4.0",
4949
"nhsuk-frontend": "^4.1.0",
50+
"nhsuk-frontend-legacy": "npm:[email protected]",
5051
"node-sass": "^4.14.1",
5152
"prettier": "^1.18.2",
5253
"react": "^16.9.3",

rollup.config.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
import typescript from 'rollup-plugin-typescript2';
22
import pkg from './package.json';
33

4-
export default {
5-
input: 'src/index.ts',
6-
output: [
7-
{ file: pkg.main, format: 'cjs' },
8-
{ file: pkg.module, format: 'es' },
9-
],
10-
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
11-
plugins: [
12-
typescript({
13-
typescript: require('typescript'),
14-
exclude: ['**/*.test.d.ts'],
15-
}),
16-
],
17-
};
4+
export default [
5+
{
6+
input: 'src/index.ts',
7+
output: [
8+
{ file: pkg.main, format: 'cjs' },
9+
{ file: pkg.module, format: 'es' },
10+
],
11+
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
12+
plugins: [
13+
typescript({
14+
typescript: require('typescript'),
15+
exclude: ['**/*.test.d.ts'],
16+
}),
17+
],
18+
},
19+
{
20+
input: 'src/deprecated/index.ts',
21+
output: [
22+
{ file: 'dist/deprecated.js', format: 'cjs' },
23+
{ file: 'dist/deprecated.es.js', format: 'es' },
24+
],
25+
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
26+
plugins: [
27+
typescript({
28+
typescript: require('typescript'),
29+
exclude: ['**/*.test.d.ts'],
30+
}),
31+
],
32+
},
33+
];

src/__tests__/index.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ describe('Index', () => {
4949
'ListPanel',
5050
'NavAZ',
5151
'Pagination',
52-
'Panel',
53-
'Promo',
5452
'Radios',
5553
'ReviewDate',
5654
'Select',

src/components/checkboxes/Checkboxes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Checkboxes extends PureComponent<CheckboxesProps, CheckboxesState> {
2121

2222
private boxIds: Record<string, string> = {};
2323

24-
constructor(props: {}) {
24+
constructor(props: CheckboxesProps) {
2525
super(props);
2626
this.state = {
2727
conditionalBoxes: [],

src/components/date-input/DateInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DateInputChangeEvent = ChangeEvent<HTMLInputElement> & {
1717

1818
interface DateInputProps
1919
extends Omit<HTMLProps<HTMLDivElement>, 'value' | 'defaultValue'>,
20-
FormElementProps {
20+
FormElementProps {
2121
autoSelectNext?: boolean;
2222
value?: Partial<DateInputValue>;
2323
defaultValue?: Partial<DateInputValue>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as deprecatedIndex from '../index';
2+
3+
describe('DeprecatedIndex', () => {
4+
it('contains all expected elements', () => {
5+
expect(Object.keys(deprecatedIndex)).toEqual(['Panel', 'Promo']);
6+
});
7+
});
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, { HTMLProps, isValidElement } from 'react';
22
import classNames from 'classnames';
3-
import { Row, Col } from '../layout';
3+
import { Row, Col } from '../../../components/layout';
44
import PanelContext, { PanelContextType } from './PanelContext';
5+
import useDevWarning from '../../../util/hooks/UseDevWarning';
6+
import { PanelDeprecationWarning } from '../../warnings';
57

68
interface PanelProps extends HTMLProps<HTMLDivElement> {
79
grey?: boolean;
@@ -20,24 +22,28 @@ const BasePanel: React.FC<PanelProps> = ({
2022
labelProps,
2123
children,
2224
...rest
23-
}) => (
24-
<div
25-
className={classNames(
26-
{ 'nhsuk-panel': !label },
27-
{ 'nhsuk-panel--grey': grey },
28-
{ 'nhsuk-panel-with-label': label },
29-
className,
30-
)}
31-
{...rest}
32-
>
33-
{label ? (
34-
<h3 className="nhsuk-panel-with-label__label" {...labelProps}>
35-
{label}
36-
</h3>
37-
) : null}
38-
{children}
39-
</div>
40-
);
25+
}) => {
26+
useDevWarning(PanelDeprecationWarning);
27+
28+
return (
29+
<div
30+
className={classNames(
31+
{ 'nhsuk-panel': !label },
32+
{ 'nhsuk-panel--grey': grey },
33+
{ 'nhsuk-panel-with-label': label },
34+
className,
35+
)}
36+
{...rest}
37+
>
38+
{label ? (
39+
<h3 className="nhsuk-panel-with-label__label" {...labelProps}>
40+
{label}
41+
</h3>
42+
) : null}
43+
{children}
44+
</div>
45+
);
46+
};
4147

4248
const Panel: Panel = props => {
4349
const PanelGroupContext = React.useContext<PanelContextType | null>(PanelContext);
File renamed without changes.

0 commit comments

Comments
 (0)