-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-schema-2020-12): add support for vocabulary keyword
Refs #8513
- Loading branch information
Showing
9 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/$vocabulary.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React, { useCallback, useState } from "react" | ||
import classNames from "classnames" | ||
|
||
import { schema } from "../../../prop-types" | ||
import { useComponent, useIsExpandedDeeply } from "../../../hooks" | ||
|
||
const $vocabulary = ({ schema }) => { | ||
if (!schema?.$vocabulary) return null | ||
if (typeof schema.$vocabulary !== "object") return null | ||
|
||
const isExpandedDeeply = useIsExpandedDeeply() | ||
const [expanded, setExpanded] = useState(isExpandedDeeply) | ||
const Accordion = useComponent("Accordion") | ||
|
||
const handleExpansion = useCallback(() => { | ||
setExpanded((prev) => !prev) | ||
}, []) | ||
|
||
return ( | ||
<div className="json-schema-2020-12__$vocabulary"> | ||
<Accordion expanded={expanded} onChange={handleExpansion}> | ||
<span className="json-schema-2020-12-core-keyword">$vocabulary</span> | ||
</Accordion> | ||
<ul> | ||
{expanded && | ||
Object.entries(schema.$vocabulary).map(([uri, enabled]) => ( | ||
<li | ||
key={uri} | ||
className={classNames("json-schema-2020-12__$vocabulary-uri", { | ||
"json-schema-2020-12__$vocabulary-uri--disabled": !enabled, | ||
})} | ||
> | ||
<span className="json-schema-2020-12-core-keyword__value"> | ||
{uri} | ||
</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} | ||
|
||
$vocabulary.propTypes = { | ||
schema: schema.isRequired, | ||
} | ||
|
||
export default $vocabulary |
14 changes: 14 additions & 0 deletions
14
src/core/plugins/json-schema-2020-12/components/keywords/$vocabulary/_$vocabulary.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.json-schema-2020-12 { | ||
&__\$vocabulary { | ||
ul { | ||
margin: 0 0 0 20px; | ||
border-left: 1px dashed rgba($section-models-model-container-background-color, 0.1); | ||
} | ||
} | ||
|
||
&__\$vocabulary-uri { | ||
&--disabled { | ||
text-decoration: line-through; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,8 @@ | |
color: #6b6b6b; | ||
font-size: 12px; | ||
margin-left: 20px; | ||
|
||
& p { | ||
margin: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters