jeudi 12 octobre 2023

How to implement a toggle switch on the following scenario?

I have an implemented a toggle switch based off a checkbox input; unchecked and checked.

  1. So based on the change event, if the user pressed on the left, the toggle switch will on false (unchecked) and the background color will be grey.
  2. And if user pressed on the right, toggle switch will be true (checked). And this is based on a single checked (true/false) state which is how a normal fixed toggle switch state should behave.

But there is a enhancement where I need to change the toggle switch to be more configurable such that:

  • Essentially, the enhancement now requires switch needs two states (e.g., leftState and rightState) instead of replying on just a single checked state.
  • So if the switch toggles on either left or right ends, it will give the same background color of blue where in the above scenario, it will give the background color of gray when unchecked and blue when checked.

So I tried implementing a basic toggle switch and it works and there are not many examples for the second enhancement scenario.

I am wondering if the second scenario is possible as I am blocked by this requirement.

Can anyone give any suggestion to this whether this is possible or not? Thanks!




Aucun commentaire:

Enregistrer un commentaire