Skip to content

Commit a82d6c3

Browse files
authored
ref(ui): Rename SlideOverPanel's strange props (#104163)
Confusing! The brain doesn't like negatives. Instead, `isOpen` which is more common in the codebase. Also, `slidePosition` to `position`, a little simpler.
1 parent eb9d001 commit a82d6c3

File tree

7 files changed

+30
-34
lines changed

7 files changed

+30
-34
lines changed

static/app/components/core/slideOverPanel/slideOverPanel.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The `SlideOverPanel` component is a panel that can appear on the right, left, or
3030
```jsx
3131
<Button onClick={() => setIsPanelOpen(true)}>Open Panel</Button>
3232

33-
<SlideOverPanel collapsed={!isPanelOpen} slidePosition="right">
33+
<SlideOverPanel open={isPanelOpen} position="right">
3434
<Container border="primary" height="100%" padding="md">
3535
<Button onClick={() => setIsPanelOpen(false)}>Close Panel</Button>
3636
</Container>
@@ -59,7 +59,7 @@ To enable a loading skeleton, pass a render prop as the children to `SlideOverPa
5959
```jsx
6060
<Button onClick={() => setIsPanelOpen(true)}>Open Panel</Button>
6161

62-
<SlideOverPanel collapsed={!isPanelOpen} slidePosition="right">
62+
<SlideOverPanel open={isPanelOpen} ePosition="right">
6363
{({isOpening}) => isOpening ? <Placeholder /> :
6464
<Container border="primary" height="100%" padding="md">
6565
<Button onClick={() => setIsPanelOpen(false)}>Close Panel</Button>

static/app/components/core/slideOverPanel/slideOverPanel.tsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type SlideOverPanelProps = {
3333
/**
3434
* Whether the panel is visible. In most cases it's better to use this prop rather than render the panel conditionally, since it'll defer rendering the contents of the panel to a lower priority React lane.
3535
*/
36-
collapsed: boolean;
36+
open: boolean;
3737
ariaLabel?: string;
3838
className?: string;
3939
'data-test-id'?: string;
@@ -42,8 +42,8 @@ type SlideOverPanelProps = {
4242
*/
4343
onOpen?: () => void;
4444
panelWidth?: string;
45+
position?: 'right' | 'bottom' | 'left';
4546
ref?: React.Ref<HTMLDivElement>;
46-
slidePosition?: 'right' | 'bottom' | 'left';
4747
/**
4848
* A Framer Motion `Transition` object that specifies the transition properties that apply when the panel opens and closes.
4949
*/
@@ -53,23 +53,21 @@ type SlideOverPanelProps = {
5353
export function SlideOverPanel({
5454
'data-test-id': testId,
5555
ariaLabel,
56-
collapsed,
56+
open: isOpen,
5757
children,
5858
className,
5959
onOpen,
60-
slidePosition,
60+
position,
6161
transitionProps = {},
6262
panelWidth,
6363
ref,
6464
}: SlideOverPanelProps) {
6565
const theme = useTheme();
6666

67-
const isOpen = !collapsed;
68-
6967
// Create a deferred version of `isOpen`. Here's how the rendering flow works
7068
// when the visibility changes to `true`:
7169
//
72-
// 1. Parent component sets `collapsed` to `false`. This triggers a render.
70+
// 1. Parent component sets `isOpen` to `true`. This triggers a render.
7371
// 2. The render runs with `isOpen` `true` and `isContentVisible` `false`. We
7472
// pass `isOpening: true` to the `children` render prop. The render prop
7573
// contents should render a fast skeleton.
@@ -83,10 +81,10 @@ export function SlideOverPanel({
8381
const isContentVisible = useDeferredValue(isOpen);
8482

8583
useEffect(() => {
86-
if (!collapsed && onOpen) {
84+
if (isOpen && onOpen) {
8785
onOpen();
8886
}
89-
}, [collapsed, onOpen]);
87+
}, [isOpen, onOpen]);
9088

9189
// Create a fallback render function, in case the parent component passes
9290
// `React.ReactNode` as `children`. This way, even if they don't pass a render
@@ -102,25 +100,23 @@ export function SlideOverPanel({
102100
isOpening: isOpen !== isContentVisible && !isContentVisible,
103101
};
104102

105-
const openStyle = slidePosition ? OPEN_STYLES[slidePosition] : OPEN_STYLES.right;
103+
const openStyle = position ? OPEN_STYLES[position] : OPEN_STYLES.right;
106104

107-
const collapsedStyle = slidePosition
108-
? COLLAPSED_STYLES[slidePosition]
109-
: COLLAPSED_STYLES.right;
105+
const collapsedStyle = position ? COLLAPSED_STYLES[position] : COLLAPSED_STYLES.right;
110106

111107
return isOpen ? (
112108
<_SlideOverPanel
113109
ref={ref}
114110
initial={collapsedStyle}
115111
animate={openStyle}
116112
exit={collapsedStyle}
117-
slidePosition={slidePosition}
113+
position={position}
118114
transition={{
119115
...theme.motion.framer.spring.moderate,
120116
...transitionProps,
121117
}}
122118
role="complementary"
123-
aria-hidden={collapsed}
119+
aria-hidden={!isOpen}
124120
aria-label={ariaLabel ?? 'slide out drawer'}
125121
className={className}
126122
data-test-id={testId}
@@ -140,17 +136,17 @@ export function SlideOverPanel({
140136
const _SlideOverPanel = styled(motion.div, {
141137
shouldForwardProp: prop =>
142138
['initial', 'animate', 'exit', 'transition'].includes(prop) ||
143-
(prop !== 'collapsed' && isPropValid(prop)),
139+
(prop !== 'isOpen' && isPropValid(prop)),
144140
})<{
145141
panelWidth?: string;
146-
slidePosition?: 'right' | 'bottom' | 'left';
142+
position?: 'right' | 'bottom' | 'left';
147143
}>`
148144
position: fixed;
149145
150-
top: ${p => (p.slidePosition === 'left' ? '54px' : space(2))};
151-
right: ${p => (p.slidePosition === 'left' ? space(2) : 0)};
146+
top: ${p => (p.position === 'left' ? '54px' : space(2))};
147+
right: ${p => (p.position === 'left' ? space(2) : 0)};
152148
bottom: ${space(2)};
153-
left: ${p => (p.slidePosition === 'left' ? 0 : space(2))};
149+
left: ${p => (p.position === 'left' ? 0 : space(2))};
154150
155151
overflow: auto;
156152
pointer-events: auto;
@@ -166,7 +162,7 @@ const _SlideOverPanel = styled(motion.div, {
166162
167163
@media (min-width: ${p => p.theme.breakpoints.sm}) {
168164
${p =>
169-
p.slidePosition === 'bottom'
165+
p.position === 'bottom'
170166
? css`
171167
position: sticky;
172168
@@ -177,7 +173,7 @@ const _SlideOverPanel = styled(motion.div, {
177173
bottom: 0;
178174
left: 0;
179175
`
180-
: p.slidePosition === 'right'
176+
: p.position === 'right'
181177
? css`
182178
position: fixed;
183179

static/app/components/globalDrawer/components.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function DrawerPanel({
7474
<DrawerWidthContext.Provider value={actualDrawerWidth}>
7575
<DrawerSlidePanel
7676
ariaLabel={ariaLabel}
77-
slidePosition="right"
78-
collapsed={false}
77+
position="right"
78+
open
7979
ref={mergeRefs(panelRef, ref)}
8080
transitionProps={transitionProps}
8181
panelWidth="var(--drawer-width)" // Initial width only

static/app/stories/playground/slideOverPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function SlideOverPanelPlayground() {
1414
<Fragment>
1515
<Button onClick={() => setIsPanelOpen(true)}>Open Panel</Button>
1616

17-
<SlideOverPanel collapsed={!isPanelOpen} slidePosition="right">
17+
<SlideOverPanel open={isPanelOpen} position="right">
1818
<Container border="primary" height="100%" padding="md">
1919
<Button onClick={() => setIsPanelOpen(false)}>Close Panel</Button>
2020
</Container>
@@ -34,7 +34,7 @@ export function SlideOverPanelSkeletonPlayground() {
3434
<Fragment>
3535
<Button onClick={() => setIsPanelOpen(true)}>Open Panel</Button>
3636

37-
<SlideOverPanel collapsed={!isPanelOpen} slidePosition="right">
37+
<SlideOverPanel open={isPanelOpen} position="right">
3838
{(options: {isOpening: boolean}) => {
3939
return options.isOpening ? (
4040
<SkeletonPanelContents onClick={closePanel} />

static/app/views/dashboards/widgetBuilder/components/widgetBuilderSlideout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ function WidgetBuilderSlideout({
209209

210210
return (
211211
<SlideOverPanel
212-
collapsed={false}
213-
slidePosition="left"
212+
open
213+
position="left"
214214
data-test-id="widget-slideout"
215215
transitionProps={animationTransitionSettings}
216216
>

static/app/views/preprod/buildDetails/main/insights/appSizeInsightsSidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ export function AppSizeInsightsSidebar({
9595
)}
9696
</AnimatePresence>
9797
<SlideOverPanel
98-
collapsed={!isOpen}
99-
slidePosition="right"
98+
open={isOpen}
99+
position="right"
100100
panelWidth={`${constrainedWidth}px`}
101101
ariaLabel={t('App size insights details')}
102102
>

static/app/views/prevent/preventAI/manageReposPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function ManageReposPanel({
110110

111111
return (
112112
<SlideOverPanel
113-
collapsed={collapsed}
114-
slidePosition="right"
113+
open={!collapsed}
114+
position="right"
115115
ariaLabel="Settings Panel"
116116
data-test-id="manage-repos-panel"
117117
>

0 commit comments

Comments
 (0)