Skip to content

fix: resolve React 19 compatibility by replacing defaultProps with attrs #1351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-actors-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'spectacle': patch
---

Fix React 19 compatibility by replacing defaultProps with attrs method
7 changes: 1 addition & 6 deletions packages/spectacle/src/components/fullscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Container = styled('div')`
`;

const FullScreen = forwardRef<HTMLDivElement, FSProps>(
({ size, color, ...props }, ref) => {
({ size = 24, color = '#fff', ...props }, ref) => {
const toggleFullScreen = useToggleFullScreen();
const [isClient, setIsClient] = useState(false);

Expand Down Expand Up @@ -52,9 +52,4 @@ const FullScreen = forwardRef<HTMLDivElement, FSProps>(

FullScreen.displayName = 'Fullscreen';

FullScreen.defaultProps = {
color: '#fff',
size: 24
};

export default FullScreen;
9 changes: 4 additions & 5 deletions packages/spectacle/src/components/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ type ImageType = FC<
>;

const Image = styled.img(compose(layout, position)) as ImageType;
const FullSizeImage = styled(Image) as unknown as ImageType;

FullSizeImage.defaultProps = {
const FullSizeImage = styled(Image).attrs<SS.LayoutProps>((props) => ({
maxWidth: '100%',
maxHeight: '100%'
};
maxHeight: '100%',
...props
})) as unknown as ImageType;

export { Image, FullSizeImage };
25 changes: 10 additions & 15 deletions packages/spectacle/src/components/layout-primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ const Box = styled.div<BoxProps>(
containerPrintStyle
);

const FlexBox = styled.div<BoxProps & SS.FlexboxProps>(
compose(layout, space, position, color, border, flexbox),
containerPrintStyle
);

FlexBox.defaultProps = {
const FlexBox = styled.div.attrs<BoxProps & SS.FlexboxProps>((props) => ({
alignItems: 'center',
justifyContent: 'center',
display: 'flex'
};

type GridProps = SS.LayoutProps & SS.GridProps & SS.PositionProps;
const Grid = styled.div<GridProps>(
compose(layout, grid, position),
display: 'flex',
...props
}))<BoxProps & SS.FlexboxProps>(
compose(layout, space, position, color, border, flexbox),
containerPrintStyle
);

Grid.defaultProps = {
display: 'grid'
};
type GridProps = SS.LayoutProps & SS.GridProps & SS.PositionProps;
const Grid = styled.div.attrs<GridProps>((props) => ({
display: 'grid',
...props
}))<GridProps>(compose(layout, grid, position), containerPrintStyle);

export { Box, FlexBox, Grid };
55 changes: 20 additions & 35 deletions packages/spectacle/src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,52 @@ export type TableProps = ColorProps &
BorderProps &
LayoutProps;

const Table = styled.table<TableProps>(
compose(color, typography, space, border, layout)
);

Table.defaultProps = {
const Table = styled.table.attrs<TableProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 'listMargin',
width: 1
};

const TableHeader = styled.thead<TableProps>(
compose(color, typography, space, border, layout)
);
width: 1,
...props
}))<TableProps>(compose(color, typography, space, border, layout));

TableHeader.defaultProps = {
const TableHeader = styled.thead.attrs<TableProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
fontWeight: 'bold',
textAlign: 'left',
margin: 'listMargin'
};

const TableBody = styled.tbody<TableProps>(
compose(color, typography, space, border, layout)
);
margin: 'listMargin',
...props
}))<TableProps>(compose(color, typography, space, border, layout));

TableBody.defaultProps = {
const TableBody = styled.tbody.attrs<TableProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 'listMargin',
width: 1
};
width: 1,
...props
}))<TableProps>(compose(color, typography, space, border, layout));

const TableRow = styled.tr<TableProps>(
compose(color, typography, space, border, layout)
);

TableRow.defaultProps = {
const TableRow = styled.tr.attrs<TableProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 'listMargin'
};

const TableCell = styled.td<TableProps>(
compose(color, typography, space, border, layout)
);
margin: 'listMargin',
...props
}))<TableProps>(compose(color, typography, space, border, layout));

TableCell.defaultProps = {
const TableCell = styled.td.attrs<TableProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 'listMargin'
};
margin: 'listMargin',
...props
}))<TableProps>(compose(color, typography, space, border, layout));

export { Table, TableCell, TableRow, TableHeader, TableBody };
124 changes: 61 additions & 63 deletions packages/spectacle/src/components/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,101 +25,101 @@ type DecorationProps = Pick<CSSObject, 'textDecoration'>;

