chore: 🤖 move loading-button component to core addon (#1083)
This commit is contained in:
1 parent
01e4ec0a07
commit
043dbc3736
7 files changed
+13
-58
No files matched your search
@@ -0,0 +1,18 @@
|
||||
<Rose::Button
|
||||
...attributes
|
||||
@style='inline-link-action'
|
||||
@iconLeft={{if
|
||||
this.isLoading
|
||||
'flight-icons/svg/loading-16'
|
||||
'flight-icons/svg/reload-16'
|
||||
}}
|
||||
class={{if
|
||||
this.isLoading
|
||||
'loading-button is-loading'
|
||||
'loading-button'
|
||||
}}
|
||||
@disabled={{this.isLoading}}
|
||||
{{on 'click' this.toggleRefresh}}
|
||||
>
|
||||
{{yield}}
|
||||
</Rose::Button>
|
||||
@@ -0,0 +1,20 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { later } from '@ember/runloop';
|
||||
|
||||
export default class LoadingButton extends Component {
|
||||
// =actions
|
||||
@tracked isLoading = false;
|
||||
|
||||
@action
|
||||
async toggleRefresh() {
|
||||
this.isLoading = true;
|
||||
try {
|
||||
await this.args.onClick();
|
||||
} catch (e) {
|
||||
console.error('Error while loading data', e);
|
||||
}
|
||||
later(() => (this.isLoading = false), 1000);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user