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

TS Migration: addon-notes #4758

Merged
merged 30 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aaf78da
First poc approach with addon-notes
kroeder Nov 9, 2018
c51d7c8
Tsconfig configuration update
kroeder Nov 10, 2018
6dc5f05
Added public_api entry point
kroeder Nov 10, 2018
8891dd4
Removed addon-react since it's not used anymore
kroeder Nov 11, 2018
dca0f7d
Fixed import for addon-notes test file
kroeder Nov 11, 2018
3bf2c8a
Added @types/node for allowing the use of 'module'
kroeder Nov 11, 2018
558da37
fixed jsnext:main path
kroeder Nov 11, 2018
6823d78
removed prop-types, they are not needed anymore
kroeder Nov 11, 2018
b51f8d1
Moved addon tsconfig configuration to root tsconfig
kroeder Nov 11, 2018
d37fcf6
Added default export, might fix CI
kroeder Nov 11, 2018
5e84f3b
Added marked types and updated marked implementation
kroeder Nov 11, 2018
852973f
Removed unnecessary function; updated marked dependencies
kroeder Dec 6, 2018
f25a05b
Changed addon.ts back to index.ts
kroeder Dec 6, 2018
94e6e12
Updated @emotion/styled because the newest version has definition fil…
kroeder Dec 8, 2018
206b304
Added .tsx to the allowed file extensions for jsx
kroeder Dec 8, 2018
49b467d
Re-enabled noImplicitAny again
kroeder Dec 8, 2018
149f471
Resolved a couple of any to their actual types
kroeder Dec 8, 2018
e943ff3
Updated NotesApi; refactored "styled" usage
kroeder Dec 8, 2018
14afa9c
Refactoring
kroeder Dec 8, 2018
88d1f70
Re-added .ts to import/resolver in eslint
kroeder Dec 8, 2018
a11cd70
Added todo for refactoring purpose
kroeder Dec 8, 2018
2d00ee6
Force eslint to ignore *.ts files
igor-dv Dec 8, 2018
73f4715
Merge remote-tracking branch 'origin/next' into typescript-poc
igor-dv Dec 8, 2018
79306bd
Set @emotion/styled back to ^0.10.6
kroeder Dec 9, 2018
876488c
Added 'jsx-double' rule for tsx files
kroeder Dec 9, 2018
018f83a
Created @emotion/styled module to satisfy noImplicitAny rule
kroeder Dec 9, 2018
d7184fe
Fixed build issue
kroeder Dec 9, 2018
c1669d8
Reverted @emotion/styled change
kroeder Dec 9, 2018
5312cd4
Refactoring
kroeder Dec 9, 2018
1a4e510
Added prop-types + typings for prop-types. Restored the old prop-type…
kroeder Dec 9, 2018
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
9 changes: 7 additions & 2 deletions addons/notes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"url": "https://github.com/storybooks/storybook.git"
},
"license": "MIT",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"main": "dist/public_api.js",
"types": "dist/public_api.d.ts",
"jsnext:main": "src/public_api.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
Expand All @@ -30,6 +31,10 @@
"marked": "^0.5.1",
"prop-types": "^15.6.2"
},
"devDependencies": {
"@types/jest": "^23.3.9",
"@types/react": "^16.7.1"
},
kroeder marked this conversation as resolved.
Show resolved Hide resolved
"peerDependencies": {
"react": "*"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import addons from '@storybook/addons';
import { withNotes } from '..';
import { withNotes } from '../addon';
kroeder marked this conversation as resolved.
Show resolved Hide resolved

addons.getChannel = jest.fn();

Expand Down
8 changes: 7 additions & 1 deletion addons/notes/src/index.js → addons/notes/src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export const withNotes = makeDecorator({
const storyOptions = parameters || options;

const { text, markdown, markdownOptions } =
typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions;
typeof storyOptions === 'string'
? {
text: storyOptions,
markdown: undefined,
kroeder marked this conversation as resolved.
Show resolved Hide resolved
markdownOptions: undefined,
}
: storyOptions;

if (!text && !markdown) {
throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter');
Expand Down
1 change: 1 addition & 0 deletions addons/notes/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './addon';
23 changes: 0 additions & 23 deletions addons/notes/src/react.js

This file was deleted.

59 changes: 36 additions & 23 deletions addons/notes/src/register.js → addons/notes/src/register.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
import React from 'react';
import PropTypes from 'prop-types';
import * as React from 'react';
import addons from '@storybook/addons';

import styled from '@emotion/styled';

interface NotesChannel {
kroeder marked this conversation as resolved.
Show resolved Hide resolved
on: (listener: string, callback: (text: string) => void) => any; // todo check correct return value definition
emit: any; // todo check correct definition
removeListener: (listener: string, callback: (text: string) => void) => void;
}

interface NotesApi {
onStory: (callback: () => void) => void;
getQueryParam: any; // todo check correct definition
setQueryParams: any; // todo check correct definition
}

interface NotesProps {
active: boolean;
channel: NotesChannel;
api: NotesApi;
}

interface NotesState {
text: string;
}

const Panel = styled.div({
padding: 10,
boxSizing: 'border-box',
width: '100%',
width: '100%'
});

export class Notes extends React.Component {
constructor(...args) {
super(...args);
export class Notes extends React.Component<NotesProps, NotesState> {

// todo check how react typescript does this, especially unmounted
stopListeningOnStory: any; // todo check correct definition
unmounted: any; // todo check correct definition

constructor(...args: any) {
super(args /* todo: This was ...args before, check if this was a bug */);
kroeder marked this conversation as resolved.
Show resolved Hide resolved
this.state = { text: '' };
kroeder marked this conversation as resolved.
Show resolved Hide resolved
this.onAddNotes = this.onAddNotes.bind(this);
}
Expand Down Expand Up @@ -48,9 +74,9 @@ export class Notes extends React.Component {
const { text } = this.state;
const textAfterFormatted = text
? text
.trim()
.replace(/(<\S+.*>)\n/g, '$1')
.replace(/\n/g, '<br />')
.trim()
.replace(/(<\S+.*>)\n/g, '$1')
.replace(/\n/g, '<br />')
: '';

return active ? (
Expand All @@ -62,25 +88,12 @@ export class Notes extends React.Component {
}
}

Notes.propTypes = {
active: PropTypes.bool.isRequired,
channel: PropTypes.shape({
on: PropTypes.func,
emit: PropTypes.func,
removeListener: PropTypes.func,
}).isRequired,
api: PropTypes.shape({
onStory: PropTypes.func,
getQueryParam: PropTypes.func,
setQueryParams: PropTypes.func,
}).isRequired,
};

addons.register('storybook/notes', api => {
const channel = addons.getChannel();
addons.addPanel('storybook/notes/panel', {
title: 'Notes',
// eslint-disable-next-line react/prop-types
render: ({ active }) => <Notes channel={channel} api={api} active={active} />,
render: ({ active }) => <Notes channel={channel} api={api} active={active}/>
});
});
15 changes: 15 additions & 0 deletions addons/notes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"jsx": "react",
"module": "commonjs"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"src/__tests__/**/*"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.1.2",
"@emotion/snapshot-serializer": "0.8.2",
"@types/node": "^10.12.5",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
Expand Down
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"noImplicitAny": true,
"noImplicitAny": false,
kroeder marked this conversation as resolved.
Show resolved Hide resolved
"target": "es5",
"types": [
"node",
"jest"
],
"lib": [
"es2016",
"dom"
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.1.tgz#da61b64a2930a80fa708e57c45cd5441eb379d5b"
integrity sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ==

"@types/node@^10.12.5":
version "10.12.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.5.tgz#7e7ea1a9b34d2c8d704cb0b755dffbcda34741ad"
integrity sha512-GzdHjq3t3eGLMv92Al90Iq+EoLL+86mPfQhuglbBFO7HiLdC/rkt+zrzJJumAiBF6nsrBWhou22rPW663AAyFw==

"@types/node@^6.0.0", "@types/node@^6.0.46":
version "6.14.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.14.0.tgz#85c6998293fc6f2945915419296c7fbb63384f66"
Expand All @@ -2034,11 +2039,24 @@
dependencies:
"@types/node" "*"

"@types/prop-types@*":
version "15.5.6"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.6.tgz#9c03d3fed70a8d517c191b7734da2879b50ca26c"
integrity sha512-ZBFR7TROLVzCkswA3Fmqq+IIJt62/T7aY/Dmz+QkU7CaW2QFqAitCE8Ups7IzmGhcN1YWMBT4Qcoc07jU9hOJQ==

"@types/q@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5"
integrity sha1-vShOV8hPEyXacCur/IKlMoGQwMU=

"@types/react@^16.7.1":
version "16.7.1"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.1.tgz#ae76b653d1d7d26b32186bba33c39745316bcdc4"
integrity sha512-kxde2oP2JvHiEXiAfb8WkL+8Aa9txDRD7L8zb3BipMNRoBbcr32xy/kfpbxmWMus71yXgJDqBgLmWil6UXdLzQ==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/selenium-webdriver@^3.0.0":
version "3.0.12"
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.12.tgz#6affe5aed1ba379175075a889adbe2bc3aa62159"
Expand Down Expand Up @@ -7326,6 +7344,11 @@ cssstyle@^1.0.0, cssstyle@^1.1.1:
dependencies:
cssom "0.3.x"

csstype@^2.2.0:
version "2.5.7"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff"
integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw==

csurf@~1.8.3:
version "1.8.3"
resolved "https://registry.yarnpkg.com/csurf/-/csurf-1.8.3.tgz#23f2a13bf1d8fce1d0c996588394442cba86a56a"
Expand Down