wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
147 lines • 6.78 kB
JavaScript
import { __assign, __extends } from "tslib";
import * as React from 'react';
import { Driver, r } from './driver';
import { PrimitiveDocumentation } from './primitive-documentation';
import { MethodDocumentation } from './method-documentation';
import { FieldsDocumentation } from './fields-documentation';
import { DriverDocumentation } from './driver-documentation';
import { AutoTestkit } from './index';
import Markdown from '../Markdown';
var DriverDocumentationDriver = /** @class */ (function (_super) {
__extends(DriverDocumentationDriver, _super);
function DriverDocumentationDriver() {
var _this = _super.call(this, DriverDocumentation, 'driver-') || this;
_this.get = {
name: function () { return _this.select('name').text(); },
descriptor: function () { return _this.select('descriptor').text(); },
fields: function () {
var component = _this.select('descriptor').childAt(0);
return createFieldsDocumentationDriver().reuse(component);
},
allFields: function () {
var components = _this.select('fields');
var allFields = components.reduce(function (fields, component) {
var field = createFieldsDocumentationDriver().reuse(component);
var count = field.get.count();
var i = 0;
while (i < count) {
fields.push(field.get.at(i));
i++;
}
return fields;
}, []);
return allFields;
},
tag: function (hook) { return _this.select(hook).name(); },
importCode: function () {
return _this.find('[data-hook="metadata-import-markdown"]').prop('source');
},
};
return _this;
}
return DriverDocumentationDriver;
}(Driver));
var AutoTestkitDriver = /** @class */ (function (_super) {
__extends(AutoTestkitDriver, _super);
function AutoTestkitDriver() {
var _this = _super.call(this, AutoTestkit, '') || this;
_this.get = {
driverAt: function (index) {
var driverDoc = _this.select('driver').at(index);
return driverDoc.length === 0
? null
: createDriverDocumentationDriver().reuse(driverDoc);
},
heading: function () { return _this.select('heading').text(); },
tag: function (hook) { return _this.select(hook).name(); },
rootClass: function () { return _this.selectRoot().props().className; },
warning: function () {
return _this.select('warning')
.find(Markdown)
.prop('source');
},
};
return _this;
}
return AutoTestkitDriver;
}(Driver));
var FieldsDocumentationDriver = /** @class */ (function (_super) {
__extends(FieldsDocumentationDriver, _super);
function FieldsDocumentationDriver() {
var _this = _super.call(this, FieldsDocumentation, '') || this;
_this.get = {
content: function () { return _this.select('fields').text(); },
at: function (index) {
var component = _this.select('field').at(index);
switch (component.props().unit.type) {
case 'value':
case 'error':
case 'object':
return createPrimitiveDocumentationDriver().reuse(component);
case 'function':
return createMethodDocumentationDriver().reuse(component);
default:
return _this;
}
},
count: function () { return _this.find('tbody tr').length; },
header: function (hook) {
var header = _this.select("".concat(hook, "-header"));
return {
tag: function () { return header.name(); },
text: function () { return header.text(); },
};
},
};
return _this;
}
return FieldsDocumentationDriver;
}(Driver));
var MethodDocumentationDriver = /** @class */ (function (_super) {
__extends(MethodDocumentationDriver, _super);
function MethodDocumentationDriver() {
var _this = _super.call(this, MethodDocumentationDriver.Component, 'function-') || this;
_this.get = {
name: function () { return _this.select('name').text(); },
arguments: function () { return _this.select('arguments').text(); },
argumentNames: function () { return _this.select('argument-name').map(function (name) { return name.text(); }); },
argumentTypes: function () { return _this.select('argument-type').map(function (type) { return type.text(); }); },
description: function () { return _this.select('description').text(); },
};
return _this;
}
MethodDocumentationDriver.Component = function (props) { return (React.createElement("table", null,
React.createElement("tbody", null,
React.createElement(MethodDocumentation, __assign({}, props))))); };
return MethodDocumentationDriver;
}(Driver));
var PrimitiveDocumentationDriver = /** @class */ (function (_super) {
__extends(PrimitiveDocumentationDriver, _super);
function PrimitiveDocumentationDriver() {
var _this = _super.call(this, PrimitiveDocumentationDriver.Component, 'primitive-') || this;
_this.get = {
name: function () { return _this.select('name').text(); },
description: function () { return _this.select('description').text(); },
tag: function (hook) { return _this.select(hook).name(); },
};
return _this;
}
PrimitiveDocumentationDriver.Component = function (props) { return (React.createElement("table", null,
React.createElement("tbody", null,
React.createElement(PrimitiveDocumentation, __assign({}, props))))); };
return PrimitiveDocumentationDriver;
}(Driver));
export var createPrimitiveDocumentationDriver = function () {
return r(new PrimitiveDocumentationDriver());
};
export var createMethodDocumentationDriver = function () {
return r(new MethodDocumentationDriver());
};
export var createFieldsDocumentationDriver = function () {
return r(new FieldsDocumentationDriver());
};
export var createAutoTestkitDriver = function () { return r(new AutoTestkitDriver()); };
export var createDriverDocumentationDriver = function () {
return r(new DriverDocumentationDriver());
};
//# sourceMappingURL=drivers.js.map