Could you help me make an MUI switch component with simple loading animation-- the action of switching it triggers a promise with a loading value. For simplicity's sake, I'll provide a 'loading' boolean arg to the component in addition to the usual switch props. Ideally it does something to indicate the loading state :)
I'll create a custom MUI Switch component with a loading animation. When the switch is toggled, it will show a loading state until the promise resolves.
I've created a custom MUI Switch component with loading animation functionality. Here's what it includes:
Features:
onToggle
propUsage Examples:
onToggle
propThe component is flexible and can be used in two main ways:
onToggle
prop that automatically handles loading stateloading
propYou can customize the appearance further by adjusting the styling in the styled component definition.
Hm, well it works but I don't love it:
I'll redesign the MUI switch component to be more sci-fi and polished, with the loading animation in the label area instead of on the switch itself.
I've completely redesigned the switch component with a more sci-fi, polished look that addresses all your concerns:
Better Loading Animation:
Improved Switch Styling:
ON/OFF Labels:
Sci-Fi Control Panel Demo:
Fully TypeScript Compatible:
The component now feels much more polished and "next level" with the loading state elegantly shown in the label area rather than disrupting the switch itself.
Instead of such an insanely customized styled switch, maybe we focus on working with the switch?
That said, this is working and doesn't look terrible... but the change is still jarring as the loading animation is much much larger than the label, so it just grows and shrinks during the load rather than staying the right size