@fluid-topics/ft-search-input 0.3.62
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/README.md +21 -0
- package/build/SearchInputMessages.d.ts +7 -0
- package/build/SearchInputMessages.js +3 -0
- package/build/ft-search-input-suggestion.css.d.ts +2 -0
- package/build/ft-search-input-suggestion.css.js +47 -0
- package/build/ft-search-input-suggestion.d.ts +21 -0
- package/build/ft-search-input-suggestion.js +120 -0
- package/build/ft-search-input-suggestion.properties.d.ts +3 -0
- package/build/ft-search-input-suggestion.properties.js +2 -0
- package/build/ft-search-input.css.d.ts +16 -0
- package/build/ft-search-input.css.js +96 -0
- package/build/ft-search-input.d.ts +22 -0
- package/build/ft-search-input.js +117 -0
- package/build/ft-search-input.light.js +708 -0
- package/build/ft-search-input.min.js +845 -0
- package/build/ft-search-input.properties.d.ts +3 -0
- package/build/ft-search-input.properties.js +2 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +7 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Search bar input for integrated search component
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-search-input
|
|
7
|
+
yarn add @fluid-topics/ft-search-input
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ft-search-input"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html`<ft-search-context>
|
|
18
|
+
<ft-search-input></ft-search-input>
|
|
19
|
+
</ft-search-context>`
|
|
20
|
+
}
|
|
21
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export interface SearchInputMessages extends I18nMessages {
|
|
3
|
+
placeholder(): string;
|
|
4
|
+
searchButton(): string;
|
|
5
|
+
}
|
|
6
|
+
export declare const searchInputContext: I18nMessageContext<SearchInputMessages>;
|
|
7
|
+
//# sourceMappingURL=SearchInputMessages.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
import { FtSearchInputCssVariables } from "./ft-search-input.css";
|
|
3
|
+
// language=CSS
|
|
4
|
+
export const suggestionStyles = css `
|
|
5
|
+
* {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ft-search-input-suggestion {
|
|
10
|
+
position: absolute;
|
|
11
|
+
z-index: ${FtSearchInputCssVariables.floatingZIndex};
|
|
12
|
+
top: calc(100% + 2px);
|
|
13
|
+
left: -1px;
|
|
14
|
+
right: -1px;
|
|
15
|
+
background: ${FtSearchInputCssVariables.colorSurface};
|
|
16
|
+
border: 1px solid ${FtSearchInputCssVariables.colorOutline};
|
|
17
|
+
border-radius: 0 0 ${FtSearchInputCssVariables.borderRadius} ${FtSearchInputCssVariables.borderRadius};
|
|
18
|
+
box-shadow: ${FtSearchInputCssVariables.elevation02};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.ft-search-input-suggestion--suggestion {
|
|
22
|
+
text-decoration: none;
|
|
23
|
+
position: relative;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
padding: 8px;
|
|
27
|
+
gap: 8px;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
color: ${FtSearchInputCssVariables.colorOnSurface};
|
|
30
|
+
min-height: 44px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.ft-search-input-suggestion--suggestion > *:not(ft-ripple) {
|
|
34
|
+
position: relative;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ft-search-input-suggestion--suggestion:focus {
|
|
38
|
+
outline: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ft-search-input-suggestion--suggestion ft-typography {
|
|
42
|
+
display: block;
|
|
43
|
+
flex-grow: 1;
|
|
44
|
+
flex-shrink: 1;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
//# sourceMappingURL=ft-search-input-suggestion.css.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtSearchInputSuggestionProperties } from "./ft-search-input-suggestion.properties";
|
|
3
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
4
|
+
export declare class SuggestionSelectedEvent extends CustomEvent<string> {
|
|
5
|
+
constructor(value: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class FtSearchInputSuggestion extends FtSearchComponent implements FtSearchInputSuggestionProperties {
|
|
8
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
9
|
+
static styles: import("lit").CSSResult[];
|
|
10
|
+
private suggestResults;
|
|
11
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
12
|
+
private onSuggestKeyDown;
|
|
13
|
+
private onSuggestKeyUp;
|
|
14
|
+
private onSuggestSelected;
|
|
15
|
+
private getIcon;
|
|
16
|
+
private getFocusedSuggestionElement;
|
|
17
|
+
private getLastSuggestionElement;
|
|
18
|
+
private getFirstSuggestionElement;
|
|
19
|
+
focusFirstSuggestion(): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ft-search-input-suggestion.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
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 { redux, wordWrap } from "@fluid-topics/ft-wc-utils";
|
|
8
|
+
import { html } from "lit";
|
|
9
|
+
import { customElement } from "lit/decorators.js";
|
|
10
|
+
import { suggestionStyles } from "./ft-search-input-suggestion.css";
|
|
11
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
12
|
+
import { FtIcon, FtIcons, FtIconVariants, resolveFileFormatIcon } from "@fluid-topics/ft-icon";
|
|
13
|
+
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
14
|
+
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
15
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
16
|
+
export class SuggestionSelectedEvent extends CustomEvent {
|
|
17
|
+
constructor(value) {
|
|
18
|
+
super("suggestion-selected", { detail: value });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let FtSearchInputSuggestion = class FtSearchInputSuggestion extends FtSearchComponent {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.suggestResults = [];
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
return html `
|
|
28
|
+
<div class="ft-search-input-suggestion ft-word-wrap"
|
|
29
|
+
part="container"
|
|
30
|
+
@keydown=${(e) => this.onSuggestKeyDown(e)}>
|
|
31
|
+
${repeat(this.suggestResults, suggest => suggest.value, suggest => html `
|
|
32
|
+
<a href="#"
|
|
33
|
+
part="suggestion"
|
|
34
|
+
class="ft-search-input-suggestion--suggestion"
|
|
35
|
+
@keyup=${(e) => this.onSuggestKeyUp(e, suggest.value)}
|
|
36
|
+
@click=${(e) => this.onSuggestSelected(e, suggest.value)}>
|
|
37
|
+
<ft-ripple></ft-ripple>
|
|
38
|
+
${this.getIcon(suggest)}
|
|
39
|
+
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
40
|
+
</a>
|
|
41
|
+
`)}
|
|
42
|
+
</div>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
onSuggestKeyDown(e) {
|
|
46
|
+
var _a, _b, _c, _d, _e, _f;
|
|
47
|
+
switch (e.key) {
|
|
48
|
+
case "ArrowUp":
|
|
49
|
+
(_c = ((_b = (_a = this.getFocusedSuggestionElement()) === null || _a === void 0 ? void 0 : _a.previousElementSibling) !== null && _b !== void 0 ? _b : this.getLastSuggestionElement())) === null || _c === void 0 ? void 0 : _c.focus();
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
break;
|
|
53
|
+
case "ArrowDown":
|
|
54
|
+
(_f = ((_e = (_d = this.getFocusedSuggestionElement()) === null || _d === void 0 ? void 0 : _d.nextElementSibling) !== null && _e !== void 0 ? _e : this.getFirstSuggestionElement())) === null || _f === void 0 ? void 0 : _f.focus();
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
onSuggestKeyUp(e, suggest) {
|
|
61
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
62
|
+
this.onSuggestSelected(e, suggest);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
onSuggestSelected(e, suggest) {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
this.dispatchEvent(new SuggestionSelectedEvent(suggest));
|
|
68
|
+
}
|
|
69
|
+
getIcon(suggest) {
|
|
70
|
+
const iconVariant = suggest.type === "DOCUMENT" ? FtIconVariants.file_format : FtIconVariants.fluid_topics;
|
|
71
|
+
let icon;
|
|
72
|
+
switch (suggest.type) {
|
|
73
|
+
case "MAP":
|
|
74
|
+
icon = suggest.editorialType === "BOOK" ? FtIcons.BOOK : FtIcons.ARTICLE;
|
|
75
|
+
break;
|
|
76
|
+
case "DOCUMENT":
|
|
77
|
+
icon = resolveFileFormatIcon(suggest.mimeType, suggest.filenameExtension);
|
|
78
|
+
break;
|
|
79
|
+
case "TOPIC":
|
|
80
|
+
icon = FtIcons.TOPICS;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return html `
|
|
84
|
+
<ft-icon variant="${iconVariant}" part="suggestion-icon">
|
|
85
|
+
${icon}
|
|
86
|
+
</ft-icon>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
getFocusedSuggestionElement() {
|
|
90
|
+
return this.shadowRoot.querySelector(".ft-search-input-suggestion--suggestion:focus-within");
|
|
91
|
+
}
|
|
92
|
+
getLastSuggestionElement() {
|
|
93
|
+
let suggestions = this.shadowRoot.querySelectorAll(".ft-search-input-suggestion--suggestion");
|
|
94
|
+
return suggestions.length > 0 ? suggestions[suggestions.length - 1] : null;
|
|
95
|
+
}
|
|
96
|
+
getFirstSuggestionElement() {
|
|
97
|
+
return this.shadowRoot.querySelector(".ft-search-input-suggestion--suggestion");
|
|
98
|
+
}
|
|
99
|
+
focusFirstSuggestion() {
|
|
100
|
+
var _a;
|
|
101
|
+
(_a = this.getFirstSuggestionElement()) === null || _a === void 0 ? void 0 : _a.focus();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
FtSearchInputSuggestion.elementDefinitions = {
|
|
105
|
+
"ft-ripple": FtRipple,
|
|
106
|
+
"ft-typography": FtTypography,
|
|
107
|
+
"ft-icon": FtIcon,
|
|
108
|
+
};
|
|
109
|
+
FtSearchInputSuggestion.styles = [
|
|
110
|
+
wordWrap,
|
|
111
|
+
suggestionStyles,
|
|
112
|
+
];
|
|
113
|
+
__decorate([
|
|
114
|
+
redux()
|
|
115
|
+
], FtSearchInputSuggestion.prototype, "suggestResults", void 0);
|
|
116
|
+
FtSearchInputSuggestion = __decorate([
|
|
117
|
+
customElement("ft-search-input-suggestion")
|
|
118
|
+
], FtSearchInputSuggestion);
|
|
119
|
+
export { FtSearchInputSuggestion };
|
|
120
|
+
//# sourceMappingURL=ft-search-input-suggestion.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const FtSearchInputCssVariables: {
|
|
2
|
+
height: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
3
|
+
borderRadius: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
4
|
+
desktopFiltersHeight: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
5
|
+
floatingZIndex: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
6
|
+
colorSurface: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
7
|
+
colorOnSurface: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
8
|
+
colorOnSurfaceMedium: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
9
|
+
colorOutline: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
10
|
+
colorPrimary: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
11
|
+
elevation02: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
12
|
+
buttonColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
13
|
+
buttonRippleColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
14
|
+
};
|
|
15
|
+
export declare const styles: import("lit").CSSResult;
|
|
16
|
+
//# sourceMappingURL=ft-search-input.css.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
import { designSystemVariables, FtCssVariableFactory, setVariable } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { FtButtonCssVariables } from "@fluid-topics/ft-button";
|
|
4
|
+
import { FtTooltipCssVariables } from "@fluid-topics/ft-tooltip";
|
|
5
|
+
export const FtSearchInputCssVariables = {
|
|
6
|
+
height: FtCssVariableFactory.create("--ft-search-input-height", "SIZE", "38px"),
|
|
7
|
+
borderRadius: FtCssVariableFactory.extend("--ft-search-input-border-radius", designSystemVariables.borderRadiusS),
|
|
8
|
+
desktopFiltersHeight: FtCssVariableFactory.create("--ft-search-input-desktop-filters-height", "SIZE", "350px"),
|
|
9
|
+
floatingZIndex: FtCssVariableFactory.create("--ft-search-input-floating-components-z-index", "NUMBER", "3"),
|
|
10
|
+
colorSurface: FtCssVariableFactory.external(designSystemVariables.colorSurface, "Design system"),
|
|
11
|
+
colorOnSurface: FtCssVariableFactory.external(designSystemVariables.colorOnSurface, "Design system"),
|
|
12
|
+
colorOnSurfaceMedium: FtCssVariableFactory.external(designSystemVariables.colorOnSurfaceMedium, "Design system"),
|
|
13
|
+
colorOutline: FtCssVariableFactory.external(designSystemVariables.colorOutline, "Design system"),
|
|
14
|
+
colorPrimary: FtCssVariableFactory.external(designSystemVariables.colorPrimary, "Design system"),
|
|
15
|
+
elevation02: FtCssVariableFactory.external(designSystemVariables.elevation02, "Design system"),
|
|
16
|
+
buttonColor: FtCssVariableFactory.external(FtButtonCssVariables.color, "Button"),
|
|
17
|
+
buttonRippleColor: FtCssVariableFactory.external(FtButtonCssVariables.rippleColor, "Button"),
|
|
18
|
+
};
|
|
19
|
+
// language=CSS
|
|
20
|
+
export const styles = css `
|
|
21
|
+
* {
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ft-search-input {
|
|
26
|
+
position: relative;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: row;
|
|
29
|
+
align-items: center;
|
|
30
|
+
height: ${FtSearchInputCssVariables.height};
|
|
31
|
+
|
|
32
|
+
background: ${FtSearchInputCssVariables.colorSurface};
|
|
33
|
+
border: 1px solid ${FtSearchInputCssVariables.colorOutline};
|
|
34
|
+
border-radius: ${FtSearchInputCssVariables.borderRadius};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ft-search-input--input-container {
|
|
38
|
+
flex-grow: 1;
|
|
39
|
+
flex-shrink: 1;
|
|
40
|
+
position: relative;
|
|
41
|
+
height: calc(100% - 2px);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.ft-search-input--input-outline {
|
|
45
|
+
height: 100%;
|
|
46
|
+
width: 100%;
|
|
47
|
+
display: grid;
|
|
48
|
+
padding: 0 8px;
|
|
49
|
+
border-radius: ${FtSearchInputCssVariables.borderRadius};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ft-search-input--input-container:focus-within .ft-search-input--input-outline {
|
|
53
|
+
outline: 2px solid ${FtSearchInputCssVariables.colorPrimary};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.ft-search-input--input {
|
|
57
|
+
height: 100%;
|
|
58
|
+
border: none;
|
|
59
|
+
background-color: transparent;
|
|
60
|
+
color: ${FtSearchInputCssVariables.colorOnSurface};
|
|
61
|
+
outline: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.ft-search-input--input::placeholder {
|
|
65
|
+
color: ${FtSearchInputCssVariables.colorOnSurfaceMedium};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.ft-search-input--actions {
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: row;
|
|
72
|
+
align-items: center;
|
|
73
|
+
height: 100%;
|
|
74
|
+
|
|
75
|
+
${setVariable(FtTooltipCssVariables.zIndex, `calc(${FtSearchInputCssVariables.floatingZIndex} + 1)`)};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ft-search-input > ft-button,
|
|
79
|
+
.ft-search-input--actions ft-button {
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
${setVariable(FtButtonCssVariables.backgroundColor, "transparent")};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.ft-search-input .ft-search-input--launch-search {
|
|
85
|
+
margin: 0 4px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ft-search-input-suggestion {
|
|
89
|
+
display: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.ft-search-input.ft-search-input--with-suggestions:focus-within:not(.ft-search-input--with-suggestions-closed) ft-search-input-suggestion {
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
//# sourceMappingURL=ft-search-input.css.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtSearchInputProperties } from "./ft-search-input.properties";
|
|
3
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
4
|
+
declare const FtSearchInput_base: typeof FtSearchComponent & (new (...args: any[]) => import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface);
|
|
5
|
+
export declare class FtSearchInput extends FtSearchInput_base implements FtSearchInputProperties {
|
|
6
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
7
|
+
static styles: import("lit").CSSResult[];
|
|
8
|
+
constructor();
|
|
9
|
+
private request?;
|
|
10
|
+
private liveQuery;
|
|
11
|
+
private suggestResults;
|
|
12
|
+
private forceCloseSuggestion;
|
|
13
|
+
private input;
|
|
14
|
+
private suggestion;
|
|
15
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
16
|
+
private onSearchBarKeyDown;
|
|
17
|
+
private onSearchBarKeyUp;
|
|
18
|
+
private launchSearch;
|
|
19
|
+
private onSuggestionSelected;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=ft-search-input.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { html } from "lit";
|
|
8
|
+
import { redux } from "@fluid-topics/ft-wc-utils";
|
|
9
|
+
import { styles } from "./ft-search-input.css";
|
|
10
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
11
|
+
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
12
|
+
import { searchInputContext } from "./SearchInputMessages";
|
|
13
|
+
import { query, state } from "lit/decorators.js";
|
|
14
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
15
|
+
import { FtSearchInputSuggestion } from "./ft-search-input-suggestion";
|
|
16
|
+
import { FtButton } from "@fluid-topics/ft-button";
|
|
17
|
+
import { FtTypographyBody2 } from "@fluid-topics/ft-typography";
|
|
18
|
+
export class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.liveQuery = "";
|
|
22
|
+
this.suggestResults = [];
|
|
23
|
+
this.forceCloseSuggestion = false;
|
|
24
|
+
this.addI18nContext(searchInputContext);
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
let classes = {
|
|
28
|
+
"ft-search-input": true,
|
|
29
|
+
"ft-search-input--with-suggestions": this.suggestResults.length > 0,
|
|
30
|
+
"ft-search-input--with-suggestions-closed": this.forceCloseSuggestion,
|
|
31
|
+
};
|
|
32
|
+
return html `
|
|
33
|
+
<div class="${classMap(classes)}" @focusout=${() => this.forceCloseSuggestion = false}>
|
|
34
|
+
<div class="ft-search-input--input-container" part="input-container" tabindex="-1">
|
|
35
|
+
<div class="ft-search-input--input-outline" part="input-outline">
|
|
36
|
+
<input class="ft-search-input--input ft-typography--body2"
|
|
37
|
+
part="input"
|
|
38
|
+
type="text"
|
|
39
|
+
placeholder="${searchInputContext.messages.placeholder()}"
|
|
40
|
+
.value="${this.liveQuery}"
|
|
41
|
+
@keydown=${(e) => this.onSearchBarKeyDown(e)}
|
|
42
|
+
@keyup=${(e) => this.onSearchBarKeyUp(e)}>
|
|
43
|
+
</div>
|
|
44
|
+
<ft-search-input-suggestion exportpartsPrefix="suggestion"
|
|
45
|
+
@suggestion-selected=${this.onSuggestionSelected}
|
|
46
|
+
></ft-search-input-suggestion>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="ft-search-input--actions" part="actions">
|
|
49
|
+
<ft-button class="ft-search-input--launch-search"
|
|
50
|
+
part="launch-search-in-input"
|
|
51
|
+
icon="search"
|
|
52
|
+
round dense
|
|
53
|
+
label="${searchInputContext.messages.searchButton()}"
|
|
54
|
+
@click=${() => this.launchSearch()}
|
|
55
|
+
></ft-button>
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
onSearchBarKeyDown(e) {
|
|
61
|
+
switch (e.key) {
|
|
62
|
+
case "ArrowDown":
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
this.suggestion.focusFirstSuggestion();
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
onSearchBarKeyUp(e) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (e.key === "Enter") {
|
|
72
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(this.input.value);
|
|
73
|
+
this.forceCloseSuggestion = true;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
(_b = this.stateManager) === null || _b === void 0 ? void 0 : _b.setLiveQuery(this.input.value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
launchSearch() {
|
|
80
|
+
var _a;
|
|
81
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(this.liveQuery);
|
|
82
|
+
this.forceCloseSuggestion = true;
|
|
83
|
+
}
|
|
84
|
+
onSuggestionSelected(e) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(e.detail);
|
|
87
|
+
(_b = this.stateManager) === null || _b === void 0 ? void 0 : _b.setLiveQuery(e.detail);
|
|
88
|
+
this.forceCloseSuggestion = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
FtSearchInput.elementDefinitions = {
|
|
92
|
+
"ft-search-input-suggestion": FtSearchInputSuggestion,
|
|
93
|
+
"ft-button": FtButton,
|
|
94
|
+
};
|
|
95
|
+
FtSearchInput.styles = [
|
|
96
|
+
FtTypographyBody2,
|
|
97
|
+
styles,
|
|
98
|
+
];
|
|
99
|
+
__decorate([
|
|
100
|
+
redux()
|
|
101
|
+
], FtSearchInput.prototype, "request", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
redux()
|
|
104
|
+
], FtSearchInput.prototype, "liveQuery", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
redux()
|
|
107
|
+
], FtSearchInput.prototype, "suggestResults", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
state()
|
|
110
|
+
], FtSearchInput.prototype, "forceCloseSuggestion", void 0);
|
|
111
|
+
__decorate([
|
|
112
|
+
query(".ft-search-input--input")
|
|
113
|
+
], FtSearchInput.prototype, "input", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
query("ft-search-input-suggestion")
|
|
116
|
+
], FtSearchInput.prototype, "suggestion", void 0);
|
|
117
|
+
//# sourceMappingURL=ft-search-input.js.map
|