generated from Groftware/template-reactnpm
-
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.
Fix index.js issue in published version and update to 1.0.2
- Loading branch information
Showing
5 changed files
with
70 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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,63 @@ | ||
// This component also requires 'react', | ||
// but it has already been included in the | ||
// list of dependencies in package.json | ||
import React, {useEffect, useRef, useState} from 'react'; | ||
|
||
import './index.css'; | ||
|
||
function Index({width, height, ...props}) { | ||
const [shouldHide, setShouldHide] = useState(true); | ||
const requiredBox = useRef(null); | ||
const currentBox = useRef(null); | ||
|
||
useEffect(() => { | ||
onScreenResize(); | ||
window.addEventListener('resize', onScreenResize); | ||
}) | ||
|
||
function onScreenResize() { | ||
// update hidden status | ||
console.log(window.innerWidth, window.innerHeight) | ||
if (window.innerWidth && window.innerWidth < width) { | ||
setShouldHide(true) | ||
} else if (window.innerHeight && window.innerHeight < height) { | ||
setShouldHide(true) | ||
} else { | ||
setShouldHide(false) | ||
return; | ||
} | ||
|
||
// update present box | ||
let requiredWidth = 300; | ||
let requiredHeight = Math.floor(requiredWidth * height / width); | ||
requiredBox.current.style.height = `${requiredHeight}px`; | ||
requiredBox.current.style.width = `${requiredWidth}px`; | ||
|
||
let currentWidth = 300 * window.innerWidth / width; | ||
let currentHeight = requiredHeight * window.innerHeight / height; | ||
currentBox.current.style.height = `${currentHeight}px`; | ||
currentBox.current.style.width = `${currentWidth}px`; | ||
} | ||
|
||
return ( | ||
<div className="minimum-window-size-container"> | ||
<div className={"minimum-window-size-hide-content"} hidden={!shouldHide}> | ||
<div className={"minimum-window-size-caption"}>Adjust browser size</div> | ||
<div className={"minimum-window-size-sub-caption"}>This app requires a larger screen size</div> | ||
<div className={"minimum-window-size-present-container"}> | ||
<div className={"minimum-window-size-caption-required"}>Required size</div> | ||
<div className={"minimum-window-size-box-required"} ref={requiredBox}> | ||
<div className={"minimum-window-size-box-current"} ref={currentBox}> | ||
<div className={"minimum-window-size-caption-current"}>Browser size</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className={"minimum-window-size-real-content"} hidden={shouldHide}> | ||
{props.children} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Index; |
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