Skip to content

Commit

Permalink
Fix layout & tooltips on mobile (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlfwong authored Apr 18, 2024
1 parent 785429f commit 9e1bf21
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
7 changes: 6 additions & 1 deletion src/app/views/calculator-app-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const CalculatorAppView: React.FC<{}> = () => {
const welcomeFormHasBeenSubmit = useAtomValue(welcomeFormHasBeenSubmitAtom);

return (
<Container maxW="1600px" minH="100vh" display="flex" padding={0}>
<Container
maxW="1600px"
minH="100vh"
display="flex"
padding={{ base: "10px", md: 0 }}
>
{welcomeFormHasBeenSubmit ? <CalculatorView /> : <WelcomeScreenView />}
</Container>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/calculator-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export const CalculatorView: React.FC = () => {
</FormRow>
<OtherGasAppliancesSelect />
</FormSectionView>,
<EquipmentPurchaseAndInstallFormSectionView key={"equipment"} />,
];

if (columns == null || columns > 1) {
formSections.push(
<EquipmentPurchaseAndInstallFormSectionView key={"equipment"} />,
<UtilityPricesFormSectionView key={"utilityprices"} />,
<ThermostatFormSectionView key={"thermostat"} />
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const InfoCardView: React.FC<InfoCardViewProps & StackProps> = ({
w="full"
bg="white"
borderRadius={"10px"}
p="20px"
p={{ base: "5px", md: "20px" }}
gap={"5px"}
align="start"
{...props}
Expand Down
61 changes: 43 additions & 18 deletions src/app/views/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type FormLabelProps,
HStack,
Text,
useDisclosure,
} from "@chakra-ui/react";
import { Box, Heading, Stack } from "@chakra-ui/react";
import React, { forwardRef, useState } from "react";
Expand All @@ -39,7 +40,7 @@ export const FormSectionView: React.FC<FormSectionViewProps> = (props) => {
}

return (
<Stack as="section" gap={0}>
<Stack as="section" gap={0} w="full">
<Box>
<Heading size="small">{props.title}</Heading>
<hr />
Expand Down Expand Up @@ -80,14 +81,15 @@ interface FormInputProps {
tooltip?: React.ReactNode;
}

export const FormInput = forwardRef<HTMLInputElement, FormInputProps & InputProps>(
({ label, tooltip, ...props }, ref) => (
<FormControl>
<FormLabelWithTooltipOption label={label} tooltip={tooltip} />
<Input {...props} ref={ref} />
</FormControl>
)
);
export const FormInput = forwardRef<
HTMLInputElement,
FormInputProps & InputProps
>(({ label, tooltip, ...props }, ref) => (
<FormControl>
<FormLabelWithTooltipOption label={label} tooltip={tooltip} />
<Input {...props} ref={ref} />
</FormControl>
));
interface FormSelectProps {
label: string;
tooltip?: React.ReactNode;
Expand Down Expand Up @@ -189,15 +191,38 @@ interface InfoTooltipViewProps {
}

export const InfoTooltipView: React.FC<InfoTooltipViewProps> = (props) => {
const { isOpen, onOpen, onClose, onToggle } = useDisclosure();

const isTouchDevice = window.matchMedia(
"(hover: none) and (pointer: coarse)"
).matches;

return (
<Tooltip
hasArrow
label={props.message}
placement="top"
bg="gray.50"
color="black"
>
<QuestionOutlineIcon color={"gray.500"} />
</Tooltip>
<>
<Tooltip
hasArrow
label={props.message}
placement="top"
bg="gray.50"
color="black"
isOpen={isOpen}
>
<QuestionOutlineIcon
color={"gray.500"}
onMouseEnter={onOpen}
onMouseLeave={onClose}
onClick={(ev) => {
if (isTouchDevice) {
onToggle();

// Stop propagation to prevent labels from focusing their associated
// input elements
ev.preventDefault();
ev.stopPropagation();
}
}}
/>
</Tooltip>
</>
);
};
7 changes: 4 additions & 3 deletions src/app/views/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export const HeatPumpBackupFuelSelect: React.FC = () => {
tooltip={
<Stack>
<p>
Canada's cold climate will require your heat pump has a backup heat
source. This is either an electric heating coil or a gas furnace
that's used in conjunction with the heat pump when it's very cold.
Canada's cold climate means your heat pump will typically need a
backup heat source. This is either an electric heating coil or a gas
furnace that's used in conjunction with the heat pump when it's very
cold.
</p>
<p>
For electric backups, smart thermostats will automatically turn on
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/welcome-screen-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const WelcomeFormView: React.FC = () => {
const buildingGeometry = useAtomValue(buildingGeometryAtom);

return (
<Box maxW="1280px" p={"20px"} borderRadius="md">
<Box maxW="1280px" p={{ base: 0, md: "20px" }} borderRadius="md">
<Stack spacing={"20px"}>
<FormSectionView title="About your home">
<FormRow>
Expand Down Expand Up @@ -168,7 +168,7 @@ const WelcomeMessage: React.FC<{}> = () => {
export const WelcomeScreenView: React.FC<{}> = () => {
return (
<Center h="100vh" w="full">
<Flex direction={{ oneColumn: "column", twoColumn: "row" }} gap={"40px"}>
<Flex direction={{ base: "column", md: "row" }} gap={"40px"}>
<Stack>
<Heading textAlign={"center"}>Heat Pump Calculator 🇨🇦</Heading>
<WelcomeFormView />
Expand Down

0 comments on commit 9e1bf21

Please sign in to comment.