-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDraggableResizerPanel.tsx
More file actions
67 lines (59 loc) · 1.65 KB
/
DraggableResizerPanel.tsx
File metadata and controls
67 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Libraries
import React, {forwardRef, CSSProperties} from 'react'
import classnames from 'classnames'
// Types
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 */
sizePercent?: number
/** Test ID for Integration Tests */
}
export type DraggableResizerPanelRef = HTMLDivElement
export const DraggableResizerPanel = forwardRef<
DraggableResizerPanelRef,
DraggableResizerPanelProps
>(
(
{
id,
style,
children,
className,
sizePercent,
minSizePixels = 0,
testID = 'draggable-resizer--panel',
},
ref
) => {
const draggableResizerPanelClass = classnames(
'cf-draggable-resizer--panel',
{
[`${className}`]: className,
}
)
const draggableResizerPanelStyle = (): CSSProperties | undefined => {
if (sizePercent) {
return {flex: `${sizePercent} 0 ${minSizePixels}px`, ...style}
}
return style
}
return (
<div
ref={ref}
className={draggableResizerPanelClass}
style={draggableResizerPanelStyle()}
data-testid={testID}
id={id}
>
{children}
</div>
)
}
)
DraggableResizerPanel.displayName = 'DraggableResizerPanel'