/** * @prettier */ import React, { useCallback, useState } from "react" import PropTypes from "prop-types" import classNames from "classnames" const Xml = ({ schema, getSystem }) => { const xml = schema?.xml || {} const { fn, getComponent } = getSystem() const { useIsExpandedDeeply, useComponent } = fn.jsonSchema202012 const isExpandedDeeply = useIsExpandedDeeply() const isExpandable = !!(xml.name || xml.namespace || xml.prefix) const [expanded, setExpanded] = useState(isExpandedDeeply) const [expandedDeeply, setExpandedDeeply] = useState(false) const Accordion = useComponent("Accordion") const ExpandDeepButton = useComponent("ExpandDeepButton") 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(xml).length === 0) { return null } return (
{isExpandable ? ( <> XML ) : ( XML )} {xml.attribute === true && ( attribute )} {xml.wrapped === true && ( wrapped )} object
    {expanded && ( <> {xml.name && (
  • name {xml.name}
  • )} {xml.namespace && (
  • namespace {xml.namespace}
  • )} {xml.prefix && (
  • prefix {xml.prefix}
  • )} )}
) } Xml.propTypes = { schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, getSystem: PropTypes.func.isRequired, } export default Xml