@fluid-topics/ft-text-input 1.3.14 → 1.3.16

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.
@@ -2,11 +2,15 @@ import { FtdsTextInputProperties, FtdsTextInputType } from "./ftds-text-input.pr
2
2
  import { PropertyValues } from "lit/development";
3
3
  import { ElementDefinitionsMap, FtdsBase } from "@fluid-topics/ft-wc-utils";
4
4
  import { FtIcons } from "@fluid-topics/ft-icon";
5
+ export declare class ClearEvent extends Event {
6
+ constructor();
7
+ }
5
8
  declare const FtdsTextInput_base: typeof FtdsBase & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-wc-utils").FtInputInterface<string>> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
6
9
  export declare class FtdsTextInput extends FtdsTextInput_base implements FtdsTextInputProperties {
7
10
  static elementDefinitions: ElementDefinitionsMap;
8
11
  static styles: import("lit").CSSResult[];
9
12
  type: FtdsTextInputType;
13
+ clearable: boolean;
10
14
  private showClearPassword;
11
15
  private input?;
12
16
  constructor();
@@ -14,9 +18,10 @@ export declare class FtdsTextInput extends FtdsTextInput_base implements FtdsTex
14
18
  onInput(): void;
15
19
  connectedCallback(): void;
16
20
  protected willUpdate(props: PropertyValues): void;
17
- get showLabel(): string | false;
18
- get passwordIconForCurrentState(): FtIcons.EYE_SLASH | FtIcons.EYE | undefined;
21
+ get appendIcon(): FtIcons.EYE_SLASH | FtIcons.X_MARK | FtIcons.EYE | undefined;
22
+ get appendIconLabel(): string;
19
23
  protected render(): import("lit-html").TemplateResult<1>;
24
+ private onAppendedIconClick;
20
25
  private updateTypeBasedAdditionalRules;
21
26
  }
22
27
  export {};
@@ -18,11 +18,17 @@ import { withI18n } from "@fluid-topics/ft-i18n";
18
18
  import { textInputContext, textInputDefaultMessages } from "./TextInputMessages";
19
19
  import { FtTooltip } from "@fluid-topics/ft-tooltip";
20
20
  import { FtdsBaseInput } from "@fluid-topics/ft-base-input";
