1
0
Fork 0

[react] feat: Added docs for components/Yaml

This commit is contained in:
joostdecock 2025-05-29 14:19:57 +02:00
parent 0a345b3347
commit 54fe6275af
4 changed files with 52 additions and 4 deletions

View file

@ -3,6 +3,18 @@ import { Highlight } from '@freesewing/react/components/Highlight'
import hljs from 'highlight.js/lib/common'
import yaml from 'js-yaml'
/**
* A component to code-highlight YAML data
*
* @component
* @param {object} props - All component props
* @param {JSX.Element} props.children - Use this if you are not using props.json or props.js to pass the YAML data
* @param {object} [props.js = undefined] - Use this to pass the YAML data as Javascript Object
* @param {string} [props.json = undefined] - Use this to pass the YAML data as JSON
* @param {bool} [props.noCopy = false] - Set this to true to not add the copy to clipboard button
* @param {string} [props.title = "YAML"] - Title for the highlight
* @returns {JSX.Element}
*/
export const Yaml = (props) => {
let code
if (props.json) code = yaml.dump(JSON.parse(props.json))
@ -11,8 +23,8 @@ export const Yaml = (props) => {
return (
<Highlight
{...props}
language="yaml"
{...props}
raw={hljs.highlight(code, { language: 'yaml' }).value}
copy={code}
/>

View file

@ -42,3 +42,4 @@ jsdoc -c jsdoc.json components/Time/* > ../../sites/dev/prebuild/jsdoc/react/com
jsdoc -c jsdoc.json components/Uuid/* > ../../sites/dev/prebuild/jsdoc/react/components/uuid.json
jsdoc -c jsdoc.json components/Ux/* > ../../sites/dev/prebuild/jsdoc/react/components/ux.json
jsdoc -c jsdoc.json components/Xray/* > ../../sites/dev/prebuild/jsdoc/react/components/xray.json
jsdoc -c jsdoc.json components/Yaml/* > ../../sites/dev/prebuild/jsdoc/react/components/yaml.json

View file

@ -0,0 +1,18 @@
import React from 'react'
import { Yaml } from '@freesewing/react/components/Yaml'
export const YamlExample = () => <Yaml js={{
some: 'yaml',
data: 'here',
more: {
things: {
like: ['an', 'array'],
or: {
a: {
number: 12
}
}
}
}
}} />

View file

@ -2,6 +2,23 @@
title: Yaml
---
:::note
This page is yet to be created
:::
import { DocusaurusDoc } from '@freesewing/react/components/Docusaurus'
import { ComponentDocs } from '@site/src/components/component-docs.js'
import * as jsdoc from '@site/prebuild/jsdoc/components.yaml.mjs'
import { YamlExample } from './_examples.js'
<DocusaurusDoc>
- [Components](#components)
## Components
The **Yaml** component family provides the following components:
- [Yaml](#yaml)
### Yaml
<ComponentDocs docs={jsdoc.jsdocYaml} example={YamlExample} />
</DocusaurusDoc>