feat(fe/layout): add columns layout

This commit is contained in:
hexxa 2022-03-15 22:06:04 +08:00 committed by Hexxa
parent 7c1bc34c48
commit e013acadfe

View file

@ -0,0 +1,43 @@
import * as React from "react";
import { List } from "immutable";
export interface Props {
rows: List<List<React.ReactNode>>;
widths: List<string>;
childrenClassNames?: List<string>;
style?: React.CSSProperties;
className?: string;
}
export const Columns = (props: Props) => {
const children = props.rows.map(
(row: List<React.ReactNode>, i: number): React.ReactNode => {
const cells = row.map((cell: React.ReactNode, j: number) => {
const width = props.widths.get(j, Math.trunc(100 / row.size));
const className = props.childrenClassNames.get(j, "");
return (
<div
key={`td-${i}-${j}`}
className={`float-l ${className}`}
style={{ width }}
>
{cell}
</div>
);
});
return (
<div key={`tr-${i}`}>
{cells}
<div className="fix"></div>
</div>
);
}
);
return (
<div style={props.style} className={props.className}>
{children}
</div>
);
};