@frontile/notifications 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/addon-main.js +4 -0
  2. package/{-private → declarations/-private}/get-config.d.ts +2 -1
  3. package/declarations/-private/get-config.d.ts.map +1 -0
  4. package/{-private → declarations/-private}/manager.d.ts +2 -1
  5. package/declarations/-private/manager.d.ts.map +1 -0
  6. package/{-private → declarations/-private}/notification.d.ts +2 -1
  7. package/declarations/-private/notification.d.ts.map +1 -0
  8. package/{-private → declarations/-private}/timer.d.ts +1 -0
  9. package/declarations/-private/timer.d.ts.map +1 -0
  10. package/{-private → declarations/-private}/types.d.ts +2 -0
  11. package/declarations/-private/types.d.ts.map +1 -0
  12. package/{components → declarations/components}/notification-card.d.ts +6 -4
  13. package/declarations/components/notification-card.d.ts.map +1 -0
  14. package/{components → declarations/components}/notifications-container.d.ts +6 -4
  15. package/declarations/components/notifications-container.d.ts.map +1 -0
  16. package/declarations/get-config-a59d13fc.d.ts +3 -0
  17. package/{index.d.ts → declarations/index.d.ts} +1 -0
  18. package/declarations/index.d.ts.map +1 -0
  19. package/declarations/notification-64b501e5.d.ts +15 -0
  20. package/declarations/notifications-02bGKw8W.d.ts +10 -0
  21. package/declarations/notifications-6S2s2xJm.d.ts +10 -0
  22. package/{services → declarations/services}/notifications.d.ts +4 -1
  23. package/declarations/services/notifications.d.ts.map +1 -0
  24. package/declarations/template-registry.d.ts +7 -0
  25. package/declarations/template-registry.d.ts.map +1 -0
  26. package/declarations/timer-dbe538e6.d.ts +13 -0
  27. package/declarations/types-16c08671.d.ts +55 -0
  28. package/dist/_app_/components/notification-card.js +1 -0
  29. package/dist/_app_/components/notifications-container.js +1 -0
  30. package/dist/_app_/services/notifications.js +1 -0
  31. package/dist/components/notification-card.js +105 -0
  32. package/dist/components/notification-card.js.map +1 -0
  33. package/dist/components/notifications-container.js +53 -0
  34. package/dist/components/notifications-container.js.map +1 -0
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/notifications-02bGKw8W.js +185 -0
  38. package/dist/notifications-02bGKw8W.js.map +1 -0
  39. package/dist/services/notifications.js +4 -0
  40. package/dist/services/notifications.js.map +1 -0
  41. package/dist/template-registry.js +2 -0
  42. package/dist/template-registry.js.map +1 -0
  43. package/package.json +79 -46
  44. package/addon/-private/get-config.ts +0 -19
  45. package/addon/-private/manager.ts +0 -61
  46. package/addon/-private/notification.ts +0 -42
  47. package/addon/-private/timer.ts +0 -51
  48. package/addon/-private/types.ts +0 -66
  49. package/addon/components/notification-card.hbs +0 -44
  50. package/addon/components/notification-card.ts +0 -105
  51. package/addon/components/notifications-container.hbs +0 -19
  52. package/addon/components/notifications-container.md +0 -9
  53. package/addon/components/notifications-container.ts +0 -56
  54. package/addon/index.ts +0 -12
  55. package/addon/services/notifications.ts +0 -36
  56. package/app/components/notification-card.js +0 -1
  57. package/app/components/notifications-container.js +0 -1
  58. package/app/services/notifications.js +0 -1
  59. package/config/environment.js +0 -5
  60. package/docs/notifications-usage-demo/demo.md +0 -153
  61. package/docs/notifications-usage.md +0 -6
  62. package/index.js +0 -5
  63. package/tsconfig.json +0 -23
  64. package/types/dummy/index.d.ts +0 -0
  65. package/types/ember-get-config.d.ts +0 -3
  66. package/types/global.d.ts +0 -6
  67. package/types/index.d.ts +0 -1