export type CommonTypographyProps = ColorProps & TypographyProps & SpaceProps;

const Text = styled.div<CommonTypographyProps>(
compose(color, typography, space)
);
Text.defaultProps = {
const Text = styled.div.attrs<CommonTypographyProps>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
padding: 0,
margin: 0
};
margin: 0,
...props
}))<CommonTypographyProps>(compose(color, typography, space));

const CodeSpan = styled.code<CommonTypographyProps>(
compose(color, typography, space)
);
CodeSpan.defaultProps = {
const CodeSpan = styled.code.attrs<CommonTypographyProps>((props) => ({
fontFamily: 'monospace',
fontSize: 'text'
};

const Link = styled.a<CommonTypographyProps & DecorationProps>(
fontSize: 'text',
...props
}))<CommonTypographyProps>(compose(color, typography, space));

const Link = styled.a.attrs<CommonTypographyProps & DecorationProps>(
(props) => ({
fontFamily: 'text',
fontSize: 'text',
textDecoration: 'underline',
color: 'quaternary',
...props
})
)<CommonTypographyProps & DecorationProps>(
compose(color, typography, space, decoration)
);
Link.defaultProps = {
fontFamily: 'text',
fontSize: 'text',
textDecoration: 'underline',
color: 'quaternary'
};

const Heading = styled(Text)({});
Heading.defaultProps = {
const Heading = styled(Text).attrs<CommonTypographyProps>((props) => ({
color: 'secondary',
fontFamily: 'header',
fontSize: 'h1',
fontWeight: 'bold',
textAlign: 'center',
margin: 1
};
margin: 1,
...props
}))<CommonTypographyProps>({});

const Quote = styled(
Text as FC<
PropsWithChildren<CommonTypographyProps & Pick<BorderProps, 'borderColor'>>
>
)`
).attrs<CommonTypographyProps & Pick<BorderProps, 'borderColor'>>((props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
fontStyle: 'italic',
padding: '16px 0 16px 8px',
margin: 0,
...props
}))<CommonTypographyProps & Pick<BorderProps, 'borderColor'>>`
border-left: 1px solid
${({ theme, borderColor }) => borderColor || theme.colors.secondary};

div {
margin: 0;
}
`;
Quote.defaultProps = {
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
fontStyle: 'italic',
padding: '16px 0 16px 8px',
margin: 0
};

const listStyle = system({
listStyleType: true
});
type ListStyleProps = Pick<CSSObject, 'listStyleType'>;

const OrderedList = styled.ol<CommonTypographyProps & ListStyleProps>(
const OrderedList = styled.ol.attrs<CommonTypographyProps & ListStyleProps>(
(props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 0,
...props
})
)<CommonTypographyProps & ListStyleProps>(
compose(color, typography, space, listStyle)
);
OrderedList.defaultProps = {
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 0
};

const UnorderedList = styled.ul<CommonTypographyProps & ListStyleProps>(
const UnorderedList = styled.ul.attrs<CommonTypographyProps & ListStyleProps>(
(props) => ({
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 0,
...props
})
)<CommonTypographyProps & ListStyleProps>(
compose(color, typography, space, listStyle)
);
UnorderedList.defaultProps = {
color: 'primary',
fontFamily: 'text',
fontSize: 'text',
textAlign: 'left',
margin: 0
};

const ListItem = styled.li<CommonTypographyProps>(
compose(color, typography, space)
);
ListItem.defaultProps = {
margin: 0
};
const ListItem = styled.li.attrs<CommonTypographyProps>((props) => ({
margin: 0,
...props
}))<CommonTypographyProps>(compose(color, typography, space));

const FitContainer = styled.div`
width: 100%;
Expand All @@ -130,16 +130,14 @@ const FitContainer = styled.div`

const ScalableText = styled(
Text as FC<CommonTypographyProps & RefAttributes<HTMLDivElement>>
)<{ scale: number }>`
).attrs<CommonTypographyProps & { scale?: number }>((props) => ({
textAlign: 'center',
...props
}))<{ scale?: number }>`
transform-origin: center;
transform: scale(${(props) => props.scale});
transform: scale(${(props) => props.scale || 1});
white-space: nowrap;
`;
ScalableText.defaultProps = {
...Text.defaultProps,
textAlign: 'center',
scale: 1
};

const FitText: FC<
PropsWithChildren<CommonTypographyProps & HTMLAttributes<HTMLDivElement>>
Expand Down