fix: improve rendering of types

This commit is contained in:
Roman Hotsiy 2017-12-07 19:12:34 +02:00
parent 435cccd72f
commit 17da7b74db
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 13 additions and 7 deletions

View File

@ -18,7 +18,10 @@ export const TypePrefix = styled(FieldLabel)`
`; `;
export const TypeName = styled(FieldLabel)` export const TypeName = styled(FieldLabel)`
color: ${props => transparentizeHex(props.theme.colors.text, 0.4)}; color: ${props => transparentizeHex(props.theme.colors.text, 0.8)};
`;
export const TypeTitle = styled(FieldLabel)`
color: ${props => transparentizeHex(props.theme.colors.text, 0.5)};
`; `;
export const TypeFormat = TypeName; export const TypeFormat = TypeName;
@ -29,7 +32,7 @@ export const RequiredLabel = styled(FieldLabel)`
font-weight: bold; font-weight: bold;
`; `;
export const CircularLabel = styled(FieldLabel)` export const RecursiveLabel = styled(FieldLabel)`
color: #dd9900; color: #dd9900;
font-size: 13px; font-size: 13px;
`; `;

View File

@ -6,12 +6,13 @@ import { EnumValues } from './EnumValues';
import { FieldDetail } from './FieldDetail'; import { FieldDetail } from './FieldDetail';
import { ConstraintsView } from './FieldContstraints'; import { ConstraintsView } from './FieldContstraints';
import { import {
CircularLabel, RecursiveLabel,
NullableLabel, NullableLabel,
PatternLabel, PatternLabel,
RequiredLabel, RequiredLabel,
TypeFormat, TypeFormat,
TypeName, TypeName,
TypeTitle,
TypePrefix, TypePrefix,
} from '../../common-elements/fields'; } from '../../common-elements/fields';
@ -34,11 +35,12 @@ export class FieldDetails extends React.PureComponent<FieldProps> {
{schema.format}> {schema.format}>
</TypeFormat> </TypeFormat>
)} )}
{schema.title && <TypeTitle> ({schema.title}) </TypeTitle>}
<ConstraintsView constraints={schema.constraints} /> <ConstraintsView constraints={schema.constraints} />
{schema.nullable && <NullableLabel> Nullable </NullableLabel>} {schema.nullable && <NullableLabel> Nullable </NullableLabel>}
{schema.pattern && <PatternLabel>{schema.pattern}</PatternLabel>} {schema.pattern && <PatternLabel>{schema.pattern}</PatternLabel>}
{required && <RequiredLabel> Required </RequiredLabel>} {required && <RequiredLabel> Required </RequiredLabel>}
{schema.isCircular && <CircularLabel> Circular </CircularLabel>} {schema.isCircular && <RecursiveLabel> Recursive </RecursiveLabel>}
</div> </div>
{deprecated && ( {deprecated && (
<div> <div>

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { FieldDetails } from '../Fields/FieldDetails'; import { FieldDetails } from '../Fields/FieldDetails';
import { TypeName, CircularLabel } from '../../common-elements/fields'; import { RecursiveLabel, TypeName, TypeTitle } from '../../common-elements/fields';
import { SchemaModel } from '../../services/models'; import { SchemaModel } from '../../services/models';
@ -28,7 +28,8 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
return ( return (
<div> <div>
<TypeName>{schema.displayType}</TypeName> <TypeName>{schema.displayType}</TypeName>
<CircularLabel> Circular </CircularLabel> {schema.title && <TypeTitle> {schema.title} </TypeTitle>}
<RecursiveLabel> Recursive </RecursiveLabel>
</div> </div>
); );
} }

View File

@ -100,7 +100,7 @@ export class SchemaModel {
this.pattern = schema.pattern; this.pattern = schema.pattern;
this.constraints = humanizeConstraints(schema); this.constraints = humanizeConstraints(schema);
this.displayType = this.title === '' ? this.type : `${this.title} (${this.type})`; this.displayType = this.type;
this.isPrimitive = isPrimitiveType(schema); this.isPrimitive = isPrimitiveType(schema);
this.default = schema.default; this.default = schema.default;
this.readOnly = !!schema.readOnly; this.readOnly = !!schema.readOnly;