@nectary/labs 2.8.0 → 2.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/labs",
3
- "version": "2.8.0",
3
+ "version": "2.9.1",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
@@ -19,7 +19,7 @@
19
19
  "dev": "vite build --watch"
20
20
  },
21
21
  "dependencies": {
22
- "@nectary/components": "5.33.0"
22
+ "@nectary/components": "5.35.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "22.12.0",
@@ -13,8 +13,11 @@ export declare class RcsChatMessage extends NectaryElement {
13
13
  attributeChangedCallback(name: string, oldVal: string | null, newVal: string | null): void;
14
14
  get text(): string;
15
15
  set text(value: string);
16
+ get direction(): 'in' | 'out';
17
+ set direction(value: 'in' | 'out');
16
18
  }
17
19
  type Props = {
20
+ direction?: 'in' | 'out';
18
21
  text?: string;
19
22
  };
20
23
  type ElementProps = Partial<{
@@ -1,6 +1,46 @@
1
1
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
2
- const templateHTML = '<style>\n:host {\n display: block;\n}\n\n.message {\n padding: 8px 12px;\n margin-inline-end: 8px;\n border-radius: 16px;\n border-end-start-radius: 0;\n background: var(--sinch-sys-color-feedback-info-subtle);\n font: var(--sinch-sys-font-body-xs);\n}\n</style>\n\n<section class="message">\n <span id="message-text">Sample message</span>\n</section>\n';
2
+ const templateHTML = `<style>
3
+ :host {
4
+ display: block;
5
+ }
6
+
7
+ :host([direction='in']) {
8
+ display: flex;
9
+ justify-content: flex-start;
10
+ }
11
+
12
+ :host([direction='out']) {
13
+ display: flex;
14
+ justify-content: flex-end;
15
+ }
16
+
17
+ .message {
18
+ max-inline-size: 80%;
19
+ padding: 8px 12px;
20
+ border-radius: 16px;
21
+ font: var(--sinch-sys-font-body-xs);
22
+ }
23
+
24
+ :host([direction='in']) .message {
25
+ margin-inline-end: 8px;
26
+ border-end-start-radius: 0;
27
+ background: var(--sinch-sys-color-surface-tertiary-default);
28
+ }
29
+
30
+ :host([direction='out']) .message {
31
+ margin-inline-start: 8px;
32
+ border-end-end-radius: 0;
33
+ background: var(--sinch-sys-color-feedback-info-subtle);
34
+ }
35
+ </style>
36
+
37
+ <section class="message">
38
+ <span id="message-text">Sample message</span>
39
+ </section>
40
+ `;
3
41
  const template = document.createElement("template");
42
+ const DIRECTION_IN = "in";
43
+ const DIRECTION_OUT = "out";
4
44
  template.innerHTML = templateHTML;
5
45
  class RcsChatMessage extends NectaryElement {
6
46
  #messageText;
@@ -12,10 +52,13 @@ class RcsChatMessage extends NectaryElement {
12
52
  }
13
53
  connectedCallback() {
14
54
  super.connectedCallback();
55
+ if (!this.hasAttribute("direction")) {
56
+ this.direction = DIRECTION_IN;
57
+ }
15
58
  this.#updateUI();
16
59
  }
17
60
  static get observedAttributes() {
18
- return ["text"];
61
+ return ["text", "direction"];
19
62
  }
20
63
  attributeChangedCallback(name, oldVal, newVal) {
21
64
  if (oldVal === newVal) {
@@ -23,6 +66,7 @@ class RcsChatMessage extends NectaryElement {
23
66
  }
24
67
  switch (name) {
25
68
  case "text":
69
+ case "direction":
26
70
  this.#updateUI();
27
71
  break;
28
72
  }
@@ -33,6 +77,13 @@ class RcsChatMessage extends NectaryElement {
33
77
  set text(value) {
34
78
  this.setAttribute("text", value);
35
79
  }
80
+ get direction() {
81
+ const direction = this.getAttribute("direction");
82
+ return direction === DIRECTION_OUT ? DIRECTION_OUT : DIRECTION_IN;
83
+ }
84
+ set direction(value) {
85
+ this.setAttribute("direction", value === DIRECTION_OUT ? DIRECTION_OUT : DIRECTION_IN);
86
+ }
36
87
  #updateUI() {
37
88
  if (!this.isDomConnected) {
38
89
  return;
@@ -3,13 +3,33 @@
3
3
  display: block;
4
4
  }
5
5
 
6
+ :host([direction='in']) {
7
+ display: flex;
8
+ justify-content: flex-start;
9
+ }
10
+
11
+ :host([direction='out']) {
12
+ display: flex;
13
+ justify-content: flex-end;
14
+ }
15
+
6
16
  .message {
17
+ max-inline-size: 80%;
7
18
  padding: 8px 12px;
8
- margin-inline-end: 8px;
9
19
  border-radius: 16px;
20
+ font: var(--sinch-sys-font-body-xs);
21
+ }
22
+
23
+ :host([direction='in']) .message {
24
+ margin-inline-end: 8px;
10
25
  border-end-start-radius: 0;
26
+ background: var(--sinch-sys-color-surface-tertiary-default);
27
+ }
28
+
29
+ :host([direction='out']) .message {
30
+ margin-inline-start: 8px;
31
+ border-end-end-radius: 0;
11
32
  background: var(--sinch-sys-color-feedback-info-subtle);
12
- font: var(--sinch-sys-font-body-xs);
13
33
  }
14
34
  </style>
15
35