11// @flow
22import * as React from "react" ;
33import { createUseStyles } from "react-jss" ;
4+ import type { TextAlign } from "../commonTypes" ;
45
56type TableProps = {
67 children ?: React . Node ,
78} ;
89
910type TableDataProps = {
10- center ?: boolean ,
11+ borderWidth ?: string ,
1112 colSpan ?: number ,
1213 rowSpan ?: number ,
1314 styles ?: any ,
15+ textAlign ?: TextAlign ,
16+ width ?: string ,
1417 children ?: React . Node ,
1518} ;
1619
@@ -19,7 +22,7 @@ type TableHeaderProps = TableDataProps & {
1922} ;
2023
2124export function Table ( { children } : TableProps ) : React . Node {
22- const classes = useTableStyles ( ) ;
25+ const classes = useTableStyles ( { } ) ;
2326
2427 return < table className = { classes . table } > { children } </ table > ;
2528}
@@ -37,18 +40,19 @@ export function TableHead({ children }: TableProps): React.Node {
3740}
3841
3942export function TableHeader ( {
40- center,
4143 colSpan,
4244 rowSpan,
4345 scope,
46+ textAlign,
47+ width,
4448 children,
4549 styles,
4650} : TableHeaderProps ) : React . Node {
47- const classes = useTableStyles ( ) ;
51+ const classes = useTableStyles ( { textAlign , width } ) ;
4852
4953 return (
5054 < th
51- className = { center && classes . center }
55+ className = { classes . tableHeader }
5256 style = { styles }
5357 colSpan = { colSpan ? colSpan : 1 }
5458 rowSpan = { rowSpan ? rowSpan : 1 }
@@ -59,18 +63,24 @@ export function TableHeader({
5963 ) ;
6064}
6165
66+ TableHeader . defaultProps = {
67+ textAlign : "center" ,
68+ } ;
69+
6270export function TableData ( {
63- center ,
71+ borderWidth ,
6472 colSpan,
6573 rowSpan,
6674 children,
75+ textAlign,
76+ width,
6777 styles,
6878} : TableDataProps ) : React . Node {
69- const classes = useTableStyles ( ) ;
79+ const classes = useTableStyles ( { borderWidth , textAlign , width } ) ;
7080
7181 return (
7282 < td
73- className = { ` ${ classes . tableData } ${ center ? classes . center : "" } ` }
83+ className = { classes . tableData }
7484 style = { styles }
7585 colSpan = { colSpan ? colSpan : 1 }
7686 rowSpan = { rowSpan ? rowSpan : 1 }
@@ -80,17 +90,22 @@ export function TableData({
8090 ) ;
8191}
8292
93+ TableData . defaultProps = { borderWidth : "1px" , textAlign : "right" } ;
94+
8395const useTableStyles = createUseStyles ( {
84- center : {
85- textAlign : "center" ,
86- } ,
8796 table : {
8897 borderCollapse : "collapse" ,
8998 } ,
9099 tableData : {
91- border : "1px" ,
100+ borderWidth : ( { borderWidth } ) => borderWidth ,
92101 borderStyle : "solid" ,
93102 margin : 0 ,
94103 padding : "5px 5px" ,
104+ textAlign : ( { textAlign } ) => textAlign ,
105+ width : ( { width } ) => width ,
106+ } ,
107+ tableHeader : {
108+ textAlign : ( { textAlign } ) => textAlign ,
109+ width : ( { width } ) => width ,
95110 } ,
96111} ) ;
0 commit comments