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 lib/ui to Typescript #9791

Merged
merged 35 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
029c0c1
MIGRATE provider
ndelangen Feb 6, 2020
76a96d6
Merge branch 'next' into ts/ui-slow
ndelangen Feb 6, 2020
4ccb704
MIGRATE zoom
ndelangen Feb 6, 2020
19dc18f
MGRATE toolbar
ndelangen Feb 6, 2020
e74484e
MIGRATE preview components
ndelangen Feb 6, 2020
5ccb58a
MIGRATE merge
ndelangen Feb 6, 2020
7f2b3e0
MIGRATE withLifecycleDecorator
ndelangen Feb 6, 2020
9c176c6
FIX a problem in router && FIX a problem in api/version && MIGRATE li…
ndelangen Feb 6, 2020
5b96087
MIGRATE settings
ndelangen Feb 6, 2020
6cdc6aa
MIGRATE shortcuts
ndelangen Feb 6, 2020
ed8380f
Merge branch 'next' into ts/ui-slow
ndelangen Feb 7, 2020
6820bb7
ADD depenency
ndelangen Feb 7, 2020
bbe5d49
FIX treeview/util
ndelangen Feb 7, 2020
46b552b
CLEANUP
ndelangen Feb 7, 2020
4e61e0e
FIX shortcuts validation
ndelangen Feb 7, 2020
1f940ff
MIGRATE more of lib/ui
ndelangen Feb 7, 2020
c4300fa
MIGRATE mobile layout
ndelangen Feb 7, 2020
c78a43f
MIGRATE draggers
ndelangen Feb 7, 2020
e317326
MIGRATE more lib/ui
ndelangen Feb 8, 2020
4ef7455
FIX tests
ndelangen Feb 8, 2020
6cfcd3d
FIX layout container
ndelangen Feb 8, 2020
0b40c8c
MIGRATE preview some more
ndelangen Feb 9, 2020
da53d63
Merge branch 'next' into ts/ui-slow
ndelangen Feb 10, 2020
14300d0
MIGRATE preview
ndelangen Feb 10, 2020
f8453d8
FIX ts error
ndelangen Feb 10, 2020
ba2bc03
FIX lint issue
ndelangen Feb 10, 2020
2d9831c
FIX linting
ndelangen Feb 10, 2020
2b03e47
FIX tests
ndelangen Feb 10, 2020
dc54ed3
MIGRATE desktop layout & app
ndelangen Feb 10, 2020
d69bac1
complete the MIGRATION of lib/ui to TS
ndelangen Feb 10, 2020
1f88b05
CHANGE to use yarn
ndelangen Feb 10, 2020
fe1437d
RESET lockfile
ndelangen Feb 10, 2020
d6f98a5
FIX lockfile
ndelangen Feb 10, 2020
316a07e
FIX linting
ndelangen Feb 10, 2020
643bc2e
FIX linting
ndelangen Feb 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/a11y/src/register.tsx
Expand Up @@ -93,7 +93,7 @@ addons.register(ADDON_ID, api => {
addons.add(PANEL_ID, {
title: 'Accessibility',
type: types.PANEL,
render: ({ active, key }) => <A11YPanel key={key} api={api} active={active} />,
render: ({ active = true, key }) => <A11YPanel key={key} api={api} active={active} />,
paramKey: PARAM_KEY,
});

Expand Down
@@ -1,6 +1,7 @@
import { Parser } from 'acorn';
// @ts-ignore
import jsx from 'acorn-jsx';
// eslint-disable-next-line import/no-extraneous-dependencies
import estree from 'estree';
// @ts-ignore
import * as acornWalk from 'acorn-walk';
Expand Down
1 change: 0 additions & 1 deletion app/riot/src/client/preview/rendering/stringified.js
@@ -1,4 +1,3 @@
/* eslint-disable import/no-duplicates */
import { mount, unregister, tag2 as tag } from 'riot';
import * as riot from 'riot';
import compiler from 'riot-compiler';
Expand Down
6 changes: 3 additions & 3 deletions examples/angular-cli/package.json
Expand Up @@ -5,14 +5,14 @@
"license": "MIT",
"scripts": {
"build": "ng build",
"prebuild-storybook": "npm run storybook:prebuild",
"prebuild-storybook": "yarn storybook:prebuild",
"build-storybook": "build-storybook -s src/assets",
"docs:json": "compodoc -p ./tsconfig.json -e json -d .",
"e2e": "ng e2e",
"ng": "ng",
"start": "ng serve",
"storybook": "npm run storybook:prebuild && start-storybook -p 9008 -s src/assets",
"storybook:prebuild": "npm run test:generate-output && npm run docs:json",
"storybook": "yarn storybook:prebuild && start-storybook -p 9008 -s src/assets",
"storybook:prebuild": "yarn test:generate-output && yarn docs:json",
"test": "jest",
"test:coverage": "jest --coverage",
"test:generate-output": "jest --json --config=jest.addon-config.js --outputFile=addon-jest.testresults.json || true",
Expand Down
2 changes: 1 addition & 1 deletion examples/marko-cli/package.json
Expand Up @@ -16,7 +16,7 @@
"serve-static": "NODE_ENV=production marko-starter serve-static",
"start": "marko-starter server",
"storybook": "start-storybook -p 9005",
"test": "npm run lint"
"test": "yarn lint"
},
"dependencies": {
"marko": "^4.18.39",
Expand Down
Expand Up @@ -5,7 +5,7 @@ Object {
"__": null,
"__b": 0,
"__c": null,
"__d": null,
"__d": undefined,
"__e": null,
"__k": null,
"constructor": undefined,
Expand All @@ -15,7 +15,7 @@ Object {
"__": null,
"__b": 0,
"__c": null,
"__d": null,
"__d": undefined,
"__e": null,
"__k": null,
"constructor": undefined,
Expand Down
1 change: 1 addition & 0 deletions lib/addons/package.json
Expand Up @@ -36,6 +36,7 @@
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@reach/router": "^1.2.1",
"@types/util-deprecate": "^1.0.0"
},
"peerDependencies": {
Expand Down
18 changes: 15 additions & 3 deletions lib/addons/src/index.ts
Expand Up @@ -4,17 +4,27 @@ import { ReactElement } from 'react';
import { Channel } from '@storybook/channels';
import { API } from '@storybook/api';
import { logger } from '@storybook/client-logger';
// eslint-disable-next-line import/no-extraneous-dependencies
import { WindowLocation } from '@reach/router';
import { types, Types } from './types';

export type ViewMode = 'story' | 'info' | 'settings' | undefined | string;

export interface RenderOptions {
active: boolean;
key: string;
active?: boolean;
key?: string;
}
export interface RouteOptions {
storyId: string;
viewMode: ViewMode;
location: WindowLocation;
path: string;
}
export interface MatchOptions {
viewMode: string;
storyId: string;
viewMode: ViewMode;
location: WindowLocation;
path: string;
}

export interface Addon {
Expand All @@ -25,6 +35,8 @@ export interface Addon {
match?: (matchOptions: MatchOptions) => boolean;
render: (renderOptions: RenderOptions) => ReactElement<any>;
paramKey?: string;
disabled?: boolean;
hidden?: boolean;
}

export type Loader = (api: API) => void;
Expand Down
1 change: 1 addition & 0 deletions lib/addons/src/types.ts
Expand Up @@ -5,6 +5,7 @@ export enum types {
TAB = 'tab',
PANEL = 'panel',
TOOL = 'tool',
TOOLEXTRA = 'toolextra',
PREVIEW = 'preview',
NOTES_ELEMENT = 'notes-element',
}
Expand Down
21 changes: 14 additions & 7 deletions lib/api/src/index.tsx
@@ -1,4 +1,12 @@
import React, { ReactElement, Component, useContext, useEffect, useMemo, useRef } from 'react';
import React, {
ReactElement,
Component,
useContext,
useEffect,
useMemo,
useRef,
ReactNode,
} from 'react';
import memoize from 'memoizerific';
// @ts-ignore shallow-equal is not in DefinitelyTyped
import shallowEqualObjects from 'shallow-equal/objects';
Expand Down Expand Up @@ -104,7 +112,7 @@ interface StoreData {
}

interface Children {
children: Component | ((props: Combo) => Component);
children: ReactNode | ((props: Combo) => ReactNode);
}

type StatePartial = Partial<State>;
Expand Down Expand Up @@ -248,11 +256,10 @@ class ManagerProvider extends Component<Props, State> {
api: this.api,
};

return (
<ManagerContext.Provider value={value}>
{typeof children === 'function' ? children(value) : children}
</ManagerContext.Provider>
);
// @ts-ignore
const content: ReactNode = typeof children === 'function' ? children(value) : children;

return <ManagerContext.Provider value={value}>{content}</ManagerContext.Provider>;
}
}

Expand Down
15 changes: 12 additions & 3 deletions lib/api/src/init-provider-api.ts
@@ -1,12 +1,21 @@
import { ReactElement } from 'react';
import { ReactNode } from 'react';
import { Channel } from '@storybook/channels';

import { API } from './index';
import { API, State } from './index';
import Store from './store';

type IframeRenderer = (
storyId: string,
viewMode: State['viewMode'],
id: string,
baseUrl: string,
scale: number,
queryParams: Record<string, any>
) => ReactNode;

export interface Provider {
channel?: Channel;
renderPreview?: () => ReactElement;
renderPreview?: IframeRenderer;
handleAPI(api: API): void;
[key: string]: any;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/api/src/modules/addons.ts
@@ -1,8 +1,11 @@
import { ReactElement } from 'react';

import { WindowLocation } from '@reach/router';
import { Module } from '../index';
import { Options } from '../store';

export type ViewMode = 'story' | 'info' | 'settings' | undefined | string;

export enum types {
TAB = 'tab',
PANEL = 'panel',
Expand All @@ -19,9 +22,15 @@ export interface RenderOptions {

export interface RouteOptions {
storyId: string;
viewMode: ViewMode;
location: WindowLocation;
path: string;
}
export interface MatchOptions {
viewMode: string;
storyId: string;
viewMode: ViewMode;
location: WindowLocation;
path: string;
}

export interface Addon {
Expand All @@ -32,6 +41,8 @@ export interface Addon {
match?: (matchOptions: MatchOptions) => boolean;
render: (renderOptions: RenderOptions) => ReactElement<any>;
paramKey?: string;
disabled?: boolean;
hidden?: boolean;
}
export interface Collection {
[key: string]: Addon;
Expand Down
2 changes: 2 additions & 0 deletions lib/api/src/modules/notifications.ts
Expand Up @@ -2,6 +2,8 @@ import { Module } from '../index';

export interface Notification {
id: string;
link: string;
content: string;
onClear?: () => void;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/modules/stories.ts
Expand Up @@ -9,7 +9,7 @@ type Direction = -1 | 1;
type StoryId = string;
type ParameterName = string;

type ViewMode = 'story' | 'info' | 'settings' | undefined;
type ViewMode = 'story' | 'info' | 'settings' | undefined | string;

export interface SubState {
storiesHash: StoriesHash;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/modules/versions.ts
Expand Up @@ -8,7 +8,7 @@ import { Module, API } from '../index';

export interface Version {
version: string;
info?: string;
info?: { plain: string };
[key: string]: any;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/components/src/tabs/tabs.tsx
Expand Up @@ -139,7 +139,7 @@ export interface TabsProps {
selected?: string;
actions?: {
onSelect: (id: string) => void;
};
} & Record<string, any>;
backgroundColor?: string;
absolute?: boolean;
bordered?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions lib/core-events/src/index.test.ts
@@ -1,5 +1,4 @@
/* eslint-disable import/no-duplicates */
import * as EventsPackageExport from '.';
import * as EventsPackageExport from './index';
import EventsDefaultExport, { CHANNEL_CREATED } from './index';

describe('Core Events', () => {
Expand Down
8 changes: 4 additions & 4 deletions lib/router/src/router.tsx
Expand Up @@ -33,12 +33,12 @@ interface QueryMatchProps {
}
interface RouteProps {
path: string;
startsWith: boolean;
hideOnly: boolean;
children: (renderData: RenderData) => ReactNode;
startsWith?: boolean;
hideOnly?: boolean;
children: ReactNode;
}

interface QueryLinkProps {
export interface QueryLinkProps {
to: string;
children: ReactNode;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/package.json
Expand Up @@ -36,6 +36,7 @@
"@storybook/core-events": "6.0.0-alpha.9",
"@storybook/router": "6.0.0-alpha.9",
"@storybook/theming": "6.0.0-alpha.9",
"@types/markdown-to-jsx":"^6.9.1",
"copy-to-clipboard": "^3.0.8",
"core-js": "^3.0.1",
"core-js-pure": "^3.0.1",
Expand Down Expand Up @@ -63,6 +64,7 @@
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@storybook/react": "6.0.0-alpha.9",
"@storybook/addon-actions": "6.0.0-alpha.9",
"@storybook/addon-knobs": "6.0.0-alpha.9",
"corejs-upgrade-webpack-plugin": "^3.0.1",
Expand Down
36 changes: 15 additions & 21 deletions lib/ui/src/app.js → lib/ui/src/app.tsx
@@ -1,11 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import { Global, createGlobal, styled } from '@storybook/theming';
import memoize from 'memoizerific';
import sizeMe from 'react-sizeme';

import { Route } from '@storybook/router';

import { State } from '@storybook/api';
import { Mobile } from './components/layout/mobile';
import { Desktop } from './components/layout/desktop';
import Nav from './containers/nav';
Expand All @@ -24,12 +24,11 @@ const createProps = memoize(1)(() => ({
{
key: 'settings',
render: () => <SettingsPages />,
// eslint-disable-next-line react/prop-types
route: ({ children }) => (
route: (({ children }) => (
<Route path="/settings" startsWith>
{children}
</Route>
),
)) as FunctionComponent,
},
],
}));
Expand All @@ -41,7 +40,16 @@ const View = styled.div({
width: '100vw',
});

const App = React.memo(({ viewMode, docsOnly, layout, panelCount, size: { width, height } }) => {
const App = React.memo<{
viewMode: State['viewMode'];
docsOnly: boolean;
layout: State['layout'];
panelCount: number;
size: {
width: number;
height: number;
};
}>(({ viewMode, docsOnly, layout, panelCount, size: { width, height } }) => {
const props = createProps();

let content;
Expand All @@ -53,7 +61,7 @@ const App = React.memo(({ viewMode, docsOnly, layout, panelCount, size: { width,
</div>
);
} else if (width < 600) {
content = <Mobile {...props} viewMode={viewMode} options={layout} panelCount={panelCount} />;
content = <Mobile {...props} viewMode={viewMode} options={layout} />;
} else {
content = (
<Desktop
Expand All @@ -74,20 +82,6 @@ const App = React.memo(({ viewMode, docsOnly, layout, panelCount, size: { width,
</View>
);
});
App.propTypes = {
viewMode: PropTypes.string,
panelCount: PropTypes.number.isRequired,
layout: PropTypes.shape({}).isRequired,
size: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number,
}).isRequired,
docsOnly: PropTypes.bool,
};
App.defaultProps = {
viewMode: undefined,
docsOnly: false,
};

const SizedApp = sizeMe({ monitorHeight: true })(App);

Expand Down
10 changes: 10 additions & 0 deletions lib/ui/src/components/layout/Root.tsx
@@ -0,0 +1,10 @@
import { styled } from '@storybook/theming';

export const Root = styled.div({
position: 'fixed',
left: 0,
top: 0,
width: '100vw',
height: '100vh',
overflow: 'hidden',
});