Skip to content

Commit d6a5f82

Browse files
authored
Merge pull request #292 from storybookjs/typescript/more-conversion
convert more to typescript
2 parents 1c94473 + eb1b9b5 commit d6a5f82

46 files changed

Lines changed: 4064 additions & 7140 deletions

Some content is hidden

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

.eslintrc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// const error = 2;
2-
// const warn = 1;
3-
const ignore = 0;
4-
51
module.exports = {
62
root: true,
73
extends: ['@storybook/eslint-config-storybook'],

.github/workflows/type-checking.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
- run: |
1111
yarn
1212
- run: |
13-
yarn types
13+
yarn typescript:check

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
],
1818
"scripts": {
1919
"build": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\" --ignore \"**/*.test.js\" --ignore \"**/*.stories.js\"",
20-
"types": "tsc --declaration --emitDeclarationOnly --outDir dist --declarationMap",
2120
"build-docs": "build-storybook --docs",
2221
"build-storybook": "build-storybook -s .storybook/static",
2322
"lint": "yarn lint:js && yarn lint:package",
2423
"lint:js": "cross-env NODE_ENV=production eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.html,.ts,.tsx,.mjs --report-unused-disable-directives",
2524
"lint:package": "sort-package-json",
26-
"release": "dotenv yarn build & yarn types && auto shipit",
27-
"storybook": "start-storybook -p 6006 -s .storybook/static"
25+
"release": "dotenv yarn build & yarn typescript:generate && auto shipit",
26+
"storybook": "start-storybook -p 6006 -s .storybook/static",
27+
"typescript:check": "tsc --project ./tsconfig.json --noEmit",
28+
"typescript:generate": "tsc --declaration --emitDeclarationOnly --outDir dist --declarationMap"
2829
},
2930
"husky": {
3031
"hooks": {
@@ -48,11 +49,13 @@
4849
"dependencies": {
4950
"@types/pluralize": "^0.0.29",
5051
"@types/prismjs": "^1.16.6",
52+
"@types/react-modal": "^3.12.1",
53+
"@types/styled-components": "^5.1.0",
54+
"@types/uuid": "^8.3.1",
5155
"copy-to-clipboard": "^3.3.1",
5256
"pluralize": "^8.0.0",
5357
"polished": "^3.6.4",
5458
"prismjs": "1.23.0",
55-
"prop-types": "^15.5.4",
5659
"react-github-button": "^0.1.11",
5760
"react-modal": "^3.11.2",
5861
"react-popper-tooltip": "^2.11.1",
@@ -77,7 +80,6 @@
7780
"@storybook/linter-config": "^2.5.0",
7881
"@storybook/react": "^6.2.0",
7982
"@types/fs-extra": "^9.0.1",
80-
"@types/styled-components": "^5.1.0",
8183
"auto": "^9.50.1",
8284
"babel-eslint": "^10.1.0",
8385
"babel-loader": "^8.1.0",
@@ -89,17 +91,17 @@
8991
"husky": "^4.2.5",
9092
"lint-staged": "^10.2.9",
9193
"node-fetch": "^2.6.0",
92-
"prettier": "^2.0.5",
93-
"react": "^16.13.1",
94-
"react-dom": "^16.13.1",
94+
"prettier": "^2.3.0",
95+
"react": "17",
96+
"react-dom": "17",
9597
"seedrandom": "^3.0.5",
9698
"sort-package-json": "^1.44.0",
9799
"ts-loader": "^7.0.5",
98100
"typescript": "^3.9.5"
99101
},
100102
"peerDependencies": {
101-
"react": "^15.0.0 || ^16.0.0",
102-
"react-dom": "^15.0.0 || ^16.0.0"
103+
"react": "^15.0.0 || ^16.0.0 || ^17.0.0",
104+
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0"
103105
},
104106
"engines": {
105107
"node": ">=10",
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import { Button } from './Button';
43
import { CodeSnippets } from './CodeSnippets';
5-
import { Highlight } from './Highlight';
64
import { javascriptCodeWithWrappers, typescriptCodeWithWrappers } from './Highlight.stories';
75
import { color } from './shared/styles';
86

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react';
2-
import PropTypes from 'prop-types';
1+
import React, { ComponentProps, ComponentType, useRef, useState } from 'react';
32
import styled from 'styled-components';
43

54
import { Clipboard } from './clipboard/Clipboard';
@@ -53,9 +52,9 @@ const StyledClipboard = styled(Clipboard)`
5352
}
5453
`;
5554

56-
function Snippet({ snippet }) {
55+
function Snippet({ snippet }: { snippet: SnippetType }) {
5756
const { PreSnippet: PreSnippetComponent, Snippet: SnippetComponent } = snippet;
58-
const snippetRef = useRef();
57+
const snippetRef = useRef<HTMLDivElement>();
5958
const getCopyContent = () => snippetRef.current && snippetRef.current.textContent;
6059

6160
return (
@@ -71,13 +70,6 @@ function Snippet({ snippet }) {
7170
);
7271
}
7372

74-
Snippet.propTypes = {
75-
snippet: PropTypes.shape({
76-
Snippet: PropTypes.elementType.isRequired,
77-
PreSnippet: PropTypes.elementType,
78-
}).isRequired,
79-
};
80-
8173
const TabsWrapper = styled.div`
8274
background: ${color.lightest};
8375
border-top-left-radius: ${spacing.borderRadius.small}px;
@@ -97,7 +89,7 @@ const StyledTabs = styled(LinkTabs)`
9789
}
9890
`;
9991

100-
function SnippetList({ snippets }) {
92+
function SnippetList({ snippets }: { snippets: SnippetType[] }) {
10193
const [activeSnippet, setActiveSnippet] = useState(snippets[0]);
10294

10395
const tabItems = snippets.map((snippet, index) => {
@@ -123,16 +115,10 @@ function SnippetList({ snippets }) {
123115
);
124116
}
125117

126-
SnippetList.propTypes = {
127-
snippets: PropTypes.arrayOf(
128-
PropTypes.shape({
129-
id: PropTypes.string.isRequired,
130-
renderTabLabel: PropTypes.func.isRequired,
131-
}).isRequired
132-
).isRequired,
133-
};
134-
135-
export function CodeSnippets({ snippets, ...rest }) {
118+
export function CodeSnippets({
119+
snippets,
120+
...rest
121+
}: Props & ComponentProps<typeof Wrapper> & { children?: never }) {
136122
return (
137123
<Wrapper {...rest}>
138124
<Background>
@@ -146,6 +132,13 @@ export function CodeSnippets({ snippets, ...rest }) {
146132
);
147133
}
148134

149-
CodeSnippets.propTypes = {
150-
snippets: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
151-
};
135+
interface SnippetType {
136+
Snippet: ComponentType;
137+
PreSnippet?: ComponentType;
138+
id: string;
139+
renderTabLabel: (...a: any[]) => string;
140+
}
141+
142+
interface Props {
143+
snippets: SnippetType[];
144+
}

src/components/Highlight.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ import { color } from './shared/styles';
77
if (typeof document !== 'undefined') {
88
// @ts-ignore
99
global.Prism = Prism;
10+
// @ts-ignore
1011
require('prismjs/components/prism-bash');
12+
// @ts-ignore
1113
require('prismjs/components/prism-javascript');
14+
// @ts-ignore
1215
require('prismjs/components/prism-typescript');
16+
// @ts-ignore
1317
require('prismjs/components/prism-json');
18+
// @ts-ignore
1419
require('prismjs/components/prism-css');
20+
// @ts-ignore
1521
require('prismjs/components/prism-yaml');
22+
// @ts-ignore
1623
require('prismjs/components/prism-markdown');
24+
// @ts-ignore
1725
require('prismjs/components/prism-jsx');
26+
// @ts-ignore
1827
require('prismjs/components/prism-tsx');
1928
}
2029

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Meta = styled.div`
99
font-size: 12px;
1010
`;
1111

12-
const Item = styled.li`
12+
const Item = styled.li<{ minimal?: boolean }>`
1313
display: inline-flex;
1414
flex-direction: row;
1515
align-items: center;
@@ -62,7 +62,7 @@ export const Labels = () => (
6262
<List>
6363
{Object.keys(icons).map((key) => (
6464
<Item key={key}>
65-
<Icon icon={key} aria-hidden />
65+
<Icon icon={key as keyof typeof icons} aria-hidden />
6666
<Meta>{key}</Meta>
6767
</Item>
6868
))}
@@ -74,7 +74,7 @@ export const NoLabels = () => (
7474
<List>
7575
{Object.keys(icons).map((key) => (
7676
<Item minimal key={key}>
77-
<Icon icon={key} aria-label={key} />
77+
<Icon icon={key as keyof typeof icons} aria-label={key} />
7878
</Item>
7979
))}
8080
</List>
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
32
import { action } from '@storybook/addon-actions';
43
import styled from 'styled-components';
54

@@ -148,17 +147,9 @@ const All = ({ appearance }) => (
148147
</>
149148
);
150149

151-
All.propTypes = {
152-
appearance: PropTypes.string,
153-
};
154-
155-
All.defaultProps = {
156-
appearance: undefined,
157-
};
158-
159150
export const Default = () => (
160151
<DarkForm>
161-
<All />
152+
<All appearance="default" />
162153
</DarkForm>
163154
);
164155

0 commit comments

Comments
 (0)