UNPKG

@storybook/addon-info

Version:

A Storybook addon to show additional information for your stories.

138 lines (115 loc) 4.49 kB
"use strict"; require("core-js/modules/es.object.assign"); Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaults = setDefaults; Object.defineProperty(exports, "Story", { enumerable: true, get: function get() { return _Story["default"]; } }); exports.withInfo = void 0; var _react = _interopRequireDefault(require("react")); var _nestedObjectAssign = _interopRequireDefault(require("nested-object-assign")); var _utilDeprecate = _interopRequireDefault(require("util-deprecate")); var _addons = require("@storybook/addons"); var _clientLogger = require("@storybook/client-logger"); var _Story = _interopRequireDefault(require("./components/Story")); var _index = _interopRequireDefault(require("./components/PropTable/index")); var _makeTableComponent = _interopRequireDefault(require("./components/makeTableComponent")); var _markdown = require("./components/markdown"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var defaultOptions = { inline: false, header: true, source: true, propTables: [], propTableCompare: function propTableCompare(element, Component) { return (// https://github.com/gaearon/react-hot-loader#checking-element-types typeof reactHotLoaderGlobal === 'undefined' ? element.type === Component : // eslint-disable-next-line no-undef reactHotLoaderGlobal.areComponentsEqual(element.type, Component) ); }, TableComponent: _index["default"], maxPropsIntoLine: 3, maxPropObjectKeys: 3, maxPropArrayLength: 3, maxPropStringLength: 50 }; var defaultComponents = { h1: _markdown.H1, h2: _markdown.H2, h3: _markdown.H3, h4: _markdown.H4, h5: _markdown.H5, h6: _markdown.H6, code: _markdown.Code, p: _markdown.P, a: _markdown.A, li: _markdown.LI, ul: _markdown.UL }; var hasWarned = false; function addInfo(storyFn, context, infoOptions) { var options = Object.assign({}, defaultOptions, {}, infoOptions); // props.propTables can only be either an array of components or null // propTables option is allowed to be set to 'false' (a boolean) // if the option is false, replace it with null to avoid react warnings if (!options.propTables) { options.propTables = null; } var components = Object.assign({}, defaultComponents); if (options && options.components) { Object.assign(components, options.components); } if (options && options.marksyConf) { if (!hasWarned) { _clientLogger.logger.warn('@storybook/addon-info: "marksyConf" option has been renamed to "components"'); hasWarned = true; } Object.assign(components, options.marksyConf); } var props = { info: options.text, context: context, showInline: Boolean(options.inline), showHeader: Boolean(options.header), showSource: Boolean(options.source), styles: typeof options.styles === 'function' ? options.styles : function (s) { return (0, _nestedObjectAssign["default"])({}, s, options.styles); }, propTables: options.propTables, propTablesExclude: options.propTablesExclude, propTableCompare: options.propTableCompare, PropTable: (0, _makeTableComponent["default"])(options.TableComponent), components: components, maxPropObjectKeys: options.maxPropObjectKeys, maxPropArrayLength: options.maxPropArrayLength, maxPropsIntoLine: options.maxPropsIntoLine, maxPropStringLength: options.maxPropStringLength, excludedPropTypes: options.excludedPropTypes }; return _react["default"].createElement(_Story["default"], props, storyFn(context)); } var withInfo = (0, _addons.makeDecorator)({ name: 'withInfo', parameterName: 'info', allowDeprecatedUsage: true, wrapper: function wrapper(getStory, context, _ref) { var options = _ref.options, parameters = _ref.parameters; var storyOptions = parameters || options; var infoOptions = typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions; var mergedOptions = typeof infoOptions === 'string' ? infoOptions : Object.assign({}, options, {}, infoOptions); return addInfo(getStory, context, mergedOptions); } }); exports.withInfo = withInfo; function setDefaults(newDefaults) { return (0, _utilDeprecate["default"])(function () { return Object.assign(defaultOptions, newDefaults); }, 'setDefaults is deprecated. Instead, you can pass options into withInfo(options) directly, or use the info parameter.')(); }