diff --git a/src/components/render-plugin-doc/render-plugin-doc.tsx b/src/components/render-plugin-doc/render-plugin-doc.tsx index 9b069c91f2..8dd45ae434 100644 --- a/src/components/render-plugin-doc/render-plugin-doc.tsx +++ b/src/components/render-plugin-doc/render-plugin-doc.tsx @@ -1,5 +1,6 @@ +import { Trans, t } from '@lingui/macro'; import { dom, parse } from 'antsibull-docs'; -import React from 'react'; +import React, { ReactNode } from 'react'; import { PluginContentType, PluginDoc, @@ -31,6 +32,18 @@ interface IProps { renderWarning: (text: string) => React.ReactElement; } +function Choice({ children }: { children: ReactNode }) { + return
{children}
; +} + +function Legend({ children }: { children: ReactNode }) { + return ( +
+ {children} +
+ ); +} + export class RenderPluginDoc extends React.Component { subOptionsMaxDepth: number; returnContainMaxDepth: number; @@ -644,47 +657,86 @@ export class RenderPluginDoc extends React.Component { ); } + private renderLegend(legend) { + if (!legend) { + return null; + } + + if (!Array.isArray(legend)) { + legend = [legend]; + } + + return ( + <> + {': '} + + {legend.map((d, i) => ( + <> + {i ?
: null} + {this.applyDocFormatters(d)} + + ))} +
+ + ); + } + private renderChoices(option) { - let choices, defaul; + let choices, + defaultChoice, + legends = {}; if (option['type'] === 'bool') { choices = ['true', 'false']; + if (option['default'] === true) { - defaul = 'true'; + defaultChoice = 'true'; } else if (option['default'] === false) { - defaul = 'false'; + defaultChoice = 'false'; } } else { choices = option['choices'] || []; - defaul = option['default']; + defaultChoice = option['default']; + } + + if (typeof choices === 'object' && !Array.isArray(choices)) { + legends = choices; + choices = Object.keys(choices); } return ( - + <> {choices && Array.isArray(choices) && choices.length !== 0 ? (
- Choices: + + Choices: +
    {choices.map((c, i) => (
  • - {c === defaul ? ( - {c}  ← + {c === defaultChoice ? ( + + {c}  ← + ) : ( - c + {c} )} + {this.renderLegend(legends[c])}
  • ))}
) : null} - {defaul && !choices.includes(defaul) ? ( + {defaultChoice !== undefined && !choices.includes(defaultChoice) ? ( - Default: - {defaul} + + Default: + + {defaultChoice} ) : null} -
+ ); } diff --git a/src/containers/collection-detail/collection-docs.tsx b/src/containers/collection-detail/collection-docs.tsx index 39f7c96333..2f1f6116c5 100644 --- a/src/containers/collection-detail/collection-docs.tsx +++ b/src/containers/collection-detail/collection-docs.tsx @@ -155,7 +155,7 @@ class CollectionDocs extends React.Component { />
{displayHTML || pluginData ? (