Small expander meta formatting (#3713)
* Small expander meta formatting * Updates
This commit is contained in:
parent
32db999a90
commit
88c511d536
@ -29,6 +29,16 @@ export interface Props {
|
||||
withHidden?: boolean;
|
||||
}
|
||||
|
||||
function splitSingle (value: string[], sep: string): string[] {
|
||||
return value.reduce((result: string[], value: string): string[] => {
|
||||
return value.split(sep).reduce((result: string[], value: string) => result.concat(value), result);
|
||||
}, []);
|
||||
}
|
||||
|
||||
function splitParts (value: string): string[] {
|
||||
return ['[', ']'].reduce((result: string[], sep) => splitSingle(result, sep), [value]);
|
||||
}
|
||||
|
||||
function formatMeta (meta?: Meta): React.ReactNode | null {
|
||||
if (!meta || !meta.documentation.length) {
|
||||
return null;
|
||||
@ -36,12 +46,13 @@ function formatMeta (meta?: Meta): React.ReactNode | null {
|
||||
|
||||
const strings = meta.documentation.map((doc) => doc.toString().trim());
|
||||
const firstEmpty = strings.findIndex((doc) => !doc.length);
|
||||
|
||||
return (
|
||||
const parts = splitParts((
|
||||
firstEmpty === -1
|
||||
? strings
|
||||
: strings.slice(0, firstEmpty)
|
||||
).join(' ');
|
||||
).join(' ').replace(/\\/g, '').replace(/`/g, ''));
|
||||
|
||||
return <>{parts.map((part, index) => index % 2 ? <em key={index}>[{part}]</em> : <span key={index}>{part}</span>)} </>;
|
||||
}
|
||||
|
||||
function Expander ({ children, className = '', help, helpIcon, isOpen, isPadded, summary, summaryHead, summaryMeta, summarySub, withHidden }: Props): React.ReactElement<Props> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user