diff --git a/packages/web/components/templates/library/LibrarySearchBar.tsx b/packages/web/components/templates/library/LibrarySearchBar.tsx index feaa2dde6..a0f243dd2 100644 --- a/packages/web/components/templates/library/LibrarySearchBar.tsx +++ b/packages/web/components/templates/library/LibrarySearchBar.tsx @@ -1,102 +1,215 @@ +import { useState, useEffect } from 'react' +import { Clock, Sliders, X } from 'phosphor-react' +import Downshift from 'downshift' + import { HStack, SpanBox, VStack } from './../../elements/LayoutPrimitives' -import { useState } from 'react' import { FormInput } from '../../elements/FormElements' import { Button } from '../../elements/Button' -import { Sliders, SlidersHorizontal, X } from 'phosphor-react' -import { theme } from '../../tokens/stitches.config' +import { styled, theme } from '../../tokens/stitches.config' import { SearchCoordinator } from './LibraryContainer' +// Styles +const List = styled('ul', { + width: '91%', + maxHeight: '400px', + overflow: 'auto', + top: '65px', + left: '-32px', + color: 'var(--colors-utilityTextDefault)', + backgroundColor: 'var(--colors-grayBase)', + position: 'absolute', + zIndex: '2', + '@smDown': { + fontSize: 16, + }, +}) + +const Item = styled('li', { + listStyleType: 'none', + m: '8px', + borderRadius: '5px', + width: '100%', +}) + export type LibrarySearchBarProps = { coordinator: SearchCoordinator } export function LibrarySearchBar(props: LibrarySearchBarProps): JSX.Element { - const [searchTerm, setSearchTerm] = useState('') + const [recentSearches, setRecentSearches] = useState(Array<[]>()) + + useEffect(() => { + setRecentSearches(Object.values(localStorage)) + }, []) return ( - <> - - -
{ - event.preventDefault() - // props.applySearchQuery(searchTerm || '') - // inputRef.current?.blur() - }} + (item ? item : '')}> + {({ + getInputProps, + getRootProps, + getMenuProps, + getItemProps, + isOpen, + highlightedIndex, + inputValue, + clearSelection, + openMenu, + }) => ( + + - { - setSearchTerm(event.target.value) - }} - /> - - {!searchTerm && ( - - )} - {searchTerm && ( - - - + {/* {searchTerm && ( */} + + + + + {/* )} */} + {/* {!searchTerm && ( */} + + {/* )} */} + + + + {isOpen && + recentSearches + .filter((item) => !inputValue || item.includes(inputValue)) + .map((item, index) => ( + + + + {item} + + { + localStorage.removeItem(`${item}`) + setRecentSearches(Object.values(localStorage)) + }} + /> + + ))} + + - )} - - - +
+ )} + ) -} \ No newline at end of file +} diff --git a/packages/web/package.json b/packages/web/package.json index 4c18caea8..3610ecbf3 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -32,6 +32,7 @@ "color2k": "^2.0.0", "cookie": "^0.5.0", "diff-match-patch": "^1.0.5", + "downshift": "^6.1.9", "graphql-request": "^3.6.1", "kbar": "^0.1.0-beta.35", "nanoid": "^3.1.29", diff --git a/packages/web/styles/menu.css b/packages/web/styles/menu.css index 6d03b1491..f860a896a 100644 --- a/packages/web/styles/menu.css +++ b/packages/web/styles/menu.css @@ -1,5 +1,7 @@ /* Menu Override styles */ - +.pro-sidebar { + z-index: 1; +} .pro-sidebar > .pro-sidebar-inner, .pro-menu, .pro-menu > ul > .pro-sub-menu > .pro-inner-list-item, diff --git a/yarn.lock b/yarn.lock index b76eae9d8..36102cecd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12596,6 +12596,17 @@ downshift@^6.0.15: react-is "^17.0.2" tslib "^2.3.0" +downshift@^6.1.9: + version "6.1.12" + resolved "https://registry.yarnpkg.com/downshift/-/downshift-6.1.12.tgz#f14476b41a6f6fd080c340bad1ddf449f7143f6f" + integrity sha512-7XB/iaSJVS4T8wGFT3WRXmSF1UlBHAA40DshZtkrIscIN+VC+Lh363skLxFTvJwtNgHxAMDGEHT4xsyQFWL+UA== + dependencies: + "@babel/runtime" "^7.14.8" + compute-scroll-into-view "^1.0.17" + prop-types "^15.7.2" + react-is "^17.0.2" + tslib "^2.3.0" + dset@^3.1.0, dset@^3.1.1, dset@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.2.tgz#89c436ca6450398396dc6538ea00abc0c54cd45a"