Fix SelectWithInput styles and functionality

* Adapts styles for CSS modules
* Add name to errors
* Properly sends validity
This commit is contained in:
Justin Edmund 2023-07-02 16:26:05 -07:00
parent 1c805e3f88
commit 1f26b0afc8
2 changed files with 42 additions and 38 deletions

View file

@ -1,20 +1,8 @@
.SelectWithItem { .set {
.InputSet {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: $unit; gap: $unit;
width: 100%; width: 100%;
.SelectTrigger {
flex-grow: 1;
width: 100%;
}
.Input {
flex-grow: 0;
text-align: right;
width: 13rem;
}
} }
.errors { .errors {
@ -26,4 +14,3 @@
display: block; display: block;
} }
} }
}

View file

@ -59,13 +59,13 @@ const SelectWithInput = ({
// Classes // Classes
const inputClasses = classNames({ const inputClasses = classNames({
Bound: true, fullHeight: true,
Hidden: currentItemSkill?.id === 0, range: true,
}) })
const errorClasses = classNames({ const errorClasses = classNames({
errors: true, [styles.errors]: true,
visible: error !== '', [styles.visible]: error !== '',
}) })
// Hooks // Hooks
@ -127,18 +127,24 @@ const SelectWithInput = ({
let error = '' let error = ''
if (currentItemSkill) { 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`, { error = t(`${object}.errors.value_too_low`, {
name: currentItemSkill.name[locale],
minValue: currentItemSkill.minValue, minValue: currentItemSkill.minValue,
}) })
} else if (value > currentItemSkill.maxValue) { } else if (value > currentItemSkill.maxValue) {
error = t(`${object}.errors.value_too_high`, { error = t(`${object}.errors.value_too_high`, {
name: currentItemSkill.name[locale],
maxValue: currentItemSkill.maxValue, maxValue: currentItemSkill.maxValue,
}) })
} else if (!currentItemSkill.fractional && value % 1 != 0) {
error = t(`${object}.errors.value_not_whole`)
} else if (!value || value <= 0) { } else if (!value || value <= 0) {
error = t(`${object}.errors.value_empty`) error = t(`${object}.errors.value_empty`, {
name: currentItemSkill.name[locale],
})
} else { } else {
error = '' error = ''
} }
@ -146,7 +152,13 @@ const SelectWithInput = ({
setError(error) setError(error)
return error.length === 0 if (error.length > 0) {
sendValidity(false)
return false
} else {
sendValidity(true)
return true
}
} }
const rangeString = () => { const rangeString = () => {
@ -162,17 +174,19 @@ const SelectWithInput = ({
} }
return ( return (
<div className="SelectWithItem"> <div>
<div className="InputSet"> <div className={styles.set}>
<Select <Select
key={`${currentItemSkill?.name.en}_type`} key={`${currentItemSkill?.name.en}_type`}
value={`${currentItemSkill ? currentItemSkill.id : 0}`} value={`${currentItemSkill ? currentItemSkill.id : 0}`}
open={open} open={open}
trigger={{
className: 'grow',
}}
disabled={selectDisabled} disabled={selectDisabled}
onValueChange={handleSelectChange} onValueChange={handleSelectChange}
onOpenChange={changeOpen} onOpenChange={changeOpen}
onClose={onClose} onClose={onClose}
triggerClass="modal"
overlayVisible={false} overlayVisible={false}
> >
{generateOptions()} {generateOptions()}
@ -181,13 +195,16 @@ const SelectWithInput = ({
<Input <Input
value={fieldInputValue} value={fieldInputValue}
className={inputClasses} className={inputClasses}
fieldsetClassName={classNames({
hidden: currentItemSkill?.id === 0,
})}
wrapperClassName="fullHeight"
type="number" type="number"
placeholder={rangeString()} placeholder={rangeString()}
min={currentItemSkill?.minValue} min={currentItemSkill?.minValue}
max={currentItemSkill?.maxValue} max={currentItemSkill?.maxValue}
step="1" step="1"
onChange={handleInputChange} onChange={handleInputChange}
visible={currentItemSkill ? 'true' : 'false'}
ref={input} ref={input}
/> />
</div> </div>