From 53cb8cd7181bafa65c33aa99e2440d8fca588905 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Tue, 12 Sep 2023 18:57:48 +0300 Subject: [PATCH] feat: CustomTextField error --- .../Questions/SliderOptions/SliderOptions.tsx | 16 ++++++++++++++-- src/ui_kit/CustomNumberField.tsx | 3 +++ src/ui_kit/CustomTextField.tsx | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/pages/Questions/SliderOptions/SliderOptions.tsx b/src/pages/Questions/SliderOptions/SliderOptions.tsx index 3bcb433f..c1ae6e54 100644 --- a/src/pages/Questions/SliderOptions/SliderOptions.tsx +++ b/src/pages/Questions/SliderOptions/SliderOptions.tsx @@ -1,7 +1,7 @@ +import { useState } from "react"; import { useParams } from "react-router-dom"; import { Box, Typography } from "@mui/material"; import ButtonsOptions from "../ButtonsOptions"; -import React from "react"; import CustomNumberField from "@ui_kit/CustomNumberField"; import SwitchSlider from "./switchSlider"; import { questionStore, updateQuestionsList } from "@root/questions"; @@ -11,7 +11,8 @@ interface Props { } export default function SliderOptions({ totalIndex }: Props) { - const [switchState, setSwitchState] = React.useState("setting"); + const [switchState, setSwitchState] = useState("setting"); + const [stepError, setStepError] = useState(""); const quizId = Number(useParams().quizId); const { listQuestions } = questionStore(); @@ -151,6 +152,7 @@ export default function SliderOptions({ totalIndex }: Props) { min={0} max={100} placeholder={"1"} + error={stepError} value={String(listQuestions[quizId][totalIndex].content.step)} onChange={({ target }) => { const clonContent = listQuestions[quizId][totalIndex].content; @@ -177,6 +179,16 @@ export default function SliderOptions({ totalIndex }: Props) { }, }); } + + if (range % step) { + setStepError( + `Шаг должен делить без остатка диапазон ${max} - ${min} = ${ + max - min + }` + ); + } else { + setStepError(""); + } }} /> diff --git a/src/ui_kit/CustomNumberField.tsx b/src/ui_kit/CustomNumberField.tsx index 2b124c72..37fab7c2 100644 --- a/src/ui_kit/CustomNumberField.tsx +++ b/src/ui_kit/CustomNumberField.tsx @@ -8,6 +8,7 @@ interface CustomNumberFieldProps { onChange?: (event: ChangeEvent) => void; onKeyDown?: (event: KeyboardEvent) => void; onBlur?: (event: FocusEvent) => void; + error?: string; value: string; sx?: SxProps; min?: number; @@ -18,6 +19,7 @@ export default function CustomNumberField({ placeholder, value, sx, + error, onChange, onKeyDown, onBlur, @@ -42,6 +44,7 @@ export default function CustomNumberField({ ) => void; onKeyDown?: (event: KeyboardEvent) => void; onBlur?: (event: FocusEvent) => void; @@ -23,6 +24,7 @@ export default function CustomTextField({ value, text, sx, + error, onChange, onKeyDown, onBlur, @@ -36,6 +38,8 @@ export default function CustomTextField({ fullWidth value={value} placeholder={placeholder} + error={!!error} + label={error} onChange={onChange} onKeyDown={onKeyDown} onBlur={onBlur} @@ -45,6 +49,10 @@ export default function CustomTextField({ height: "48px", borderRadius: "10px", }, + "& .MuiInputLabel-root": { + fontSize: "13.5px", + marginTop: "3px", + }, ...sx, }} inputProps={{