@proximus/lavender-price 1.0.0-alpha.32

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 (2) hide show
  1. package/dist/index.js +87 -0
  2. package/package.json +40 -0
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ import { PxElement as v } from "@proximus/lavender-common";
2
+ const h = '.price{--price-s: var(--px-text-size-l-mobile);--price-m: var(--px-text-size-xl-mobile);--price-l: var(--px-text-size-3xl-mobile);font-family:var(--px-font-family);white-space:nowrap;font-weight:700;color:var(--px-color-txt-primary-default);font-size:var(--price-s)}@media only screen and (min-width: 641px){.price{--price-s: var(--px-text-size-l-tablet);--price-m: var(--px-text-size-xl-tablet);--price-l: var(--px-text-size-3xl-tablet)}}@media only screen and (min-width: 1025px){.price{--price-s: var(--px-text-size-l-desktop);--price-m: var(--px-text-size-xl-desktop);--price-l: var(--px-text-size-3xl-desktop)}}.promo,.free{color:var(--px-color-txt-promo-default)}.neutral{color:var(--px-color-txt-body-default)}.exceeding{color:var(--px-color-txt-error-default)}.disabled{color:var(--px-color-txt-disabled-default)}::slotted([slot="oldprice"]){text-decoration:line-through;color:var(--px-color-txt-body-default);font-size:var(--px-text-size-base-mobile);font-weight:400}@media only screen and (min-width: 641px){{font-size:var(--px-text-size-base-tablet)}}@media only screen and (min-width: 1025px){{font-size:var(--px-text-size-base-desktop)}}::slotted([slot="newpromoprice"]){position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden}:host([inverted]) .price{color:var(--px-color-txt-primary-inverted)}:host([inverted]) .promo,:host([inverted]) .free{color:var(--px-color-txt-promo-inverted)}:host([inverted]) .neutral{color:var(--px-color-txt-body-inverted)}:host([inverted]) .exceeding{color:var(--px-color-txt-error-inverted)}:host([inverted]) .disabled{color:var(--px-color-txt-disabled-inverted)}:host([inverted]) ::slotted(s){color:var(--px-color-txt-body-inverted)}.price:not(.promo):not(.free) ::slotted(s){display:none}::slotted(.euro){font-size:calc(var(--price-s) * .75)}::slotted(.decimals){font-size:calc(var(--price-s) * .5)}.m{font-size:var(--price-m)}:host([size="m"]) ::slotted(.decimals){font-size:calc(var(--price-m) * .5)}:host([size="m"]) ::slotted(.euro){font-size:calc(var(--price-m) * .75)}.l{font-size:var(--price-l)}:host([size="l"]) ::slotted(.decimals){font-size:calc(var(--price-l) * .5)}:host([size="l"]) ::slotted(.euro){font-size:calc(var(--price-l) * .75)}', c = new CSSStyleSheet();
3
+ c.replaceSync(h);
4
+ const m = [
5
+ "default",
6
+ "promo",
7
+ "free",
8
+ "neutral",
9
+ "exceeding",
10
+ "disabled"
11
+ ], b = ["", "s", "m", "l"], a = class a extends v {
12
+ constructor() {
13
+ super(c), this.template = () => '<span class="price"><slot name="oldprice"></slot><slot name="newpromoprice"></slot><slot></slot></span>', this.shadowRoot.innerHTML = this.template();
14
+ }
15
+ static get observedAttributes() {
16
+ return [...super.observedAttributes, "variant", "size", "inverted"];
17
+ }
18
+ get variant() {
19
+ return this.getAttribute("variant");
20
+ }
21
+ set variant(e) {
22
+ this.setAttribute("variant", e);
23
+ }
24
+ get size() {
25
+ return this.getAttribute("size");
26
+ }
27
+ set size(e) {
28
+ this.setAttribute("size", e);
29
+ }
30
+ get inverted() {
31
+ return this.getAttribute("inverted");
32
+ }
33
+ set inverted(e) {
34
+ this.setAttribute("inverted", e);
35
+ }
36
+ connectedCallback() {
37
+ this.buildPrice();
38
+ }
39
+ attributeChangedCallback(e, t, r) {
40
+ if (t !== r)
41
+ switch (e) {
42
+ case "variant":
43
+ this.updateAttribute(e, t, r, m);
44
+ break;
45
+ case "size":
46
+ this.updateAttribute(e, t, r, b);
47
+ break;
48
+ default:
49
+ super.attributeChangedCallback(e, t, r);
50
+ break;
51
+ }
52
+ }
53
+ checkName(e, t) {
54
+ return e.includes(t);
55
+ }
56
+ toggleClass(e, t) {
57
+ e !== null && e !== "" && e !== "default" && this.$el.classList.toggle(e), t !== null && t !== "" && t !== "default" && this.$el.classList.toggle(t);
58
+ }
59
+ updateAttribute(e, t, r, i) {
60
+ this.toggleClass(t, r), this.checkName(i, r) || console.error(
61
+ `${r} is not an allowed ${e} value for ${this.$el}`
62
+ );
63
+ }
64
+ buildPrice() {
65
+ let e = this.innerHTML.trim();
66
+ const t = this.querySelector('[slot="oldprice"]');
67
+ let r = "", i = "", s;
68
+ t && t.innerHTML !== "" ? (t.innerHTML = "€" + t.innerHTML, s = this.querySelector('[slot="newpromoprice"]'), s ? (i = s.outerHTML, e = s.nextSibling.textContent) : e = t.nextSibling.textContent, r = t.outerHTML + " ") : t && t.innerHTML === "" && (e = t.nextSibling.textContent);
69
+ const p = /^[\d|.|,]+/.test(e);
70
+ let o = "";
71
+ p ? o = '<span class="euro">€</span>' : o = "";
72
+ const l = e.charAt(e.length - 3);
73
+ if (l === "." || l === ",") {
74
+ const [d, x] = e.split(l);
75
+ this.innerHTML = `${r}${i}${o}${d}<span class="decimals">${l}${x}</span>`;
76
+ } else
77
+ this.innerHTML = `${r}${i}${o}${e}`;
78
+ }
79
+ };
80
+ a.nativeName = "span";
81
+ let n = a;
82
+ customElements.define("px-price", n);
83
+ export {
84
+ n as Price,
85
+ b as sizeValues,
86
+ m as variantValues
87
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@proximus/lavender-price",
3
+ "version": "1.0.0-alpha.32",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "development": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./src/*.css": {
13
+ "development": "src/*.css"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "type": "module",
20
+ "scripts": {
21
+ "build": "rm -rf dist;tsc; vite build",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "gitHead": "15a231df98020f83813279639a9a7712a5a5e759",
28
+ "lerna": {
29
+ "command": {
30
+ "publish": {
31
+ "assets": [
32
+ "CHANGELOG.md",
33
+ "package.json",
34
+ "dist/*.js",
35
+ "dist/css/**/*.css"
36
+ ]
37
+ }
38
+ }
39
+ }
40
+ }