1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-30 00:14:19 +00:00
pds-2021-g2-nest/nest_frontend/components/base/RequireSize.js

29 lines
1,022 B
JavaScript
Raw Normal View History

import React, { useState } from "react"
import { useWindowSize } from "@react-hook/window-size/throttled"
import Alert from "./Alert"
import useStrings from "../../hooks/useStrings"
import Button from "./Button"
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons"
import makeIcon from "../../utils/makeIcon"
import BodyFlex from "./layout/BodyFlex"
export default function RequireSize({ children, width, height, ...props }) {
const [windowWidth, windowHeight] = useWindowSize()
const [warn, setWarn] = useState(true)
const strings = useStrings()
if(warn && (windowWidth < width || windowHeight < height)) {
return <BodyFlex {...props}>
<Alert color={"Red"}>
{strings.resolutionTooSmall}
</Alert>
<Button color={"Yellow"} onClick={() => setWarn(false)} style={{alignSelf: "center"}}>
{makeIcon(faExclamationTriangle)} {strings.ignore}
</Button>
</BodyFlex>
}
return children
}