-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #622 from MTES-MCT/master
Release 09/01/2025
- Loading branch information
Showing
26 changed files
with
467 additions
and
283 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react"; | ||
import { Input } from "./Input"; | ||
|
||
export const NumericInput = ({ | ||
initialValue, | ||
onChangeValue, | ||
label, | ||
required = false, | ||
min = 0, | ||
max | ||
}) => { | ||
const [value, setValue] = React.useState(initialValue); | ||
const [touched, setTouched] = React.useState(false); | ||
const state = React.useMemo( | ||
() => (touched && (value < min || value > max) ? "error" : "default"), | ||
[touched, min, max, value] | ||
); | ||
React.useEffect(() => { | ||
onChangeValue(value); | ||
}, [value]); | ||
const errorMessage = React.useMemo(() => { | ||
if (!touched) { | ||
return ""; | ||
} | ||
if (!max || isNaN(parseInt(max))) { | ||
return `Veuillez entrer une valeur supérieure à ${min}`; | ||
} | ||
return `Veuillez entrer une valeur comprise entre ${min} et ${max}`; | ||
}, [touched, min, max, value]); | ||
|
||
const handleChange = event => { | ||
const inputValue = event.target.value; | ||
if (!inputValue) { | ||
setValue(inputValue); | ||
} | ||
|
||
const parsedValue = parseInt(inputValue); | ||
|
||
if (!isNaN(parsedValue)) { | ||
setValue(parsedValue); | ||
} else { | ||
event.target.value = value; | ||
} | ||
}; | ||
|
||
return ( | ||
<Input | ||
label={label} | ||
required={required} | ||
nativeInputProps={{ | ||
value: value, | ||
onInput: handleChange, | ||
inputMode: "numeric", | ||
pattern: "[0-9]*", | ||
type: "number", | ||
onBlur: () => setTouched(true) | ||
}} | ||
type="number" | ||
state={state} | ||
stateRelatedMessage={errorMessage} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.