Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: negative numbers in button text for expanding enum values #1324

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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