UNPKG

storybook-amp

Version:

Storybook addon for AMP Html. Allows to display in your stories AMP Html components generated with React.

27 lines (26 loc) 723 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _server = require("react-dom/server"); var _styledComponents = require("styled-components"); var _default = function _default(storyFn, context) { var html = ""; var styles; var sheet = new _styledComponents.ServerStyleSheet(); try { html = (0, _server.renderToStaticMarkup)(sheet.collectStyles(storyFn(context))); var styleTags = sheet.getStyleTags(); styles = styleTags.replace(/<style[^>]*>/, "").replace("</style>", ""); } catch (error) { console.error(error); } finally { sheet.seal(); } return { html: html, styles: styles }; }; exports["default"] = _default;