INNER CODE UNIT · TypeScript
tag
f5/unovis · packages/mcp/src/codegen/index.ts:257
const tag = (name: string): string => `Vis${name}`
const renderProps = (props: Prop[]): string =>
props.map(p => p.expr.startsWith("'") ? ` ${p.name}=${p.expr.replace(/'/g, '"')}` : ` ${p.name}={${p.expr}}`).join('')
const children = [
...components.map(c => `<${tag(c.type)} data={data}${renderProps(c.props)} />`),
...(xAxis ? [`<${tag('Axis')}${renderProps(xAxis)} />`] : []),
...(yAxis ? [`<${tag('Axis')}${renderProps(yAxis)} />`] : []),
]
const used = [`Vis${containerName(spec)}`, ...components.map(c => tag(c.type)), ...(xAxis || yAxis ? ['VisAxis'] : [])]
const legendTag = spec.legend?.length ? `<VisBulletLegend items={${json(spec.legend.map(i => ({ name: i.name })), 0)}} />\n ` : ''
if (spec.legend?.length) used.push('VisBulletLegend')
const pkg = framework === 'react' ? '@unovis/react' : '@unovis/solid'
const header = framework === 'react'
? `import React from 'react'\nimport { ${[...new Set(used)].sort().join(', ')} } from '${pkg}'`
: `import type { JSX } from 'solid-js'\nimport { ${[...new Set(used)].sort().join(', ')} } from '${pkg}'`