Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ draggableResizerExamplesStories.add(
)

draggableResizerExamplesStories.add(
'4 Panels',
'4 Panels, init rightmost collapsed',
() => {
const [positions, updatePositions] = useState<number[]>([0.25, 0.5, 0.75])

Expand Down Expand Up @@ -252,6 +252,7 @@ draggableResizerExamplesStories.add(
<DraggableResizer.Panel
ref={draggableResizerPanelRef4}
isCollapsible={true}
collapsed={true}
>
<div className="mockCard">
<span>4</span>
Expand All @@ -270,3 +271,83 @@ draggableResizerExamplesStories.add(
},
}
)

draggableResizerExamplesStories.add(
'3 Horizontal Panels, init middle collapsed',
() => {
const [position, updatePosition] = useState<number[]>([0.25, 0.5])
const draggableResizerPanelRef1 = createRef<DraggableResizerPanelRef>()
const draggableResizerPanelRef2 = createRef<DraggableResizerPanelRef>()
const draggableResizerPanelRef3 = createRef<DraggableResizerPanelRef>()
const defaultBackgroundStyle = {backgroundColor: 'transparent'}
const defaultBarStyle = {backgroundColor: '#ffffff'}

const logRef = (): void => {
/* eslint-disable */
console.log(draggableResizerPanelRef1.current)
console.log(draggableResizerPanelRef2.current)
/* eslint-enable */
}

return (
<div className="mockPage padded">
<DraggableResizer
handleOrientation={
Orientation[
select(
'handleOrientation',
mapEnumKeys(Orientation),
'Horizontal'
)
]
}
handleGradient={
Gradients[
Gradients[
select('handleGradient', mapEnumKeys(Gradients), 'PastelGothic')
]
]
}
backgroundStyle={object('backgroundStyle', defaultBackgroundStyle)}
handleBarStyle={object('handleBarStyle', defaultBarStyle)}
handlePositions={position}
onChangePositions={handlePositions => updatePosition(handlePositions)}
>
<DraggableResizer.Panel
ref={draggableResizerPanelRef1}
isCollapsible={true}
>
<div className="mockCard">
<span>1</span>
</div>
</DraggableResizer.Panel>
<DraggableResizer.Panel
ref={draggableResizerPanelRef2}
isCollapsible={true}
collapsed={true}
>
<div className="mockCard">
<span>2</span>
</div>
</DraggableResizer.Panel>
<DraggableResizer.Panel
ref={draggableResizerPanelRef3}
isCollapsible={true}
>
<div className="mockCard">
<span>3</span>
</div>
</DraggableResizer.Panel>
</DraggableResizer>
<div className="story--test-buttons">
<button onClick={logRef}>Log Ref</button>
</div>
</div>
)
},
{
readme: {
content: marked(DraggableResizerExampleAReadme),
},
}
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 2 Panel Stateful Example
# 3 Panel Stateful Example

Here's a stateful example of `DraggableResizer` with 2 panels. Because this example contained in a stateful wrapper the example code in the JSX tab is obscured. Try looking at the State tab to see state changes in real time.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a mismatch in the markdown text versus storybook fixture.
2 versus 3

Screen Shot 2022-11-08 at 1 54 57 PM

Here's a stateful example of `DraggableResizer` with 3 panels. Because this example contained in a stateful wrapper the example code in the JSX tab is obscured. Try looking at the State tab to see state changes in real time.

### Usage
```tsx
Expand Down
5 changes: 5 additions & 0 deletions src/Components/DraggableResizer/DraggableResizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,21 @@ export const DraggableResizerRoot: FunctionComponent<DraggableResizerProps> = ({
const dragging = i === dragIndex

const isCollapsibleToLower = child.props.isCollapsible
const collapsedLower = child.props.collapsed
const isCollapsibleToUpper =
!isLastPanel && children && children[i + 1].props.isCollapsible
const collapsedUpper =
!isLastPanel && children && children[i + 1].props.collapsed

return (
<>
{cloneElement(child, {sizePercent: calculatePanelSize(i)})}
{!isLastPanel && (
<DraggableResizerHandle
isCollapsibleToLower={isCollapsibleToLower}
collapsedLower={collapsedLower}
isCollapsibleToUpper={isCollapsibleToUpper}
collapsedUpper={collapsedUpper}
onCollapseButtonClick={onCollapseButtonClick}
dragIndex={i}
onStartDrag={handleStartDrag}
Expand Down
25 changes: 22 additions & 3 deletions src/Components/DraggableResizer/DraggableResizerHandle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Libraries
import React, {forwardRef, CSSProperties, useState} from 'react'
import React, {forwardRef, CSSProperties, useState, useEffect} from 'react'
import classnames from 'classnames'

// Components
Expand All @@ -19,8 +19,12 @@ import {getColorsFromGradient} from '../../Utils/colors'
export interface DraggableResizerHandleProps extends StandardFunctionProps {
/** Enables a 0.0 direction (Left/Up) Collapse button */
isCollapsibleToLower?: boolean
/** Collapsed state observed from parent */
collapsedLower?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only an initial state that can be overriden by the collapse buttons? as in, when this prop is provided, can the user then override the collapse state by pressing the collapse buttons?

Copy link
Author

@wiedld wiedld Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly. See the video.

And the parent can still pass a prop too. Such that the parent can ask for the panel to collapse. e.g. when we are in SQL editing, and want to collapse certain panels, and reopen as needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would initialCollapsedLower be a better prop name to communicate that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's both the initial, and any change based from the parent.

Use case:

  1. Qx builder is rendered
  2. user is editing flux. panel is init on expanded.
  3. user switches to SQL. which does not re-mount the panel. Instead, we pass a prop changing collapse={true}.
  4. panel collapses.

I also just thought of another use case. Let me make changes, and will ping you back once that's done.

/** Enables a 1.0 direction (Right/Down) Collapse Button */
isCollapsibleToUpper?: boolean
/** Collapsed state observed from parent */
collapsedUpper?: boolean
/** Function that updates panel positions after collapsing */
onCollapseButtonClick: (direction: number, dragIndex: number) => void
/** Gets passed a function by being a child of DraggableResizer */
Expand Down Expand Up @@ -52,7 +56,9 @@ export const DraggableResizerHandle = forwardRef<
className,
orientation,
isCollapsibleToLower = false,
collapsedLower = false,
isCollapsibleToUpper = false,
collapsedUpper = false,
onCollapseButtonClick,
dragging = false,
dragIndex = 9999,
Expand All @@ -63,8 +69,21 @@ export const DraggableResizerHandle = forwardRef<
},
ref
) => {
const [collapsibleLower, setCollapsibleLower] = useState<boolean>(false)
const [collapsibleUpper, setCollapsibleUpper] = useState<boolean>(false)
const [collapsibleLower, setCollapsibleLower] = useState<boolean>(
collapsedLower
)
const [collapsibleUpper, setCollapsibleUpper] = useState<boolean>(
collapsedUpper
)

useEffect(() => {
if (isCollapsibleToLower && collapsedLower) {
onCollapseButtonClick(0, dragIndex)
}
if (isCollapsibleToUpper && collapsedUpper) {
onCollapseButtonClick(1, dragIndex)
}
}, [ref, collapsedLower, collapsedUpper])

const handleMouseDown = (): void => {
onStartDrag(dragIndex)
Expand Down
2 changes: 2 additions & 0 deletions src/Components/DraggableResizer/DraggableResizerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {StandardFunctionProps} from '../../Types'
export interface DraggableResizerPanelProps extends StandardFunctionProps {
/** Checks if the current panel is collapsible or not */
isCollapsible?: boolean
/** Collapse state, consumed on component mounting and prop change from parent */
collapsed?: boolean
/** Panel will not shrink past this size (experimental, not guaranteed to work) */
minSizePixels?: number
/** Does not have a value initially, gets passed a value by being a child of DraggableResizer */
Expand Down