-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[김미소] week11 #381
The head ref may contain hidden characters: "part2-\uAE40\uBBF8\uC18C-week11"
[김미소] week11 #381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { CheckBoxWrap } from './checkBoxStyle'; | ||
import { IModal } from '../modal/interface'; | ||
|
||
interface ICheckBoxData { | ||
$data: IModal['$modalData']; | ||
} | ||
|
||
function CheckBox({ $data }: ICheckBoxData) { | ||
if (typeof $data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeof 로 분기처리하는 것은 트랜스파일시에 문제는 없지만, $data.data 가 있는지 판단하는 식으로 짜는 것을 추천드려요! |
||
return ( | ||
<CheckBoxWrap className="chk--list-type1"> | ||
{$data && | ||
$data.data.map((list: any) => ( | ||
<div className="inner" key={list.id}> | ||
<input type="checkbox" id={list.id} /> | ||
<label htmlFor={list.id}> | ||
<strong>{list.name}</strong> | ||
<span>{list.link.count}개 링크</span> | ||
</label> | ||
</div> | ||
))} | ||
</CheckBoxWrap> | ||
); | ||
} else { | ||
return ( | ||
<div> | ||
<input type="text" /> | ||
<label htmlFor=""></label> | ||
</div> | ||
); | ||
} | ||
} | ||
export default CheckBox; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,32 +1,64 @@ | ||||||
import Button from "./Button"; | ||||||
import { InputModule } from "./inputStyle"; | ||||||
import { ChangeEvent, ReactNode, useEffect, useRef, useState } from 'react'; | ||||||
import Button from './Button'; | ||||||
import { InputModule } from './inputStyle'; | ||||||
interface IButtonModule { | ||||||
$type?: string; | ||||||
$inputClass?: string; | ||||||
$btnShow?: boolean; | ||||||
$btnText?: string; | ||||||
$placeholder?: string; | ||||||
$beforeBgIcon?: string; | ||||||
$btnClass?: string; | ||||||
children?: ReactNode; | ||||||
$clickEvent?: string; | ||||||
onchange?: (value: string) => void; | ||||||
} | ||||||
|
||||||
function Input({ | ||||||
$btnShow = false, | ||||||
$type = "text", | ||||||
$type = 'text', | ||||||
$inputClass, | ||||||
$placeholder, | ||||||
$btnText, | ||||||
$beforeBgIcon = "", | ||||||
$btnClass = "", | ||||||
$beforeBgIcon = '', | ||||||
$btnClass = '', | ||||||
children, | ||||||
$clickEvent, | ||||||
onchange, | ||||||
}: IButtonModule) { | ||||||
const [value, setValue] = useState(''); | ||||||
const refInput = useRef(null); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
string 타입같은 경우엔 확실히 타입을 정해주시는 게 좋아요! |
||||||
const handleChangInput = (e: ChangeEvent<HTMLInputElement>) => { | ||||||
const { value } = e.target; | ||||||
setValue(value); | ||||||
|
||||||
if (onchange) { | ||||||
// value값 전달 | ||||||
onchange(value); | ||||||
} | ||||||
}; | ||||||
|
||||||
const handleButtonEvent = (text: string) => { | ||||||
if (!$clickEvent) return; | ||||||
if ($clickEvent === 'reset') { | ||||||
setValue(''); | ||||||
} | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<> | ||||||
<InputModule | ||||||
type={$type} | ||||||
className={$inputClass} | ||||||
placeholder={$placeholder} | ||||||
value={value} | ||||||
onChange={handleChangInput} | ||||||
$beforeBgIcon={$beforeBgIcon} | ||||||
ref={refInput} | ||||||
/> | ||||||
{$btnShow && <Button $btnClass={$btnClass}>{$btnText}</Button>} | ||||||
{$btnShow && ( | ||||||
<Button $btnClass={$btnClass} onclick={() => handleButtonEvent(value)}> | ||||||
{children} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return 부에서 가져오는 value 가 아닌 위쪽에 있는 state 상의 value 인 경우에는 그냥 handleButtonEvent에 input 을 안받고 바로 value 를 참조하게 하시는 것을 추천드려요! |
||||||
</Button> | ||||||
)} | ||||||
</> | ||||||
); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import styled from 'styled-components'; | ||
import { theme } from '../../../styles/theme'; | ||
|
||
export const CheckBoxWrap = styled.div` | ||
&.chk { | ||
&--list { | ||
&-type1 { | ||
max-height: 240px; | ||
overflow-y: auto; | ||
text-align: left; | ||
.inner { | ||
cursor: pointer; | ||
input { | ||
display: none !important; | ||
} | ||
label { | ||
position: relative; | ||
display: block; | ||
padding: 0 8px; | ||
line-height: 40px; | ||
&::after { | ||
content: ''; | ||
display: none; | ||
position: absolute; | ||
top: 13px; | ||
right: 8px; | ||
width: 14px; | ||
height: 14px; | ||
background: url('/assets/icon/icon_check.svg'); | ||
} | ||
strong { | ||
font-size: 16px; | ||
} | ||
span { | ||
font-size: 14px; | ||
color: ${theme.color.gray9}; | ||
padding-left: 8px; | ||
} | ||
} | ||
input:checked + label { | ||
background-color: ${theme.color.grayf}; | ||
&::after { | ||
display: block; | ||
} | ||
strong { | ||
color: ${theme.color.primary}; | ||
} | ||
} | ||
&:hover { | ||
background-color: ${theme.color.grayf}; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
동일할 거 같아요!