Skip to content

Commit b79cf0f

Browse files
chazdeanlaurkim
andcommitted
[Typography foundations] Add deprecation warnings for existing Text components (#6605)
~~#### WARNING ⚠️~~ ~~https://polaris.shopify.com/components/text is not currently active~~ ~~Do Not Merge!~~ Fixes #6537 <!-- link to issue if one exists --> <!-- Context about the problem that’s being addressed. --> Add deprecation warnings to all of the following existing Text components: - TextStyle - DisplayText - Heading - Subheading - Caption - VisuallyHidden | Text component | `console.log` | | --- | --- | | <img width="870" alt="Screen Shot 2022-07-12 at 10 12 53 AM" src="https://user-images.githubusercontent.com/59836805/178513139-742442e5-ccdc-4591-b0ad-b5ad0a19cbf0.png"> | <img width="633" alt="Screen Shot 2022-07-12 at 10 12 23 AM" src="https://user-images.githubusercontent.com/59836805/178513188-95c3db0e-0536-4de8-8396-fc36cf876818.png"> | Co-authored-by: Lo Kim <[email protected]>
1 parent de19332 commit b79cf0f

File tree

14 files changed

+99
-2
lines changed

14 files changed

+99
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Deprecated `DisplayText`, `Heading`, `Subheading`, `Caption`, `TextStyle`, and `VisuallyHidden` components

polaris-react/playground/DetailsPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import {
2020
ActionList,
2121
Badge,
22+
// eslint-disable-next-line import/no-deprecated
2223
Caption,
2324
Card,
2425
ContextualSaveBar,
@@ -41,6 +42,7 @@ import {
4142
Thumbnail,
4243
Toast,
4344
TopBar,
45+
// eslint-disable-next-line import/no-deprecated
4446
VisuallyHidden,
4547
} from '../src';
4648

polaris-react/src/components/Caption/Caption.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ export interface CaptionProps {
77
children?: React.ReactNode;
88
}
99

10+
/**
11+
* @deprecated The Caption component will be removed in the next
12+
* major version. Use the Text component instead. See the
13+
* Polaris component guide on how to use Text.
14+
*
15+
* https://polaris.shopify.com/components/text
16+
*/
1017
export function Caption({children}: CaptionProps) {
18+
if (process.env.NODE_ENV === 'development') {
19+
// eslint-disable-next-line no-console
20+
console.warn(
21+
'Deprecation: The `Caption` component has been deprecated. Use the `Text` component instead. See the Polaris component guide on how to use `Text`. https://polaris.shopify.com/components/text',
22+
);
23+
}
24+
1125
return <p className={styles.Caption}>{children}</p>;
1226
}

polaris-react/src/components/Caption/tests/Caption.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

4+
// eslint-disable-next-line import/no-deprecated
45
import {Caption} from '../Caption';
56

67
describe('<Caption />', () => {

polaris-react/src/components/DisplayText/DisplayText.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export interface DisplayTextProps {
2222
children?: React.ReactNode;
2323
}
2424

25+
/**
26+
* @deprecated The DisplayText component will be removed in the next
27+
* major version. Use the Text component instead. See the
28+
* Polaris component guide on how to use Text.
29+
*
30+
* https://polaris.shopify.com/components/text
31+
*/
2532
export function DisplayText({
2633
element: Element = 'p',
2734
children,
@@ -32,5 +39,12 @@ export function DisplayText({
3239
size && styles[variationName('size', size)],
3340
);
3441

42+
if (process.env.NODE_ENV === 'development') {
43+
// eslint-disable-next-line no-console
44+
console.warn(
45+
'Deprecation: The `DisplayText` component has been deprecated. Use the `Text` component instead. See the Polaris component guide on how to use `Text`. https://polaris.shopify.com/components/text',
46+
);
47+
}
48+
3549
return <Element className={className}>{children}</Element>;
3650
}

polaris-react/src/components/DisplayText/tests/DisplayText.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

4+
// eslint-disable-next-line import/no-deprecated
45
import {DisplayText} from '../DisplayText';
56

67
describe('<DisplayText />', () => {

polaris-react/src/components/Heading/Heading.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ export interface HeadingProps {
1616
id?: string;
1717
}
1818

19+
/**
20+
* @deprecated The Heading component will be removed in the next
21+
* major version. Use the Text component instead. See the
22+
* Polaris component guide on how to use Text.
23+
*
24+
* https://polaris.shopify.com/components/text
25+
*/
1926
export function Heading({element: Element = 'h2', children, id}: HeadingProps) {
27+
if (process.env.NODE_ENV === 'development') {
28+
// eslint-disable-next-line no-console
29+
console.warn(
30+
'Deprecation: The `Heading` component has been deprecated. Use the `Text` component instead. See the Polaris component guide on how to use `Text`. https://polaris.shopify.com/components/text',
31+
);
32+
}
33+
2034
return (
2135
<Element className={styles.Heading} id={id}>
2236
{children}

polaris-react/src/components/Heading/tests/Heading.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

4+
// eslint-disable-next-line import/no-deprecated
45
import {Heading} from '../Heading';
56

67
describe('<Heading />', () => {

polaris-react/src/components/Subheading/Subheading.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ export interface SubheadingProps {
1313
/** Text to display in subheading */
1414
children?: React.ReactNode;
1515
}
16-
16+
/**
17+
* @deprecated The Subheading component will be removed in the next
18+
* major version. Use the Text component instead. See the
19+
* Polaris component guide on how to use Text.
20+
*
21+
* https://polaris.shopify.com/components/text
22+
*/
1723
export function Subheading({
1824
element: Element = 'h3',
1925
children,
2026
}: SubheadingProps) {
2127
const ariaLabel = typeof children === 'string' ? children : undefined;
28+
29+
if (process.env.NODE_ENV === 'development') {
30+
// eslint-disable-next-line no-console
31+
console.warn(
32+
'Deprecation: The `Subheading` component has been deprecated. Use the `Text` component instead. See the Polaris component guide on how to use `Text`. https://polaris.shopify.com/components/text',
33+
);
34+
}
35+
2236
return (
2337
<Element aria-label={ariaLabel} className={styles.Subheading}>
2438
{children}

polaris-react/src/components/Subheading/tests/Subheading.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

44
import {Button} from '../../Button';
5+
// eslint-disable-next-line import/no-deprecated
56
import {Subheading} from '../Subheading';
67

78
describe('<Subheading />', () => {

0 commit comments

Comments
 (0)