wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
33 lines • 1.88 kB
JavaScript
var _a;
import { __assign } from "tslib";
import * as React from 'react';
import { SectionType, } from '../../typings/story-section';
import Markdown from '../../Markdown';
import styles from './styles.scss';
import { AnchoredTitle } from '../../AnchoredTitle/AnchoredTitle';
export var SIBLINGS = ['pretitle', 'title', 'subtitle', 'description'];
var SECTIONS_WITHOUT_SIBLINGS = [
SectionType.Title,
SectionType.Header,
SectionType.Example,
];
var sectionPrepares = (_a = {},
_a[SectionType.ImportExample] = function (section) { return (__assign(__assign({}, section), { title: section.title || 'Import' })); },
_a);
var prepareSection = function (section) {
var preparedSection = (sectionPrepares[section.type] || (function (i) { return i; }))(section);
var siblingsWithDiv = SIBLINGS.filter(function (sibling) { return preparedSection[sibling]; }).reduce(function (sections, key) {
var _a;
return (__assign(__assign({}, sections), (_a = {}, _a[key] = (React.createElement(Markdown, { key: key, className: styles[key], source: preparedSection[key] })), _a)));
}, {});
return __assign(__assign({}, preparedSection), siblingsWithDiv);
};
export var sectionWithSiblings = function (section, children, isAnchored) {
var preparedSection = prepareSection(section);
var siblings = 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.titles }, isAnchored ? (React.createElement(AnchoredTitle, { title: section.title })) : (siblings.map(function (row) { return preparedSection[row]; })))) : null,
children));
};
//# sourceMappingURL=index.js.map