@fluid-topics/ft-button 2.1.22 → 2.1.24

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.
@@ -1,7 +1,7 @@
1
1
  import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
2
2
  import { Position } from "@fluid-topics/ft-tooltip";
3
3
  import { FtIconVariants } from "@fluid-topics/ft-icon";
4
- import { HTMLTemplateResult } from "lit";
4
+ import { HTMLTemplateResult, PropertyValues } from "lit";
5
5
  import { ClassInfo } from "lit/directives/class-map.js";
6
6
  import { FtButtonProperties, HTMLAnchorElementTargetAttribute } from "./ft-button.properties";
7
7
  declare const FtButton_base: import("@fluid-topics/ft-wc-utils").FtFormComponentType<typeof FtLitElement>;
@@ -15,7 +15,7 @@ export declare class FtButton extends FtButton_base implements FtButtonPropertie
15
15
  icon?: string;
16
16
  iconVariant?: FtIconVariants;
17
17
  trailingIcon: boolean;
18
- label: string;
18
+ label?: string;
19
19
  type: "button" | "submit" | "reset";
20
20
  href?: string;
21
21
  target?: HTMLAnchorElementTargetAttribute;
@@ -28,6 +28,8 @@ export declare class FtButton extends FtButton_base implements FtButtonPropertie
28
28
  forceTooltip: boolean;
29
29
  activated: boolean;
30
30
  private button?;
31
+ private labelContainer?;
32
+ hasTextContent: boolean;
31
33
  private slottedContent?;
32
34
  private tooltip?;
33
35
  static styles: import("lit").CSSResult[];
@@ -41,10 +43,9 @@ export declare class FtButton extends FtButton_base implements FtButtonPropertie
41
43
  showTemporaryTooltip(text: string, duration: number): Promise<void> | undefined;
42
44
  private setTooltipManual;
43
45
  click(): void;
44
- private getLabel;
45
- getTextContent(): string;
46
- protected hasTextContent(): boolean;
47
- private onSlotchange;
48
46
  private isDisabled;
47
+ private static readonly labelsObserver;
48
+ protected contentAvailableCallback(props: PropertyValues): void;
49
+ disconnectedCallback(): void;
49
50
  }
50
51
  export {};
@@ -4,14 +4,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { FtLitElement, isSafari, noTextSelect, safariEllipsisFix, toFtFormComponent, unslotText, } from "@fluid-topics/ft-wc-utils";
7
+ import { FtLitElement, isSafari, noTextSelect, safariEllipsisFix, toFtFormComponent, } from "@fluid-topics/ft-wc-utils";
8
8
  import { FtRipple } from "@fluid-topics/ft-ripple";
9
9
  import { FtTooltip, } from "@fluid-topics/ft-tooltip";
10
10
  import { FtIcon, } from "@fluid-topics/ft-icon";
11
11
  import { FtLoader } from "@fluid-topics/ft-loader";
12
12
  import { html, } from "lit";
13
13
  import { classMap, } from "lit/directives/class-map.js";
14
- import { property, query, } from "lit/decorators.js";
14
+ import { property, query, state, } from "lit/decorators.js";
15
15
  import { ifDefined } from "lit/directives/if-defined.js";
16
16
  import { FtTypography, FtTypographyVariants, } from "@fluid-topics/ft-typography";
17
17
  import { buttonStyles } from "./ft-button.styles";
@@ -37,7 +37,6 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
37
37
  this.disabled = false;
38
38
  this.icon = undefined;
39
39
  this.trailingIcon = false;
40
- this.label = "";
41
40
  this.type = "button";
42
41
  this.href = undefined;
43
42
  this.target = undefined;
@@ -49,6 +48,7 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
49
48
  this.hideTooltip = false;
50
49
  this.forceTooltip = false;
51
50
  this.activated = false;
