wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
53 lines • 2.77 kB
JavaScript
import { __spreadArray } from "tslib";
import * as React from 'react';
import get from 'lodash/get';
import { DriverDocumentation } from './driver-documentation';
import { UnifiedTestkitDocumentation } from './unified-testkit-documentation';
import { isUnidriver, determineTestkit } from './determine-testkit';
import Markdown from '../Markdown';
var unidriverFirst = function (drivers) {
var _a = drivers.reduce(function (_a, driver) {
var uni = _a[0], rest = _a[1];
if (isUnidriver(driver.file)) {
uni.push(driver);
}
else {
rest.push(driver);
}
return [uni, rest];
}, [[], []]), unidrivers = _a[0], others = _a[1];
return __spreadArray(__spreadArray([], unidrivers, true), others, true);
};
var createDriverDocumentation = function (metadata, storyConfig, hideImport) {
return unidriverFirst(metadata.drivers)
.filter(function (_a) {
var error = _a.error;
return !error;
})
.map(function (_a) {
var file = _a.file, descriptor = _a.descriptor;
var _b = determineTestkit({
fileName: file,
displayName: metadata.displayName,
}), type = _b.type, title = _b.title;
return (React.createElement(DriverDocumentation, { key: file, dataHook: "auto-testkit-driver", unidriver: isUnidriver(file), descriptor: descriptor, metadata: metadata, title: title, testkitConfig: get(storyConfig, "config.testkits.".concat(type)), hideImport: hideImport }));
});
};
var createUnifiedTestkitDocumentation = function (metadata, storyConfig, hideImport) {
return (React.createElement(UnifiedTestkitDocumentation, { dataHook: "auto-unified-testkit", metadata: metadata, storyConfig: storyConfig, hideImport: hideImport }));
};
export var AutoTestkit = function (_a) {
var metadata = _a.metadata, storyConfig = _a.storyConfig, hideImport = _a.hideImport;
return (React.createElement("div", { className: "markdown-body" },
get(storyConfig, 'config.unifiedTestkit') ? (React.createElement("h1", { "data-hook": "auto-testkit-heading" },
metadata.displayName,
" Testkit")) : (React.createElement("h1", { "data-hook": "auto-testkit-heading" },
metadata.displayName,
" Testkits")),
get(storyConfig, 'config.testkitsWarning') && (React.createElement("div", { "data-hook": "auto-testkit-warning" },
React.createElement(Markdown, { source: storyConfig.config.testkitsWarning }))),
get(storyConfig, 'config.unifiedTestkit')
? createUnifiedTestkitDocumentation(metadata, storyConfig, hideImport)
: createDriverDocumentation(metadata, storyConfig, hideImport)));
};
//# sourceMappingURL=index.js.map