diff --git a/scripts/babel/react-docgen-typescript.js b/scripts/babel/react-docgen-typescript.js index a04fdebce4e..7b72ce70512 100644 --- a/scripts/babel/react-docgen-typescript.js +++ b/scripts/babel/react-docgen-typescript.js @@ -103,7 +103,7 @@ module.exports = function({ types }) { if (docgenResults.length !== 0) { docgenResults.forEach(function(docgenResult) { const exportName = docgenResult.displayName; - docgenResult.extends = componentExtends; + docgenResult.extendedInterfaces = componentExtends; path.node.body.push( template.default.ast(` try{ @@ -247,11 +247,8 @@ function filterProp( if (prop.parent) { //Check if props are extended from other node module if (whiteListedParent.includes(prop.parent.name)) return true; - if ( - prop.parent.name === 'DOMAttributes' && - !componentExtends.includes('DOMAttributes') - ) { - componentExtends.push('DOMAttributes'); + if (!componentExtends.includes(prop.parent.name)) { + componentExtends.push(prop.parent.name); } if (prop.name.includes(whiteListedProps)) { return true; diff --git a/src-docs/src/components/guide_section/guide_section.js b/src-docs/src/components/guide_section/guide_section.js index dfe86d289e1..9592b7a07d3 100644 --- a/src-docs/src/components/guide_section/guide_section.js +++ b/src-docs/src/components/guide_section/guide_section.js @@ -19,12 +19,16 @@ import { EuiTitle, EuiLink, EuiButtonEmpty, + EuiFlexGroup, + EuiFlexItem, } from '../../../../src/components'; import { CodeSandboxLink } from '../codesandbox'; import { cleanEuiImports } from '../../services'; +import { extendedTypesInfo } from './guide_section_extends'; + export const markup = text => { const regex = /(#[a-zA-Z]+)|(`[^`]+`)/g; return text.split('\n').map(token => { @@ -54,7 +58,7 @@ export const markup = text => { } return token; }); - return [...values, ]; + return [...values, ]; }); }; @@ -289,7 +293,7 @@ export class GuideSection extends Component { const docgenInfo = Array.isArray(component.__docgenInfo) ? component.__docgenInfo[0] : component.__docgenInfo; - const { description, props } = docgenInfo; + const { description, props, extendedInterfaces } = docgenInfo; if (!props && !description) { return; @@ -360,7 +364,22 @@ export class GuideSection extends Component { return {cells}; }); - const title = {componentName}; + const extendedTypes = extendedInterfaces + ? extendedInterfaces.filter(type => !!extendedTypesInfo[type]) + : []; + // if there is an HTMLAttributes type present among others, remove HTMLAttributes + if (extendedTypes.includes('HTMLAttributes') && extendedTypes.length > 1) { + const htmlAttributesIndex = extendedTypes.indexOf('HTMLAttributes'); + extendedTypes.splice(htmlAttributesIndex, 1); + } + const extendedTypesElements = extendedTypes.map((type, index) => ( + + + {extendedTypesInfo[type].name} + + {index + 1 < extendedTypes.length && ', '} + + )); let descriptionElement; @@ -405,9 +424,23 @@ export class GuideSection extends Component { return [ , - - {title} - , + + + + {componentName} + + + {extendedTypesElements.length > 0 && ( + + + [ extends {extendedTypesElements} ] + + + )} + , , descriptionElement, table, diff --git a/src-docs/src/components/guide_section/guide_section_extends.js b/src-docs/src/components/guide_section/guide_section_extends.js new file mode 100644 index 00000000000..694b95a98c7 --- /dev/null +++ b/src-docs/src/components/guide_section/guide_section_extends.js @@ -0,0 +1,27 @@ +export const extendedTypesInfo = { + // HTMLAttributes is removed from display if any of the following elements also exist + HTMLAttributes: { + name: 'HTMLElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement', + }, + SelectHTMLAttributes: { + name: 'HTMLSelectElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement', + }, + TextareaHTMLAttributes: { + name: 'HTMLTextAreaElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement', + }, + InputHTMLAttributes: { + name: 'HTMLInputElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement', + }, + AnchorHTMLAttributes: { + name: 'HTMLAnchorElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement', + }, + ButtonHTMLAttributes: { + name: 'HTMLButtonElement', + url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement', + }, +};
[ extends {extendedTypesElements} ]