@viasat/beam-web-components 2.21.1 → 2.23.0

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.
@@ -0,0 +1,68 @@
1
+ import { LitElement } from 'lit';
2
+ import { ThemeTypes } from '@viasat/beam-shared/utils/constants';
3
+ import { Optional } from '@viasat/beam-shared/utils/types';
4
+ /**
5
+ * @summary `bm-label`
6
+ *
7
+ * @slot text - Specify the text for Label
8
+ * @slot optional - Specify if the Label displays as optional
9
+ * @slot tooltip - Specify if the icon displays to add a Tooltip
10
+ *
11
+ * @remarks
12
+ * **Accessibility with non-Beam inputs:**
13
+ * The `for` attribute handles click-to-focus for native inputs outside the shadow root,
14
+ * but the native `<label for>` association does not cross shadow DOM boundaries.
15
+ * Screen readers will not automatically announce the label text when the input is focused.
16
+ * To ensure accessible labeling, add `aria-labelledby` on your input pointing to the
17
+ * `bm-label` host element's `id`:
18
+ *
19
+ * ```html
20
+ * <bm-label id="name-label" text="First name" for="name-input"></bm-label>
21
+ * <input id="name-input" aria-labelledby="name-label" />
22
+ * ```
23
+ *
24
+ * This is not needed for Beam form components (e.g. `bm-text-field`), which handle
25
+ * label association internally via `bm-label-click` and `aria-labelledby`.
26
+ */
27
+ export declare class BmLabel extends LitElement {
28
+ #private;
29
+ /**
30
+ * Specify if the Label displays disabled
31
+ */
32
+ disabled: boolean;
33
+ /**
34
+ * Specify if the Label displays as required
35
+ */
36
+ required: boolean;
37
+ /**
38
+ * Specify the text for Label
39
+ */
40
+ text: Optional<string>;
41
+ /**
42
+ * Specify the optional text for Label
43
+ */
44
+ optional: Optional<string>;
45
+ /**
46
+ * Specify the id of the form element the Label is associated with.
47
+ * Handles click-to-focus across shadow DOM. See class-level remarks
48
+ * for accessibility guidance with non-Beam inputs.
49
+ */
50
+ for: Optional<string>;
51
+ /**
52
+ * Specify the theme of the Label. By default it inherits the theme from the parent
53
+ */
54
+ theme: Optional<ThemeTypes>;
55
+ static styles: import('lit').CSSResult;
56
+ private optionalNodes?;
57
+ private tooltipNodes?;
58
+ private get hasOptionalSlot();
59
+ private get hasTooltipSlot();
60
+ private get hasOptional();
61
+ render(): import('lit-html').TemplateResult<1>;
62
+ }
63
+ declare global {
64
+ interface HTMLElementTagNameMap {
65
+ 'bm-label': BmLabel;
66
+ }
67
+ }
68
+ //# sourceMappingURL=Label.d.ts.map
@@ -1,85 +1,109 @@
1
- import { r as _, a as x, x as u } from "../../chunks/lit-element.CJtt9wj5.js";
2
- import { n as s, c as S } from "../../chunks/register-custom-element.vod7zfGv.js";
3
- import { n as P } from "../../chunks/query-assigned-nodes.Dgvsf6BR.js";
4
- import { n as $, c as f, g as k } from "../../chunks/classNames.C6fNrXWF.js";
5
- import { t as C } from "../../chunks/constants.jOWREYQE.js";
1
+ import { unsafeCSS as $, LitElement as P, nothing as k, html as d } from "lit";
2
+ import { property as m, queryAssignedNodes as S } from "lit/decorators.js";
3
+ import v from "clsx";
4
+ import { n as g, g as C } from "../chunks/classNames.Cq_tbDRp.js";
5
+ import { t as O } from "../chunks/constants.jOWREYQE.js";
6
+ import { c as q } from "../chunks/register-custom-element.DHGKOhmA.js";
6
7
  const w = ':root,:host,.bm-light,.bm-dark .bm-inverse,.bm-dark.bm-inverse,[data-bm-theme~=bm-dark] .bm-inverse,[data-bm-theme~=bm-dark].bm-inverse,.bm-enterprise,.bm-consumer,[data-bm-theme~=bm-light]{--bm-comp-label-color-text: var(--bm-sem-color-text-secondary, #576775);--bm-comp-label-color-icon: var(--bm-sem-color-icon-secondary, #576775);--bm-comp-label-typo-default: var( --bm-sem-typo-label-sm, 600 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-typo-optional: var( --bm-sem-typo-body-sm, 400 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-typo-character-count: var( --bm-sem-typo-body-sm, 400 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-space-gap: var(--bm-sem-space-25, .25rem);--bm-comp-label-space-bottom: var(--bm-sem-space-50, .5rem);--bm-comp-label-size-icon: var(--bm-sem-size-icon-sm, 1rem)}:host,.bm-dark,.bm-light .bm-inverse,.bm-light.bm-inverse,[data-bm-theme~=bm-light] .bm-inverse,[data-bm-theme~=bm-light].bm-inverse,.bm-enterprise,.bm-consumer,[data-bm-theme~=bm-dark]{--bm-comp-label-color-text: var(--bm-sem-color-text-secondary, #c3cdd5);--bm-comp-label-color-icon: var(--bm-sem-color-icon-secondary, #c3cdd5);--bm-comp-label-typo-default: var( --bm-sem-typo-label-sm, 600 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-typo-optional: var( --bm-sem-typo-body-sm, 400 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-typo-character-count: var( --bm-sem-typo-body-sm, 400 .875rem/1.25rem "Source Sans Pro" );--bm-comp-label-space-gap: var(--bm-sem-space-25, .25rem);--bm-comp-label-space-bottom: var(--bm-sem-space-50, .5rem);--bm-comp-label-size-icon: var(--bm-sem-size-icon-sm, 1rem)}.bm-label{color:var(--bm-comp-label-color-text);font:var(--bm-comp-label-typo-default);margin-bottom:var(--bm-comp-label-space-bottom, var(--bm-sem-space-0))}.bm-label label{cursor:var(--bm-comp-label-cursor, default);pointer-events:var(--bm-comp-label-pointer-events, inherit)}.bm-label--disabled label{opacity:var(--bm-sem-opacity-disabled)}.bm-label--required label:after{content:"*";color:var(--bm-sem-color-text-negative)}.bm-label--required label:has(:last-child):after{content:""}.bm-label--required label:has(:last-child)>*:last-child:after{content:"*";color:var(--bm-sem-color-text-negative)}.bm-label__optional{font:var(--bm-comp-label-typo-optional);margin-left:var(--bm-comp-label-space-gap)}.bm-label__tooltip{vertical-align:top;display:inline-block;margin-inline-start:var(--bm-comp-label-space-gap)}.bm-label__tooltip button{color:var(--bm-comp-tooltip-color-icon-trigger)}.bm-label__tooltip svg{height:var(--bm-comp-label-size-icon);width:var(--bm-comp-label-size-icon)}.bm-label--no-box{display:contents}';
