feat: SelectOption

This commit is contained in:
unknown 2021-08-30 15:42:58 +07:00
parent fa46766cf5
commit 38be2e7a7d
5 changed files with 64 additions and 19 deletions

View File

@ -1,18 +1,33 @@
import { Layout } from 'src/components/common'; import { Layout } from 'src/components/common';
import { HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home'; import { HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
import {SelectCommon} from 'src/components/common'
const OPTION_SORT = [
{
name: "By Name"
},
{
name: "Price (High to Low)"
},
{
name: "On Sale"
}
]
export default function Home() { export default function Home() {
return ( return (
<> <>
<HomeBanner /> {/* <HomeBanner />
<HomeFeature /> <HomeFeature />
<HomeCategories /> <HomeCategories />
<HomeCollection /> <HomeCollection />
<HomeVideo /> <HomeVideo />
<HomeCTA /> <HomeCTA />
<HomeRecipe /> <HomeRecipe />
<HomeSubscribe /> <HomeSubscribe /> */}
<SelectCommon option={OPTION_SORT}>Sort By</SelectCommon>
<SelectCommon option={OPTION_SORT} size="large" type="custom">Sort By</SelectCommon>
// todo: uncomment // todo: uncomment
{/* <ModalCreateUserInfo/> */} {/* <ModalCreateUserInfo/> */}

View File

@ -48,15 +48,9 @@
margin-top: 0.6rem; margin-top: 0.6rem;
&.base{ &.base{
width: 20.6rem; width: 20.6rem;
.selectOption{
padding: 1.2rem 1.6rem;
}
} }
&.large{ &.large{
width: 34.25rem; width: 34.25rem;
.selectOption{
padding: 1.6rem 1.6rem;
}
} }
&.default{ &.default{
@apply border-solid border border-current; @apply border-solid border border-current;
@ -69,11 +63,6 @@
&.active{ &.active{
@apply hidden; @apply hidden;
} }
.selectOption{
&:hover{
background-color: var(--background);
}
}
} }

View File

@ -2,6 +2,7 @@ import s from './SelectCommon.module.scss'
import classNames from 'classnames' import classNames from 'classnames'
import { useState, useRef, useEffect } from 'react' import { useState, useRef, useEffect } from 'react'
import { IconVectorDown } from 'src/components/icons' import { IconVectorDown } from 'src/components/icons'
import SelectOption from './SelectOption/SelectOption'
interface Props { interface Props {
children? : React.ReactNode, children? : React.ReactNode,
@ -35,6 +36,9 @@ const SelectCommon = ({ type = 'default', size = 'base', option, children }: Pro
setActive(!isActive) setActive(!isActive)
} }
const changeSelectedName = (item:string) => {
setSelectedName(item)
}
return( return(
<> <>
<div className={classNames({ <div className={classNames({
@ -60,12 +64,7 @@ const SelectCommon = ({ type = 'default', size = 'base', option, children }: Pro
> >
{ {
option.map(item => option.map(item =>
<div className={classNames({ <SelectOption itemName={item.name} onClick={changeSelectedName} size={size} />
[s.selectOption] : true,
[s[size]] : !!size,
})}
onClick = { () => setSelectedName(item.name) }
>{item.name}</div>
) )
} }
</div> </div>

View File

@ -0,0 +1,17 @@
@import "../../../../styles/utilities";
.selectOption {
@apply outline-none;
background-color: var(--white);
&.base{
width: 20.4rem;
padding: 0.8rem 1.6rem;
}
&.large{
width: 33.75rem;
padding: 0.8rem 1.6rem;
}
&:hover{
background-color: var(--gray);
}
}

View File

@ -0,0 +1,25 @@
import s from './SelectOption.module.scss'
import classNames from 'classnames'
interface Props{
onClick: (value: string) => void,
itemName: string,
size: 'base' | 'large',
}
const SelectOption = ({onClick, itemName, size}: Props) => {
const changeName = () => {
onClick(itemName)
}
return(
<div className={classNames({
[s.selectOption] : true,
[s[size]] : !!size,
})}
onClick = {changeName}
>{itemName}</div>
)
}
export default SelectOption