diff --git a/CHANGELOG.md b/CHANGELOG.md index a5185f12..0aff43c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,13 @@ ### Changed - Saving file now uses proper save dialog in Chromium browser ([support#84]). +- Toolbar buttons now scale with screen size ([support#300]). ### Fixed - Fixed buttons wrong size while image is downloading ([support#369]). [support#84]: https://github.com/pybricks/support/issues/84 +[support#300]: https://github.com/pybricks/support/issues/300 [support#369]: https://github.com/pybricks/support/issues/369 ## [1.1.0] - 2021-12-16 diff --git a/public/manifest.json b/public/manifest.json index 17901a91..d3674ffd 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -22,7 +22,6 @@ ], "start_url": ".", "display": "fullscreen", - "orientation": "landscape", "theme_color": "#000000", "background_color": "#ffffff" } diff --git a/src/toolbar/ActionButton.tsx b/src/toolbar/ActionButton.tsx index 58c7f709..9f893e6d 100644 --- a/src/toolbar/ActionButton.tsx +++ b/src/toolbar/ActionButton.tsx @@ -11,11 +11,13 @@ import { } from '@blueprintjs/core'; import { Tooltip2 } from '@blueprintjs/popover2'; import { useI18n } from '@shopify/react-i18n'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { tooltipDelay } from '../app/constants'; import { TooltipId } from './i18n'; import en from './i18n.en.json'; +const smallScreenThreshold = 700; + export interface ActionButtonProps { /** A unique id for each instance. */ readonly id: string; @@ -40,6 +42,20 @@ export interface ActionButtonProps { const ActionButton: React.FC = (props) => { const [i18n] = useI18n({ id: 'actionButton', translations: { en }, fallback: en }); + const [isSmallScreen, setIsSmallScreen] = useState( + window.innerWidth <= smallScreenThreshold, + ); + + useEffect(() => { + const handleResize = () => { + setIsSmallScreen(window.innerWidth <= smallScreenThreshold); + }; + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }); + + const buttonSize = isSmallScreen ? SpinnerSize.SMALL : SpinnerSize.STANDARD; + const tooltipText = props.showProgress && props.progressTooltip ? i18n.translate(props.progressTooltip, { @@ -97,11 +113,15 @@ const ActionButton: React.FC = (props) => { } > {props.showProgress ? ( - + ) : ( {props.id} = (props) => { fallback: en, }); + const [isSmallScreen, setIsSmallScreen] = useState( + window.innerWidth <= smallScreenThreshold, + ); + + useEffect(() => { + const handleResize = () => { + setIsSmallScreen(window.innerWidth <= smallScreenThreshold); + }; + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }); + + const buttonSize = isSmallScreen ? SpinnerSize.SMALL : SpinnerSize.STANDARD; + const { getRootProps, getInputProps } = useDropzone({ accept: props.fileExtension, multiple: false, @@ -113,11 +129,15 @@ const OpenFileButton: React.FC = (props) => { > {props.showProgress ? ( - + ) : (