-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
PropTable
component to EUI docusaurus theme (#7932)
- Loading branch information
Showing
10 changed files
with
832 additions
and
30 deletions.
There are no files selected for viewing
599 changes: 599 additions & 0 deletions
599
.yarn/patches/infima-npm-0.2.0-alpha.43-8d3b77b44d.patch
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ | |
"react-focus-lock": "2.9.5", | ||
"@babel/core": "^7.21.8", | ||
"jsdom": "24.1.0", | ||
"@types/jsdom@npm:^20.0.0": "patch:@types/jsdom@npm%3A20.0.1#~/.yarn/patches/@types-jsdom-npm-20.0.1-5bb899e006.patch" | ||
"@types/jsdom@npm:^20.0.0": "patch:@types/jsdom@npm%3A20.0.1#~/.yarn/patches/@types-jsdom-npm-20.0.1-5bb899e006.patch", | ||
"infima@npm:0.2.0-alpha.43": "patch:infima@npm%3A0.2.0-alpha.43#~/.yarn/patches/infima-npm-0.2.0-alpha.43-8d3b77b44d.patch" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/docusaurus-theme/src/components/prop_table/extended_types.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Fragment, useMemo } from 'react'; | ||
import { EuiLink, EuiText } from '@elastic/eui'; | ||
import { ProcessedComponent } from '@elastic/eui-docgen'; | ||
import { extendedTypesInfo } from './extended_types_info'; | ||
|
||
export interface PropTableExtendedTypesProps { | ||
definition: ProcessedComponent; | ||
} | ||
|
||
export const PropTableExtendedTypes = ({ definition }: PropTableExtendedTypesProps) => { | ||
const extendedTypes = useMemo(() => { | ||
const types = definition.extends.filter( | ||
(type) => extendedTypesInfo.hasOwnProperty(type.displayName), | ||
); | ||
|
||
if (types.every((type) => type.displayName.indexOf('HTMLAttributes') > -1)) { | ||
const htmlAttributesIndex = types.findIndex((type) => type.displayName === 'HTMLAttributes'); | ||
if (htmlAttributesIndex > -1 && types.length > 1) { | ||
types.splice(htmlAttributesIndex, 1); | ||
} | ||
} | ||
|
||
return types; | ||
}, [definition.extends]); | ||
|
||
if (!extendedTypes.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiText size="s"> | ||
Extends{' '} | ||
{extendedTypes.map((type, index) => ( | ||
<Fragment key={index}> | ||
<EuiLink href={extendedTypesInfo[type.displayName as keyof typeof extendedTypesInfo].url}> | ||
{type.displayName} | ||
</EuiLink> | ||
{extendedTypes.length - 1 > index && ', '} | ||
</Fragment> | ||
))} | ||
</EuiText> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/docusaurus-theme/src/components/prop_table/extended_types_info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters