8.3. Progress and capacity
The shipment fits ten pallets, but the counter happily goes on to eleven. Let's show how full it is and stop at ten.
ProgressIndicator draws the bar. Its value is a percentage from 0 to 100, so turn the count into one. Give the ten a name, capacity, and use it everywhere. When loaded reaches it, disabled switches Load pallet off.
import { Button } from '@ui5/webcomponents-react/Button';
import { ProgressIndicator } from '@ui5/webcomponents-react/ProgressIndicator';
import '@ui5/webcomponents-icons/dist/add.js';
import '@ui5/webcomponents-icons/dist/refresh.js';
import './styles.css';
const capacity = 10;
<p>{loaded} / {capacity} pallets loaded</p>
<ProgressIndicator
value={(loaded / capacity) * 100}
accessibleName="Shipment loading"
/>
<Button
icon="add"
design="Emphasized"
disabled={loaded >= capacity}
onClick={() => setLoaded(loaded + 1)}
>
Load pallet
</Button>
Need a hint?
- value is a percentage from 0 to 100, not a pallet count.
- disabled={loaded >= capacity} turns the button off; Reset turns it back on.
Load until the bar is full. At ten the button stops, and Reset starts a new shipment.