2023-01-29 16:44:02 +01:00
|
|
|
import React from 'react'
|
2025-04-01 16:15:20 +02:00
|
|
|
import { Highlight } from '@freesewing/react/components/Highlight'
|
2023-01-29 16:44:02 +01:00
|
|
|
import hljs from 'highlight.js/lib/common'
|
|
|
|
|
2025-05-24 12:22:21 +02:00
|
|
|
/**
|
|
|
|
* A component to code-highlight JSON data
|
|
|
|
*
|
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {object} [props.js = undefined] - An optional Javascript Object to highlight
|
|
|
|
* @param {JSX.Element} props.children - The component children, will be rendered if props.js is not set
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2023-01-29 16:44:02 +01:00
|
|
|
export const Json = (props) => {
|
|
|
|
const code = props.js ? JSON.stringify(props.js, null, 2) : props.children
|
|
|
|
|
2025-04-01 16:15:20 +02:00
|
|
|
return (
|
|
|
|
<Highlight language="json" raw={hljs.highlight(code, { language: 'json' }).value} copy={code} />
|
|
|
|
)
|
2023-01-29 16:44:02 +01:00
|
|
|
}
|