-
Notifications
You must be signed in to change notification settings - Fork 18
/
register.js
40 lines (34 loc) · 1005 Bytes
/
register.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
39
40
import { types } from '@storybook/addons';
import { useParameter } from '@storybook/api';
import { AddonPanel } from '@storybook/components';
import addonAPI, { addons } from '@storybook/addons';
import React from 'react';
const ADDON_ID = 'axa-ch/changelog';
const PANEL_ID = `${ADDON_ID}/panel`;
const MyPanel = () => {
const value = useParameter('changelog', null);
const replaceUnneeded = (value) => {
if (value) {
return value
.replace('module.exports = "', '')
.replace(/\\n";/g, '<br>')
.replace(/\\n/g, '<br>');
}
return 'No Changelog found.';
};
return <div style={{ margin: '8px' }}
dangerouslySetInnerHTML={{ __html: replaceUnneeded(value) }}></div>;
};
addonAPI.register(ADDON_ID, api => {
const render = ({ active, key }) => (
<AddonPanel active={active} key={key}>
<MyPanel/>
</AddonPanel>
);
const title = 'Changelog';
addons.add(PANEL_ID, {
type: types.PANEL,
title,
render,
});
});