This repository was archived by the owner on Mar 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed
Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -23,13 +23,17 @@ export type PopoutAnchorPosition =
2323 PopoutAnchorPositionString
2424 ] ;
2525
26+
27+ export interface IPopoutBoxRef {
28+ toggleOpen : ( ) => void ;
29+ }
2630export interface IPopoutBoxProps {
2731 renderButton : ( opts : IRenderPopoutButtonProps ) => React . ReactNode ;
2832 children ?: React . ReactNode ;
2933 popoutContainerStyle ?: SystemStyleObject ;
3034 anchorPosition ?: PopoutAnchorPosition ;
3135 buttonProps ?: any ;
32- parentRef ?: React . RefObject < HTMLDivElement >
36+ popoutBoxRef ?: React . RefObject < IPopoutBoxRef > ;
3337}
3438
3539const getAnchorPositionStyle = (
@@ -92,16 +96,23 @@ const containerStyle = {
9296 position : "relative" ,
9397} as SystemStyleObject ;
9498
95- export default ( {
99+
100+ const PopoutBox = ( {
96101 children,
97102 renderButton,
98103 popoutContainerStyle = { } ,
99104 anchorPosition,
100105 buttonProps = { } ,
101- parentRef
106+ popoutBoxRef
102107} : IPopoutBoxProps ) => {
103108 const [ isOpen , setIsOpen ] = React . useState ( false ) ;
104- const containerRef = parentRef || React . useRef < HTMLDivElement > ( null ) ;
109+ const containerRef = React . useRef < IPopoutBoxRef & HTMLDivElement > ( null ) ;
110+
111+ React . useImperativeHandle ( popoutBoxRef , ( ) => ( {
112+ toggleOpen : ( ) => {
113+ setIsOpen ( ! isOpen )
114+ }
115+ } ) ) ;
105116
106117 const anchorPositionStyle = getAnchorPositionStyle ( anchorPosition ) ;
107118
@@ -172,3 +183,5 @@ export default ({
172183 </ Box >
173184 ) ;
174185} ;
186+
187+ export default PopoutBox ;
Original file line number Diff line number Diff line change 11import PopoutBox from './PopoutBox' ;
2- import type { IRenderPopoutButtonProps } from './PopoutBox' ;
2+ import type { IRenderPopoutButtonProps , IPopoutBoxRef } from './PopoutBox' ;
33export { PopoutBox } ;
4- export type { IRenderPopoutButtonProps } ;
4+ export type { IRenderPopoutButtonProps , IPopoutBoxRef } ;
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ export * from "./Icon";
3232export { Card } from "./Card" ;
3333
3434export { PopoutBox } from "./PopoutBox" ;
35- export type { IRenderPopoutButtonProps } from "./PopoutBox" ;
35+ export type { IRenderPopoutButtonProps , IPopoutBoxRef } from "./PopoutBox" ;
3636
3737export { StatusChip } from "./StatusChip" ;
3838
You can’t perform that action at this time.
0 commit comments