@nectary/components 5.14.1 → 5.14.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.
package/bundle.js CHANGED
@@ -3798,6 +3798,45 @@ class Chip extends NectaryElement {
3798
3798
  };
3799
3799
  }
3800
3800
  defineCustomElement("sinch-chip", Chip);
3801
+ const SKINTONE_SWATCH_COLORS = [
3802
+ "skintone-dark",
3803
+ "skintone-default",
3804
+ "skintone-light",
3805
+ "skintone-light-medium",
3806
+ "skintone-medium",
3807
+ "skintone-medium-dark"
3808
+ ];
3809
+ const SWATCH_COLORS = [
3810
+ "blue",
3811
+ "dark-blue",
3812
+ "dark-gray",
3813
+ "dark-green",
3814
+ "dark-orange",
3815
+ "dark-pink",
3816
+ "dark-red",
3817
+ "dark-violet",
3818
+ "dark-yellow",
3819
+ "default",
3820
+ "gray",
3821
+ "green",
3822
+ "light-blue",
3823
+ "light-gray",
3824
+ "light-green",
3825
+ "light-orange",
3826
+ "light-pink",
3827
+ "light-red",
3828
+ "light-violet",
3829
+ "light-yellow",
3830
+ "orange",
3831
+ "pink",
3832
+ "red",
3833
+ "violet",
3834
+ "yellow",
3835
+ ...SKINTONE_SWATCH_COLORS
3836
+ ];
3837
+ const isSwatchColor = (value = "") => {
3838
+ return SWATCH_COLORS.includes(value);
3839
+ };
3801
3840
  const getSwatchColorBg = (id) => {
3802
3841
  return `var(--sinch-comp-color-swatch-color-${id}-background)`;
3803
3842
  };
@@ -3823,7 +3862,7 @@ class ColorSwatch extends NectaryElement {
3823
3862
  super.disconnectedCallback();
3824
3863
  }
3825
3864
  static get observedAttributes() {
3826
- return ["name"];
3865
+ return ["name", "aria-label"];
3827
3866
  }
