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/preact to Typescript #7527

Merged
merged 16 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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: 3 additions & 1 deletion app/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "MIT",
"main": "dist/client/index.js",
"jsnext:main": "src/client/index.js",
"types": "dist/client/index.d.ts",
"bin": {
"build-storybook": "./bin/build.js",
"start-storybook": "./bin/index.js",
Expand All @@ -28,6 +28,7 @@
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@storybook/core": "5.2.0-beta.4",
"@storybook/addons": "5.2.0-beta.4",
"common-tags": "^1.8.0",
"core-js": "^3.0.1",
"global": "^4.3.2",
Expand All @@ -37,6 +38,7 @@
"preact": "^8.4.2"
},
"peerDependencies": {
"@babel/core": "7.0.1",
"babel-loader": "^7.0.0 || ^8.0.0",
"preact": "^8.4.2"
},
Expand Down
File renamed without changes.
22 changes: 0 additions & 22 deletions app/preact/src/client/preview/index.js

This file was deleted.

29 changes: 29 additions & 0 deletions app/preact/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { start } from '@storybook/core/client';
import { ClientApi } from './types';

import './globals';
import render from './render';

const api = start(render);
const { load: coreLoad, clientApi, configApi } = api;
const framework = 'preact';

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
framework,
});
};
export const load: ClientApi['load'] = (...args: any) => coreLoad(...args, framework);
export const {
addDecorator,
addParameters,
clearDecorators,
setAddon,
getStorybook,
raw,
}: Pick<
ClientApi,
'addDecorator' | 'addParameters' | 'clearDecorators' | 'setAddon' | 'getStorybook' | 'raw'
> = clientApi;
export const { configure }: Pick<ClientApi, 'configure'> = configApi;
export const { forceReRender }: Pick<ClientApi, 'forceReRender'> = api;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { h, render } from 'preact';
import { document } from 'global';
import { stripIndents } from 'common-tags';
import { RenderMainArgs } from './types';

let renderedStory;
let renderedStory: Element;
const rootElement = document ? document.getElementById('root') : null;

export default function renderMain({
Expand All @@ -11,8 +12,7 @@ export default function renderMain({
selectedStory,
showMain,
showError,
// forceRender,
}) {
}: RenderMainArgs) {
const element = storyFn();

if (!element) {
Expand Down
37 changes: 37 additions & 0 deletions app/preact/src/client/preview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StoryFn, ClientStoryApi } from '@storybook/addons';

export type StoryFnPreactReturnType = string | Node;

export interface ShowErrorArgs {
title: string;
description: string;
}

export interface RenderMainArgs {
storyFn: () => StoryFn<StoryFnPreactReturnType>;
selectedKind: string;
selectedStory: string;
showMain: () => void;
showError: (args: ShowErrorArgs) => void;
forceRender: boolean;
}

export interface IStorybookStory {
name: string;
render: () => any;
}

export interface IStorybookSection {
kind: string;
stories: IStorybookStory[];
}

export interface ClientApi extends ClientStoryApi<StoryFnPreactReturnType> {
setAddon(addon: any): void;
configure(loaders: () => void, module: NodeModule): void;
getStorybook(): IStorybookSection[];
clearDecorators(): void;
forceReRender(): void;
raw: () => any; // todo add type
load: (...args: any[]) => void;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function babelDefault(config) {
import { TransformOptions } from '@babel/core';

export function babelDefault(config: TransformOptions) {
return {
...config,
plugins: [
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import packageJson from '../../package.json';
const packageJson = require('../../package.json');

export default {
packageJson,
Expand Down
2 changes: 2 additions & 0 deletions app/preact/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module '@storybook/core/*';
declare module 'global';
14 changes: 14 additions & 0 deletions app/preact/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"types": ["webpack-env"],
"resolveJsonModule": true
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.test.*"
]
}