@omicronenergy/oscd-ui 0.0.13 → 0.0.15

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 (115) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/custom-elements.json +8243 -5766
  3. package/dist/action-icon/oscd-action-icon.stories.d.ts +12 -69
  4. package/dist/action-list/oscd-action-list.stories.d.ts +12 -33
  5. package/dist/action-pane/oscd-action-pane.stories.d.ts +13 -36
  6. package/dist/action-tree/oscd-action-tree.stories.d.ts +13 -36
  7. package/dist/button/OscdElevatedButton.stories.d.ts +13 -36
  8. package/dist/button/OscdFilledButton.stories.d.ts +13 -36
  9. package/dist/button/OscdFilledTonalButton.stories.d.ts +13 -36
  10. package/dist/button/OscdOutlinedButton.stories.d.ts +13 -36
  11. package/dist/button/OscdTextButton.stories.d.ts +13 -36
  12. package/dist/checkbox/OscdCheckbox.stories.d.ts +13 -36
  13. package/dist/chips/OscdAssistChip.stories.d.ts +13 -36
  14. package/dist/chips/OscdChipSet.stories.d.ts +13 -36
  15. package/dist/chips/OscdFilterChip.stories.d.ts +13 -36
  16. package/dist/chips/OscdInputChip.stories.d.ts +13 -36
  17. package/dist/chips/OscdSuggestionChip.stories.d.ts +13 -36
  18. package/dist/decorators/localstorage.d.ts +8 -0
  19. package/dist/decorators/localstorage.js +136 -0
  20. package/dist/decorators/localstorage.js.map +1 -0
  21. package/dist/decorators/localstorage.spec.d.ts +1 -0
  22. package/dist/decorators/localstorage.spec.js +138 -0
  23. package/dist/decorators/localstorage.spec.js.map +1 -0
  24. package/dist/dialog/OscdDialog.stories.d.ts +13 -36
  25. package/dist/divider/OscdDivider.stories.d.ts +13 -36
  26. package/dist/elevation/OscdElevation.stories.d.ts +13 -36
  27. package/dist/fab/OscdBrandedFab.stories.d.ts +13 -36
  28. package/dist/fab/OscdFab.stories.d.ts +13 -36
  29. package/dist/field/OscdFilledField.stories.d.ts +13 -36
  30. package/dist/field/OscdOutlinedField.stories.d.ts +13 -36
  31. package/dist/filter-button/oscd-filter-button.stories.d.ts +12 -32
  32. package/dist/focus/OscdFocusRing.stories.d.ts +13 -36
  33. package/dist/icon/OscdIcon.stories.d.ts +13 -36
  34. package/dist/iconbutton/OscdFilledIconButton.stories.d.ts +13 -36
  35. package/dist/iconbutton/OscdFilledTonalIconButton.stories.d.ts +13 -36
  36. package/dist/iconbutton/OscdIconButton.stories.d.ts +13 -36
  37. package/dist/iconbutton/OscdOutlinedIconButton.stories.d.ts +13 -36
  38. package/dist/labs/badge/OscdBadge.stories.d.ts +13 -36
  39. package/dist/labs/card/OscdElevatedCard.stories.d.ts +13 -36
  40. package/dist/labs/card/OscdFilledCard.stories.d.ts +13 -36
  41. package/dist/labs/card/OscdOutlinedCard.stories.d.ts +13 -36
  42. package/dist/labs/item/OscdItem.stories.d.ts +13 -36
  43. package/dist/labs/navigationbar/OscdNavigationBar.stories.d.ts +13 -36
  44. package/dist/labs/navigationtab/OscdNavigationTab.stories.d.ts +13 -36
  45. package/dist/labs/segmentedbutton/OscdOutlinedSegmentedButton.stories.d.ts +12 -32
  46. package/dist/labs/segmentedbuttonset/OscdOutlinedSegmentedButtonSet.stories.d.ts +12 -32
  47. package/dist/list/OscdList.stories.d.ts +13 -36
  48. package/dist/list/OscdListItem.stories.d.ts +13 -36
  49. package/dist/menu/OscdMenuItem.stories.d.ts +13 -36
  50. package/dist/menu/OscdSubMenu.stories.d.ts +23 -50
  51. package/dist/menu/OscdSubMenu.stories.js +188 -13
  52. package/dist/menu/OscdSubMenu.stories.js.map +1 -1
  53. package/dist/progress/OscdCircularProgress.stories.d.ts +13 -36
  54. package/dist/progress/OscdLinearProgress.stories.d.ts +13 -36
  55. package/dist/radio/OscdRadio.stories.d.ts +12 -32
  56. package/dist/ripple/OscdRipple.stories.d.ts +13 -36
  57. package/dist/scl-checkbox/oscd-scl-checkbox.stories.d.ts +13 -36
  58. package/dist/scl-icon/OscdSclIcon.stories.d.ts +13 -36
  59. package/dist/scl-select/oscd-scl-select.stories.d.ts +13 -36
  60. package/dist/scl-textfield/oscd-scl-text-field.stories.d.ts +13 -36
  61. package/dist/select/OscdFilledSelect.stories.d.ts +12 -32
  62. package/dist/select/OscdOutlinedSelect.stories.d.ts +12 -32
  63. package/dist/select/OscdSelectOption.stories.d.ts +12 -32
  64. package/dist/selection-list/oscd-selection-list.stories.d.ts +12 -32
  65. package/dist/selection-list/oscd-selection-list.stories.js +1 -1
  66. package/dist/selection-list/oscd-selection-list.stories.js.map +1 -1
  67. package/dist/slider/OscdSlider.stories.d.ts +13 -36
  68. package/dist/snackbar/OscdSnackbar.d.ts +133 -0
  69. package/dist/snackbar/OscdSnackbar.js +505 -0
  70. package/dist/snackbar/OscdSnackbar.js.map +1 -0
  71. package/dist/snackbar/OscdSnackbar.spec.d.ts +1 -0
  72. package/dist/snackbar/OscdSnackbar.spec.js +287 -0
  73. package/dist/snackbar/OscdSnackbar.spec.js.map +1 -0
  74. package/dist/snackbar/OscdSnackbar.stories.d.ts +22 -0
  75. package/dist/snackbar/OscdSnackbar.stories.js +214 -0
  76. package/dist/snackbar/OscdSnackbar.stories.js.map +1 -0
  77. package/dist/snackbar/oscd-snackbar.d.ts +2 -0
  78. package/dist/snackbar/oscd-snackbar.js +4 -0
  79. package/dist/snackbar/oscd-snackbar.js.map +1 -0
  80. package/dist/switch/OscdSwitch.stories.d.ts +13 -36
  81. package/dist/tabs/OscdPrimaryTab.stories.d.ts +12 -32
  82. package/dist/tabs/OscdSecondaryTab.stories.d.ts +12 -32
  83. package/dist/tabs/OscdTabs.stories.d.ts +13 -36
  84. package/dist/textfield/OscdFilledTextField.stories.d.ts +13 -36
  85. package/dist/textfield/OscdOutlinedTextField.stories.d.ts +13 -36
  86. package/dist/tree/OscdTree.d.ts +102 -0
  87. package/dist/tree/OscdTree.js +97 -0
  88. package/dist/tree/OscdTree.js.map +1 -0
  89. package/dist/tree/OscdTree.stories.d.ts +39 -0
  90. package/dist/tree/OscdTree.stories.js +488 -0
  91. package/dist/tree/OscdTree.stories.js.map +1 -0
  92. package/dist/tree/OscdTreeItem.d.ts +60 -0
  93. package/dist/tree/OscdTreeItem.js +56 -0
  94. package/dist/tree/OscdTreeItem.js.map +1 -0
  95. package/dist/tree/internal/Tree.d.ts +233 -0
  96. package/dist/tree/internal/Tree.js +732 -0
  97. package/dist/tree/internal/Tree.js.map +1 -0
  98. package/dist/tree/internal/TreeItem.d.ts +47 -0
  99. package/dist/tree/internal/TreeItem.js +257 -0
  100. package/dist/tree/internal/TreeItem.js.map +1 -0
  101. package/dist/tree/oscd-tree-item.d.ts +2 -0
  102. package/dist/tree/oscd-tree-item.js +4 -0
  103. package/dist/tree/oscd-tree-item.js.map +1 -0
  104. package/dist/tree/oscd-tree.d.ts +3 -0
  105. package/dist/tree/oscd-tree.js +5 -0
  106. package/dist/tree/oscd-tree.js.map +1 -0
  107. package/dist/tree/oscd-tree.spec.d.ts +3 -0
  108. package/dist/tree/oscd-tree.spec.js +144 -0
  109. package/dist/tree/oscd-tree.spec.js.map +1 -0
  110. package/dist/tree-grid/oscd-tree-grid.stories.d.ts +13 -36
  111. package/dist/utils/storybook/getStorybookMeta.d.ts +1 -3
  112. package/dist/utils/storybook/getStorybookMeta.js +10 -1
  113. package/dist/utils/storybook/getStorybookMeta.js.map +1 -1
  114. package/package.json +13 -6
  115. package/regenerating-library.md +4 -2
