-
Notifications
You must be signed in to change notification settings - Fork 0
/
react.js
38 lines (32 loc) · 929 Bytes
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { Fragment } from 'react'
import injectScript from './inject'
class WithExternalLink extends React.PureComponent {
componentDidMount() {
injectScript(this.props.url, this.props.options)
}
render() {
return this.props.children
}
}
/**
* Method to create storybook vue decorator for inject external links
* @param {String} url
* @param {Object} options
* @return {Function} decorator method
*/
function decoratorFactory(url = '', options) {
if (!url || !url.length) {
console.warn('No url provided to `external-links` Storybook decorator')
return getStory => getStory();
}
// return getStory => <WithExternalLink url={url} options={options}>{ getStory() }</WithExternalLink>
return getStory => React.createElement(
WithExternalLink,
{
url,
options,
},
getStory(),
)
}
export default decoratorFactory