question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

I mentioned this on Twitter, but I’d really love to see an example of displaying tabular data with Ink.

I’ve figured out how to get tabular columns aligned using flexBasis/minWidth, but it’s a hack–I have to find the max string length of all table headers and data in table cells (for each column), then share this number among each cell in the column & the associated header.

e.g. (pseudo-jsx):

<!-- colSizes must be manually computed -->
<Box flexDirection="column">
  <Box>
    <Box flexBasis={colSize[0]}>HeaderA</Box>
    <Box flexBasis={colSize[1]}>HeaderB</Box>  
    <Box flexBasis={colSize[2]}>HeaderC</Box>  
  </Box>
  <Box>
    {rows.map(row => (
      <Box flexBasis={colSize[0]}>{row[0]}</Box>
      <Box flexBasis={colSize[1]}>{row[1]}</Box>
      <Box flexBasis={colSize[2]}>{row[2]}</Box>
    ))}
  </Box>
</Box>

My feeling is that <Box> is perhaps not well-suited to this task, but could be wrong–I’m inexperienced with both React and flexbox.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
SimenBcommented, May 5, 2019

One thing you could do is split up into columns manually, e.g. left, middle, right arrays, then render them into separate <Box flexDirection="column"> and wrap that whole thing into a <Box flexDirection="row">

import React from "react";
import { render, Box, Text, Color } from "ink";

const left = ["Rule", "cpu usage", "library-mismatch", "long-timeout"];
const middle = ["ID", "id 1", "id 2", "id 3"];
const right = [
  "Description",
  "description 1",
  "description 2",
  "description 3"
];

function App() {
  return (
    <Box flexDirection="row">
      <Box flexDirection="column">
        {left.map((e, i) => {
          if (i === 0) return <Text underline>{e}</Text>;

          return <Color blue>{e}</Color>;
        })}
      </Box>
      <Box flexDirection="column" paddingX={1}>
        {middle.map((e, i) => {
          if (i === 0) return <Text underline>{e}</Text>;

          return <Text>{e}</Text>;
        })}
      </Box>
      <Box flexDirection="column">
        {right.map((e, i) => {
          if (i === 0) return <Text underline>{e}</Text>;

          return (
            <Color yellow underline>
              {e}
            </Color>
          );
        })}
      </Box>
    </Box>
  );
}

render(<App />);

image

I don’t know if that’s something that should be encouraged, but it works at least 🙂

1reaction
SimenBcommented, Jun 13, 2019

CSS grid is probably far off: https://github.com/facebook/yoga/issues/867. It would be sweet though 😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Tables - W3Schools
A table in HTML consists of table cells inside rows and columns. Example. A simple HTML table: <table> <tr>
Read more >
HTML table basics - Learn web development | MDN
A table allows you to quickly and easily look up values that indicate some kind of connection between different types of data, for...
Read more >
HTML Tables – Table Tutorial with Example Code
A table is a representation of data arranged in rows and columns. Really, it's more like a spreadsheet. In HTML, with the help...
Read more >
HTML - Tables - Tutorialspoint
HTML - Tables, The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into rows and columns...
Read more >
Create An HTML Table Quickly & Easily With Our Code ...
Tables : This reference explains all the attributes for use with the TABLE tag, ... What does Create An HTML Table Quickly &...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found