From 1f26b0afc8b91b48875493cad3f72dad52bf4793 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 2 Jul 2023 16:26:05 -0700 Subject: [PATCH] Fix SelectWithInput styles and functionality * Adapts styles for CSS modules * Add name to errors * Properly sends validity --- .../common/SelectWithInput/index.module.scss | 37 ++++++---------- components/common/SelectWithInput/index.tsx | 43 +++++++++++++------ 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/components/common/SelectWithInput/index.module.scss b/components/common/SelectWithInput/index.module.scss index 659676be..f2bf7fe3 100644 --- a/components/common/SelectWithInput/index.module.scss +++ b/components/common/SelectWithInput/index.module.scss @@ -1,29 +1,16 @@ -.SelectWithItem { - .InputSet { - display: flex; - flex-direction: row; - gap: $unit; - width: 100%; +.set { + display: flex; + flex-direction: row; + gap: $unit; + width: 100%; +} - .SelectTrigger { - flex-grow: 1; - width: 100%; - } +.errors { + color: $error; + display: none; + padding: $unit 0; - .Input { - flex-grow: 0; - text-align: right; - width: 13rem; - } - } - - .errors { - color: $error; - display: none; - padding: $unit 0; - - &.visible { - display: block; - } + &.visible { + display: block; } } diff --git a/components/common/SelectWithInput/index.tsx b/components/common/SelectWithInput/index.tsx index d16c356e..dbecfb07 100644 --- a/components/common/SelectWithInput/index.tsx +++ b/components/common/SelectWithInput/index.tsx @@ -59,13 +59,13 @@ const SelectWithInput = ({ // Classes const inputClasses = classNames({ - Bound: true, - Hidden: currentItemSkill?.id === 0, + fullHeight: true, + range: true, }) const errorClasses = classNames({ - errors: true, - visible: error !== '', + [styles.errors]: true, + [styles.visible]: error !== '', }) // Hooks @@ -127,18 +127,24 @@ const SelectWithInput = ({ let error = '' if (currentItemSkill) { - if (value < currentItemSkill.minValue) { + if (!currentItemSkill.fractional && value && value % 1 != 0) { + error = t(`${object}.errors.value_not_whole`, { + name: currentItemSkill.name[locale], + }) + } else if (value < currentItemSkill.minValue) { error = t(`${object}.errors.value_too_low`, { + name: currentItemSkill.name[locale], minValue: currentItemSkill.minValue, }) } else if (value > currentItemSkill.maxValue) { error = t(`${object}.errors.value_too_high`, { + name: currentItemSkill.name[locale], maxValue: currentItemSkill.maxValue, }) - } else if (!currentItemSkill.fractional && value % 1 != 0) { - error = t(`${object}.errors.value_not_whole`) } else if (!value || value <= 0) { - error = t(`${object}.errors.value_empty`) + error = t(`${object}.errors.value_empty`, { + name: currentItemSkill.name[locale], + }) } else { error = '' } @@ -146,7 +152,13 @@ const SelectWithInput = ({ setError(error) - return error.length === 0 + if (error.length > 0) { + sendValidity(false) + return false + } else { + sendValidity(true) + return true + } } const rangeString = () => { @@ -162,17 +174,19 @@ const SelectWithInput = ({ } return ( -
-
+
+