Skip to content

Commit e0686d4

Browse files
mengX666Meng-atl
andauthored
Add deprecated styling on deprecated props (#225)
* add deprecated styling * docs(changeset): Changed the heading styles for deprecated props and removed "@deprecated" from the prop description. * add a deprecated prop to story examples Co-authored-by: mengX666 <[email protected]>
1 parent eab7424 commit e0686d4

File tree

8 files changed

+97
-17
lines changed

8 files changed

+97
-17
lines changed

.changeset/angry-pets-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pretty-proptypes': patch
3+
---
4+
5+
Changed the heading styles for deprecated props and removed "@deprecated" from the prop description.

packages/pretty-proptypes/src/HybridLayout/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { Component, type Node } from 'react';
99
import md from 'react-markings';
1010
import PropsWrapper from '../Props/Wrapper';
1111
import LayoutRenderer, { type LayoutRendererProps } from '../LayoutRenderer';
12-
import { HeadingType, HeadingDefault, Heading, HeadingRequired } from '../Prop/Heading';
12+
import {
13+
HeadingType,
14+
HeadingDefault,
15+
Heading,
16+
HeadingRequired,
17+
HeadingDeprecated
18+
} from '../Prop/Heading';
1319
import { colors } from '../components/constants';
1420

1521
type DynamicPropsProps = LayoutRendererProps & {
@@ -46,6 +52,7 @@ export default class HybridLayout extends Component<DynamicPropsProps> {
4652
defaultValue,
4753
description,
4854
required,
55+
deprecated,
4956
name,
5057
type,
5158
componentDisplayName,
@@ -103,6 +110,7 @@ export default class HybridLayout extends Component<DynamicPropsProps> {
103110
padding: 4px 8px;
104111
line-height: 20px;
105112
display: inline-block;
113+
text-decoration: ${deprecated ? 'line-through' : 'none'};
106114
`}
107115
>
108116
{name}
@@ -117,12 +125,28 @@ export default class HybridLayout extends Component<DynamicPropsProps> {
117125
required
118126
</HeadingRequired>
119127
)}
128+
{deprecated && (
129+
<HeadingDeprecated
130+
css={css`
131+
margin-left: 1em;
132+
color: ${colors.N300};
133+
`}
134+
>
135+
deprecated
136+
</HeadingDeprecated>
137+
)}
120138
</Heading>
121139
</caption>
122140
<tbody>
123141
<tr>
124142
<th scope="row">Description</th>
125-
<td>{description && <Description>{md([description])}</Description>}</td>
143+
<td>
144+
{description && (
145+
<Description>
146+
{md([description && description.replace('@deprecated', '')])}
147+
</Description>
148+
)}
149+
</td>
126150
</tr>
127151
{defaultValue !== undefined && (
128152
<tr>

packages/pretty-proptypes/src/Prop/Heading.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export const HeadingRequired = (props: { children: Node }) => (
3838
/>
3939
);
4040

41+
export const HeadingDeprecated = (props: { children: Node }) => (
42+
<code
43+
css={css`
44+
color: ${colors.N300};
45+
`}
46+
{...props}
47+
/>
48+
);
49+
4150
export const HeadingType = (props: { children: Node }) => (
4251
<code
4352
css={css`
@@ -70,20 +79,24 @@ const Whitespace = () => ' ';
7079
type PropTypeHeadingProps = {
7180
name: any,
7281
required: boolean,
82+
deprecated?: boolean,
7383
type: any,
7484
// This is probably giving up
7585
defaultValue?: any
7686
};
7787

7888
const PropTypeHeading = (props: PropTypeHeadingProps) => (
7989
<Heading>
80-
<HeadingName>{props.name}</HeadingName>
90+
<HeadingName style={{ textDecoration: props.deprecated ? 'line-through' : 'none' }}>
91+
{props.name}
92+
</HeadingName>
8193
<Whitespace />
8294
<HeadingType>{props.type}</HeadingType>
8395
{props.defaultValue !== undefined && <HeadingDefault> = {props.defaultValue}</HeadingDefault>}
8496
{props.required && props.defaultValue === undefined ? (
8597
<HeadingRequired> required</HeadingRequired>
8698
) : null}
99+
{props.deprecated && <HeadingDeprecated> deprecated</HeadingDeprecated>}
87100
</Heading>
88101
);
89102

packages/pretty-proptypes/src/Prop/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default class Prop extends Component<PropProps> {
3838
description,
3939
name,
4040
required,
41+
deprecated,
4142
type,
4243
components,
4344
componentDisplayName
@@ -47,8 +48,19 @@ export default class Prop extends Component<PropProps> {
4748
<PropTypeWrapper
4849
{...(componentDisplayName ? { id: `${componentDisplayName}-${name}` } : null)}
4950
>
50-
<PropTypeHeading name={name} required={required} type={type} defaultValue={defaultValue} />
51-
{description && <components.Description>{md([description])}</components.Description>}
51+
<PropTypeHeading
52+
name={name}
53+
required={required}
54+
type={type}
55+
defaultValue={defaultValue}
56+
deprecated={deprecated}
57+
/>
58+
{description && (
59+
<components.Description>
60+
{' '}
61+
{md([deprecated ? description.replace('@deprecated', '') : description])}
62+
</components.Description>
63+
)}
5264
<ShapeComponent {...commonProps} />
5365
</PropTypeWrapper>
5466
);

packages/pretty-proptypes/src/renderPropType.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import convert, { getKind, reduceToObj } from 'kind2string';
55
import allComponents from './components';
66

77
const IGNORE_COMMENTS_STARTING_WITH = ['eslint-disable', '@ts-'];
8+
const DEPRECATE_PROPS_THAT_CONTAIN = '@deprecated';
89
const HIDE_PROPS_THAT_CONTAIN = ['@internal', '@access private'];
910

1011
const shouldIgnoreComment = comment => {
@@ -37,6 +38,14 @@ const shouldHideProp = comment => {
3738
return false;
3839
};
3940

41+
const shouldDeprecateProp = comment => {
42+
if (!comment) {
43+
return false;
44+
}
45+
46+
return comment.includes(DEPRECATE_PROPS_THAT_CONTAIN);
47+
};
48+
4049
const renderPropType = (
4150
propType: any,
4251
{ overrides = {}, shouldCollapseProps, components, componentDisplayName = {} }: any,
@@ -88,6 +97,7 @@ const renderPropType = (
8897
name={name}
8998
description={description}
9099
required={!propType.optional}
100+
deprecated={shouldDeprecateProp(description)}
91101
type={getKind(propType.value)}
92102
defaultValue={propType.default && convert(propType.default)}
93103
shouldCollapse={shouldCollapseProps}

packages/pretty-proptypes/src/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type CommonProps = {
77
defaultValue?: string,
88
description?: string,
99
required: boolean,
10+
deprecated?: boolean,
1011
name: string,
1112
typeValue: Kind,
1213
type: string,

stories/TypeScriptComponent.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ type TypeScriptComponentProps = {
4141
// @internal
4242
hideProp: Boolean;
4343
nocomment: boolean;
44+
/**
45+
* @deprecated
46+
* This prop is deprecated
47+
*/
48+
deprecatedProp: boolean;
4449
};
4550

4651
const TypeScriptComponent = (props: TypeScriptComponentProps) => <p>Hello World</p>;
@@ -59,7 +64,8 @@ TypeScriptComponent.defaultProps = {
5964
anyProp: 'any',
6065
unionProp: 'hello',
6166
unknownProp: 'hello',
62-
unsupportedProp: 'text'
67+
unsupportedProp: 'text',
68+
deprecatedProp: true
6369
};
6470

6571
export default TypeScriptComponent;

stories/layout/LayoutRenderer.stories.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Heading,
99
HeadingDefault,
1010
HeadingRequired,
11+
HeadingDeprecated,
1112
HeadingType
1213
} from '../../packages/pretty-proptypes/src/Prop/Heading';
1314
import { colors } from '../../packages/pretty-proptypes/src/components/constants';
@@ -41,10 +42,6 @@ const rowStyles = css`
4142
tbody {
4243
border-bottom: none;
4344
}
44-
45-
&:target {
46-
background: #e9f2ff;
47-
}
4845
`;
4946

5047
const headingStyles = css`
@@ -74,6 +71,11 @@ const headingRequiredStyles = css`
7471
color: ${colors.R400};
7572
`;
7673

74+
const headingDeprecatedStyles = css`
75+
margin-left: 1em;
76+
color: ${colors.N300};
77+
`;
78+
7779
Base.args = {
7880
component: (
7981
<div>
@@ -88,25 +90,32 @@ Base.args = {
8890
name,
8991
type,
9092
components,
91-
componentDisplayName
93+
deprecated
9294
}) => (
93-
<table
94-
css={rowStyles}
95-
{...(componentDisplayName ? { id: `${componentDisplayName}-${name}` } : null)}
96-
>
95+
<table css={rowStyles}>
9796
<caption css={captionStyles}>
9897
<Heading css={headingStyles}>
99-
<code css={headingCodeStyles}>{name}</code>
98+
<code
99+
css={headingCodeStyles}
100+
style={{ textDecoration: deprecated ? 'line-through' : 'none' }}
101+
>
102+
{name}
103+
</code>
100104
{required && defaultValue === undefined && (
101105
<HeadingRequired css={headingRequiredStyles}>required</HeadingRequired>
102106
)}
107+
{deprecated && (
108+
<HeadingDeprecated css={headingDeprecatedStyles}>deprecated</HeadingDeprecated>
109+
)}
103110
</Heading>
104111
</caption>
105112
<tbody>
106113
<tr>
107114
<th scope="row">Description</th>
108115
<td>
109-
<components.Description>{md([description])}</components.Description>
116+
<components.Description>
117+
{md([description && description.replace('@deprecated', '')])}
118+
</components.Description>
110119
</td>
111120
</tr>
112121
{defaultValue !== undefined && (

0 commit comments

Comments
 (0)