(name: string, props: Props, controls?: Controls, indent = '')
| 331 | } |
| 332 | |
| 333 | function renderElement(name: string, props: Props, controls?: Controls, indent = '') { |
| 334 | let start = ( |
| 335 | <> |
| 336 | <<span className={style({color: 'red-1000'})}>{name}</span> |
| 337 | </> |
| 338 | ); |
| 339 | let renderedProps = Object.keys(props) |
| 340 | .filter(prop => prop !== 'children') |
| 341 | .map(prop => renderProp(prop, props[prop], controls?.[prop], ' ' + indent)) |
| 342 | .filter(Boolean); |
| 343 | let newlines = name.length + countChars(renderedProps) > 40; |
| 344 | renderedProps = renderedProps.map((p, i) => ( |
| 345 | <Fragment key={i}> |
| 346 | {newlines ? '\n ' + indent : ' '} |
| 347 | {p} |
| 348 | </Fragment> |
| 349 | )); |
| 350 | if (props.children) { |
| 351 | let end = ( |
| 352 | <> |
| 353 | </<span className={style({color: 'red-1000'})}>{name}</span>> |
| 354 | </> |
| 355 | ); |
| 356 | let children = renderChildren(props.children, indent); |
| 357 | if (typeof children !== 'string') { |
| 358 | newlines = true; |
| 359 | } |
| 360 | return ( |
| 361 | <> |
| 362 | {start} |
| 363 | {renderedProps}>{newlines ? '\n ' + indent : null} |
| 364 | {children} |
| 365 | {newlines ? '\n' + indent : null} |
| 366 | {end} |
| 367 | </> |
| 368 | ); |
| 369 | } |
| 370 | |
| 371 | return ( |
| 372 | <> |
| 373 | {start} |
| 374 | {renderedProps} /> |
| 375 | </> |
| 376 | ); |
| 377 | } |
| 378 | |
| 379 | function renderChildren(children, indent = '') { |
| 380 | if (children?.icon || children?.avatar || children?.badge) { |
no test coverage detected