-
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.
feat(processes/profile): add job form and add radioWithInput
- Loading branch information
Showing
7 changed files
with
106 additions
and
6 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,7 @@ | ||
.Container { | ||
|
||
} | ||
|
||
.Input { | ||
margin-left: 32px; | ||
} |
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,13 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { JobForm } from 'src/processes/my_profile/JobForm/JobForm'; | ||
|
||
const meta: Meta<typeof JobForm> = { | ||
component: JobForm, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof JobForm>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
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,51 @@ | ||
import { useState } from 'react'; | ||
import styles from './JobForm.module.css'; | ||
import { RadioWithInput } from 'src/shared/ui/RadioWithInput/RadioWithInput'; | ||
|
||
const JobTypeList = ['STUDENT', 'OFFICE_WORKER', 'FREELANCER', 'ETC']; | ||
type JobType = (typeof JobTypeList)[number]; | ||
|
||
const JobMetaMap: Record<JobType, { name: string; inputPlaceHolder: string }> = { | ||
STUDENT: { | ||
name: '학생(대학원생)', | ||
inputPlaceHolder: '학과나 학교를 입력해주세요.', | ||
}, | ||
OFFICE_WORKER: { | ||
name: '직장인', | ||
inputPlaceHolder: '직무나 회사를 입력해주세요.', | ||
}, | ||
FREELANCER: { | ||
name: '자영업자, 프리랜서', | ||
inputPlaceHolder: '어떤 사업을 하는지 입력해주세요.', | ||
}, | ||
ETC: { | ||
name: '기타', | ||
inputPlaceHolder: '기타 하시는 일을 입력해주세요.', | ||
}, | ||
}; | ||
|
||
export const JobForm = () => { | ||
const [selected, setSelected] = useState<JobType | null>(null); | ||
const [inputValue, setInputValue] = useState<string>(''); | ||
|
||
const onSelect = (job: JobType) => { | ||
setSelected(job); | ||
setInputValue(''); | ||
}; | ||
|
||
return ( | ||
<section className={styles.Container} role={'radiogroup'}> | ||
{JobTypeList.map((job) => ( | ||
<RadioWithInput | ||
key={job} | ||
label={JobMetaMap[job].name} | ||
checked={selected === job} | ||
onChange={() => onSelect(job)} | ||
inputPlaceholder={JobMetaMap[job].inputPlaceHolder} | ||
inputValue={inputValue} | ||
onChangeInputValue={setInputValue} | ||
/> | ||
))} | ||
</section> | ||
); | ||
}; |
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,15 +1,15 @@ | ||
import { DetailedHTMLProps, InputHTMLAttributes, ReactNode } from 'react'; | ||
import { DetailedHTMLProps, forwardRef, InputHTMLAttributes, ReactNode } from 'react'; | ||
import styles from './Input.module.css'; | ||
|
||
type InputProps = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & { | ||
suffixSlot?: ReactNode; | ||
}; | ||
|
||
export const Input = ({ suffixSlot, ...props }: InputProps) => { | ||
export const Input = forwardRef<HTMLInputElement | null, InputProps>(function InputComponent({ className, suffixSlot, ...props }: InputProps, ref) { | ||
return ( | ||
<div className={styles.Container}> | ||
<input className={styles.Input} {...props} /> | ||
<div className={`${className} ${styles.Container}`}> | ||
<input ref={ref} className={styles.Input} {...props} /> | ||
{suffixSlot && <span className={styles.SuffixSlotContainer}>{suffixSlot}</span>} | ||
</div> | ||
); | ||
}; | ||
}); |
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,28 @@ | ||
import { Radio, RadioProps } from 'src/shared/ui/Radio/Radio'; | ||
import { Input } from 'src/shared/ui/Input/Input'; | ||
import styles from 'src/processes/my_profile/JobForm/JobForm.module.css'; | ||
import { useRef } from 'react'; | ||
|
||
type RadioWithInputProps = RadioProps & { | ||
inputPlaceholder: string; | ||
inputValue: string; | ||
onChangeInputValue: (value: string) => void; | ||
}; | ||
|
||
export const RadioWithInput = ({ inputPlaceholder, inputValue, onChangeInputValue, ...props }: RadioWithInputProps) => { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
return ( | ||
<> | ||
<Radio {...props} /> | ||
{props.checked && ( | ||
<Input | ||
ref={inputRef} | ||
className={styles.Input} | ||
placeholder={inputPlaceholder} | ||
value={inputValue} | ||
onChange={(e) => onChangeInputValue(e.target.value)} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |