Skip to content

Commit

Permalink
Fix unrecognized prop errors in React (#1154)
Browse files Browse the repository at this point in the history
React does not like receiving object props that don't match any HTML
spec. Styled components is dealing with this problem by prefixing all
non-standard properties one might want to send in with dollar signs as
`$transientProps`

You can read more about it here:
https://styled-components.com/docs/api#transient-props
  • Loading branch information
HendrikPetertje authored Aug 24, 2023
1 parent 5844212 commit 23103c5
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 84 deletions.
8 changes: 4 additions & 4 deletions src/DataTable/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { media } from './media';
import { TableColumnBase } from './types';

export const CellBase = styled.div<{
headCell?: boolean;
noPadding?: boolean;
$headCell?: boolean;
$noPadding?: boolean;
}>`
position: relative;
display: flex;
align-items: center;
box-sizing: border-box;
line-height: normal;
${({ theme, headCell }) => theme[headCell ? 'headCells' : 'cells'].style};
${({ noPadding }) => noPadding && 'padding: 0'};
${({ theme, $headCell }) => theme[$headCell ? 'headCells' : 'cells'].style};
${({ $noPadding }) => $noPadding && 'padding: 0'};
`;

export type CellProps = Pick<
Expand Down
12 changes: 6 additions & 6 deletions src/DataTable/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ContextActions = styled.div`
`;

const ContextMenuStyle = styled.div<{
rtl?: boolean;
visible: boolean;
$rtl?: boolean;
$visible: boolean;
}>`
position: absolute;
top: 0;
Expand All @@ -35,9 +35,9 @@ const ContextMenuStyle = styled.div<{
align-items: center;
justify-content: space-between;
display: flex;
${({ rtl }) => rtl && 'direction: rtl'};
${({ $rtl }) => $rtl && 'direction: rtl'};
${({ theme }) => theme.contextMenu.style};
${({ theme, visible }) => visible && theme.contextMenu.activeStyle};
${({ theme, $visible }) => $visible && theme.contextMenu.activeStyle};
`;

const generateDefaultContextTitle = (contextMessage: ContextMessage, selectedCount: number, rtl: boolean) => {
Expand Down Expand Up @@ -75,14 +75,14 @@ function ContextMenu({

if (contextComponent) {
return (
<ContextMenuStyle visible={visible}>
<ContextMenuStyle $visible={visible}>
{React.cloneElement(contextComponent as React.ReactElement, { selectedCount })}
</ContextMenuStyle>
);
}

return (
<ContextMenuStyle visible={visible} rtl={isRTL}>
<ContextMenuStyle $visible={visible} $rtl={isRTL}>
<Title>{generateDefaultContextTitle(contextMessage, selectedCount, isRTL)}</Title>
<ContextActions>{contextActions}</ContextActions>
</ContextMenuStyle>
Expand Down
10 changes: 5 additions & 5 deletions src/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
)}

<ResponsiveWrapper
responsive={responsive}
fixedHeader={fixedHeader}
fixedHeaderScrollHeight={fixedHeaderScrollHeight}
$responsive={responsive}
$fixedHeader={fixedHeader}
$fixedHeaderScrollHeight={fixedHeaderScrollHeight}
className={className}
{...wrapperProps}
>
Expand All @@ -370,8 +370,8 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {

<Table disabled={disabled} className="rdt_Table" role="table">
{showTableHead() && (
<Head className="rdt_TableHead" role="rowgroup" fixedHeader={fixedHeader}>
<HeadRow className="rdt_TableHeadRow" role="row" dense={dense}>
<Head className="rdt_TableHead" role="rowgroup" $fixedHeader={fixedHeader}>
<HeadRow className="rdt_TableHeadRow" role="row" $dense={dense}>
{selectableRows &&
(showSelectAll ? (
<CellBase style={{ flex: '0 0 48px' }} />
Expand Down
6 changes: 3 additions & 3 deletions src/DataTable/ExpanderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import styled, { CSSObject } from 'styled-components';
import { ComponentProps, ExpandableRowsComponent } from './types';

const ExpanderRowStyle = styled.div<{
extendedRowStyle: CSSObject;
$extendedRowStyle: CSSObject;
}>`
width: 100%;
box-sizing: border-box;
${({ theme }) => theme.expanderRow.style};
${({ extendedRowStyle }) => extendedRowStyle};
${({ $extendedRowStyle }) => $extendedRowStyle};
`;

type ExpanderRowProps<T> = {
Expand All @@ -31,7 +31,7 @@ function ExpanderRow<T>({
const classNames = ['rdt_ExpanderRow', ...classNamesSplit].join(' ');

return (
<ExpanderRowStyle className={classNames} extendedRowStyle={extendedRowStyle}>
<ExpanderRowStyle className={classNames} $extendedRowStyle={extendedRowStyle}>
<ExpanderComponent data={data} {...expanderComponentProps} />
</ExpanderRowStyle>
);
Expand Down
12 changes: 6 additions & 6 deletions src/DataTable/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ const PaginationWrapper = styled.nav`
`;

const Button = styled.button<{
isRTL: boolean;
$isRTL: boolean;
}>`
position: relative;
display: block;
user-select: none;
border: none;
${({ theme }) => theme.pagination.pageButtonsStyle};
${({ isRTL }) => isRTL && 'transform: scale(-1, -1)'};
${({ $isRTL }) => $isRTL && 'transform: scale(-1, -1)'};
`;

const PageList = styled.div`
Expand Down Expand Up @@ -157,7 +157,7 @@ function Pagination({
aria-disabled={disabledLesser}
onClick={handleFirst}
disabled={disabledLesser}
isRTL={isRTL}
$isRTL={isRTL}
>
{paginationIconFirstPage}
</Button>
Expand All @@ -169,7 +169,7 @@ function Pagination({
aria-disabled={disabledLesser}
onClick={handlePrevious}
disabled={disabledLesser}
isRTL={isRTL}
$isRTL={isRTL}
>
{paginationIconPrevious}
</Button>
Expand All @@ -183,7 +183,7 @@ function Pagination({
aria-disabled={disabledGreater}
onClick={handleNext}
disabled={disabledGreater}
isRTL={isRTL}
$isRTL={isRTL}
>
{paginationIconNext}
</Button>
Expand All @@ -195,7 +195,7 @@ function Pagination({
aria-disabled={disabledGreater}
onClick={handleLast}
disabled={disabledGreater}
isRTL={isRTL}
$isRTL={isRTL}
>
{paginationIconLastPage}
</Button>
Expand Down
18 changes: 9 additions & 9 deletions src/DataTable/ResponsiveWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import styled, { css } from 'styled-components';
*/

const ResponsiveWrapper = styled.div<{
responsive: boolean;
fixedHeader?: boolean;
fixedHeaderScrollHeight?: string;
$responsive: boolean;
$fixedHeader?: boolean;
$fixedHeaderScrollHeight?: string;
}>`
position: relative;
width: 100%;
border-radius: inherit;
${({ responsive, fixedHeader }) =>
responsive &&
${({ $responsive, $fixedHeader }) =>
$responsive &&
css`
overflow-x: auto;
// hidden prevents vertical scrolling in firefox when fixedHeader is disabled
overflow-y: ${fixedHeader ? 'auto' : 'hidden'};
overflow-y: ${$fixedHeader ? 'auto' : 'hidden'};
min-height: 0;
`};
${({ fixedHeader = false, fixedHeaderScrollHeight = '100vh' }) =>
fixedHeader &&
${({ $fixedHeader = false, $fixedHeaderScrollHeight = '100vh' }) =>
$fixedHeader &&
css`
max-height: ${fixedHeaderScrollHeight};
max-height: ${$fixedHeaderScrollHeight};
-webkit-overflow-scrolling: touch;
`};
Expand Down
30 changes: 15 additions & 15 deletions src/DataTable/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import { getProperty, getConditionalStyle } from './util';
import { TableColumn } from './types';

interface CellStyleProps {
renderAsCell: boolean | undefined;
wrapCell: boolean | undefined;
allowOverflow: boolean | undefined;
cellStyle: CSSObject | undefined;
isDragging: boolean;
$renderAsCell: boolean | undefined;
$wrapCell: boolean | undefined;
$allowOverflow: boolean | undefined;
$cellStyle: CSSObject | undefined;
$isDragging: boolean;
}

const overflowCSS = css<CellStyleProps>`
div:first-child {
white-space: ${({ wrapCell }) => (wrapCell ? 'normal' : 'nowrap')};
overflow: ${({ allowOverflow }) => (allowOverflow ? 'visible' : 'hidden')};
white-space: ${({ $wrapCell }) => ($wrapCell ? 'normal' : 'nowrap')};
overflow: ${({ $allowOverflow }) => ($allowOverflow ? 'visible' : 'hidden')};
text-overflow: ellipsis;
}
`;

const CellStyle = styled(CellExtended).attrs(props => ({
style: props.style,
}))<CellStyleProps>`
${({ renderAsCell }) => !renderAsCell && overflowCSS};
${({ theme, isDragging }) => isDragging && theme.cells.draggingStyle};
${({ cellStyle }) => cellStyle};
${({ $renderAsCell }) => !$renderAsCell && overflowCSS};
${({ theme, $isDragging }) => $isDragging && theme.cells.draggingStyle};
${({ $cellStyle }) => $cellStyle};
`;

interface CellProps<T> {
Expand Down Expand Up @@ -64,9 +64,9 @@ function Cell<T>({
role="cell"
className={classNames}
data-tag={dataTag}
cellStyle={column.style}
renderAsCell={!!column.cell}
allowOverflow={column.allowOverflow}
$cellStyle={column.style}
$renderAsCell={!!column.cell}
$allowOverflow={column.allowOverflow}
button={column.button}
center={column.center}
compact={column.compact}
Expand All @@ -76,9 +76,9 @@ function Cell<T>({
minWidth={column.minWidth}
right={column.right}
width={column.width}
wrapCell={column.wrap}
$wrapCell={column.wrap}
style={style}
isDragging={isDragging}
$isDragging={isDragging}
onDragStart={onDragStart}
onDragOver={onDragOver}
onDragEnd={onDragEnd}
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/TableCellCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function TableCellCheckbox<T>({
};

return (
<TableCellCheckboxStyle onClick={(e: React.MouseEvent) => e.stopPropagation()} className="rdt_TableCell" noPadding>
<TableCellCheckboxStyle onClick={(e: React.MouseEvent) => e.stopPropagation()} className="rdt_TableCell" $noPadding>
<Checkbox
name={name}
component={selectableRowsComponent}
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/TableCellExpander.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function CellExpander<T>({
disabled = false,
}: CellExpanderProps<T>): JSX.Element {
return (
<CellExpanderStyle onClick={(e: React.MouseEvent) => e.stopPropagation()} noPadding>
<CellExpanderStyle onClick={(e: React.MouseEvent) => e.stopPropagation()} $noPadding>
<ExpanderButton
id={id}
row={row}
Expand Down
8 changes: 4 additions & 4 deletions src/DataTable/TableCol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { equalizeId } from './util';
import { TableColumn, SortAction, SortOrder } from './types';

interface ColumnStyleProps extends CellProps {
isDragging?: boolean;
$isDragging?: boolean;
onDragStart: (e: React.DragEvent<HTMLDivElement>) => void;
onDragOver: (e: React.DragEvent<HTMLDivElement>) => void;
onDragEnd: (e: React.DragEvent<HTMLDivElement>) => void;
Expand All @@ -16,7 +16,7 @@ interface ColumnStyleProps extends CellProps {

const ColumnStyled = styled(CellExtended)<ColumnStyleProps>`
${({ button }) => button && 'text-align: center'};
${({ theme, isDragging }) => isDragging && theme.headCells.draggingStyle};
${({ theme, $isDragging }) => $isDragging && theme.headCells.draggingStyle};
`;

interface ColumnSortableProps {
Expand Down Expand Up @@ -186,7 +186,7 @@ function TableCol<T>({
<ColumnStyled
data-column-id={column.id}
className="rdt_TableCol"
headCell
$headCell
allowOverflow={column.allowOverflow}
button={column.button}
compact={column.compact}
Expand All @@ -198,7 +198,7 @@ function TableCol<T>({
center={column.center}
width={column.width}
draggable={column.reorder}
isDragging={equalizeId(column.id, draggingColumnId)}
$isDragging={equalizeId(column.id, draggingColumnId)}
onDragStart={onDragStart}
onDragOver={onDragOver}
onDragEnd={onDragEnd}
Expand Down
2 changes: 1 addition & 1 deletion src/DataTable/TableColCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ColumnCheckbox<T>({
};

return (
<ColumnStyle className="rdt_TableCol" headCell={headCell} noPadding>
<ColumnStyle className="rdt_TableCol" $headCell={headCell} $noPadding>
<Checkbox
name="select-all-rows"
component={selectableRowsComponent}
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const fixedCSS = css`
`;

const Head = styled.div<{
fixedHeader?: boolean;
$fixedHeader?: boolean;
}>`
display: flex;
width: 100%;
${({ fixedHeader }) => fixedHeader && fixedCSS};
${({ $fixedHeader }) => $fixedHeader && fixedCSS};
${({ theme }) => theme.head.style};
`;

Expand Down
4 changes: 2 additions & 2 deletions src/DataTable/TableHeadRow.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import styled from 'styled-components';

const HeadRow = styled.div<{
dense?: boolean;
$dense?: boolean;
disabled?: boolean;
}>`
display: flex;
align-items: stretch;
width: 100%;
${({ theme }) => theme.headRow.style};
${({ dense, theme }) => dense && theme.headRow.denseStyle};
${({ $dense, theme }) => $dense && theme.headRow.denseStyle};
`;

export default HeadRow;
Loading

0 comments on commit 23103c5

Please sign in to comment.