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

Migrate @storybook/components to TS #6095

Merged
merged 21 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6cd7a4f
chore: add tsconfig in lib/components
gaetanmaisse Mar 7, 2019
04c7437
chore: migrate src of lib/components to Typescript
gaetanmaisse Mar 11, 2019
1bd8262
refactor: strongly types ActionBar
gaetanmaisse Mar 17, 2019
783d769
refactor: strongly types Badge
gaetanmaisse Mar 17, 2019
1461fba
refactor: strongly types FlexBar
gaetanmaisse Mar 17, 2019
56676bf
refactor: strongly types and fix svg of StorybookIcon and StorybookLogo
gaetanmaisse Mar 17, 2019
9831f50
refactor: strongly types Button
gaetanmaisse Mar 17, 2019
5e1afb4
refactor: strongly types Icon
gaetanmaisse Mar 20, 2019
af56959
refactor: strongly types ScrollArea
gaetanmaisse Mar 20, 2019
ce4b453
refactor: strongly types Spaced
gaetanmaisse Mar 20, 2019
c703aa8
refactor: strongly types CopyableCode/SyntaxHighlighter
gaetanmaisse Mar 20, 2019
78c6ed6
refactor: strongly types Tabs
gaetanmaisse Mar 21, 2019
40e22ae
refactor: strongly types Placeholder
gaetanmaisse Mar 21, 2019
61758cf
refactor: strongly types forms
gaetanmaisse Mar 21, 2019
dbf7a3e
refactor: strongly types StoryLinkWrapper
gaetanmaisse Mar 21, 2019
3444c3e
refactor: strongly types typography
gaetanmaisse Mar 21, 2019
f385fae
refactor: strongly types tooltip
gaetanmaisse Mar 22, 2019
2283c73
refactor: strongly types form
gaetanmaisse Mar 28, 2019
7d1412b
refactor: rewrite some code to avoid anonymous fct in JS compiled code
gaetanmaisse Apr 1, 2019
57fd649
chore: disable no-literal-urls rule for specific use case
gaetanmaisse Apr 2, 2019
d8b0858
Revert "refactor: rewrite some code to avoid anonymous fct in JS comp…
gaetanmaisse Apr 5, 2019
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
2 changes: 1 addition & 1 deletion examples/official-storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function loadStories() {
req = require.context('../../lib/ui/src', true, /\.stories\.js$/);
importAll(req);

req = require.context('../../lib/components/src', true, /\.stories\.js$/);
req = require.context('../../lib/components/src', true, /\.stories\.tsx?$/);
importAll(req);

req = require.context('./stories', true, /\.stories\.js$/);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ exports[`Storyshots Basics|Brand/StorybookLogo normal 1`] = `
viewBox="0 0 200 40"
width="200px"
>
<title>
Storybook logo
</title>
<defs>
<path
d="M1.2 36.9L0 3.9c0-1.1.8-2 1.9-2.1l28-1.8a2 2 0 0 1 2.2 1.9 2 2 0 0 1 0 .1v36a2 2 0 0 1-2 2 2 2 0 0 1-.1 0L3.2 38.8a2 2 0 0 1-2-2z"
Expand Down Expand Up @@ -7470,6 +7473,7 @@ exports[`Storyshots UI|Sidebar/ListItemIcon all 1`] = `

.emotion-3 {
color: #333333;
font-weight: 400;
}

.emotion-6 {
Expand Down Expand Up @@ -7557,6 +7561,7 @@ exports[`Storyshots UI|Sidebar/ListItemIcon all 1`] = `

.emotion-3 {
color: #333333;
font-weight: 400;
}

.emotion-6 {
Expand Down Expand Up @@ -8401,7 +8406,6 @@ exports[`Storyshots UI|Sidebar/Sidebar loading 1`] = `
class="emotion-0"
height="40px"
role="img"
title="Storybook"
viewBox="0 0 200 40"
width="200px"
>
Expand Down Expand Up @@ -9834,7 +9838,6 @@ exports[`Storyshots UI|Sidebar/Sidebar simple 1`] = `
class="emotion-0"
height="40px"
role="img"
title="Storybook"
viewBox="0 0 200 40"
width="200px"
>
Expand Down Expand Up @@ -11352,7 +11355,6 @@ exports[`Storyshots UI|Sidebar/SidebarHeading menuHighlighted 1`] = `
class="emotion-0"
height="40px"
role="img"
title="Storybook"
viewBox="0 0 200 40"
width="200px"
>
Expand Down Expand Up @@ -11993,7 +11995,6 @@ exports[`Storyshots UI|Sidebar/SidebarHeading standard 1`] = `
class="emotion-0"
height="40px"
role="img"
title="Storybook"
viewBox="0 0 200 40"
width="200px"
>
Expand Down Expand Up @@ -12331,7 +12332,6 @@ exports[`Storyshots UI|Sidebar/SidebarHeading standardNoLink 1`] = `
class="emotion-0"
height="40px"
role="img"
title="Storybook"
viewBox="0 0 200 40"
width="200px"
>
Expand Down
15 changes: 14 additions & 1 deletion lib/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "MIT",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
Expand All @@ -29,7 +29,9 @@
"core-js": "^2.6.5",
"global": "^4.3.2",
"js-beautify": "^1.8.9",
"markdown-to-jsx": "^6.9.1",
"memoizerific": "^1.11.3",
"popper.js": "^1.14.7",
"polished": "^3.0.0",
"prop-types": "^15.7.2",
"react": "^16.8.4",
Expand All @@ -42,6 +44,17 @@
"recompose": "^0.30.0",
"simplebar-react": "^0.1.5"
},
"devDependencies": {
"@storybook/addon-actions": "5.1.0-alpha.22",
"@storybook/react": "5.1.0-alpha.22",
"@types/js-beautify": "^1.8.0",
"@types/react-syntax-highlighter": "^10.1.0",
"@types/react-textarea-autosize": "^4.3.3",
"@types/recompose": "^0.30.5",
"enzyme": "^3.9.0",
"jest": "^24.7.1",
"jest-enzyme": "^7.0.2"
},
"peerDependencies": {
"react": "*",
"react-dom": "*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactNode } from 'react';
import { action } from '@storybook/addon-actions';

import { ActionBar } from './ActionBar';
Expand All @@ -11,7 +11,7 @@ export default {
Component: ActionBar,
title: 'Basics|ActionBar',
decorators: [
storyFn => (
(storyFn: () => ReactNode) => (
<div
style={{
position: 'relative',
Expand All @@ -28,7 +28,7 @@ export default {
],
};

export const singleItem = () => <ActionBar actionItems={[{ title: 'Clear', onClick: action1 }]} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this space removal doesn't seem intentional. or is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't, will be back in #6500 😉

export const singleItem = () => <ActionBar actionItems={[{ title: 'Clear', onClick: action1 }]}/>;

export const manyItems = () => (
<ActionBar
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 React, { FunctionComponent } from 'react';
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

import { styled } from '@storybook/theming';

Expand Down Expand Up @@ -45,25 +44,21 @@ export const ActionButton = styled.button(({ theme }) => ({
}));
ActionButton.displayName = 'ActionButton';

export const ActionBar = ({ actionItems, ...props }) => (
export interface ActionItem {
title: string | JSX.Element;
onClick: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
}

export interface ActionBarProps {
actionItems: ActionItem[];
}

export const ActionBar: FunctionComponent<ActionBarProps> = ({ actionItems, ...props }) => (
<Container {...props}>
{actionItems.map(({ title, onClick }, index) => (
<ActionButton
// eslint-disable-next-line react/no-array-index-key
key={index}
onClick={onClick}
>
{actionItems.map(({ title, onClick }, index: number) => (
<ActionButton key={index} onClick={onClick}>
{title}
</ActionButton>
))}
</Container>
);

ActionBar.propTypes = {
actionItems: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.node.isRequired,
onClick: PropTypes.func.isRequired,
})
).isRequired,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import React, { FunctionComponent } from 'react';
import { styled, css } from '@storybook/theming';

const BadgeWrapper = styled.div`
type BadgeWrapperProps = BadgeProps;

const BadgeWrapper = styled.div<BadgeWrapperProps>`
display: inline-block;
vertical-align: top;
font-size: 11px;
Expand Down Expand Up @@ -43,8 +45,12 @@ const BadgeWrapper = styled.div`
`};
`;

function Badge({ ...props }) {
return <BadgeWrapper {...props} />;
export interface BadgeProps {
status: 'positive' | 'negative' | 'neutral';
}

const Badge: FunctionComponent<BadgeProps> = ({ ...props }) => {
return <BadgeWrapper {...props} />;
};

export default Badge;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import { styled, css } from '@storybook/theming';
import { darken, lighten, rgba, transparentize } from 'polished';

const ButtonWrapper = styled.button`
type ButtonWrapperProps = ButtonProps;

const ButtonWrapper = styled.button<ButtonWrapperProps>`
border: 0;
border-radius: 3em;
cursor: pointer;
Expand Down Expand Up @@ -220,16 +221,23 @@ const ButtonWrapper = styled.button`

const ButtonLink = ButtonWrapper.withComponent('a');

function Button({ isLink, children, ...props }) {
interface ButtonProps {
isLink?: boolean;
primary?: boolean;
secondary?: boolean;
tertiary?: boolean;
inForm?: boolean;
disabled?: boolean;
small?: boolean;
outline?: boolean;
containsIcon?: boolean;
}

const Button: FunctionComponent<ButtonProps> = ({ isLink, children, ...props }) => {
if (isLink) {
return <ButtonLink {...props}>{children}</ButtonLink>;
}
return <ButtonWrapper {...props}>{children}</ButtonWrapper>;
}

Button.propTypes = {
isLink: PropTypes.bool,
children: PropTypes.node.isRequired,
};

Button.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ const Wrapper = styled.div({
overflow: 'hidden',
});

const list = filler => [...new Array(20)].map((x, i) => filler(i));
const list = (filler: (data: number) => JSX.Element) => {
const data = [];

for (let i = 0; i < 20; i++) {
data.push(filler(i));
}

return data;
};

export default {
component: ScrollArea,
title: 'Basics|ScrollArea',
decorators: [storyFn => <Wrapper>{storyFn()}</Wrapper>],
decorators: [(storyFn: () => any) => <Wrapper>{storyFn()}</Wrapper>],
};

export const vertical = () => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Storybook's implementation of SimpleBar https://github.com/Grsmto/simplebar
// Note: "SimpleBar can't be used on the <body>, <textarea> or <iframe> elements."

import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import React, { Fragment, FunctionComponent } from 'react';
import { styled, Global } from '@storybook/theming';

import SimpleBar from 'simplebar-react';
import { getScrollAreaStyles } from './ScrollAreaStyles';

const Scroll = styled(({ vertical, horizontal, ...rest }) => <SimpleBar {...rest} />)(
export interface ScrollProps {
horizontal?: boolean;
vertical?: boolean;
[key: string]: any;
}

const Scroll = styled(({ vertical, horizontal, ...rest }: ScrollProps) => <SimpleBar {...rest} />)(
({ vertical }) =>
!vertical
? {
Expand All @@ -27,7 +32,18 @@ const Scroll = styled(({ vertical, horizontal, ...rest }) => <SimpleBar {...rest
}
);

export const ScrollArea = ({ children, vertical, horizontal, ...props }) => (
export interface ScrollAreaProps {
horizontal?: boolean;
vertical?: boolean;
className?: string;
}

export const ScrollArea: FunctionComponent<ScrollAreaProps> = ({
children,
vertical,
horizontal,
...props
}) => (
<Fragment>
<Global styles={getScrollAreaStyles} />
<Scroll vertical={vertical} horizontal={horizontal} {...props}>
Expand All @@ -36,11 +52,6 @@ export const ScrollArea = ({ children, vertical, horizontal, ...props }) => (
</Fragment>
);

ScrollArea.propTypes = {
children: PropTypes.node.isRequired,
horizontal: PropTypes.bool,
vertical: PropTypes.bool,
};
ScrollArea.defaultProps = {
horizontal: false,
vertical: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const getScrollAreaStyles = theme => ({
import { Theme, Interpolation } from '@storybook/theming';

export const getScrollAreaStyles: (theme: Theme) => Interpolation = (theme: Theme) => ({
'[data-simplebar]': {
position: 'relative',
flexDirection: 'column',
Expand Down Expand Up @@ -36,9 +38,9 @@ export const getScrollAreaStyles = theme => ({
},

'.simplebar-offset': {
direction: 'inherit !important',
boxSizing: 'inherit !important',
resize: 'none !important',
direction: 'inherit !important' as 'inherit',
boxSizing: 'inherit !important' as 'inherit',
resize: 'none !important' as 'none',
position: 'absolute',
top: 0,
left: 0,
Expand All @@ -51,7 +53,7 @@ export const getScrollAreaStyles = theme => ({

'.simplebar-content': {
direction: 'inherit',
boxSizing: 'border-box !important',
boxSizing: 'border-box !important' as 'border-box',
position: 'relative',
display: 'block',
height:
Expand All @@ -71,7 +73,7 @@ export const getScrollAreaStyles = theme => ({
},

'.simplebar-height-auto-observer-wrapper': {
boxSizing: 'inherit !important',
boxSizing: 'inherit !important' as 'inherit',
height: '100%',
width: 'inherit',
maxWidth: 1,
Expand Down Expand Up @@ -132,7 +134,7 @@ export const getScrollAreaStyles = theme => ({

'.simplebar-track .simplebar-scrollbar.simplebar-visible:before': {
/* When hovered, remove all transitions from drag handle */
opacity: '0.2',
opacity: 0.2,
transition: 'opacity 0s linear',
},

Expand Down
Loading