Skip to content

Commit

Permalink
Migrate @storybook/addon-ondevice-notes to Typescript (#7737)
Browse files Browse the repository at this point in the history
Migrate @storybook/addon-ondevice-notes to Typescript

Co-authored-by: Norbert de Langen <[email protected]>
  • Loading branch information
ndelangen authored Sep 27, 2019
2 parents 30965d7 + f78909b commit 3ef5e60
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
4 changes: 4 additions & 0 deletions addons/ondevice-notes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
"register.js"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.3.0-alpha.4",
"@storybook/api": "5.3.0-alpha.4",
"@storybook/client-api": "5.3.0-alpha.4",
"@storybook/client-logger": "5.3.0-alpha.4",
"@storybook/core-events": "5.3.0-alpha.4",
"core-js": "^3.0.1",
"prop-types": "^15.7.2",
"react-native-simple-markdown": "^1.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/* eslint-disable react/prop-types */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { View } from 'react-native';
import Markdown from 'react-native-simple-markdown';
import addons from '@storybook/addons';
import { AddonStore } from '@storybook/addons';
import Events from '@storybook/core-events';
import { API } from '@storybook/api';
import { StoryStore } from '@storybook/client-api';

export const PARAM_KEY = `notes`;

class Notes extends React.Component {
type Selection = ReturnType<StoryStore['fromId']>;
interface NotesProps {
channel: ReturnType<AddonStore['getChannel']>;
api: API;
active: boolean;
}
interface NotesState {
selection: Selection;
}

export class Notes extends React.Component<NotesProps, NotesState> {
componentDidMount() {
this.props.channel.on(Events.SELECT_STORY, this.onStorySelected);
}
Expand All @@ -18,7 +28,7 @@ class Notes extends React.Component {
this.props.channel.removeListener(Events.SELECT_STORY, this.onStorySelected);
}

onStorySelected = selection => {
onStorySelected = (selection: Selection) => {
this.setState({ selection });
};

Expand All @@ -34,7 +44,7 @@ class Notes extends React.Component {
.getStoryAndParameters(this.state.selection.kind, this.state.selection.story);
const text = story.parameters[PARAM_KEY];

const textAfterFormatted = text ? text.trim() : '';
const textAfterFormatted: string = text ? text.trim() : '';

return (
<View style={{ padding: 10, flex: 1 }}>
Expand All @@ -43,12 +53,3 @@ class Notes extends React.Component {
);
}
}

addons.register('storybook/notes', api => {
const channel = addons.getChannel();
addons.addPanel('storybook/notes/panel', {
title: 'Notes',
render: ({ active, key }) => <Notes key={key} channel={channel} api={api} active={active} />,
paramKey: PARAM_KEY,
});
});
File renamed without changes.
14 changes: 14 additions & 0 deletions addons/ondevice-notes/src/register.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import addons from '@storybook/addons';
import { Notes } from './components/Notes';

export const PARAM_KEY = `notes`;

addons.register('storybook/notes', api => {
const channel = addons.getChannel();
addons.addPanel('storybook/notes/panel', {
title: 'Notes',
render: ({ active, key }) => <Notes key={key} channel={channel} api={api} active={active} />,
paramKey: PARAM_KEY,
});
});
4 changes: 4 additions & 0 deletions addons/ondevice-notes/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'react-native-simple-markdown' {
const Markdown: any;
export default Markdown;
}
13 changes: 13 additions & 0 deletions addons/ondevice-notes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"types": ["webpack-env"]
},
"include": [
"src/**/*"
],
"exclude": [
"src/__tests__/**/*"
]
}

0 comments on commit 3ef5e60

Please sign in to comment.