@bdc-libs/trinity.shared-consts 0.0.2

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 (3) hide show
  1. package/README.md +99 -0
  2. package/package.json +20 -0
  3. package/src/sizes.js +26 -0
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @bdc-libs/trinity.shared-consts
2
+
3
+ Trinity token services libs.
4
+
5
+ ## Features
6
+
7
+ - ES6 syntax, managed with Prettier + Eslint and Stylelint
8
+ - Unit testing with jest
9
+ - Lit custom elements
10
+ - ESM
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ yarn add @bdc-libs/trinity.shared-consts
16
+ // or
17
+ npm i @bdc-libs/trinity.shared-consts
18
+ ```
19
+
20
+ ### Usage
21
+
22
+ ```js
23
+ import { LitElement, html } from 'lit';
24
+ import { property, query } from 'lit/decorators.js';
25
+ import { classMap } from 'lit/directives/class-map.js';
26
+ import { ifDefined } from 'lit/directives/if-defined.js';
27
+ import { Size } from '@bdc-libs/trinity.shared-consts';
28
+
29
+ let TriButton = class TriButton extends LitElement {
30
+ constructor() {
31
+ super();
32
+ /** Which size to display */
33
+ this.size = Size.MEDIUM;
34
+ /** Which type to display */
35
+ this.type = ButtonType.PRIMARY;
36
+ /** Which variant to display */
37
+ this.variation = Variation.NONE;
38
+ /** Whether the button is disabled */
39
+ this.disabled = false;
40
+ /** Whether the button should submit a form */
41
+ this.submit = false;
42
+ this.addEventListener('click', (e) => {
43
+ if (this.disabled) {
44
+ e.stopImmediatePropagation();
45
+ e.preventDefault();
46
+ }
47
+ });
48
+ }
49
+ click() {
50
+ this._button.click();
51
+ }
52
+ // eslint-disable-next-line
53
+ focus(options) {
54
+ this._button.focus(options);
55
+ }
56
+ blur() {
57
+ this._button.blur();
58
+ }
59
+ _handleClick(event) {
60
+ if (this.disabled) {
61
+ event.preventDefault();
62
+ event.stopPropagation();
63
+ }
64
+ }
65
+ _handleSlotChange() {
66
+ if (this.variation === Variation.ICONONLY) {
67
+ this._defaultSlot
68
+ .assignedElements()
69
+ .filter((el) => el.nodeName.includes('TRI-ICON') ||
70
+ el.nodeName.includes('TRI-WEB-ICON'))
71
+ .forEach((el) => {
72
+ // eslint-disable-next-line
73
+ el.slot = 'icon';
74
+ });
75
+ }
76
+ }
77
+ render() {
78
+ return html `
79
+ <button
80
+ class=${classMap({
81
+ Button: true,
82
+ [`Button--${this.type}`]: Boolean(this.type),
83
+ [`Button--${this.size}`]: Boolean(this.size),
84
+ [`Button--${this.variation}`]: this.variation === 'none' ? '' : Boolean(this.variation),
85
+ })}
86
+ aria-label="${ifDefined(this.label)}"
87
+ @click=${this._handleClick}
88
+ ?disabled=${this.disabled}
89
+ type=${this.submit ? 'submit' : 'button'}
90
+ >
91
+ <slot name="before"></slot>
92
+ <span><slot @slotchange=${this._handleSlotChange}></slot></span>
93
+ <slot name="icon"></slot>
94
+ <slot name="after"></slot>
95
+ </button>
96
+ `;
97
+ }
98
+ };
99
+ ```
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@bdc-libs/trinity.shared-consts",
3
+ "version": "0.0.2",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "Trinity shared consts",
9
+ "license": "MIT",
10
+ "author": "hbll",
11
+ "main": "src/sizes.js",
12
+ "scripts": {
13
+ "test": "exit 0"
14
+ },
15
+ "devDependencies": {
16
+ "@babel/core": "^7.18.13",
17
+ "@babel/preset-env": "^7.18.10",
18
+ "lit": "^2.3.1"
19
+ }
20
+ }
package/src/sizes.js ADDED
@@ -0,0 +1,26 @@
1
+ export var Size;
2
+ (function (Size) {
3
+ Size["SMALL"] = "small";
4
+ Size["MEDIUM"] = "medium";
5
+ Size["LARGE"] = "large";
6
+ })(Size || (Size = {}));
7
+ export var Padding;
8
+ (function (Padding) {
9
+ Padding["NONE"] = "none";
10
+ Padding["SMALL"] = "small";
11
+ Padding["MEDIUM"] = "medium";
12
+ Padding["LARGE"] = "large";
13
+ })(Padding || (Padding = {}));
14
+ export var ContentPaddingHorizontal;
15
+ (function (ContentPaddingHorizontal) {
16
+ ContentPaddingHorizontal["NONE"] = "none";
17
+ ContentPaddingHorizontal["SMALL"] = "small";
18
+ ContentPaddingHorizontal["MEDIUM"] = "medium";
19
+ ContentPaddingHorizontal["LARGE"] = "large";
20
+ })(ContentPaddingHorizontal || (ContentPaddingHorizontal = {}));
21
+ export var ContentPaddingVertical;
22
+ (function (ContentPaddingVertical) {
23
+ ContentPaddingVertical["NONE"] = "none";
24
+ ContentPaddingVertical["SMALL"] = "small";
25
+ ContentPaddingVertical["MEDIUM"] = "medium";
26
+ })(ContentPaddingVertical || (ContentPaddingVertical = {}));