Skip to content

Commit e9bd62b

Browse files
add React Select and create CustonSelect
1 parent 909f072 commit e9bd62b

8 files changed

+535
-2
lines changed

package-lock.json

+428
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"react-dom": "18.2.0",
2424
"react-input-mask": "^3.0.0-alpha.2",
2525
"react-redux": "^8.1.1",
26+
"react-select": "^5.7.4",
2627
"typescript": "5.1.3"
2728
},
2829
"devDependencies": {

src/components/StepOneForm/StepOneForm.module.scss

+10
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@
88
max-width: 80px;
99
}
1010
}
11+
12+
.wrapper {
13+
display: flex;
14+
flex-direction: row;
15+
justify-content: space-between;
16+
17+
& > button {
18+
max-width: 75px;
19+
}
20+
}

src/components/StepOneForm/StepOneForm.tsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
import React from 'react'
1+
'use client'
2+
import React, { FormEventHandler } from 'react'
23
import { UIInput } from '../ui-components/UIInput/UIInput'
34
import styles from './StepOneForm.module.scss'
5+
import { CustomSelect } from '../ui-components/CustomSelect/CustomSelect'
6+
import { UIButton } from '../ui-components/UIButton/UIButton'
47

58
export const StepOneForm = () => {
9+
10+
const handleSubmit: FormEventHandler = (event) => {
11+
event.preventDefault();
12+
13+
const form = event.target as HTMLFormElement;
14+
15+
const formData = new FormData(form);
16+
const formJson = Object.fromEntries(formData.entries());
17+
console.log(formJson)
18+
// if (validateMaxLength(formJson.fullName as string, 30) && isCyrillic(formJson.fullName as string) && isValidEmail(formJson.email as string)) {
19+
// console.log(formJson)
20+
// router.push('/step-1')
21+
// } else {
22+
// console.log('Проверьте поля на корректность введенных данных')
23+
// }
24+
};
25+
626
return (
7-
<form className={styles.form}>
27+
<form className={styles.form} onSubmit={handleSubmit}>
828
<UIInput
929
type={'text'}
1030
heading={'Nickname'}
@@ -29,6 +49,18 @@ export const StepOneForm = () => {
2949
formName={'StepOneForm'}
3050
/>
3151

52+
<CustomSelect
53+
heading={'Sex'}
54+
name={'sex'}
55+
formName={'StepOneForm'}
56+
/>
57+
58+
<div className={styles.wrapper}>
59+
<UIButton text={'Назад'} type={'button'}/>
60+
61+
<UIButton text={'Далее'} type={'submit'}/>
62+
</div>
63+
3264
</form>
3365
)
3466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.label {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 10px;
5+
}
6+
7+
.heading {
8+
margin: 0;
9+
font-weight: 600;
10+
font-size: 18px;
11+
line-height: 20px;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use client'
2+
import React, { FC, useState } from 'react'
3+
import Select, { OnChangeValue } from 'react-select'
4+
import styles from './CustomSelect.module.scss'
5+
import { IUIInputProps } from '../UIInput/UIInput'
6+
import { IOptions } from './customSelect.interface'
7+
8+
type ICustomSelect = Pick<IUIInputProps, 'As' | 'heading' | 'name' | 'formName'>
9+
10+
const options: IOptions[] = [
11+
{ value: 'man', label: 'man' },
12+
{ value: 'woman', label: 'woman' },
13+
]
14+
15+
export const CustomSelect: FC<ICustomSelect> = ({ As ='h2', heading, name, formName}) => {
16+
const [selectValue, setSelectValue] = useState('');
17+
18+
const onChange = (newValue: OnChangeValue<IOptions, boolean>) => {
19+
// console.log(newValue)
20+
setSelectValue((newValue as IOptions).value)
21+
}
22+
23+
return (
24+
<label className={styles.label}>
25+
<As className={styles.heading}>{heading}</As>
26+
<Select
27+
options={options}
28+
name={name}
29+
form={formName}
30+
onChange={onChange}
31+
/>
32+
</label>
33+
)
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IOptions {
2+
value: string;
3+
label: string;
4+
}

src/components/ui-components/UIButton/UIButton.module.scss

+12
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,17 @@
2121
}
2222

2323
.back {
24+
color: var(--btn-bg);
2425
background-color: var(--white);
26+
border: 2px solid var(--btn-bg);
27+
28+
&:focus-visible,
29+
&:hover {
30+
outline: none;
31+
background-color: var(--input-hover);
32+
}
33+
34+
&:active {
35+
background-color: var(--input-active);
36+
}
2537
}

0 commit comments

Comments
 (0)