Skip to content

Commit

Permalink
Merge pull request #5381 from Sayegh7/feature/markdown_giphy
Browse files Browse the repository at this point in the history
ADD giphy support in notes addon
  • Loading branch information
ndelangen authored Jan 27, 2019
2 parents f98edcb + 85c081a commit 0252f5d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
11 changes: 11 additions & 0 deletions addons/notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ import notes from './someMarkdownText.md';
storiesOf('Component', module)
.add('With Markdown', () => <Component />, { notes });
```

### Giphy

When using markdown, you can also embed gifs from Giphy into your markdown. Currently, the value `gif` of the gif prop is used to search and return the first result returned by Giphy.

```md
# Title

<Giphy gif='cheese' />
```

12 changes: 10 additions & 2 deletions addons/notes/src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { styled } from '@storybook/theming';
import { STORY_CHANGED } from '@storybook/core-events';

import { SyntaxHighlighter as SyntaxHighlighterBase, Placeholder } from '@storybook/components';
import Giphy from './giphy';
import Markdown from 'markdown-to-jsx';

import { PARAM_KEY, API, Parameters } from './shared';
Expand Down Expand Up @@ -59,7 +60,14 @@ export default class NotesPanel extends React.Component<Props, NotesPanelState>

// use our SyntaxHighlighter component in place of a <code> element when
// converting markdown to react elements
options = { overrides: { code: SyntaxHighlighter } };
options = {
overrides: {
code: SyntaxHighlighter,
Giphy: {
component: Giphy
}
}
};

componentDidMount() {
const { api } = this.props;
Expand All @@ -77,7 +85,7 @@ export default class NotesPanel extends React.Component<Props, NotesPanelState>

const value = read(params);
if (value) {
this.setState({ value });
this.setState({ value });
} else {
this.setState({ value: undefined });
}
Expand Down
34 changes: 34 additions & 0 deletions addons/notes/src/giphy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import * as PropTypes from 'prop-types';

interface Props{
gif: String
}
interface GiphyState {
src?: string;
}
export default class Giphy extends React.Component<Props, GiphyState> {
static propTypes = {
gif: PropTypes.string.isRequired,
}
constructor(props: any){
super(props)
this.state = {
src: null
}
fetch(`http://api.giphy.com/v1/gifs/search?limit=1&api_key=dc6zaTOxFJmzC&q=${props.gif}`)
.then(response => {
if(response.ok){
return response.json()
}
})
.then(data => {
this.setState({ src: data.data[0].images.original.url})
})
}
render() {
return (
<img src={this.state.src} />
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ exports[`Storyshots Addons|Notes addon notes rendering inline, github-flavored m
</button>
`;

exports[`Storyshots Addons|Notes with a markdown giphy 1`] = `
<button
type="button"
>
Button with notes - check the notes panel for details
</button>
`;

exports[`Storyshots Addons|Notes with a markdown table 1`] = `
<button
type="button"
Expand Down
9 changes: 9 additions & 0 deletions examples/official-storybook/stories/addon-notes.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const markdownTable = `
| Row4.1 | Row4.2 | Row4.3 |
`;

const giphyMarkdown = `
# Giphy
<Giphy gif='cheese' />
`;

storiesOf('Addons|Notes', module)
.add('addon notes', baseStory, {
notes:
Expand All @@ -54,4 +60,7 @@ storiesOf('Addons|Notes', module)
})
.add('with a markdown table', baseStory, {
notes: { markdown: markdownTable },
})
.add('with a markdown giphy', baseStory, {
notes: { markdown: giphyMarkdown },
});

0 comments on commit 0252f5d

Please sign in to comment.