Skip to content

Commit cf4eea3

Browse files
committed
fix: table
1 parent c93d7de commit cf4eea3

File tree

9 files changed

+26
-7
lines changed

9 files changed

+26
-7
lines changed

src/components/$Table/Cell.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const paddingMap = {
1515

1616
interface CellContainerProps {
1717
padding: 'none' | 'dense' | 'normal' | 'wide'
18+
verticalAlign: 'top' | 'middle' | 'bottom'
1819
numeric: boolean
1920
header: boolean
2021
}
@@ -28,13 +29,15 @@ const CellContainer = styled.td<CellContainerProps>`
2829
display: table-cell;
2930
border-bottom: ${({ theme }) => theme.styles.border()};
3031
${({ padding }) => paddingMap[padding]}
32+
${({ verticalAlign }) => `vertical-align: ${verticalAlign};`}
3133
${({ numeric }) =>
3234
numeric && "text-align: right; font-feature-settings: 'tnum';"}
3335
${({ header }) => header && whenHeader}
3436
`
3537

3638
export interface CellProps {
3739
padding?: 'none' | 'dense' | 'normal' | 'wide'
40+
verticalAlign?: 'top' | 'middle' | 'bottom'
3841
header?: boolean
3942
numeric?: boolean
4043
}
@@ -45,6 +48,7 @@ export const Cell: PC<'td', CellProps> = forwardRefWithGenerics(
4548
const tableRowGroupContext = useContext(TableRowGroupContext)
4649
const {
4750
padding = tableContext.padding,
51+
verticalAlign = tableRowGroupContext.verticalAlign,
4852
header = tableRowGroupContext.header,
4953
as,
5054
numeric = false,
@@ -56,6 +60,7 @@ export const Cell: PC<'td', CellProps> = forwardRefWithGenerics(
5660
return (
5761
<CellContainer
5862
padding={padding}
63+
verticalAlign={verticalAlign}
5964
numeric={numeric}
6065
header={header}
6166
ref={ref}

src/components/$Table/Row.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const RowContainer = styled.tr<RowContainerProps>`
1616
export interface RowProps {
1717
header?: boolean
1818
padding?: 'none' | 'dense' | 'normal' | 'wide'
19+
verticalAlign?: 'top' | 'middle' | 'bottom'
1920
}
2021

2122
export const Row: PC<'tr', RowProps> = forwardRefWithGenerics(
@@ -24,12 +25,15 @@ export const Row: PC<'tr', RowProps> = forwardRefWithGenerics(
2425
const {
2526
header = false,
2627
padding = tableContext.padding,
28+
verticalAlign = tableContext.verticalAlign,
2729
as = 'tr',
2830
...rest
2931
} = props
3032

3133
return (
32-
<TableContext.Provider value={{ ...tableContext, padding }}>
34+
<TableContext.Provider
35+
value={{ ...tableContext, padding, verticalAlign }}
36+
>
3337
<RowContainer header={header} ref={ref} as={as} {...rest} />
3438
</TableContext.Provider>
3539
)

src/components/$Table/TableContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import React from 'react'
33
export interface TableContextProps {
44
padding: 'none' | 'dense' | 'normal' | 'wide'
55
sticky: boolean | number | string
6+
verticalAlign: 'top' | 'middle' | 'bottom'
67
}
78

89
export const TableContext = React.createContext<TableContextProps>({
910
padding: 'normal',
1011
sticky: false,
12+
verticalAlign: 'top',
1113
})

src/components/$Table/TableHead.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ const TableHeadContainer = styled.thead<TableHeadContainerProps>`
2828

2929
export interface TableHeadProps {
3030
sticky?: boolean | number | string
31+
verticalAlign?: 'top' | 'middle' | 'bottom'
3132
}
3233

3334
export const TableHead: PC<'thead', TableHeadProps> = forwardRefWithGenerics(
3435
<T extends ElementType>(props: PP<T, TableHeadProps>, ref?: PR<T>) => {
3536
const tableContext = useContext(TableContext)
36-
const { sticky = tableContext.sticky, as = 'thead', ...rest } = props
37+
const {
38+
sticky = tableContext.sticky,
39+
verticalAlign = tableContext.verticalAlign,
40+
as = 'thead',
41+
...rest
42+
} = props
3743

3844
return (
39-
<TableRowGroupContext.Provider value={{ header: true }}>
45+
<TableRowGroupContext.Provider value={{ header: true, verticalAlign }}>
4046
<TableHeadContainer sticky={sticky} ref={ref} as={as} {...rest} />
4147
</TableRowGroupContext.Provider>
4248
)

src/components/$Table/TableRowGroupContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React from 'react'
22

33
export interface TableRowGroupContextProps {
44
header: boolean
5+
verticalAlign: 'top' | 'middle' | 'bottom'
56
}
67

78
export const TableRowGroupContext =
89
React.createContext<TableRowGroupContextProps>({
910
header: false,
11+
verticalAlign: 'top',
1012
})

src/styles/Themes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { transparentize } from 'polished'
2+
import { CSSLength } from '../types/length'
23
import { cssDiv } from '../utils/css'
34
import { cssLength } from '../utils/length'
45

@@ -52,8 +53,6 @@ const defaultPalette = {
5253
},
5354
}
5455

55-
export type CSSLength = number | string
56-
5756
export interface SolvedTextColor {
5857
main: string
5958
inverted: string

src/types/length.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type CSSLength = number | string

src/utils/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CSSLength } from '../styles'
1+
import { CSSLength } from '../types/length'
22
import { cssLength } from './length'
33

44
export const cssAdd = (a: CSSLength, b: CSSLength): CSSLength => {

src/utils/length.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CSSLength } from '../styles'
1+
import { CSSLength } from '../types/length'
22

33
export const cssLength = (cssLength?: CSSLength | null | undefined): string => {
44
if (typeof cssLength === 'number') {

0 commit comments

Comments
 (0)