@momentum-design/components 0.0.1
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/.eslintrc.js +16 -0
- package/CONTRIBUTING.md +5 -0
- package/README.md +39 -0
- package/SCRIPTS.md +15 -0
- package/TESTING.md +38 -0
- package/config/api-extractor.json +33 -0
- package/config/custom-elements-manifest.config.js +28 -0
- package/config/esbuild/configs/browser.js +21 -0
- package/config/esbuild/configs/e2e.js +10 -0
- package/config/esbuild/esbuild-e2e.config.js +22 -0
- package/config/esbuild/esbuild.config.js +9 -0
- package/config/playwright/playwright.config.ts +107 -0
- package/config/playwright/public/index.css +43 -0
- package/config/playwright/public/index.html +26 -0
- package/config/playwright/setup/Components.page.ts +163 -0
- package/config/playwright/setup/constants.ts +27 -0
- package/config/playwright/setup/index.ts +42 -0
- package/config/playwright/setup/steps/accessibility.ts +9 -0
- package/config/playwright/setup/types.ts +5 -0
- package/config/playwright/setup/utils/accessibility.ts +70 -0
- package/config/playwright/setup/utils/visual-regression.ts +35 -0
- package/config/plop/actions/AddComponent.ts +21 -0
- package/config/plop/actions/AddToComponentExports.ts +16 -0
- package/config/plop/actions/AddToComponentImports.ts +16 -0
- package/config/plop/constants/index.ts +31 -0
- package/config/plop/esbuild.config.plop.js +4 -0
- package/config/plop/generators/component/index.ts +25 -0
- package/config/plop/plopfile.ts +6 -0
- package/config/plop/prompts/index.ts +8 -0
- package/config/plop/templates/add/component/index.ts.hbs +12 -0
- package/config/plop/templates/add/component/{{componentName}}.component.ts.hbs +22 -0
- package/config/plop/templates/add/component/{{componentName}}.constants.ts.hbs +5 -0
- package/config/plop/templates/add/component/{{componentName}}.e2e-test.ts.hbs +67 -0
- package/config/plop/templates/add/component/{{componentName}}.fixtures.ts.hbs +13 -0
- package/config/plop/templates/add/component/{{componentName}}.stories.ts.hbs +18 -0
- package/config/plop/templates/add/component/{{componentName}}.styles.ts.hbs +8 -0
- package/config/plop/tsconfig.plop.json +11 -0
- package/config/storybook/MomentumStorybookTheme.js +41 -0
- package/config/storybook/main.js +21 -0
- package/config/storybook/manager.js +17 -0
- package/config/storybook/preview.js +63 -0
- package/config/storybook/provider/iconProvider.js +8 -0
- package/config/storybook/provider/themeProvider.js +31 -0
- package/config/storybook/public/background-graphic.png +0 -0
- package/config/storybook/public/fonts/Inter.var.woff2 +0 -0
- package/config/storybook/public/momentum-logo.png +0 -0
- package/config/storybook/themes/index.js +14 -0
- package/config/storybook/themes/themes.css +15 -0
- package/data/custom-elements.json +677 -0
- package/dist/browser/index.js +366 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/components/avatar/avatar.component.d.ts +28 -0
- package/dist/components/avatar/avatar.component.js +79 -0
- package/dist/components/avatar/avatar.constants.d.ts +7 -0
- package/dist/components/avatar/avatar.constants.js +14 -0
- package/dist/components/avatar/avatar.styles.d.ts +2 -0
- package/dist/components/avatar/avatar.styles.js +20 -0
- package/dist/components/avatar/avatar.types.d.ts +1 -0
- package/dist/components/avatar/avatar.types.js +2 -0
- package/dist/components/avatar/index.d.ts +7 -0
- package/dist/components/avatar/index.js +7 -0
- package/dist/components/badge/badge.component.d.ts +51 -0
- package/dist/components/badge/badge.component.js +114 -0
- package/dist/components/badge/badge.constants.d.ts +8 -0
- package/dist/components/badge/badge.constants.js +15 -0
- package/dist/components/badge/badge.styles.d.ts +2 -0
- package/dist/components/badge/badge.styles.js +26 -0
- package/dist/components/badge/badge.types.d.ts +1 -0
- package/dist/components/badge/badge.types.js +2 -0
- package/dist/components/badge/index.d.ts +7 -0
- package/dist/components/badge/index.js +7 -0
- package/dist/components/icon/icon.component.d.ts +63 -0
- package/dist/components/icon/icon.component.js +158 -0
- package/dist/components/icon/icon.constants.d.ts +6 -0
- package/dist/components/icon/icon.constants.js +12 -0
- package/dist/components/icon/icon.styles.d.ts +2 -0
- package/dist/components/icon/icon.styles.js +15 -0
- package/dist/components/icon/icon.utils.d.ts +2 -0
- package/dist/components/icon/icon.utils.js +13 -0
- package/dist/components/icon/index.d.ts +7 -0
- package/dist/components/icon/index.js +7 -0
- package/dist/components/iconprovider/iconprovider.component.d.ts +34 -0
- package/dist/components/iconprovider/iconprovider.component.js +71 -0
- package/dist/components/iconprovider/iconprovider.constants.d.ts +7 -0
- package/dist/components/iconprovider/iconprovider.constants.js +14 -0
- package/dist/components/iconprovider/iconprovider.context.d.ts +9 -0
- package/dist/components/iconprovider/iconprovider.context.js +9 -0
- package/dist/components/iconprovider/index.d.ts +7 -0
- package/dist/components/iconprovider/index.js +7 -0
- package/dist/components/text/fonts.styles.d.ts +1 -0
- package/dist/components/text/fonts.styles.js +100 -0
- package/dist/components/text/index.d.ts +7 -0
- package/dist/components/text/index.js +7 -0
- package/dist/components/text/text.component.d.ts +29 -0
- package/dist/components/text/text.component.js +41 -0
- package/dist/components/text/text.constants.d.ts +9 -0
- package/dist/components/text/text.constants.js +28 -0
- package/dist/components/text/text.styles.d.ts +2 -0
- package/dist/components/text/text.styles.js +17 -0
- package/dist/components/text/text.types.d.ts +1 -0
- package/dist/components/text/text.types.js +2 -0
- package/dist/components/text/text.utils.d.ts +20 -0
- package/dist/components/text/text.utils.js +50 -0
- package/dist/components/themeprovider/index.d.ts +7 -0
- package/dist/components/themeprovider/index.js +7 -0
- package/dist/components/themeprovider/themeprovider.component.d.ts +48 -0
- package/dist/components/themeprovider/themeprovider.component.js +86 -0
- package/dist/components/themeprovider/themeprovider.constants.d.ts +10 -0
- package/dist/components/themeprovider/themeprovider.constants.js +31 -0
- package/dist/components/themeprovider/themeprovider.context.d.ts +9 -0
- package/dist/components/themeprovider/themeprovider.context.js +13 -0
- package/dist/components/themeprovider/themeprovider.styles.d.ts +2 -0
- package/dist/components/themeprovider/themeprovider.styles.js +13 -0
- package/dist/components/themeprovider/themeprovider.types.d.ts +5 -0
- package/dist/components/themeprovider/themeprovider.types.js +2 -0
- package/dist/components/themeprovider/themeprovider.utils.d.ts +9 -0
- package/dist/components/themeprovider/themeprovider.utils.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/models/component/component.component.d.ts +38 -0
- package/dist/models/component/component.component.js +45 -0
- package/dist/models/component/component.types.d.ts +15 -0
- package/dist/models/component/component.types.js +2 -0
- package/dist/models/component/index.d.ts +3 -0
- package/dist/models/component/index.js +5 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +8 -0
- package/dist/models/provider/index.d.ts +2 -0
- package/dist/models/provider/index.js +5 -0
- package/dist/models/provider/provider.component.d.ts +70 -0
- package/dist/models/provider/provider.component.js +56 -0
- package/dist/models/provider/provider.styles.d.ts +2 -0
- package/dist/models/provider/provider.styles.js +14 -0
- package/dist/utils/provider/index.d.ts +13 -0
- package/dist/utils/provider/index.js +14 -0
- package/dist/utils/styles/index.d.ts +2 -0
- package/dist/utils/styles/index.js +14 -0
- package/dist/utils/tag-name/constants.d.ts +7 -0
- package/dist/utils/tag-name/constants.js +10 -0
- package/dist/utils/tag-name/index.d.ts +4 -0
- package/dist/utils/tag-name/index.js +10 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +2 -0
- package/jest.config.js +3 -0
- package/package.json +78 -0
- package/scripts/copyFonts.js +31 -0
- package/scripts/copyIcons.js +31 -0
- package/scripts/copyTokens.js +24 -0
- package/src/components/avatar/__screenshots__/mdc-avatar.png +0 -0
- package/src/components/avatar/avatar.component.ts +74 -0
- package/src/components/avatar/avatar.constants.ts +12 -0
- package/src/components/avatar/avatar.e2e-test.ts +70 -0
- package/src/components/avatar/avatar.stories.ts +25 -0
- package/src/components/avatar/avatar.styles.ts +20 -0
- package/src/components/avatar/avatar.types.ts +1 -0
- package/src/components/avatar/index.ts +12 -0
- package/src/components/badge/__screenshots__/mdc-badge.png +0 -0
- package/src/components/badge/badge.component.ts +121 -0
- package/src/components/badge/badge.constants.ts +13 -0
- package/src/components/badge/badge.e2e-test.ts +68 -0
- package/src/components/badge/badge.stories.ts +33 -0
- package/src/components/badge/badge.styles.ts +26 -0
- package/src/components/badge/badge.types.ts +1 -0
- package/src/components/badge/index.ts +12 -0
- package/src/components/icon/__screenshots__/mdc-icon-default.png +0 -0
- package/src/components/icon/__screenshots__/mdc-icon-scale.png +0 -0
- package/src/components/icon/icon.component.ts +155 -0
- package/src/components/icon/icon.constants.ts +10 -0
- package/src/components/icon/icon.e2e-test.ts +101 -0
- package/src/components/icon/icon.stories.ts +34 -0
- package/src/components/icon/icon.styles.ts +15 -0
- package/src/components/icon/icon.utils.ts +13 -0
- package/src/components/icon/index.ts +12 -0
- package/src/components/iconprovider/__screenshots__/mdc-iconprovider.png +0 -0
- package/src/components/iconprovider/iconprovider.component.ts +76 -0
- package/src/components/iconprovider/iconprovider.constants.ts +12 -0
- package/src/components/iconprovider/iconprovider.context.ts +16 -0
- package/src/components/iconprovider/iconprovider.e2e-test.ts +65 -0
- package/src/components/iconprovider/iconprovider.stories.ts +27 -0
- package/src/components/iconprovider/iconprovider.stories.utils.ts +27 -0
- package/src/components/iconprovider/index.ts +12 -0
- package/src/components/text/__screenshots__/mdc-text-body-large.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-body-regular.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-body-small.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-1.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-2.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-3.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-4.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-5.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-6.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-heading-7.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-image-title.png +0 -0
- package/src/components/text/__screenshots__/mdc-text-label.png +0 -0
- package/src/components/text/fonts.styles.ts +99 -0
- package/src/components/text/index.ts +12 -0
- package/src/components/text/text.component.ts +51 -0
- package/src/components/text/text.constants.ts +27 -0
- package/src/components/text/text.e2e-test.ts +76 -0
- package/src/components/text/text.stories.ts +29 -0
- package/src/components/text/text.styles.ts +17 -0
- package/src/components/text/text.types.ts +13 -0
- package/src/components/text/text.utils.ts +51 -0
- package/src/components/themeprovider/__screenshots__/mdc-themeprovider-darkWebex.png +0 -0
- package/src/components/themeprovider/__screenshots__/mdc-themeprovider-lightWebex.png +0 -0
- package/src/components/themeprovider/index.ts +12 -0
- package/src/components/themeprovider/themeprovider.component.ts +91 -0
- package/src/components/themeprovider/themeprovider.constants.ts +32 -0
- package/src/components/themeprovider/themeprovider.context.ts +18 -0
- package/src/components/themeprovider/themeprovider.e2e-test.ts +89 -0
- package/src/components/themeprovider/themeprovider.stories.styles.css +22 -0
- package/src/components/themeprovider/themeprovider.stories.ts +38 -0
- package/src/components/themeprovider/themeprovider.stories.utils.ts +23 -0
- package/src/components/themeprovider/themeprovider.styles.ts +13 -0
- package/src/components/themeprovider/themeprovider.types.ts +7 -0
- package/src/components/themeprovider/themeprovider.utils.ts +16 -0
- package/src/index.ts +22 -0
- package/src/models/component/component.component.ts +46 -0
- package/src/models/component/component.types.ts +16 -0
- package/src/models/component/index.ts +7 -0
- package/src/models/index.ts +11 -0
- package/src/models/provider/index.ts +3 -0
- package/src/models/provider/provider.component.ts +87 -0
- package/src/models/provider/provider.styles.ts +14 -0
- package/src/stories/colors.mdx +32 -0
- package/src/stories/icons.mdx +13 -0
- package/src/stories/typography.mdx +20 -0
- package/src/utils/mixins/DisabledMixin.ts +19 -0
- package/src/utils/mixins/TabIndexMixin.ts +19 -0
- package/src/utils/provider/index.ts +21 -0
- package/src/utils/styles/index.ts +13 -0
- package/src/utils/tag-name/constants.ts +10 -0
- package/src/utils/tag-name/index.ts +15 -0
- package/src/utils/types.ts +1 -0
- package/tsconfig.json +45 -0
- package/tsconfig.module.json +47 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component } from '../../models';
|
|
2
|
+
import { AvatarType } from './avatar.types';
|
|
3
|
+
/**
|
|
4
|
+
* @slot - This is a default/unnamed slot
|
|
5
|
+
*
|
|
6
|
+
* @summary This is MyElement
|
|
7
|
+
*
|
|
8
|
+
* @tag mdc-avatar
|
|
9
|
+
* @tagname mdc-avatar
|
|
10
|
+
*/
|
|
11
|
+
declare class Avatar extends Component {
|
|
12
|
+
type?: AvatarType;
|
|
13
|
+
alt?: string;
|
|
14
|
+
src?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Scale of the avatar
|
|
17
|
+
*/
|
|
18
|
+
scale?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Updates the size by setting the width and height
|
|
21
|
+
*/
|
|
22
|
+
private updateSize;
|
|
23
|
+
updated(changedProperties: Map<string, any>): void;
|
|
24
|
+
photoTemplate(): import("lit-html").TemplateResult<1>;
|
|
25
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
26
|
+
static styles: import("lit").CSSResult;
|
|
27
|
+
}
|
|
28
|
+
export default Avatar;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const lit_1 = require("lit");
|
|
5
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
6
|
+
const if_defined_js_1 = require("lit/directives/if-defined.js");
|
|
7
|
+
const avatar_styles_1 = tslib_1.__importDefault(require("./avatar.styles"));
|
|
8
|
+
const models_1 = require("../../models");
|
|
9
|
+
const avatar_constants_1 = require("./avatar.constants");
|
|
10
|
+
/**
|
|
11
|
+
* @slot - This is a default/unnamed slot
|
|
12
|
+
*
|
|
13
|
+
* @summary This is MyElement
|
|
14
|
+
*
|
|
15
|
+
* @tag mdc-avatar
|
|
16
|
+
* @tagname mdc-avatar
|
|
17
|
+
*/
|
|
18
|
+
class Avatar extends models_1.Component {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.type = avatar_constants_1.DEFAULTS.TYPE;
|
|
22
|
+
/**
|
|
23
|
+
* Scale of the avatar
|
|
24
|
+
*/
|
|
25
|
+
this.scale = avatar_constants_1.DEFAULTS.SCALE;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Updates the size by setting the width and height
|
|
29
|
+
*/
|
|
30
|
+
updateSize() {
|
|
31
|
+
if (this.scale) {
|
|
32
|
+
const value = `${this.scale}${avatar_constants_1.LENGTH_UNIT}`;
|
|
33
|
+
this.style.width = value;
|
|
34
|
+
this.style.height = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
updated(changedProperties) {
|
|
38
|
+
super.updated(changedProperties);
|
|
39
|
+
if (changedProperties.has('scale')) {
|
|
40
|
+
this.updateSize();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
photoTemplate() {
|
|
44
|
+
return (0, lit_1.html) `
|
|
45
|
+
<img
|
|
46
|
+
src="${(0, if_defined_js_1.ifDefined)(this.src)}"
|
|
47
|
+
alt="${(0, if_defined_js_1.ifDefined)(this.alt)}"
|
|
48
|
+
/>
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
let content;
|
|
53
|
+
if (this.type === 'photo') {
|
|
54
|
+
content = this.photoTemplate();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
content = (0, lit_1.html) ``;
|
|
58
|
+
}
|
|
59
|
+
return (0, lit_1.html) `${content}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Avatar.styles = avatar_styles_1.default;
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, decorators_js_1.property)({ type: String, reflect: true }),
|
|
65
|
+
tslib_1.__metadata("design:type", String)
|
|
66
|
+
], Avatar.prototype, "type", void 0);
|
|
67
|
+
tslib_1.__decorate([
|
|
68
|
+
(0, decorators_js_1.property)({ type: String }),
|
|
69
|
+
tslib_1.__metadata("design:type", String)
|
|
70
|
+
], Avatar.prototype, "alt", void 0);
|
|
71
|
+
tslib_1.__decorate([
|
|
72
|
+
(0, decorators_js_1.property)({ type: String }),
|
|
73
|
+
tslib_1.__metadata("design:type", String)
|
|
74
|
+
], Avatar.prototype, "src", void 0);
|
|
75
|
+
tslib_1.__decorate([
|
|
76
|
+
(0, decorators_js_1.property)({ type: Number }),
|
|
77
|
+
tslib_1.__metadata("design:type", Number)
|
|
78
|
+
], Avatar.prototype, "scale", void 0);
|
|
79
|
+
exports.default = Avatar;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LENGTH_UNIT = exports.DEFAULTS = exports.TAG_NAME = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tag_name_1 = tslib_1.__importDefault(require("../../utils/tag-name"));
|
|
6
|
+
const TAG_NAME = tag_name_1.default.constructTagName('avatar');
|
|
7
|
+
exports.TAG_NAME = TAG_NAME;
|
|
8
|
+
const LENGTH_UNIT = 'rem';
|
|
9
|
+
exports.LENGTH_UNIT = LENGTH_UNIT;
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
TYPE: 'photo',
|
|
12
|
+
SCALE: 1.5,
|
|
13
|
+
};
|
|
14
|
+
exports.DEFAULTS = DEFAULTS;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lit_1 = require("lit");
|
|
4
|
+
const styles = (0, lit_1.css) `
|
|
5
|
+
:host {
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
align-items: center;
|
|
9
|
+
border-radius: 100vh;
|
|
10
|
+
position: relative;
|
|
11
|
+
width: fit-content;
|
|
12
|
+
}
|
|
13
|
+
img {
|
|
14
|
+
border-radius: 100vh;
|
|
15
|
+
height: inherit;
|
|
16
|
+
width: inherit;
|
|
17
|
+
object-fit: cover;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
exports.default = styles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type AvatarType = 'photo' | 'text' | 'icon' | 'multiuser';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const avatar_component_1 = tslib_1.__importDefault(require("./avatar.component"));
|
|
5
|
+
const avatar_constants_1 = require("./avatar.constants");
|
|
6
|
+
avatar_component_1.default.register(avatar_constants_1.TAG_NAME);
|
|
7
|
+
exports.default = avatar_component_1.default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Component } from '../../models';
|
|
2
|
+
import type { BadgeType } from './badge.types';
|
|
3
|
+
/**
|
|
4
|
+
* @slot - This is a default/unnamed slot
|
|
5
|
+
*
|
|
6
|
+
* @summary This is MyElement
|
|
7
|
+
*
|
|
8
|
+
* @tag mdc-badge
|
|
9
|
+
* @tagname mdc-badge
|
|
10
|
+
*/
|
|
11
|
+
declare class Badge extends Component {
|
|
12
|
+
/**
|
|
13
|
+
* Type of the badge
|
|
14
|
+
* Can be `regular`, `icon`, `text` or `warning`
|
|
15
|
+
*
|
|
16
|
+
* Default: `regular`
|
|
17
|
+
*/
|
|
18
|
+
type?: BadgeType;
|
|
19
|
+
/**
|
|
20
|
+
* Scale of the badge (works in combination with length unit)
|
|
21
|
+
*
|
|
22
|
+
* Default: `1`
|
|
23
|
+
*/
|
|
24
|
+
scale?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Length unit attribute for scale
|
|
27
|
+
*
|
|
28
|
+
* Default: `rem`
|
|
29
|
+
*/
|
|
30
|
+
lengthUnit?: string;
|
|
31
|
+
/**
|
|
32
|
+
* If `type` is set to `icon`, attribute `iconName` can
|
|
33
|
+
* be used to choose which icon should be shown
|
|
34
|
+
*
|
|
35
|
+
* If no `iconName` is provided, no icon will be rendered.
|
|
36
|
+
*/
|
|
37
|
+
iconName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* If `type` is set to `text`, attribute `text` can
|
|
40
|
+
* be used to pass in any text to be displayed in the badge.
|
|
41
|
+
*/
|
|
42
|
+
text?: string;
|
|
43
|
+
private updateSize;
|
|
44
|
+
updated(changedProperties: Map<string, any>): void;
|
|
45
|
+
iconTemplate(): import("lit-html").TemplateResult<1>;
|
|
46
|
+
textTemplate(): import("lit-html").TemplateResult<1>;
|
|
47
|
+
warningTemplate(): import("lit-html").TemplateResult<1>;
|
|
48
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
49
|
+
static styles: import("lit").CSSResult[];
|
|
50
|
+
}
|
|
51
|
+
export default Badge;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const lit_1 = require("lit");
|
|
5
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
6
|
+
const style_map_js_1 = require("lit/directives/style-map.js");
|
|
7
|
+
const models_1 = require("../../models");
|
|
8
|
+
const badge_constants_1 = require("./badge.constants");
|
|
9
|
+
const badge_styles_1 = tslib_1.__importDefault(require("./badge.styles"));
|
|
10
|
+
/**
|
|
11
|
+
* @slot - This is a default/unnamed slot
|
|
12
|
+
*
|
|
13
|
+
* @summary This is MyElement
|
|
14
|
+
*
|
|
15
|
+
* @tag mdc-badge
|
|
16
|
+
* @tagname mdc-badge
|
|
17
|
+
*/
|
|
18
|
+
class Badge extends models_1.Component {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
/**
|
|
22
|
+
* Type of the badge
|
|
23
|
+
* Can be `regular`, `icon`, `text` or `warning`
|
|
24
|
+
*
|
|
25
|
+
* Default: `regular`
|
|
26
|
+
*/
|
|
27
|
+
this.type = badge_constants_1.DEFAULTS.TYPE;
|
|
28
|
+
/**
|
|
29
|
+
* Scale of the badge (works in combination with length unit)
|
|
30
|
+
*
|
|
31
|
+
* Default: `1`
|
|
32
|
+
*/
|
|
33
|
+
this.scale = badge_constants_1.DEFAULTS.SCALE;
|
|
34
|
+
/**
|
|
35
|
+
* Length unit attribute for scale
|
|
36
|
+
*
|
|
37
|
+
* Default: `rem`
|
|
38
|
+
*/
|
|
39
|
+
this.lengthUnit = badge_constants_1.DEFAULTS.LENGTH_UNIT;
|
|
40
|
+
}
|
|
41
|
+
updateSize() {
|
|
42
|
+
// if (this.scale && this.lengthUnit) {
|
|
43
|
+
// const value = `${this.scale}${this.lengthUnit}`;
|
|
44
|
+
// this.style.height = value;
|
|
45
|
+
// if (this.type !== 'text') {
|
|
46
|
+
// this.style.width = value;
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
}
|
|
50
|
+
updated(changedProperties) {
|
|
51
|
+
super.updated(changedProperties);
|
|
52
|
+
if (changedProperties.has('scale') || changedProperties.has('lengthUnit')) {
|
|
53
|
+
this.updateSize();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
iconTemplate() {
|
|
57
|
+
return (0, lit_1.html) `<div class="mdc-badge-icon-container">
|
|
58
|
+
<mdc-icon name="${this.iconName}" scale="100" length-unit="%"></mdc-icon>
|
|
59
|
+
</div>`;
|
|
60
|
+
}
|
|
61
|
+
textTemplate() {
|
|
62
|
+
return (0, lit_1.html) `${this.text}`;
|
|
63
|
+
}
|
|
64
|
+
warningTemplate() {
|
|
65
|
+
return (0, lit_1.html) ` <mdc-icon name="${badge_constants_1.WARNING_ICON_NAME}" class="mdc-badge-warning"></mdc-icon> `;
|
|
66
|
+
}
|
|
67
|
+
render() {
|
|
68
|
+
let content;
|
|
69
|
+
const size = `${this.scale}${this.lengthUnit}`;
|
|
70
|
+
let sizeStyles = { width: size, height: size };
|
|
71
|
+
switch (this.type) {
|
|
72
|
+
case 'regular':
|
|
73
|
+
content = (0, lit_1.html) ``;
|
|
74
|
+
break;
|
|
75
|
+
case 'icon':
|
|
76
|
+
content = this.iconTemplate();
|
|
77
|
+
break;
|
|
78
|
+
case 'text':
|
|
79
|
+
content = this.textTemplate();
|
|
80
|
+
// make width flexible when text -> only set the height:
|
|
81
|
+
sizeStyles = { height: sizeStyles.height };
|
|
82
|
+
break;
|
|
83
|
+
case 'warning':
|
|
84
|
+
content = this.warningTemplate();
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
content = (0, lit_1.html) ``;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
return (0, lit_1.html) `<div class="mdc-badge-container" style=${(0, style_map_js_1.styleMap)(sizeStyles)}>${content}</div>`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Badge.styles = badge_styles_1.default;
|
|
94
|
+
tslib_1.__decorate([
|
|
95
|
+
(0, decorators_js_1.property)({ type: String, reflect: true }),
|
|
96
|
+
tslib_1.__metadata("design:type", String)
|
|
97
|
+
], Badge.prototype, "type", void 0);
|
|
98
|
+
tslib_1.__decorate([
|
|
99
|
+
(0, decorators_js_1.property)({ type: Number }),
|
|
100
|
+
tslib_1.__metadata("design:type", Number)
|
|
101
|
+
], Badge.prototype, "scale", void 0);
|
|
102
|
+
tslib_1.__decorate([
|
|
103
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'length-unit' }),
|
|
104
|
+
tslib_1.__metadata("design:type", String)
|
|
105
|
+
], Badge.prototype, "lengthUnit", void 0);
|
|
106
|
+
tslib_1.__decorate([
|
|
107
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'icon-name' }),
|
|
108
|
+
tslib_1.__metadata("design:type", String)
|
|
109
|
+
], Badge.prototype, "iconName", void 0);
|
|
110
|
+
tslib_1.__decorate([
|
|
111
|
+
(0, decorators_js_1.property)({ type: String }),
|
|
112
|
+
tslib_1.__metadata("design:type", String)
|
|
113
|
+
], Badge.prototype, "text", void 0);
|
|
114
|
+
exports.default = Badge;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WARNING_ICON_NAME = exports.DEFAULTS = exports.TAG_NAME = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tag_name_1 = tslib_1.__importDefault(require("../../utils/tag-name"));
|
|
6
|
+
const TAG_NAME = tag_name_1.default.constructTagName('badge');
|
|
7
|
+
exports.TAG_NAME = TAG_NAME;
|
|
8
|
+
const WARNING_ICON_NAME = 'warning-badge-filled';
|
|
9
|
+
exports.WARNING_ICON_NAME = WARNING_ICON_NAME;
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
TYPE: 'regular',
|
|
12
|
+
SCALE: 1,
|
|
13
|
+
LENGTH_UNIT: 'rem',
|
|
14
|
+
};
|
|
15
|
+
exports.DEFAULTS = DEFAULTS;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lit_1 = require("lit");
|
|
4
|
+
const styles_1 = require("../../utils/styles");
|
|
5
|
+
const styles = [
|
|
6
|
+
styles_1.hostFitContentStyles,
|
|
7
|
+
(0, lit_1.css) `
|
|
8
|
+
:host {
|
|
9
|
+
--mdc-badge-icon-background-color: var(--mds-color-theme-background-accent-normal);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.mdc-badge-container {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
align-items: center;
|
|
16
|
+
border-radius: 9999px;
|
|
17
|
+
background-color: var(--mdc-badge-icon-background-color);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mdc-badge-icon-container {
|
|
21
|
+
height: 80%;
|
|
22
|
+
width: 80%;
|
|
23
|
+
}
|
|
24
|
+
`,
|
|
25
|
+
];
|
|
26
|
+
exports.default = styles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BadgeType = 'regular' | 'text' | 'icon' | 'warning';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const badge_component_1 = tslib_1.__importDefault(require("./badge.component"));
|
|
5
|
+
const badge_constants_1 = require("./badge.constants");
|
|
6
|
+
badge_component_1.default.register(badge_constants_1.TAG_NAME);
|
|
7
|
+
exports.default = badge_component_1.default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Component } from '../../models';
|
|
2
|
+
/**
|
|
3
|
+
* Icon component, which has to be mounted inside of a `IconProvider`
|
|
4
|
+
* component.
|
|
5
|
+
*
|
|
6
|
+
* The `IconProvider` component defines where icons should be consumed from (`url`).
|
|
7
|
+
* This `Icon` component accepts the `name` attribute, which will be
|
|
8
|
+
* the file name of the icon to be loaded from the given `url`.
|
|
9
|
+
*
|
|
10
|
+
* Once fetched, the icon will be mounted. If fetching wasn't successful,
|
|
11
|
+
* nothing will be shown.
|
|
12
|
+
*
|
|
13
|
+
* The `scale` attribute allows scaling the icon based on the provided
|
|
14
|
+
* `length-unit` attribute (which will either come from the IconProvider or
|
|
15
|
+
* could be overridden per icon). For example:
|
|
16
|
+
* if `scale = 1` and `length-unit = 'em'`, the size of the icon will be
|
|
17
|
+
* `width: 1em; height: 1em`.
|
|
18
|
+
*
|
|
19
|
+
* For accessibility the `role` and `aria-label` of the icon can be set.
|
|
20
|
+
*
|
|
21
|
+
* @tag mdc-icon
|
|
22
|
+
* @tagname mdc-icon
|
|
23
|
+
*/
|
|
24
|
+
declare class Icon extends Component {
|
|
25
|
+
private iconData?;
|
|
26
|
+
private lengthUnitFromContext?;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the icon (= filename)
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Scale of the icon (works in combination with length unit)
|
|
33
|
+
*/
|
|
34
|
+
scale?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Length unit attribute for overridding length-unit from `IconProvider`
|
|
37
|
+
*/
|
|
38
|
+
lengthUnit?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Role attribute to be set for accessibility
|
|
41
|
+
*/
|
|
42
|
+
role: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Aria-label attribute to be set for accessibility
|
|
45
|
+
*/
|
|
46
|
+
ariaLabel: string | null;
|
|
47
|
+
private iconProviderContext;
|
|
48
|
+
/**
|
|
49
|
+
* Get Icon Data function which will fetch the icon (currently only svg)
|
|
50
|
+
* and sets state and attributes once fetched successfully
|
|
51
|
+
*/
|
|
52
|
+
private getIconData;
|
|
53
|
+
/**
|
|
54
|
+
* Updates the size by setting the width and height
|
|
55
|
+
*/
|
|
56
|
+
private updateSize;
|
|
57
|
+
private setRoleOnIcon;
|
|
58
|
+
private setAriaLabelOnIcon;
|
|
59
|
+
updated(changedProperties: Map<string, any>): void;
|
|
60
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
61
|
+
static styles: import("lit").CSSResult[];
|
|
62
|
+
}
|
|
63
|
+
export default Icon;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const lit_1 = require("lit");
|
|
5
|
+
const decorators_js_1 = require("lit/decorators.js");
|
|
6
|
+
const icon_styles_1 = tslib_1.__importDefault(require("./icon.styles"));
|
|
7
|
+
const models_1 = require("../../models");
|
|
8
|
+
const provider_1 = tslib_1.__importDefault(require("../../utils/provider"));
|
|
9
|
+
const iconprovider_component_1 = tslib_1.__importDefault(require("../iconprovider/iconprovider.component"));
|
|
10
|
+
const icon_utils_1 = require("./icon.utils");
|
|
11
|
+
const icon_constants_1 = require("./icon.constants");
|
|
12
|
+
/**
|
|
13
|
+
* Icon component, which has to be mounted inside of a `IconProvider`
|
|
14
|
+
* component.
|
|
15
|
+
*
|
|
16
|
+
* The `IconProvider` component defines where icons should be consumed from (`url`).
|
|
17
|
+
* This `Icon` component accepts the `name` attribute, which will be
|
|
18
|
+
* the file name of the icon to be loaded from the given `url`.
|
|
19
|
+
*
|
|
20
|
+
* Once fetched, the icon will be mounted. If fetching wasn't successful,
|
|
21
|
+
* nothing will be shown.
|
|
22
|
+
*
|
|
23
|
+
* The `scale` attribute allows scaling the icon based on the provided
|
|
24
|
+
* `length-unit` attribute (which will either come from the IconProvider or
|
|
25
|
+
* could be overridden per icon). For example:
|
|
26
|
+
* if `scale = 1` and `length-unit = 'em'`, the size of the icon will be
|
|
27
|
+
* `width: 1em; height: 1em`.
|
|
28
|
+
*
|
|
29
|
+
* For accessibility the `role` and `aria-label` of the icon can be set.
|
|
30
|
+
*
|
|
31
|
+
* @tag mdc-icon
|
|
32
|
+
* @tagname mdc-icon
|
|
33
|
+
*/
|
|
34
|
+
class Icon extends models_1.Component {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
/**
|
|
38
|
+
* Name of the icon (= filename)
|
|
39
|
+
*/
|
|
40
|
+
this.name = icon_constants_1.DEFAULTS.NAME;
|
|
41
|
+
/**
|
|
42
|
+
* Scale of the icon (works in combination with length unit)
|
|
43
|
+
*/
|
|
44
|
+
this.scale = icon_constants_1.DEFAULTS.SCALE;
|
|
45
|
+
/**
|
|
46
|
+
* Role attribute to be set for accessibility
|
|
47
|
+
*/
|
|
48
|
+
this.role = null;
|
|
49
|
+
/**
|
|
50
|
+
* Aria-label attribute to be set for accessibility
|
|
51
|
+
*/
|
|
52
|
+
this.ariaLabel = null;
|
|
53
|
+
this.iconProviderContext = provider_1.default.consume({ host: this, context: iconprovider_component_1.default.Context });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get Icon Data function which will fetch the icon (currently only svg)
|
|
57
|
+
* and sets state and attributes once fetched successfully
|
|
58
|
+
*/
|
|
59
|
+
async getIconData() {
|
|
60
|
+
if (this.iconProviderContext.value) {
|
|
61
|
+
const { fileExtension, url } = this.iconProviderContext.value;
|
|
62
|
+
if (url && fileExtension && this.name) {
|
|
63
|
+
const iconHtml = await (0, icon_utils_1.dynamicSVGImport)(url, this.name, fileExtension);
|
|
64
|
+
// update iconData state once fetched:
|
|
65
|
+
this.iconData = iconHtml;
|
|
66
|
+
// when icon got fetched, set role and aria-label:
|
|
67
|
+
this.setRoleOnIcon();
|
|
68
|
+
this.setAriaLabelOnIcon();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Updates the size by setting the width and height
|
|
74
|
+
*/
|
|
75
|
+
updateSize() {
|
|
76
|
+
if (this.scale && (this.lengthUnit || this.lengthUnitFromContext)) {
|
|
77
|
+
const value = `${this.scale}${this.lengthUnit || this.lengthUnitFromContext}`;
|
|
78
|
+
this.style.width = value;
|
|
79
|
+
this.style.height = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
setRoleOnIcon() {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
if (this.role) {
|
|
85
|
+
// pass through role attribute to svg if set on mdc-icon
|
|
86
|
+
(_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('role', this.role);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
(_b = this.iconData) === null || _b === void 0 ? void 0 : _b.removeAttribute('role');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
setAriaLabelOnIcon() {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
if (this.ariaLabel) {
|
|
95
|
+
// pass through aria-label attribute to svg if set on mdc-icon
|
|
96
|
+
(_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-label', this.ariaLabel);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
(_b = this.iconData) === null || _b === void 0 ? void 0 : _b.removeAttribute('aria-label');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
updated(changedProperties) {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
super.updated(changedProperties);
|
|
105
|
+
if (changedProperties.has('name')) {
|
|
106
|
+
// fetch icon data if name changes:
|
|
107
|
+
this.getIconData().catch((err) => {
|
|
108
|
+
console.error(err);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (changedProperties.has('role')) {
|
|
112
|
+
this.setRoleOnIcon();
|
|
113
|
+
}
|
|
114
|
+
if (changedProperties.has('ariaLabel')) {
|
|
115
|
+
this.setAriaLabelOnIcon();
|
|
116
|
+
}
|
|
117
|
+
if (changedProperties.has('scale') || changedProperties.has('lengthUnit')) {
|
|
118
|
+
this.updateSize();
|
|
119
|
+
}
|
|
120
|
+
if (this.lengthUnitFromContext !== ((_a = this.iconProviderContext.value) === null || _a === void 0 ? void 0 : _a.lengthUnit)) {
|
|
121
|
+
this.lengthUnitFromContext = (_b = this.iconProviderContext.value) === null || _b === void 0 ? void 0 : _b.lengthUnit;
|
|
122
|
+
this.updateSize();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
render() {
|
|
126
|
+
return (0, lit_1.html) ` ${this.iconData} `;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
Icon.styles = icon_styles_1.default;
|
|
130
|
+
tslib_1.__decorate([
|
|
131
|
+
(0, decorators_js_1.state)(),
|
|
132
|
+
tslib_1.__metadata("design:type", HTMLElement)
|
|
133
|
+
], Icon.prototype, "iconData", void 0);
|
|
134
|
+
tslib_1.__decorate([
|
|
135
|
+
(0, decorators_js_1.state)(),
|
|
136
|
+
tslib_1.__metadata("design:type", String)
|
|
137
|
+
], Icon.prototype, "lengthUnitFromContext", void 0);
|
|
138
|
+
tslib_1.__decorate([
|
|
139
|
+
(0, decorators_js_1.property)({ type: String, reflect: true }),
|
|
140
|
+
tslib_1.__metadata("design:type", String)
|
|
141
|
+
], Icon.prototype, "name", void 0);
|
|
142
|
+
tslib_1.__decorate([
|
|
143
|
+
(0, decorators_js_1.property)({ type: Number }),
|
|
144
|
+
tslib_1.__metadata("design:type", Number)
|
|
145
|
+
], Icon.prototype, "scale", void 0);
|
|
146
|
+
tslib_1.__decorate([
|
|
147
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'length-unit' }),
|
|
148
|
+
tslib_1.__metadata("design:type", String)
|
|
149
|
+
], Icon.prototype, "lengthUnit", void 0);
|
|
150
|
+
tslib_1.__decorate([
|
|
151
|
+
(0, decorators_js_1.property)({ type: String }),
|
|
152
|
+
tslib_1.__metadata("design:type", Object)
|
|
153
|
+
], Icon.prototype, "role", void 0);
|
|
154
|
+
tslib_1.__decorate([
|
|
155
|
+
(0, decorators_js_1.property)({ type: String, attribute: 'aria-label' }),
|
|
156
|
+
tslib_1.__metadata("design:type", Object)
|
|
157
|
+
], Icon.prototype, "ariaLabel", void 0);
|
|
158
|
+
exports.default = Icon;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULTS = exports.TAG_NAME = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tag_name_1 = tslib_1.__importDefault(require("../../utils/tag-name"));
|
|
6
|
+
const TAG_NAME = tag_name_1.default.constructTagName('icon');
|
|
7
|
+
exports.TAG_NAME = TAG_NAME;
|
|
8
|
+
const DEFAULTS = {
|
|
9
|
+
NAME: undefined,
|
|
10
|
+
SCALE: 1,
|
|
11
|
+
};
|
|
12
|
+
exports.DEFAULTS = DEFAULTS;
|