From 30355562b2601f319a6c07a16fc1be2eb2341eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Tue, 16 Apr 2019 13:42:36 +0200 Subject: [PATCH 1/6] chore: fix cyclic dependency in devDependencies of @storybook/components Remove `@storybook/react` and `@storybook/addon-actions` from devDependencies of `@storybook/components` to avoid lerna to find cyclic dependency. Also add them to ts-lint no-implicit-dependencies whitelist to avoid tslint error. For more details about this see:https://github.com/storybooks/storybook/issues/6523 --- lib/components/package.json | 2 -- lib/components/tsconfig.json | 3 ++- tslint.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/components/package.json b/lib/components/package.json index aae563d02345..4281ccaf8f4c 100644 --- a/lib/components/package.json +++ b/lib/components/package.json @@ -45,8 +45,6 @@ "simplebar-react": "^0.1.5" }, "devDependencies": { - "@storybook/addon-actions": "5.1.0-alpha.28", - "@storybook/react": "5.1.0-alpha.28", "@types/js-beautify": "^1.8.0", "@types/react-syntax-highlighter": "^10.1.0", "@types/react-textarea-autosize": "^4.3.3", diff --git a/lib/components/tsconfig.json b/lib/components/tsconfig.json index 31dedcc1d8c5..088e0f247933 100644 --- a/lib/components/tsconfig.json +++ b/lib/components/tsconfig.json @@ -12,6 +12,7 @@ "src/**/*" ], "exclude": [ - "src/**/__tests__/**/*" + "src/**/__tests__/**/*", + "src/**/*.stories.*" ] } diff --git a/tslint.json b/tslint.json index be2adec3353f..9be0bbebb26d 100644 --- a/tslint.json +++ b/tslint.json @@ -55,7 +55,7 @@ "prefer-const": false, "quotemark": false, "radix": true, - "no-implicit-dependencies": [true, "dev"], + "no-implicit-dependencies": [true, "dev", ["@storybook/react", "@storybook/addon-actions"]], "triple-equals": [true, "allow-null-check"], "unified-signatures": true, "variable-name": false, From 6b86dee847d678c7773427ef20938f6a0da292e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 12 Apr 2019 14:47:46 +0200 Subject: [PATCH 2/6] refactor: improve typings in `storybook/components` --- lib/components/src/tooltip/TooltipLinkList.tsx | 6 +++--- lib/components/src/tooltip/WithTooltip.tsx | 1 + lib/components/src/typography/link/link.tsx | 8 +++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/components/src/tooltip/TooltipLinkList.tsx b/lib/components/src/tooltip/TooltipLinkList.tsx index 792fea78eb34..8d181b5aa47d 100644 --- a/lib/components/src/tooltip/TooltipLinkList.tsx +++ b/lib/components/src/tooltip/TooltipLinkList.tsx @@ -24,14 +24,14 @@ export interface Link { export interface TooltipLinkListProps { links: Link[]; - LinkWrapper: LinkWrapperType; + LinkWrapper?: LinkWrapperType; } const TooltipLinkList: FunctionComponent = ({ links, LinkWrapper }) => ( - {links.map(({ id, title, href, onClick, active, isGatsby, ...props }: any) => ( + {links.map(({ id, title, href, onClick, active, isGatsby, ...props }) => ( void; + onDoubleClick?: () => void; } // Pure, does not bind to the body diff --git a/lib/components/src/typography/link/link.tsx b/lib/components/src/typography/link/link.tsx index 3deee81693ec..dda577d5a3ab 100644 --- a/lib/components/src/typography/link/link.tsx +++ b/lib/components/src/typography/link/link.tsx @@ -1,4 +1,4 @@ -import React, { FunctionComponent } from 'react'; +import React, { AnchorHTMLAttributes, FunctionComponent } from 'react'; import { styled, css, Theme } from '@storybook/theming'; import { darken } from 'polished'; @@ -180,15 +180,13 @@ const LinkInner = styled.span` `}; `; -interface AProps { - href?: string; -} +type AProps = AnchorHTMLAttributes; const A = styled.a` ${linkStyles}; `; -const Link: FunctionComponent = ({ +const Link: FunctionComponent = ({ cancel, children, onClick, From 223183cb74ce895164f5b7d02ab9bc27f0a9ebd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 12 Apr 2019 14:50:14 +0200 Subject: [PATCH 3/6] refactor: remove `@storybook/components` module declaration in addons As `@storybook/components` is now in TS (and so export its types) there is no more need to declare it in `typings.d.ts` of addons written in TS --- addons/a11y/src/typings.d.ts | 2 -- addons/actions/src/typings.d.ts | 1 - addons/backgrounds/src/typings.d.ts | 2 -- addons/cssresources/src/typings.d.ts | 1 - addons/jest/src/typings.d.ts | 2 -- addons/notes/src/typings.d.ts | 3 --- 6 files changed, 11 deletions(-) delete mode 100644 addons/backgrounds/src/typings.d.ts diff --git a/addons/a11y/src/typings.d.ts b/addons/a11y/src/typings.d.ts index 1cebcd2c971a..2f4eb9cf4fd9 100644 --- a/addons/a11y/src/typings.d.ts +++ b/addons/a11y/src/typings.d.ts @@ -1,3 +1 @@ -// TODO: following packages need definition files or a TS migration -declare module '@storybook/components'; declare module 'global'; diff --git a/addons/actions/src/typings.d.ts b/addons/actions/src/typings.d.ts index 71fa74c16e2a..5d85a4ae4c0a 100644 --- a/addons/actions/src/typings.d.ts +++ b/addons/actions/src/typings.d.ts @@ -1,4 +1,3 @@ // TODO: following packages need definition files or a TS migration -declare module '@storybook/components'; declare module 'global'; declare module 'react-inspector'; diff --git a/addons/backgrounds/src/typings.d.ts b/addons/backgrounds/src/typings.d.ts deleted file mode 100644 index 0ca9d4552932..000000000000 --- a/addons/backgrounds/src/typings.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// TODO: following packages need definition files or a TS migration -declare module '@storybook/components'; diff --git a/addons/cssresources/src/typings.d.ts b/addons/cssresources/src/typings.d.ts index 1cebcd2c971a..a41bf8a45b79 100644 --- a/addons/cssresources/src/typings.d.ts +++ b/addons/cssresources/src/typings.d.ts @@ -1,3 +1,2 @@ // TODO: following packages need definition files or a TS migration -declare module '@storybook/components'; declare module 'global'; diff --git a/addons/jest/src/typings.d.ts b/addons/jest/src/typings.d.ts index 04c872d49586..a41bf8a45b79 100644 --- a/addons/jest/src/typings.d.ts +++ b/addons/jest/src/typings.d.ts @@ -1,4 +1,2 @@ // TODO: following packages need definition files or a TS migration - declare module 'global'; -declare module '@storybook/components'; diff --git a/addons/notes/src/typings.d.ts b/addons/notes/src/typings.d.ts index 75c8db941995..b05c2516a214 100644 --- a/addons/notes/src/typings.d.ts +++ b/addons/notes/src/typings.d.ts @@ -1,6 +1,3 @@ -// todo the following packages need definition files or a TS migration -declare module '@storybook/components'; - // There are no types for markdown-to-jsx declare module 'markdown-to-jsx' { const Markdown: any; From 0e95d62f76b5f7fc8f347692333463b3c317bfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Fri, 12 Apr 2019 16:01:23 +0200 Subject: [PATCH 4/6] chore: use named import/export instead of default ones in sb/components Named exports enables better IDE integration and simplify a lot code refactoring --- .../__snapshots__/A11YPanel.test.js.snap | 8 +++---- lib/components/src/Badge/Badge.stories.tsx | 2 +- lib/components/src/Badge/Badge.tsx | 4 +--- lib/components/src/Button/Button.stories.tsx | 12 +++++----- lib/components/src/Button/Button.tsx | 4 +--- lib/components/src/form/field/field.tsx | 4 +--- lib/components/src/form/form.stories.tsx | 2 +- lib/components/src/form/index.tsx | 6 ++--- lib/components/src/form/input/input.tsx | 2 +- lib/components/src/icon/icon.stories.tsx | 8 +++---- lib/components/src/icon/icon.tsx | 6 ++--- lib/components/src/icon/icons.tsx | 2 +- lib/components/src/index.ts | 22 +++++++++---------- .../src/placeholder/placeholder.stories.tsx | 2 +- .../syntaxhighlighter.stories.tsx | 2 +- .../syntaxhighlighter/syntaxhighlighter.tsx | 20 +++++++++-------- .../src/tooltip/ListItem.stories.tsx | 2 +- .../src/tooltip/Tooltip.stories.tsx | 2 +- lib/components/src/tooltip/Tooltip.tsx | 4 +--- .../src/tooltip/TooltipLinkList.stories.tsx | 8 +++---- .../src/tooltip/TooltipLinkList.tsx | 7 +++--- .../src/tooltip/TooltipMessage.stories.tsx | 4 ++-- lib/components/src/tooltip/TooltipMessage.tsx | 7 ++---- .../src/tooltip/TooltipNote.stories.tsx | 4 ++-- lib/components/src/tooltip/TooltipNote.tsx | 5 +---- .../src/tooltip/WithTooltip.stories.tsx | 2 +- lib/components/src/tooltip/WithTooltip.tsx | 6 ++--- .../typography/DocumentFormatting.stories.tsx | 2 +- .../src/typography/DocumentFormatting.tsx | 4 +--- .../src/typography/link/link.stories.tsx | 4 ++-- .../src/typography/link/link.test.tsx | 2 +- lib/components/src/typography/link/link.tsx | 22 +++++++++---------- 32 files changed, 85 insertions(+), 106 deletions(-) diff --git a/addons/a11y/src/components/__snapshots__/A11YPanel.test.js.snap b/addons/a11y/src/components/__snapshots__/A11YPanel.test.js.snap index d791b9056b45..b7d67a158fe8 100644 --- a/addons/a11y/src/components/__snapshots__/A11YPanel.test.js.snap +++ b/addons/a11y/src/components/__snapshots__/A11YPanel.test.js.snap @@ -63,12 +63,12 @@ exports[`A11YPanel should render loader when it's running 1`] = `
- - - - + + Please wait while a11y scan is running ...
diff --git a/lib/components/src/Badge/Badge.stories.tsx b/lib/components/src/Badge/Badge.stories.tsx index 3299d4004c34..c98533de1300 100644 --- a/lib/components/src/Badge/Badge.stories.tsx +++ b/lib/components/src/Badge/Badge.stories.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; -import Badge from './Badge'; +import { Badge } from './Badge'; storiesOf('Basics|Badge', module).add('all badges', () => (
diff --git a/lib/components/src/Badge/Badge.tsx b/lib/components/src/Badge/Badge.tsx index c78410823082..93b89a9b0b9d 100644 --- a/lib/components/src/Badge/Badge.tsx +++ b/lib/components/src/Badge/Badge.tsx @@ -49,8 +49,6 @@ export interface BadgeProps { status: 'positive' | 'negative' | 'neutral'; } -const Badge: FunctionComponent = ({ ...props }) => { +export const Badge: FunctionComponent = ({ ...props }) => { return ; }; - -export default Badge; diff --git a/lib/components/src/Button/Button.stories.tsx b/lib/components/src/Button/Button.stories.tsx index cff92c4dec8c..cb3699a3dd45 100644 --- a/lib/components/src/Button/Button.stories.tsx +++ b/lib/components/src/Button/Button.stories.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; -import Button from './Button'; -import Icon from '../icon/icon'; +import { Button } from './Button'; +import { Icons } from '../icon/icon'; -import Form from '../form/index'; +import { Form } from '../form/index'; const { Button: FormButton } = Form; @@ -16,7 +16,7 @@ storiesOf('Basics|Button', module).add('all buttons', () => (
@@ -43,10 +43,10 @@ storiesOf('Basics|Button', module).add('all buttons', () => ( Disabled
diff --git a/lib/components/src/Button/Button.tsx b/lib/components/src/Button/Button.tsx index aab57b088385..3fc6ba6909e7 100644 --- a/lib/components/src/Button/Button.tsx +++ b/lib/components/src/Button/Button.tsx @@ -233,7 +233,7 @@ interface ButtonProps { containsIcon?: boolean; } -const Button: FunctionComponent = ({ isLink, children, ...props }) => { +export const Button: FunctionComponent = ({ isLink, children, ...props }) => { if (isLink) { return {children}; } @@ -243,5 +243,3 @@ const Button: FunctionComponent = ({ isLink, children, ...props }) Button.defaultProps = { isLink: false, }; - -export default Button; diff --git a/lib/components/src/form/field/field.tsx b/lib/components/src/form/field/field.tsx index 9b25d39c55f1..58cd8682c339 100644 --- a/lib/components/src/form/field/field.tsx +++ b/lib/components/src/form/field/field.tsx @@ -26,7 +26,7 @@ export interface FieldProps { label?: ReactNode; } -const Field: FunctionComponent = ({ label, children }) => ( +export const Field: FunctionComponent = ({ label, children }) => ( {label ? (