Skip to content

Commit 87b25f4

Browse files
authored
ref(react19): Remove various styled defaultProps (#83409)
1 parent 4c54823 commit 87b25f4

22 files changed

+166
-200
lines changed

static/app/components/alerts/toastIndicator.tsx

+8-20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ function ToastIndicator({indicator, onDismiss, className, ...props}: Props) {
4343
onClick={handleClick}
4444
data-test-id={type ? `toast-${type}` : 'toast'}
4545
className={classNames(className, 'ref-toast', `ref-${type}`)}
46+
initial={{opacity: 0, y: 70}}
47+
animate={{opacity: 1, y: 0}}
48+
exit={{opacity: 0, y: 70}}
49+
transition={testableTransition({
50+
type: 'spring',
51+
stiffness: 450,
52+
damping: 25,
53+
})}
4654
{...props}
4755
>
4856
{type === 'loading' ? (
@@ -74,26 +82,6 @@ const Toast = styled(motion.div)`
7482
position: relative;
7583
`;
7684

77-
Toast.defaultProps = {
78-
initial: {
79-
opacity: 0,
80-
y: 70,
81-
},
82-
animate: {
83-
opacity: 1,
84-
y: 0,
85-
},
86-
exit: {
87-
opacity: 0,
88-
y: 70,
89-
},
90-
transition: testableTransition({
91-
type: 'spring',
92-
stiffness: 450,
93-
damping: 25,
94-
}),
95-
};
96-
9785
const Icon = styled('div', {shouldForwardProp: p => p !== 'type'})<{type: string}>`
9886
margin-right: ${space(0.75)};
9987
svg {

static/app/components/banner.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,17 @@ function Banner({
5959
return (
6060
<BannerWrapper backgroundImg={backgroundImg} className={className}>
6161
{backgroundComponent}
62-
{isDismissable ? <CloseButton onClick={dismiss} aria-label={t('Close')} /> : null}
62+
{isDismissable ? (
63+
<CloseButton
64+
type="button"
65+
borderless
66+
size="xs"
67+
priority="link"
68+
icon={<IconClose />}
69+
onClick={dismiss}
70+
aria-label={t('Close')}
71+
/>
72+
) : null}
6373
<BannerContent>
6474
<BannerTitle>{title}</BannerTitle>
6575
<BannerSubtitle>{subtitle}</BannerSubtitle>
@@ -139,12 +149,4 @@ const CloseButton = styled(Button)`
139149
z-index: 1;
140150
`;
141151

142-
CloseButton.defaultProps = {
143-
icon: <IconClose />,
144-
['aria-label']: t('Close'),
145-
priority: 'link',
146-
borderless: true,
147-
size: 'xs',
148-
};
149-
150152
export default Banner;

static/app/components/charts/loadingPanel.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import styled from '@emotion/styled';
33
import LoadingMask from 'sentry/components/loadingMask';
44

55
interface Props extends React.HTMLAttributes<HTMLDivElement> {
6+
/**
7+
* @default '200px'
8+
*/
69
height?: string;
710
}
811

@@ -14,14 +17,10 @@ const LoadingPanel = styled(({height: _height, ...props}: Props) => (
1417
flex: 1;
1518
flex-shrink: 0;
1619
overflow: hidden;
17-
height: ${p => p.height};
20+
height: ${p => p.height ?? '200px'};
1821
position: relative;
1922
border-color: transparent;
2023
margin-bottom: 0;
2124
`;
2225

23-
LoadingPanel.defaultProps = {
24-
height: '200px',
25-
};
26-
2726
export default LoadingPanel;

static/app/components/checkInTimeline/timelineZoom.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,22 @@ function useTimelineZoom<E extends HTMLElement>({enabled = true, onSelect}: Opti
146146
}, [enabled, handleMouseMove, handleMouseDown, handleMouseUp]);
147147

148148
const timelineSelector = (
149-
<AnimatePresence>{isActive && <Selection role="presentation" />}</AnimatePresence>
149+
<AnimatePresence>
150+
{isActive && (
151+
<Selection
152+
role="presentation"
153+
initial="initial"
154+
animate="animate"
155+
exit="exit"
156+
transition={testableTransition({duration: 0.2})}
157+
variants={{
158+
initial: {opacity: 0},
159+
animate: {opacity: 1},
160+
exit: {opacity: 0},
161+
}}
162+
/>
163+
)}
164+
</AnimatePresence>
150165
);
151166

152167
return {selectionContainerRef: containerRef, isActive, timelineSelector};
@@ -165,16 +180,4 @@ const Selection = styled(motion.div)`
165180
z-index: 2;
166181
`;
167182

168-
Selection.defaultProps = {
169-
initial: 'initial',
170-
animate: 'animate',
171-
exit: 'exit',
172-
transition: testableTransition({duration: 0.2}),
173-
variants: {
174-
initial: {opacity: 0},
175-
animate: {opacity: 1},
176-
exit: {opacity: 0},
177-
},
178-
};
179-
180183
export {useTimelineZoom};

static/app/components/circleIndicator.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@ import styled from '@emotion/styled';
22

33
type Props = {
44
color?: string;
5+
/**
6+
* @default true
7+
*/
58
enabled?: boolean;
9+
/**
10+
* @default 14
11+
*/
612
size?: number;
713
};
814

15+
const defaultProps = {
16+
enabled: true,
17+
size: 14,
18+
};
19+
920
const CircleIndicator = styled('div')<Props>`
1021
display: inline-block;
1122
position: relative;
1223
border-radius: 50%;
13-
height: ${p => p.size}px;
14-
width: ${p => p.size}px;
15-
background: ${p => p.color ?? (p.enabled ? p.theme.success : p.theme.error)};
24+
height: ${p => p.size ?? defaultProps.size}px;
25+
width: ${p => p.size ?? defaultProps.size}px;
26+
background: ${p =>
27+
p.color ?? (p.enabled ?? defaultProps.enabled ? p.theme.success : p.theme.error)};
1628
`;
1729

18-
CircleIndicator.defaultProps = {
19-
enabled: true,
20-
size: 14,
21-
};
22-
2330
export default CircleIndicator;

static/app/components/globalModal/index.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,19 @@ function GlobalModal({onClose}: Props) {
233233
>
234234
<AnimatePresence>
235235
{visible && (
236-
<Modal role="dialog" aria-modal css={options.modalCss}>
236+
<Modal
237+
role="dialog"
238+
aria-modal
239+
css={options.modalCss}
240+
initial={{opacity: 0, y: -10}}
241+
animate={{opacity: 1, y: 0}}
242+
exit={{opacity: 0, y: 15}}
243+
transition={testableTransition({
244+
type: 'spring',
245+
stiffness: 450,
246+
damping: 25,
247+
})}
248+
>
237249
<Content role="document">{renderedChild}</Content>
238250
</Modal>
239251
)}
@@ -285,16 +297,6 @@ const Modal = styled(motion.div)`
285297
}
286298
`;
287299

288-
Modal.defaultProps = {
289-
initial: {opacity: 0, y: -10},
290-
animate: {opacity: 1, y: 0},
291-
exit: {opacity: 0, y: 15},
292-
transition: testableTransition({
293-
opacity: {duration: 0.2},
294-
y: {duration: 0.25},
295-
}),
296-
};
297-
298300
const Content = styled('div')`
299301
background: ${p => p.theme.background};
300302
border-radius: ${p => p.theme.modalBorderRadius};

static/app/components/highlightModalContainer.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ import BottomLeft from 'sentry-images/pattern/highlight-bottom-left.svg';
55
import TopRight from 'sentry-images/pattern/highlight-top-right.svg';
66

77
type Props = {
8-
bottomWidth: string;
98
children: React.ReactNode;
10-
topWidth: string;
9+
/**
10+
* @default '200px'
11+
*/
12+
bottomWidth?: string;
13+
/**
14+
* @default '400px'
15+
*/
16+
topWidth?: string;
1117
};
1218

1319
export default function HighlightModalContainer({
14-
topWidth,
15-
bottomWidth,
20+
topWidth = '400px',
21+
bottomWidth = '200px',
1622
children,
1723
}: Props) {
1824
return (
@@ -41,8 +47,3 @@ const PositionBottomLeft = styled('img')<{width: string}>`
4147
pointer-events: none;
4248
border-radius: 0 0 0 ${p => p.theme.modalBorderRadius};
4349
`;
44-
45-
HighlightModalContainer.defaultProps = {
46-
topWidth: '400px',
47-
bottomWidth: '200px',
48-
};

static/app/components/interactionStateLayer.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ interface StateLayerProps extends React.HTMLAttributes<HTMLSpanElement> {
1010
/**
1111
* Controls if the opacity is increased when the element is in a
1212
* selected or expanded state (aria-selected='true' or aria-expanded='true')
13+
*
14+
* @default true
1315
*/
1416
hasSelectedBackground?: boolean;
1517
higherOpacity?: boolean;
1618
isHovered?: boolean;
1719
isPressed?: boolean;
1820
}
1921

22+
const defaultProps = {
23+
hasSelectedBackground: true,
24+
};
25+
2026
const InteractionStateLayer = styled(
2127
(props: StateLayerProps) => {
2228
// Prevent type checking of `rest` as it has hundreds of properties and is slow
@@ -74,7 +80,7 @@ const InteractionStateLayer = styled(
7480
*:active > && {
7581
opacity: ${p.higherOpacity ? 0.12 : 0.09};
7682
}
77-
${p.hasSelectedBackground &&
83+
${(p.hasSelectedBackground ?? defaultProps.hasSelectedBackground) &&
7884
css`
7985
*[aria-expanded='true'] > &&,
8086
*[aria-selected='true'] > && {
@@ -90,8 +96,4 @@ const InteractionStateLayer = styled(
9096
}
9197
`;
9298

93-
InteractionStateLayer.defaultProps = {
94-
hasSelectedBackground: true,
95-
};
96-
9799
export default InteractionStateLayer;

static/app/components/letterAvatar.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ const LetterAvatar = styled(
106106
${imageStyle};
107107
`;
108108

109-
LetterAvatar.defaultProps = {
110-
round: false,
111-
};
112-
113109
export default forwardRef<SVGSVGElement, Props>((props, ref) => (
114110
<LetterAvatar forwardedRef={ref} {...props} />
115111
));

static/app/components/pageOverlay.tsx

+13-18
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,21 @@ const subItemAnimation = {
3232
},
3333
};
3434

35-
const Header = styled(motion.h2)`
35+
const Header = styled((props: React.ComponentProps<typeof motion.h2>) => (
36+
<motion.h2 variants={subItemAnimation} transition={testableTransition()} {...props} />
37+
))`
3638
display: flex;
3739
align-items: center;
3840
font-weight: ${p => p.theme.fontWeightNormal};
3941
margin-bottom: ${space(1)};
4042
`;
4143

42-
Header.defaultProps = {
43-
variants: subItemAnimation,
44-
transition: testableTransition(),
45-
};
46-
47-
const Body = styled(motion.div)`
44+
const Body = styled((props: React.ComponentProps<typeof motion.div>) => (
45+
<motion.div variants={subItemAnimation} transition={testableTransition()} {...props} />
46+
))`
4847
margin-bottom: ${space(2)};
4948
`;
5049

51-
Body.defaultProps = {
52-
variants: subItemAnimation,
53-
transition: testableTransition(),
54-
};
55-
5650
type ContentOpts = {
5751
Body: typeof Body;
5852
Header: typeof Header;
@@ -206,7 +200,13 @@ function PageOverlay({
206200
return (
207201
<MaskedContent {...props}>
208202
{children}
209-
<ContentWrapper ref={contentRef} transition={transition} variants={{animate: {}}}>
203+
<ContentWrapper
204+
initial="initial"
205+
animate="animate"
206+
ref={contentRef}
207+
transition={transition}
208+
variants={{animate: {}}}
209+
>
210210
{BackgroundComponent && (
211211
<Background>
212212
<BackgroundComponent anchorRef={anchorRef} />
@@ -234,11 +234,6 @@ const ContentWrapper = styled(motion.div)`
234234
z-index: 900;
235235
`;
236236

237-
ContentWrapper.defaultProps = {
238-
initial: 'initial',
239-
animate: 'animate',
240-
};
241-
242237
const Background = styled('div')`
243238
${absoluteFull}
244239
z-index: -1;

static/app/components/platformPicker.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,6 @@ const ClearButton = styled(Button)`
286286
color: ${p => p.theme.textColor};
287287
`;
288288

289-
ClearButton.defaultProps = {
290-
icon: <IconClose isCircled />,
291-
borderless: true,
292-
size: 'xs',
293-
};
294-
295289
const PlatformCard = styled(({platform, selected, onClear, ...props}) => (
296290
<div {...props}>
297291
<StyledPlatformIcon
@@ -302,7 +296,15 @@ const PlatformCard = styled(({platform, selected, onClear, ...props}) => (
302296
format="lg"
303297
/>
304298
<h3>{platform.name}</h3>
305-
{selected && <ClearButton onClick={onClear} aria-label={t('Clear')} />}
299+
{selected && (
300+
<ClearButton
301+
icon={<IconClose isCircled />}
302+
borderless
303+
size="xs"
304+
onClick={onClear}
305+
aria-label={t('Clear')}
306+
/>
307+
)}
306308
</div>
307309
))`
308310
position: relative;

0 commit comments

Comments
 (0)