Skip to content

Commit

Permalink
chore: show spinner when loading dynamic data (#389)
Browse files Browse the repository at this point in the history
* chore: show spinner when loading dynamic data

* chore: standardize spinner
  • Loading branch information
pregnantboy authored Jan 8, 2024
1 parent b38d8de commit 9115115
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Controller, useFormContext } from 'react-hook-form'
import { BiRefresh } from 'react-icons/bi'
import Markdown from 'react-markdown'
import { Flex, FormControl } from '@chakra-ui/react'
import { Paper, PaperProps } from '@mui/material'
import { Paper, PaperProps, TextField } from '@mui/material'
import Autocomplete, {
AutocompleteProps,
createFilterOptions,
Expand All @@ -15,6 +15,7 @@ import {
Button,
FormErrorMessage,
FormLabel,
Spinner,
} from '@opengovsg/design-system-react'

interface PaperWithRefreshProps extends PaperProps {
Expand All @@ -35,6 +36,7 @@ function PaperWithRefresh(props: PaperWithRefreshProps): JSX.Element {
onMouseDown={(e) => {
e.preventDefault()
}}
spinner={<Spinner fontSize={24} color="primary.600" />}
onClick={onRefresh}
isLoading={loading}
>
Expand Down Expand Up @@ -145,6 +147,22 @@ function ControlledAutocomplete(
freeSolo={freeSolo}
options={options}
value={getOption(options, field.value, freeSolo)}
renderInput={(params) => (
<TextField
{...params}
InputProps={{
...params.InputProps,
endAdornment: (
<>
{loading && (
<Spinner fontSize={24} color="primary.600" />
)}
{params.InputProps.endAdornment}
</>
),
}}
/>
)}
onChange={(_event, selectedOption) => {
const typedSelectedOption =
selectedOption as IFieldDropdownOption
Expand Down

0 comments on commit 9115115

Please sign in to comment.