* Constructs a Row element from the configuration.
(config: RowConfig)
| 276 | * Constructs a Row element from the configuration. |
| 277 | */ |
| 278 | function row<T extends ScalarDict>(config: RowConfig): (props: RowProps<T>) => React.JSX.Element { |
| 279 | /* This is a component builder. We return a function. */ |
| 280 | |
| 281 | const skeleton = config.skeleton; |
| 282 | |
| 283 | /* Row */ |
| 284 | return (props) => ( |
| 285 | <Box flexDirection="row"> |
| 286 | {/* Left */} |
| 287 | <skeleton.component>{skeleton.left}</skeleton.component> |
| 288 | {/* Data */} |
| 289 | {...intersperse( |
| 290 | (i) => { |
| 291 | const key = `${props.key}-hseparator-${i}`; |
| 292 | |
| 293 | // The horizontal separator. |
| 294 | return <skeleton.component key={key}>{skeleton.cross}</skeleton.component>; |
| 295 | }, |
| 296 | |
| 297 | // Values. |
| 298 | props.columns.map((column, colI) => { |
| 299 | // content |
| 300 | const value = props.data[column.column]; |
| 301 | |
| 302 | if (value == undefined || value == null) { |
| 303 | const key = `${props.key}-empty-${column.key}`; |
| 304 | |
| 305 | return ( |
| 306 | <config.cell key={key} column={colI}> |
| 307 | {skeleton.line.repeat(column.width)} |
| 308 | </config.cell> |
| 309 | ); |
| 310 | } else { |
| 311 | const key = `${props.key}-cell-${column.key}`; |
| 312 | |
| 313 | // margins |
| 314 | const ml = config.padding; |
| 315 | const mr = column.width - String(value).length - config.padding; |
| 316 | |
| 317 | return ( |
| 318 | /* prettier-ignore */ |
| 319 | <config.cell key={key} column={colI}> |
| 320 | {`${skeleton.line.repeat(ml)}${String(value)}${skeleton.line.repeat(mr)}`} |
| 321 | </config.cell> |
| 322 | ); |
| 323 | } |
| 324 | }) |
| 325 | )} |
| 326 | {/* Right */} |
| 327 | <skeleton.component>{skeleton.right}</skeleton.component> |
| 328 | </Box> |
| 329 | ); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Renders the header of a table. |