-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add search input to chain, bridges and exchanges pages (#305)
- Loading branch information
Showing
24 changed files
with
500 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { styled } from '@mui/material'; | ||
import type { PageContainerProps } from './PageContainer.js'; | ||
import { PageContainer } from './PageContainer.js'; | ||
|
||
// In max height and default layout | ||
// the PageContainer collapses to use the minimum space need to display its child components whereas | ||
// the FullPageContainer expands and fills the available vertical space provide by the max-height | ||
// See the CssBaselineContainer component styles in AppContainer.tsx for usage of full-page-container | ||
export const FullPageContainer = styled((props: PageContainerProps) => ( | ||
<PageContainer | ||
{...props} | ||
className={`${props.className} full-page-container`} | ||
/> | ||
))``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/widget/src/components/Search/SearchInput.style.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Box, List, styled } from '@mui/material'; | ||
import { Input as InputBase } from '../../components/Input.js'; | ||
|
||
export const Input = styled(InputBase)(({ theme }) => ({ | ||
paddingRight: theme.spacing(1.5), | ||
})); | ||
|
||
interface SearchStickyContainerProps { | ||
headerHeight: number; | ||
} | ||
|
||
export const searchContainerHeight = 64; | ||
|
||
// When the widget is in Full Height layout mode in order to appear "sticky the StickySearchInputContainer needs to use | ||
// position fixed in the same way as the header (see Header.tsx). The headerHeight value here is used as the top value | ||
// to ensure that this container positioned correctly beneath the header | ||
export const StickySearchInputContainer = styled(Box, { | ||
shouldForwardProp: (prop) => prop !== 'headerHeight', | ||
})<SearchStickyContainerProps>(({ theme, headerHeight }) => ({ | ||
position: 'sticky', | ||
top: headerHeight, | ||
zIndex: 1, | ||
height: searchContainerHeight, | ||
paddingBottom: theme.spacing(2), | ||
paddingLeft: theme.spacing(3), | ||
paddingRight: theme.spacing(3), | ||
backgroundColor: theme.palette.background.default, | ||
...(theme.header?.position === 'fixed' | ||
? { | ||
position: 'fixed', | ||
minWidth: theme.breakpoints.values.xs, | ||
maxWidth: theme.breakpoints.values.sm, | ||
width: '100%', | ||
} | ||
: {}), | ||
})); | ||
|
||
// When in Full Height layout mode, as the StickySearchInputContainer (see above) uses fixed position, the list element needs to provide | ||
// additional paddingTop in order to be positioned correctly. | ||
export const SearchList = styled(List)(({ theme }) => ({ | ||
paddingTop: | ||
theme.header?.position === 'fixed' ? `${searchContainerHeight}px` : 0, | ||
paddingLeft: theme.spacing(1.5), | ||
paddingRight: theme.spacing(1.5), | ||
paddingBottom: theme.spacing(1.5), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Search } from '@mui/icons-material'; | ||
import { FormControl, InputAdornment } from '@mui/material'; | ||
import type { FocusEventHandler, FormEventHandler } from 'react'; | ||
import { InputCard } from '../../components/Card/InputCard.js'; | ||
import { useHeaderHeight } from '../../stores/header/useHeaderStore.js'; | ||
import { Input, StickySearchInputContainer } from './SearchInput.style.js'; | ||
|
||
interface SearchInputProps { | ||
name?: string; | ||
value?: string; | ||
placeholder?: string; | ||
onChange?: FormEventHandler<HTMLInputElement>; | ||
onBlur?: FocusEventHandler<HTMLInputElement>; | ||
} | ||
|
||
export const SearchInput = ({ | ||
name, | ||
placeholder, | ||
onChange, | ||
onBlur, | ||
value, | ||
}: SearchInputProps) => { | ||
return ( | ||
<InputCard> | ||
<FormControl fullWidth> | ||
<Input | ||
size="small" | ||
placeholder={placeholder} | ||
endAdornment={ | ||
<InputAdornment position="end"> | ||
<Search /> | ||
</InputAdornment> | ||
} | ||
inputProps={{ | ||
inputMode: 'search', | ||
onChange, | ||
onBlur, | ||
name, | ||
value, | ||
maxLength: 128, | ||
}} | ||
autoComplete="off" | ||
/> | ||
</FormControl> | ||
</InputCard> | ||
); | ||
}; | ||
|
||
export const StickySearchInput = ({ ...rest }: SearchInputProps) => { | ||
const { headerHeight } = useHeaderHeight(); | ||
|
||
return ( | ||
<StickySearchInputContainer headerHeight={headerHeight}> | ||
<SearchInput {...rest} /> | ||
</StickySearchInputContainer> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/widget/src/components/Search/SearchNotFound.style.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { BoxProps } from '@mui/material'; | ||
import { Box, styled, Typography } from '@mui/material'; | ||
import { searchContainerHeight } from './SearchInput.style.js'; | ||
|
||
interface NotFoundContainerProps extends BoxProps { | ||
adjustForStickySearchInput?: boolean; | ||
} | ||
|
||
export const NotFoundContainer = styled(Box, { | ||
shouldForwardProp: (prop) => prop !== 'adjustForStickySearchInput', | ||
})<NotFoundContainerProps>(({ theme, adjustForStickySearchInput }) => ({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
flex: 1, | ||
padding: theme.spacing(3), | ||
...(adjustForStickySearchInput && theme.header?.position === 'fixed' | ||
? { paddingTop: `calc(${searchContainerHeight}px + ${theme.spacing(3)})` } | ||
: {}), | ||
})); | ||
|
||
export const NotFoundMessage = styled(Typography)(({ theme }) => ({ | ||
fontSize: 14, | ||
color: theme.palette.text.secondary, | ||
textAlign: 'center', | ||
flex: 1, | ||
marginTop: theme.spacing(2), | ||
paddingLeft: theme.spacing(2), | ||
paddingRight: theme.spacing(2), | ||
})); | ||
|
||
export const NotFoundIconContainer = styled(Typography)(({ theme }) => ({ | ||
fontSize: 48, | ||
lineHeight: 1, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { SearchOff } from '@mui/icons-material'; | ||
import { | ||
NotFoundContainer, | ||
NotFoundIconContainer, | ||
NotFoundMessage, | ||
} from './SearchNotFound.style.js'; | ||
|
||
interface SearchNotFoundProps { | ||
message: string; | ||
adjustForStickySearchInput?: boolean; | ||
} | ||
|
||
export const SearchNotFound = ({ | ||
message, | ||
adjustForStickySearchInput, | ||
}: SearchNotFoundProps) => ( | ||
<NotFoundContainer adjustForStickySearchInput={adjustForStickySearchInput}> | ||
<NotFoundIconContainer> | ||
<SearchOff fontSize="inherit" /> | ||
</NotFoundIconContainer> | ||
<NotFoundMessage>{message}</NotFoundMessage> | ||
</NotFoundContainer> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.