fix: update EnumValues component (#1324)

This commit is contained in:
Oleksiy Kachynskyy 2020-07-24 10:15:36 +03:00 committed by GitHub
parent 676faa943a
commit de27ac0308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -26,7 +26,7 @@ const specUrl =
(userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml'); (userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml');
let store; let store;
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 2 }; const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3 };
async function init() { async function init() {
const spec = await loadAndBundleSpec(specUrl); const spec = await loadAndBundleSpec(specUrl);

View File

@ -42,6 +42,16 @@ export class EnumValues extends React.PureComponent<EnumValuesProps, EnumValuesS
? values.slice(0, maxDisplayedEnumValues) ? values.slice(0, maxDisplayedEnumValues)
: values; : values;
const showToggleButton = maxDisplayedEnumValues
? values.length > maxDisplayedEnumValues
: false;
const toggleButtonText = maxDisplayedEnumValues
? collapsed
? `${values.length - maxDisplayedEnumValues} more`
: 'Hide'
: '';
return ( return (
<div> <div>
<FieldLabel> <FieldLabel>
@ -56,13 +66,13 @@ export class EnumValues extends React.PureComponent<EnumValuesProps, EnumValuesS
</React.Fragment> </React.Fragment>
); );
})} })}
{maxDisplayedEnumValues ? ( {showToggleButton ? (
<ToggleButton <ToggleButton
onClick={() => { onClick={() => {
this.toggle(); this.toggle();
}} }}
> >
{collapsed ? `${values.length - maxDisplayedEnumValues} more` : 'Hide'} {toggleButtonText}
</ToggleButton> </ToggleButton>
) : null} ) : null}
</div> </div>