UNPKG

wix-storybook-utils

Version:

Utilities for automated component documentation within Storybook

37 lines 2.33 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.sectionWithSiblings = exports.SIBLINGS = void 0; var tslib_1 = require("tslib"); var React = tslib_1.__importStar(require("react")); var story_section_1 = require("../../typings/story-section"); var Markdown_1 = tslib_1.__importDefault(require("../../Markdown")); var styles_scss_1 = tslib_1.__importDefault(require("./styles.scss")); var AnchoredTitle_1 = require("../../AnchoredTitle/AnchoredTitle"); exports.SIBLINGS = ['pretitle', 'title', 'subtitle', 'description']; var SECTIONS_WITHOUT_SIBLINGS = [ story_section_1.SectionType.Title, story_section_1.SectionType.Header, story_section_1.SectionType.Example, ]; var sectionPrepares = (_a = {}, _a[story_section_1.SectionType.ImportExample] = function (section) { return (tslib_1.__assign(tslib_1.__assign({}, section), { title: section.title || 'Import' })); }, _a); var prepareSection = function (section) { var preparedSection = (sectionPrepares[section.type] || (function (i) { return i; }))(section); var siblingsWithDiv = exports.SIBLINGS.filter(function (sibling) { return preparedSection[sibling]; }).reduce(function (sections, key) { var _a; return (tslib_1.__assign(tslib_1.__assign({}, sections), (_a = {}, _a[key] = (React.createElement(Markdown_1.default, { key: key, className: styles_scss_1.default[key], source: preparedSection[key] })), _a))); }, {}); return tslib_1.__assign(tslib_1.__assign({}, preparedSection), siblingsWithDiv); }; var sectionWithSiblings = function (section, children, isAnchored) { var preparedSection = prepareSection(section); var siblings = exports.SIBLINGS.filter(function (row) { return preparedSection[row]; }); var shouldShowSiblings = siblings.length > 0 && !SECTIONS_WITHOUT_SIBLINGS.includes(section.type); return (React.createElement("div", { "data-hook": section.dataHook || null }, shouldShowSiblings ? (React.createElement("div", { className: styles_scss_1.default.titles }, isAnchored ? (React.createElement(AnchoredTitle_1.AnchoredTitle, { title: section.title })) : (siblings.map(function (row) { return preparedSection[row]; })))) : null, children)); }; exports.sectionWithSiblings = sectionWithSiblings; //# sourceMappingURL=index.js.map