@aquera/nile-elements 0.0.29 → 0.0.31

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 (190) hide show
  1. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.d.ts +1 -0
  2. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js +1 -0
  3. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/index.js.map +1 -1
  4. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-button/nile-button.css.js +2 -2
  5. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-button/nile-button.css.js.map +1 -1
  6. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-button-toggle/nile-button-toggle.css.js +12 -0
  7. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-button-toggle/nile-button-toggle.css.js.map +1 -1
  8. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-calendar/nile-calendar.js +1 -3
  9. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-calendar/nile-calendar.js.map +1 -1
  10. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.css.js +1 -0
  11. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-content-editor/nile-content-editor.css.js.map +1 -1
  12. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-dialog/nile-dialog.js +0 -6
  13. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-dialog/nile-dialog.js.map +1 -1
  14. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-error-message/nile-error-message.css.js +5 -0
  15. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-error-message/nile-error-message.css.js.map +1 -1
  16. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-error-message/nile-error-message.js +5 -2
  17. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-error-message/nile-error-message.js.map +1 -1
  18. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-icon-button/nile-icon-button.d.ts +4 -0
  19. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-icon-button/nile-icon-button.js +16 -2
  20. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-icon-button/nile-icon-button.js.map +1 -1
  21. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-input/nile-input.css.js +4 -0
  22. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-input/nile-input.css.js.map +1 -1
  23. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-input/nile-input.js +4 -4
  24. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-input/nile-input.js.map +1 -1
  25. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-select/nile-select.d.ts +1 -0
  26. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-select/nile-select.js +9 -0
  27. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-select/nile-select.js.map +1 -1
  28. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js +43 -6
  29. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.css.js.map +1 -1
  30. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.d.ts +30 -17
  31. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js +143 -110
  32. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-switcher/nile-switcher.js.map +1 -1
  33. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-tab/nile-tab.css.js +1 -0
  34. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-tab/nile-tab.css.js.map +1 -1
  35. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-tab/nile-tab.js +1 -0
  36. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-tab/nile-tab.js.map +1 -1
  37. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-textarea/nile-textarea.css.js +4 -1
  38. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-textarea/nile-textarea.css.js.map +1 -1
  39. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-textarea/nile-textarea.js +5 -0
  40. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-textarea/nile-textarea.js.map +1 -1
  41. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/index.d.ts +1 -0
  42. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/index.js +2 -0
  43. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/index.js.map +1 -0
  44. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.css.d.ts +12 -0
  45. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.css.js +174 -0
  46. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.css.js.map +1 -0
  47. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.d.ts +88 -0
  48. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.js +350 -0
  49. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/src/nile-toast/nile-toast.js.map +1 -0
  50. package/.rollup.cache/opt/atlassian/pipelines/agent/build/packages/nile-elements/dist/tsconfig.tsbuildinfo +1 -1
  51. package/dist/index.cjs.js +1 -1
  52. package/dist/index.esm.js +1 -1
  53. package/dist/index.iife.js +651 -325
  54. package/dist/nile-button/nile-button.css.cjs.js +1 -1
  55. package/dist/nile-button/nile-button.css.cjs.js.map +1 -1
  56. package/dist/nile-button/nile-button.css.esm.js +2 -2
  57. package/dist/nile-button-toggle/nile-button-toggle.css.cjs.js +1 -1
  58. package/dist/nile-button-toggle/nile-button-toggle.css.cjs.js.map +1 -1
  59. package/dist/nile-button-toggle/nile-button-toggle.css.esm.js +12 -0
  60. package/dist/nile-calendar/index.cjs.js +1 -1
  61. package/dist/nile-calendar/index.esm.js +1 -1
  62. package/dist/nile-calendar/nile-calendar.cjs.js +1 -1
  63. package/dist/nile-calendar/nile-calendar.cjs.js.map +1 -1
  64. package/dist/nile-calendar/nile-calendar.esm.js +4 -6
  65. package/dist/nile-calendar/timezones.cjs.js +1 -1
  66. package/dist/nile-calendar/timezones.cjs.js.map +1 -1
  67. package/dist/nile-calendar/timezones.esm.js +1 -1
  68. package/dist/nile-content-editor/nile-content-editor.css.cjs.js +1 -1
  69. package/dist/nile-content-editor/nile-content-editor.css.cjs.js.map +1 -1
  70. package/dist/nile-content-editor/nile-content-editor.css.esm.js +1 -0
  71. package/dist/nile-dialog/nile-dialog.cjs.js.map +1 -1
  72. package/dist/nile-error-message/nile-error-message.cjs.js +1 -1
  73. package/dist/nile-error-message/nile-error-message.cjs.js.map +1 -1
  74. package/dist/nile-error-message/nile-error-message.css.cjs.js +1 -1
  75. package/dist/nile-error-message/nile-error-message.css.cjs.js.map +1 -1
  76. package/dist/nile-error-message/nile-error-message.css.esm.js +5 -0
  77. package/dist/nile-error-message/nile-error-message.esm.js +6 -4
  78. package/dist/nile-icon-button/nile-icon-button.cjs.js +1 -1
  79. package/dist/nile-icon-button/nile-icon-button.cjs.js.map +1 -1
  80. package/dist/nile-icon-button/nile-icon-button.esm.js +5 -2
  81. package/dist/nile-input/nile-input.cjs.js +1 -1
  82. package/dist/nile-input/nile-input.cjs.js.map +1 -1
  83. package/dist/nile-input/nile-input.css.cjs.js +1 -1
  84. package/dist/nile-input/nile-input.css.cjs.js.map +1 -1
  85. package/dist/nile-input/nile-input.css.esm.js +4 -0
  86. package/dist/nile-input/nile-input.esm.js +2 -2
  87. package/dist/nile-select/nile-select.cjs.js +1 -1
  88. package/dist/nile-select/nile-select.cjs.js.map +1 -1
  89. package/dist/nile-select/nile-select.esm.js +2 -2
  90. package/dist/nile-switcher/index.cjs.js +1 -1
  91. package/dist/nile-switcher/index.esm.js +1 -1
  92. package/dist/nile-switcher/nile-switcher.cjs.js +1 -1
  93. package/dist/nile-switcher/nile-switcher.cjs.js.map +1 -1
  94. package/dist/nile-switcher/nile-switcher.css.cjs.js +1 -1
  95. package/dist/nile-switcher/nile-switcher.css.cjs.js.map +1 -1
  96. package/dist/nile-switcher/nile-switcher.css.esm.js +45 -8
  97. package/dist/nile-switcher/nile-switcher.esm.js +72 -44
  98. package/dist/nile-tab/nile-tab.cjs.js +1 -1
  99. package/dist/nile-tab/nile-tab.cjs.js.map +1 -1
  100. package/dist/nile-tab/nile-tab.css.cjs.js +1 -1
  101. package/dist/nile-tab/nile-tab.css.cjs.js.map +1 -1
  102. package/dist/nile-tab/nile-tab.css.esm.js +1 -0
  103. package/dist/nile-tab/nile-tab.esm.js +1 -0
  104. package/dist/nile-textarea/nile-textarea.cjs.js +1 -1
  105. package/dist/nile-textarea/nile-textarea.cjs.js.map +1 -1
  106. package/dist/nile-textarea/nile-textarea.css.cjs.js +1 -1
  107. package/dist/nile-textarea/nile-textarea.css.cjs.js.map +1 -1
  108. package/dist/nile-textarea/nile-textarea.css.esm.js +4 -1
  109. package/dist/nile-textarea/nile-textarea.esm.js +3 -1
  110. package/dist/nile-toast/index.cjs.js +2 -0
  111. package/dist/nile-toast/index.cjs.js.map +1 -0
  112. package/dist/nile-toast/index.esm.js +1 -0
  113. package/dist/nile-toast/nile-toast.cjs.js +2 -0
  114. package/dist/nile-toast/nile-toast.cjs.js.map +1 -0
  115. package/dist/nile-toast/nile-toast.css.cjs.js +2 -0
  116. package/dist/nile-toast/nile-toast.css.cjs.js.map +1 -0
  117. package/dist/nile-toast/nile-toast.css.esm.js +162 -0
  118. package/dist/nile-toast/nile-toast.esm.js +74 -0
  119. package/dist/src/index.d.ts +1 -0
  120. package/dist/src/index.js +1 -0
  121. package/dist/src/index.js.map +1 -1
  122. package/dist/src/nile-button/nile-button.css.js +2 -2
  123. package/dist/src/nile-button/nile-button.css.js.map +1 -1
  124. package/dist/src/nile-button-toggle/nile-button-toggle.css.js +12 -0
  125. package/dist/src/nile-button-toggle/nile-button-toggle.css.js.map +1 -1
  126. package/dist/src/nile-calendar/nile-calendar.js +1 -3
  127. package/dist/src/nile-calendar/nile-calendar.js.map +1 -1
  128. package/dist/src/nile-content-editor/nile-content-editor.css.js +1 -0
  129. package/dist/src/nile-content-editor/nile-content-editor.css.js.map +1 -1
  130. package/dist/src/nile-dialog/nile-dialog.js +0 -6
  131. package/dist/src/nile-dialog/nile-dialog.js.map +1 -1
  132. package/dist/src/nile-error-message/nile-error-message.css.js +5 -0
  133. package/dist/src/nile-error-message/nile-error-message.css.js.map +1 -1
  134. package/dist/src/nile-error-message/nile-error-message.js +5 -2
  135. package/dist/src/nile-error-message/nile-error-message.js.map +1 -1
  136. package/dist/src/nile-icon-button/nile-icon-button.d.ts +4 -0
  137. package/dist/src/nile-icon-button/nile-icon-button.js +16 -2
  138. package/dist/src/nile-icon-button/nile-icon-button.js.map +1 -1
  139. package/dist/src/nile-input/nile-input.css.js +4 -0
  140. package/dist/src/nile-input/nile-input.css.js.map +1 -1
  141. package/dist/src/nile-input/nile-input.js +4 -4
  142. package/dist/src/nile-input/nile-input.js.map +1 -1
  143. package/dist/src/nile-select/nile-select.d.ts +1 -0
  144. package/dist/src/nile-select/nile-select.js +9 -0
  145. package/dist/src/nile-select/nile-select.js.map +1 -1
  146. package/dist/src/nile-switcher/nile-switcher.css.js +43 -6
  147. package/dist/src/nile-switcher/nile-switcher.css.js.map +1 -1
  148. package/dist/src/nile-switcher/nile-switcher.d.ts +30 -17
  149. package/dist/src/nile-switcher/nile-switcher.js +143 -110
  150. package/dist/src/nile-switcher/nile-switcher.js.map +1 -1
  151. package/dist/src/nile-tab/nile-tab.css.js +1 -0
  152. package/dist/src/nile-tab/nile-tab.css.js.map +1 -1
  153. package/dist/src/nile-tab/nile-tab.js +1 -0
  154. package/dist/src/nile-tab/nile-tab.js.map +1 -1
  155. package/dist/src/nile-textarea/nile-textarea.css.js +4 -1
  156. package/dist/src/nile-textarea/nile-textarea.css.js.map +1 -1
  157. package/dist/src/nile-textarea/nile-textarea.js +5 -0
  158. package/dist/src/nile-textarea/nile-textarea.js.map +1 -1
  159. package/dist/src/nile-toast/index.d.ts +1 -0
  160. package/dist/src/nile-toast/index.js +2 -0
  161. package/dist/src/nile-toast/index.js.map +1 -0
  162. package/dist/src/nile-toast/nile-toast.css.d.ts +12 -0
  163. package/dist/src/nile-toast/nile-toast.css.js +174 -0
  164. package/dist/src/nile-toast/nile-toast.css.js.map +1 -0
  165. package/dist/src/nile-toast/nile-toast.d.ts +88 -0
  166. package/dist/src/nile-toast/nile-toast.js +350 -0
  167. package/dist/src/nile-toast/nile-toast.js.map +1 -0
  168. package/dist/tsconfig.tsbuildinfo +1 -1
  169. package/package.json +1 -1
  170. package/src/index.ts +1 -0
  171. package/src/nile-button/nile-button.css.ts +2 -2
  172. package/src/nile-button-toggle/nile-button-toggle.css.ts +12 -0
  173. package/src/nile-calendar/nile-calendar.ts +1 -5
  174. package/src/nile-content-editor/nile-content-editor.css.ts +1 -0
  175. package/src/nile-dialog/nile-dialog.ts +0 -6
  176. package/src/nile-error-message/nile-error-message.css.ts +5 -0
  177. package/src/nile-error-message/nile-error-message.ts +6 -2
  178. package/src/nile-icon-button/nile-icon-button.ts +24 -5
  179. package/src/nile-input/nile-input.css.ts +4 -0
  180. package/src/nile-input/nile-input.ts +6 -6
  181. package/src/nile-select/nile-select.ts +9 -0
  182. package/src/nile-switcher/nile-switcher.css.ts +43 -6
  183. package/src/nile-switcher/nile-switcher.ts +167 -172
  184. package/src/nile-tab/nile-tab.css.ts +1 -0
  185. package/src/nile-tab/nile-tab.ts +1 -0
  186. package/src/nile-textarea/nile-textarea.css.ts +4 -1
  187. package/src/nile-textarea/nile-textarea.ts +6 -1
  188. package/src/nile-toast/index.ts +1 -0
  189. package/src/nile-toast/nile-toast.css.ts +176 -0
  190. package/src/nile-toast/nile-toast.ts +381 -0
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Copyright Aquera Inc 2023
3
+ *
4
+ * This source code is licensed under the BSD-3-Clause license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { css } from 'lit-element';
9
+
10
+ /**
11
+ * Toast CSS
12
+ */
13
+ export const styles = css`
14
+ :host {
15
+ display: contents;
16
+
17
+ /* For better DX, we'll reset the margin here so the base part can inherit it */
18
+ margin: 0;
19
+ }
20
+
21
+ [hidden] {
22
+ display: none;
23
+ }
24
+
25
+ .alert {
26
+ position: relative;
27
+ display: flex;
28
+ align-items: stretch;
29
+ border: solid 2px 2px;
30
+ border-radius: var(--nile-radius-base-standard);
31
+ margin: inherit;
32
+ padding: 12px;
33
+ gap: 10px;
34
+ }
35
+
36
+ .alert:not(.alert--has-icon) .alert__icon,
37
+ .alert:not(.alert--closable) .alert__close-button {
38
+ display: none;
39
+ }
40
+
41
+ .alert__prefix-icon-container {
42
+ height: 26px;
43
+ width: 26px;
44
+ border-radius: 4px;
45
+ padding: 6px;
46
+ box-sizing: border-box;
47
+ display: flex;
48
+ justify-content: center;
49
+ align-items: center;
50
+ }
51
+
52
+ .alert__icon {
53
+ flex: 0 0 auto;
54
+ display: flex;
55
+ align-items: center;
56
+ font-size: 10px;
57
+ }
58
+
59
+ .alert--success {
60
+ border: 1px solid var(--nile-colors-green-500);
61
+ background: var(--nile-colors-green-100);
62
+ box-shadow: 0px 14px 28px 0px rgba(119, 125, 130, 0.15);
63
+ }
64
+
65
+ .alert--success .alert__prefix-icon-container {
66
+ background: var(--nile-colors-green-500);
67
+ }
68
+
69
+ .alert--info {
70
+ border: 1px solid var(--nile-colors-blue-500);
71
+ background: var(--nile-colors-blue-100);
72
+ box-shadow: 0px 4px 8px 0px rgba(119, 125, 130, 0.15);
73
+ }
74
+
75
+ .alert--info .alert__prefix-icon-container {
76
+ background: var(--nile-colors-blue-500);
77
+ }
78
+
79
+ .alert--warning {
80
+ border: 1px solid var(--nile-colors-yellow-500);
81
+ background: var(--nile-colors-yellow-100);
82
+ box-shadow: 0px 4px 8px 0px rgba(119, 125, 130, 0.15);
83
+ }
84
+
85
+ .alert--warning .alert__prefix-icon-container {
86
+ background: var(--nile-colors-yellow-500);
87
+ }
88
+
89
+ .alert--error {
90
+ border: 1px solid var(--nile-colors-red-500);
91
+ background: var(--nile-colors-red-100);
92
+ box-shadow: 0px 4px 8px 0px rgba(119, 125, 130, 0.15);
93
+ }
94
+
95
+ .alert--error .alert__prefix-icon-container {
96
+ border: 1px solid var(--nile-colors-red-500);
97
+ background: var(--nile-colors-red-500);
98
+ }
99
+
100
+ .alert__message {
101
+ flex: 1 1 auto;
102
+ display: block;
103
+ overflow: hidden;
104
+ display: flex;
105
+ align-items: center;
106
+ flex-direction: column;
107
+ align-items: flex-start;
108
+ font-family: Colfax-regular;
109
+ font-size: 14px;
110
+ font-weight: 400;
111
+ line-height: 14px;
112
+ color: black;
113
+ }
114
+
115
+ .alert__message--title {
116
+ font-weight: 600;
117
+ }
118
+
119
+ .alert__message--content {
120
+ line-height: 21px;
121
+ }
122
+
123
+ .alert__message--content-only {
124
+ margin-top: 3px;
125
+ }
126
+
127
+ .alert__close-button {
128
+ flex: 0 0 auto;
129
+ display: flex;
130
+ align-items: center;
131
+ }
132
+
133
+ .alert__tags {
134
+ display: flex;
135
+ flex-wrap: wrap;
136
+ gap: 10px;
137
+ margin-top: 4px;
138
+ }
139
+
140
+ .alert__tag {
141
+ height: 24px;
142
+ display: flex;
143
+ border-radius: 4px;
144
+ border: 1px solid #e5e9eb;
145
+ background: var(--nile-colors-white-base);
146
+ }
147
+
148
+ .alert__tag-content {
149
+ border-left: 1px solid #e5e9eb;
150
+ display: flex;
151
+ align-items: center;
152
+ justify-content: center;
153
+ padding: 0 6px;
154
+
155
+ color: var(--nile-colors-dark-900);
156
+ font-family: Colfax-regular;
157
+ font-size: 12px;
158
+ font-style: normal;
159
+ font-weight: 500;
160
+ line-height: 12px;
161
+ letter-spacing: 0.2px;
162
+ }
163
+
164
+ .alert__tag-image {
165
+ height: 24px;
166
+ width: 24px;
167
+ border-radius: 4px 0 0 4px;
168
+ }
169
+
170
+ .alert__prefix-img{
171
+ height: 24px;
172
+ border-radius: 4px;
173
+ }
174
+ `;
175
+
176
+ export default [styles];
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Copyright Aquera Inc 2023
3
+ *
4
+ * This source code is licensed under the BSD-3-Clause license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { LitElement, CSSResultArray, TemplateResult } from 'lit-element';
9
+
10
+ import '../nile-icon-button/nile-icon-button';
11
+ import { animateTo, stopAnimations } from '../internal/animate';
12
+ import { classMap } from 'lit/directives/class-map.js';
13
+ import { customElement, property, query } from 'lit/decorators.js';
14
+ import {
15
+ getAnimation,
16
+ setDefaultAnimation,
17
+ } from '../utilities/animation-registry';
18
+ import { HasSlotController } from '../internal/slot';
19
+ import { html } from 'lit';
20
+ import { waitForEvent } from '../internal/event';
21
+ import { watch } from '../internal/watch';
22
+ import NileElement from '../internal/nile-element';
23
+ import { styles } from './nile-toast.css';
24
+ import type { CSSResultGroup } from 'lit';
25
+
26
+ const toastStack = Object.assign(document.createElement('div'), {
27
+ className: 'nile-toast-stack',
28
+ });
29
+
30
+ /**
31
+ * Nile icon component.
32
+ *
33
+ * @tag nile-toast
34
+ *
35
+ * @dependency nile-icon-button
36
+ *
37
+ * @slot - The alert's main content.
38
+ * @slot icon - An icon to show in the alert. Works best with `<nile-icon>`.
39
+ *
40
+ * @event nile-show - Emitted when the alert opens.
41
+ * @event nile-after-show - Emitted after the alert opens and all animations are complete.
42
+ * @event nile-hide - Emitted when the alert closes.
43
+ * @event nile-after-hide - Emitted after the alert closes and all animations are complete.
44
+ *
45
+ * @csspart base - The component's base wrapper.
46
+ * @csspart icon - The container that wraps the optional icon.
47
+ * @csspart message - The container that wraps the alert's main content.
48
+ * @csspart close-button - The close button, an `<nile-icon-button>`.
49
+ * @csspart close-button__base - The close button's exported `base` part.
50
+ *
51
+ * @animation alert.show - The animation to use when showing the alert.
52
+ * @animation alert.hide - The animation to use when hiding the alert.
53
+ */
54
+
55
+ @customElement('nile-toast')
56
+ export class NileToast extends NileElement {
57
+ static styles: CSSResultGroup = styles;
58
+
59
+ private autoHideTimeout: number;
60
+ private readonly hasSlotController = new HasSlotController(
61
+ this,
62
+ 'icon',
63
+ 'suffix'
64
+ );
65
+
66
+ @query('[part~="base"]') base: HTMLElement;
67
+
68
+ /**
69
+ * Indicates whether or not the alert is open. You can toggle this attribute to show and hide the alert, or you can
70
+ * use the `show()` and `hide()` methods and this attribute will reflect the alert's open state.
71
+ */
72
+ @property({ type: Boolean, reflect: true }) open = false;
73
+
74
+ @property({ type: Boolean, reflect: true }) noIcon = false;
75
+
76
+ /** Enables a close button that allows the user to dismiss the alert. */
77
+
78
+ @property({ type: Boolean, reflect: true }) closable = false;
79
+
80
+ @property({ type: Boolean, reflect: true }) hasSlottedContent = false;
81
+
82
+ @property({ type: Boolean, reflect: true }) hasSlottedIcon = false;
83
+
84
+ @property({ type: String, reflect: true }) prefixImageUrl = '';
85
+
86
+ /** The alert's theme variant. */
87
+ @property({ reflect: true }) variant:
88
+ | 'success'
89
+ | 'info'
90
+ | 'warning'
91
+ | 'error' = 'success';
92
+
93
+ /**
94
+ * The length of time, in milliseconds, the alert will show before closing itself. If the user interacts with
95
+ * the alert before it closes (e.g. moves the mouse over it), the timer will restart. Defaults to `Infinity`, meaning
96
+ * the alert will not close on its own.
97
+ */
98
+ @property({ type: Number }) duration = Infinity;
99
+
100
+ @property({ type: String }) title = '';
101
+
102
+ @property({ type: String }) content = '';
103
+
104
+ @property({ type: Array, reflect: true }) tags: any[] = [];
105
+
106
+ firstUpdated() {
107
+ this.base.hidden = !this.open;
108
+ }
109
+
110
+ private restartAutoHide() {
111
+ clearTimeout(this.autoHideTimeout);
112
+ if (this.open && this.duration < Infinity) {
113
+ this.autoHideTimeout = window.setTimeout(
114
+ () => this.hide(),
115
+ this.duration
116
+ );
117
+ }
118
+ }
119
+
120
+ private handleCloseClick() {
121
+ this.hide();
122
+ }
123
+
124
+ private handleMouseMove() {
125
+ this.restartAutoHide();
126
+ }
127
+
128
+ @watch('open', { waitUntilFirstUpdate: true })
129
+ async handleOpenChange() {
130
+ if (this.open) {
131
+ // Show
132
+ this.emit('nile-show');
133
+
134
+ if (this.duration < Infinity) {
135
+ this.restartAutoHide();
136
+ }
137
+
138
+ await stopAnimations(this.base);
139
+ this.base.hidden = false;
140
+ const { keyframes, options } = getAnimation(this, 'alert.show', {
141
+ dir: 'ltr',
142
+ });
143
+ await animateTo(this.base, keyframes, options);
144
+
145
+ this.emit('nile-after-show');
146
+ } else {
147
+ // Hide
148
+ this.emit('nile-hide');
149
+
150
+ clearTimeout(this.autoHideTimeout);
151
+
152
+ await stopAnimations(this.base);
153
+ const { keyframes, options } = getAnimation(this, 'alert.hide', {
154
+ dir: 'ltr',
155
+ });
156
+ await animateTo(this.base, keyframes, options);
157
+ this.base.hidden = true;
158
+
159
+ this.emit('nile-after-hide');
160
+ }
161
+ }
162
+
163
+ @watch('duration')
164
+ handleDurationChange() {
165
+ this.restartAutoHide();
166
+ }
167
+
168
+ /** Shows the alert. */
169
+ async show() {
170
+ if (this.open) {
171
+ return undefined;
172
+ }
173
+
174
+ this.open = true;
175
+ return waitForEvent(this, 'nile-after-show');
176
+ }
177
+
178
+ /** Hides the alert */
179
+ async hide() {
180
+ if (!this.open) {
181
+ return undefined;
182
+ }
183
+
184
+ this.open = false;
185
+ return waitForEvent(this, 'nile-after-hide');
186
+ }
187
+
188
+ getIconNameByVariant() {
189
+ switch (this.variant) {
190
+ case 'success':
191
+ return 'tick';
192
+ case 'info':
193
+ return 'helpsupport';
194
+ case 'warning':
195
+ return 'info-icon';
196
+ case 'error':
197
+ return 'cancel';
198
+ default:
199
+ return 'tick';
200
+ }
201
+ }
202
+
203
+ handleSlotChange(e: any) {
204
+ const slot = e.target;
205
+ const nodes = slot.assignedNodes({ flatten: true });
206
+ if (slot.name === 'message') {
207
+ const nodes = slot.assignedNodes({ flatten: true });
208
+ this.hasSlottedContent = nodes.length > 0;
209
+ }
210
+
211
+ if (slot.name === 'icon') {
212
+ const nodes = slot.assignedNodes({ flatten: true });
213
+ this.hasSlottedIcon = nodes.length > 0;
214
+ }
215
+
216
+ }
217
+
218
+ /**
219
+ * Displays the alert as a toast notification. This will move the alert out of its position in the DOM and, when
220
+ * dismissed, it will be removed from the DOM completely. By storing a reference to the alert, you can reuse it by
221
+ * calling this method again. The returned promise will resolve after the alert is hidden.
222
+ */
223
+ async toast() {
224
+ return new Promise<void>(resolve => {
225
+ if (toastStack.parentElement === null) {
226
+ document.body.append(toastStack);
227
+ }
228
+
229
+ toastStack.appendChild(this);
230
+
231
+ // Wait for the toast stack to render
232
+ requestAnimationFrame(() => {
233
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- force a reflow for the initial transition
234
+ this.clientWidth;
235
+ this.show();
236
+ });
237
+
238
+ this.addEventListener(
239
+ 'nile-after-hide',
240
+ () => {
241
+ toastStack.removeChild(this);
242
+ resolve();
243
+
244
+ // Remove the toast stack from the DOM when there are no more alerts
245
+ if (toastStack.querySelector('nile-alert') === null) {
246
+ toastStack.remove();
247
+ }
248
+ },
249
+ { once: true }
250
+ );
251
+ });
252
+ }
253
+
254
+ private toastTags(content: string, imageUrl: string) {
255
+ return html`
256
+ <div class="alert__tag">
257
+ <img class="alert__tag-image" src="${imageUrl}" />
258
+ <span class="alert__tag-content"> ${content} </span>
259
+ </div>
260
+ `;
261
+ }
262
+
263
+ render() {
264
+ return html`
265
+ <div
266
+ part="base"
267
+ class=${classMap({
268
+ alert: true,
269
+ 'alert--open': this.open,
270
+ 'alert--closable': this.closable,
271
+ 'alert--has-icon': this.hasSlotController.test('icon'),
272
+ 'alert--success': this.variant === 'success',
273
+ 'alert--info': this.variant === 'info',
274
+ 'alert--warning': this.variant === 'warning',
275
+ 'alert--error': this.variant === 'error',
276
+ })}
277
+ role="alert"
278
+ aria-hidden=${this.open ? 'false' : 'true'}
279
+ @mousemove=${this.handleMouseMove}
280
+ >
281
+ <slot name="icon" part="icon" ?hidden="${this.noIcon === true}">
282
+ ${!this.prefixImageUrl
283
+ ? html`
284
+ <div
285
+ class="alert__prefix-icon-container"
286
+ ?hidden="${this.hasSlottedIcon ||
287
+ this.prefixImageUrl.length > 0}"
288
+ >
289
+ <nile-icon
290
+ name="${this.getIconNameByVariant()}"
291
+ size="15"
292
+ color="white"
293
+ ></nile-icon>
294
+ </div>
295
+ `
296
+ : ``}
297
+
298
+ ${this.prefixImageUrl
299
+ ? html`
300
+ <img src="${this.prefixImageUrl}" class="alert__prefix-img" />
301
+ `
302
+ : ``}
303
+ </slot>
304
+
305
+ <slot
306
+ name="message"
307
+ part="message"
308
+ class="alert__message"
309
+ aria-live="polite"
310
+ @slotchange="${this.handleSlotChange}"
311
+ >
312
+ <div
313
+ ?hidden="${this.hasSlottedContent && this.title === ''}"
314
+ class="alert__message--title"
315
+ >
316
+ ${this.title}
317
+ </div>
318
+ <div
319
+ ?hidden="${this.hasSlottedContent && this.content === ''}"
320
+ class="alert__message--content ${this.title === ''
321
+ ? 'alert__message--content-only'
322
+ : ''}"
323
+ >
324
+ ${this.content}
325
+ </div>
326
+
327
+ ${this.tags?.length > 0
328
+ ? html`
329
+ <div class="alert__tags">
330
+ ${this.tags.map(
331
+ tag =>
332
+ html`<span
333
+ >${this.toastTags(tag.content, tag.imageUrl)}</span
334
+ >`
335
+ )}
336
+ </div>
337
+ `
338
+ : ``}
339
+ </slot>
340
+
341
+ ${this.closable
342
+ ? html`
343
+ <nile-icon-button
344
+ part="close-button"
345
+ exportparts="base:close-button__base"
346
+ class="alert__close-button"
347
+ name="close"
348
+ label="close"
349
+ size="14"
350
+ @click=${this.handleCloseClick}
351
+ ></nile-icon-button>
352
+ `
353
+ : ''}
354
+ </div>
355
+ `;
356
+ }
357
+ }
358
+
359
+ setDefaultAnimation('alert.show', {
360
+ keyframes: [
361
+ { opacity: 0, scale: 0.8 },
362
+ { opacity: 1, scale: 1 },
363
+ ],
364
+ options: { duration: 250, easing: 'ease' },
365
+ });
366
+
367
+ setDefaultAnimation('alert.hide', {
368
+ keyframes: [
369
+ { opacity: 1, scale: 1 },
370
+ { opacity: 0, scale: 0.8 },
371
+ ],
372
+ options: { duration: 250, easing: 'ease' },
373
+ });
374
+
375
+ export default NileToast;
376
+
377
+ declare global {
378
+ interface HTMLElementTagNameMap {
379
+ 'nile-toast': NileToast;
380
+ }
381
+ }