feat(json-schema-2020-12): add support for required keyword (#8628)
Refs #8513
This commit is contained in:
@@ -2,12 +2,14 @@
|
|||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
import React from "react"
|
import React from "react"
|
||||||
|
import classNames from "classnames"
|
||||||
|
|
||||||
import { schema } from "../../../prop-types"
|
import { schema } from "../../../prop-types"
|
||||||
import { useComponent } from "../../../hooks"
|
import { useComponent } from "../../../hooks"
|
||||||
|
|
||||||
const Properties = ({ schema }) => {
|
const Properties = ({ schema }) => {
|
||||||
const properties = schema?.properties || {}
|
const properties = schema?.properties || {}
|
||||||
|
const required = Array.isArray(schema?.required) ? schema.required : []
|
||||||
const JSONSchema = useComponent("JSONSchema")
|
const JSONSchema = useComponent("JSONSchema")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +23,13 @@ const Properties = ({ schema }) => {
|
|||||||
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--properties">
|
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--properties">
|
||||||
<ul>
|
<ul>
|
||||||
{Object.entries(properties).map(([propertyName, schema]) => (
|
{Object.entries(properties).map(([propertyName, schema]) => (
|
||||||
<li key={propertyName} className="json-schema-2020-12-property">
|
<li
|
||||||
|
key={propertyName}
|
||||||
|
className={classNames("json-schema-2020-12-property", {
|
||||||
|
"json-schema-2020-12-property--required":
|
||||||
|
required.includes(propertyName),
|
||||||
|
})}
|
||||||
|
>
|
||||||
<JSONSchema name={propertyName} schema={schema} />
|
<JSONSchema name={propertyName} schema={schema} />
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -9,5 +9,13 @@
|
|||||||
|
|
||||||
&-property {
|
&-property {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
|
|
||||||
|
&--required {
|
||||||
|
.json-schema-2020-12__title:after {
|
||||||
|
content: '*';
|
||||||
|
color: red;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user