-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
jsondoc.js
50 lines (44 loc) · 1.3 KB
/
jsondoc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* eslint-disable no-underscore-dangle */
import { global } from '@storybook/global';
export const setJSONDoc = (jsondoc) => {
global.__EMBER_GENERATED_DOC_JSON__ = jsondoc;
};
export const getJSONDoc = () => {
return global.__EMBER_GENERATED_DOC_JSON__;
};
export const extractArgTypes = (componentName) => {
const json = getJSONDoc();
if (!(json && json.included)) {
return null;
}
const componentDoc = json.included.find((doc) => doc.attributes.name === componentName);
if (!componentDoc) {
return null;
}
return componentDoc.attributes.arguments.reduce((acc, prop) => {
acc[prop.name] = {
name: prop.name,
defaultValue: prop.defaultValue,
description: prop.description,
table: {
defaultValue: { summary: prop.defaultValue },
type: {
summary: prop.type,
required: prop.tags.length ? prop.tags.some((tag) => tag.name === 'required') : false,
},
},
};
return acc;
}, {});
};
export const extractComponentDescription = (componentName) => {
const json = getJSONDoc();
if (!(json && json.included)) {
return null;
}
const componentDoc = json.included.find((doc) => doc.attributes.name === componentName);
if (!componentDoc) {
return null;
}
return componentDoc.attributes.description;
};