Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

Commit 829c30c

Browse files
onpawsmilesrichardson
authored andcommitted
PopoutBox interface
1 parent 61f3950 commit 829c30c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

tdesign/src/PopoutBox/PopoutBox.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ export type PopoutAnchorPosition =
2323
PopoutAnchorPositionString
2424
];
2525

26+
27+
export interface IPopoutBoxRef {
28+
toggleOpen: () => void;
29+
}
2630
export 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

3539
const 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;

tdesign/src/PopoutBox/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import PopoutBox from './PopoutBox';
2-
import type { IRenderPopoutButtonProps } from './PopoutBox';
2+
import type { IRenderPopoutButtonProps, IPopoutBoxRef } from './PopoutBox';
33
export { PopoutBox };
4-
export type { IRenderPopoutButtonProps };
4+
export type { IRenderPopoutButtonProps, IPopoutBoxRef };

tdesign/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export * from "./Icon";
3232
export { Card } from "./Card";
3333

3434
export { PopoutBox } from "./PopoutBox";
35-
export type { IRenderPopoutButtonProps } from "./PopoutBox";
35+
export type { IRenderPopoutButtonProps, IPopoutBoxRef } from "./PopoutBox";
3636

3737
export { StatusChip } from "./StatusChip";
3838

0 commit comments

Comments
 (0)