Skip to content

Commit

Permalink
feat: constant modifier in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
jy95 committed Jan 8, 2024
1 parent 3d21631 commit 47e0ad9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ exports[`JSONSchemaViewer - constructor Overwrite default ValueComponent value 1
>
object
</span>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,10 @@ exports[`JSONSchemaViewer - generateFriendlyName cases test Prefer title 1`] = `
>
string
</span>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ exports[`JSONSchemaViewer - Generic keywords test const 1`] = `
>
string
</span>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
>
string
</span>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down Expand Up @@ -602,6 +606,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
<strong>
required
</strong>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down Expand Up @@ -865,6 +873,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
<strong>
required
</strong>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down Expand Up @@ -1262,6 +1274,10 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else 1`] = `
>
string
</span>
 
<strong>
constant
</strong>
</summary>
<div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DeprecatedLabel,
WriteOnlyLabel,
ReadOnlyLabel,
ConstantLabel
} from "@theme/JSONSchemaViewer/labels"

import { GenerateFriendlyName } from "@theme/JSONSchemaViewer/utils"
Expand Down Expand Up @@ -43,6 +44,10 @@ export default function SchemaItem({
typeof typedSchema !== "boolean" && typedSchema.readOnly === true
let isWriteOnly =
typeof typedSchema !== "boolean" && typedSchema.writeOnly === true
let isConstant =
typeof typedSchema !== "boolean" &&
(typedSchema.const !== undefined ||
(Array.isArray(typedSchema.enum) && typedSchema.enum.length === 1))
let isRequired = !isDeprecated && required

// Header
Expand All @@ -58,6 +63,8 @@ export default function SchemaItem({
{isReadOnly && <ReadOnlyLabel />}
{isWriteOnly && <>&nbsp;</>}
{isWriteOnly && <WriteOnlyLabel />}
{isConstant && <>&nbsp;</>}
{isConstant && <ConstantLabel />}
</>
)

Expand Down
18 changes: 18 additions & 0 deletions src/theme/JSONSchemaViewer/labels/Constant/Constant.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react"
import Translate from "@docusaurus/Translate"

import styles from "./styles.module.css"

export default function ConstantLabel(): JSX.Element {
return (
<strong className={styles.constant}>
<Translate
values={{
id: "json-schema.keywords.const",
}}
>
{"constant"}
</Translate>
</strong>
)
}
4 changes: 4 additions & 0 deletions src/theme/JSONSchemaViewer/labels/Constant/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.constant {
font-size: var(--ifm-code-font-size);
color: var(--ifm-color-secondary-darkest);
}
1 change: 1 addition & 0 deletions src/theme/JSONSchemaViewer/labels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export { default as AndLabel } from "@theme/JSONSchemaViewer/labels/And"
export { default as OrLabel } from "@theme/JSONSchemaViewer/labels/Or"
export { default as NotLabel } from "@theme/JSONSchemaViewer/labels/Not"
export { default as XorLabel } from "@theme/JSONSchemaViewer/labels/Xor"
export { default as ConstantLabel } from "@theme/JSONSchemaViewer/labels/Constant/Constant"

0 comments on commit 47e0ad9

Please sign in to comment.