-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: table components * feat(table): add verticalAlign prop --------- Co-authored-by: denkristoffer <denkristoffer@users.noreply.github.com>
- Loading branch information
1 parent
79d96ae
commit 53695c2
Showing
19 changed files
with
345 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@contentful/f36-table': minor | ||
--- | ||
|
||
- Add new `verticalAlign` prop to control vertical alignment of table cell content. | ||
- Table styles minor update. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { css } from 'emotion'; | ||
import tokens from '@contentful/f36-tokens'; | ||
|
||
export const getTableStyles = () => ({ | ||
inline: css({ | ||
borderRadius: tokens.borderRadiusMedium, | ||
boxShadow: `0 0 0 1px ${tokens.gray200}`, | ||
'th:first-child': { | ||
borderTopLeftRadius: tokens.borderRadiusMedium, | ||
}, | ||
'th:last-child': { | ||
borderTopRightRadius: tokens.borderRadiusMedium, | ||
}, | ||
'tr:last-child td:first-child': { | ||
borderBottomLeftRadius: tokens.borderRadiusMedium, | ||
}, | ||
'tr:last-child td:last-child': { | ||
borderBottomRightRadius: tokens.borderRadiusMedium, | ||
}, | ||
}), | ||
embedded: css({ | ||
borderBottom: `1px solid ${tokens.gray200}`, | ||
}), | ||
root: css({ | ||
width: '100%', | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
packages/components/table/src/TableCell/TableCell.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { css } from 'emotion'; | ||
import tokens from '@contentful/f36-tokens'; | ||
import { TableCellInternalProps } from './TableCell'; | ||
import { TableProps } from '../Table'; | ||
|
||
export const getTableCellStyles = ({ | ||
isTableHead, | ||
sorting, | ||
align, | ||
verticalAlign, | ||
}: { | ||
isTableHead?: boolean; | ||
verticalAlign?: TableProps['verticalAlign']; | ||
} & Pick<TableCellInternalProps, 'sorting' | 'align'>) => ({ | ||
container: css({ | ||
borderBottom: `1px solid ${tokens.gray200}`, | ||
padding: tokens.spacingS, | ||
textAlign: align, | ||
color: sorting ? tokens.gray900 : tokens.gray700, | ||
fontWeight: isTableHead ? tokens.fontWeightMedium : tokens.fontWeightNormal, | ||
verticalAlign, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { cx } from 'emotion'; | ||
import React, { forwardRef } from 'react'; | ||
import { | ||
type CommonProps, | ||
type PropsWithHTMLElement, | ||
type ExpandProps, | ||
type PolymorphicComponent, | ||
} from '@contentful/f36-core'; | ||
import { Text, Caption, type TextProps } from '@contentful/f36-typography'; | ||
|
||
import { useTableCellContext } from './TableCellContext'; | ||
import { getTableCellStyles } from './TableCell.styles'; | ||
import { useTableContext } from '../tableContext'; | ||
|
||
export const sortingDirections = { | ||
asc: 'asc', | ||
desc: 'desc', | ||
}; | ||
|
||
export type TableCellSorting = keyof typeof sortingDirections | boolean; | ||
|
||
export type TableCellInternalProps = CommonProps & { | ||
align?: 'center' | 'left' | 'right'; | ||
sorting?: TableCellSorting; | ||
width?: string | number; | ||
children?: React.ReactNode; | ||
} & Pick<TextProps, 'isTruncated' | 'isWordBreak'>; | ||
|
||
export type TableCellProps = PropsWithHTMLElement< | ||
TableCellInternalProps, | ||
'th' | 'td' | ||
>; | ||
|
||
function _TableCell( | ||
{ | ||
align = 'left', | ||
children, | ||
className, | ||
sorting = false as TableCellSorting, | ||
testId = 'cf-ui-table-cell', | ||
...otherProps | ||
}: TableCellProps, | ||
forwardedRef: React.Ref<any>, | ||
) { | ||
const { as, name: context, offsetTop } = useTableCellContext(); | ||
const { verticalAlign } = useTableContext(); | ||
|
||
const isTableHead = context === 'head'; | ||
const styles = getTableCellStyles({ | ||
isTableHead, | ||
sorting, | ||
align, | ||
verticalAlign, | ||
}); | ||
|
||
const BaseComponent = isTableHead ? Caption : Text; | ||
|
||
return ( | ||
<BaseComponent | ||
{...otherProps} | ||
as={as} | ||
className={cx(styles.container, className)} | ||
ref={forwardedRef} | ||
style={{ | ||
...otherProps.style, | ||
top: offsetTop || undefined, | ||
}} | ||
testId={testId} | ||
> | ||
{children} | ||
</BaseComponent> | ||
); | ||
} | ||
|
||
_TableCell.displayName = 'TableCell'; | ||
|
||
export const TableCell: PolymorphicComponent< | ||
ExpandProps<TableCellInternalProps>, | ||
'th' | 'td' | ||
> = forwardRef(_TableCell); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/components/table/src/TableHead/TableHead.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { css } from 'emotion'; | ||
import tokens from '@contentful/f36-tokens'; | ||
|
||
export const getTableHeadStyles = () => ({ | ||
sticky: css({ | ||
th: { | ||
position: 'sticky', | ||
top: 0, | ||
zIndex: tokens.zIndexDefault, | ||
}, | ||
}), | ||
}); |
Oops, something went wrong.
53695c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
forma-36 – ./
forma-36.vercel.app
v4.f36.contentful.com
f36.contentful.com
forma-36.colorfuldemo.com
forma-36-git-main.colorfuldemo.com