Skip to content

Commit

Permalink
Fix index.js issue in published version and update to 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bofeiw committed Dec 4, 2020
1 parent 2df155e commit 89f7f24
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 73 deletions.
64 changes: 1 addition & 63 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minimum-window-size",
"version": "1.1.1",
"version": "1.1.2",
"description": "Minimum Window Size library is a React library that prevents users with small window size from using your React app and visually hints users to adjust window size.",
"keywords": [
"minimum",
Expand All @@ -14,13 +14,9 @@
"hide"
],
"files": [
"src/*",
"README.md",
"package.json",
".babelrc",
".npmignore",
"index.js",
"index.css"
"index.js"
],
"repository": {
"type": "git",
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions src/index.js
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;
8 changes: 4 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const path = require('path');

module.exports = {
mode: 'production',
entry: './index.js',
entry: './src/index.js',
output: {
path: path.resolve('lib'),
path: path.resolve(__dirname),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
Expand All @@ -13,14 +13,14 @@ module.exports = {
{
test: /\.js?$/,
include: [
path.resolve(__dirname)
path.resolve(__dirname, "src")
],
loader: 'babel-loader',
},
{
test: /\.css$/,
include: [
path.resolve(__dirname)
path.resolve(__dirname, "src")
],
use: [
'style-loader',
Expand Down

0 comments on commit 89f7f24

Please sign in to comment.