Add success-toast

This commit is contained in:
Stanislav Romanov 2022-09-13 17:27:17 +03:00
parent 8c7e93db4d
commit e92f698d4a
6 changed files with 54 additions and 24 deletions

View file

@ -0,0 +1,19 @@
<Toast>
<div class='inline-flex flex-shrink-0 justify-center items-center self-start'>
<Icons::Loading @spin={{true}} class='mr-4' />
</div>
<div>
{{@text}}
</div>
<button
type='button'
class='ml-auto self-start'
{{! data-dismiss-target='#toast-default' }}
aria-label='Close'
{{on 'click' @onClose}}
>
<Icons::Close />
</button>
</Toast>

View file

@ -0,0 +1,3 @@
import Component from '@glimmer/component';
export default class SuccessToastComponent extends Component {}

View file

@ -2,26 +2,8 @@
<div
class='flex items-center p-4 w-full max-w-xs border rounded shadow-sm'
role='alert'
{{did-insert this.registerInPlate}}
{{did-insert this.registerInQueue}}
>
<div
class='inline-flex flex-shrink-0 justify-center items-center self-start'
>
<Icons::Loading @spin={{true}} class='mr-4' />
</div>
<div>
{{@text}}
</div>
<button
type='button'
class='ml-auto self-start'
{{! data-dismiss-target='#toast-default' }}
aria-label='Close'
{{on 'click' this.triggerOnClose}}
>
<Icons::Close />
</button>
{{yield (hash triggerOnClose=this.triggerOnClose)}}
</div>
{{/in-element}}

View file

@ -12,7 +12,7 @@ export default class ToastComponent extends Component {
}
@action
registerInPlate() {
registerInQueue() {
this.toasts.add(this);
registerDestructor(this, () => {

View file

@ -1,12 +1,12 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import Toast from '../components/toast';
import SuccessToast from '../components/success-toast';
import { hbs } from 'ember-template-imports';
import { fn } from '@ember/helper';
export default class ToastsService extends Service {
@tracked container = [];
@tracked plate = [];
@tracked queue = [];
constructor() {
super();
@ -21,7 +21,7 @@ export default class ToastsService extends Service {
this.container = this.container.filter((item) => item !== wrapper);
};
const wrapper = hbs`<Toast @text={{text}} @onClose={{onClose}} />`;
const wrapper = hbs`<SuccessToast @text={{text}} @onClose={{onClose}} />`;
this.container = this.container.concat([wrapper]);
}

View file

@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'meiliadmin/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | success-toast', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`<SuccessToast />`);
assert.dom(this.element).hasText('');
// Template block usage:
await render(hbs`
<SuccessToast>
template block text
</SuccessToast>
`);
assert.dom(this.element).hasText('template block text');
});
});