<div class="table--scroll table--custom-borders" data-table-scroller='{ "maxCols": 6 }'>
    <figure class="table--scroll__container col-12" data-table-bounds>
        <figcaption>
            Default table caption
        </figcaption>
        <div class="table--scroll__viewport" data-table-viewport>
            <table class="table">
                <colgroup>
                    <col style="width: 12rem">
                    <col>
                    <col>
                    <col>
                    <col>
                    <col>
                    <col style="width: 8rem">
                </colgroup>
                <thead>
                    <tr>
                        <td class="table__head">
                            Column 01
                        </td>
                        <td class="table__head">
                            Column 02
                        </td>
                        <td class="table__head">
                            Column 03
                        </td>
                        <td class="table__head">
                            Column 04
                        </td>
                        <td class="table__head">
                            Column 05
                        </td>
                        <td class="table__head">
                            Column 06
                        </td>
                        <td class="table__head">
                            Column 07
                        </td>
                        <td class="table__head">
                            Column 08
                        </td>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td class="table__foot">
                            Footer Column 01
                        </td>
                        <td class="table__foot" colspan="7">
                            Footer content span across 7 columns
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <tr class="is-collapsed">
                        <td data-content="Column 01" data-accordion-toggle>
                            <span>Row 01 / Thead Cell 01</span>
                        </td>
                        <td data-content="Column 02" data-accordion-body>
                            <span>Row 01 / Cell 02</span>
                        </td>
                        <td data-content="Column 03" data-accordion-body>
                            <span>Row 01 / Cell 03</span>
                        </td>
                        <td data-content="Column 04" data-accordion-body>
                            <span>Row 01 / Cell 04</span>
                        </td>
                        <td data-content="Column 05" data-accordion-body>
                            <span>Row 01 / Cell 05</span>
                        </td>
                        <td data-content="Column 06" data-accordion-body>
                            <span>Row 01 / Cell 06</span>
                        </td>
                        <td data-content="Column 07" data-accordion-body>
                            <span>Row 01 / Cell 07</span>
                        </td>
                        <td data-content="Column 08" data-accordion-body>
                            <span>Row 01 / Cell 08</span>
                        </td>
                    </tr>
                    <tr class="is-collapsed">
                        <td data-content="Column 01" data-accordion-toggle>
                            <span>Row 02 / Thead Cell 01</span>
                        </td>
                        <td data-content="Column 02" data-accordion-body>
                            <span>Row 02 / Cell 02</span>
                        </td>
                        <td data-content="Column 03" data-accordion-body>
                            <span>Row 02 / Cell 03</span>
                        </td>
                        <td data-content="Column 04" data-accordion-body>
                            <span>Row 02 / Cell 04</span>
                        </td>
                        <td data-content="Column 05" data-accordion-body>
                            <span>Row 02 / Cell 05</span>
                        </td>
                        <td data-content="Column 06" data-accordion-body>
                            <span>Row 02 / Cell 06</span>
                        </td>
                        <td data-content="Column 07" data-accordion-body>
                            <span>Row 02 / Cell 07</span>
                        </td>
                        <td data-content="Column 08" data-accordion-body>
                            <span>Row 02 / Cell 08</span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </figure>
    <div class="table__controls text-center d-flex gap-5 py-3">
        <button class="button rounded-circle" data-table-scroll="start">&#x276F;</button>
        <button class="button rounded-circle" data-table-scroll="end">&#x276F;</button>
    </div>
