mirror of
https://github.com/IgnatZakalinsky/home-works.git
synced 2025-12-25 20:39:24 +00:00
final ref hw4
This commit is contained in:
@@ -3,6 +3,7 @@ import s from './App.module.css'
|
|||||||
import HW1 from '../s2-homeworks/hw01/HW1'
|
import HW1 from '../s2-homeworks/hw01/HW1'
|
||||||
import HW2 from '../s2-homeworks/hw02/HW2'
|
import HW2 from '../s2-homeworks/hw02/HW2'
|
||||||
import HW3 from '../s2-homeworks/hw03/HW3'
|
import HW3 from '../s2-homeworks/hw03/HW3'
|
||||||
|
import HW4 from '../s2-homeworks/hw04/HW4'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
// для дз 12
|
// для дз 12
|
||||||
@@ -19,7 +20,7 @@ function App() {
|
|||||||
<HW1/>
|
<HW1/>
|
||||||
<HW2/>
|
<HW2/>
|
||||||
<HW3/>
|
<HW3/>
|
||||||
{/*<HW4/>*/}
|
<HW4/>
|
||||||
|
|
||||||
{/*<HW5/>*/}
|
{/*<HW5/>*/}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ import React from 'react'
|
|||||||
import s2 from '../../s1-main/App.module.css'
|
import s2 from '../../s1-main/App.module.css'
|
||||||
import Stand from './Stand'
|
import Stand from './Stand'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1 - понять (и простить) SuperInputText
|
||||||
|
* 2 - в зависимости от типа и дизэйбла прицепить нужный класс в SuperButton.tsx (строка 21)
|
||||||
|
* 3 - дописать onChangeCallback в SuperCheckbox.tsx чтоб оба чекбокса работали на стенде
|
||||||
|
* 4 - сделать стили в соответствии с дизайном
|
||||||
|
* */
|
||||||
|
|
||||||
const HW4 = () => {
|
const HW4 = () => {
|
||||||
return (
|
return (
|
||||||
<div id={'hw4'}>
|
<div id={'hw4'}>
|
||||||
|
|||||||
@@ -5,14 +5,22 @@ import SuperCheckbox from './common/c3-SuperCheckbox/SuperCheckbox'
|
|||||||
import SuperButton from './common/c2-SuperButton/SuperButton'
|
import SuperButton from './common/c2-SuperButton/SuperButton'
|
||||||
|
|
||||||
const Stand = () => {
|
const Stand = () => {
|
||||||
const [stateForAllInputs, setValue] = useState('')
|
const [stateForAllInputs, setValue] = useState<string>('')
|
||||||
const [error, setError] = useState<undefined | string>(undefined)
|
const [error, setError] = useState<string>('')
|
||||||
|
|
||||||
const [stateForAllCheckboxes, setChecked] = useState(false)
|
const [stateForAllCheckboxes, setChecked] = useState<boolean>(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id={'hw4-stand'} className={s.stand}>
|
<div id={'hw4-stand'} className={s.stand}>
|
||||||
<div className={s.inputs}>
|
<div className={s.inputs}>
|
||||||
|
{/*совместим со старым кодом:*/}
|
||||||
|
<div>
|
||||||
|
<SuperInputText
|
||||||
|
id={'hw4-super-input-like-old'}
|
||||||
|
value={stateForAllInputs}
|
||||||
|
onChange={(e) => setValue(e.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{/*инпут с ошибкой:*/}
|
{/*инпут с ошибкой:*/}
|
||||||
<div>
|
<div>
|
||||||
<SuperInputText
|
<SuperInputText
|
||||||
@@ -23,21 +31,13 @@ const Stand = () => {
|
|||||||
onEnter={() => {
|
onEnter={() => {
|
||||||
setError(
|
setError(
|
||||||
stateForAllInputs.trim()
|
stateForAllInputs.trim()
|
||||||
? undefined
|
? ''
|
||||||
: 'some error'
|
: 'Error'
|
||||||
)
|
)
|
||||||
setValue('')
|
setValue('')
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/*совместим со старым кодом*/}
|
|
||||||
<div>
|
|
||||||
<SuperInputText
|
|
||||||
id={'hw4-super-input-like-old'}
|
|
||||||
value={stateForAllInputs}
|
|
||||||
onChange={(e) => setValue(e.currentTarget.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={s.buttons}>
|
<div className={s.buttons}>
|
||||||
@@ -63,6 +63,15 @@ const Stand = () => {
|
|||||||
disabled
|
disabled
|
||||||
</SuperButton>
|
</SuperButton>
|
||||||
</div>
|
</div>
|
||||||
|
{/*задизэйбленная кнопка:*/}
|
||||||
|
<div>
|
||||||
|
<SuperButton
|
||||||
|
id={'hw4-super-button-secondary'}
|
||||||
|
xType={'secondary'}
|
||||||
|
>
|
||||||
|
secondary
|
||||||
|
</SuperButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={s.checkboxes}>
|
<div className={s.checkboxes}>
|
||||||
@@ -76,7 +85,7 @@ const Stand = () => {
|
|||||||
some text
|
some text
|
||||||
</SuperCheckbox>
|
</SuperCheckbox>
|
||||||
</div>
|
</div>
|
||||||
{/*совместим со старым кодом*/}
|
{/*совместим со старым кодом:*/}
|
||||||
<div>
|
<div>
|
||||||
<SuperCheckbox
|
<SuperCheckbox
|
||||||
id={'hw4-super-checkbox-like-old'}
|
id={'hw4-super-checkbox-like-old'}
|
||||||
|
|||||||
@@ -7,18 +7,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
|
width: 370px;
|
||||||
|
height: 36px;
|
||||||
|
padding: 8px 0 8px 12px;
|
||||||
|
|
||||||
|
color: #000;
|
||||||
border: 1px solid #d1d1d1;
|
border: 1px solid #d1d1d1;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
width: 370px;
|
outline: none;
|
||||||
|
|
||||||
font-family: 'Montserrat', sans-serif;
|
font-family: 'Montserrat', sans-serif;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
padding: 8px 0 8px 12px;
|
|
||||||
color: #000;
|
|
||||||
outline: none;
|
|
||||||
height: 36px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.inputWrapper {
|
.inputWrapper {
|
||||||
@@ -30,13 +32,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
|
position: absolute;
|
||||||
|
top: -17px;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
color: #cc1439;
|
||||||
font-family: 'Montserrat', sans-serif;
|
font-family: 'Montserrat', sans-serif;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
line-height: 12px;
|
line-height: 12px;
|
||||||
color: #cc1439;
|
|
||||||
position: absolute;
|
|
||||||
top: -17px;
|
|
||||||
left: 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ import React, {
|
|||||||
import s from './SuperInputText.module.css'
|
import s from './SuperInputText.module.css'
|
||||||
|
|
||||||
// тип пропсов обычного инпута
|
// тип пропсов обычного инпута
|
||||||
type DefaultInputPropsType = DetailedHTMLProps<
|
type DefaultInputPropsType = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>,
|
||||||
InputHTMLAttributes<HTMLInputElement>,
|
HTMLInputElement>
|
||||||
HTMLInputElement
|
|
||||||
>
|
|
||||||
|
|
||||||
// здесь мы говорим что у нашего инпута будут такие же пропсы как у обычного инпута, кроме type
|
// здесь мы говорим что у нашего инпута будут такие же пропсы как у обычного инпута, кроме type
|
||||||
// (чтоб не писать value: string, onChange: ...; они уже все описаны в DefaultInputPropsType)
|
// (чтоб не писать value: string, onChange: ...; они уже все описаны в DefaultInputPropsType)
|
||||||
@@ -23,7 +21,8 @@ type SuperInputTextPropsType = Omit<DefaultInputPropsType, 'type'> & {
|
|||||||
spanClassName?: string
|
spanClassName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const SuperInputText: React.FC<SuperInputTextPropsType> = ({
|
const SuperInputText: React.FC<SuperInputTextPropsType> = (
|
||||||
|
{
|
||||||
onChange,
|
onChange,
|
||||||
onChangeText,
|
onChangeText,
|
||||||
onKeyPress,
|
onKeyPress,
|
||||||
@@ -34,7 +33,8 @@ const SuperInputText: React.FC<SuperInputTextPropsType> = ({
|
|||||||
id,
|
id,
|
||||||
|
|
||||||
...restProps // все остальные пропсы попадут в объект restProps
|
...restProps // все остальные пропсы попадут в объект restProps
|
||||||
}) => {
|
}
|
||||||
|
) => {
|
||||||
const onChangeCallback = (e: ChangeEvent<HTMLInputElement>) => {
|
const onChangeCallback = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
onChange?.(e) // если есть пропс onChange, то передать ему е (поскольку onChange не обязателен)
|
onChange?.(e) // если есть пропс onChange, то передать ему е (поскольку onChange не обязателен)
|
||||||
|
|
||||||
@@ -48,12 +48,11 @@ const SuperInputText: React.FC<SuperInputTextPropsType> = ({
|
|||||||
onEnter() // то вызвать его
|
onEnter() // то вызвать его
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalSpanClassName = `${s.error} ${
|
const finalSpanClassName = s.error
|
||||||
spanClassName ? spanClassName : ''
|
+ (spanClassName ? ' ' + spanClassName : '')
|
||||||
}`
|
const finalInputClassName = s.input
|
||||||
const finalInputClassName = `${s.input} ${
|
+ (error ? ' ' + s.errorInput : ' ' + s.superInput)
|
||||||
error ? s.errorInput : s.superInput
|
+ (className ? ' ' + s.className : '') // задача на смешивание классов
|
||||||
} ${className}` // задача на смешивание классов
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={s.inputWrapper}>
|
<div className={s.inputWrapper}>
|
||||||
|
|||||||
@@ -1,38 +1,29 @@
|
|||||||
@keyframes blink {
|
|
||||||
0% {
|
|
||||||
left: -130%;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
left: 130%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.disabled {
|
|
||||||
background: #004d99;
|
|
||||||
opacity: 0.5;
|
|
||||||
color: #002e5c;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 3px;
|
|
||||||
border: 1px solid #0066CC;
|
|
||||||
color: white;
|
|
||||||
padding: 5px 24px;
|
padding: 5px 24px;
|
||||||
|
|
||||||
|
border-radius: 3px;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
color: white;
|
||||||
font-family: 'Montserrat', sans-serif;
|
font-family: 'Montserrat', sans-serif;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled {
|
||||||
|
color: #002e5c;
|
||||||
|
background: #004d99;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.secondary {
|
.secondary {
|
||||||
|
color: #0066CC;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: 1px solid #0066CC;
|
border: 1px solid #0066CC;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
color: #0066CC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.default {
|
.default {
|
||||||
@@ -43,24 +34,6 @@
|
|||||||
background: #cc1439;
|
background: #cc1439;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button::after {
|
|
||||||
display: block;
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
|
|
||||||
left: -130%;
|
|
||||||
top: 0;
|
|
||||||
height: 100%;
|
|
||||||
width: 20%;
|
|
||||||
|
|
||||||
transform: skew(45deg);
|
|
||||||
|
|
||||||
background-color: #fff;
|
|
||||||
opacity: 0.7;
|
|
||||||
|
|
||||||
z-index: 14;
|
|
||||||
}
|
|
||||||
|
|
||||||
.default:hover {
|
.default:hover {
|
||||||
background: #0080ff;
|
background: #0080ff;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
import React, { ButtonHTMLAttributes, DetailedHTMLProps } from 'react'
|
import React, {ButtonHTMLAttributes, DetailedHTMLProps} from 'react'
|
||||||
import s from './SuperButton.module.css'
|
import s from './SuperButton.module.css'
|
||||||
|
|
||||||
// тип пропсов обычной кнопки, children в котором храниться название кнопки там уже описан
|
// тип пропсов обычной кнопки, children в котором храниться название кнопки там уже описан
|
||||||
type DefaultButtonPropsType = DetailedHTMLProps<
|
type DefaultButtonPropsType = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
ButtonHTMLAttributes<HTMLButtonElement>,
|
HTMLButtonElement>
|
||||||
HTMLButtonElement
|
|
||||||
>
|
|
||||||
|
|
||||||
type SuperButtonPropsType = DefaultButtonPropsType & {
|
type SuperButtonPropsType = DefaultButtonPropsType & {
|
||||||
xType?: string
|
xType?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const SuperButton: React.FC<SuperButtonPropsType> = ({
|
const SuperButton: React.FC<SuperButtonPropsType> = (
|
||||||
|
{
|
||||||
xType,
|
xType,
|
||||||
className,
|
className,
|
||||||
disabled,
|
disabled,
|
||||||
...restProps // все остальные пропсы попадут в объект restProps, там же будет children
|
...restProps // все остальные пропсы попадут в объект restProps, там же будет children
|
||||||
}) => {
|
}
|
||||||
const finalClassName = `${s.button} ${
|
) => {
|
||||||
disabled
|
const finalClassName = s.button
|
||||||
? s.disabled
|
+ (disabled
|
||||||
|
? ' ' + s.disabled
|
||||||
: xType === 'red'
|
: xType === 'red'
|
||||||
? s.red
|
? ' ' + s.red
|
||||||
: xType === 'secondary'
|
: xType === 'secondary'
|
||||||
? s.secondary
|
? ' ' + s.secondary
|
||||||
: s.default
|
: ' ' + s.default)
|
||||||
} ${className}` // задачка на смешивание классов
|
+ (className ? ' ' + className : '') // задачка на смешивание классов
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -6,17 +6,16 @@ import React, {
|
|||||||
import s from './SuperCheckbox.module.css'
|
import s from './SuperCheckbox.module.css'
|
||||||
|
|
||||||
// тип пропсов обычного инпута
|
// тип пропсов обычного инпута
|
||||||
type DefaultInputPropsType = DetailedHTMLProps<
|
type DefaultInputPropsType = DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>,
|
||||||
InputHTMLAttributes<HTMLInputElement>,
|
HTMLInputElement>
|
||||||
HTMLInputElement
|
|
||||||
>
|
|
||||||
|
|
||||||
type SuperCheckboxPropsType = Omit<DefaultInputPropsType, 'type'> & {
|
type SuperCheckboxPropsType = Omit<DefaultInputPropsType, 'type'> & {
|
||||||
onChangeChecked?: (checked: boolean) => void
|
onChangeChecked?: (checked: boolean) => void
|
||||||
spanClassName?: string
|
spanClassName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const SuperCheckbox: React.FC<SuperCheckboxPropsType> = ({
|
const SuperCheckbox: React.FC<SuperCheckboxPropsType> = (
|
||||||
|
{
|
||||||
onChange,
|
onChange,
|
||||||
onChangeChecked,
|
onChangeChecked,
|
||||||
className,
|
className,
|
||||||
@@ -25,7 +24,8 @@ const SuperCheckbox: React.FC<SuperCheckboxPropsType> = ({
|
|||||||
id,
|
id,
|
||||||
|
|
||||||
...restProps // все остальные пропсы попадут в объект restProps
|
...restProps // все остальные пропсы попадут в объект restProps
|
||||||
}) => {
|
}
|
||||||
|
) => {
|
||||||
const onChangeCallback = (e: ChangeEvent<HTMLInputElement>) => {
|
const onChangeCallback = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
// задачка на написание онченджа
|
// задачка на написание онченджа
|
||||||
onChange?.(e)
|
onChange?.(e)
|
||||||
@@ -33,7 +33,8 @@ const SuperCheckbox: React.FC<SuperCheckboxPropsType> = ({
|
|||||||
onChangeChecked?.(e.currentTarget.checked)
|
onChangeChecked?.(e.currentTarget.checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalInputClassName = `${s.checkbox} ${className ? className : ''}`
|
const finalInputClassName = s.checkbox
|
||||||
|
+ (className ? ' ' + className : '')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<label className={s.label}>
|
<label className={s.label}>
|
||||||
|
|||||||
Reference in New Issue
Block a user