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

Commit

Permalink
PopoutBox interface
Browse files Browse the repository at this point in the history
  • Loading branch information
onpaws authored and milesrichardson committed Mar 27, 2021
1 parent 61f3950 commit 829c30c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions tdesign/src/PopoutBox/PopoutBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ export type PopoutAnchorPosition =
PopoutAnchorPositionString
];


export interface IPopoutBoxRef {
toggleOpen: () => void;
}
export interface IPopoutBoxProps {
renderButton: (opts: IRenderPopoutButtonProps) => React.ReactNode;
children?: React.ReactNode;
popoutContainerStyle?: SystemStyleObject;
anchorPosition?: PopoutAnchorPosition;
buttonProps?: any;
parentRef?: React.RefObject<HTMLDivElement>
popoutBoxRef?: React.RefObject<IPopoutBoxRef>;
}

const getAnchorPositionStyle = (
Expand Down Expand Up @@ -92,16 +96,23 @@ const containerStyle = {
position: "relative",
} as SystemStyleObject;

export default ({

const PopoutBox = ({
children,
renderButton,
popoutContainerStyle = {},
anchorPosition,
buttonProps = {},
parentRef
popoutBoxRef
}: IPopoutBoxProps) => {
const [isOpen, setIsOpen] = React.useState(false);
const containerRef = parentRef || React.useRef<HTMLDivElement>(null);
const containerRef = React.useRef<IPopoutBoxRef & HTMLDivElement>(null);

React.useImperativeHandle(popoutBoxRef, () => ({
toggleOpen: () => {
setIsOpen(!isOpen)
}
}));

const anchorPositionStyle = getAnchorPositionStyle(anchorPosition);

Expand Down Expand Up @@ -172,3 +183,5 @@ export default ({
</Box>
);
};

export default PopoutBox;
4 changes: 2 additions & 2 deletions tdesign/src/PopoutBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PopoutBox from './PopoutBox';
import type { IRenderPopoutButtonProps } from './PopoutBox';
import type { IRenderPopoutButtonProps, IPopoutBoxRef } from './PopoutBox';
export { PopoutBox };
export type { IRenderPopoutButtonProps };
export type { IRenderPopoutButtonProps, IPopoutBoxRef };
2 changes: 1 addition & 1 deletion tdesign/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export * from "./Icon";
export { Card } from "./Card";

export { PopoutBox } from "./PopoutBox";
export type { IRenderPopoutButtonProps } from "./PopoutBox";
export type { IRenderPopoutButtonProps, IPopoutBoxRef } from "./PopoutBox";

export { StatusChip } from "./StatusChip";

Expand Down

0 comments on commit 829c30c

Please sign in to comment.