51
+ this.hasTextContent = false;
52
52
  this.addEventListener("click", (e) => {
53
53
  var _a;
54
54
  if (this.isDisabled()) {
@@ -63,6 +63,11 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
63
63
  }
64
64
  render() {
65
65
  var _a, _b, _c;
66
+ const labelClasses = {
67
+ "ft-button--label": true,
68
+ "ft-safari-ellipsis-fix": isSafari,
69
+ "ft-button--label-no-text": !this.hasTextContent,
70
+ };
66
71
  const content = html `
67
72
  <ft-ripple part="ripple"
68
73
  ?disabled=${this.isDisabled()}
@@ -71,9 +76,8 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
71
76
  <ft-typography part="label"
72
77
  variant="${FtTypographyVariants.button}"
73
78
  element="span"
74
- class="ft-button--label ${isSafari ? "ft-safari-ellipsis-fix" : ""}"
75
- ?hidden=${!this.hasTextContent()}>
76
- <slot @slotchange=${this.onSlotchange}></slot>
79
+ class="${classMap(labelClasses)}">
80
+ <slot></slot>
77
81
  </ft-typography>
78
82
  ${this.resolveIcon()}
79
83
  `;
@@ -83,14 +87,14 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
83
87
  target="${(_a = this.target) !== null && _a !== void 0 ? _a : "_self"}"
84
88
  part="button"
85
89
  class="${classMap(this.buttonClasses)}"
86
- aria-label="${(_b = this.ariaLabel) !== null && _b !== void 0 ? _b : this.getLabel()}"
90
+ aria-label="${ifDefined((_b = this.ariaLabel) !== null && _b !== void 0 ? _b : this.label)}"
87
91
  ?disabled=${this.isDisabled()}>
88
92
  ${content}
89
93
  </a>
90
94
  ` : html `
91
95
  <button part="button"
92
96
  class="${classMap(this.buttonClasses)}"
93
- aria-label="${(_c = this.ariaLabel) !== null && _c !== void 0 ? _c : this.getLabel()}"
97
+ aria-label="${ifDefined((_c = this.ariaLabel) !== null && _c !== void 0 ? _c : this.label)}"
94
98
  aria-haspopup="${ifDefined(this.ariaHasPopup)}"
95
99
  aria-pressed="${ifDefined(this.ariaPressed)}"
96
100
  ?disabled=${this.isDisabled()}>
@@ -99,10 +103,10 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
99
103
  `);
100
104
  }
101
105
  addTooltipIfNeeded(button) {
102
- return this.getLabel().trim().length > 0 && (this.forceTooltip || (!this.hasTextContent() && !this.hideTooltip))
106
+ return this.label && this.label.trim().length > 0 && (this.forceTooltip || (!this.hasTextContent && !this.hideTooltip))
103
107
  ? html `
104
108
  <ft-tooltip part="tooltip"
105
- text="${this.getLabel()}"
109
+ text="${this.label}"
106
110
  position="${this.tooltipPosition}">
107
111
  ${button}
108
112
  </ft-tooltip>
@@ -143,21 +147,21 @@ export class FtButton extends toFtFormComponent(FtLitElement) {
143
147
  var _a;
144
148
  (_a = this.button) === null || _a === void 0 ? void 0 : _a.click();
145
149
  }
146
- getLabel() {
147
- return this.label || this.getTextContent();
148
- }
149
- getTextContent() {
150
- return unslotText(this.slottedContent).trim();
151
- }
152
- hasTextContent() {
153
- return this.getTextContent().length > 0;
154
- }
155
- onSlotchange() {
156
- this.requestUpdate();
157
- }
158
150
  isDisabled() {
159
151
  return this.disabled || this.loading;
160
152
  }
153
+ contentAvailableCallback(props) {
154
+ super.contentAvailableCallback(props);
155
+ if (this.labelContainer) {
156
+ FtButton.labelsObserver.observe(this.labelContainer);
157
+ }
158
+ }
159
+ disconnectedCallback() {
160
+ super.disconnectedCallback();
161
+ if (this.labelContainer) {
162
+ FtButton.labelsObserver.unobserve(this.labelContainer);
163
+ }
164
+ }
161
165
  }
162
166
  FtButton.elementDefinitions = {
163
167
  "ft-ripple": FtRipple,
@@ -171,6 +175,17 @@ FtButton.styles = [
171
175
  buttonStyles,
172
176
  noTextSelect,
173
177
  ];
178
+ FtButton.labelsObserver = new IntersectionObserver((labels) => {
179
+ for (const label of labels) {
180
+ const root = label.target.getRootNode();
181
+ if (root.host) {
182
+ root.host.hasTextContent = label.boundingClientRect.width > 0;
183
+ }
184
+ else {
185
+ FtButton.labelsObserver.unobserve(label.target);
186
+ }
187
+ }
188
+ });
174
189
  __decorate([
175
190
  property({ type: Boolean })
176
191
  ], FtButton.prototype, "primary", void 0);
@@ -234,6 +249,12 @@ __decorate([
234
249
  __decorate([
235
250
  query(".ft-button")
236
251
  ], FtButton.prototype, "button", void 0);
252
+ __decorate([
253
+ query(".ft-button--label")
254
+ ], FtButton.prototype, "labelContainer", void 0);
255
+ __decorate([
256
+ state()
257
+ ], FtButton.prototype, "hasTextContent", void 0);
237
258
  __decorate([
238
259
  query(".ft-button--label slot")
239
260
  ], FtButton.prototype, "slottedContent", void 0);