aboutsummaryrefslogtreecommitdiffstats
path: root/stories/react/utils/Examples.js
blob: 5948b68c7e2686c5acd4a08cbac27ada2f7b829d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React from 'react';
import {renderToStaticMarkup} from 'react-dom/server';
import SourceToggle from './SourceToggle.js';
import beautifyHTML from './BeautifyHTML.js';
import insertSVGIcons from './InsertSVGIcons.js';

const Examples = ({examples}) => (
  <div className={'examples'}>
	  {Object.keys(examples).map(key => {
		let title = key;
		let {jsx, html, displayTitle = true, exclude, renderFromJsx = false} = examples[key];
		if (!html) {
			html = renderToStaticMarkup(jsx);
			html = beautifyHTML({html, indentChar: '  '});
		} else {
			html = insertSVGIcons({html, jsx});
		}
		return <SourceToggle title={displayTitle && title} jsx={jsx} html={html} key={key} exclude={exclude} renderFromJsx={renderFromJsx}/>;
	  })}
  </div>
);

export default Examples;