UNPKG

4.49 kBJavaScriptView Raw
1"use strict";
2
3require("core-js/modules/es.object.assign");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.setDefaults = setDefaults;
9Object.defineProperty(exports, "Story", {
10 enumerable: true,
11 get: function get() {
12 return _Story["default"];
13 }
14});
15exports.withInfo = void 0;
16
17var _react = _interopRequireDefault(require("react"));
18
19var _nestedObjectAssign = _interopRequireDefault(require("nested-object-assign"));
20
21var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
22
23var _addons = require("@storybook/addons");
24
25var _clientLogger = require("@storybook/client-logger");
26
27var _Story = _interopRequireDefault(require("./components/Story"));
28
29var _index = _interopRequireDefault(require("./components/PropTable/index"));
30
31var _makeTableComponent = _interopRequireDefault(require("./components/makeTableComponent"));
32
33var _markdown = require("./components/markdown");
34
35function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
36
37var defaultOptions = {
38 inline: false,
39 header: true,
40 source: true,
41 propTables: [],
42 propTableCompare: function propTableCompare(element, Component) {
43 return (// https://github.com/gaearon/react-hot-loader#checking-element-types
44 typeof reactHotLoaderGlobal === 'undefined' ? element.type === Component : // eslint-disable-next-line no-undef
45 reactHotLoaderGlobal.areComponentsEqual(element.type, Component)
46 );
47 },
48 TableComponent: _index["default"],
49 maxPropsIntoLine: 3,
50 maxPropObjectKeys: 3,
51 maxPropArrayLength: 3,
52 maxPropStringLength: 50
53};
54var defaultComponents = {
55 h1: _markdown.H1,
56 h2: _markdown.H2,
57 h3: _markdown.H3,
58 h4: _markdown.H4,
59 h5: _markdown.H5,
60 h6: _markdown.H6,
61 code: _markdown.Code,
62 p: _markdown.P,
63 a: _markdown.A,
64 li: _markdown.LI,
65 ul: _markdown.UL
66};
67var hasWarned = false;
68
69function addInfo(storyFn, context, infoOptions) {
70 var options = Object.assign({}, defaultOptions, {}, infoOptions); // props.propTables can only be either an array of components or null
71 // propTables option is allowed to be set to 'false' (a boolean)
72 // if the option is false, replace it with null to avoid react warnings
73
74 if (!options.propTables) {
75 options.propTables = null;
76 }
77
78 var components = Object.assign({}, defaultComponents);
79
80 if (options && options.components) {
81 Object.assign(components, options.components);
82 }
83
84 if (options && options.marksyConf) {
85 if (!hasWarned) {
86 _clientLogger.logger.warn('@storybook/addon-info: "marksyConf" option has been renamed to "components"');
87
88 hasWarned = true;
89 }
90
91 Object.assign(components, options.marksyConf);
92 }
93
94 var props = {
95 info: options.text,
96 context: context,
97 showInline: Boolean(options.inline),
98 showHeader: Boolean(options.header),
99 showSource: Boolean(options.source),
100 styles: typeof options.styles === 'function' ? options.styles : function (s) {
101 return (0, _nestedObjectAssign["default"])({}, s, options.styles);
102 },
103 propTables: options.propTables,
104 propTablesExclude: options.propTablesExclude,
105 propTableCompare: options.propTableCompare,
106 PropTable: (0, _makeTableComponent["default"])(options.TableComponent),
107 components: components,
108 maxPropObjectKeys: options.maxPropObjectKeys,
109 maxPropArrayLength: options.maxPropArrayLength,
110 maxPropsIntoLine: options.maxPropsIntoLine,
111 maxPropStringLength: options.maxPropStringLength,
112 excludedPropTypes: options.excludedPropTypes
113 };
114 return _react["default"].createElement(_Story["default"], props, storyFn(context));
115}
116
117var withInfo = (0, _addons.makeDecorator)({
118 name: 'withInfo',
119 parameterName: 'info',
120 allowDeprecatedUsage: true,
121 wrapper: function wrapper(getStory, context, _ref) {
122 var options = _ref.options,
123 parameters = _ref.parameters;
124 var storyOptions = parameters || options;
125 var infoOptions = typeof storyOptions === 'string' ? {
126 text: storyOptions
127 } : storyOptions;
128 var mergedOptions = typeof infoOptions === 'string' ? infoOptions : Object.assign({}, options, {}, infoOptions);
129 return addInfo(getStory, context, mergedOptions);
130 }
131});
132exports.withInfo = withInfo;
133
134function setDefaults(newDefaults) {
135 return (0, _utilDeprecate["default"])(function () {
136 return Object.assign(defaultOptions, newDefaults);
137 }, 'setDefaults is deprecated. Instead, you can pass options into withInfo(options) directly, or use the info parameter.')();
138}
\No newline at end of file