-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[components] Work around tsconfig issue
- Loading branch information
1 parent
2abe8fa
commit 573152b
Showing
2 changed files
with
14 additions
and
12 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,19 +1,8 @@ | ||
import {createContext} from 'react' | ||
import {defaultContextValue} from './defaultContextValue' | ||
|
||
export interface PortalContextInterface { | ||
element: HTMLElement | ||
} | ||
|
||
let globalElement: HTMLDivElement | null = null | ||
|
||
const defaultContextValue = { | ||
get element() { | ||
if (globalElement) return globalElement | ||
globalElement = document.createElement('div') | ||
globalElement.setAttribute('data-portal', 'default') | ||
document.body.appendChild(globalElement) | ||
return globalElement | ||
} | ||
} | ||
|
||
export const PortalContext = createContext<PortalContextInterface>(defaultContextValue) |
13 changes: 13 additions & 0 deletions
13
packages/@sanity/components/src/portal/defaultContextValue.js
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,13 @@ | ||
let globalElement = null | ||
|
||
export const defaultContextValue = { | ||
get element() { | ||
if (globalElement) return globalElement | ||
|
||
globalElement = document.createElement('div') | ||
globalElement.setAttribute('data-portal', 'default') | ||
document.body.appendChild(globalElement) | ||
|
||
return globalElement | ||
} | ||
} |