@fluid-topics/ft-text-field 0.2.2 → 0.2.6

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.
@@ -11,6 +11,7 @@ import { designSystemVariables, FtCssVariable, FtLitElement, setVariable } from
11
11
  import { FtTypography, FtTypographyBody1, FtTypographyBody1CssVariables } from "@fluid-topics/ft-typography";
12
12
  import { FtInputLabel, FtInputLabelCssVariables } from "@fluid-topics/ft-input-label";
13
13
  import { FtRipple, FtRippleCssVariables } from "@fluid-topics/ft-ripple";
14
+ import { FtIcon } from "@fluid-topics/ft-icon";
14
15
  export const FtTextFieldCssVariables = {
15
16
  fontSize: FtCssVariable.create("--ft-text-field-font-size", "SIZE", "14px"),
16
17
  labelSize: FtCssVariable.create("--ft-text-field-label-size", "SIZE", "11px"),
@@ -21,6 +22,9 @@ export const FtTextFieldCssVariables = {
21
22
  colorOnSurface: FtCssVariable.external(designSystemVariables.colorOnSurface, "Design system"),
22
23
  colorOnSurfaceDisabled: FtCssVariable.external(designSystemVariables.colorOnSurfaceDisabled, "Design system"),
23
24
  borderRadiusS: FtCssVariable.external(designSystemVariables.borderRadiusS, "Design system"),
25
+ colorError: FtCssVariable.external(designSystemVariables.colorError, "Design system"),
26
+ prefixColor: FtCssVariable.extend("--ft-text-field-prefix-color", designSystemVariables.colorOnSurfaceMedium),
27
+ iconColor: FtCssVariable.extend("--ft-text-field-icon-color", designSystemVariables.colorOnSurfaceMedium),
24
28
  };
25
29
  export class FtTextField extends FtLitElement {
26
30
  constructor() {
@@ -30,9 +34,16 @@ export class FtTextField extends FtLitElement {
30
34
  this.helper = "";
31
35
  this.outlined = false;
32
36
  this.disabled = false;
33
- this.dataList = [];
37
+ this.error = false;
38
+ this.prefix = "";
39
+ this.icon = "";
40
+ this.iconVariant = "";
34
41
  this.focused = false;
35
42
  }
43
+ focus() {
44
+ var _a;
45
+ (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
46
+ }
36
47
  render() {
37
48
  const classes = {
38
49
  "ft-text-field": true,
@@ -40,7 +51,10 @@ export class FtTextField extends FtLitElement {
40
51
  "ft-text-field--outlined": this.outlined,
41
52
  "ft-text-field--disabled": this.disabled,
42
53
  "ft-text-field--has-value": !!this.value,
43
- "ft-text-field--no-label": !this.label
54
+ "ft-text-field--no-label": !this.label,
55
+ "ft-text-field--in-error": this.error,
56
+ "ft-text-field--with-prefix": !!this.prefix,
57
+ "ft-text-field--raised-label": this.focused || this.value != "",
44
58
  };
45
59
  return html `
46
60
  <div class="${classMap(classes)}">
@@ -49,28 +63,28 @@ export class FtTextField extends FtLitElement {
49
63
  ?disabled=${this.disabled}
50
64
  ?outlined=${this.outlined}
51
65
  ?raised=${this.focused || this.value != ""}
66
+ ?error=${this.error}
52
67
  ></ft-input-label>
53
68
  <div class="ft-text-field--input-panel"
54
69
  aria-label="${this.label}">
55
70
  ${this.outlined ? null : html `
56
71
  <ft-ripple ?disabled=${this.disabled} activated></ft-ripple>
57
72
  `}
58
- <input type="text"
59
- class="ft-typography--body1 ft-text-field--input"
60
- ?disabled=${this.disabled}
61
- .value=${this.value}
62
- @change=${this.updateValueFromInputField}
63
- @keyup=${this.liveUpdateValueFromInputField}
64
- @focus=${() => this.focused = true}
65
- @focusout=${() => this.focused = false}
66
- list="datalist"
67
- />
68
-
69
- <datalist id="datalist">
70
- ${this.dataList.map(optionValue => html `
71
- <option value="${optionValue}"></option>`)}
72
- </datalist>
73
-
73
+ <div class="ft-text-field--input-wrapper">
74
+ <ft-typography class="ft-text-field--prefix" vaiant="body1">${this.prefix}</ft-typography>
75
+ <input type="text"
76
+ class="ft-typography--body1 ft-text-field--input"
77
+ ?disabled=${this.disabled}
78
+ .value=${this.value}
79
+ @change=${this.updateValueFromInputField}
80
+ @keyup=${this.liveUpdateValueFromInputField}
81
+ @focus=${() => this.focused = true}
82
+ @focusout=${() => this.focused = false}
83
+ />
84
+ </div>
85
+ ${this.icon ? html `
86
+ <ft-icon class="ft-text-field--icon" variant="${this.iconVariant}">${this.icon}
87
+ </ft-icon>` : undefined}
74
88
  </div>
75
89
  </div>
76
90
  ${this.helper ? html `
@@ -99,6 +113,7 @@ FtTextField.elementDefinitions = {
99
113
  "ft-input-label": FtInputLabel,
100
114
  "ft-ripple": FtRipple,
101
115
  "ft-typography": FtTypography,
116
+ "ft-icon": FtIcon,
102
117
  };
103
118
  // language=CSS
104
119
  FtTextField.styles = [
@@ -133,7 +148,6 @@ FtTextField.styles = [
133
148
  display: flex;
134
149
  align-items: center;
135
150
  overflow: hidden;
136
- gap: 8px;
137
151
  }
138
152
 
139
153
  .ft-text-field--input-panel ft-ripple {
@@ -141,22 +155,51 @@ FtTextField.styles = [
141
155
  ${setVariable(FtRippleCssVariables.opacityContentOnSurfacePressed, "0.04")};
142
156
  }
143
157
 
144
- .ft-text-field--input {
145
- display: block;
158
+ .ft-text-field--input-wrapper {
146
159
  flex-grow: 1;
147
160
  flex-shrink: 1;
148
- min-width: 0; /* flex sets this to auto an prevents input from shrinking properly */
161
+
162
+ display: flex;
163
+ align-items: center;
149
164
 
150
165
  ${setVariable(FtTypographyBody1CssVariables.fontSize, FtTextFieldCssVariables.fontSize)};
151
166
  ${setVariable(FtTypographyBody1CssVariables.lineHeight, FtTextFieldCssVariables.fontSize)};
152
- color: ${FtTextFieldCssVariables.colorOnSurface};
153
167
 
154
168
  padding: 0 ${FtTextFieldCssVariables.horizontalSpacing};
169
+ }
155
170
 
171
+ .ft-text-field--filled:not(.ft-text-field--no-label) .ft-text-field--input-wrapper {
172
+ align-items: flex-end;
173
+ padding: 0 ${FtTextFieldCssVariables.horizontalSpacing} ${FtTextFieldCssVariables.verticalSpacing} ${FtTextFieldCssVariables.horizontalSpacing};
174
+ }
175
+
176
+ .ft-text-field--prefix {
177
+ display: none;
178
+ color: ${FtTextFieldCssVariables.prefixColor}
179
+ }
180
+
181
+ .ft-text-field--with-prefix.ft-text-field--raised-label .ft-text-field--prefix {
182
+ display: block;
183
+ }
184
+
185
+ .ft-text-field--input {
186
+ display: block;
187
+ position: relative;
188
+ flex-grow: 1;
189
+ flex-shrink: 1;
190
+ min-width: 0; /* flex sets this to auto an prevents input from shrinking properly */
191
+
192
+ color: ${FtTextFieldCssVariables.colorOnSurface};
193
+ padding: calc(2 * ${FtTextFieldCssVariables.verticalSpacing}) 0;
156
194
  border: none;
157
195
  background: none;
158
196
  }
159
197
 
198
+ .ft-text-field--filled:not(.ft-text-field--no-label) .ft-text-field--input {
199
+ padding-bottom: 0;
200
+ padding-top: calc(${FtTextFieldCssVariables.labelSize} + 2 * ${FtTextFieldCssVariables.verticalSpacing});
201
+ }
202
+
160
203
  .ft-text-field--input::-webkit-calendar-picker-indicator,
161
204
  .ft-text-field--input::-webkit-list-button {
162
205
  display: none !important;
@@ -179,12 +222,6 @@ FtTextField.styles = [
179
222
  border-radius: ${FtTextFieldCssVariables.borderRadiusS} ${FtTextFieldCssVariables.borderRadiusS} 0 0;
180
223
  }
181
224
 
182
- .ft-text-field--filled:not(.ft-text-field--no-label) .ft-text-field--input {
183
- align-self: stretch;
184
- padding-bottom: ${FtTextFieldCssVariables.verticalSpacing};
185
- padding-top: calc(${FtTextFieldCssVariables.labelSize} + 2 * ${FtTextFieldCssVariables.verticalSpacing});
186
- }
187
-
188
225
  .ft-text-field--outlined .ft-text-field--input-panel {
189
226
  border-radius: ${FtTextFieldCssVariables.borderRadiusS};
190
227
  }
@@ -193,6 +230,17 @@ FtTextField.styles = [
193
230
  padding: 0 12px 0 ${FtTextFieldCssVariables.horizontalSpacing};
194
231
  color: ${FtTextFieldCssVariables.helperColor};
195
232
  }
233
+
234
+ .ft-text-field--in-error .ft-text-field--input,
235
+ .ft-text-field--in-error .ft-text-field--helper-text,
236
+ .ft-text-field--in-error .ft-text-field--prefix {
237
+ color: ${FtTextFieldCssVariables.colorError};
238
+ }
239
+
240
+ .ft-text-field--icon {
241
+ padding-right: ${FtTextFieldCssVariables.horizontalSpacing};
242
+ color: ${FtTextFieldCssVariables.iconColor};
243
+ }
196
244
  `
197
245
  ];
198
246
  __decorate([
@@ -210,12 +258,21 @@ __decorate([
210
258
  __decorate([
211
259
  property({ type: Boolean })
212
260
  ], FtTextField.prototype, "disabled", void 0);
261
+ __decorate([
262
+ property({ type: Boolean })
263
+ ], FtTextField.prototype, "error", void 0);
213
264
  __decorate([
214
265
  query(".ft-text-field--input")
215
266
  ], FtTextField.prototype, "input", void 0);
216
267
  __decorate([
217
- property({ attribute: false })
218
- ], FtTextField.prototype, "dataList", void 0);
268
+ property({ type: String })
269
+ ], FtTextField.prototype, "prefix", void 0);
270
+ __decorate([
271
+ property({ type: String })
272
+ ], FtTextField.prototype, "icon", void 0);
273
+ __decorate([
274
+ property({ type: String })
275
+ ], FtTextField.prototype, "iconVariant", void 0);
219
276
  __decorate([
220
277
  state()
221
278
  ], FtTextField.prototype, "focused", void 0);