Skip to content

Commit 1ca7a43

Browse files
authored
migrate typography components to typescript (#553)
* migrate typography components to TS * add lint command and fix merge * more leftovers * update jsdoc * rm unneeded changes * export types * rm babel proptype plugin and keep proptypes around * revert unneeded change in tsconfig * s/string/number
1 parent 40d45cf commit 1ca7a43

File tree

18 files changed

+228
-158
lines changed

18 files changed

+228
-158
lines changed

.babelrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"plugins": [
44
"@babel/plugin-transform-runtime",
55
"@babel/plugin-proposal-class-properties",
6-
"babel-plugin-add-react-displayname",
7-
"babel-plugin-typescript-to-proptypes"
6+
"babel-plugin-add-react-displayname"
87
],
98
"env": {
109
"esm": {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"babel-eslint": "^10.0.1",
9090
"babel-loader": "^8.0.5",
9191
"babel-plugin-add-react-displayname": "^0.0.5",
92-
"babel-plugin-typescript-to-proptypes": "^0.17.1",
9392
"concurrently": "^4.0.1",
9493
"enzyme": "^3.7.0",
9594
"enzyme-adapter-react-16": "^1.6.0",

src/text-input/src/TextInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TextInput extends PureComponent<any & React.ComponentProps<typeof Text>> {
4848
theme: PropTypes.object.isRequired,
4949

5050
/**
51-
* Class name passed to the button.
51+
* Class name passed to the input.
5252
* Only use if you know what you are doing.
5353
*/
5454
className: PropTypes.string

src/textarea/src/Textarea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Textarea extends PureComponent<any & React.ComponentProps<typeof Text>> {
5353
theme: PropTypes.object.isRequired,
5454

5555
/**
56-
* Class name passed to the button.
56+
* Class name passed to the textarea.
5757
* Only use if you know what you are doing.
5858
*/
5959
className: PropTypes.string

src/typography/src/Code.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
import React, { PureComponent } from 'react'
1+
import React, { PureComponent, Validator } from 'react'
22
import PropTypes from 'prop-types'
33
import cx from 'classnames'
4-
import { withTheme } from '../../theme'
4+
import { withTheme, Theme } from '../../theme'
55
import Text from './Text'
66

7-
class Code extends PureComponent<any & React.ComponentProps<typeof Text>> {
7+
type Appearance = 'default' | 'minimal'
8+
9+
export interface CodeProps extends React.ComponentProps<typeof Text> {
10+
/**
11+
* The appearance of the code.
12+
*/
13+
appearance: Appearance
14+
15+
/**
16+
* Class name passed to the component.
17+
* Only use if you know what you are doing.
18+
*/
19+
className?: string
20+
21+
/**
22+
* Theme provided by ThemeProvider.
23+
*/
24+
theme: Theme
25+
}
26+
27+
class Code extends PureComponent<CodeProps> {
828
static propTypes = {
9-
/**
10-
* The appearance of the code.
11-
*/
12-
appearance: PropTypes.oneOf(['default', 'minimal']).isRequired,
13-
14-
/**
15-
* Theme provided by ThemeProvider.
16-
*/
17-
theme: PropTypes.object.isRequired,
18-
19-
/**
20-
* Class name passed to the button.
21-
* Only use if you know what you are doing.
22-
*/
23-
className: PropTypes.string
29+
appearance: PropTypes.oneOf(['default', 'minimal']).isRequired as Validator<
30+
Appearance
31+
>,
32+
className: PropTypes.string,
33+
theme: PropTypes.object.isRequired as Validator<Theme>
2434
}
2535

26-
static defaultProps = {
36+
static defaultProps: Partial<CodeProps> = {
2737
appearance: 'default'
2838
}
2939

src/typography/src/Heading.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
import React, { PureComponent } from 'react'
1+
import React, { PureComponent, Validator } from 'react'
22
import PropTypes from 'prop-types'
33
import Box from 'ui-box'
4-
import { withTheme } from '../../theme'
4+
import { withTheme, Theme } from '../../theme'
55

6-
class Heading extends PureComponent<any & React.ComponentProps<typeof Box>> {
7-
static propTypes = {
8-
/**
9-
* The size of the heading.
10-
*/
11-
size: PropTypes.oneOf([100, 200, 300, 400, 500, 600, 700, 800, 900])
12-
.isRequired,
6+
type HeadingSize = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
7+
8+
export interface HeadingProps extends React.ComponentProps<typeof Box> {
9+
/**
10+
* Pass `default` to use the default margin top for that size.
11+
*/
12+
marginTop?: boolean | number | string | 'default'
1313

14-
/**
15-
* Pass `default` to use the default margin top for that size.
16-
*/
14+
/**
15+
* The size of the heading.
16+
*/
17+
size: HeadingSize
18+
19+
/**
20+
* Theme provided by ThemeProvider.
21+
*/
22+
theme: Theme
23+
}
24+
25+
class Heading extends PureComponent<HeadingProps> {
26+
static propTypes = {
1727
marginTop: PropTypes.oneOfType([
1828
PropTypes.bool,
1929
PropTypes.number,
2030
PropTypes.string
2131
]),
22-
23-
/**
24-
* Theme provided by ThemeProvider.
25-
*/
26-
theme: PropTypes.object.isRequired
32+
size: PropTypes.oneOf([100, 200, 300, 400, 500, 600, 700, 800, 900])
33+
.isRequired as Validator<HeadingSize>,
34+
theme: PropTypes.object.isRequired as Validator<Theme>
2735
}
2836

29-
static defaultProps = {
37+
static defaultProps: Partial<HeadingProps> = {
3038
size: 500
3139
}
3240

src/typography/src/Label.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { PureComponent } from 'react'
22
import Text from './Text'
33

4-
export default class Label extends PureComponent<
5-
React.ComponentProps<typeof Text>
6-
> {
4+
export interface LabelProps extends React.ComponentProps<typeof Text> {}
5+
6+
export default class Label extends PureComponent<LabelProps> {
7+
static propTypes = Text.propTypes
8+
79
render() {
810
return <Text is="label" fontWeight={500} {...this.props} />
911
}

src/typography/src/Link.tsx

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
1-
import React, { PureComponent } from 'react'
1+
import React, { PureComponent, Validator } from 'react'
22
import PropTypes from 'prop-types'
33
import cx from 'classnames'
4-
import { withTheme } from '../../theme'
4+
import { withTheme, Theme } from '../../theme'
55
import Text from './Text'
66

7-
class Link extends PureComponent<any & React.ComponentProps<typeof Text>> {
8-
static propTypes = {
9-
/**
10-
* This attribute names a relationship of the linked document to the current document.
11-
* Common use case is: rel="noopener noreferrer".
12-
*/
13-
rel: PropTypes.string,
7+
export interface LinkProps extends React.ComponentProps<typeof Text> {
8+
/**
9+
* Class name passed to the link.
10+
* Only use if you know what you are doing.
11+
*/
12+
className?: string
1413

15-
/**
16-
* Specifies the URL of the linked resource. A URL might be absolute or relative.
17-
*/
18-
href: PropTypes.string,
14+
/**
15+
* The color (and styling) of the Link. Can be default, blue, green or neutral.
16+
*/
17+
color?: string
1918

20-
/**
21-
* Target atrribute, common use case is target="_blank."
22-
*/
23-
target: PropTypes.string,
19+
/**
20+
* Specifies the URL of the linked resource. A URL might be absolute or relative.
21+
*/
22+
href?: string
23+
24+
/**
25+
* This attribute names a relationship of the linked document to the current document.
26+
* Common use case is: rel="noopener noreferrer".
27+
*/
28+
rel?: string
29+
30+
/**
31+
* Target atrribute, common use case is target="_blank."
32+
*/
33+
target?: string
2434

25-
/**
26-
* The color (and styling) of the Link. Can be default, blue, green or neutral.
27-
*/
28-
color: PropTypes.string.isRequired,
29-
30-
/**
31-
* Theme provided by ThemeProvider.
32-
*/
33-
theme: PropTypes.object.isRequired,
34-
35-
/**
36-
* Class name passed to the link.
37-
* Only use if you know what you are doing.
38-
*/
39-
className: PropTypes.string
35+
/**
36+
* Theme provided by ThemeProvider.
37+
*/
38+
theme: Theme
39+
}
40+
41+
class Link extends PureComponent<LinkProps> {
42+
static propTypes = {
43+
className: PropTypes.string,
44+
color: PropTypes.string,
45+
href: PropTypes.string,
46+
rel: PropTypes.string,
47+
target: PropTypes.string,
48+
theme: PropTypes.object.isRequired as Validator<Theme>
4049
}
4150

4251
static defaultProps = {

src/typography/src/ListItem.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ import PropTypes from 'prop-types'
33
import { Icon } from '../../icon'
44
import Text from './Text'
55

6-
export default class ListItem extends PureComponent<
7-
any & React.ComponentProps<typeof Text>
8-
> {
6+
export interface ListItemProps extends React.ComponentProps<typeof Text> {
7+
/**
8+
* When passed, adds a icon before the list item.
9+
* See Evergreen `Icon` for documentation.
10+
*/
11+
icon?: string
12+
13+
/**
14+
* The color of the icon.
15+
*/
16+
iconColor?: string
17+
}
18+
19+
export default class ListItem extends PureComponent<ListItemProps> {
920
static propTypes = {
10-
/**
11-
* When passed, adds a icon before the list item.
12-
* See Evergreen `Icon` for documentation.
13-
*/
21+
...Text.propTypes,
1422
icon: PropTypes.string,
15-
16-
/**
17-
* The color of the icon.
18-
*/
1923
iconColor: PropTypes.string
2024
}
2125

src/typography/src/OrderedList.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import React, { PureComponent } from 'react'
1+
import React, { PureComponent, Validator } from 'react'
22
import PropTypes from 'prop-types'
33
import Box from 'ui-box'
44

5-
export default class OrderedList extends PureComponent<
6-
any & React.ComponentProps<typeof Box>
7-
> {
5+
type ListSize = 300 | 400 | 500 | 600
6+
7+
export interface OrderedListProps extends React.ComponentProps<typeof Box> {
8+
/**
9+
* Size of the text used in a list item.
10+
* Can be: 300, 400, 500, 600.
11+
*/
12+
size: ListSize
13+
}
14+
15+
export default class OrderedList extends PureComponent<OrderedListProps> {
816
static propTypes = {
9-
/**
10-
* Size of the text used in a list item.
11-
* Can be: 300, 400, 500, 600.
12-
*/
13-
size: PropTypes.oneOf([300, 400, 500, 600]).isRequired
17+
size: PropTypes.number as Validator<ListSize>
1418
}
1519

1620
static defaultProps = {

0 commit comments

Comments
 (0)