/** * @prettier */ import React, { useCallback, useState } from "react" import PropTypes from "prop-types" import classNames from "classnames" import { sanitizeUrl } from "core/utils" const ExternalDocs = ({ schema, getSystem }) => { const externalDocs = schema?.externalDocs || {} const { fn, getComponent } = getSystem() const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012 const isExpandedDeeply = useIsExpandedDeeply() const isExpandable = !!(externalDocs.description || externalDocs.url) const [expanded, setExpanded] = useState(isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") const KeywordDescription = getComponent("JSONSchema202012KeywordDescription") const Link = getComponent("Link") const JSONSchemaDeepExpansionContext = getComponent( "JSONSchema202012DeepExpansionContext" )() /** * Event handlers. */ const handleExpansion = useCallback(() => { setExpanded((prev) => !prev) }, []) const handleExpansionDeep = useCallback((e, expandedDeepNew) => { setExpanded(expandedDeepNew) setExpandedDeeply(expandedDeepNew) }, []) /** * Rendering. */ if (Object.keys(externalDocs).length === 0) { return null } return (
{isExpandable ? ( <> External documentation ) : ( External documentation )} object
    {expanded && ( <> {externalDocs.description && (
  • )} {externalDocs.url && (
  • url {externalDocs.url}
  • )} )}
) } ExternalDocs.propTypes = { schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } export default ExternalDocs