-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/next' into next
# Conflicts: # .teamcity/OpenSourceProjects_Storybook/buildTypes/StorybookApp.kt
- Loading branch information
Showing
15 changed files
with
201 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ built-storybooks | |
lib/cli/test | ||
*.bundle.js | ||
*.js.map | ||
*.ts | ||
|
||
!.remarkrc.js | ||
!.babelrc.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '.'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import * as React from 'react'; | ||
import addons from '@storybook/addons'; | ||
import * as PropTypes from 'prop-types'; | ||
|
||
import styled from '@emotion/styled'; | ||
|
||
// todo this is going to be refactored after the migration of @storybook/channel to TypeScript | ||
interface NotesChannel { | ||
emit: any; | ||
on(listener: string, callback: (text: string) => void): any; | ||
removeListener(listener: string, callback: (text: string) => void): void; | ||
} | ||
|
||
interface NotesApi { | ||
setQueryParams: any; // todo check correct definition | ||
getQueryParam(queryParamName: string): any; | ||
|
||
onStory(callback: () => void): () => void; | ||
} | ||
|
||
interface NotesProps { | ||
active: boolean; | ||
channel: NotesChannel; | ||
api: NotesApi; | ||
} | ||
|
||
interface NotesState { | ||
text: string; | ||
} | ||
|
||
const Panel = styled.div({ | ||
padding: 10, | ||
boxSizing: 'border-box', | ||
width: '100%', | ||
}); | ||
|
||
export class Notes extends React.Component<NotesProps, NotesState> { | ||
|
||
static 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, | ||
}; | ||
|
||
stopListeningOnStory: () => void; | ||
isUnmounted = false; | ||
|
||
readonly state: NotesState = { text: '' }; | ||
|
||
constructor(props: NotesProps) { | ||
super(props); | ||
this.onAddNotes = this.onAddNotes.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
const { channel, api } = this.props; | ||
// Listen to the notes and render it. | ||
channel.on('storybook/notes/add_notes', this.onAddNotes); | ||
|
||
// Clear the current notes on every story change. | ||
this.stopListeningOnStory = api.onStory(() => { | ||
this.onAddNotes(''); | ||
}); | ||
} | ||
|
||
// This is some cleanup tasks when the Notes panel is unmounting. | ||
componentWillUnmount() { | ||
if (this.stopListeningOnStory) { | ||
this.stopListeningOnStory(); | ||
} | ||
|
||
this.isUnmounted = true; | ||
const { channel } = this.props; | ||
channel.removeListener('storybook/notes/add_notes', this.onAddNotes); | ||
} | ||
|
||
onAddNotes(text: string) { | ||
this.setState({ text }); | ||
} | ||
|
||
render() { | ||
const { active } = this.props; | ||
const { text } = this.state; | ||
const textAfterFormatted = text | ||
? text | ||
.trim() | ||
.replace(/(<\S+.*>)\n/g, '$1') | ||
.replace(/\n/g, '<br />') | ||
: ''; | ||
|
||
return active ? ( | ||
<Panel | ||
className="addon-notes-container" | ||
dangerouslySetInnerHTML={{ __html: textAfterFormatted }} | ||
/> | ||
) : null; | ||
} | ||
} | ||
|
||
addons.register('storybook/notes', (api: any) => { | ||
const channel = addons.getChannel(); | ||
addons.addPanel('storybook/notes/panel', { | ||
title: 'Notes', | ||
render: ({ active }: { active: boolean }) => <Notes channel={channel} api={api} active={active}/>, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Fixes 'noImplicitAny' lint error because @storybook/addons isn't migrated to typescript yet | ||
declare module '@storybook/addons'; | ||
|
||
// Only necessary for 0.x.x. Version 10.x.x has definition files included | ||
declare module '@emotion/styled'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.tsx" | ||
], | ||
"exclude": [ | ||
"src/__tests__/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.