Comments (7)
With loading icon
Screen.Recording.2023-06-07.at.09.42.55.mov
from baklava.
Maybe you can add a feature called "async" and make it automatic as you said.
But my opinion is to leave the process to the developer by adding a preventable event called before-toggle and adding the "loading" property rather than automatic.
from baklava.
The button component doesn't have internal state changes like the switch. And currently, we are not able to "cancel" a button click. We can just disable the button which is also possible in the switch but this doesn't cover our requirements here. So, in theory, we may add a cancellable before-click
event for the button as well, which automatically switches itself to the loading state if this event is canceled.
But, when I consider the implementation part, I couldn't find a way to make that "automatic" approach work for reverting back to the normal state. So I think we can consider that "automatic" way in the future with a different approach like being able to set an async function as the toggle checker
middleware, which the switch component can call and wait to make the toggle.
<bl-switch id="lightSwitcher"></bl-switch>
<script>
lightSwitcher.addToggleChecker(async ({ state }) => {
return await lightService.toggle(state);
});
</script>
So in the example above, the switch component can run toggle checker functions if provided, wait for them in loading
state then revert back to the normal state with the approval of that checker function. Like a "custom validator" as we discussed for the input component. That would be a very practical and also UX-wise well-quality solution.
But, as I mentioned earlier, we need a publicly accessible loading
state anyway and having before-toggle
event can be also helpful for some other advanced use cases. So let's just leave the setting loading
state to the developer as you suggested and leave the "automatic approach" to another discussion. 👍🏻
from baklava.
We also have a loading state for the button component. So, we can add it to the switch component, too. Good idea. 🚀
We need to make sure it is aligned with the button component, we should use our loading icon (16x16px) here. And also the speed of the rotation of the loader can be aligned with the button. 🙏🏻
Loading color will be consistent when the switch component is given primary or other colors, right?
@muratcorlu what do you think?
from baklava.
I think this would be a nice addition, indeed.
@Enes5519 What is your idea about how to implement this? I think we will need to have a new cancellable before-toggle
event to interrupt toggle and change the state to in progress. Maybe even this can be automatic, like: "when toggle requested, set state to it in progress, fire before-toggle, if it's not prevented return back to normal state and finish the toggle" But I believe there will be some other use cases that we'll want to show the switch in progress state (like, fetching the initial state of the switch by a remote call that can take some time)
from baklava.
If we add a loading
state to switch and a cancellable event named before-toggle
, if the developer wants to prevent toggling but not show a loader (which will look weird from the user perspective, like nothing happens) then the developer can just set switch.loading = false
inside the event handler. Is this not flexible enough? 😊
As we discussed in preventing dialog closing, the better approach would be to give visual feedback to the user that will mean "I got your request but something is blocking or waiting for this action". Otherwise, it'll look like a bug.
I think we need to focus on "good defaults" while giving options.
@buseselvi What do you think?
from baklava.
I think there should be an approach like the buttons here. When you prevent the click event of the button, the loading
is not active, it should not be here either.
from baklava.
Related Issues (20)
- [BUG]: Baklava select input popover close event trigger problem HOT 2
- trendyol.design Website HOT 1
- [BUG]: border-top is not coming correctly in BlInput label animation HOT 3
- Enhancing SSR Compatibility HOT 1
- npm install @trendyol/baklava
- Add Custom CSS Properties for Border Radius, Style, and Color to bl-button HOT 4
- Change table row hover color
- [BUG]: <Border of single select clear button is missing> HOT 1
- [Feature Request]: <Textarea Custom Validation>
- [BUG]: Empty bl-select causes floating-ui to throw an error HOT 2
- [BUG]: False positives for notification UI tests on PRs
- [BUG]: Searchable select hides label HOT 2
- [Feature Request]: Select search should support international character set
- [BUG]: Select search isn't cleared on option select
- [BUG]: Storybook select input triggers storybook shortcuts
- [Feature Request]: <Adding Critical Dialog Variant to Dialog Component>
- [Feature Request]: Create ADRs folder per component
- [Component]: <Spinner Component>
- [BUG]: <Split Button seperated events>
- [BUG]: Disabled select option can be selected with enter HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baklava.