wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
50 lines • 2.64 kB
JavaScript
import { __assign, __spreadArray } from "tslib";
import { header, tabs, tab, description, importExample, api, playground, testkit, } from '.';
import { importString } from '../StoryPage/import-string';
var given = function (expr) { return function (item) { return (expr ? [item] : []); }; };
var getHeader = function (sections) { return sections[0] || {}; };
var getSourceUrl = function (_a) {
var _b = _a.config.repoBaseURL, repoBaseURL = _b === void 0 ? '' : _b, displayName = _a.metadata.displayName;
return (repoBaseURL && displayName ? "".concat(repoBaseURL).concat(displayName) : undefined);
};
export var createDefaultSections = function (_a) {
var config = _a.config, metadata = _a.metadata, exampleImport = _a.exampleImport, examples = _a.examples, storyName = _a.storyName, _b = _a.sections, sections = _b === void 0 ? [] : _b;
return [
header(__assign({ dataHook: 'section-header', sourceUrl: getSourceUrl({ config: config, metadata: metadata }), title: storyName || metadata.displayName }, getHeader(sections))),
tabs(__spreadArray([
tab({
title: 'Usage',
sections: __spreadArray(__spreadArray(__spreadArray([], given(metadata.readme || metadata.description)(description({
title: 'Description',
text: metadata.readme || metadata.description,
dataHook: 'metadata-readme',
})), true), [
importExample({
source: importString({ config: config, metadata: metadata, exampleImport: exampleImport }),
dataHook: 'metadata-import',
}),
playground()
], false), given(!!examples)(examples), true),
}),
tab({
title: 'API',
sections: __spreadArray(__spreadArray([], given(metadata.readmeApi)(description({ text: metadata.readmeApi, dataHook: 'api-markdown' })), true), [
api(),
], false),
}),
tab({
title: 'Testkit',
sections: __spreadArray([
testkit()
], given(metadata.readmeTestkit)(description({
text: metadata.readmeTestkit,
dataHook: 'testkit-markdown',
})), true),
})
], given(metadata.readmeAccessibility)(tab({
title: 'Accessibility',
sections: [description(metadata.readmeAccessibility)],
})), true)),
];
};
//# sourceMappingURL=create-default-sections.js.map