Use json-stringify-pretty-compact to give compact pretty JSON in purple code for x- extensions

This commit is contained in:
Stuart McGrigor 2019-08-23 01:37:48 +12:00
parent 500708b6c6
commit 3549819f80
3 changed files with 17 additions and 3 deletions

View File

@ -88,7 +88,14 @@ export const ExampleValue = styled(FieldLabel)`
${extensionsHook('ExampleValue')}; ${extensionsHook('ExampleValue')};
`; `;
export const ExtensionValue = styled(ExampleValue)``;
export const ExtensionValue = styled(ExampleValue)`
white-space: pre;
display: block;
overflow: scroll;
max-height: ${({ theme }) => theme.extension.maxHeight};
${extensionsHook('ExtensionValue')};
`;
export const ConstraintItem = styled(FieldLabel)` export const ConstraintItem = styled(FieldLabel)`
border-radius: 2px; border-radius: 2px;

View File

@ -1,5 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import * as prettyCompactJSON from 'json-stringify-pretty-compact';
import { ExtensionValue, FieldLabel } from '../../common-elements/fields'; import { ExtensionValue, FieldLabel } from '../../common-elements/fields';
import styled from '../../styled-components'; import styled from '../../styled-components';
@ -30,7 +32,7 @@ export class Extensions extends React.PureComponent<ExtensionsProps> {
<Extension key={key}> <Extension key={key}>
<FieldLabel> {key.substring(2)}: </FieldLabel>{' '} <FieldLabel> {key.substring(2)}: </FieldLabel>{' '}
<ExtensionValue> <ExtensionValue>
{typeof exts[key] === 'string' ? exts[key] : JSON.stringify(exts[key])} {typeof exts[key] === 'string' ? exts[key] : prettyCompactJSON(exts[key], {indent: 2})}
</ExtensionValue> </ExtensionValue>
</Extension> </Extension>
))} ))}

View File

@ -150,6 +150,9 @@ const defaultTheme: ThemeInterface = {
codeSample: { codeSample: {
backgroundColor: ({ rightPanel }) => darken(0.1, rightPanel.backgroundColor), backgroundColor: ({ rightPanel }) => darken(0.1, rightPanel.backgroundColor),
}, },
extension: {
maxHeight: '16em'
}
}; };
export default defaultTheme; export default defaultTheme;
@ -320,7 +323,9 @@ export interface ResolvedThemeInterface {
codeSample: { codeSample: {
backgroundColor: string; backgroundColor: string;
}; };
extension: {
maxHeight: string;
}
extensionsHook?: (name: string, props: any) => string; extensionsHook?: (name: string, props: any) => string;
} }