From 8f2c595eca30e2d7138c8e8d6685774a8f44e55d Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 15 Feb 2018 16:59:58 -0500 Subject: omg --- frontend/components/Search.js | 81 ++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 27 deletions(-) (limited to 'frontend/components/Search.js') diff --git a/frontend/components/Search.js b/frontend/components/Search.js index 0ce136e..33017dd 100644 --- a/frontend/components/Search.js +++ b/frontend/components/Search.js @@ -1,9 +1,9 @@ import Downshift from 'downshift'; -import { SEARCH_ITEMS_QUERY } from '../queries'; import { graphql, compose } from 'react-apollo'; -import makeImage from '../lib/image'; -import { Router } from '../routes'; import slugify from 'slugify'; +import styled from 'styled-components'; +import { SEARCH_ITEMS_QUERY } from '../queries'; +import { Router } from '../routes'; function routeToItem(item) { Router.pushRoute('item', { @@ -12,38 +12,62 @@ function routeToItem(item) { }); } -function BasicAutocomplete(props) { +const DropDown = styled.div` + position: absolute; + width: 100%; + z-index: 2; + border: 1px solid ${props => props.theme.lightgrey}; + input { + border: 0; + } +`; + +const DropDownItem = styled.div` + border-bottom: 1px solid ${props => props.theme.lightgrey}; + background: ${props => (props.highlighted ? '#f7f7f7' : 'white')}; + padding: 1rem; + transition: all 0.2s; + ${props => (props.highlighted ? 'padding-left: 2rem;' : null)}; + display: flex; + align-items: center; + border-left: 10px solid ${props => (props.highlighted ? props.theme.lightgrey : 'white')}; + img { + margin-right: 10px; + } +`; + +const SearchStyles = styled.div` + position: relative; +`; + +function AutoComplete(props) { const { items, onChange } = props; return ( - item.title}> + (i === null ? '' : i.title)}> {({ getInputProps, getItemProps, isOpen, inputValue, selectedItem, highlightedIndex }) => (
+ {/* This is the searchInput */} props.refetch({ searchTerm: e.target.value }), - style: { fontSize: '20px', padding: '20px', display: 'block', width: '100%' }, + id: 'search', + onChange: e => { + console.log('Change happened'); + props.refetch({ searchTerm: e.target.value }); + }, + style: { fontSize: '20px', padding: '10px', display: 'block', width: '100%' }, })} /> {isOpen ? ( -
+ + {/* This is the Dropdown */} {items.map((item, index) => ( -
- {item.title} + + {item.title} {item.title} -
+ ))} -
+ ) : null}
)} @@ -52,16 +76,19 @@ function BasicAutocomplete(props) { } const Search = props => ( - console.log(selectedItem)} - refetch={props.searchItems.refetch} - /> + + console.log(selectedItem)} + refetch={props.searchItems.refetch} + /> + ); const searchEnhancer = graphql(SEARCH_ITEMS_QUERY, { name: 'searchItems', options: { + // TODO: Why is this camo variables: { searchTerm: 'camo' }, }, }); -- cgit v1.3