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