This commit is contained in:
Philippe Torrel
2026-10-26 10:10:08 +01:00
parent 778d1f2929
commit f8fc579c6f
12 changed files with 6751 additions and 16 deletions
File diff suppressed because it is too large Load Diff
@@ -1,11 +1,17 @@
import InputAmount from './components/inputs/InputAmount'; import InputPrice from './components/inputs/InputPrice';
function App(props) { function App(props) {
// const { } = props; // const { } = props;
return ( return (
<div className="container py-5"> <div className="container py-5">
<InputAmount /> <InputPrice />
<br />
<InputPrice currency="$" />
<br />
<InputPrice currency="€" />
<br />
<InputPrice currency="¥" />
</div> </div>
); );
} }
@@ -0,0 +1,18 @@
const InputPrice = (props) => {
const { currency = '$' } = props;
const InputGroupText = () => {
return <div className="input-group-text">{currency}</div>;
};
return (
<div className="m-input-price input-price">
<div className="input-group">
{currency === '$' && InputGroupText()}
<input type="text" placeholder="0.00" name="price" className="form-control input-price" />
{(currency === '€' || currency === '¥') && InputGroupText()}
</div>
</div>
);
};
export default InputPrice;
File diff suppressed because it is too large Load Diff
@@ -15,7 +15,9 @@ const InputPrice = (props) => {
const handleChange = (e) => { const handleChange = (e) => {
// console.log(`Preis: ${e.target.value}`); // console.log(`Preis: ${e.target.value}`);
// console.log('RegEx: ', isValidPrice(e.target.value)); // console.log('RegEx: ', isValidPrice(e.target.value));
setPrice(e.target.value); let value = Number(e.target.value);
setPrice(value);
}; };
return ( return (
@@ -29,10 +31,11 @@ const InputPrice = (props) => {
<input <input
type="number" type="number"
name="price" name="price"
placeholder="0.00" placeholder={0.0}
aria-label="Price" aria-label="Price"
className={`form-control input-price ${!isValidPrice(price) ? 'is-invalid' : 'is-valid'}`} className={`form-control input-price
step="0.01" ${!isValidPrice(price) ? 'is-invalid' : 'is-valid'}`}
step={0.01}
value={price} value={price}
onChange={handleChange} onChange={handleChange}
/> />
@@ -3,4 +3,10 @@
input { input {
text-align: center; text-align: center;
} }
.error {
border: 2px solid #c00;
}
.valid {
border: 2px solid green;
}
} }
@@ -1,7 +1,15 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react';
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
}) css: {
preprocessorOptions: {
scss: {
quietDeps: true, // Unix
silenceDeprecations: ['color-functions', 'global-builtin', 'import', 'legacy-js-api', 'if-function'],
},
},
},
});
File diff suppressed because it is too large Load Diff
@@ -1,19 +1,41 @@
import { useState } from 'react';
import { FaMinus, FaPlus } from 'react-icons/fa6'; import { FaMinus, FaPlus } from 'react-icons/fa6';
// npm install react-icons | Auf der npm Seite mit --save, ist nicht mehr nötig // npm install react-icons | Auf der npm Seite mit --save, ist nicht mehr nötig
const InputAmount = (props) => { const InputAmount = (props) => {
// const { } = props; // const { } = props;
const min = 0;
const max = 10;
const [amount, setAmount] = useState(0);
// EventHandlers ================ // EventHandlers ================
const handleChange = (e) => { const handleChange = (e) => {
console.log(e); // Event-Objekte wurden um React Methoden und Eigenschaften erweitert. (SyntheticBaseEvent anstatt InputEvent) console.log(e); // Event-Objekte wurden um React Methoden und Eigenschaften erweitert. (SyntheticBaseEvent anstatt InputEvent)
console.log(e.target.value);
const value = Number(e.target.value);
if (isNaN(value) || value > max) return;
setAmount(value);
};
const handleClickDecrease = (e) => {
if (amount <= min) return;
setAmount(amount - 1);
};
const handleClickIncrease = (e) => {
if (amount >= max) return;
setAmount(amount + 1);
}; };
return ( return (
<div className="m-input-amount input-amount"> <div className="m-input-amount input-amount">
<div className="input-group mb-3"> <div className="input-group mb-3">
<span className="input-group-text"> <span className="input-group-text">
<button className="btn btn-dark button-decrease" aria-label="Decrease Amount"> <button
className="btn btn-dark button-decrease"
aria-label="Decrease Amount"
onClick={handleClickDecrease}
disabled={amount <= min}>
<FaMinus /> <FaMinus />
</button> </button>
</span> </span>
@@ -21,12 +43,19 @@ const InputAmount = (props) => {
type="number" type="number"
name="amount" name="amount"
placeholder="0" placeholder="0"
min={min}
max={max}
aria-label="Amount" aria-label="Amount"
className="form-control input-amount" className="form-control input-amount"
onChange={handleChange} onChange={handleChange}
value={amount}
/> />
<span className="input-group-text"> <span className="input-group-text">
<button className="btn btn-dark button-increase" aria-label="Increase Amount"> <button
className="btn btn-dark button-increase"
aria-label="Increase Amount"
onClick={handleClickIncrease}
disabled={amount >= max}>
<FaPlus /> <FaPlus />
</button> </button>
</span> </span>
@@ -23,7 +23,7 @@
value="0" value="0"
onchange="console.log(this.value)" /> onchange="console.log(this.value)" />
<hr /> <hr />
<input type="text" name="text" class="form-control input-text" oninput="console.log(this.value)" /> <input type="number" name="text" class="form-control input-text" oninput="console.log(this.value)" />
</div> </div>
</main> </main>
<script> <script>
@@ -14,10 +14,10 @@ const InputAmount = (props) => {
console.log(e.currentTarget.name); console.log(e.currentTarget.name);
switch (e.currentTarget.name) { switch (e.currentTarget.name) {
case 'increase': case 'increase':
console.loge('inc'); console.log('inc');
break; break;
case 'decrease': case 'decrease':
console.loge('dec'); console.log('dec');
break; break;
default: //nothing default: //nothing
} }
@@ -17,7 +17,6 @@ const InputAmount = (props) => {
}; };
const handleClick = (e) => { const handleClick = (e) => {
console.log('Event: ', e); console.log('Event: ', e);
console.log(e.currentTarget.name); console.log(e.currentTarget.name);
switch (e.currentTarget.name) { switch (e.currentTarget.name) {
case 'increase': case 'increase':