File tree Expand file tree Collapse file tree 2 files changed +107
-0
lines changed
Expand file tree Collapse file tree 2 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1+ .table {
2+ --table-border-color : var (--color-gray-200 );
3+
4+ width : 100% ;
5+ overflow-x : auto;
6+ }
7+
8+ .table table {
9+ width : 100% ;
10+ max-width : 100% ;
11+ border-collapse : collapse;
12+ font-size : var (--body-font-size-xs );
13+ }
14+
15+ @media (width > = 600px) {
16+ .table table {
17+ font-size : var (--body-font-size-s );
18+ }
19+ }
20+
21+ @media (width > = 900px) {
22+ .table table {
23+ font-size : var (--body-font-size-m );
24+ }
25+ }
26+
27+ .table table thead tr {
28+ border-top : 2px solid var (--table-border-color );
29+ border-bottom : 2px solid var (--table-border-color );
30+ }
31+
32+ .table table tbody tr {
33+ border-bottom : 1px solid var (--table-border-color );
34+ }
35+
36+ .table table th {
37+ font-weight : 700 ;
38+ }
39+
40+ .table table th ,
41+ .table table td {
42+ padding : 0.5em ;
43+ text-align : left;
44+ }
45+
46+ .table table th p ,
47+ .table table td p {
48+ margin : 0 ;
49+ }
50+
51+ .table table td p + p {
52+ margin-top : 0.25em ;
53+ }
54+
55+ /* no header variant */
56+ .table .no-header table tbody tr {
57+ border-top : 1px solid var (--table-border-color );
58+ }
59+
60+ /* striped variant */
61+ .table .striped tbody tr : nth-child (odd) {
62+ background-color : var (--light-color );
63+ }
64+
65+ /* bordered variant */
66+ .table .bordered table th ,
67+ .table .bordered table td {
68+ border : 1px solid var (--table-border-color );
69+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Table Block
3+ * Recreate a table
4+ * https://www.hlx.live/developer/block-collection/table
5+ */
6+
7+ function buildCell ( rowIndex ) {
8+ const cell = rowIndex ? document . createElement ( 'td' ) : document . createElement ( 'th' ) ;
9+ if ( ! rowIndex ) cell . setAttribute ( 'scope' , 'col' ) ;
10+ return cell ;
11+ }
12+
13+ export default async function decorate ( block ) {
14+ const table = document . createElement ( 'table' ) ;
15+ const thead = document . createElement ( 'thead' ) ;
16+ const tbody = document . createElement ( 'tbody' ) ;
17+
18+ const header = ! block . classList . contains ( 'no-header' ) ;
19+ if ( header ) table . append ( thead ) ;
20+ table . append ( tbody ) ;
21+
22+ [ ...block . children ] . forEach ( ( child , i ) => {
23+ const row = document . createElement ( 'tr' ) ;
24+ if ( header && i === 0 ) thead . append ( row ) ;
25+ else tbody . append ( row ) ;
26+ [ ...child . children ] . forEach ( ( col ) => {
27+ const cell = buildCell ( header ? i : i + 1 ) ;
28+ const align = col . getAttribute ( 'data-align' ) ;
29+ const valign = col . getAttribute ( 'data-valign' ) ;
30+ if ( align ) cell . style . textAlign = align ;
31+ if ( valign ) cell . style . verticalAlign = valign ;
32+ cell . innerHTML = col . innerHTML ;
33+ row . append ( cell ) ;
34+ } ) ;
35+ } ) ;
36+ block . innerHTML = '' ;
37+ block . append ( table ) ;
38+ }
You can’t perform that action at this time.
0 commit comments