|
| 1 | +import { action } from '@storybook/addon-actions'; |
| 2 | +import { Meta, Preview, Story } from '@storybook/addon-docs/blocks'; |
| 3 | +import "./style-overrides.css"; |
| 4 | + |
| 5 | +import { Inspector, getMaximumFieldValueFromSchemaGroup } from "../src/index"; |
| 6 | + |
| 7 | +import metaSchema from "./schema-meta.json"; |
| 8 | +import hyperMetaSchema from "./schema-hyper-meta.json"; |
| 9 | +import linksMetaSchema from "./schema-links-meta.json"; |
| 10 | + |
| 11 | +<Meta title='MDX|Inspector' component={Inspector} /> |
| 12 | + |
| 13 | +# Inspector |
| 14 | + |
| 15 | +<Preview> |
| 16 | + <Story name="show-case"> |
| 17 | + <Inspector |
| 18 | + schemas={{ |
| 19 | + "Meta Core JSON Schema": { $ref: "http://json-schema.org/draft-07/schema#" }, |
| 20 | + "Meta Hyper JSON Schema": { $ref: "http://json-schema.org/draft-07/hyper-schema#" }, |
| 21 | + "Meta Links JSON Schema": { $ref: "http://json-schema.org/draft-07/links#" } |
| 22 | + }} |
| 23 | + referenceSchemas={[metaSchema, hyperMetaSchema, linksMetaSchema]} |
| 24 | + searchOptions={{ |
| 25 | + fields: ["title", "description"], |
| 26 | + byPropertyName: true |
| 27 | + }} |
| 28 | + buildArrayProperties={(arrayItemSchema, arraySchemaGroup, optionIndexes) => ({ |
| 29 | + "[0]": arrayItemSchema, |
| 30 | + length: { |
| 31 | + title: "Number of Items", |
| 32 | + type: "number", |
| 33 | + minimum: getMaximumFieldValueFromSchemaGroup(arraySchemaGroup, "minItems", 0, optionIndexes) |
| 34 | + } |
| 35 | + })} |
| 36 | + renderEmptyDetails={({ rootColumnSchemas }) => ( |
| 37 | + <div style={{ padding: "0.5em 1em 0" }}> |
| 38 | + <h3>JSON Schema Inspector</h3> |
| 39 | + <p> |
| 40 | + {`Just click on one of the ${Object.keys(rootColumnSchemas).length} schema titles |
| 41 | + on the left side in order to traverse their nested properties |
| 42 | + – but don't get lost in the circular references.`} |
| 43 | + </p> |
| 44 | + <img |
| 45 | + src="https://raw.githubusercontent.com/CarstenWickner/react-jsonschema-inspector/master/logo.svg?sanitize=true" |
| 46 | + alt="JSON Schema Inspector Logo" |
| 47 | + style={{ width: "70%", margin: "0 15%" }} |
| 48 | + /> |
| 49 | + </div> |
| 50 | + )} |
| 51 | + onSelect={action("onSelect")} |
| 52 | + /> |
| 53 | + </Story> |
| 54 | +</Preview> |
0 commit comments