Skip to content

Commit 2a2d121

Browse files
authored
decouple the resize handle from the vertical divider
1 parent 8ef210f commit 2a2d121

File tree

2 files changed

+65
-44
lines changed

2 files changed

+65
-44
lines changed

src/PageLayout/PageLayout.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ export const ResizablePane: Story = args => (
701701
regular: args['Pane.position.regular'],
702702
wide: args['Pane.position.wide']
703703
}}
704-
divider="line"
705704
canResizePane={true}
706705
paneWidthStorageKey="primer-react.pane-width"
707706
>

src/PageLayout/PageLayout.tsx

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,7 @@ const verticalDividerVariants = {
184184
}
185185
}
186186

187-
const VerticalDivider: React.FC<React.PropsWithChildren<DividerProps>> = ({
188-
variant = 'none',
189-
canResize,
190-
isResizing,
191-
onClick,
192-
onMouseDown,
193-
sx = {}
194-
}) => {
187+
const VerticalDivider: React.FC<React.PropsWithChildren<DividerProps>> = ({variant = 'none', sx = {}}) => {
195188
const responsiveVariant = useResponsiveValue(variant, 'none')
196189
return (
197190
<Box
@@ -203,45 +196,66 @@ const VerticalDivider: React.FC<React.PropsWithChildren<DividerProps>> = ({
203196
},
204197
sx
205198
)}
199+
></Box>
200+
)
201+
}
202+
203+
// ----------------------------------------------------------------------------
204+
// ResizeHandle (internal)
205+
206+
type ResizeHandleProps = {
207+
isResizing: boolean
208+
onClick: (e: React.MouseEvent) => void
209+
onMouseDown: (e: React.MouseEvent) => void
210+
} & SxProp
211+
212+
const ResizeHandle: React.FC<React.PropsWithChildren<ResizeHandleProps>> = ({isResizing, onClick, onMouseDown, sx}) => {
213+
return (
214+
<Box
215+
sx={merge<BetterSystemStyleObject>(
216+
{
217+
height: '100%',
218+
position: 'relative'
219+
},
220+
sx
221+
)}
206222
>
207-
{canResize && (
208-
<Box
209-
onMouseDown={onMouseDown}
210-
onClick={onClick}
211-
sx={{
212-
width: '16px',
213-
height: '100%',
214-
display: 'flex',
215-
justifyContent: 'center',
216-
position: 'absolute',
217-
transform: 'translateX(50%)',
218-
right: 0,
219-
opacity: isResizing ? 1 : 0,
220-
cursor: 'col-resize',
221-
'&:hover': {
222-
animation: isResizing ? 'none' : 'resizer-appear 80ms 300ms both',
223-
224-
'@keyframes resizer-appear': {
225-
from: {
226-
opacity: 0
227-
},
228-
229-
to: {
230-
opacity: 1
231-
}
223+
<Box
224+
onMouseDown={onMouseDown}
225+
onClick={onClick}
226+
sx={{
227+
width: '16px',
228+
height: '100%',
229+
display: 'flex',
230+
justifyContent: 'center',
231+
position: 'absolute',
232+
transform: 'translateX(50%)',
233+
right: 0,
234+
opacity: isResizing ? 1 : 0,
235+
cursor: 'col-resize',
236+
'&:hover': {
237+
animation: isResizing ? 'none' : 'resizer-appear 80ms 300ms both',
238+
239+
'@keyframes resizer-appear': {
240+
from: {
241+
opacity: 0
242+
},
243+
244+
to: {
245+
opacity: 1
232246
}
233247
}
248+
}
249+
}}
250+
>
251+
<Box
252+
sx={{
253+
backgroundColor: 'accent.fg',
254+
width: '1px',
255+
height: '100%'
234256
}}
235-
>
236-
<Box
237-
sx={{
238-
backgroundColor: 'accent.fg',
239-
width: '1px',
240-
height: '100%'
241-
}}
242-
/>
243-
</Box>
244-
)}
257+
/>
258+
</Box>
245259
</Box>
246260
)
247261
}
@@ -567,6 +581,14 @@ const Pane = React.forwardRef<HTMLDivElement, React.PropsWithChildren<PageLayout
567581
onMouseDown={onMouseDown}
568582
sx={{[position === 'end' ? 'marginRight' : 'marginLeft']: SPACING_MAP[columnGap]}}
569583
/>
584+
{canResizePane && (
585+
<ResizeHandle
586+
isResizing={isResizing}
587+
onClick={onClick}
588+
onMouseDown={onMouseDown}
589+
sx={{[position === 'end' ? 'marginRight' : 'marginLeft']: SPACING_MAP[columnGap]}}
590+
/>
591+
)}
570592
<Box
571593
ref={paneRef}
572594
sx={(theme: Theme) => ({

0 commit comments

Comments
 (0)