Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert more to typescript #292

Merged
merged 8 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// const error = 2;
// const warn = 1;
const ignore = 0;

module.exports = {
root: true,
extends: ['@storybook/eslint-config-storybook'],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/type-checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- run: |
yarn
- run: |
yarn types
yarn typescript:check
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
],
"scripts": {
"build": "babel src -d dist --extensions \".js,.jsx,.ts,.tsx\" --ignore \"**/*.test.js\" --ignore \"**/*.stories.js\"",
"types": "tsc --declaration --emitDeclarationOnly --outDir dist --declarationMap",
"build-docs": "build-storybook --docs",
"build-storybook": "build-storybook -s .storybook/static",
"lint": "yarn lint:js && yarn lint:package",
"lint:js": "cross-env NODE_ENV=production eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.html,.ts,.tsx,.mjs --report-unused-disable-directives",
"lint:package": "sort-package-json",
"release": "dotenv yarn build & yarn types && auto shipit",
"storybook": "start-storybook -p 6006 -s .storybook/static"
"release": "dotenv yarn build & yarn typescript:generate && auto shipit",
"storybook": "start-storybook -p 6006 -s .storybook/static",
"typescript:check": "tsc --project ./tsconfig.json --noEmit",
"typescript:generate": "tsc --declaration --emitDeclarationOnly --outDir dist --declarationMap"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -52,7 +53,6 @@
"pluralize": "^8.0.0",
"polished": "^3.6.4",
"prismjs": "1.23.0",
"prop-types": "^15.5.4",
"react-github-button": "^0.1.11",
"react-modal": "^3.11.2",
"react-popper-tooltip": "^2.11.1",
Expand All @@ -77,7 +77,9 @@
"@storybook/linter-config": "^2.5.0",
"@storybook/react": "^6.2.0",
"@types/fs-extra": "^9.0.1",
"@types/react-modal": "^3.12.1",
"@types/styled-components": "^5.1.0",
"@types/uuid": "^8.3.1",
"auto": "^9.50.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import { Button } from './Button';
import { CodeSnippets } from './CodeSnippets';
import { Highlight } from './Highlight';
import { javascriptCodeWithWrappers, typescriptCodeWithWrappers } from './Highlight.stories';
import { color } from './shared/styles';

Expand Down
43 changes: 18 additions & 25 deletions src/components/CodeSnippets.js → src/components/CodeSnippets.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import React, { ComponentProps, ComponentType, useRef, useState } from 'react';
import styled from 'styled-components';

import { Clipboard } from './clipboard/Clipboard';
Expand Down Expand Up @@ -53,9 +52,9 @@ const StyledClipboard = styled(Clipboard)`
}
`;

function Snippet({ snippet }) {
function Snippet({ snippet }: { snippet: SnippetType }) {
const { PreSnippet: PreSnippetComponent, Snippet: SnippetComponent } = snippet;
const snippetRef = useRef();
const snippetRef = useRef<HTMLDivElement>();
const getCopyContent = () => snippetRef.current && snippetRef.current.textContent;

return (
Expand All @@ -71,13 +70,6 @@ function Snippet({ snippet }) {
);
}

Snippet.propTypes = {
snippet: PropTypes.shape({
Snippet: PropTypes.elementType.isRequired,
PreSnippet: PropTypes.elementType,
}).isRequired,
};

const TabsWrapper = styled.div`
background: ${color.lightest};
border-top-left-radius: ${spacing.borderRadius.small}px;
Expand All @@ -97,7 +89,7 @@ const StyledTabs = styled(LinkTabs)`
}
`;

function SnippetList({ snippets }) {
function SnippetList({ snippets }: { snippets: SnippetType[] }) {
const [activeSnippet, setActiveSnippet] = useState(snippets[0]);

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

SnippetList.propTypes = {
snippets: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
renderTabLabel: PropTypes.func.isRequired,
}).isRequired
).isRequired,
};

export function CodeSnippets({ snippets, ...rest }) {
export function CodeSnippets({
snippets,
...rest
}: Props & ComponentProps<typeof Wrapper> & { children?: never }) {
return (
<Wrapper {...rest}>
<Background>
Expand All @@ -146,6 +132,13 @@ export function CodeSnippets({ snippets, ...rest }) {
);
}

CodeSnippets.propTypes = {
snippets: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
};
interface SnippetType {
Snippet: ComponentType;
PreSnippet?: ComponentType;
id: string;
renderTabLabel: (...a: any[]) => string;
}

interface Props {
snippets: SnippetType[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Meta = styled.div`
font-size: 12px;
`;

const Item = styled.li`
const Item = styled.li<{ minimal?: boolean }>`
display: inline-flex;
flex-direction: row;
align-items: center;
Expand Down Expand Up @@ -62,7 +62,7 @@ export const Labels = () => (
<List>
{Object.keys(icons).map((key) => (
<Item key={key}>
<Icon icon={key} aria-hidden />
<Icon icon={key as keyof typeof icons} aria-hidden />
<Meta>{key}</Meta>
</Item>
))}
Expand All @@ -74,7 +74,7 @@ export const NoLabels = () => (
<List>
{Object.keys(icons).map((key) => (
<Item minimal key={key}>
<Icon icon={key} aria-label={key} />
<Icon icon={key as keyof typeof icons} aria-label={key} />
</Item>
))}
</List>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import { action } from '@storybook/addon-actions';
import styled from 'styled-components';

Expand Down Expand Up @@ -148,17 +147,9 @@ const All = ({ appearance }) => (
</>
);

All.propTypes = {
appearance: PropTypes.string,
};

All.defaultProps = {
appearance: undefined,
};

export const Default = () => (
<DarkForm>
<All />
<All appearance="default" />
</DarkForm>
);

Expand Down
Loading