3828
3867
  attributeChangedCallback(name) {
3829
3868
  switch (name) {
@@ -3839,18 +3878,33 @@ class ColorSwatch extends NectaryElement {
3839
3878
  set name(value) {
3840
3879
  updateAttribute(this, "name", value);
3841
3880
  }
3881
+ get "aria-label"() {
3882
+ return getAttribute(this, "aria-label");
3883
+ }
3884
+ set "aria-label"(value) {
3885
+ updateAttribute(this, "aria-label", value);
3886
+ }
3842
3887
  #updateColor() {
3843
3888
  if (!this.isDomConnected) {
3844
3889
  return;
3845
3890
  }
3846
3891
  const colorName = this.name;
3847
- if (colorName !== null && colorName.length > 0) {
3892
+ if (colorName === null || colorName.length === 0) {
3893
+ this.#$wrapper.style.removeProperty("background-color");
3894
+ setClass(this.#$wrapper, "no-color", true);
3895
+ return;
3896
+ }
3897
+ if (isSwatchColor(colorName)) {
3898
+ const exitingAriaLabel = getAttribute(this, "aria-label");
3899
+ if (exitingAriaLabel == null || isSwatchColor(exitingAriaLabel)) {
3900
+ updateAttribute(this, "aria-label", colorName);
3901
+ }
3848
3902
  const bg = getSwatchColorBg(colorName);
3849
3903
  this.#$wrapper.style.setProperty("background-color", bg);
3850
3904
  setClass(this.#$wrapper, "no-color", false);
3851
3905
  } else {
3852
- this.#$wrapper.style.removeProperty("background-color");
3853
- setClass(this.#$wrapper, "no-color", true);
3906
+ this.#$wrapper.style.setProperty("background-color", colorName);
3907
+ setClass(this.#$wrapper, "no-color", false);
3854
3908
  }
3855
3909
  }
3856
3910
  }
@@ -3876,18 +3930,29 @@ class ColorMenuOption extends NectaryElement {
3876
3930
  disconnectedCallback() {
3877
3931
  }
3878
3932
  static get observedAttributes() {
3879
- return ["value"];
3933
+ return ["value", "aria-label"];
3880
3934
  }
3881
3935
  attributeChangedCallback(name, _, newVal) {
3882
3936
  switch (name) {
3883
3937
  case "value": {
3938
+ if (newVal == null) {
3939
+ this.#$wrapper.style.removeProperty("--sinch-global-color-icon");
3940
+ break;
3941
+ }
3942
+ if (!isSwatchColor(newVal)) {
3943
+ this.#$wrapper.style.setProperty("--sinch-global-color-icon", newVal);
3944
+ break;
3945
+ }
3884
3946
  updateAttribute(this.#$tooltip, "text", newVal);
3885
3947
  updateAttribute(this.#$swatch, "name", newVal);
3886
- if (newVal !== null) {
3887
- this.#$wrapper.style.setProperty("--sinch-global-color-icon", getSwatchColorFg(newVal));
3888
- } else {
3889
- this.#$wrapper.style.removeProperty("--sinch-global-color-icon");
3948
+ this.#$wrapper.style.setProperty("--sinch-global-color-icon", getSwatchColorFg(newVal));
3949
+ break;
3950
+ }
3951
+ case "aria-label": {
3952
+ if (newVal == null) {
3953
+ break;
3890
3954
  }
3955
+ updateAttribute(this.#$swatch, "aria-label", newVal);
3891
3956
  break;
3892
3957
  }
3893
3958
  }
@@ -13562,6 +13627,8 @@ export {
13562
13627
  RadioOption,
13563
13628
  RichText,
13564
13629
  RichTextarea,
13630
+ SKINTONE_SWATCH_COLORS,
13631
+ SWATCH_COLORS,
13565
13632
  SegmentCollapse,
13566
13633
  SegmentedControl,
13567
13634
  SegmentedControlOption,
@@ -1,6 +1,6 @@
1
1
  import "../color-swatch/index.js";
2
2
  import "../tooltip/index.js";
3
- import { getSwatchColorFg } from "../color-swatch/utils.js";
3
+ import { isSwatchColor, getSwatchColorFg } from "../color-swatch/utils.js";
4
4
  import { updateAttribute, getAttribute } from "../utils/dom.js";
5
5
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
6
6
  const templateHTML = '<style>:host{display:block;outline:0}#wrapper{width:44px;height:56px;padding:12px 6px;box-sizing:border-box}#swatch-wrapper{position:relative;cursor:pointer;width:32px;height:32px}#swatch-wrapper::after{content:"";position:absolute;width:34px;height:34px;inset:-3px;border:2px solid var(--sinch-comp-color-menu-option-color-default-border-initial);border-radius:50%;pointer-events:none}:host([data-checked]) #swatch-wrapper::after{border-color:var(--sinch-comp-color-menu-option-color-default-border-selected)}:host([data-selected]) #swatch-wrapper::after{border-color:var(--sinch-comp-color-menu-option-color-default-border-focus)}:host(:hover) #swatch-wrapper::after{border-color:var(--sinch-comp-color-menu-option-color-default-border-hover)}:host(:active) #swatch-wrapper::after{border-color:var(--sinch-comp-color-menu-option-color-default-border-active)}</style><div id="wrapper"><sinch-tooltip id="tooltip"><div id="swatch-wrapper"><sinch-color-swatch id="swatch"></sinch-color-swatch></div></sinch-tooltip></div>';
@@ -24,18 +24,29 @@ class ColorMenuOption extends NectaryElement {
24
24
  disconnectedCallback() {
25
25
  }
26
26
  static get observedAttributes() {
27
- return ["value"];
27
+ return ["value", "aria-label"];
28
28
  }
29
29
  attributeChangedCallback(name, _, newVal) {
30
30
  switch (name) {
31
31
  case "value": {
32
+ if (newVal == null) {
33
+ this.#$wrapper.style.removeProperty("--sinch-global-color-icon");
34
+ break;
35
+ }
36
+ if (!isSwatchColor(newVal)) {
37
+ this.#$wrapper.style.setProperty("--sinch-global-color-icon", newVal);
38
+ break;
39
+ }
32
40
  updateAttribute(this.#$tooltip, "text", newVal);
33
41
  updateAttribute(this.#$swatch, "name", newVal);
34
- if (newVal !== null) {
35
- this.#$wrapper.style.setProperty("--sinch-global-color-icon", getSwatchColorFg(newVal));
36
- } else {
37
- this.#$wrapper.style.removeProperty("--sinch-global-color-icon");
42
+ this.#$wrapper.style.setProperty("--sinch-global-color-icon", getSwatchColorFg(newVal));
43
+ break;
44
+ }
45
+ case "aria-label": {
46
+ if (newVal == null) {
47
+ break;
38
48
  }
49
+ updateAttribute(this.#$swatch, "aria-label", newVal);
39
50
  break;
40
51
  }
41
52
  }
@@ -2,6 +2,8 @@ import type { NectaryComponentReactByType, NectaryComponentVanillaByType, Nectar
2
2
  export type TSinchColorMenuOptionProps = {
3
3
  /** Value */
4
4
  value: string;
5
+ /** Aria label */
6
+ 'aria-label'?: string;
5
7
  };
6
8
  export type TSinchColorMenuOptionStyle = {
7
9
  '--sinch-comp-color-menu-option-color-default-border-initial'?: string;
@@ -1,2 +1,7 @@
1
1
  import { defineCustomElement } from "../../utils/element.js";
2
+ import { SKINTONE_SWATCH_COLORS, SWATCH_COLORS } from "../types.js";
2
3
  defineCustomElement("sinch-color-swatch");
4
+ export {
5
+ SKINTONE_SWATCH_COLORS,
6
+ SWATCH_COLORS
7
+ };
@@ -10,4 +10,6 @@ export declare class ColorSwatch extends NectaryElement {
10
10
  attributeChangedCallback(name: string): void;
11
11
  get name(): string | null;
12
12
  set name(value: string | null);
13
+ get 'aria-label'(): string | null;
14
+ set 'aria-label'(value: string | null);
13
15
  }
@@ -1,7 +1,8 @@
1
1
  import "../text/index.js";
2
2
  import { getAttribute, updateAttribute, setClass } from "../utils/dom.js";
3
3
  import { defineCustomElement, NectaryElement } from "../utils/element.js";
4
- import { getSwatchColorBg } from "./utils.js";
4
+ import { isSwatchColor, getSwatchColorBg } from "./utils.js";
5
+ import { SKINTONE_SWATCH_COLORS, SWATCH_COLORS } from "./types.js";
5
6
  const templateHTML = '<style>:host{display:inline-block;vertical-align:middle}#wrapper{width:var(--sinch-global-size-icon,32px);height:var(--sinch-global-size-icon,32px);border-radius:50%}#wrapper.no-color{background:linear-gradient(45deg,var(--sinch-ref-color-violet-200),var(--sinch-ref-color-honey-200),var(--sinch-ref-color-grass-200),var(--sinch-ref-color-ocean-200),var(--sinch-ref-color-violet-200))}</style><div id="wrapper"></div>';
6
7
  const template = document.createElement("template");
7
8
  template.innerHTML = templateHTML;
@@ -21,7 +22,7 @@ class ColorSwatch extends NectaryElement {
21
22
  super.disconnectedCallback();
22
23
  }
23
24
  static get observedAttributes() {
24
- return ["name"];
25
+ return ["name", "aria-label"];
25
26
  }
26
27
  attributeChangedCallback(name) {
27
28
  switch (name) {
@@ -37,22 +38,39 @@ class ColorSwatch extends NectaryElement {
37
38
  set name(value) {
38
39
  updateAttribute(this, "name", value);
39
40
  }
41
+ get "aria-label"() {
42
+ return getAttribute(this, "aria-label");
43
+ }
44
+ set "aria-label"(value) {
45
+ updateAttribute(this, "aria-label", value);
46
+ }
40
47
  #updateColor() {
41
48
  if (!this.isDomConnected) {
42
49
  return;
43
50
  }
44
51
  const colorName = this.name;
45
- if (colorName !== null && colorName.length > 0) {
52
+ if (colorName === null || colorName.length === 0) {
53
+ this.#$wrapper.style.removeProperty("background-color");
54
+ setClass(this.#$wrapper, "no-color", true);
55
+ return;
56
+ }
57
+ if (isSwatchColor(colorName)) {
58
+ const exitingAriaLabel = getAttribute(this, "aria-label");
59
+ if (exitingAriaLabel == null || isSwatchColor(exitingAriaLabel)) {
60
+ updateAttribute(this, "aria-label", colorName);
61
+ }
46
62
  const bg = getSwatchColorBg(colorName);
47
63
  this.#$wrapper.style.setProperty("background-color", bg);
48
64
  setClass(this.#$wrapper, "no-color", false);
49
65
  } else {
50
- this.#$wrapper.style.removeProperty("background-color");
51
- setClass(this.#$wrapper, "no-color", true);
66
+ this.#$wrapper.style.setProperty("background-color", colorName);
67
+ setClass(this.#$wrapper, "no-color", false);
52
68
  }
53
69
  }
54
70
  }
55
71
  defineCustomElement("sinch-color-swatch", ColorSwatch);
56
72
  export {
57
- ColorSwatch
73
+ ColorSwatch,
74
+ SKINTONE_SWATCH_COLORS,
75
+ SWATCH_COLORS
58
76
  };
@@ -1,7 +1,13 @@
1
1
  import type { NectaryComponentReactByType, NectaryComponentVanillaByType, NectaryComponentReact, NectaryComponentVanilla } from '../types';
2
+ export declare const SKINTONE_SWATCH_COLORS: readonly ["skintone-dark", "skintone-default", "skintone-light", "skintone-light-medium", "skintone-medium", "skintone-medium-dark"];
3
+ export declare const SWATCH_COLORS: readonly ["blue", "dark-blue", "dark-gray", "dark-green", "dark-orange", "dark-pink", "dark-red", "dark-violet", "dark-yellow", "default", "gray", "green", "light-blue", "light-gray", "light-green", "light-orange", "light-pink", "light-red", "light-violet", "light-yellow", "orange", "pink", "red", "violet", "yellow", "skintone-dark", "skintone-default", "skintone-light", "skintone-light-medium", "skintone-medium", "skintone-medium-dark"];
4
+ export type SkinToneColor = typeof SKINTONE_SWATCH_COLORS[number];
5
+ export type SwatchColors = typeof SWATCH_COLORS[number];
2
6
  export type TSinchColorSwatchProps = {
3
7
  /** Color name */
4
8
  name?: string;
9
+ /** Aria label */
10
+ 'aria-label'?: string;
5
11
  };
6
12
  export type TSinchColorSwatchStyle = {
7
13
  '--sinch-global-size-icon'?: string;
@@ -1 +1,40 @@
1
-
1
+ const SKINTONE_SWATCH_COLORS = [
2
+ "skintone-dark",
3
+ "skintone-default",
4
+ "skintone-light",
5
+ "skintone-light-medium",
6
+ "skintone-medium",
7
+ "skintone-medium-dark"
8
+ ];
9
+ const SWATCH_COLORS = [
10
+ "blue",
11
+ "dark-blue",
12
+ "dark-gray",
13
+ "dark-green",
14
+ "dark-orange",
15
+ "dark-pink",
16
+ "dark-red",
17
+ "dark-violet",
18
+ "dark-yellow",
19
+ "default",
20
+ "gray",
21
+ "green",
22
+ "light-blue",
23
+ "light-gray",
24
+ "light-green",
25
+ "light-orange",
26
+ "light-pink",
27
+ "light-red",
28
+ "light-violet",
29
+ "light-yellow",
30
+ "orange",
31
+ "pink",
32
+ "red",
33
+ "violet",
34
+ "yellow",
35
+ ...SKINTONE_SWATCH_COLORS
36
+ ];
37
+ export {
38
+ SKINTONE_SWATCH_COLORS,
39
+ SWATCH_COLORS
40
+ };
@@ -1,2 +1,4 @@
1
- export declare const getSwatchColorBg: (id: string) => string;
2
- export declare const getSwatchColorFg: (id: string) => string;
1
+ import type { SwatchColors } from './types';
2
+ export declare const isSwatchColor: (value?: string) => value is SwatchColors;
3
+ export declare const getSwatchColorBg: (id: SwatchColors) => "var(--sinch-comp-color-swatch-color-blue-background)" | "var(--sinch-comp-color-swatch-color-dark-blue-background)" | "var(--sinch-comp-color-swatch-color-dark-gray-background)" | "var(--sinch-comp-color-swatch-color-dark-green-background)" | "var(--sinch-comp-color-swatch-color-dark-orange-background)" | "var(--sinch-comp-color-swatch-color-dark-pink-background)" | "var(--sinch-comp-color-swatch-color-dark-red-background)" | "var(--sinch-comp-color-swatch-color-dark-violet-background)" | "var(--sinch-comp-color-swatch-color-dark-yellow-background)" | "var(--sinch-comp-color-swatch-color-default-background)" | "var(--sinch-comp-color-swatch-color-gray-background)" | "var(--sinch-comp-color-swatch-color-green-background)" | "var(--sinch-comp-color-swatch-color-light-blue-background)" | "var(--sinch-comp-color-swatch-color-light-gray-background)" | "var(--sinch-comp-color-swatch-color-light-green-background)" | "var(--sinch-comp-color-swatch-color-light-orange-background)" | "var(--sinch-comp-color-swatch-color-light-pink-background)" | "var(--sinch-comp-color-swatch-color-light-red-background)" | "var(--sinch-comp-color-swatch-color-light-violet-background)" | "var(--sinch-comp-color-swatch-color-light-yellow-background)" | "var(--sinch-comp-color-swatch-color-orange-background)" | "var(--sinch-comp-color-swatch-color-pink-background)" | "var(--sinch-comp-color-swatch-color-red-background)" | "var(--sinch-comp-color-swatch-color-violet-background)" | "var(--sinch-comp-color-swatch-color-yellow-background)" | "var(--sinch-comp-color-swatch-color-skintone-dark-background)" | "var(--sinch-comp-color-swatch-color-skintone-default-background)" | "var(--sinch-comp-color-swatch-color-skintone-light-background)" | "var(--sinch-comp-color-swatch-color-skintone-light-medium-background)" | "var(--sinch-comp-color-swatch-color-skintone-medium-background)" | "var(--sinch-comp-color-swatch-color-skintone-medium-dark-background)";
4
+ export declare const getSwatchColorFg: (id: SwatchColors) => "var(--sinch-comp-color-swatch-color-blue-foreground)" | "var(--sinch-comp-color-swatch-color-dark-blue-foreground)" | "var(--sinch-comp-color-swatch-color-dark-gray-foreground)" | "var(--sinch-comp-color-swatch-color-dark-green-foreground)" | "var(--sinch-comp-color-swatch-color-dark-orange-foreground)" | "var(--sinch-comp-color-swatch-color-dark-pink-foreground)" | "var(--sinch-comp-color-swatch-color-dark-red-foreground)" | "var(--sinch-comp-color-swatch-color-dark-violet-foreground)" | "var(--sinch-comp-color-swatch-color-dark-yellow-foreground)" | "var(--sinch-comp-color-swatch-color-default-foreground)" | "var(--sinch-comp-color-swatch-color-gray-foreground)" | "var(--sinch-comp-color-swatch-color-green-foreground)" | "var(--sinch-comp-color-swatch-color-light-blue-foreground)" | "var(--sinch-comp-color-swatch-color-light-gray-foreground)" | "var(--sinch-comp-color-swatch-color-light-green-foreground)" | "var(--sinch-comp-color-swatch-color-light-orange-foreground)" | "var(--sinch-comp-color-swatch-color-light-pink-foreground)" | "var(--sinch-comp-color-swatch-color-light-red-foreground)" | "var(--sinch-comp-color-swatch-color-light-violet-foreground)" | "var(--sinch-comp-color-swatch-color-light-yellow-foreground)" | "var(--sinch-comp-color-swatch-color-orange-foreground)" | "var(--sinch-comp-color-swatch-color-pink-foreground)" | "var(--sinch-comp-color-swatch-color-red-foreground)" | "var(--sinch-comp-color-swatch-color-violet-foreground)" | "var(--sinch-comp-color-swatch-color-yellow-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-dark-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-default-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-light-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-light-medium-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-medium-foreground)" | "var(--sinch-comp-color-swatch-color-skintone-medium-dark-foreground)";
@@ -1,3 +1,7 @@
1
+ import { SWATCH_COLORS } from "./types.js";
2
+ const isSwatchColor = (value = "") => {
3
+ return SWATCH_COLORS.includes(value);
4
+ };
1
5
  const getSwatchColorBg = (id) => {
2
6
  return `var(--sinch-comp-color-swatch-color-${id}-background)`;
3
7
  };
@@ -6,5 +10,6 @@ const getSwatchColorFg = (id) => {
6
10
  };
7
11
  export {
8
12
  getSwatchColorBg,
9
- getSwatchColorFg
13
+ getSwatchColorFg,
14
+ isSwatchColor
10
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.14.1",
3
+ "version": "5.14.2",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",