@exmg/exm-snackbar 1.0.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.
- package/README.md +75 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +43 -0
- package/src/exm-snackbar.d.ts +17 -0
- package/src/exm-snackbar.js +58 -0
- package/src/styles/exm-snackbar-styles-css.d.ts +2 -0
- package/src/styles/exm-snackbar-styles-css.js +4 -0
- package/src/styles/exm-snackbar-styles.scss +31 -0
- package/src/types.d.ts +4 -0
- package/src/types.js +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# `<exm-snackbar>` [](https://www.npmjs.com/package/@exmg/exm-snackbar)
|
|
2
|
+
|
|
3
|
+
# @exmg/exm-snackbar
|
|
4
|
+
|
|
5
|
+
Snackbar element to show information and feedback based on user interaction.
|
|
6
|
+
|
|
7
|
+
Based on `mwc-snackbar`
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @exmg/exm-snackbar
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example Usage
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<exm-button unelevated @click=${() =>
|
|
19
|
+
this.shadowRoot?.querySelector<ExmgSnackbar>('#default-snackbar')?.show()}>
|
|
20
|
+
Open default
|
|
21
|
+
</exm-button>
|
|
22
|
+
<exm-snackbar id="default-snackbar" labelText="Default auto close"></exm-snackbar>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
### Slots
|
|
28
|
+
|
|
29
|
+
| Name | Description |
|
|
30
|
+
| --------- | ------------------------------------------------------------- |
|
|
31
|
+
| `icon` | Icon of the snackbar |
|
|
32
|
+
| `action` | Action element of the snackbar |
|
|
33
|
+
| `dismiss` | Dismiss element of the snackbar, used to dismiss the snackbar |
|
|
34
|
+
|
|
35
|
+
### Properties/Attributes
|
|
36
|
+
|
|
37
|
+
| Name | Type | Default | Description |
|
|
38
|
+
| --------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
39
|
+
| `variant` | `string` | _null_ | Sets the Snackbar variant, options from MWC ('positive', 'negative', 'info') |
|
|
40
|
+
| `xOffset` | `Number` | _0_ | The horizontal offset of the snackbar |
|
|
41
|
+
| `yOffset` | `Number` | _0_ | The vertical offset of the snackbar |
|
|
42
|
+
| `open` | `boolean` | Whether the snackbar is currently open. |
|
|
43
|
+
| `timeoutMs` | `number` | Automatic dismiss timeout in milliseconds. Value must be between `4000` and `10000` (or `-1` to disable the timeout completely) or an error will be thrown. Defaults to `5000` (5 seconds). |
|
|
44
|
+
| `closeOnEscape` | `boolean` | Whether the snackbar closes when it is focused and the user presses the ESC key. Defaults to `false`. |
|
|
45
|
+
| `labelText` | `string` | The text content of the label element. |
|
|
46
|
+
| `stacked` | `boolean` | Enables the _stacked_ layout (see above). |
|
|
47
|
+
| `leading` | `boolean` | Enables the _leading_ layout (see above). |
|
|
48
|
+
|
|
49
|
+
### Methods
|
|
50
|
+
|
|
51
|
+
| Name | Description |
|
|
52
|
+
| ------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
53
|
+
| `show() => void` | Opens the snackbar. |
|
|
54
|
+
| `close(reason: string = '') => void` | Closes the snackbar, optionally with the specified reason indicating why it was closed. |
|
|
55
|
+
|
|
56
|
+
### Events
|
|
57
|
+
|
|
58
|
+
| Name | Detail | Description |
|
|
59
|
+
| --------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `MDCSnackbar:opening` | `{}` | Indicates when the snackbar begins its opening animation. |
|
|
61
|
+
| `MDCSnackbar:opened` | `{}` | Indicates when the snackbar finishes its opening animation. |
|
|
62
|
+
| `MDCSnackbar:closing` | `{reason?: string}` | Indicates when the snackbar begins its closing animation. `reason` contains the reason why the snackbar closed (`'dismiss'`, `'action'`, or a custom `string` via the `close` method). |
|
|
63
|
+
| `MDCSnackbar:closed` | `{reason?: string}` | Indicates when the snackbar finishes its closing animation. `reason` contains the reason why the snackbar closed (`'dismiss'`, `'action'`, or a custom `string` via the `close` method). |
|
|
64
|
+
|
|
65
|
+
### CSS Custom Properties
|
|
66
|
+
|
|
67
|
+
| Name | Default | Description |
|
|
68
|
+
| ----------------------------- | -------------------------------------- | -------------------------------- |
|
|
69
|
+
| `--mdc-snackbar-action-color` |  `#bb86fc` | Color of the action button text. |
|
|
70
|
+
|
|
71
|
+
## Additional references
|
|
72
|
+
|
|
73
|
+
- [Additional Documentation](https://exmg.github.io/exmachina-web-components/ExmgSnackbar.html)
|
|
74
|
+
|
|
75
|
+
- [Demo](https://exmg.github.io/exmachina-web-components/demo/?el=exm-snackbar)
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exmg/exm-snackbar",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./exm-snackbar.js": "./src/exm-snackbar.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@material/mwc-snackbar": "=0.27.0",
|
|
13
|
+
"lit": "2.8.0",
|
|
14
|
+
"tslib": "^2.6.2"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@exmg/lit-cli": "1.1.13"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"web-components",
|
|
21
|
+
"lit",
|
|
22
|
+
"button"
|
|
23
|
+
],
|
|
24
|
+
"files": [
|
|
25
|
+
"**/*.scss",
|
|
26
|
+
"**/*.js",
|
|
27
|
+
"**/*.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://github.com/exmg/exmachina-web-components",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git@github.com:exmg/exm-web-components.git",
|
|
33
|
+
"directory": "packages/exm-snackbar"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build:styles": "exmg-lit-cli sass -f \"./**/*.scss\""
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "0907b55c89325d59902b98a64c352bf6e1fc81ff"
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SnackbarBase } from '@material/mwc-snackbar/mwc-snackbar-base.js';
|
|
2
|
+
export declare class ExmgSnackbar extends SnackbarBase {
|
|
3
|
+
/**
|
|
4
|
+
* Sets the Snackbar variant, options from MWC
|
|
5
|
+
* @type {String}
|
|
6
|
+
*/
|
|
7
|
+
variant: 'positive' | 'negative' | 'info' | null;
|
|
8
|
+
xOffset: number;
|
|
9
|
+
yOffset: number;
|
|
10
|
+
static styles: import("lit").CSSResult[];
|
|
11
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
12
|
+
}
|
|
13
|
+
declare global {
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
'exm-snackbar': ExmgSnackbar;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
4
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
5
|
+
import { SnackbarBase } from '@material/mwc-snackbar/mwc-snackbar-base.js';
|
|
6
|
+
import { accessibleSnackbarLabel } from '@material/mwc-snackbar/accessible-snackbar-label-directive.js';
|
|
7
|
+
import { style as newStyles } from './styles/exm-snackbar-styles-css.js';
|
|
8
|
+
import { styles } from '@material/mwc-snackbar/mwc-snackbar.css.js';
|
|
9
|
+
let ExmgSnackbar = class ExmgSnackbar extends SnackbarBase {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* Sets the Snackbar variant, options from MWC
|
|
14
|
+
* @type {String}
|
|
15
|
+
*/
|
|
16
|
+
this.variant = null;
|
|
17
|
+
this.xOffset = 0;
|
|
18
|
+
this.yOffset = 0;
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
const classes = {
|
|
22
|
+
'mdc-snackbar--stacked': this.stacked,
|
|
23
|
+
'mdc-snackbar--leading': this.leading,
|
|
24
|
+
'mdc-snackbar--positive': this.variant === 'positive',
|
|
25
|
+
'mdc-snackbar--negative': this.variant === 'negative',
|
|
26
|
+
'mdc-snackbar--info': this.variant === 'info',
|
|
27
|
+
};
|
|
28
|
+
return html ` <div
|
|
29
|
+
class="mdc-snackbar ${classMap(classes)}"
|
|
30
|
+
style="left:${this.xOffset}px; bottom:${this.yOffset}px;"
|
|
31
|
+
@keydown="${this._handleKeydown}"
|
|
32
|
+
>
|
|
33
|
+
<div class="mdc-snackbar__surface">
|
|
34
|
+
<slot name="icon"></slot>
|
|
35
|
+
${accessibleSnackbarLabel(this.labelText, this.open)}
|
|
36
|
+
<div class="mdc-snackbar__actions">
|
|
37
|
+
<slot name="action" @click="${this._handleActionClick}"></slot>
|
|
38
|
+
<slot name="dismiss" @click="${this._handleDismissClick}"></slot>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
ExmgSnackbar.styles = [styles, newStyles];
|
|
45
|
+
__decorate([
|
|
46
|
+
property({ type: String })
|
|
47
|
+
], ExmgSnackbar.prototype, "variant", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
property({ type: Number })
|
|
50
|
+
], ExmgSnackbar.prototype, "xOffset", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
property({ type: Number })
|
|
53
|
+
], ExmgSnackbar.prototype, "yOffset", void 0);
|
|
54
|
+
ExmgSnackbar = __decorate([
|
|
55
|
+
customElement('exm-snackbar')
|
|
56
|
+
], ExmgSnackbar);
|
|
57
|
+
export { ExmgSnackbar };
|
|
58
|
+
//# sourceMappingURL=exm-snackbar.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
export const style = css `:host{--exm-snackbar-positive-background-color: #12805c;--exm-snackbar-negative-background-color: #c9252d;--exm-snackbar-info-background-color: #0d66d0;--exm-snackbar-text-color: #fff}.mdc-snackbar--positive .mdc-snackbar__surface{background-color:var(--exm-snackbar-positive-background-color) !important}.mdc-snackbar--negative .mdc-snackbar__surface{background-color:var(--exm-snackbar-negative-background-color) !important}.mdc-snackbar--info .mdc-snackbar__surface{background-color:var(--exm-snackbar-info-background-color) !important}.mdc-snackbar__surface{color:var(--exm-snackbar-text-color)}slot[name=icon]::slotted(*){margin-left:12px;min-width:24px}`;
|
|
3
|
+
export default style;
|
|
4
|
+
//# sourceMappingURL=exm-snackbar-styles-css.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--exm-snackbar-positive-background-color: #12805c;
|
|
3
|
+
--exm-snackbar-negative-background-color: #c9252d;
|
|
4
|
+
--exm-snackbar-info-background-color: #0d66d0;
|
|
5
|
+
--exm-snackbar-text-color: #fff;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.mdc-snackbar--positive {
|
|
9
|
+
.mdc-snackbar__surface {
|
|
10
|
+
background-color: var(--exm-snackbar-positive-background-color) !important;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
.mdc-snackbar--negative {
|
|
14
|
+
.mdc-snackbar__surface {
|
|
15
|
+
background-color: var(--exm-snackbar-negative-background-color) !important;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
.mdc-snackbar--info {
|
|
19
|
+
.mdc-snackbar__surface {
|
|
20
|
+
background-color: var(--exm-snackbar-info-background-color) !important;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.mdc-snackbar__surface {
|
|
25
|
+
color: var(--exm-snackbar-text-color);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
slot[name='icon']::slotted(*) {
|
|
29
|
+
margin-left: 12px;
|
|
30
|
+
min-width: 24px;
|
|
31
|
+
}
|
package/src/types.d.ts
ADDED
package/src/types.js
ADDED