From 0c1f0989986238c38d7e85ba7d0b35b5de2abd2f Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Fri, 10 May 2024 14:42:24 +0100 Subject: [PATCH] feat: Inline loading indicator for address lookup --- .../components/FindProperty/Public/index.tsx | 28 +++++++++++++++---- .../components/DelayedLoadingIndicator.tsx | 17 +++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx b/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx index 762391b272..236d5a6df5 100644 --- a/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx +++ b/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx @@ -1,6 +1,7 @@ import { gql } from "@apollo/client"; import Box from "@mui/material/Box"; import Link from "@mui/material/Link"; +import { styled } from "@mui/material/styles"; import Typography from "@mui/material/Typography"; import Card from "@planx/components/shared/Preview/Card"; import QuestionHeader from "@planx/components/shared/Preview/QuestionHeader"; @@ -33,6 +34,18 @@ export const FETCH_BLPU_CODES = gql` type Props = PublicProps; +const AddressLoadingWrap = styled(Box)(({ theme }) => ({ + marginBottom: theme.spacing(-2.5), + minHeight: theme.spacing(3), + pointerEvents: "none", + [theme.breakpoints.up("md")]: { + position: "absolute", + bottom: theme.spacing(1), + margin: 0, + paddingRight: theme.spacing(14), + }, +})); + export default Component; function Component(props: Props) { @@ -185,12 +198,15 @@ function Component(props: Props) { )} - {Boolean(address) && isValidating && ( - - )} + + {Boolean(address) && isValidating && ( + + )} + ); } diff --git a/editor.planx.uk/src/components/DelayedLoadingIndicator.tsx b/editor.planx.uk/src/components/DelayedLoadingIndicator.tsx index d09f68b9f3..22074a899b 100644 --- a/editor.planx.uk/src/components/DelayedLoadingIndicator.tsx +++ b/editor.planx.uk/src/components/DelayedLoadingIndicator.tsx @@ -4,17 +4,27 @@ import { styled } from "@mui/material/styles"; import Typography from "@mui/material/Typography"; import React, { useEffect, useState } from "react"; -const Root = styled(Box)(() => ({ +export interface Props { + inline?: boolean; +} + +const Root = styled(Box, { + shouldForwardProp: (prop) => prop !== "inline", +})(({ inline }) => ({ padding: 60, display: "flex", alignItems: "center", justifyContent: "center", + ...(inline && { + padding: 0, + }), })); const DelayedLoadingIndicator: React.FC<{ msDelayBeforeVisible?: number; text?: string; -}> = ({ msDelayBeforeVisible = 0, text }) => { + inline?: boolean; +}> = ({ msDelayBeforeVisible = 0, text, inline }) => { const [visible, setVisible] = useState(false); useEffect(() => { @@ -30,8 +40,9 @@ const DelayedLoadingIndicator: React.FC<{ aria-busy="true" aria-live="assertive" data-testid="delayed-loading-indicator" + inline={inline} > - + {text ?? "Loading..."}