21
+ export class ClearEvent extends Event {
22
+ constructor() {
23
+ super("clear");
24
+ }
25
+ }
21
26
  class FtdsTextInput extends withI18n(toFtInput(FtdsBase)) {
22
27
  constructor() {
23
28
  var _a;
24
29
  super();
25
30
  this.type = FtdsTextInputType.text;
31
+ this.clearable = false;
26
32
  this.showClearPassword = false;
27
33
  this.value = (_a = this.value) !== null && _a !== void 0 ? _a : "";
28
34
  this.addI18nContext(textInputContext, textInputDefaultMessages);
@@ -47,11 +53,26 @@ class FtdsTextInput extends withI18n(toFtInput(FtdsBase)) {
47
53
  this.updateTypeBasedAdditionalRules(this.type);
48
54
  }
49
55
  }
50
- get showLabel() {
51
- return !this.hideLabel && this.label;
56
+ get appendIcon() {
57
+ if (this.disabled) {
58
+ return undefined;
59
+ }
60
+ if (this.type === FtdsTextInputType.password) {
61
+ return this.showClearPassword ? FtIcons.EYE_SLASH : FtIcons.EYE;
62
+ }
63
+ if (this.clearable && this.value) {
64
+ return FtIcons.X_MARK;
65
+ }
66
+ return undefined;
52
67
  }
53
- get passwordIconForCurrentState() {
54
- return (this.type === FtdsTextInputType.password && !this.disabled) ? (this.showClearPassword ? FtIcons.EYE_SLASH : FtIcons.EYE) : undefined;
68
+ get appendIconLabel() {
69
+ if (this.type === FtdsTextInputType.password) {
70
+ return this.showClearPassword ? textInputContext.messages.hidePassword() : textInputContext.messages.showPassword();
71
+ }
72
+ if (this.clearable) {
73
+ return textInputContext.messages.clear();
74
+ }
75
+ return "";
55
76
  }
56
77
  render() {
57
78
  const inputClasses = classMap({
@@ -73,13 +94,12 @@ class FtdsTextInput extends withI18n(toFtInput(FtdsBase)) {
73
94
  ?hideLabel=${this.hideLabel}
74
95
  ?raiseLabel=${(this.type == FtdsTextInputType.date || this.type == FtdsTextInputType.time || this.focused || this.value != "")}
75
96
 
76
- .appendIcon=${this.passwordIconForCurrentState}
77
- .appendIconLabel=${this.showClearPassword ? textInputContext.messages.hidePassword() : textInputContext.messages.showPassword()}
97
+ .appendIcon=${this.appendIcon}
98
+ .appendIconLabel=${this.appendIconLabel}
78
99
  appendIconIsClickable
79
- @append-icon-click="${() => this.showClearPassword = !this.showClearPassword}"
100
+ @append-icon-click="${this.onAppendedIconClick}"
80
101
 
81
102
  >
82
-
83
103
  <input class="${inputClasses}"
84
104
  name="${this.name}"
85
105
  .value=${this.value}
@@ -92,12 +112,19 @@ class FtdsTextInput extends withI18n(toFtInput(FtdsBase)) {
92
112
  aria-invalid="${this.status === Status.error}"
93
113
  aria-describedby="${this.messagesForScreenReaderElementId}"
94
114
  />
95
-
96
115
  ${this.renderMessagesForScreenReader()}
97
-
98
116
  </ftds-base-input>
99
117
  `;
100
118
  }
119
+ onAppendedIconClick() {
120
+ if (this.type === FtdsTextInputType.password) {
121
+ this.showClearPassword = !this.showClearPassword;
122
+ }
123
+ else if (this.clearable) {
124
+ this.value = "";
125
+ this.dispatchEvent(new ClearEvent());
126
+ }
127
+ }
101
128
  updateTypeBasedAdditionalRules(type) {
102
129
  this.additionalErrorRules = (() => {
103
130
  switch (type) {
@@ -128,6 +155,9 @@ FtdsTextInput.styles = [styles];
128
155
  __decorate([
129
156
  property()
130
157
  ], FtdsTextInput.prototype, "type", void 0);
158
+ __decorate([
159
+ property({ type: Boolean })
160
+ ], FtdsTextInput.prototype, "clearable", void 0);
131
161
  __decorate([
132
162
  state()
133
163
  ], FtdsTextInput.prototype, "showClearPassword", void 0);
@@ -6,8 +6,10 @@ export declare enum FtdsTextInputType {
6
6
  url = "url",
7
7
  number = "number",
8
8
  date = "date",
9
- time = "time"
9
+ time = "time",
10
+ search = "search"
10
11
  }
11
12
  export interface FtdsTextInputProperties extends FtInputInterface<string> {
12
13
  type: FtdsTextInputType;
14
+ clearable: boolean;
13
15
  }
@@ -7,4 +7,5 @@ export var FtdsTextInputType;
7
7
  FtdsTextInputType["number"] = "number";
8
8
  FtdsTextInputType["date"] = "date";
9
9
  FtdsTextInputType["time"] = "time";
10
+ FtdsTextInputType["search"] = "search";
10
11
  })(FtdsTextInputType || (FtdsTextInputType = {}));
@@ -39,4 +39,9 @@ export const styles = css `
39
39
  font-weight: ${typographyBody2Medium.fontWeight};
40
40
  }
41
41
 
42
+ input[type="search"]::-webkit-search-cancel-button,
43
+ input[type="search"]::-webkit-search-decoration {
44
+ -webkit-appearance: none;
45
+ appearance: none;
46
+ }
42
47
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-text-input",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "description": "Text Input",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,17 +19,17 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-base-input": "1.3.14",
23
- "@fluid-topics/ft-i18n": "1.3.14",
24
- "@fluid-topics/ft-icon": "1.3.14",
25
- "@fluid-topics/ft-input-helper-text": "1.3.14",
26
- "@fluid-topics/ft-input-label": "1.3.14",
27
- "@fluid-topics/ft-tooltip": "1.3.14",
28
- "@fluid-topics/ft-wc-utils": "1.3.14",
22
+ "@fluid-topics/ft-base-input": "1.3.16",
23
+ "@fluid-topics/ft-i18n": "1.3.16",
24
+ "@fluid-topics/ft-icon": "1.3.16",
25
+ "@fluid-topics/ft-input-helper-text": "1.3.16",
26
+ "@fluid-topics/ft-input-label": "1.3.16",
27
+ "@fluid-topics/ft-tooltip": "1.3.16",
28
+ "@fluid-topics/ft-wc-utils": "1.3.16",
29
29
  "lit": "3.1.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@fluid-topics/ft-wc-test-utils": "1.3.14"
32
+ "@fluid-topics/ft-wc-test-utils": "1.3.16"
33
33
  },
34
- "gitHead": "18f0f8e7a68ec235ee6838c4f86002821393322e"
34
+ "gitHead": "092d409b397263ffef1f860386137eea8e5f7c2c"
35
35
  }