Skip to content

Commit b72edf5

Browse files
committed
style: fix types
1 parent 3304c77 commit b72edf5

File tree

5 files changed

+138
-16
lines changed

5 files changed

+138
-16
lines changed

.storybook/theme.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ export const zones = {
2323
row: {
2424
hoverBg: '#999',
2525
hoverFg: '#222',
26-
evenBg: '#333',
26+
evenBg: '#232222',
27+
},
28+
29+
types: {
30+
object: '#00f',
31+
array: '#008000',
32+
allOff: '#B8860B',
33+
oneOf: '#B8860B',
34+
anyOf: '#B8860B',
35+
null: '#ff7f50',
36+
integer: '#a52a2a',
37+
number: '#a52a2a',
38+
boolean: '#ff69b4',
39+
binary: '#66cdaa',
40+
string: '#008080',
41+
$ref: '#8a2be2',
2742
}
2843
} : {
2944
canvas: {
@@ -42,5 +57,21 @@ export const zones = {
4257
hoverFg: '#111',
4358
evenBg: '#e4e4e4',
4459
},
60+
61+
62+
types: {
63+
object: '#00f',
64+
array: '#008000',
65+
allOff: '#B8860B',
66+
oneOf: '#B8860B',
67+
anyOf: '#B8860B',
68+
null: '#ff7f50',
69+
integer: '#a52a2a',
70+
number: '#a52a2a',
71+
boolean: '#ff69b4',
72+
binary: '#66cdaa',
73+
string: '#008080',
74+
$ref: '#8a2be2',
75+
},
4576
},
4677
};
Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,60 @@
11
{
2+
"title": "User",
3+
"type": "object",
24
"properties": {
3-
"data": {
5+
"name": {
6+
"type": "string",
7+
"description": "The user's full name."
8+
},
9+
"age": {
10+
"type": "number",
11+
"minimum": 0,
12+
"maximum": 150
13+
},
14+
"completed_at": {},
15+
"items": {
16+
"type": [
17+
"string",
18+
"array"
19+
],
420
"items": {
5-
"$ref": "#/definitions/Gif"
6-
},
7-
"type": "array"
21+
"type": "string"
22+
}
823
},
9-
"meta": {
10-
"$ref": "#/definitions/Meta"
24+
"email": {
25+
"type": "string",
26+
"format": "email",
27+
"minLength": 2
1128
},
12-
"pagination": {
13-
"$ref": "#/definitions/Pagination"
29+
"plan": {
30+
"anyOf": [
31+
{
32+
"type": "object",
33+
"properties": {
34+
"foo": {
35+
"type": "string"
36+
},
37+
"bar": {
38+
"type": "string"
39+
}
40+
},
41+
"required": [
42+
"foo",
43+
"bar"
44+
]
45+
},
46+
{
47+
"type": "array",
48+
"items": {
49+
"type": "integer"
50+
}
51+
}
52+
]
1453
}
15-
}
54+
},
55+
"required": [
56+
"name",
57+
"age",
58+
"completed_at"
59+
]
1660
}

src/common/RowType.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* @jsx jsx */
2+
3+
import { jsx } from '@emotion/core';
4+
import { Box, IBox } from '@stoplight/ui-kit';
5+
import { FunctionComponent } from 'react';
6+
import { useTheme } from '../theme';
7+
8+
export const RowType: FunctionComponent<IRowType> = props => {
9+
const { children, type, ...rest } = props;
10+
const css = rowStyles({ type });
11+
12+
return (
13+
<Box css={css} {...rest}>
14+
{children}
15+
</Box>
16+
);
17+
};
18+
19+
export interface IRowTypeProps {
20+
type?: string;
21+
}
22+
23+
export interface IRowType extends IRowTypeProps, IBox {}
24+
25+
export const rowStyles = ({ type }: IRowTypeProps) => {
26+
const theme = useTheme();
27+
28+
return {
29+
...(type !== undefined && type in theme.types && { color: theme.types[type] }),
30+
};
31+
};

src/renderers/renderProp.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @jsx jsx */
22
import { jsx } from '@emotion/core';
3-
import { Box, Flex, Icon, IconLibrary, Textarea } from '@stoplight/ui-kit';
3+
import { Box, Flex, Icon, IconLibrary } from '@stoplight/ui-kit';
44
import has = require('lodash/has');
55
import isEmpty = require('lodash/isEmpty');
66
import isString = require('lodash/isString');
@@ -11,6 +11,7 @@ import { faCaretRight } from '@fortawesome/free-solid-svg-icons/faCaretRight';
1111
import { ErrorMessage } from '../common/ErrorMessage';
1212
import { MutedText } from '../common/MutedText';
1313
import { Row } from '../common/Row';
14+
import { RowType } from '../common/RowType';
1415
import { PropValidations } from '../PropValidations';
1516
import { useTheme } from '../theme';
1617
import { ICommonProps } from '../types';
@@ -116,9 +117,9 @@ export const renderProp = ({
116117
if (!isEmpty(types)) {
117118
typeElems = types.reduce((acc: ReactNode[], type: string, i) => {
118119
acc.push(
119-
<span key={i}>
120+
<RowType as="span" type={type} key={i}>
120121
{type === 'array' && childPropType && childPropType !== 'array' ? `array[${childPropType}]` : type}
121-
</span>
122+
</RowType>
122123
);
123124

124125
if (types[i + 1]) {
@@ -132,7 +133,7 @@ export const renderProp = ({
132133
return acc;
133134
}, []);
134135
} else if (prop.$ref) {
135-
typeElems.push(<span key="prop-ref">{`{${prop.$ref}}`}</span>);
136+
typeElems.push(<RowType as="span" type="$ref" key="prop-ref">{`{${prop.$ref}}`}</RowType>);
136137
} else if (prop.__error || isBasic) {
137138
typeElems.push(
138139
<Box as="span" key="no-types" color={theme.canvas.error}>
@@ -166,6 +167,7 @@ export const renderProp = ({
166167
rowElems.push(
167168
<Row
168169
as={Flex}
170+
alignItems="center"
169171
position="relative"
170172
py={2}
171173
key={position}
@@ -178,7 +180,7 @@ export const renderProp = ({
178180
}}
179181
>
180182
{expandable ? (
181-
<Flex justifyContent="center" mt={1} pl="0.5rem" mr="0.5rem" ml="-1.5rem" width="1rem">
183+
<Flex justifyContent="center" pl="0.5rem" mr="0.5rem" ml="-1.5rem" width="1rem">
182184
<Icon size="1x" icon={expanded ? faCaretDown : faCaretRight} />
183185
</Flex>
184186
) : null}
@@ -190,7 +192,7 @@ export const renderProp = ({
190192
{!isEmpty(typeElems) && <div>{typeElems}</div>}
191193
</Flex>
192194

193-
{!isEmpty(prop.description) ? <MutedText as={Textarea} fontSize=".875rem" value={prop.description} /> : null}
195+
{!isEmpty(prop.description) ? <MutedText fontSize=".875rem">{prop.description}</MutedText> : null}
194196
</Box>
195197

196198
{requiredElem || showInheritedFrom || expanded ? (

src/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ export interface IJSONSchemaViewerTheme extends ICustomTheme {
3434
evenBg: string;
3535
};
3636

37+
types: {
38+
array: string;
39+
object: string;
40+
allOf: string;
41+
oneOf: string;
42+
anyOf: string;
43+
null: string;
44+
integer: string;
45+
number: string;
46+
boolean: string;
47+
binary: boolean;
48+
$ref: string;
49+
};
50+
3751
divider: {
3852
bg: string;
3953
};

0 commit comments

Comments
 (0)