@@ -1,44 +0,0 @@
1
- {{!-- template-lint-disable no-invalid-interactive --}}
2
- {{!-- template-lint-disable no-unnecessary-concat --}}
3
- {{!-- template-lint-disable no-inline-styles --}}
4
- {{!-- template-lint-disable style-concatenation --}}
5
- <div
6
- {{did-insert this.transitionIn}}
7
- {{did-update this.transitionOut @notification.isRemoving}}
8
- >
9
- {{#unless @notification.isRemoving}}
10
- <div
11
- {{on "mouseenter" this.pause}}
12
- {{on "mouseleave" this.resume}}
13
- {{css-transition (concat "notification-transition--slide-from-" @placement) isEnabled=true}}
14
- class={{use-frontile-class "notification-card" @notification.appearance}}
15
- style="{{this.styles}}"
16
- ...attributes
17
- >
18
- <div class={{use-frontile-class "notification-card" @notification.appearance part="message"}}>
19
- {{@notification.message}}
20
- </div>
21
-
22
- {{#if @notification.customActions}}
23
- <div class={{use-frontile-class "notification-card" @notification.appearance part="custom-actions"}}>
24
- {{#each @notification.customActions as |customAction|}}
25
- <button
26
- type="button"
27
- class={{use-frontile-class "notification-card" @notification.appearance part="custom-action-btn"}}
28
- {{on "click" (fn this.handleClickCustomAction customAction)}}
29
- >
30
- {{customAction.label}}
31
- </button>
32
- {{/each}}
33
- </div>
34
- {{/if}}
35
-
36
- {{#if @notification.allowClosing}}
37
- <CloseButton
38
- @onClick={{this.remove}}
39
- class={{use-frontile-class "notification-card" @notification.appearance part="close-btn"}}
40
- />
41
- {{/if}}
42
- </div>
43
- {{/unless}}
44
- </div>
@@ -1,105 +0,0 @@
1
- import Component from '@glimmer/component';
2
- import { tracked } from '@glimmer/tracking';
3
- import { action } from '@ember/object';
4
- import { inject as service } from '@ember/service';
5
- import { htmlSafe } from '@ember/template';
6
- import { NotificationsService, Notification, CustomAction } from '../.';
7
- import { later } from '@ember/runloop';
8
- import { NotificationsContainerSignature } from './notifications-container';
9
-
10
- export interface NotificationCardArgs {
11
- notification: Notification;
12
- placement: NotificationsContainerSignature['Args']['placement'];
13
-
14
- /**
15
- * Spacing for each notification, in px.
16
- *
17
- * @defaultValue 16
18
- */
19
- spacing?: number;
20
- }
21
-
22
- export interface NotificationCardSignature {
23
- Args: NotificationCardArgs;
24
- Element: HTMLDivElement | null;
25
- }
26
-
27
- export default class NotificationCard extends Component<NotificationCardSignature> {
28
- @service notifications!: NotificationsService;
29
- @tracked hasEntered = false;
30
-
31
- get styles(): unknown {
32
- const styles = [
33
- `transition-duration: ${this.args.notification.transitionDuration}ms`
34
- ];
35
-
36
- if (!this.hasEntered) {
37
- styles.push(
38
- `transition-delay: ${this.args.notification.transitionDuration}ms`
39
- );
40
- }
41
-
42
- return htmlSafe(styles.join('; '));
43
- }
44
-
45
- @action addSpacing(element: HTMLElement): void {
46
- if (this.args.placement && this.args.placement.includes('top')) {
47
- element.style.marginTop = `${this.args.spacing || 16}px`;
48
- }
49
- }
50
-
51
- @action transitionIn(element: HTMLElement): void {
52
- const spacing =
53
- typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;
54
- const expectedHeight = element.offsetHeight + spacing;
55
- const duration = this.args.notification.transitionDuration / 2;
56
-
57
- requestAnimationFrame(() => {
58
- element.style.height = '0';
59
- const transition = `height ${duration}ms ease-in ${duration}ms`;
60
- element.style.transition = transition;
61
-
62
- requestAnimationFrame(() => {
63
- element.style.height = `${expectedHeight}px`;
64
- });
65
- });
66
-
67
- later(
68
- this,
69
- () => {
70
- this.hasEntered = true;
71
- },
72
- this.args.notification.transitionDuration
73
- );
74
- }
75
-
76
- @action transitionOut(
77
- element: HTMLElement,
78
- [isExiting, ..._]: boolean[]
79
- ): void {
80
- if (isExiting) {
81
- element.style.height = '0';
82
- }
83
- }
84
-
85
- @action remove(): void {
86
- this.notifications.remove(this.args.notification);
87
- }
88
-
89
- @action pause(): void {
90
- if (this.args.notification.timer) {
91
- this.args.notification.timer.pause();
92
- }
93
- }
94
-
95
- @action resume(): void {
96
- if (this.args.notification.timer) {
97
- this.args.notification.timer.resume();
98
- }
99
- }
100
-
101
- @action handleClickCustomAction(customAction: CustomAction): void {
102
- customAction.onClick();
103
- this.remove();
104
- }
105
- }
@@ -1,19 +0,0 @@
1
- {{#if this.sortedNotifications}}
2
- <div
3
- {{did-insert this.addSpacing}}
4
- {{did-update this.addSpacing @spacing @placement}}
5
- class={{use-frontile-class "notifications-container" (if @placement @placement "bottom-right")}}
6
- role="alert"
7
- aria-live="assertive"
8
- aria-atomic="true"
9
- ...attributes
10
- >
11
- {{#each this.sortedNotifications as |notification|}}
12
- <NotificationCard
13
- @spacing={{@spacing}}
14
- @placement={{if @placement @placement "bottom-right"}}
15
- @notification={{notification}}
16
- />
17
- {{/each}}
18
- </div>
19
- {{/if}}
@@ -1,9 +0,0 @@
1
- ---
2
- category: components
3
- ---
4
-
5
- # NotificationsContainer
6
-
7
- ## API
8
-
9
- <ArgsTable @of="NotificationsContainer" />
@@ -1,56 +0,0 @@
1
- import Component from '@glimmer/component';
2
- import { inject as service } from '@ember/service';
3
- import NotificationsService from '../services/notifications';
4
- import { action } from '@ember/object';
5
- import { Notification } from '../';
6
-
7
- export interface NotificationsContainerArgs {
8
- /**
9
- * The placement of the notifications
10
- *
11
- * @defaultValue 'bottom-right'
12
- */
13
- placement?:
14
- | 'top-left'
15
- | 'top-center'
16
- | 'top-right'
17
- | 'bottom-left'
18
- | 'bottom-center'
19
- | 'bottom-right';
20
-
21
- /**
22
- * Spacing for each notification, in px.
23
- *
24
- * @defaultValue 16
25
- */
26
- spacing?: number;
27
- }
28
-
29
- export interface NotificationsContainerSignature {
30
- Args: NotificationsContainerArgs;
31
- Element: HTMLDivElement | null;
32
- }
33
-
34
- export default class NotificationsContainer extends Component<NotificationsContainerSignature> {
35
- @service notifications!: NotificationsService;
36
-
37
- get isTopPlacement(): boolean {
38
- return !!(this.args.placement && this.args.placement.includes('top'));
39
- }
40
-
41
- get sortedNotifications(): Notification[] {
42
- if (this.isTopPlacement) {
43
- return this.notifications.notifications.slice().reverse();
44
- } else {
45
- return this.notifications.notifications;
46
- }
47
- }
48
-
49
- @action addSpacing(element: HTMLElement): void {
50
- const spacing =
51
- typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;
52
- if (this.isTopPlacement) {
53
- element.style.marginTop = `${spacing}px`;
54
- }
55
- }
56
- }
package/addon/index.ts DELETED
@@ -1,12 +0,0 @@
1
- import Notification from './-private/notification';
2
- import Timer from './-private/timer';
3
- import NotificationsService from './services/notifications';
4
- import type {
5
- DefaultConfig,
6
- NotificationOptions,
7
- CustomAction
8
- } from './-private/types';
9
-
10
- export { Notification, Timer, NotificationsService };
11
-
12
- export type { NotificationOptions, DefaultConfig, CustomAction };
@@ -1,36 +0,0 @@
1
- import Service from '@ember/service';
2
- import Notification from '../-private/notification';
3
- import NotificationsManager from '../-private/manager';
4
- import { NotificationOptions } from '../-private/types';
5
-
6
- export default class NotificationsService extends Service {
7
- manager = new NotificationsManager();
8
-
9
- get notifications(): Notification[] {
10
- return this.manager.notifications;
11
- }
12
-
13
- add = (message: string, options?: NotificationOptions): Notification => {
14
- return this.manager.add(message, options);
15
- };
16
-
17
- remove = (notification?: Notification): void => {
18
- this.manager.remove(notification);
19
- };
20
-
21
- removeAll = (): void => {
22
- this.manager.removeAll();
23
- };
24
-
25
- willDestroy(): void {
26
- this.removeAll();
27
- super.willDestroy();
28
- }
29
- }
30
-
31
- // DO NOT DELETE: this is how TypeScript knows how to look up your services.
32
- declare module '@ember/service' {
33
- interface Registry {
34
- notifications: NotificationsService;
35
- }
36
- }
@@ -1 +0,0 @@
1
- export { default } from '@frontile/notifications/components/notification-card';
@@ -1 +0,0 @@
1
- export { default } from '@frontile/notifications/components/notifications-container';
@@ -1 +0,0 @@
1
- export { default } from '@frontile/notifications/services/notifications';
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (/* environment, appConfig */) {
4
- return {};
5
- };
@@ -1,153 +0,0 @@
1
- ---
2
- order: 1
3
- ---
4
-
5
- # Demo
6
-
7
- ```hbs template
8
- <div class="flex items-baseline">
9
- <FormRadioGroup
10
- @containerClass="mr-6"
11
- @label="Placement"
12
- @value={{this.placement}}
13
- @onChange={{this.setPlacement}}
14
- as |Radio|
15
- >
16
- <Radio @value="top-left" @label="top-left" />
17
- <Radio @value="top-center" @label="top-center" />
18
- <Radio @value="top-right" @label="top-right" />
19
- <Radio @value="bottom-left" @label="bottom-left" />
20
- <Radio @value="bottom-center" @label="bottom-center" />
21
- <Radio @value="bottom-right" @label="bottom-right" />
22
- </FormRadioGroup>
23
-
24
- <FormRadioGroup
25
- @label="Appearance"
26
- @value={{this.options.appearance}}
27
- @onChange={{fn this.setValue "appearance"}}
28
- as |Radio|
29
- >
30
- <Radio @value="info" @label="info" />
31
- <Radio @value="success" @label="success" />
32
- <Radio @value="warning" @label="warning" />
33
- <Radio @value="error" @label="error" />
34
- </FormRadioGroup>
35
- </div>
36
-
37
- <FormCheckbox
38
- @containerClass="mt-6"
39
- @label="Preserve"
40
- @hint="Preserved notifications will not automatically close"
41
- @checked={{this.options.preserve}}
42
- @onChange={{fn this.setValue "preserve"}}
43
- />
44
-
45
- <FormCheckbox
46
- @containerClass="mt-6"
47
- @label="Allow Closing"
48
- @hint="Allow users to close the notification"
49
- @checked={{this.options.allowClosing}}
50
- @onChange={{fn this.setValue "allowClosing"}}
51
- />
52
-
53
- <div class="flex items-baseline mt-6 ">
54
- <FormInput
55
- @containerClass="w-24 mr-6"
56
- @label="Duration"
57
- @hint="Duration is in ms"
58
- @value={{this.options.duration}}
59
- @onInput={{fn this.setValue "duration"}}
60
- />
61
-
62
- <FormSelect
63
- @containerClass="w-64"
64
- @hint="Allow users to take an action on a notification"
65
- @label="Custom Actions"
66
- @options={{this.customActions}}
67
- @isMultiple={{true}}
68
- @selected={{this.options.customActions}}
69
- @onChange={{fn this.setValue "customActions"}}
70
- as |action|
71
- >
72
- {{action.label}}
73
- </FormSelect>
74
- </div>
75
-
76
- <button
77
- type="button"
78
- {{on "click" this.addNotification}}
79
- class="px-4 py-2 mt-6 text-white bg-teal-700 rounded hover:bg-teal-800"
80
- >
81
- Add Notification
82
- </button>
83
-
84
- <NotificationsContainer @placement={{this.placement}} />
85
- ```
86
-
87
- ```ts component
88
- import Component from '@glimmer/component';
89
- import { tracked } from '@glimmer/tracking';
90
- import { inject as service } from '@ember/service';
91
- import { action } from '@ember/object';
92
- import {
93
- NotificationOptions,
94
- NotificationsService
95
- } from '@frontile/notifications';
96
-
97
- interface DemoArgs {}
98
-
99
- export default class Demo extends Component<DemoArgs> {
100
- @service notifications!: NotificationsService;
101
- @tracked options: NotificationOptions = {
102
- appearance: 'info',
103
- preserve: false,
104
- duration: 5000,
105
- allowClosing: true
106
- };
107
-
108
- @tracked placement = 'bottom-right';
109
-
110
- @tracked customActions: NotificationOptions['customActions'] = [
111
- {
112
- label: 'Ok',
113
- onClick: (): void => {
114
- // empty
115
- }
116
- },
117
- {
118
- label: 'Undo',
119
- onClick: (): void => {
120
- // empty
121
- }
122
- },
123
- {
124
- label: 'Cancel',
125
- onClick: (): void => {
126
- // empty
127
- }
128
- }
129
- ];
130
-
131
- @action setPlacement(placement: string): void {
132
- this.placement = placement;
133
- }
134
-
135
- @action setValue<T extends keyof NotificationOptions>(
136
- key: T,
137
- value: NotificationOptions[T]
138
- ): void {
139
- const options = {
140
- ...this.options,
141
- [key]: value
142
- };
143
- this.options = options;
144
- }
145
-
146
- @action addNotification(): void {
147
- this.notifications.add(
148
- 'Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna.',
149
- this.options
150
- );
151
- }
152
- }
153
- ```
@@ -1,6 +0,0 @@
1
- ---
2
- title: Usage
3
- url: /
4
- ---
5
-
6
- # Notifications Usage
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- name: require('./package').name
5
- };
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "paths": {
6
- "dummy/tests/*": ["tests/*"],
7
- "dummy/*": ["tests/dummy/app/*", "app/*"],
8
- "@frontile/notifications": ["addon"],
9
- "@frontile/notifications/*": ["addon/*"],
10
- "@frontile/notifications/test-support": ["addon-test-support"],
11
- "@frontile/notifications/test-support/*": ["addon-test-support/*"],
12
- "*": ["types/*"]
13
- }
14
- },
15
- "include": [
16
- "app/**/*",
17
- "addon/**/*",
18
- "tests/**/*",
19
- "types/**/*",
20
- "test-support/**/*",
21
- "addon-test-support/**/*", "tailwind/default-options.js"
22
- ]
23
- }
File without changes
@@ -1,3 +0,0 @@
1
- import Config from 'dummy/config/environment';
2
-
3
- export default Config;
package/types/global.d.ts DELETED
@@ -1,6 +0,0 @@
1
- // Types for compiled templates
2
- declare module '@frontile/notifications/templates/*' {
3
- import { TemplateFactory } from 'htmlbars-inline-precompile';
4
- const tmpl: TemplateFactory;
5
- export default tmpl;
6
- }
package/types/index.d.ts DELETED
@@ -1 +0,0 @@
1
- import 'ember-source/types';