Skip to content

Commit

Permalink
fix: update EnumValues component (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy Kachynskyy authored Jul 24, 2020
1 parent 676faa9 commit de27ac0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demo/playground/hmr-playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const specUrl =
(userUrl && userUrl[1]) || (swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml');

let store;
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 2 };
const options: RedocRawOptions = { nativeScrollbars: false, maxDisplayedEnumValues: 3 };

async function init() {
const spec = await loadAndBundleSpec(specUrl);
Expand Down
14 changes: 12 additions & 2 deletions src/components/Fields/EnumValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export class EnumValues extends React.PureComponent<EnumValuesProps, EnumValuesS
? values.slice(0, maxDisplayedEnumValues)
: values;

const showToggleButton = maxDisplayedEnumValues
? values.length > maxDisplayedEnumValues
: false;

const toggleButtonText = maxDisplayedEnumValues
? collapsed
? `… ${values.length - maxDisplayedEnumValues} more`
: 'Hide'
: '';

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

0 comments on commit de27ac0

Please sign in to comment.