-
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.
Added and styled search type selector, added the logic of setting search params
- Loading branch information
1 parent
901b2bf
commit 852443e
Showing
13 changed files
with
260 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const PageTitle = styled.h2` | ||
font-weight: 600; | ||
font-size: 28px; | ||
@media screen and (min-width: 768px) { | ||
font-size: 32px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
font-size: 44px; | ||
} | ||
`; |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { FC } from 'react'; | ||
import { IMainTitleProps } from './mainTitleTypes'; | ||
import { PageTitle } from './MainTitle.styled'; | ||
|
||
const MainTitle: FC<IMainTitleProps> = ({ title }) => { | ||
return <h2>{title}</h2>; | ||
return <PageTitle>{title}</PageTitle>; | ||
}; | ||
|
||
export default MainTitle; |
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
export {}; | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 24px; | ||
margin-top: 50px; | ||
`; |
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
120 changes: 119 additions & 1 deletion
120
src/components/Search/SearchTypeSelector/SearchTypeSelector.styled.tsx
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 |
---|---|---|
@@ -1 +1,119 @@ | ||
export {}; | ||
import styled from 'styled-components'; | ||
import { FaAngleDown } from 'react-icons/fa6'; | ||
|
||
interface SelectProps { | ||
$theme: string; | ||
} | ||
|
||
export const SelectWrap = styled.div` | ||
display: flex; | ||
align-items: center; | ||
gap: 15px; | ||
@media screen and (min-width: 768px) { | ||
gap: 32px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
gap: 18px; | ||
} | ||
`; | ||
|
||
export const SelectName = styled.p` | ||
font-weight: 500; | ||
font-size: 12px; | ||
line-height: 133%; | ||
@media screen and (min-width: 768px) { | ||
font-size: 14px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
font-size: 18px; | ||
} | ||
`; | ||
|
||
export const Select = styled.div<SelectProps>` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 146px; | ||
height: 34px; | ||
border: ${({ $theme }) => | ||
$theme === 'light' ? 'none' : '1px solid var(--heroInput)'}; | ||
background-color: ${({ $theme }) => | ||
$theme === 'light' ? '#d9d9d928' : 'transparent'}; | ||
color: ${({ $theme }) => ($theme === 'light' ? '#23262a80' : '#fafafa7f')}; | ||
border-radius: 6px; | ||
padding: 8px 14px; | ||
font-size: 12px; | ||
@media screen and (min-width: 768px) { | ||
width: 175px; | ||
height: 41px; | ||
font-size: 14px; | ||
padding: 10px 14px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
width: 198px; | ||
height: 49px; | ||
padding: 14px; | ||
} | ||
`; | ||
|
||
export const SelectContainer = styled.div` | ||
position: relative; | ||
`; | ||
|
||
export const Options = styled.ul` | ||
position: absolute; | ||
top: 100%; | ||
left: 0; | ||
width: 100%; | ||
background-color: var(--selectBg); | ||
border-radius: 6px; | ||
font-size: 12px; | ||
padding: 8px 14px; | ||
@media screen and (min-width: 768px) { | ||
font-size: 14px; | ||
padding: 10px 14px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
padding: 14px; | ||
} | ||
`; | ||
|
||
export const Option = styled.li` | ||
display: flex; | ||
align-items: center; | ||
height: 23px; | ||
opacity: 0.5; | ||
transition: all 200ms ease-in-out; | ||
&:hover { | ||
opacity: 1; | ||
} | ||
@media screen and (min-width: 768px) { | ||
height: 27px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
height: 25px; | ||
} | ||
`; | ||
|
||
export const ArrowDown = styled(FaAngleDown)` | ||
color: var(--accentGreen); | ||
width: 14px; | ||
@media screen and (min-width: 768px) { | ||
width: 20px; | ||
} | ||
@media screen and (min-width: 1440px) { | ||
} | ||
`; |
59 changes: 57 additions & 2 deletions
59
src/components/Search/SearchTypeSelector/SearchTypeSelector.tsx
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 |
---|---|---|
@@ -1,7 +1,62 @@ | ||
import { FC } from 'react'; | ||
import { FC, useState } from 'react'; | ||
import { | ||
ArrowDown, | ||
Option, | ||
Options, | ||
Select, | ||
SelectContainer, | ||
SelectName, | ||
SelectWrap, | ||
} from './SearchTypeSelector.styled'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { updateSearchTypeAction } from '../../../redux/search/slice'; | ||
import { selectSearchType } from '../../../redux/search/selectors'; | ||
import useTheme from 'hooks/useTheme'; | ||
|
||
const SearchTypeSelector: FC = () => { | ||
return <div></div>; | ||
const dispatch = useDispatch(); | ||
const searchType = useSelector(selectSearchType); | ||
const { theme } = useTheme(); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const onSearchTypeChange = (event: React.MouseEvent<HTMLLIElement>) => { | ||
const value = event.currentTarget.dataset.value; | ||
|
||
dispatch(updateSearchTypeAction(value)); | ||
closeDropdown(); | ||
}; | ||
|
||
const openDropdown = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
const closeDropdown = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<SelectWrap> | ||
<SelectName>Search by:</SelectName> | ||
<SelectContainer> | ||
<Select onClick={openDropdown} $theme={theme}> | ||
{searchType === 'query' ? 'Title' : 'Ingredients'} | ||
<ArrowDown /> | ||
</Select> | ||
|
||
{isOpen && ( | ||
<Options> | ||
<Option data-value="query" onClick={onSearchTypeChange}> | ||
Title | ||
</Option> | ||
<Option data-value="ingredient" onClick={onSearchTypeChange}> | ||
Ingredients | ||
</Option> | ||
</Options> | ||
)} | ||
</SelectContainer> | ||
</SelectWrap> | ||
); | ||
}; | ||
|
||
export default SearchTypeSelector; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { RootState } from 'redux/store'; | ||
|
||
export const selectSearchQuery = (state: RootState) => state.search.searchQuery; | ||
|
||
export const selectSearchType = (state: RootState) => state.search.searchType; |
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,28 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export interface SearchState { | ||
searchQuery: string; | ||
searchType: 'query' | 'ingredient'; | ||
} | ||
|
||
const searchInitialState: SearchState = { | ||
searchQuery: '', | ||
searchType: 'query', | ||
}; | ||
|
||
const searchSlice = createSlice({ | ||
name: 'search', | ||
initialState: searchInitialState, | ||
reducers: { | ||
updateSearchQueryAction(state, action) { | ||
state.searchQuery = action.payload; | ||
}, | ||
updateSearchTypeAction(state, action) { | ||
state.searchType = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { updateSearchQueryAction, updateSearchTypeAction } = | ||
searchSlice.actions; | ||
export const searchReducer = searchSlice.reducer; |
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