Skip to content

Commit

Permalink
fix(react-components): replace "shouldForwardProp" for Box and Typogr…
Browse files Browse the repository at this point in the history
…aphy
  • Loading branch information
donskov committed Feb 27, 2024
1 parent 48eeed4 commit 0093523
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/react-components/src/Backdrop/backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ export type BackdropProps = BackdropOwnProps
*
*/

const reactPropsRegex = /^(as|open|invisible|transitionDuration|variant)$/;

/**
* Styles.
*/
const BackdropRoot = styled(Box)<Required<Pick<BackdropOwnProps, 'invisible'>>>((props) => ({
const BackdropRoot = styled(Box, {
shouldForwardProp: (prop) => !reactPropsRegex.test(prop),
})<Required<Pick<BackdropOwnProps, 'invisible'>>>((props) => ({
zIndex: -1,
position: 'fixed',
right: 0,
Expand Down
5 changes: 3 additions & 2 deletions packages/react-components/src/Box/box.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import styled from '@emotion/styled';
import isPropValid from '@emotion/is-prop-valid';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { ColorType } from '../styles';

Expand Down Expand Up @@ -34,11 +33,13 @@ export type BoxProps<
*
*/

const reactPropsRegex = /^(as|background|borderColor|borderWidth|borderStyle|borderPosition|borderRadius)$/;

/**
* Styles.
*/
const BoxRoot = styled('div', {
shouldForwardProp: (prop) => isPropValid(prop),
shouldForwardProp: (prop) => !reactPropsRegex.test(prop),
})<BoxOwnProps>(
(props) => ({
background: props.background && `var(--pv-color-${props.background})`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const LinearProgress = React.forwardRef<HTMLDivElement, LinearProgressPro
(props, ref) => {
const {
color,
variant,
...other
} = props;

Expand Down
4 changes: 3 additions & 1 deletion packages/react-components/src/Skeleton/skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type SkeletonProps<
*
*/

const reactPropsRegex = /^(as|height|width|variant)$/;

/**
* Styles.
*/
Expand All @@ -58,7 +60,7 @@ const pulseKeyframe = keyframes`
`;

const SkeletonRoot = styled(Box, {
shouldForwardProp: (prop) => !['width', 'height'].includes(prop),
shouldForwardProp: (prop) => !reactPropsRegex.test(prop),
})<SkeletonProps>((props) => ({
display: 'block',
height: '1.2em',
Expand Down
5 changes: 3 additions & 2 deletions packages/react-components/src/Typography/typography.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import styled from '@emotion/styled';
import isPropValid from '@emotion/is-prop-valid';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import {
ColorType,
Expand Down Expand Up @@ -45,11 +44,13 @@ export type TypographyProps<
*
*/

const reactPropsRegex = /^(as|color|variant|noWrap)$/;

/**
* Styles.
*/
const TypographyRoot = styled('p', {
shouldForwardProp: (prop) => isPropValid(prop) && prop !== 'color',
shouldForwardProp: (prop) => !reactPropsRegex.test(prop),
})<TypographyOwnProps>((props) => ({
margin: 0,
color: props.color === 'inherit' ? 'inherit' : `var(--pv-color-${props.color})`,
Expand Down

0 comments on commit 0093523

Please sign in to comment.