7
- var q = Object.defineProperty, O = Object.getOwnPropertyDescriptor, g = (e) => {
8
+ var E = Object.defineProperty, N = Object.getOwnPropertyDescriptor, x = (e) => {
8
9
  throw TypeError(e);
9
- }, m = (e, a, t, b) => {
10
- for (var l = b > 1 ? void 0 : b ? O(a, t) : a, p = e.length - 1, n; p >= 0; p--)
11
- (n = e[p]) && (l = (b ? n(a, t, l) : n(l)) || l);
12
- return b && l && q(a, t, l), l;
13
- }, E = (e, a, t) => a.has(e) || g("Cannot " + t), r = (e, a, t) => (E(e, a, "read from private field"), t ? t.call(e) : a.get(e)), i = (e, a, t) => a.has(e) ? g("Cannot add the same private member more than once") : a instanceof WeakSet ? a.add(e) : a.set(e, t), c, h, v, y;
14
- const { baseClassNamePrefix: z, subElementClassPrefix: M, classModifierPrefix: d } = k("label");
15
- let o = class extends x {
10
+ }, l = (e, t, a, i) => {
11
+ for (var r = i > 1 ? void 0 : i ? N(t, a) : t, c = e.length - 1, h; c >= 0; c--)
12
+ (h = e[c]) && (r = (i ? h(t, a, r) : h(r)) || r);
13
+ return i && r && E(t, a, r), r;
14
+ }, z = (e, t, a) => t.has(e) || x("Cannot " + a), s = (e, t, a) => (z(e, t, "read from private field"), a ? a.call(e) : t.get(e)), b = (e, t, a) => t.has(e) ? x("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, a), n, y, u, f;
15
+ const { baseClassNamePrefix: B, subElementClassPrefix: _, classModifierPrefix: p } = C("label");
16
+ let o = class extends P {
16
17
  constructor() {
17
- super(...arguments), this.disabled = !1, this.required = !1, i(this, c, () => !!(this.hasOptionalSlot || this.optional)), i(this, h, () => this.requestUpdate()), i(this, v, () => {
18
+ super(...arguments), this.disabled = !1, this.required = !1, b(this, n, () => this.requestUpdate()), b(this, y, () => {
19
+ if (this.for) {
20
+ const e = document.getElementById(this.for);
21
+ e == null || e.click();
22
+ }
18
23
  this.dispatchEvent(
19
24
  new CustomEvent("bm-label-click", {
20
25
  bubbles: !0,
21
26
  composed: !0
22
27
  })
23
28
  );
24
- }), i(this, y, () => u`
25
- <span
26
- class="${f(
27
- `${M}optional`,
28
- !r(this, c).call(this) && `${d}no-box`
29
+ }), b(this, u, () => d`
30
+ <span
31
+ class="${v(
32
+ `${_}optional`,
33
+ !this.hasOptional && `${p}no-box`
29
34
  )}"
30
- >
31
- <slot name="optional" @slotchange=${r(this, h)}>
32
- ${this.optional}
33
- </slot>
34
- </span>
35
- `);
35
+ >
36
+ <slot name="optional" @slotchange=${s(this, n)}> ${this.optional} </slot>
37
+ </span>
38
+ `), b(this, f, () => d`
39
+ <span
40
+ class="${v(
41
+ `${_}tooltip`,
42
+ !this.hasTooltipSlot && `${p}no-box`
43
+ )}"
44
+ >
45
+ <slot name="tooltip" @slotchange=${s(this, n)}></slot>
46
+ </span>
47
+ `);
36
48
  }
37
49
  get hasOptionalSlot() {
38
- return $(this.optionalNodes);
50
+ return g(this.optionalNodes);
51
+ }
52
+ get hasTooltipSlot() {
53
+ return g(this.tooltipNodes);
54
+ }
55
+ get hasOptional() {
56
+ return !!(this.hasOptionalSlot || this.optional);
39
57
  }
40
58
  render() {
41
- const e = f(
42
- z,
43
- this.theme && C(this.theme),
44
- this.disabled && `${d}disabled`,
45
- this.required && !r(this, c).call(this) && `${d}required`
59
+ const e = v(
60
+ B,
61
+ this.theme && O(this.theme),
62
+ this.disabled && `${p}disabled`,
63
+ this.required && !this.hasOptional && `${p}required`
46
64
  );
47
- return u`
65
+ return d`
48
66
  <div class="${e}">
49
- <label @click="${r(this, v)}">
67
+ <label for=${this.for || k} @click="${s(this, y)}">
50
68
  <slot name="text">${this.text}</slot>
51
- ${r(this, y).call(this)}
69
+ ${s(this, u).call(this)}
52
70
  </label>
53
- <slot name="tooltip"></slot>
71
+ ${s(this, f).call(this)}
54
72
  </div>
55
73
  `;
56
74
  }
57
75
  };
58
- c = /* @__PURE__ */ new WeakMap();
59
- h = /* @__PURE__ */ new WeakMap();
60
- v = /* @__PURE__ */ new WeakMap();
76
+ n = /* @__PURE__ */ new WeakMap();
61
77
  y = /* @__PURE__ */ new WeakMap();
62
- o.styles = _(w);
63
- m([
64
- s({ type: Boolean })
78
+ u = /* @__PURE__ */ new WeakMap();
79
+ f = /* @__PURE__ */ new WeakMap();
80
+ o.styles = $(w);
81
+ l([
82
+ m({ type: Boolean })
65
83
  ], o.prototype, "disabled", 2);
66
- m([
67
- s({ type: Boolean })
84
+ l([
85
+ m({ type: Boolean })
68
86
  ], o.prototype, "required", 2);
69
- m([
70
- s({ type: String })
87
+ l([
88
+ m({ type: String })
71
89
  ], o.prototype, "text", 2);
72
- m([
73
- s({ type: String })
90
+ l([
91
+ m({ type: String })
74
92
  ], o.prototype, "optional", 2);
75
- m([
76
- s({ type: String })
93
+ l([
94
+ m({ type: String })
95
+ ], o.prototype, "for", 2);
96
+ l([
97
+ m({ type: String })
77
98
  ], o.prototype, "theme", 2);
78
- m([
79
- P({ slot: "optional", flatten: !0 })
99
+ l([
100
+ S({ slot: "optional", flatten: !0 })
80
101
  ], o.prototype, "optionalNodes", 2);
81
- o = m([
82
- S("bm-label")
102
+ l([
103
+ S({ slot: "tooltip", flatten: !0 })
104
+ ], o.prototype, "tooltipNodes", 2);
105
+ o = l([
106
+ q("bm-label")
83
107
  ], o);
84
108
  export {
85
109
  o as BmLabel