committed by
Vladimír Gorej
parent
e517397fd2
commit
fe181ede90
@@ -3,4 +3,5 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgb(175, 174, 174);
|
color: rgb(175, 174, 174);
|
||||||
border: none;
|
border: none;
|
||||||
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as propTypes from "../../prop-types"
|
|||||||
import {
|
import {
|
||||||
useComponent,
|
useComponent,
|
||||||
useLevel,
|
useLevel,
|
||||||
|
useFn,
|
||||||
useIsEmbedded,
|
useIsEmbedded,
|
||||||
useIsExpandedDeeply,
|
useIsExpandedDeeply,
|
||||||
} from "../../hooks"
|
} from "../../hooks"
|
||||||
@@ -18,11 +19,13 @@ import {
|
|||||||
} from "../../context"
|
} from "../../context"
|
||||||
|
|
||||||
const JSONSchema = ({ schema, name }) => {
|
const JSONSchema = ({ schema, name }) => {
|
||||||
|
const fn = useFn()
|
||||||
const isExpandedDeeply = useIsExpandedDeeply()
|
const isExpandedDeeply = useIsExpandedDeeply()
|
||||||
const [expanded, setExpanded] = useState(isExpandedDeeply)
|
const [expanded, setExpanded] = useState(isExpandedDeeply)
|
||||||
const [expandedDeeply, setExpandedDeeply] = useState(false)
|
const [expandedDeeply, setExpandedDeeply] = useState(false)
|
||||||
const [level, nextLevel] = useLevel()
|
const [level, nextLevel] = useLevel()
|
||||||
const isEmbedded = useIsEmbedded()
|
const isEmbedded = useIsEmbedded()
|
||||||
|
const isExpandable = fn.isExpandable(schema)
|
||||||
const Accordion = useComponent("Accordion")
|
const Accordion = useComponent("Accordion")
|
||||||
const KeywordProperties = useComponent("KeywordProperties")
|
const KeywordProperties = useComponent("KeywordProperties")
|
||||||
const KeywordType = useComponent("KeywordType")
|
const KeywordType = useComponent("KeywordType")
|
||||||
@@ -63,6 +66,8 @@ const JSONSchema = ({ schema, name }) => {
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className="json-schema-2020-12-head">
|
<div className="json-schema-2020-12-head">
|
||||||
|
{isExpandable ? (
|
||||||
|
<>
|
||||||
<Accordion expanded={expanded} onChange={handleExpansion}>
|
<Accordion expanded={expanded} onChange={handleExpansion}>
|
||||||
<KeywordTitle title={name} schema={schema} />
|
<KeywordTitle title={name} schema={schema} />
|
||||||
</Accordion>
|
</Accordion>
|
||||||
@@ -70,6 +75,10 @@ const JSONSchema = ({ schema, name }) => {
|
|||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
onClick={handleExpansionDeep}
|
onClick={handleExpansionDeep}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<KeywordTitle title={name} schema={schema} />
|
||||||
|
)}
|
||||||
<KeywordType schema={schema} />
|
<KeywordType schema={schema} />
|
||||||
<KeywordFormat schema={schema} />
|
<KeywordFormat schema={schema} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
|
|
||||||
import { schema } from "../../prop-types"
|
import { schema } from "../../prop-types"
|
||||||
import { useFn, useComponent } from "../../hooks"
|
import { useComponent } from "../../hooks"
|
||||||
|
|
||||||
const Properties = ({ schema }) => {
|
const Properties = ({ schema }) => {
|
||||||
const fn = useFn()
|
|
||||||
const JSONSchema = useComponent("JSONSchema")
|
const JSONSchema = useComponent("JSONSchema")
|
||||||
const properties = schema?.properties || {}
|
const properties = schema?.properties || {}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
.json-schema-2020-12__title {
|
.json-schema-2020-12__title {
|
||||||
@include text_code();
|
@include text_code();
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
vertical-align: bottom;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
.json-schema-2020-12__type {
|
.json-schema-2020-12 {
|
||||||
|
&__type {
|
||||||
@include text_code();
|
@include text_code();
|
||||||
color: $prop-type-font-color;
|
color: $prop-type-font-color;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
text-transform: lowercase;
|
text-transform: lowercase;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-property {
|
||||||
|
.json-schema-2020-12__type {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export const getType = (schema, processedSchemas = new WeakSet()) => {
|
|||||||
schema.exclusiveMaximum ||
|
schema.exclusiveMaximum ||
|
||||||
schema.multipleOf
|
schema.multipleOf
|
||||||
) {
|
) {
|
||||||
return "number|integer"
|
return "number | integer"
|
||||||
} else if (schema.const !== undefined) {
|
} else if (schema.const !== undefined) {
|
||||||
if (schema.const === null) {
|
if (schema.const === null) {
|
||||||
return "null"
|
return "null"
|
||||||
@@ -110,3 +110,7 @@ export const getType = (schema, processedSchemas = new WeakSet()) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const isBooleanJSONSchema = (schema) => typeof schema === "boolean"
|
export const isBooleanJSONSchema = (schema) => typeof schema === "boolean"
|
||||||
|
|
||||||
|
export const isExpandable = (schema) => {
|
||||||
|
return schema?.description || schema?.properties
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ import Accordion from "./components/Accordion/Accordion"
|
|||||||
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
|
import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
|
||||||
import ChevronRightIcon from "./components/icons/ChevronRight"
|
import ChevronRightIcon from "./components/icons/ChevronRight"
|
||||||
import { JSONSchemaContext } from "./context"
|
import { JSONSchemaContext } from "./context"
|
||||||
import { getTitle, isBooleanJSONSchema, upperFirst, getType } from "./fn"
|
import {
|
||||||
|
getTitle,
|
||||||
|
isBooleanJSONSchema,
|
||||||
|
upperFirst,
|
||||||
|
getType,
|
||||||
|
isExpandable,
|
||||||
|
} from "./fn"
|
||||||
|
|
||||||
export const withJSONSchemaContext = (Component, overrides = {}) => {
|
export const withJSONSchemaContext = (Component, overrides = {}) => {
|
||||||
const value = {
|
const value = {
|
||||||
@@ -38,6 +44,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
|
|||||||
getTitle,
|
getTitle,
|
||||||
getType,
|
getType,
|
||||||
isBooleanJSONSchema,
|
isBooleanJSONSchema,
|
||||||
|
isExpandable,
|
||||||
...overrides.fn,
|
...overrides.fn,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user