JSFiddle - React, Tailwind, and code Playground

by oilvier

HTML

<table id="treegrid"
       role="treegrid"
       aria-label="Inbox">
  <colgroup>
    <col id="treegrid-col1">
    <col id="treegrid-col2">
    <col id="treegrid-col3">
  </colgroup>
  <thead>
    <tr>
      <th scope="col">
        Subject
      </th>
      <th scope="col">
        Summary
      </th>
      <th scope="col">
        Email
      </th>
    </tr>
  </thead>
  <tbody>
    <tr role="row"
        aria-level="1"
        aria-posinset="1"
        aria-setsize="1"
        aria-expanded="true">
      <td role="gridcell">
        Treegrids are awesome
      </td>
      <td role="gridcell">
        Want to learn how to use them?
      </td>
      <td role="gridcell">
        <a href="mailto:[email protected]">
          [email protected]
        </a>
        <span></span>
      </td>
    </tr>
    <tr role="row"
        aria-level="2"
        aria-posinset="1"
        aria-setsize="3"
        >
      <td role="gridcell">
        re: Treegrids are awesome
      </td>
      <td role="gridcell">
        I agree with you, they are the shizzle
      </td>
      <td role="gridcell">
        <a href="mailto:[email protected]">
          [email protected]
        </a>
      </td>
    </tr>
    <tr role="row"
        aria-level="2"
        aria-posinset="2"
        aria-setsize="3"
        aria-expanded="false"
        class="hidden">
      <td role="gridcell">
        re: Treegrids are awesome
      </td>
      <td role="gridcell">
        They are great for showing a lot of data, like a grid
      </td>
      <td role="gridcell">
        <a href="mailto:[email protected]">
          [email protected]
        </a>
      </td>
    </tr>
    <tr role="row"
        aria-level="3"
        aria-posinset="1"
        aria-setsize="1"
        class="hidden">
      <td role="gridcell">
        re: Treegrids are awesome
      </td>
      <td role="gridcell">
        Cool, we've been needing an example and documentation
      </td>
      <td...

SCSS

#treegrid {
  width: 100%;
  white-space: nowrap;
  border-collapse: collapse;
  table-layout: fixed;
}

#treegrid tr {
  display: table-row;
  cursor: default;
}

/* Extra space between columns for readability */
#treegrid th,
#treegrid td {
  padding-bottom: 3px;
  overflow-x: hidden;
  text-overflow: ellipsis;
}

#treegrid tbody td {
  cursor: default;
}

#treegrid-col1,
#treegrid-col3 {
  width: 30%;
}

#treegrid th {
  text-align: left;
  background-color: #eee;
}

#treegrid a {
  padding-left: 0.25ch;
  padding-right: 0.25ch;
}

#treegrid tr:focus,
#treegrid td:focus,
#treegrid a:focus {
  outline: 2px solid hsl(216, 94%, 70%);
  background-color: hsl(216, 80%, 97%);
}

#treegrid tr > td:not(:first-child),
#treegrid tr > th:not(:first-child) {
  padding-left: 3ch;
}

#treegrid a:focus {
  border-bottom: none;
}

/* Hide collapsed rows */
#treegrid tr.hidden {
  display: none;
}

/* Indents */
#treegrid tr[aria-level="2"] > td:first-child {
  padding-left: 2.5ch;
}

#treegrid tr[aria-level="3"] > td:first-child {
  padding-left: 5ch;
}

#treegrid tr[aria-level="4"] > td:first-child {
  padding-left: 7.5ch;
}

#treegrid tr[aria-level="5"] > td:first-child {
  padding-left: 10ch;
}

/* Collapse/expand icons */
#treegrid tr > td:first-child::before {
  font-family: monospace;
  content: " ";
  display: inline-block;
  width: 2ch;
  height: 11px;
  transition: transform 0.3s;
  transform-origin: 5px 5px;
}

#treegrid tr[aria-expanded] > td:first-child::before,
#treegrid td[aria-expanded]:first-child::before {
  cursor: pointer;

  /* Load both right away so there is no lag when we need the other */
  background-image: url("expand-icon.svg"), url("expand-icon-highlighted.svg");
  background-repeat: no-repeat;
}


#treegrid tr[aria-expanded]:focus > td:first-child::before,
#treegrid tr[aria-expanded] > td:focus:first-child::before,
#treegrid tr:focus > td[aria-expanded]:first-child::before,
#treegrid tr > td[aria-expanded]:focus:first-child::before {
 ...