forked from myke-roly/capsEcommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
239 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ COPY . . | |
# production | ||
RUN npm run build | ||
|
||
CMD [ "npm", "start"] | ||
CMD [ "npm", "start", "build"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
import React, { | ||
useState, | ||
useContext, | ||
useEffect, | ||
useRef, | ||
useLayoutEffect, | ||
} from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { FaSearch } from 'react-icons/fa'; | ||
import { Search, ChevronRight } from 'react-feather'; | ||
import { SearchWrapper, ResultSearch, ModalSearch } from './styled'; | ||
import { ContextSearch } from '../../context/SearchContext'; | ||
import Link from 'next/link'; | ||
|
||
const Buscador = () => { | ||
const [searchON, setSearchOn] = useState(false); | ||
const [textSearch, setTextSearch] = useState(''); | ||
const inputRef = useRef(); | ||
|
||
const contextSearch = useContext(ContextSearch); | ||
const { results, getResultsSearch } = contextSearch; | ||
|
||
const router = useRouter(); | ||
|
||
useLayoutEffect(() => { | ||
if (textSearch.length < 1) { | ||
getResultsSearch(null); | ||
} else { | ||
getResultsSearch(textSearch); | ||
} | ||
}, [textSearch]); | ||
|
||
const handleChange = (e) => { | ||
const text = e.target.value; | ||
setTextSearch(text); | ||
}; | ||
|
||
const handleKeyPress = (e) => { | ||
if (e.key === 'Enter' && textSearch) { | ||
router.push(`/search?query=${textSearch}`); | ||
} | ||
}; | ||
|
||
const handleBlur = () => { | ||
setSearchOn(false); | ||
setTextSearch(''); | ||
}; | ||
|
||
return ( | ||
<> | ||
<SearchWrapper> | ||
<label htmlFor="search" onClick={() => setSearchOn(!searchON)}> | ||
<Search size={18} /> | ||
</label> | ||
{searchON && ( | ||
<input | ||
ref={inputRef} | ||
type="text" | ||
id="search" | ||
placeholder="Buscar..." | ||
value={textSearch} | ||
onChange={handleChange} | ||
onKeyPress={handleKeyPress} | ||
onBlur={handleBlur} | ||
/> | ||
)} | ||
</SearchWrapper> | ||
{results && ( | ||
<ResultSearch> | ||
{results && results.map(result => ( | ||
<Link href={`/producto/[id]/`} as={`/producto/${result._id}`} key={result._id}> | ||
<a><ChevronRight size={15} />{result.title}</a> | ||
</Link> | ||
))} | ||
</ResultSearch> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Buscador; |
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,56 @@ | ||
import styled, { keyframes } from 'styled-components'; | ||
|
||
const animateSearch = keyframes` | ||
from {width: 0;} | ||
to {width: auto;} | ||
`; | ||
const animateSearchResults = keyframes` | ||
from {height: 0;} | ||
to {height: auto;} | ||
`; | ||
|
||
export const SearchWrapper = styled.div` | ||
position: relative; | ||
input { | ||
display: inline-block; | ||
width: 250px; | ||
padding: 0.2rem 0.5rem; | ||
border: none; | ||
background: transparent; | ||
font-size: 0.7em; | ||
border: 2px solid ${({ theme }) => theme.color.default}; | ||
animation: ${animateSearch} 0.5s ease; | ||
border-radius: 50px; | ||
} | ||
label { | ||
position: relative; | ||
right: 0; | ||
top: 0.35rem; | ||
} | ||
`; | ||
|
||
export const ResultSearch = styled.section` | ||
position: fixed; | ||
top: 3rem; | ||
left: 0; | ||
width: 100%; | ||
height: auto; | ||
background: ${({ theme }) => theme.color.gray}; | ||
animation: ${animateSearchResults} .5s ease; | ||
a { | ||
display: block; | ||
font-weight: 400; | ||
font-size: .8em; | ||
text-align: center; | ||
text-transform: uppercase; | ||
padding: .6rem 0; | ||
color: ${({ theme }) => theme.color.dark}; | ||
&:hover { | ||
background: ${({ theme }) => theme.color.primary}; | ||
} | ||
} | ||
`; |
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.