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

@@ -48,15 +48,9 @@
margin-top: 0.6rem;
&.base{
width: 20.6rem;
.selectOption{
padding: 1.2rem 1.6rem;
}
}
&.large{
width: 34.25rem;
.selectOption{
padding: 1.6rem 1.6rem;
}
}
&.default{
@apply border-solid border border-current;
@@ -69,11 +63,6 @@
&.active{
@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 { useState, useRef, useEffect } from 'react'
import { IconVectorDown } from 'src/components/icons'
import SelectOption from './SelectOption/SelectOption'
interface Props {
children? : React.ReactNode,
@@ -35,6 +36,9 @@ const SelectCommon = ({ type = 'default', size = 'base', option, children }: Pro
setActive(!isActive)
}
const changeSelectedName = (item:string) => {
setSelectedName(item)
}
return(
<>
<div className={classNames({
@@ -60,12 +64,7 @@ const SelectCommon = ({ type = 'default', size = 'base', option, children }: Pro
>
{
option.map(item =>
<div className={classNames({
[s.selectOption] : true,
[s[size]] : !!size,
})}
onClick = { () => setSelectedName(item.name) }
>{item.name}</div>
<SelectOption itemName={item.name} onClick={changeSelectedName} size={size} />
)
}
</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