@fluid-topics/ft-text-field 0.3.36 → 0.3.38
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/build/ft-text-field-suggestion.css.d.ts +2 -0
- package/build/ft-text-field-suggestion.css.js +29 -0
- package/build/ft-text-field-suggestion.d.ts +20 -0
- package/build/ft-text-field-suggestion.js +75 -0
- package/build/ft-text-field-suggestion.properties.d.ts +4 -0
- package/build/ft-text-field-suggestion.properties.js +2 -0
- package/build/ft-text-field.css.d.ts +5 -0
- package/build/ft-text-field.css.js +54 -24
- package/build/ft-text-field.d.ts +21 -8
- package/build/ft-text-field.js +133 -47
- package/build/ft-text-field.light.js +195 -127
- package/build/ft-text-field.min.js +294 -222
- package/build/ft-text-field.properties.d.ts +3 -2
- package/build/index.d.ts +3 -0
- package/build/index.js +5 -0
- package/package.json +7 -6
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
// language=CSS
|
|
3
|
+
export const suggestionStyles = css `
|
|
4
|
+
.ft-text-field-suggestion {
|
|
5
|
+
position: relative;
|
|
6
|
+
padding: 8px 16px;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
min-height: 44px;
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
outline: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ft-text-field-suggestion,
|
|
14
|
+
.ft-text-field-suggestion--label {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 8px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.ft-text-field-suggestion--label {
|
|
21
|
+
flex-grow: 1;
|
|
22
|
+
flex-shrink: 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
slot {
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
//# sourceMappingURL=ft-text-field-suggestion.css.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtTextFieldSuggestionProperties } from "./ft-text-field-suggestion.properties";
|
|
3
|
+
export declare class SuggestionSelectedEvent extends CustomEvent<string> {
|
|
4
|
+
constructor(value: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class FtTextFieldSuggestion extends FtLitElement implements FtTextFieldSuggestionProperties {
|
|
7
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
8
|
+
value?: string;
|
|
9
|
+
private container?;
|
|
10
|
+
private assignedNodes;
|
|
11
|
+
static styles: import("lit").CSSResult;
|
|
12
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
13
|
+
focus(options?: FocusOptions): void;
|
|
14
|
+
click(): void;
|
|
15
|
+
private confirmSuggestion;
|
|
16
|
+
getValue(): string;
|
|
17
|
+
get textContent(): string;
|
|
18
|
+
private onKeyDown;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ft-text-field-suggestion.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
8
|
+
import { html } from "lit";
|
|
9
|
+
import { property, query, queryAssignedNodes } from "lit/decorators.js";
|
|
10
|
+
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
11
|
+
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
12
|
+
import { suggestionStyles } from "./ft-text-field-suggestion.css";
|
|
13
|
+
import { FtIcon } from "@fluid-topics/ft-icon";
|
|
14
|
+
export class SuggestionSelectedEvent extends CustomEvent {
|
|
15
|
+
constructor(value) {
|
|
16
|
+
super("suggestion-selected", { detail: value, bubbles: true, composed: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class FtTextFieldSuggestion extends FtLitElement {
|
|
20
|
+
render() {
|
|
21
|
+
return html `
|
|
22
|
+
<div class="ft-text-field-suggestion"
|
|
23
|
+
tabindex="-1"
|
|
24
|
+
@keydown=${this.onKeyDown}
|
|
25
|
+
@click=${this.confirmSuggestion}>
|
|
26
|
+
<ft-ripple></ft-ripple>
|
|
27
|
+
<ft-typography part="label"
|
|
28
|
+
variant="body1"
|
|
29
|
+
class="ft-text-field-suggestion--label">
|
|
30
|
+
<slot></slot>
|
|
31
|
+
</ft-typography>
|
|
32
|
+
</div>
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
focus(options) {
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = this.container) === null || _a === void 0 ? void 0 : _a.focus(options);
|
|
38
|
+
}
|
|
39
|
+
click() {
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = this.container) === null || _a === void 0 ? void 0 : _a.click();
|
|
42
|
+
}
|
|
43
|
+
confirmSuggestion() {
|
|
44
|
+
this.dispatchEvent(new SuggestionSelectedEvent(this.getValue()));
|
|
45
|
+
}
|
|
46
|
+
getValue() {
|
|
47
|
+
return this.value || this.textContent;
|
|
48
|
+
}
|
|
49
|
+
get textContent() {
|
|
50
|
+
return this.assignedNodes.map(n => n.textContent).join("").trim();
|
|
51
|
+
}
|
|
52
|
+
onKeyDown(event) {
|
|
53
|
+
if (["Enter", " "].includes(event.key)) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
event.stopPropagation();
|
|
56
|
+
this.confirmSuggestion();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
FtTextFieldSuggestion.elementDefinitions = {
|
|
61
|
+
"ft-ripple": FtRipple,
|
|
62
|
+
"ft-typography": FtTypography,
|
|
63
|
+
"ft-icon": FtIcon,
|
|
64
|
+
};
|
|
65
|
+
FtTextFieldSuggestion.styles = suggestionStyles;
|
|
66
|
+
__decorate([
|
|
67
|
+
property()
|
|
68
|
+
], FtTextFieldSuggestion.prototype, "value", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
query(".ft-text-field-suggestion")
|
|
71
|
+
], FtTextFieldSuggestion.prototype, "container", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
queryAssignedNodes()
|
|
74
|
+
], FtTextFieldSuggestion.prototype, "assignedNodes", void 0);
|
|
75
|
+
//# sourceMappingURL=ft-text-field-suggestion.js.map
|
|
@@ -11,6 +11,11 @@ export declare const FtTextFieldCssVariables: {
|
|
|
11
11
|
colorError: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
12
12
|
prefixColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
13
13
|
iconColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
14
|
+
floatingZIndex: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
15
|
+
colorSurface: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
16
|
+
colorOutline: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
17
|
+
elevation02: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
18
|
+
suggestSize: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
14
19
|
};
|
|
15
20
|
export declare const styles: import("lit").CSSResult;
|
|
16
21
|
//# sourceMappingURL=ft-text-field.css.d.ts.map
|
|
@@ -16,6 +16,11 @@ export const FtTextFieldCssVariables = {
|
|
|
16
16
|
colorError: FtCssVariableFactory.external(designSystemVariables.colorError, "Design system"),
|
|
17
17
|
prefixColor: FtCssVariableFactory.extend("--ft-text-field-prefix-color", designSystemVariables.colorOnSurfaceMedium),
|
|
18
18
|
iconColor: FtCssVariableFactory.extend("--ft-text-field-icon-color", designSystemVariables.colorOnSurfaceMedium),
|
|
19
|
+
floatingZIndex: FtCssVariableFactory.create("--ft-text-field-floating-components-z-index", "NUMBER", "3"),
|
|
20
|
+
colorSurface: FtCssVariableFactory.external(designSystemVariables.colorSurface, "Design system"),
|
|
21
|
+
colorOutline: FtCssVariableFactory.external(designSystemVariables.colorOutline, "Design system"),
|
|
22
|
+
elevation02: FtCssVariableFactory.external(designSystemVariables.elevation02, "Design system"),
|
|
23
|
+
suggestSize: FtCssVariableFactory.create("--ft-text-field-suggest-size", "SIZE", "300px"),
|
|
19
24
|
};
|
|
20
25
|
// language=CSS
|
|
21
26
|
export const styles = css `
|
|
@@ -27,6 +32,7 @@ export const styles = css `
|
|
|
27
32
|
display: flex;
|
|
28
33
|
flex-direction: column;
|
|
29
34
|
align-items: stretch;
|
|
35
|
+
position: relative;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
ft-input-label {
|
|
@@ -48,6 +54,10 @@ export const styles = css `
|
|
|
48
54
|
display: flex;
|
|
49
55
|
align-items: center;
|
|
50
56
|
overflow: hidden;
|
|
57
|
+
padding: 0 ${FtTextFieldCssVariables.horizontalSpacing};
|
|
58
|
+
|
|
59
|
+
${setVariable(FtTypographyBody1CssVariables.fontSize, FtTextFieldCssVariables.fontSize)};
|
|
60
|
+
${setVariable(FtTypographyBody1CssVariables.lineHeight, FtTextFieldCssVariables.fontSize)};
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
.ft-text-field--input-panel ft-ripple {
|
|
@@ -55,31 +65,22 @@ export const styles = css `
|
|
|
55
65
|
${setVariable(FtRippleCssVariables.opacityContentOnSurfacePressed, "0.04")};
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
.ft-text-field--input-
|
|
59
|
-
flex-grow: 1;
|
|
60
|
-
flex-shrink: 1;
|
|
61
|
-
|
|
62
|
-
display: flex;
|
|
63
|
-
align-items: center;
|
|
64
|
-
|
|
65
|
-
${setVariable(FtTypographyBody1CssVariables.fontSize, FtTextFieldCssVariables.fontSize)};
|
|
66
|
-
${setVariable(FtTypographyBody1CssVariables.lineHeight, FtTextFieldCssVariables.fontSize)};
|
|
67
|
-
|
|
68
|
-
padding: 0 ${FtTextFieldCssVariables.horizontalSpacing};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.ft-text-field--filled:not(.ft-text-field--no-label) .ft-text-field--input-wrapper {
|
|
68
|
+
.ft-text-field--filled.ft-text-field--with-label .ft-text-field--input-panel {
|
|
72
69
|
align-items: flex-end;
|
|
73
70
|
padding: 0 ${FtTextFieldCssVariables.horizontalSpacing} ${FtTextFieldCssVariables.verticalSpacing} ${FtTextFieldCssVariables.horizontalSpacing};
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
.ft-text-field--prefix {
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
color: ${FtTextFieldCssVariables.prefixColor};
|
|
75
|
+
margin-right: 2px;
|
|
76
|
+
flex-shrink: 1;
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
white-space: nowrap;
|
|
79
|
+
text-overflow: ellipsis;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
.ft-text-field--with-
|
|
82
|
-
display:
|
|
82
|
+
.ft-text-field--with-label:not(.ft-text-field--raised-label) .ft-text-field--prefix {
|
|
83
|
+
display: none;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
.ft-text-field--input {
|
|
@@ -95,7 +96,7 @@ export const styles = css `
|
|
|
95
96
|
background: none;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
.ft-text-field--filled
|
|
99
|
+
.ft-text-field--filled.ft-text-field--with-label .ft-text-field--input {
|
|
99
100
|
padding-bottom: 0;
|
|
100
101
|
padding-top: calc(${FtTextFieldCssVariables.labelSize} + 2 * ${FtTextFieldCssVariables.verticalSpacing});
|
|
101
102
|
}
|
|
@@ -109,10 +110,6 @@ export const styles = css `
|
|
|
109
110
|
color: ${FtTextFieldCssVariables.colorOnSurfaceDisabled};
|
|
110
111
|
}
|
|
111
112
|
|
|
112
|
-
.ft-text-field:not(.ft-text-field--disabled) .ft-text-field--input-panel {
|
|
113
|
-
cursor: pointer;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
113
|
.ft-text-field:not(.ft-text-field--disabled):focus-within ft-input-label {
|
|
117
114
|
${setVariable(FtInputLabelCssVariables.borderColor, FtTextFieldCssVariables.colorPrimary)};
|
|
118
115
|
${setVariable(FtInputLabelCssVariables.textColor, FtTextFieldCssVariables.colorPrimary)};
|
|
@@ -138,8 +135,41 @@ export const styles = css `
|
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
.ft-text-field--icon {
|
|
141
|
-
|
|
138
|
+
align-self: center;
|
|
139
|
+
margin-left: 8px;
|
|
142
140
|
color: ${FtTextFieldCssVariables.iconColor};
|
|
143
141
|
}
|
|
142
|
+
|
|
143
|
+
.ft-text-field--container {
|
|
144
|
+
position: relative;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.ft-text-field--suggestions {
|
|
148
|
+
display: none;
|
|
149
|
+
flex-direction: column;
|
|
150
|
+
position: absolute;
|
|
151
|
+
left: 0;
|
|
152
|
+
right: 0;
|
|
153
|
+
z-index: ${FtTextFieldCssVariables.floatingZIndex};
|
|
154
|
+
background: ${FtTextFieldCssVariables.colorSurface};
|
|
155
|
+
border: 1px solid ${FtTextFieldCssVariables.colorOutline};
|
|
156
|
+
border-radius: 0 0 ${FtTextFieldCssVariables.borderRadiusS} ${FtTextFieldCssVariables.borderRadiusS};
|
|
157
|
+
box-shadow: ${FtTextFieldCssVariables.elevation02};
|
|
158
|
+
outline: none;
|
|
159
|
+
max-height: ${FtTextFieldCssVariables.suggestSize};
|
|
160
|
+
overflow-y: auto;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.ft-text-field--suggestions:not(.ft-text-field--suggestions-on-top) {
|
|
164
|
+
top: 100%;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.ft-text-field--suggestions.ft-text-field--suggestions-on-top {
|
|
168
|
+
bottom: 100%;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.ft-text-field--suggestions-displayed .ft-text-field--suggestions {
|
|
172
|
+
display: flex;
|
|
173
|
+
}
|
|
144
174
|
`;
|
|
145
175
|
//# sourceMappingURL=ft-text-field.css.js.map
|
package/build/ft-text-field.d.ts
CHANGED
|
@@ -4,21 +4,34 @@ import { FtTextFieldProperties } from "./ft-text-field.properties";
|
|
|
4
4
|
export declare class FtTextField extends FtLitElement implements FtTextFieldProperties {
|
|
5
5
|
static elementDefinitions: ElementDefinitionsMap;
|
|
6
6
|
static styles: import("lit").CSSResult[];
|
|
7
|
-
label
|
|
7
|
+
label?: string;
|
|
8
8
|
value: string;
|
|
9
|
-
helper
|
|
9
|
+
helper?: string;
|
|
10
10
|
outlined: boolean;
|
|
11
11
|
disabled: boolean;
|
|
12
12
|
error: boolean;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
prefix: string | null;
|
|
14
|
+
icon?: string;
|
|
15
|
+
iconVariant?: string;
|
|
16
|
+
filterSuggestions: boolean;
|
|
17
17
|
private focused;
|
|
18
|
+
private suggestionsOnTop;
|
|
19
|
+
private displaySuggestions;
|
|
20
|
+
private visibleSuggestions;
|
|
21
|
+
private input?;
|
|
22
|
+
private suggestionsContainer?;
|
|
23
|
+
private suggestions;
|
|
18
24
|
focus(): void;
|
|
19
25
|
protected render(): import("lit-html").TemplateResult<1>;
|
|
20
|
-
protected
|
|
26
|
+
protected update(props: PropertyValues): void;
|
|
27
|
+
private filterSuggestionsIfNeeded;
|
|
28
|
+
protected contentAvailableCallback(props: PropertyValues): void;
|
|
21
29
|
private updateValueFromInputField;
|
|
22
|
-
private
|
|
30
|
+
private handleInput;
|
|
31
|
+
setValue(newValue: string, fireEvent?: boolean): void;
|
|
32
|
+
private handleKeyboardNavigation;
|
|
33
|
+
private onSuggestionSelected;
|
|
34
|
+
private onFocus;
|
|
35
|
+
private onFocusOut;
|
|
23
36
|
}
|
|
24
37
|
//# sourceMappingURL=ft-text-field.d.ts.map
|
package/build/ft-text-field.js
CHANGED
|
@@ -4,8 +4,8 @@ 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 { html } from "lit";
|
|
8
|
-
import { property, query, state } from "lit/decorators.js";
|
|
7
|
+
import { html, nothing } from "lit";
|
|
8
|
+
import { property, query, queryAssignedElements, state } from "lit/decorators.js";
|
|
9
9
|
import { classMap } from "lit/directives/class-map.js";
|
|
10
10
|
import { FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
11
11
|
import { FtTypography, FtTypographyBody1 } from "@fluid-topics/ft-typography";
|
|
@@ -16,16 +16,16 @@ import { styles } from "./ft-text-field.css";
|
|
|
16
16
|
export class FtTextField extends FtLitElement {
|
|
17
17
|
constructor() {
|
|
18
18
|
super(...arguments);
|
|
19
|
-
this.label = "";
|
|
20
19
|
this.value = "";
|
|
21
|
-
this.helper = "";
|
|
22
20
|
this.outlined = false;
|
|
23
21
|
this.disabled = false;
|
|
24
22
|
this.error = false;
|
|
25
|
-
this.prefix =
|
|
26
|
-
this.
|
|
27
|
-
this.iconVariant = "";
|
|
23
|
+
this.prefix = null;
|
|
24
|
+
this.filterSuggestions = false;
|
|
28
25
|
this.focused = false;
|
|
26
|
+
this.suggestionsOnTop = false;
|
|
27
|
+
this.displaySuggestions = false;
|
|
28
|
+
this.visibleSuggestions = 0;
|
|
29
29
|
}
|
|
30
30
|
focus() {
|
|
31
31
|
var _a;
|
|
@@ -38,62 +38,130 @@ export class FtTextField extends FtLitElement {
|
|
|
38
38
|
"ft-text-field--outlined": this.outlined,
|
|
39
39
|
"ft-text-field--disabled": this.disabled,
|
|
40
40
|
"ft-text-field--has-value": !!this.value,
|
|
41
|
-
"ft-text-field--
|
|
41
|
+
"ft-text-field--with-label": !!this.label,
|
|
42
42
|
"ft-text-field--in-error": this.error,
|
|
43
43
|
"ft-text-field--with-prefix": !!this.prefix,
|
|
44
|
+
"ft-text-field--suggestions-displayed": this.visibleSuggestions > 0 && this.displaySuggestions,
|
|
44
45
|
"ft-text-field--raised-label": this.focused || this.value != "",
|
|
45
46
|
};
|
|
46
47
|
return html `
|
|
47
48
|
<div class="${classMap(classes)}">
|
|
48
|
-
<div class="ft-text-field--main-panel"
|
|
49
|
+
<div class="ft-text-field--main-panel"
|
|
50
|
+
@keydown=${this.handleKeyboardNavigation}
|
|
51
|
+
@focusout=${this.onFocusOut}>
|
|
49
52
|
<ft-input-label text="${this.label}"
|
|
50
53
|
?disabled=${this.disabled}
|
|
51
54
|
?outlined=${this.outlined}
|
|
52
55
|
?raised=${this.focused || this.value != ""}
|
|
53
|
-
?error=${this.error}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
aria-label="${this.label}">
|
|
57
|
-
${this.outlined ? null : html `
|
|
56
|
+
?error=${this.error}></ft-input-label>
|
|
57
|
+
<div class="ft-text-field--input-panel">
|
|
58
|
+
${this.outlined ? nothing : html `
|
|
58
59
|
<ft-ripple ?disabled=${this.disabled} activated></ft-ripple>
|
|
59
60
|
`}
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@focusout=${() => this.focused = false}
|
|
70
|
-
/>
|
|
71
|
-
</div>
|
|
61
|
+
<ft-typography class="ft-text-field--prefix" vaiant="body1">${this.prefix}</ft-typography>
|
|
62
|
+
<input type="text"
|
|
63
|
+
aria-label="${this.label}"
|
|
64
|
+
class="ft-typography--body1 ft-text-field--input"
|
|
65
|
+
?disabled=${this.disabled}
|
|
66
|
+
.value=${this.value}
|
|
67
|
+
@change=${this.updateValueFromInputField}
|
|
68
|
+
@keyup=${this.handleInput}
|
|
69
|
+
@focus=${this.onFocus}/>
|
|
72
70
|
${this.icon ? html `
|
|
73
|
-
<ft-icon class="ft-text-field--icon"
|
|
74
|
-
|
|
71
|
+
<ft-icon class="ft-text-field--icon"
|
|
72
|
+
.variant=${this.iconVariant}
|
|
73
|
+
.value=${this.icon}
|
|
74
|
+
@click=${() => { var _a; return (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus(); }}></ft-icon>
|
|
75
|
+
` : nothing}
|
|
76
|
+
</div>
|
|
77
|
+
<div class="ft-text-field--suggestions ${this.suggestionsOnTop ? "ft-text-field--suggestions-on-top" : ""}"
|
|
78
|
+
@suggestion-selected=${this.onSuggestionSelected}>
|
|
79
|
+
<slot @slotchange=${() => this.filterSuggestionsIfNeeded()}></slot>
|
|
75
80
|
</div>
|
|
76
81
|
</div>
|
|
77
82
|
${this.helper ? html `
|
|
78
|
-
<ft-typography class="ft-text-field--helper-text" variant="caption"
|
|
79
|
-
|
|
83
|
+
<ft-typography class="ft-text-field--helper-text" variant="caption">
|
|
84
|
+
${this.helper}
|
|
85
|
+
</ft-typography>
|
|
86
|
+
` : nothing}
|
|
80
87
|
</div>
|
|
81
88
|
`;
|
|
82
89
|
}
|
|
83
|
-
|
|
84
|
-
super.
|
|
85
|
-
if (props.has("value")) {
|
|
86
|
-
this.
|
|
90
|
+
update(props) {
|
|
91
|
+
super.update(props);
|
|
92
|
+
if (props.has("value") || props.has("filterSuggestions")) {
|
|
93
|
+
this.filterSuggestionsIfNeeded();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
filterSuggestionsIfNeeded() {
|
|
97
|
+
if (this.filterSuggestions) {
|
|
98
|
+
this.suggestions.forEach(s => s.hidden = !s.getValue().toLowerCase().includes(this.value.toLowerCase()));
|
|
99
|
+
this.visibleSuggestions = this.suggestions.filter(s => !s.hidden).length;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.visibleSuggestions = this.suggestions.length;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
contentAvailableCallback(props) {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
super.contentAvailableCallback(props);
|
|
108
|
+
if (this.suggestions.length && props.has("suggestionsDisplayed") && this.displaySuggestions) {
|
|
109
|
+
const rect = (_a = this.input) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
110
|
+
const suggestRect = (_b = this.suggestionsContainer) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
|
|
111
|
+
if (rect && suggestRect) {
|
|
112
|
+
this.suggestionsOnTop = rect.bottom + suggestRect.height > window.innerHeight && rect.top - suggestRect.height > 0;
|
|
113
|
+
}
|
|
87
114
|
}
|
|
88
115
|
}
|
|
89
116
|
updateValueFromInputField() {
|
|
90
117
|
var _a;
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
118
|
+
this.setValue(((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || "", true);
|
|
119
|
+
this.displaySuggestions = false;
|
|
120
|
+
}
|
|
121
|
+
handleInput() {
|
|
122
|
+
var _a;
|
|
123
|
+
const newValue = ((_a = this.input) === null || _a === void 0 ? void 0 : _a.value) || "";
|
|
124
|
+
if (this.value !== newValue) {
|
|
125
|
+
this.value = newValue;
|
|
126
|
+
this.dispatchEvent(new CustomEvent("live-change", { detail: this.value }));
|
|
127
|
+
}
|
|
93
128
|
}
|
|
94
|
-
|
|
129
|
+
setValue(newValue, fireEvent) {
|
|
130
|
+
this.value = newValue;
|
|
131
|
+
if (fireEvent) {
|
|
132
|
+
this.dispatchEvent(new CustomEvent("change", { detail: this.value }));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
handleKeyboardNavigation(event) {
|
|
95
136
|
var _a;
|
|
96
|
-
this.
|
|
137
|
+
if (this.suggestions.length && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
event.stopPropagation();
|
|
140
|
+
this.displaySuggestions = true;
|
|
141
|
+
const currentSuggestion = this.suggestions.findIndex((element) => element.matches((":focus-within")));
|
|
142
|
+
let target;
|
|
143
|
+
if (event.key === "ArrowDown") {
|
|
144
|
+
target = currentSuggestion < this.suggestions.length - 1 ? currentSuggestion + 1 : 0;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
target = currentSuggestion > 0 ? currentSuggestion - 1 : this.suggestions.length - 1;
|
|
148
|
+
}
|
|
149
|
+
(_a = this.suggestions[target]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
onSuggestionSelected(event) {
|
|
153
|
+
var _a;
|
|
154
|
+
this.setValue(event.detail, true);
|
|
155
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
|
|
156
|
+
setTimeout(() => this.displaySuggestions = false, 0);
|
|
157
|
+
}
|
|
158
|
+
onFocus() {
|
|
159
|
+
this.focused = true;
|
|
160
|
+
this.displaySuggestions = true;
|
|
161
|
+
}
|
|
162
|
+
onFocusOut() {
|
|
163
|
+
this.focused = false;
|
|
164
|
+
setTimeout(() => { var _a, _b; return this.displaySuggestions = this.focused || ((_b = (_a = this.suggestionsContainer) === null || _a === void 0 ? void 0 : _a.matches(":focus-within")) !== null && _b !== void 0 ? _b : false); }, 0);
|
|
97
165
|
}
|
|
98
166
|
}
|
|
99
167
|
FtTextField.elementDefinitions = {
|
|
@@ -108,13 +176,13 @@ FtTextField.styles = [
|
|
|
108
176
|
styles
|
|
109
177
|
];
|
|
110
178
|
__decorate([
|
|
111
|
-
property(
|
|
179
|
+
property()
|
|
112
180
|
], FtTextField.prototype, "label", void 0);
|
|
113
181
|
__decorate([
|
|
114
|
-
property(
|
|
182
|
+
property()
|
|
115
183
|
], FtTextField.prototype, "value", void 0);
|
|
116
184
|
__decorate([
|
|
117
|
-
property(
|
|
185
|
+
property()
|
|
118
186
|
], FtTextField.prototype, "helper", void 0);
|
|
119
187
|
__decorate([
|
|
120
188
|
property({ type: Boolean })
|
|
@@ -126,18 +194,36 @@ __decorate([
|
|
|
126
194
|
property({ type: Boolean })
|
|
127
195
|
], FtTextField.prototype, "error", void 0);
|
|
128
196
|
__decorate([
|
|
129
|
-
|
|
130
|
-
], FtTextField.prototype, "input", void 0);
|
|
131
|
-
__decorate([
|
|
132
|
-
property({ type: String })
|
|
197
|
+
property()
|
|
133
198
|
], FtTextField.prototype, "prefix", void 0);
|
|
134
199
|
__decorate([
|
|
135
|
-
property(
|
|
200
|
+
property()
|
|
136
201
|
], FtTextField.prototype, "icon", void 0);
|
|
137
202
|
__decorate([
|
|
138
|
-
property(
|
|
203
|
+
property()
|
|
139
204
|
], FtTextField.prototype, "iconVariant", void 0);
|
|
205
|
+
__decorate([
|
|
206
|
+
property({ type: Boolean })
|
|
207
|
+
], FtTextField.prototype, "filterSuggestions", void 0);
|
|
140
208
|
__decorate([
|
|
141
209
|
state()
|
|
142
210
|
], FtTextField.prototype, "focused", void 0);
|
|
211
|
+
__decorate([
|
|
212
|
+
state()
|
|
213
|
+
], FtTextField.prototype, "suggestionsOnTop", void 0);
|
|
214
|
+
__decorate([
|
|
215
|
+
state()
|
|
216
|
+
], FtTextField.prototype, "displaySuggestions", void 0);
|
|
217
|
+
__decorate([
|
|
218
|
+
state()
|
|
219
|
+
], FtTextField.prototype, "visibleSuggestions", void 0);
|
|
220
|
+
__decorate([
|
|
221
|
+
query(".ft-text-field--input")
|
|
222
|
+
], FtTextField.prototype, "input", void 0);
|
|
223
|
+
__decorate([
|
|
224
|
+
query(".ft-text-field--suggestions")
|
|
225
|
+
], FtTextField.prototype, "suggestionsContainer", void 0);
|
|
226
|
+
__decorate([
|
|
227
|
+
queryAssignedElements({ selector: "ft-text-field-suggestion" })
|
|
228
|
+
], FtTextField.prototype, "suggestions", void 0);
|
|
143
229
|
//# sourceMappingURL=ft-text-field.js.map
|