diff --git a/src/s1-main/App.tsx b/src/s1-main/App.tsx index 233f912..093964f 100644 --- a/src/s1-main/App.tsx +++ b/src/s1-main/App.tsx @@ -3,6 +3,7 @@ import s from './App.module.css' import HW1 from '../s2-homeworks/hw01/HW1' import HW2 from '../s2-homeworks/hw02/HW2' import HW3 from '../s2-homeworks/hw03/HW3' +import HW4 from '../s2-homeworks/hw04/HW4' function App() { // для дз 12 @@ -19,7 +20,7 @@ function App() { - {/**/} + {/**/} diff --git a/src/s2-homeworks/hw04/HW4.tsx b/src/s2-homeworks/hw04/HW4.tsx index e982e7a..04aa701 100644 --- a/src/s2-homeworks/hw04/HW4.tsx +++ b/src/s2-homeworks/hw04/HW4.tsx @@ -2,6 +2,13 @@ import React from 'react' import s2 from '../../s1-main/App.module.css' import Stand from './Stand' +/* +* 1 - понять (и простить) SuperInputText +* 2 - в зависимости от типа и дизэйбла прицепить нужный класс в SuperButton.tsx (строка 21) +* 3 - дописать onChangeCallback в SuperCheckbox.tsx чтоб оба чекбокса работали на стенде +* 4 - сделать стили в соответствии с дизайном +* */ + const HW4 = () => { return (
diff --git a/src/s2-homeworks/hw04/Stand.tsx b/src/s2-homeworks/hw04/Stand.tsx index dbe13e8..0236717 100644 --- a/src/s2-homeworks/hw04/Stand.tsx +++ b/src/s2-homeworks/hw04/Stand.tsx @@ -5,14 +5,22 @@ import SuperCheckbox from './common/c3-SuperCheckbox/SuperCheckbox' import SuperButton from './common/c2-SuperButton/SuperButton' const Stand = () => { - const [stateForAllInputs, setValue] = useState('') - const [error, setError] = useState(undefined) + const [stateForAllInputs, setValue] = useState('') + const [error, setError] = useState('') - const [stateForAllCheckboxes, setChecked] = useState(false) + const [stateForAllCheckboxes, setChecked] = useState(false) return (
+ {/*совместим со старым кодом:*/} +
+ setValue(e.currentTarget.value)} + /> +
{/*инпут с ошибкой:*/}
{ onEnter={() => { setError( stateForAllInputs.trim() - ? undefined - : 'some error' + ? '' + : 'Error' ) setValue('') }} />
- {/*совместим со старым кодом*/} -
- setValue(e.currentTarget.value)} - /> -
@@ -63,6 +63,15 @@ const Stand = () => { disabled
+ {/*задизэйбленная кнопка:*/} +
+ + secondary + +
@@ -76,7 +85,7 @@ const Stand = () => { some text
- {/*совместим со старым кодом*/} + {/*совместим со старым кодом:*/}
, - HTMLInputElement -> +type DefaultInputPropsType = DetailedHTMLProps, + HTMLInputElement> // здесь мы говорим что у нашего инпута будут такие же пропсы как у обычного инпута, кроме type // (чтоб не писать value: string, onChange: ...; они уже все описаны в DefaultInputPropsType) @@ -23,18 +21,20 @@ type SuperInputTextPropsType = Omit & { spanClassName?: string } -const SuperInputText: React.FC = ({ - onChange, - onChangeText, - onKeyPress, - onEnter, - error, - className, - spanClassName, - id, +const SuperInputText: React.FC = ( + { + onChange, + onChangeText, + onKeyPress, + onEnter, + error, + className, + spanClassName, + id, - ...restProps // все остальные пропсы попадут в объект restProps -}) => { + ...restProps // все остальные пропсы попадут в объект restProps + } +) => { const onChangeCallback = (e: ChangeEvent) => { onChange?.(e) // если есть пропс onChange, то передать ему е (поскольку onChange не обязателен) @@ -44,16 +44,15 @@ const SuperInputText: React.FC = ({ onKeyPress?.(e) onEnter && // если есть пропс onEnter - e.key === 'Enter' && // и если нажата кнопка Enter - onEnter() // то вызвать его + e.key === 'Enter' && // и если нажата кнопка Enter + onEnter() // то вызвать его } - const finalSpanClassName = `${s.error} ${ - spanClassName ? spanClassName : '' - }` - const finalInputClassName = `${s.input} ${ - error ? s.errorInput : s.superInput - } ${className}` // задача на смешивание классов + const finalSpanClassName = s.error + + (spanClassName ? ' ' + spanClassName : '') + const finalInputClassName = s.input + + (error ? ' ' + s.errorInput : ' ' + s.superInput) + + (className ? ' ' + s.className : '') // задача на смешивание классов return (
diff --git a/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.module.css b/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.module.css index b11b31d..06dba34 100644 --- a/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.module.css +++ b/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.module.css @@ -1,38 +1,29 @@ -@keyframes blink { - 0% { - left: -130%; - } - 100% { - left: 130%; - } -} - - -.disabled { - background: #004d99; - opacity: 0.5; - color: #002e5c; -} - - .button { overflow: hidden; - cursor: pointer; - border-radius: 3px; - border: 1px solid #0066CC; - color: white; padding: 5px 24px; + + border-radius: 3px; + border: none; + + color: white; font-family: 'Montserrat', sans-serif; font-weight: 600; font-size: 14px; line-height: 20px; + cursor: pointer; +} + +.disabled { + color: #002e5c; + background: #004d99; + opacity: 0.5; } .secondary { + color: #0066CC; background: transparent; border: 1px solid #0066CC; border-radius: 3px; - color: #0066CC; } .default { @@ -43,24 +34,6 @@ 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 { background: #0080ff; } diff --git a/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.tsx b/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.tsx index ccea9d8..19e5db0 100644 --- a/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.tsx +++ b/src/s2-homeworks/hw04/common/c2-SuperButton/SuperButton.tsx @@ -1,31 +1,31 @@ -import React, { ButtonHTMLAttributes, DetailedHTMLProps } from 'react' +import React, {ButtonHTMLAttributes, DetailedHTMLProps} from 'react' import s from './SuperButton.module.css' // тип пропсов обычной кнопки, children в котором храниться название кнопки там уже описан -type DefaultButtonPropsType = DetailedHTMLProps< - ButtonHTMLAttributes, - HTMLButtonElement -> +type DefaultButtonPropsType = DetailedHTMLProps, + HTMLButtonElement> type SuperButtonPropsType = DefaultButtonPropsType & { xType?: string } -const SuperButton: React.FC = ({ - xType, - className, - disabled, - ...restProps // все остальные пропсы попадут в объект restProps, там же будет children -}) => { - const finalClassName = `${s.button} ${ - disabled - ? s.disabled - : xType === 'red' - ? s.red - : xType === 'secondary' - ? s.secondary - : s.default - } ${className}` // задачка на смешивание классов +const SuperButton: React.FC = ( + { + xType, + className, + disabled, + ...restProps // все остальные пропсы попадут в объект restProps, там же будет children + } +) => { + const finalClassName = s.button + + (disabled + ? ' ' + s.disabled + : xType === 'red' + ? ' ' + s.red + : xType === 'secondary' + ? ' ' + s.secondary + : ' ' + s.default) + + (className ? ' ' + className : '') // задачка на смешивание классов return (