UNPKG

1.68 kBJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.object.assign");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports["default"] = void 0;
9
10var _global = require("global");
11
12var _addons = require("@storybook/addons");
13
14var _parameters = _interopRequireDefault(require("./parameters"));
15
16var _styles = _interopRequireDefault(require("./styles"));
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
20var INNER_ID = 'sb-addon-centered-inner';
21var WRAPPER_ID = 'sb-addon-centered-wrapper';
22
23function getOrCreate(id, style) {
24 var elementOnDom = _global.document.getElementById(id);
25
26 if (elementOnDom) {
27 return elementOnDom;
28 }
29
30 var element = _global.document.createElement('div');
31
32 element.setAttribute('id', id);
33 Object.assign(element.style, style);
34 return element;
35}
36
37function getInnerDiv() {
38 return getOrCreate(INNER_ID, _styles["default"].innerStyle);
39}
40
41function getWrapperDiv() {
42 return getOrCreate(WRAPPER_ID, _styles["default"].style);
43}
44
45function centered(storyFn) {
46 var inner = getInnerDiv();
47 var wrapper = getWrapperDiv();
48 wrapper.appendChild(inner);
49 var element = storyFn();
50
51 if (typeof element === 'string') {
52 inner.innerHTML = element;
53 } else if (element instanceof _global.Node) {
54 inner.innerHTML = '';
55 inner.appendChild(element);
56 } else {
57 return element;
58 }
59
60 return wrapper;
61}
62
63var _default = (0, _addons.makeDecorator)(Object.assign({}, _parameters["default"], {
64 wrapper: function wrapper(getStory) {
65 return centered(getStory);
66 }
67}));
68
69exports["default"] = _default;
70
71if (module && module.hot && module.hot.decline) {
72 module.hot.decline();
73}
\No newline at end of file