@storybook/addon-docs
Version:
Superior documentation for your components
83 lines (62 loc) • 3.56 kB
JavaScript
;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
require("core-js/modules/es.regexp.exec");
require("core-js/modules/es.string.split");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Title = exports.defaultTitleSlot = void 0;
var _react = _interopRequireWildcard(require("react"));
var _csf = require("@storybook/csf");
var _components = require("@storybook/components");
var _DocsContext = require("./DocsContext");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var defaultTitleSlot = function defaultTitleSlot(_ref) {
var selectedKind = _ref.selectedKind,
parameters = _ref.parameters;
var _ref2 = parameters && parameters.options || {},
showRoots = _ref2.showRoots,
_ref2$hierarchyRootSe = _ref2.hierarchyRootSeparator,
rootSeparator = _ref2$hierarchyRootSe === void 0 ? '|' : _ref2$hierarchyRootSe,
_ref2$hierarchySepara = _ref2.hierarchySeparator,
groupSeparator = _ref2$hierarchySepara === void 0 ? /\/|\./ : _ref2$hierarchySepara;
var groups;
if (typeof showRoots !== 'undefined') {
groups = selectedKind.split('/');
} else {
// This covers off all the remaining cases:
// - If the separators were set above, we should use them
// - If they weren't set, we should only should use the old defaults if the kind contains '.' or '|',
// which for this particular splitting is the only case in which it actually matters.
var _parseKind = (0, _csf.parseKind)(selectedKind, {
rootSeparator: rootSeparator,
groupSeparator: groupSeparator
});
groups = _parseKind.groups;
}
return groups && groups[groups.length - 1] || selectedKind;
};
exports.defaultTitleSlot = defaultTitleSlot;
var Title = function Title(_ref3) {
var slot = _ref3.slot,
children = _ref3.children;
var context = (0, _react.useContext)(_DocsContext.DocsContext);
var selectedKind = context.selectedKind,
parameters = context.parameters;
var text = children;
if (!text) {
if (slot) {
text = slot(context);
} else {
text = defaultTitleSlot({
selectedKind: selectedKind,
parameters: parameters
});
}
}
return text ? _react["default"].createElement(_components.Title, {
className: "sbdocs-title"
}, text) : null;
};
exports.Title = Title;