feat: add responvise page view (#2453)

This commit is contained in:
Whitewater
2023-05-21 16:25:25 -07:00
committed by GitHub
parent 1f510799e2
commit d68b421a4b
15 changed files with 381 additions and 287 deletions

View File

@@ -1,18 +1,16 @@
import { styled, textEllipsis } from '../../styles';
import type { TableCellProps } from './interface';
export const StyledTable = styled('table')<{ tableLayout: 'auto' | 'fixed' }>(
({ tableLayout }) => {
return {
fontSize: 'var(--affine-font-base)',
color: 'var(--affine-text-primary-color)',
tableLayout,
width: '100%',
borderCollapse: 'separate',
borderSpacing: '0',
};
}
);
export const StyledTable = styled('table')(() => {
return {
fontSize: 'var(--affine-font-base)',
color: 'var(--affine-text-primary-color)',
tableLayout: 'fixed',
width: '100%',
borderCollapse: 'separate',
borderSpacing: '0',
};
});
export const StyledTableBody = styled('tbody')(() => {
return {
@@ -37,7 +35,7 @@ export const StyledTableCell = styled('td')<
return {
width,
height: '52px',
padding: '0 30px',
paddingLeft: '16px',
boxSizing: 'border-box',
textAlign: align,
verticalAlign: 'middle',

View File

@@ -1,11 +1,4 @@
import type { HTMLAttributes, PropsWithChildren } from 'react';
import { StyledTableBody } from './styles';
export const TableBody = ({
children,
...props
}: PropsWithChildren<HTMLAttributes<HTMLTableSectionElement>>) => {
return <StyledTableBody {...props}>{children}</StyledTableBody>;
};
export const TableBody = StyledTableBody;
export default TableBody;

View File

@@ -1,7 +1,4 @@
import type { TableCellProps } from './interface';
import { StyledTableCell } from './styles';
export const TableCell = ({ children, ...props }: TableCellProps) => {
return <StyledTableCell {...props}>{children}</StyledTableCell>;
};
export const TableCell = StyledTableCell;
export default TableCell;

View File

@@ -1,11 +1,4 @@
import type { HTMLAttributes, PropsWithChildren } from 'react';
import { StyledTableRow } from './styles';
export const TableRow = ({
children,
...props
}: PropsWithChildren<HTMLAttributes<HTMLTableRowElement>>) => {
return <StyledTableRow {...props}>{children}</StyledTableRow>;
};
export const TableRow = StyledTableRow;
export default TableRow;

View File

@@ -1,31 +1,5 @@
import type { HTMLAttributes, PropsWithChildren, ReactNode } from 'react';
import { Children } from 'react';
import { StyledTable } from './styles';
const childrenHasEllipsis = (children: ReactNode | ReactNode[]): boolean => {
return Children.toArray(children).some(child => {
if (typeof child === 'object' && 'props' in child) {
if (!child.props.ellipsis && child.props.children) {
return childrenHasEllipsis(child.props.children);
}
return child.props.ellipsis ?? false;
}
return false;
});
};
export const Table = ({
children,
...props
}: PropsWithChildren<HTMLAttributes<HTMLTableElement>>) => {
const tableLayout = childrenHasEllipsis(children) ? 'fixed' : 'auto';
return (
<StyledTable tableLayout={tableLayout} {...props}>
{children}
</StyledTable>
);
};
export const Table = StyledTable;
export default Table;