diff --git a/src/components/NavBar/SearchBar.css.ts b/src/components/NavBar/SearchBar.css.ts index 521c1ebc2c..a764befbc3 100644 --- a/src/components/NavBar/SearchBar.css.ts +++ b/src/components/NavBar/SearchBar.css.ts @@ -4,6 +4,7 @@ import { buttonTextSmall, subhead, subheadSmall } from 'nft/css/common.css' import { breakpoints, sprinkles, vars } from '../../nft/css/sprinkles.css' const DESKTOP_NAVBAR_WIDTH = 360 +const MAGNIFYING_GLASS_ICON_WIDTH = 28 const baseSearchStyle = style([ sprinkles({ @@ -31,11 +32,8 @@ export const searchBarContainer = style([ }), { '@media': { - [`screen and (min-width: ${breakpoints.sm}px)`]: { - top: '-24px', - }, [`screen and (min-width: ${breakpoints.lg}px)`]: { - right: `-${DESKTOP_NAVBAR_WIDTH / 2}px`, + right: `-${DESKTOP_NAVBAR_WIDTH / 2 - MAGNIFYING_GLASS_ICON_WIDTH}px`, }, }, }, @@ -44,7 +42,6 @@ export const searchBarContainer = style([ export const searchBar = style([ baseSearchStyle, sprinkles({ - height: 'full', color: 'placeholder', paddingX: '16', cursor: 'pointer', @@ -60,8 +57,11 @@ export const searchBarInput = style([ color: { default: 'blackBlue', placeholder: 'placeholder' }, border: 'none', background: 'none', + width: 'full', }), - { lineHeight: '24px' }, + { + lineHeight: '24px', + }, ]) export const searchBarDropdown = style([ @@ -70,6 +70,7 @@ export const searchBarDropdown = style([ borderBottomLeftRadius: '12', borderBottomRightRadius: '12', background: 'lightGray', + height: { sm: 'viewHeight', md: 'auto' }, }), { borderTop: 'none', @@ -84,7 +85,6 @@ export const suggestionRow = style([ justifyContent: 'space-between', paddingY: '8', paddingX: '16', - transition: '250', }), { ':hover': { @@ -167,3 +167,50 @@ export const notFoundContainer = style([ paddingLeft: '16', }), ]) + +const visibilityTransition = `visibility ${vars.time[125]}, opacity ${vars.time[125]}` +const delayedTransitionProperties = `padding 0s ${vars.time[125]}, height 0s ${vars.time[125]}` + +export const hidden = style([ + sprinkles({ + visibility: 'hidden', + opacity: '0', + padding: '0', + height: '0', + }), + { + transition: `${visibilityTransition}, ${delayedTransitionProperties}`, + transitionTimingFunction: 'ease-in', + }, +]) +export const visible = style([ + sprinkles({ + visibility: 'visible', + opacity: '1', + height: 'full', + }), + { + transition: `${visibilityTransition}`, + transitionTimingFunction: 'ease-out', + }, +]) + +export const searchContentCentered = style({ + '@media': { + [`screen and (min-width: ${breakpoints.lg}px)`]: { + transform: `translateX(${DESKTOP_NAVBAR_WIDTH / 4}px)`, + transition: `transform ${vars.time[125]}`, + transitionTimingFunction: 'ease-out', + }, + }, +}) + +export const searchContentLeftAlign = style({ + '@media': { + [`screen and (min-width: ${breakpoints.lg}px)`]: { + transform: 'translateX(0)', + transition: `transform ${vars.time[125]}`, + transitionTimingFunction: 'ease-in', + }, + }, +}) diff --git a/src/components/NavBar/SearchBar.tsx b/src/components/NavBar/SearchBar.tsx index 3c84f6ad9b..71565b3716 100644 --- a/src/components/NavBar/SearchBar.tsx +++ b/src/components/NavBar/SearchBar.tsx @@ -9,7 +9,7 @@ import { Box } from 'nft/components/Box' import { Column, Row } from 'nft/components/Flex' import { Overlay } from 'nft/components/modals/Overlay' import { magicalGradientOnHover, subheadSmall } from 'nft/css/common.css' -import { useIsMobile, useSearchHistory } from 'nft/hooks' +import { useIsMobile, useIsTablet, useSearchHistory } from 'nft/hooks' import { fetchSearchCollections, fetchTrendingCollections } from 'nft/queries' import { fetchSearchTokens } from 'nft/queries/genie/SearchTokensFetcher' import { fetchTrendingTokens } from 'nft/queries/genie/TrendingTokensFetcher' @@ -273,6 +273,7 @@ export const SearchBar = () => { const { pathname } = useLocation() const phase1Flag = useNftFlag() const isMobile = useIsMobile() + const isTablet = useIsTablet() useOnClickOutside(searchRef, () => { isOpen && toggleOpen() @@ -330,53 +331,56 @@ export const SearchBar = () => { }, [isOpen]) const placeholderText = phase1Flag === NftVariant.Enabled ? t`Search tokens and NFT collections` : t`Search tokens` + const isMobileOrTablet = isMobile || isTablet + const showCenteredSearchContent = !isOpen && phase1Flag !== NftVariant.Enabled && !isMobileOrTablet return ( !isOpen && toggleOpen()} onClick={() => !isOpen && toggleOpen()} gap="12" > - - - - - + + + + + + + ) => { !isOpen && toggleOpen() setSearchValue(event.target.value) }} - className={styles.searchBarInput} + className={`${styles.searchBarInput} ${ + showCenteredSearchContent ? styles.searchContentCentered : styles.searchContentLeftAlign + }`} value={searchValue} ref={inputRef} /> - - - - - - {isOpen && - (debouncedSearchValue.length > 0 && (tokensAreLoading || collectionsAreLoading) ? ( + + {debouncedSearchValue.length > 0 && (tokensAreLoading || collectionsAreLoading) ? ( ) : ( { collections={reducedCollections} hasInput={debouncedSearchValue.length > 0} /> - ))} + )} + + + + {isOpen && } ) diff --git a/src/nft/css/sprinkles.css.ts b/src/nft/css/sprinkles.css.ts index f9bef28450..5910c39c8f 100644 --- a/src/nft/css/sprinkles.css.ts +++ b/src/nft/css/sprinkles.css.ts @@ -209,6 +209,7 @@ export const vars = createGlobalTheme(':root', { black: '900', }, time: { + '125': '125ms', '250': '250ms', '500': '500ms', }, @@ -297,6 +298,7 @@ const layoutStyles = defineProperties({ position: ['absolute', 'fixed', 'relative', 'sticky', 'static'], objectFit: ['contain', 'cover'], order: [0, 1], + opacity: ['auto', '0', '1'], } as const, shorthands: { paddingX: ['paddingLeft', 'paddingRight'], diff --git a/src/nft/hooks/index.ts b/src/nft/hooks/index.ts index 3d8efc1c7b..1c31f817df 100644 --- a/src/nft/hooks/index.ts +++ b/src/nft/hooks/index.ts @@ -3,6 +3,7 @@ export * from './useCollectionFilters' export * from './useFiltersExpanded' export * from './useGenieList' export * from './useIsMobile' +export * from './useIsTablet' export * from './useMarketplaceSelect' export * from './useNFTSelect' export * from './useSearchHistory' diff --git a/src/nft/hooks/useIsMobile.ts b/src/nft/hooks/useIsMobile.ts index 6c2e84a273..1e31414d54 100644 --- a/src/nft/hooks/useIsMobile.ts +++ b/src/nft/hooks/useIsMobile.ts @@ -1,7 +1,7 @@ import { breakpoints } from 'nft/css/sprinkles.css' import { useEffect, useState } from 'react' -const isClient = typeof window === 'object' +const isClient = typeof window !== 'undefined' function getIsMobile() { return isClient ? window.innerWidth < breakpoints.sm : false diff --git a/src/nft/hooks/useIsTablet.ts b/src/nft/hooks/useIsTablet.ts new file mode 100644 index 0000000000..0ed57bed99 --- /dev/null +++ b/src/nft/hooks/useIsTablet.ts @@ -0,0 +1,28 @@ +import { breakpoints } from 'nft/css/sprinkles.css' +import { useEffect, useState } from 'react' + +const isClient = typeof window !== 'undefined' + +function getIsTablet() { + return isClient ? window.innerWidth < breakpoints.lg && window.innerWidth >= breakpoints.sm : false +} + +export function useIsTablet(): boolean { + const [isTablet, setIsTablet] = useState(getIsTablet) + + useEffect(() => { + function handleResize() { + setIsTablet(getIsTablet()) + } + + if (isClient) { + window.addEventListener('resize', handleResize) + return () => { + window.removeEventListener('resize', handleResize) + } + } + return undefined + }, []) + + return isTablet +}