Files
swagger-ui/src/core/components/example.jsx
Adrien Becchis b5e8081115 fix(syntax-highlighter): configuration for Examples (#6455)
* Complement #5259, getConfigs was not correctly forwarded to Examples. As a result, syntax highlight could not be disabled be disabled or configured in that elements
2020-10-02 14:44:46 -07:00

44 lines
1.2 KiB
JavaScript

/**
* @prettier
*/
import React from "react"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import { stringify } from "core/utils"
export default function Example(props) {
const { example, showValue, getComponent, getConfigs } = props
const Markdown = getComponent("Markdown", true)
const HighlightCode = getComponent("highlightCode")
if(!example) return null
return (
<div className="example">
{example.get("description") ? (
<section className="example__section">
<div className="example__section-header">Example Description</div>
<p>
<Markdown source={example.get("description")} />
</p>
</section>
) : null}
{showValue && example.has("value") ? (
<section className="example__section">
<div className="example__section-header">Example Value</div>
<HighlightCode getConfigs={ getConfigs } value={stringify(example.get("value"))} />
</section>
) : null}
</div>
)
}
Example.propTypes = {
example: ImPropTypes.map.isRequired,
showValue: PropTypes.bool,
getComponent: PropTypes.func.isRequired,
getConfigs: PropTypes.func.getConfigs,
}