@@ -0,0 +1,133 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { OscdElevation } from '../elevation/OscdElevation.js';
3
+ import { OscdIcon } from '../icon/OscdIcon.js';
4
+ import { OscdIconButton } from '../iconbutton/OscdIconButton.js';
5
+ export type SnackbarVariant = 'info' | 'success' | 'warning' | 'error';
6
+ export type SnackbarMode = 'replace' | 'stack';
7
+ export type SnackbarAutoDismiss = boolean | number;
8
+ export type SnackbarAction = {
9
+ label: string;
10
+ onClick: () => void;
11
+ };
12
+ export type SnackbarShowOptions = {
13
+ message: string;
14
+ variant?: SnackbarVariant;
15
+ autoDismiss?: SnackbarAutoDismiss;
16
+ dismissible?: boolean;
17
+ action?: SnackbarAction;
18
+ mode?: SnackbarMode;
19
+ };
20
+ declare global {
21
+ interface HTMLElementTagNameMap {
22
+ 'oscd-snackbar': OscdSnackbar;
23
+ }
24
+ }
25
+ declare const OscdSnackbar_base: typeof LitElement & import("@open-wc/scoped-elements/lit-element.js").ScopedElementsHostConstructor;
26
+ /**
27
+ * @tagname oscd-snackbar
28
+ * @summary Snackbar banner for transient status, warning, and error messages.
29
+ *
30
+ * @cssprop [--oscd-snackbar-z-index=9999] - Stacking order for the fixed snackbar stack.
31
+ * @cssprop [--oscd-snackbar-bottom=16px] - Distance from the bottom viewport edge.
32
+ * @cssprop [--oscd-snackbar-gap=8px] - Gap between stacked snackbars.
33
+ * @cssprop [--oscd-snackbar-max-width=80vw] - Maximum snackbar stack width.
34
+ * @cssprop [--oscd-snackbar-min-width=min(360px, 80vw)] - Minimum snackbar item width.
35
+ * @cssprop [--oscd-snackbar-min-height=48px] - Minimum snackbar item height.
36
+ * @cssprop [--oscd-snackbar-container-padding=12px 16px] - Snackbar item padding.
37
+ * @cssprop [--oscd-snackbar-elevation-level=3] - Snackbar elevation level.
38
+ * @cssprop [--oscd-snackbar-enter-duration=160ms] - Show animation duration.
39
+ * @cssprop [--oscd-snackbar-exit-duration=160ms] - Hide animation duration.
40
+ * @cssprop [--oscd-snackbar-text-color=#233042] - Snackbar text color.
41
+ * @cssprop [--oscd-snackbar-font-family=var(--md-sys-typescale-body-large-font)] - Snackbar font family.
42
+ * @cssprop [--oscd-snackbar-font-size=var(--md-sys-typescale-body-large-size)] - Snackbar font size.
43
+ * @cssprop [--oscd-snackbar-line-height=var(--md-sys-typescale-body-large-line-height)] - Snackbar line height.
44
+ * @cssprop [--oscd-snackbar-message-line-clamp=3] - Maximum visible message lines before truncation.
45
+ *
46
+ * @cssprop [--oscd-snackbar-info-container-color=var(--md-sys-color-secondary-container)] - Info snackbar container color.
47
+ * @cssprop [--oscd-snackbar-info-text-color=var(--oscd-snackbar-text-color)] - Info text color.
48
+ * @cssprop [--oscd-snackbar-info-icon-color=var(--md-sys-color-on-secondary-container)] - Info icon color.
49
+ *
50
+ * @cssprop [--oscd-snackbar-success-container-color=#d8f8bd] - Success snackbar container color.
51
+ * @cssprop [--oscd-snackbar-success-text-color=var(--oscd-snackbar-text-color)] - Success text color.
52
+ * @cssprop [--oscd-snackbar-success-icon-color=#5ba300] - Success icon color.
53
+ *
54
+ * @cssprop [--oscd-snackbar-warning-container-color=#fff584] - Warning snackbar container color.
55
+ * @cssprop [--oscd-snackbar-warning-text-color=var(--oscd-snackbar-text-color)] - Warning text color.
56
+ * @cssprop [--oscd-snackbar-warning-icon-color=#f5a400] - Warning icon color.
57
+ *
58
+ * @cssprop [--oscd-snackbar-error-container-color=#ffd9df] - Error snackbar container color.
59
+ * @cssprop [--oscd-snackbar-error-text-color=var(--oscd-snackbar-text-color)] - Error text color.
60
+ * @cssprop [--oscd-snackbar-error-icon-color=#d52031] - Error icon color.
61
+ *
62
+ * @csspart snackbar - Snackbar surface.
63
+ * @csspart icon - Leading variant icon.
64
+ * @csspart message - Message text.
65
+ * @csspart action - Optional action button.
66
+ * @csspart action-icon - Icon inside the optional action button.
67
+ * @csspart action-label - Label inside the optional action button.
68
+ * @csspart close - Optional close button.
69
+ * @csspart elevation - Elevation shadow.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const id = snackbar.show({
74
+ * message: 'Validation failed',
75
+ * variant: 'error',
76
+ * autoDismiss: false,
77
+ * action: {
78
+ * label: 'See More',
79
+ * onClick: () => showValidationDetails(),
80
+ * },
81
+ * });
82
+ *
83
+ * snackbar.close(id); // closes a visible or queued notification
84
+ * snackbar.close(); // closes visible notifications and clears queued notifications
85
+ * ```
86
+ *
87
+ * @final
88
+ * @suppress {visibility}
89
+ */
90
+ export declare class OscdSnackbar extends OscdSnackbar_base {
91
+ static scopedElements: {
92
+ 'oscd-elevation': typeof OscdElevation;
93
+ 'oscd-icon': typeof OscdIcon;
94
+ 'oscd-icon-button': typeof OscdIconButton;
95
+ };
96
+ defaultAutoDismissMs: number;
97
+ autoDismissMsPerWord: number;
98
+ minAutoDismissMs: number;
99
+ maxAutoDismissMs: number;
100
+ maxVisible: number;
101
+ mode: SnackbarMode;
102
+ private notifications;
103
+ private queuedNotifications;
104
+ disconnectedCallback(): void;
105
+ /**
106
+ * Shows a notification and returns an id that can be passed to `close()`.
107
+ * In `stack` mode, notifications beyond `maxVisible` are queued until space
108
+ * becomes available. Auto-dismiss timing starts when a notification becomes
109
+ * visible, not while it is queued.
110
+ */
111
+ show(options: SnackbarShowOptions): string;
112
+ /**
113
+ * Closes a visible or queued notification by id. Without an id, closes all
114
+ * visible notifications and clears all queued notifications.
115
+ */
116
+ close(id?: string): void;
117
+ private dismissNotifications;
118
+ private handleActionClick;
119
+ private handleCloseClick;
120
+ private get visibleLimit();
121
+ private get visibleNotifications();
122
+ private static clearTimeouts;
123
+ private promoteQueuedNotifications;
124
+ private scheduleAutoDismiss;
125
+ private resolveAutoDismissMs;
126
+ private calculateAutoDismissMs;
127
+ private renderAction;
128
+ private renderCloseButton;
129
+ private renderNotification;
130
+ render(): TemplateResult;
131
+ static styles: import("lit").CSSResult;
132
+ }
133
+ export {};
@@ -0,0 +1,505 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement, nothing } from 'lit';
3
+ import { property, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
5
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
6
+ import { OscdElevation } from '../elevation/OscdElevation.js';
7
+ import { OscdIcon } from '../icon/OscdIcon.js';
8
+ import { OscdIconButton } from '../iconbutton/OscdIconButton.js';
9
+ const closeAnimationMs = 160;
10
+ const iconByVariant = {
11
+ info: 'info',
12
+ success: 'check_circle',
13
+ warning: 'warning',
14
+ error: 'cancel',
15
+ };
16
+ let nextSnackbarId = 0;
17
+ /**
18
+ * @tagname oscd-snackbar
19
+ * @summary Snackbar banner for transient status, warning, and error messages.
20
+ *
21
+ * @cssprop [--oscd-snackbar-z-index=9999] - Stacking order for the fixed snackbar stack.
22
+ * @cssprop [--oscd-snackbar-bottom=16px] - Distance from the bottom viewport edge.
23
+ * @cssprop [--oscd-snackbar-gap=8px] - Gap between stacked snackbars.
24
+ * @cssprop [--oscd-snackbar-max-width=80vw] - Maximum snackbar stack width.
25
+ * @cssprop [--oscd-snackbar-min-width=min(360px, 80vw)] - Minimum snackbar item width.
26
+ * @cssprop [--oscd-snackbar-min-height=48px] - Minimum snackbar item height.
27
+ * @cssprop [--oscd-snackbar-container-padding=12px 16px] - Snackbar item padding.
28
+ * @cssprop [--oscd-snackbar-elevation-level=3] - Snackbar elevation level.
29
+ * @cssprop [--oscd-snackbar-enter-duration=160ms] - Show animation duration.
30
+ * @cssprop [--oscd-snackbar-exit-duration=160ms] - Hide animation duration.
31
+ * @cssprop [--oscd-snackbar-text-color=#233042] - Snackbar text color.
32
+ * @cssprop [--oscd-snackbar-font-family=var(--md-sys-typescale-body-large-font)] - Snackbar font family.
33
+ * @cssprop [--oscd-snackbar-font-size=var(--md-sys-typescale-body-large-size)] - Snackbar font size.
34
+ * @cssprop [--oscd-snackbar-line-height=var(--md-sys-typescale-body-large-line-height)] - Snackbar line height.
35
+ * @cssprop [--oscd-snackbar-message-line-clamp=3] - Maximum visible message lines before truncation.
36
+ *
37
+ * @cssprop [--oscd-snackbar-info-container-color=var(--md-sys-color-secondary-container)] - Info snackbar container color.
38
+ * @cssprop [--oscd-snackbar-info-text-color=var(--oscd-snackbar-text-color)] - Info text color.
39
+ * @cssprop [--oscd-snackbar-info-icon-color=var(--md-sys-color-on-secondary-container)] - Info icon color.
40
+ *
41
+ * @cssprop [--oscd-snackbar-success-container-color=#d8f8bd] - Success snackbar container color.
42
+ * @cssprop [--oscd-snackbar-success-text-color=var(--oscd-snackbar-text-color)] - Success text color.
43
+ * @cssprop [--oscd-snackbar-success-icon-color=#5ba300] - Success icon color.
44
+ *
45
+ * @cssprop [--oscd-snackbar-warning-container-color=#fff584] - Warning snackbar container color.
46
+ * @cssprop [--oscd-snackbar-warning-text-color=var(--oscd-snackbar-text-color)] - Warning text color.
47
+ * @cssprop [--oscd-snackbar-warning-icon-color=#f5a400] - Warning icon color.
48
+ *
49
+ * @cssprop [--oscd-snackbar-error-container-color=#ffd9df] - Error snackbar container color.
50
+ * @cssprop [--oscd-snackbar-error-text-color=var(--oscd-snackbar-text-color)] - Error text color.
51
+ * @cssprop [--oscd-snackbar-error-icon-color=#d52031] - Error icon color.
52
+ *
53
+ * @csspart snackbar - Snackbar surface.
54
+ * @csspart icon - Leading variant icon.
55
+ * @csspart message - Message text.
56
+ * @csspart action - Optional action button.
57
+ * @csspart action-icon - Icon inside the optional action button.
58
+ * @csspart action-label - Label inside the optional action button.
59
+ * @csspart close - Optional close button.
60
+ * @csspart elevation - Elevation shadow.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const id = snackbar.show({
65
+ * message: 'Validation failed',
66
+ * variant: 'error',
67
+ * autoDismiss: false,
68
+ * action: {
69
+ * label: 'See More',
70
+ * onClick: () => showValidationDetails(),
71
+ * },
72
+ * });
73
+ *
74
+ * snackbar.close(id); // closes a visible or queued notification
75
+ * snackbar.close(); // closes visible notifications and clears queued notifications
76
+ * ```
77
+ *
78
+ * @final
79
+ * @suppress {visibility}
80
+ */
81
+ export class OscdSnackbar extends ScopedElementsMixin(LitElement) {
82
+ constructor() {
83
+ super(...arguments);
84
+ this.defaultAutoDismissMs = 5000;
85
+ this.autoDismissMsPerWord = 500;
86
+ this.minAutoDismissMs = 5000;
87
+ this.maxAutoDismissMs = 15000;
88
+ this.maxVisible = 1;
89
+ this.mode = 'replace';
90
+ this.notifications = [];
91
+ this.queuedNotifications = [];
92
+ }
93
+ disconnectedCallback() {
94
+ super.disconnectedCallback();
95
+ OscdSnackbar.clearTimeouts(this.notifications);
96
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
97
+ }
98
+ /**
99
+ * Shows a notification and returns an id that can be passed to `close()`.
100
+ * In `stack` mode, notifications beyond `maxVisible` are queued until space
101
+ * becomes available. Auto-dismiss timing starts when a notification becomes
102
+ * visible, not while it is queued.
103
+ */
104
+ show(options) {
105
+ const notification = {
106
+ id: `snackbar-${++nextSnackbarId}`,
107
+ message: options.message,
108
+ variant: options.variant ?? 'info',
109
+ dismissible: options.dismissible ?? true,
110
+ action: options.action,
111
+ autoDismiss: options.autoDismiss,
112
+ };
113
+ const mode = options.mode ?? this.mode;
114
+ if (mode === 'replace') {
115
+ this.dismissNotifications(this.notifications);
116
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
117
+ this.queuedNotifications = [];
118
+ this.notifications = [
119
+ ...this.notifications.filter(existing => !existing.closing),
120
+ notification,
121
+ ];
122
+ this.scheduleAutoDismiss(notification);
123
+ return notification.id;
124
+ }
125
+ if (this.visibleNotifications.length < this.visibleLimit) {
126
+ this.notifications = [...this.notifications, notification];
127
+ this.scheduleAutoDismiss(notification);
128
+ }
129
+ else {
130
+ this.queuedNotifications = [...this.queuedNotifications, notification];
131
+ }
132
+ return notification.id;
133
+ }
134
+ /**
135
+ * Closes a visible or queued notification by id. Without an id, closes all
136
+ * visible notifications and clears all queued notifications.
137
+ */
138
+ close(id) {
139
+ if (id) {
140
+ const queuedNotificationCount = this.queuedNotifications.length;
141
+ this.queuedNotifications = this.queuedNotifications.filter(notification => notification.id !== id);
142
+ const notifications = this.notifications.filter(notification => notification.id === id);
143
+ if (notifications.length === 0 &&
144
+ this.queuedNotifications.length !== queuedNotificationCount) {
145
+ return;
146
+ }
147
+ if (notifications.length === 0) {
148
+ return;
149
+ }
150
+ this.dismissNotifications(notifications);
151
+ return;
152
+ }
153
+ const notifications = this.notifications;
154
+ OscdSnackbar.clearTimeouts(notifications);
155
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
156
+ this.queuedNotifications = [];
157
+ if (notifications.length === 0) {
158
+ return;
159
+ }
160
+ this.dismissNotifications(notifications);
161
+ }
162
+ dismissNotifications(notifications) {
163
+ OscdSnackbar.clearTimeouts(notifications);
164
+ this.notifications = this.notifications.map(notification => notifications.includes(notification)
165
+ ? { ...notification, closing: true }
166
+ : notification);
167
+ setTimeout(() => {
168
+ this.notifications = this.notifications.filter(notification => !notifications.some(closing => closing.id === notification.id));
169
+ this.promoteQueuedNotifications();
170
+ }, closeAnimationMs);
171
+ }
172
+ handleActionClick(notification) {
173
+ notification.action?.onClick();
174
+ this.close(notification.id);
175
+ }
176
+ handleCloseClick(notification) {
177
+ this.close(notification.id);
178
+ }
179
+ get visibleLimit() {
180
+ return Math.max(1, Math.floor(this.maxVisible));
181
+ }
182
+ get visibleNotifications() {
183
+ return this.notifications.filter(notification => !notification.closing);
184
+ }
185
+ static clearTimeouts(notifications) {
186
+ notifications.forEach(notification => {
187
+ clearTimeout(notification.timeoutId);
188
+ });
189
+ }
190
+ promoteQueuedNotifications() {
191
+ const availableSlots = this.visibleLimit - this.visibleNotifications.length;
192
+ if (availableSlots <= 0 || this.queuedNotifications.length === 0) {
193
+ return;
194
+ }
195
+ const promotedNotifications = this.queuedNotifications.slice(0, availableSlots);
196
+ this.queuedNotifications = this.queuedNotifications.slice(availableSlots);
197
+ this.notifications = [...this.notifications, ...promotedNotifications];
198
+ promotedNotifications.forEach(notification => {
199
+ this.scheduleAutoDismiss(notification);
200
+ });
201
+ }
202
+ scheduleAutoDismiss(notification) {
203
+ const timeoutMs = this.resolveAutoDismissMs(notification, notification.autoDismiss);
204
+ if (timeoutMs === undefined) {
205
+ return;
206
+ }
207
+ notification.timeoutId = setTimeout(() => {
208
+ this.close(notification.id);
209
+ }, timeoutMs);
210
+ }
211
+ resolveAutoDismissMs(notification, autoDismiss) {
212
+ if (autoDismiss === false) {
213
+ return undefined;
214
+ }
215
+ if (typeof autoDismiss === 'number') {
216
+ return autoDismiss > 0 ? autoDismiss : undefined;
217
+ }
218
+ if (autoDismiss === true) {
219
+ return this.calculateAutoDismissMs(notification.message);
220
+ }
221
+ if (notification.variant === 'error' || notification.action) {
222
+ return undefined;
223
+ }
224
+ return this.calculateAutoDismissMs(notification.message);
225
+ }
226
+ calculateAutoDismissMs(message) {
227
+ if (this.defaultAutoDismissMs <= 0) {
228
+ return undefined;
229
+ }
230
+ const wordCount = message.trim().split(/\s+/).filter(Boolean).length;
231
+ const timeoutMs = this.defaultAutoDismissMs + wordCount * this.autoDismissMsPerWord;
232
+ return Math.min(this.maxAutoDismissMs, Math.max(this.minAutoDismissMs, timeoutMs));
233
+ }
234
+ renderAction(notification) {
235
+ if (!notification.action) {
236
+ return nothing;
237
+ }
238
+ return html `<button
239
+ class="action"
240
+ part="action"
241
+ type="button"
242
+ @click=${() => this.handleActionClick(notification)}
243
+ >
244
+ <oscd-icon part="action-icon">arrow_forward</oscd-icon>
245
+ <span part="action-label">${notification.action.label}</span>
246
+ </button>`;
247
+ }
248
+ renderCloseButton(notification) {
249
+ if (!notification.dismissible) {
250
+ return nothing;
251
+ }
252
+ return html `<oscd-icon-button
253
+ class="close"
254
+ part="close"
255
+ aria-label="Close"
256
+ @click=${() => this.handleCloseClick(notification)}
257
+ >
258
+ <oscd-icon>close</oscd-icon>
259
+ </oscd-icon-button>`;
260
+ }
261
+ renderNotification(notification) {
262
+ return html `<div
263
+ class=${classMap({
264
+ snackbar: true,
265
+ [notification.variant]: true,
266
+ closing: !!notification.closing,
267
+ })}
268
+ part="snackbar"
269
+ role=${notification.variant === 'error' ? 'alert' : 'status'}
270
+ >
271
+ <oscd-icon class="variant-icon" part="icon"
272
+ >${iconByVariant[notification.variant]}</oscd-icon
273
+ >
274
+ <span class="message" part="message">${notification.message}</span>
275
+ ${this.renderAction(notification)} ${this.renderCloseButton(notification)}
276
+ <oscd-elevation part="elevation"></oscd-elevation>
277
+ </div>`;
278
+ }
279
+ render() {
280
+ return html `${[...this.notifications]
281
+ .reverse()
282
+ .map(notification => this.renderNotification(notification))}`;
283
+ }
284
+ }
285
+ OscdSnackbar.scopedElements = {
286
+ 'oscd-elevation': OscdElevation,
287
+ 'oscd-icon': OscdIcon,
288
+ 'oscd-icon-button': OscdIconButton,
289
+ };
290
+ OscdSnackbar.styles = css `
291
+ :host {
292
+ box-sizing: border-box;
293
+ display: flex;
294
+ position: fixed;
295
+ bottom: var(--oscd-snackbar-bottom, 16px);
296
+ left: 50%;
297
+ flex-direction: column-reverse;
298
+ align-items: center;
299
+ gap: var(--oscd-snackbar-gap, 8px);
300
+ width: max-content;
301
+ max-width: var(--oscd-snackbar-max-width, 80vw);
302
+ transform: translateX(-50%);
303
+ z-index: var(--oscd-snackbar-z-index, 9999);
304
+ pointer-events: none;
305
+ }
306
+
307
+ .snackbar {
308
+ box-sizing: border-box;
309
+ display: grid;
310
+ position: relative;
311
+ flex: 0 0 auto;
312
+ grid-template-columns: auto minmax(0, 1fr) auto auto;
313
+ align-items: center;
314
+ width: max-content;
315
+ min-width: var(--oscd-snackbar-min-width, min(360px, 80vw));
316
+ max-width: 100%;
317
+ min-height: var(--oscd-snackbar-min-height, 48px);
318
+ padding: var(--oscd-snackbar-container-padding, 12px 16px);
319
+ --md-elevation-level: var(--oscd-snackbar-elevation-level, 3);
320
+ color: var(
321
+ --oscd-snackbar-text-color,
322
+ var(--md-sys-color-on-surface, #233042)
323
+ );
324
+ font-family: var(
325
+ --oscd-snackbar-font-family,
326
+ var(--md-sys-typescale-body-large-font)
327
+ );
328
+ font-size: var(
329
+ --oscd-snackbar-font-size,
330
+ var(--md-sys-typescale-body-large-size)
331
+ );
332
+ line-height: var(
333
+ --oscd-snackbar-line-height,
334
+ var(--md-sys-typescale-body-large-line-height)
335
+ );
336
+ pointer-events: auto;
337
+ animation: snackbar-slide-in var(--oscd-snackbar-enter-duration, 160ms)
338
+ ease-out;
339
+ }
340
+
341
+ .snackbar.closing {
342
+ pointer-events: none;
343
+ animation: snackbar-fade-out var(--oscd-snackbar-exit-duration, 160ms)
344
+ ease-in forwards;
345
+ }
346
+
347
+ .snackbar.info {
348
+ background: var(
349
+ --oscd-snackbar-info-container-color,
350
+ var(--md-sys-color-secondary-container)
351
+ );
352
+ color: var(
353
+ --oscd-snackbar-info-text-color,
354
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
355
+ );
356
+ }
357
+
358
+ .snackbar.success {
359
+ background: var(
360
+ --oscd-snackbar-success-container-color,
361
+ var(--md-sys-color-tertiary-container, #d8f8bd)
362
+ );
363
+ color: var(
364
+ --oscd-snackbar-success-text-color,
365
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
366
+ );
367
+ }
368
+
369
+ .snackbar.warning {
370
+ background: var(
371
+ --oscd-snackbar-warning-container-color,
372
+ var(--md-sys-color-error-container, #fff584)
373
+ );
374
+ color: var(
375
+ --oscd-snackbar-warning-text-color,
376
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
377
+ );
378
+ }
379
+
380
+ .snackbar.error {
381
+ background: var(
382
+ --oscd-snackbar-error-container-color,
383
+ var(--md-sys-color-error-container, #ffd9df)
384
+ );
385
+ color: var(
386
+ --oscd-snackbar-error-text-color,
387
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
388
+ );
389
+ }
390
+
391
+ .variant-icon {
392
+ width: 24px;
393
+ height: 24px;
394
+ margin-inline-end: 16px;
395
+ font-size: 24px;
396
+ color: var(
397
+ --oscd-snackbar-info-icon-color,
398
+ var(--md-sys-color-on-secondary-container)
399
+ );
400
+ }
401
+
402
+ .success .variant-icon {
403
+ color: var(
404
+ --oscd-snackbar-success-icon-color,
405
+ var(--md-sys-color-on-tertiary-container, #5ba300)
406
+ );
407
+ }
408
+
409
+ .warning .variant-icon {
410
+ color: var(
411
+ --oscd-snackbar-warning-icon-color,
412
+ var(--md-sys-color-on-error-container, #f5a400)
413
+ );
414
+ }
415
+
416
+ .error .variant-icon {
417
+ color: var(
418
+ --oscd-snackbar-error-icon-color,
419
+ var(--md-sys-color-error, #d52031)
420
+ );
421
+ }
422
+
423
+ .message {
424
+ display: -webkit-box;
425
+ min-width: 0;
426
+ overflow: hidden;
427
+ text-overflow: ellipsis;
428
+ overflow-wrap: anywhere;
429
+ white-space: normal;
430
+ -webkit-box-orient: vertical;
431
+ -webkit-line-clamp: var(--oscd-snackbar-message-line-clamp, 3);
432
+ }
433
+
434
+ .action {
435
+ display: inline-flex;
436
+ align-items: center;
437
+ gap: 8px;
438
+ min-width: max-content;
439
+ margin-inline-start: 16px;
440
+ padding: 0;
441
+ border: 0;
442
+ background: none;
443
+ color: inherit;
444
+ cursor: pointer;
445
+ font: inherit;
446
+ font-size: var(--md-sys-typescale-label-large-size);
447
+ font-weight: var(--md-sys-typescale-label-large-weight);
448
+ line-height: var(--md-sys-typescale-label-large-line-height);
449
+ }
450
+
451
+ .action oscd-icon {
452
+ width: 18px;
453
+ height: 18px;
454
+ font-size: 18px;
455
+ }
456
+
457
+ .close {
458
+ margin-inline-start: 16px;
459
+ color: inherit;
460
+ }
461
+
462
+ @keyframes snackbar-slide-in {
463
+ from {
464
+ opacity: 0;
465
+ transform: translateY(16px);
466
+ }
467
+
468
+ to {
469
+ opacity: 1;
470
+ transform: translateY(0);
471
+ }
472
+ }
473
+
474
+ @keyframes snackbar-fade-out {
475
+ from {
476
+ opacity: 1;
477
+ }
478
+
479
+ to {
480
+ opacity: 0;
481
+ }
482
+ }
483
+ `;
484
+ __decorate([
485
+ property({ type: Number, attribute: 'default-auto-dismiss-ms' })
486
+ ], OscdSnackbar.prototype, "defaultAutoDismissMs", void 0);
487
+ __decorate([
488
+ property({ type: Number, attribute: 'auto-dismiss-ms-per-word' })
489
+ ], OscdSnackbar.prototype, "autoDismissMsPerWord", void 0);
490
+ __decorate([
491
+ property({ type: Number, attribute: 'min-auto-dismiss-ms' })
492
+ ], OscdSnackbar.prototype, "minAutoDismissMs", void 0);
493
+ __decorate([
494
+ property({ type: Number, attribute: 'max-auto-dismiss-ms' })
495
+ ], OscdSnackbar.prototype, "maxAutoDismissMs", void 0);
496
+ __decorate([
497
+ property({ type: Number, attribute: 'max-visible' })
498
+ ], OscdSnackbar.prototype, "maxVisible", void 0);
499
+ __decorate([
500
+ property({ type: String })
501
+ ], OscdSnackbar.prototype, "mode", void 0);
502
+ __decorate([
503
+ state()
504
+ ], OscdSnackbar.prototype, "notifications", void 0);
505
+ //# sourceMappingURL=OscdSnackbar.js.map