</div>
<div class="table--scroll table--custom-borders" data-table-scroller='{{#if maxCols}}{ "maxCols": {{ maxCols}} }{{/if}}'>
    <figure class="table--scroll__container col-12" data-table-bounds>
        {{#if caption}}
        <figcaption>
            {{{ caption }}}
        </figcaption>
        {{/if}}
        <div class="table--scroll__viewport" data-table-viewport>
            <table class="table {{~#if responsive}} table--responsive{{/if~}}">
                {{#if cols}}
                <colgroup>
                    {{#each cols}}
                    <col {{#if width }}style="width: {{ width }}" {{/if}}>
                    {{/each}}
                </colgroup>
                {{/if}}
                {{#if thead}}
                <thead>
                    <tr>
                        {{#each thead.cells}}
                        <{{ type }} class="table__head">
                            {{ text }}
                        </{{ type }}>
                        {{/each}}
                    </tr>
                </thead>
                {{/if}}
                {{#if tfoot}}
                <tfoot>
                    <tr>
                        {{#each tfoot.cells}}
                        <{{ type }} class="table__foot" {{#if colspan}} colspan="{{ colspan }}" {{/if}}>
                            {{ text }}
                        </{{ type }}>
                        {{/each}}
                    </tr>
                </tfoot>
                {{/if}}
                {{#if tbody}}
                <tbody>
                    {{#each tbody.rows}}
                    <tr class="is-collapsed">
                        {{#each cells}}
                        <{{ type }} {{#if name}} data-content="{{name}}" {{/if}} {{~#if @index}}
                            data-accordion-body{{else}} data-accordion-toggle{{/if~}}>
                            <span>{{ text }}</span>
                        </{{ type }}>
                        {{/each}}
                    </tr>
                    {{/each}}
                </tbody>
                {{/if}}
            </table>
        </div>
    </figure>
    <div class="table__controls text-center d-flex gap-5 py-3">
        <button class="button rounded-circle" data-table-scroll="start">&#x276F;</button>
        <button class="button rounded-circle" data-table-scroll="end">&#x276F;</button>
    </div>
</div>
{
  "name": "defaults",
  "caption": "Default table caption",
  "cols": [
    {
      "width": "12rem"
    },
    {},
    {},
    {},
    {},
    {},
    {
      "width": "8rem"
    }
  ],
  "thead": {
    "cells": [
      {
        "type": "td",
        "width": 0,
        "text": "Column 01"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 02"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 03"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 04"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 05"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 06"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 07"
      },
      {
        "type": "td",
        "width": 0,
        "text": "Column 08"
      }
    ]
  },
  "tfoot": {
    "cells": [
      {
        "type": "td",
        "width": 0,
        "text": "Footer Column 01"
      },
      {
        "type": "td",
        "width": 0,
        "colspan": 7,
        "text": "Footer content span across 7 columns"
      }
    ]
  },
  "tbody": {
    "rows": [
      {
        "cells": [
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Thead Cell 01",
            "name": "Column 01"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 02",
            "name": "Column 02"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 03",
            "name": "Column 03"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 04",
            "name": "Column 04"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 05",
            "name": "Column 05"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 06",
            "name": "Column 06"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 07",
            "name": "Column 07"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 01 / Cell 08",
            "name": "Column 08"
          }
        ]
      },
      {
        "cells": [
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Thead Cell 01",
            "name": "Column 01"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 02",
            "name": "Column 02"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 03",
            "name": "Column 03"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 04",
            "name": "Column 04"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 05",
            "name": "Column 05"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 06",
            "name": "Column 06"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 07",
            "name": "Column 07"
          },
          {
            "type": "td",
            "width": 0,
            "text": "Row 02 / Cell 08",
            "name": "Column 08"
          }
        ]
      }
    ]
  },
  "maxCols": 6
}
  • Content:
    export const ScrollTable = (() => {
      window.addEventListener('click', (event) => {
      const button = event.target.closest('[data-table-scroll]');
      const container = event.target.closest('[data-table-scroller]');
      const viewport = container && container.querySelector('[data-table-viewport]');
      if (button && viewport) {
        const dir = button.dataset.tableScroll;
        if (dir === 'start') {
          viewport.scrollLeft = 0;
        }
        else if (dir === 'end') {
          viewport.scrollLeft = viewport.scrollWidth - viewport.clientWidth;
        }
      }
    });
    })();
    
    export const ResponsiveScrollTable = (() => {
      window.addEventListener('DOMContentLoaded', (event) => {
        const tables = Array.from(document.querySelectorAll(('[data-table-scroller]')));
        tables.forEach((table) => {
          const options = JSON.parse(table.dataset.tableScroller);
          if (options.maxCols) {
            const cols = Array.from(table.querySelectorAll('thead td'));
            if (cols && cols.length > options.maxCols) {
              const viewport = table.querySelector('[data-table-viewport]');
              const container = viewport.closest('.col-12');
              if (container) {
                container.classList.add('col-xl-10', 'mx-xl-auto');
              }
            }
          }
        })
      });
    });
    
    export default ScrollTable;
  • URL: /components/raw/table/table.js
  • Filesystem Path: src/components/molecules/table/table.js
  • Size: 1.3 KB
  • Content:
    :root,
    *::before,
    *::after {
        --table-bg-color: var(--brand-color-light);
        --table-border-width: .125rem;
        --table-border-color: var(--brand-color-white);
        --table-head-border-color: var(--brand-color-primary);
    }
    
    .table {
        width: 100%;
        table-layout: fixed;
        border-collapse: collapse;
        font-variant-numeric: lining-nums tabular-nums;
    
        caption {
            // caption-side: bottom;
        }
    
        th,
        td {
            padding: 1rem;
            background-color: var(--table-bg-color);
            border: var(--table-border-width) solid var(--table-border-color);
        }
    
        thead {
            th,
            td {
                font-weight: bold;
                vertical-align: top;
            }
        }
    
        &--transparent-header {
            thead {
                th,
                td {
                    background-color: transparent;
                }
            }
        }
    
        &--custom-borders {
            th,
            td {
                border: none;
                box-shadow: -.125rem 0 0 0 inset var(--table-border-color), 0 -.125rem 0 0 inset var(--table-border-color);
                &:last-child {
                    box-shadow: 0 -.125rem 0 0 inset var(--table-border-color);
                }
            }
            tr:last-child:not(tr:only-child) {
                th,
                td {
                    box-shadow: -.125rem 0 0 0 inset var(--table-border-color);
                    &:last-child {
                        box-shadow: none;
                    }
                }
            }
            thead {
                th,
                td {
                    position: relative;
                    box-shadow: -.125rem 0 0 0 inset var(--table-border-color), 0 -.125rem 0 0 inset var(--table-head-border-color);
                    &:last-child {
                        box-shadow: 0 -.125rem 0 0 inset var(--table-head-border-color);
                    }
                    &:not(:last-child)::after {
                        content: "";
                        position: absolute;
                        bottom: 0px;
                        right: 0px;
                        z-index: 1;
                        display: block;
                        width: 0.125rem;
                        height: 0.125rem;
                        background: var(--table-head-border-color);
                    }
                }
            }
            tfoot {
                tr {
                    th,
                    td {
                        box-shadow: -.125rem 0 0 0 inset var(--table-border-color);
                        &:last-child {
                            box-shadow: none;
                        }
                    }
                }
                ~ tbody {
                    tr:last-child:not(tr:only-child) {
                        th,
                        td {
                            box-shadow: -.125rem 0 0 0 inset var(--table-border-color), 0 -.125rem 0 0 inset var(--table-border-color);
                            &:last-child {
                                box-shadow: 0 -.125rem 0 0 inset var(--table-border-color);
                            }
                        }
                    }
                }
            }
    
            &--th {
                thead {
                    th,
                    td {
                        box-shadow: -.125rem 0 0 0 inset var(--table-border-color), 0 -.125rem 0 0 inset var(--table-head-border-color);
                        &:last-child {
                            box-shadow: 0 -.125rem 0 0 inset var(--table-head-border-color);
                        }
                    }
                }
                th:first-child,
                td:first-child {
                    box-shadow: -.125rem 0 0 0 inset var(--table-head-border-color), 0 -.125rem 0 0 inset var(--table-border-color);
                }
                thead {
                    th:first-child,
                    td:first-child {
                        box-shadow: -.125rem 0 0 0 inset var(--table-head-border-color), 0 -.125rem 0 0 inset var(--table-head-border-color);
                    }
                }
                tfoot {
                    tr:last-child {
                        th:first-child,
                        td:first-child {
                            box-shadow: -.125rem 0 0 0 inset var(--table-head-border-color);
                        }
                    }
                }
                tbody tr:last-child,
                tfoot ~ tbody tr:last-child:not(tr:only-child) {
                    th:first-child,
                    td:first-child {
                        box-shadow: -.125rem 0 0 0 inset var(--table-head-border-color), 0 -.125rem 0 0 inset var(--table-border-color);
                    }
                }
            }
        }
        // &--custom-borders {
        //     th,
        //     td {
        //         box-shadow: 0 .125rem 0 0 inset var(--table-border-color),
        //                     .125rem 0 0 0 inset var(--table-border-color);
        //         &:first-child {
        //             box-shadow: 0 .125rem 0 0 inset var(--table-border-color);
        //         }
        //     }
        //     thead {
        //         th,
        //         td {
        //             box-shadow: .125rem 0 0 0 inset var(--table-border-color);
        //             &:first-child {
        //                 box-shadow: none;
        //             }
        //         }
        //     }
    
        //     &--thead {
        //         tbody {
        //             tr:first-of-type {
        //                 td {
        //                     box-shadow: 0 .125rem 0 0 inset var(--table-head-border-color),
        //                                 .125rem 0 0 0 inset var(--table-border-color);
        //                     &:first-child {
        //                         box-shadow: 0 .125rem 0 0 inset var(--table-head-border-color);
        //                     }
        //                 }
        //             }
        //         }
        //     }
    
        //     &--th {
        //         thead tr {
        //             th:nth-child(2),
        //             td:nth-child(2) {
        //                 box-shadow: .125rem 0 0 0 inset var(--table-head-border-color);
        //             }
        //         }
        //         tbody {
        //             tr:first-of-type {
        //                 td {
        //                     box-shadow: 0 .125rem 0 0 inset var(--table-head-border-color),
        //                                 .125rem 0 0 0 inset var(--table-border-color);
        //                     &:first-child {
        //                         box-shadow: 0 .125rem 0 0 inset var(--table-head-border-color);
        //                     }
        //                     &:nth-child(2) {
        //                         box-shadow: 0 .125rem 0 0 inset var(--table-head-border-color),
        //                             .125rem 0 0 0 inset var(--table-head-border-color);
        //                     }
        //                 }
        //             }
        //         }
        //         th:first-child,
        //         td:first-child {
        //             + td {
        //                 box-shadow: 0 .125rem 0 0 inset var(--table-border-color),
        //                             .125rem 0 0 0 inset var(--table-head-border-color);
        //             }
        //         }
        //     }
        // }
    
        &--responsive {
            @include media-breakpoint-down(lg) {
                display: flex;
                flex-direction: column-reverse;
    
                tbody,
                tr {
                    display: block;
                    margin-bottom: .5rem;
                }
    
                thead {
                    display: none;
                }
    
                th,
                td {
                    display: flex;
                    justify-content: space-between;
                    gap: .5rem;
                    padding: 0;
                    border: none;
                    font-weight: normal;
                    margin-bottom: .125rem;
                    box-shadow: none;
                    &:first-of-type {
                        box-shadow: none;
                    }
    
                    &::before {
                        content: attr(data-content);
                        display: block;
                        flex: 0 0 50%;
                        border-right: .125rem solid $white;
                        padding: 1rem;
                        font-weight: bold;
                    }
    
                    span {
                        display: block;
                        padding: 1rem;
                    }
                }
    
                th::before {
                    // border-color: var(--brand-color-primary);
                }
    
                tbody th:first-of-type::after {
                    content: none;
                }
    
                tfoot td {
                    display: block;
                    padding: 1rem;
    
                    &::before {
                        content: none;
                    }
                }
    
                .is-collapsed {
                    td {
                        display: none;
    
                        &:first-child {
                            display: block;
                        }
                    }
                }
            }
        }
    
        &__controls {
            display: flex;
            justify-content: center;
    
            button:first-of-type {
                transform: rotate(180deg);
            }
        }
    }
    
    .table--scroll {
        position: relative;
        width: 100%;
    
        &__viewport {
            max-width: 100%;
            overflow-x: auto;
            scroll-behavior: smooth;
    
            .table {
                width: auto;
            }
    
            th,
            td {
                min-width: 8rem;
            }
        }
    
        @include media-breakpoint-up(xl) {
            .col-xl-10 {
                position: relative;
                z-index: 1;
            }
    
            .col-xl-10 + .table__controls {
                position: absolute;
                z-index: 0;
                top: 50%;
                transform: translateY(-50%);
                width: 100%;
                justify-content: space-between;
            }
        }
    }
    
  • URL: /components/raw/table/tables.scss
  • Filesystem Path: src/components/molecules/table/tables.scss
  • Size: 9.5 KB

No notes defined.