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/addon-ondevice-notes to Typescript #7737

Merged
Merged
Show file tree
Hide file tree
Changes from all 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: 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__/**/*"
]
}