|
@ -7,18 +7,22 @@ import {useSandpack} from '@codesandbox/sandpack-react'; |
|
|
import {IconArrowSmall} from '../../Icon/IconArrowSmall'; |
|
|
import {IconArrowSmall} from '../../Icon/IconArrowSmall'; |
|
|
export interface DownloadButtonProps {} |
|
|
export interface DownloadButtonProps {} |
|
|
|
|
|
|
|
|
|
|
|
let initialIsSupported = false; |
|
|
|
|
|
|
|
|
export const DownloadButton: React.FC<DownloadButtonProps> = () => { |
|
|
export const DownloadButton: React.FC<DownloadButtonProps> = () => { |
|
|
const {sandpack} = useSandpack(); |
|
|
const {sandpack} = useSandpack(); |
|
|
const [supported, setSupported] = React.useState(false); |
|
|
const [supported, setSupported] = React.useState(initialIsSupported); |
|
|
React.useEffect(() => { |
|
|
React.useEffect(() => { |
|
|
// This detection will work in Chrome 97+
|
|
|
// This detection will work in Chrome 97+
|
|
|
if ( |
|
|
if ( |
|
|
|
|
|
!supported && |
|
|
(HTMLScriptElement as any).supports && |
|
|
(HTMLScriptElement as any).supports && |
|
|
(HTMLScriptElement as any).supports('importmap') |
|
|
(HTMLScriptElement as any).supports('importmap') |
|
|
) { |
|
|
) { |
|
|
setSupported(true); |
|
|
setSupported(true); |
|
|
|
|
|
initialIsSupported = true; |
|
|
} |
|
|
} |
|
|
}, []); |
|
|
}, [supported]); |
|
|
|
|
|
|
|
|
if (!supported) { |
|
|
if (!supported) { |
|
|
return null; |
|
|
return null; |
|
|