-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from ethdebug/customize-schema-components
Customize schema component rendering
- Loading branch information
Showing
8 changed files
with
377 additions
and
107 deletions.
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
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,19 @@ | ||
import { useContext, createContext } from "react"; | ||
import type { SchemaInfo, SchemaIndex } from "@site/src/schemas"; | ||
|
||
export interface SchemaContextValue { | ||
rootSchemaInfo?: SchemaInfo; | ||
schemaIndex: SchemaIndex; | ||
} | ||
|
||
export type PointerSchemaIds = { | ||
[jsonPointer: string]: string | ||
}; | ||
|
||
export const SchemaContext = createContext<SchemaContextValue>({ | ||
schemaIndex: {}, | ||
}); | ||
|
||
export const useSchemaContext = () => useContext(SchemaContext); | ||
|
||
export const internalIdKey = Symbol("__$internalId"); |
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
44 changes: 44 additions & 0 deletions
44
web/src/theme/JSONSchemaViewer/JSONSchemaElements/SchemaConditional/schemaConditional.tsx
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,44 @@ | ||
import React from "react" | ||
|
||
import Translate from "@docusaurus/Translate" | ||
|
||
import { | ||
IfElseThen, | ||
DependentRequired, | ||
DependentSchemas, | ||
Dependencies, | ||
} from "@theme-original/JSONSchemaViewer/JSONSchemaElements/SchemaConditional" | ||
|
||
import { Collapsible } from "@theme-original/JSONSchemaViewer/components"; | ||
|
||
|
||
type Props = { | ||
schema: any; | ||
} | ||
|
||
// To handle Schema Conditional (if-then-else , dependentRequired , dependentSchemas , dependencies ) | ||
export default function SchemaConditional(props: Props): JSX.Element { | ||
const { schema } = props | ||
|
||
// Checks | ||
const isIfThenElse = schema.if !== undefined | ||
|
||
const isDependentRequired = | ||
schema.dependentRequired !== undefined | ||
const isDependentSchemas = | ||
schema.dependentSchemas !== undefined | ||
const isDependencies = schema.dependencies !== undefined | ||
|
||
return ( | ||
<> | ||
{/* Handles if-then-else case */} | ||
{isIfThenElse && <IfElseThen schema={schema} />} | ||
{/* Handles dependentRequired case */} | ||
{isDependentRequired && <DependentRequired schema={schema} />} | ||
{/* Handles dependentSchemas case */} | ||
{isDependentSchemas && <DependentSchemas schema={schema} />} | ||
{/* Handles dependencies (deprecated) */} | ||
{isDependencies && <Dependencies schema={schema} />} | ||
</> | ||
) | ||
} |
Oops, something went wrong.