refactor(dev-only): add animation to file view search box and fix search bar on mobile
This commit is contained in:
@@ -315,8 +315,12 @@ const ContentListView = forwardRef<HTMLDivElement, Props>(
|
|||||||
itemListController={itemListController}
|
itemListController={itemListController}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!isFilesTableViewEnabled && (
|
{(!isFilesTableViewEnabled || isMobileScreen()) && (
|
||||||
<SearchBar itemListController={itemListController} searchOptionsController={searchOptionsController} />
|
<SearchBar
|
||||||
|
itemListController={itemListController}
|
||||||
|
searchOptionsController={searchOptionsController}
|
||||||
|
hideOptions={shouldShowFilesTableView}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<NoAccountWarning
|
<NoAccountWarning
|
||||||
accountMenuController={accountMenuController}
|
accountMenuController={accountMenuController}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import AddItemMenuButton from './AddItemMenuButton'
|
|||||||
import { FilesController } from '@/Controllers/FilesController'
|
import { FilesController } from '@/Controllers/FilesController'
|
||||||
import SearchButton from './SearchButton'
|
import SearchButton from './SearchButton'
|
||||||
import { ItemListController } from '@/Controllers/ItemList/ItemListController'
|
import { ItemListController } from '@/Controllers/ItemList/ItemListController'
|
||||||
|
import { isMobileScreen } from '@/Utils'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
@@ -105,7 +106,7 @@ const ContentListHeader = ({
|
|||||||
}, [addButtonLabel, addNewItem, filesController, isDailyEntry, isFilesSmartView])
|
}, [addButtonLabel, addNewItem, filesController, isDailyEntry, isFilesSmartView])
|
||||||
|
|
||||||
const SearchBarButton = useMemo(() => {
|
const SearchBarButton = useMemo(() => {
|
||||||
if (!isFilesSmartView || !isFilesTableViewEnabled) {
|
if (!isFilesSmartView || !isFilesTableViewEnabled || isMobileScreen()) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,42 +4,48 @@ import Icon from '@/Components/Icon/Icon'
|
|||||||
import DecoratedInput from '@/Components/Input/DecoratedInput'
|
import DecoratedInput from '@/Components/Input/DecoratedInput'
|
||||||
import { ElementIds } from '@/Constants/ElementIDs'
|
import { ElementIds } from '@/Constants/ElementIDs'
|
||||||
import { ItemListController } from '@/Controllers/ItemList/ItemListController'
|
import { ItemListController } from '@/Controllers/ItemList/ItemListController'
|
||||||
|
import { classNames } from '@standardnotes/snjs'
|
||||||
import { observer } from 'mobx-react-lite'
|
import { observer } from 'mobx-react-lite'
|
||||||
import { useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
itemListController: ItemListController
|
itemListController: ItemListController
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchButton = ({ itemListController }: Props) => {
|
const SearchButton = ({ itemListController }: Props) => {
|
||||||
|
const searchButtonRef = useRef<HTMLButtonElement>(null)
|
||||||
|
|
||||||
const { noteFilterText, setNoteFilterText, clearFilterText } = itemListController
|
const { noteFilterText, setNoteFilterText, clearFilterText } = itemListController
|
||||||
|
|
||||||
const [isSearchBarVisible, setIsSearchBarVisible] = useState(false)
|
const [isSearchBarVisible, setIsSearchBarVisible] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isSearchBarVisible && (
|
<DecoratedInput
|
||||||
<DecoratedInput
|
autocomplete={false}
|
||||||
autocomplete={false}
|
id={ElementIds.SearchBar}
|
||||||
id={ElementIds.SearchBar}
|
className={{
|
||||||
className={{
|
container: classNames(
|
||||||
container: 'px-1',
|
isSearchBarVisible ? 'scale-x-1 opacity-100' : 'scale-x-0 opacity-0',
|
||||||
input: 'text-base placeholder:text-passive-0 lg:text-sm',
|
'origin-right px-1 transition-all duration-200 ease-in-out',
|
||||||
}}
|
),
|
||||||
placeholder={'Search...'}
|
input: 'text-base placeholder:text-passive-0 lg:text-sm',
|
||||||
value={noteFilterText}
|
}}
|
||||||
ref={(node) => {
|
placeholder={'Search...'}
|
||||||
if (node && document.activeElement !== node) {
|
value={noteFilterText}
|
||||||
node.focus()
|
ref={(node) => {
|
||||||
}
|
if (node && document.activeElement !== node) {
|
||||||
}}
|
node.focus()
|
||||||
onChange={(query) => setNoteFilterText(query)}
|
}
|
||||||
left={[<Icon type="search" className="mr-1 h-4.5 w-4.5 flex-shrink-0 text-passive-1" />]}
|
}}
|
||||||
right={[noteFilterText && <ClearInputButton onClick={clearFilterText} />]}
|
onChange={(query) => setNoteFilterText(query)}
|
||||||
roundedFull
|
left={[<Icon type="search" className="mr-1 h-4.5 w-4.5 flex-shrink-0 text-passive-1" />]}
|
||||||
/>
|
right={[noteFilterText && <ClearInputButton onClick={clearFilterText} />]}
|
||||||
)}
|
roundedFull
|
||||||
|
/>
|
||||||
<RoundIconButton
|
<RoundIconButton
|
||||||
|
ref={searchButtonRef}
|
||||||
|
className={isSearchBarVisible ? 'rotate-90 transition-transform duration-200 ease-in-out' : ''}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsSearchBarVisible(!isSearchBarVisible)
|
setIsSearchBarVisible(!isSearchBarVisible)
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ import { ElementIds } from '@/Constants/ElementIDs'
|
|||||||
type Props = {
|
type Props = {
|
||||||
itemListController: ItemListController
|
itemListController: ItemListController
|
||||||
searchOptionsController: SearchOptionsController
|
searchOptionsController: SearchOptionsController
|
||||||
|
hideOptions?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchBar = ({ itemListController, searchOptionsController }: Props) => {
|
const SearchBar = ({ itemListController, searchOptionsController, hideOptions = false }: Props) => {
|
||||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const { noteFilterText, setNoteFilterText, clearFilterText, onFilterEnter } = itemListController
|
const { noteFilterText, setNoteFilterText, clearFilterText, onFilterEnter } = itemListController
|
||||||
@@ -66,7 +67,7 @@ const SearchBar = ({ itemListController, searchOptionsController }: Props) => {
|
|||||||
roundedFull
|
roundedFull
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{(focusedSearch || noteFilterText) && (
|
{(focusedSearch || noteFilterText) && !hideOptions && (
|
||||||
<div className="animate-fade-from-top">
|
<div className="animate-fade-from-top">
|
||||||
<SearchOptions searchOptions={searchOptionsController} />
|
<SearchOptions searchOptions={searchOptionsController} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user