-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'protocol_designer-migrate-webpack-to-vite' of https://g…
…ithub.com/Opentrons/opentrons into protocol_designer-migrate-webpack-to-vite
- Loading branch information
Showing
93 changed files
with
2,340 additions
and
2,502 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,19 @@ | ||
import * as React from 'react' | ||
import ReactDom from 'react-dom' | ||
import { Box } from '@opentrons/components' | ||
|
||
// TODO(bc, 2021-02-23): this component should probably be named | ||
// something else for clarity, and may belong better in a | ||
// different directory than app/src/App/ | ||
|
||
type PortalLevel = 'page' | 'top' | ||
|
||
interface Props { | ||
children: React.ReactNode | ||
level: PortalLevel | ||
} | ||
|
||
interface State { | ||
hasRoot: boolean | ||
const TOP_PORTAL_ID = '__otAppTopPortalRoot' | ||
const MODAL_PORTAL_ID = '__otAppModalPortalRoot' | ||
export function getTopPortalEl(): HTMLElement { | ||
return global.document.getElementById(TOP_PORTAL_ID) ?? global.document.body | ||
} | ||
|
||
interface PortalLevelInfo { | ||
id: string | ||
zIndex: number | string | ||
} | ||
|
||
const PORTAL_ROOT_PROPS_BY_LEVEL: Record<PortalLevel, PortalLevelInfo> = { | ||
page: { id: '__otAppModalPortalRoot', zIndex: 1 }, | ||
top: { id: '__otAppTopPortalRoot', zIndex: 10 }, | ||
export function getModalPortalEl(): HTMLElement { | ||
return global.document.getElementById(MODAL_PORTAL_ID) ?? global.document.body | ||
} | ||
|
||
const getPortalRoot = (level: PortalLevel): HTMLElement | null => | ||
(global.document as HTMLDocument).getElementById( | ||
PORTAL_ROOT_PROPS_BY_LEVEL[level].id | ||
) | ||
|
||
export function PortalRoot(): JSX.Element { | ||
return <Box {...PORTAL_ROOT_PROPS_BY_LEVEL.page} /> | ||
return <Box zIndex={1} id={MODAL_PORTAL_ID} /> | ||
} | ||
|
||
export function TopPortalRoot(): JSX.Element { | ||
return <Box {...PORTAL_ROOT_PROPS_BY_LEVEL.top} /> | ||
} | ||
|
||
// the children of Portal are rendered into the PortalRoot if it exists in DOM | ||
export class Portal extends React.Component<Props, State> { | ||
$root: Element | null | undefined | ||
|
||
static defaultProps: { level: PortalLevel } = { | ||
level: 'page', | ||
} | ||
|
||
constructor(props: Props) { | ||
super(props) | ||
this.$root = getPortalRoot(props.level) | ||
this.state = { hasRoot: !!this.$root } | ||
} | ||
|
||
// on first launch, $portalRoot isn't in DOM; double check once we're mounted | ||
// TODO(mc, 2018-10-08): prerender UI instead | ||
componentDidMount(): void { | ||
if (!this.$root) { | ||
this.$root = getPortalRoot(this.props.level) | ||
this.setState({ hasRoot: !!this.$root }) | ||
} | ||
} | ||
|
||
render(): React.ReactPortal | null { | ||
if (!this.$root) return null | ||
return ReactDom.createPortal(this.props.children, this.$root) | ||
} | ||
return <Box zIndex={10} id={TOP_PORTAL_ID} /> | ||
} |
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
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
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.