Skip to content

Commit

Permalink
minor. fix table width
Browse files Browse the repository at this point in the history
  • Loading branch information
seungpark committed Dec 3, 2024
1 parent e579032 commit 674f090
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/ListTable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useRef } from 'react';
import React, { useMemo, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import {
Cell,
Expand Down Expand Up @@ -32,7 +32,9 @@ const styleTable = ({ customAlign, customWidth }) => css`
${customAlign && `text-align: ${align(customAlign)}`};
${customWidth && `width: ${customWidth}`};
margin: ${theme.size.medium} 0;
table-layout: fixed;
> table {
table-layout: fixed;
}
`;

const theadStyle = css`
Expand Down Expand Up @@ -230,7 +232,6 @@ const generateRowsData = (bodyRowNodes, columns) => {

const ListTable = ({ nodeData: { children, options }, ...rest }) => {
const ancestors = useAncestorComponentContext();
// const { theme: siteTheme } = useDarkMode();
// TODO: header row count should not be more than 1
// need a warning in parser
const headerRowCount = parseInt(options?.['header-rows'], 10) || 0;
Expand All @@ -239,9 +240,8 @@ const ListTable = ({ nodeData: { children, options }, ...rest }) => {
const columnCount = bodyRows[0].children[0].children.length;

// Check if :header-rows: 0 is specified or :header-rows: is omitted
const headerRows = useMemo(
() => (headerRowCount > 0 ? children[0].children[0].children.slice(0, headerRowCount) : []),
[children, headerRowCount]
const [headerRows] = useState(() =>
headerRowCount > 0 ? children[0].children[0].children.slice(0, headerRowCount) : []
);

let widths = null;
Expand All @@ -263,8 +263,8 @@ const ListTable = ({ nodeData: { children, options }, ...rest }) => {
const shouldAlternateRowColor = noTableNesting && bodyRows.length > 4;

const tableRef = useRef();
const columns = useMemo(() => generateColumns(headerRows[0], bodyRows), [headerRows, bodyRows]);
const data = useMemo(() => generateRowsData(bodyRows, columns), [bodyRows, columns]);
const [columns] = useState(() => generateColumns(headerRows[0], bodyRows));
const [data] = useState(() => generateRowsData(bodyRows, columns));
const table = useLeafyGreenTable({
containerRef: tableRef,
columns: columns,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/__snapshots__/ListTable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ exports[`when rendering a list table with fixed widths renders correctly 1`] = `
width: 100%;
position: relative;
margin: 24px 0;
}
.emotion-0>table {
table-layout: fixed;
}
Expand Down Expand Up @@ -327,6 +330,9 @@ exports[`when rendering a list-table directive renders correctly 1`] = `
width: 100%;
position: relative;
margin: 24px 0;
}
.emotion-0>table {
table-layout: fixed;
}
Expand Down

0 comments on commit 674f090

Please sign in to comment.