add ember support for docs-mode

This commit is contained in:
Matthew Irish 2019-12-04 21:14:35 -06:00
parent ab16256732
commit b54a15b934
4 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { addParameters } from '@storybook/client-api';
import { extractProps, extractComponentDescription } from './jsondoc';
addParameters({
docs: {
extractProps,
extractComponentDescription,
},
});

View File

@ -0,0 +1,27 @@
/* eslint-disable no-underscore-dangle */
/* global window */
function getJSONDoc() {
return window.__EMBER_GENERATED_DOC_JSON__;
}
export const extractProps = componentName => {
const json = getJSONDoc();
const componentDoc = json.included.find(doc => doc.attributes.name === componentName);
const rows = componentDoc.attributes.arguments.map(prop => {
return {
name: prop.name,
type: prop.type,
required: prop.tags.length ? prop.tags.some(tag => tag.name === 'required') : false,
defaultValue: prop.defaultValue,
description: prop.description,
};
});
return { rows };
};
export const extractComponentDescription = componentName => {
const json = getJSONDoc();
const componentDoc = json.included.find(doc => doc.attributes.name === componentName);
return componentDoc.attributes.description;
};

View File

@ -9,6 +9,8 @@ export {
raw,
} from './preview';
export { setJSONDoc } from './jsondoc';
if (module && module.hot && module.hot.decline) {
module.hot.decline();
}

View File

@ -0,0 +1,6 @@
/* eslint-disable no-underscore-dangle */
/* global window */
export function setJSONDoc(jsondoc) {
window.__EMBER_GENERATED_DOC_JSON__ = jsondoc;
}