UNPKG

3.67 kBJavaScriptView Raw
1import "core-js/modules/es.array.concat.js";
2import "core-js/modules/es.array.index-of.js";
3import "core-js/modules/es.object.keys.js";
4
5function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
7function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
9import React, { createElement, Fragment } from 'react';
10import { IFrame } from './IFrame';
11import { EmptyBlock } from './EmptyBlock';
12import { ZoomContext } from './ZoomContext';
13var BASE_URL = 'iframe.html';
14export var StoryError;
15/** error message for Story with null storyFn
16 * if the story id exists, it must be pointing to a non-existing story
17 * if there is assigned story id, the story must be empty
18 */
19
20(function (StoryError) {
21 StoryError["NO_STORY"] = "No component or story to display";
22})(StoryError || (StoryError = {}));
23
24var MISSING_STORY = function MISSING_STORY(id) {
25 return id ? "Story \"".concat(id, "\" doesn't exist.") : StoryError.NO_STORY;
26};
27
28var InlineStory = function InlineStory(_ref) {
29 var storyFn = _ref.storyFn,
30 height = _ref.height,
31 id = _ref.id;
32 return /*#__PURE__*/React.createElement(Fragment, null, height ? /*#__PURE__*/React.createElement("style", null, "#story--".concat(id, " { min-height: ").concat(height, "; transform: translateZ(0); overflow: auto }")) : null, /*#__PURE__*/React.createElement(Fragment, null, storyFn ? /*#__PURE__*/createElement(storyFn) : /*#__PURE__*/React.createElement(EmptyBlock, null, MISSING_STORY(id))));
33};
34
35InlineStory.displayName = "InlineStory";
36
37var IFrameStory = function IFrameStory(_ref2) {
38 var id = _ref2.id,
39 title = _ref2.title,
40 _ref2$height = _ref2.height,
41 height = _ref2$height === void 0 ? '500px' : _ref2$height;
42 return /*#__PURE__*/React.createElement("div", {
43 style: {
44 width: '100%',
45 height: height
46 }
47 }, /*#__PURE__*/React.createElement(ZoomContext.Consumer, null, function (_ref3) {
48 var scale = _ref3.scale;
49 return /*#__PURE__*/React.createElement(IFrame, {
50 key: "iframe",
51 id: "iframe--".concat(id),
52 title: title,
53 src: "".concat(BASE_URL, "?id=").concat(id, "&viewMode=story"),
54 allowFullScreen: true,
55 scale: scale,
56 style: {
57 width: '100%',
58 height: '100%',
59 border: '0 none'
60 }
61 });
62 }));
63};
64
65IFrameStory.displayName = "IFrameStory";
66
67/**
68 * A story element, either rendered inline or in an iframe,
69 * with configurable height.
70 */
71var Story = function Story(_ref4) {
72 var children = _ref4.children,
73 error = _ref4.error,
74 inline = _ref4.inline,
75 props = _objectWithoutProperties(_ref4, ["children", "error", "inline"]);
76
77 var id = props.id,
78 title = props.title,
79 height = props.height;
80
81 if (error) {
82 return /*#__PURE__*/React.createElement(EmptyBlock, null, error);
83 }
84
85 return inline ? /*#__PURE__*/React.createElement(InlineStory, props) : /*#__PURE__*/React.createElement(IFrameStory, {
86 id: id,
87 title: title,
88 height: height
89 });
90};
91
92export { Story };
\No newline at end of file