forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from jim-deriv/Jim/74998/contract-card-ts-migr…
…ation Jim/74998/contract card ts migration
- Loading branch information
Showing
35 changed files
with
432 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
...ages/components/src/components/contract-card/contract-card-items/contract-card-dialog.jsx
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
...ages/components/src/components/contract-card/contract-card-items/contract-card-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { CSSTransition } from 'react-transition-group'; | ||
import './sass/contract-card-dialog.scss'; | ||
import { IClickEvent, useOnClickOutside } from '../../../hooks/use-onclickoutside'; | ||
|
||
export type TContractCardDialogProps = { | ||
children: React.ReactNode; | ||
is_visible: boolean; | ||
left: number; | ||
toggleDialog: (e: any) => void; // This function accomodates events for various HTML elements, which have no overlap, so typing it to any | ||
toggle_ref?: React.RefObject<HTMLDivElement>; | ||
top: number; | ||
}; | ||
|
||
const ContractCardDialog = React.forwardRef( | ||
( | ||
{ children, is_visible, left, toggleDialog, toggle_ref, top }: TContractCardDialogProps, | ||
ref: React.ForwardedRef<HTMLDivElement> | ||
) => { | ||
const validateClickOutside = (event: IClickEvent) => | ||
is_visible && !toggle_ref?.current?.contains(event.target as Node); | ||
|
||
useOnClickOutside(ref, toggleDialog, validateClickOutside); | ||
|
||
const dialog = ( | ||
<CSSTransition | ||
in={is_visible} | ||
classNames={{ | ||
enter: 'dc-contract-card-dialog--enter', | ||
enterDone: 'dc-contract-card-dialog--enter-done', | ||
exit: 'dc-contract-card-dialog--exit', | ||
}} | ||
timeout={150} | ||
unmountOnExit | ||
> | ||
<div | ||
ref={ref} | ||
className='dc-contract-card-dialog' | ||
style={{ | ||
top, | ||
left: `calc(${left}px + 32px)`, | ||
}} | ||
> | ||
{children} | ||
</div> | ||
</CSSTransition> | ||
); | ||
const deriv_app_element = document.getElementById('deriv_app'); | ||
return ReactDOM.createPortal( | ||
dialog, // use portal to render dialog above ThemedScrollbars container | ||
deriv_app_element || document.body | ||
); | ||
} | ||
); | ||
|
||
ContractCardDialog.displayName = 'ContractCardDialog'; | ||
|
||
export default ContractCardDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.