Skip to content

Commit 7a8cf05

Browse files
P0lipMarc MacLeod
authored andcommitted
fix: readme + minor fixes (#7) [SL-271]
* chore: update readme + minor fixes * test: cover show extra btn * feat: export themes
1 parent f8ecd9d commit 7a8cf05

File tree

10 files changed

+102
-10
lines changed

10 files changed

+102
-10
lines changed

.storybook/theme.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const zones = {
3030
types: {
3131
object: '#83c1ff',
3232
array: '#7dff75',
33-
allOff: '#b89826',
33+
allOf: '#b89826',
3434
oneOf: '#b89826',
3535
anyOf: '#b89826',
3636
null: '#ff7f50',
@@ -63,7 +63,7 @@ export const zones = {
6363
types: {
6464
object: '#00f',
6565
array: '#008000',
66-
allOff: '#B8860B',
66+
allOf: '#B8860B',
6767
oneOf: '#B8860B',
6868
anyOf: '#B8860B',
6969
null: '#ff7f50',

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ A JSON Schema viewer React component
99

1010
### Features
1111

12-
- **Awesome**: It is.
13-
- .. more features
12+
- Full JSON Schema Draft 4 support, including `oneOf` and `anyOf` combiner properties
13+
- Renders complicated nested objects to any depth
14+
- Renders validation properties and markdown descriptions
15+
- Theme-able
16+
- Collapsible
1417

1518
### Installation
1619

@@ -23,12 +26,17 @@ yarn add @stoplight/json-schema-viewer
2326

2427
### Usage
2528

26-
```ts
27-
import { Library } from "@stoplight/json-schema-viewer";
29+
```jsx
30+
import { JsonSchemaViewer, ThemeProvider } from "@stoplight/json-schema-viewer";
31+
import { dark } from "@stoplight/json-schema-viewer/themes";
2832

29-
// ...example
33+
<ThemeProvider theme={dark}>
34+
<JsonSchemaViewer schemas={schemas} schema={schema} expanded />
35+
</ThemeProvider>
3036
```
3137

38+
More examples can be find in the [Storybook stories](./src/__stories__/JsonSchemaViewer.tsx).
39+
3240
### Contributing
3341

3442
1. Clone repo.

src/SchemaView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const SchemaView: FunctionComponent<ISchemaView> = props => {
102102
return (
103103
<Box backgroundColor={theme.canvas.bg} color={theme.canvas.fg} {...rest}>
104104
{rowElems}
105-
{showExtra || propOverflowCount > 0 ? (
105+
{showExtra || (limitPropertyCount > 0 && propOverflowCount > 0) ? (
106106
<Button onClick={toggleShowExtra}>
107107
{showExtra ? 'collapse' : `...show ${propOverflowCount} more properties`}
108108
</Button>

src/__tests__/SchemaView.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ describe('SchemaView', () => {
5454
expect(wrapper.children()).toHaveLength(3);
5555
});
5656

57+
test('should hide expand button when limitPropertyCount <= 0', () => {
58+
const wrapper = shallow(<SchemaView emptyText="" schema={schema} schemas={{}} limitPropertyCount={0} />);
59+
60+
expect(wrapper.find(Button)).not.toExist();
61+
});
62+
5763
test('should toggle showExtra on btn click', () => {
5864
const wrapper = shallow(<SchemaView emptyText="" schema={schema} schemas={{}} limitPropertyCount={2} />);
5965

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './JsonSchemaViewer';
2+
export { ThemeProvider } from './theme';

src/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { IJSONSchemaViewerTheme } from './types';
33

44
export type themeZones = 'json-schema-viewer';
55

6-
export const { useTheme, ThemeZone } = createThemedModule<themeZones, IJSONSchemaViewerTheme>();
6+
export const { useTheme, ThemeZone, ThemeProvider } = createThemedModule<themeZones, IJSONSchemaViewerTheme>();

src/themes/dark.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { IJSONSchemaViewerTheme } from '../types';
2+
3+
export const dark: IJSONSchemaViewerTheme = {
4+
base: 'dark',
5+
6+
canvas: {
7+
bg: '#111',
8+
fg: '#fff',
9+
error: 'red',
10+
muted: 'rgba(255, 255, 255, 0.6)',
11+
},
12+
13+
divider: {
14+
bg: '#bababa',
15+
},
16+
17+
row: {
18+
hoverBg: '#333',
19+
hoverFg: '#fff',
20+
evenBg: '#232222',
21+
},
22+
23+
types: {
24+
object: '#83c1ff',
25+
array: '#7dff75',
26+
allOf: '#b89826',
27+
oneOf: '#b89826',
28+
anyOf: '#b89826',
29+
null: '#ff7f50',
30+
integer: '#e03b36',
31+
number: '#e03b36',
32+
boolean: '#ff69b4',
33+
binary: '#8ccda3',
34+
string: '#19c5a0',
35+
$ref: '#a359e2',
36+
},
37+
};

src/themes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './dark';
2+
export * from './light';

src/themes/light.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { IJSONSchemaViewerTheme } from '../types';
2+
3+
export const light: IJSONSchemaViewerTheme = {
4+
base: 'light',
5+
6+
canvas: {
7+
bg: '#fff',
8+
fg: '#111',
9+
error: 'red',
10+
muted: 'rgba(0, 0, 0, 0.5)',
11+
},
12+
13+
divider: {
14+
bg: '#dae1e7',
15+
},
16+
17+
row: {
18+
hoverBg: '#e9e9e9',
19+
hoverFg: '#111',
20+
evenBg: '#f3f3f3',
21+
},
22+
23+
types: {
24+
object: '#00f',
25+
array: '#008000',
26+
allOf: '#B8860B',
27+
oneOf: '#B8860B',
28+
anyOf: '#B8860B',
29+
null: '#ff7f50',
30+
integer: '#a52a2a',
31+
number: '#a52a2a',
32+
boolean: '#ff69b4',
33+
binary: '#66cdaa',
34+
string: '#008080',
35+
$ref: '#8a2be2',
36+
},
37+
};

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export interface IJSONSchemaViewerTheme extends ICustomTheme {
4444
integer: string;
4545
number: string;
4646
boolean: string;
47-
binary: boolean;
47+
binary: string;
48+
string: string;
4849
$ref: string;
4950
};
5051

0 commit comments

Comments
 (0)