@fluid-topics/ft-search-locale-selector 1.0.4

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 ADDED
@@ -0,0 +1,24 @@
1
+ Search locale selector for integrated fluid-topics search pages
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-search-locale-selector
7
+ yarn add @fluid-topics/ft-search-locale-selector
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-search-context"
15
+ import "@fluid-topics/ft-search-locale-selector"
16
+
17
+ function render() {
18
+ return html`
19
+ <ft-search-context>
20
+ <ft-search-locale-selector></ft-search-locale-selector>
21
+ </ft-search-context>
22
+ `
23
+ }
24
+ ```
@@ -0,0 +1,7 @@
1
+ import { I18nMessageContext, I18nMessages, DefaultI18nMessages } from "@fluid-topics/ft-i18n/build/generator/I18nMessageContext";
2
+ export interface SearchLocaleSelectorMessages extends I18nMessages {
3
+ label(): string;
4
+ allLanguagesWarningMessage(): string;
5
+ }
6
+ export declare const selectorContext: I18nMessageContext<SearchLocaleSelectorMessages>;
7
+ export declare const selectorDefaultMessages: DefaultI18nMessages<SearchLocaleSelectorMessages>;
@@ -0,0 +1,6 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n/build/generator/I18nMessageContext";
2
+ export const selectorContext = I18nMessageContext.build("designedSearchLocaleSelector");
3
+ export const selectorDefaultMessages = {
4
+ label: "Select a language",
5
+ allLanguagesWarningMessage: "Only recommended when searching for language-agnostic keywords such as product references",
6
+ };
@@ -0,0 +1,5 @@
1
+ export declare const FtSearchLocaleSelectorCssVariables: {
2
+ warningIconColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
3
+ warningTooltipMaxWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
4
+ };
5
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,19 @@
1
+ import { css } from "lit";
2
+ import { designSystemVariables, FtCssVariableFactory, setVariable } from "@fluid-topics/ft-wc-utils";
3
+ import { FtTooltipCssVariables } from "@fluid-topics/ft-tooltip/build/ft-tooltip.css";
4
+ export const FtSearchLocaleSelectorCssVariables = {
5
+ warningIconColor: FtCssVariableFactory.extend("--ft-search-locale-selector-warning-icon-color", designSystemVariables.colorError),
6
+ warningTooltipMaxWidth: FtCssVariableFactory.create("--ft-search-locale-selector-warning-tooltip-max-width", "SIZE", "250px")
7
+ };
8
+ // language=CSS
9
+ export const styles = css `
10
+
11
+ [part="warning-tooltip"] {
12
+ ${setVariable(FtTooltipCssVariables.maxWidth, FtSearchLocaleSelectorCssVariables.warningTooltipMaxWidth)};
13
+ }
14
+
15
+ [part="warning-icon"] {
16
+ color: ${FtSearchLocaleSelectorCssVariables.warningIconColor};
17
+ cursor: help;
18
+ }
19
+ `;
@@ -0,0 +1,20 @@
1
+ import { PropertyValues } from "lit";
2
+ import { FtSearchLocaleSelectorProperties } from "./ft-search-locale-selector.properties";
3
+ import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
4
+ import { FtSearchLocale } from "@fluid-topics/public-api";
5
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
6
+ import { Position } from "@fluid-topics/ft-tooltip";
7
+ declare const FtSearchLocaleSelector_base: typeof FtSearchComponent & (new (...args: any[]) => import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface);
8
+ export declare class FtSearchLocaleSelector extends FtSearchLocaleSelector_base implements FtSearchLocaleSelectorProperties {
9
+ static elementDefinitions: ElementDefinitionsMap;
10
+ static styles: import("lit").CSSResult;
11
+ warningTooltipPosition: Position;
12
+ locales?: Array<FtSearchLocale>;
13
+ currentSearchLocale?: string;
14
+ selectedSearchLocale?: string;
15
+ constructor();
16
+ protected render(): import("lit-html").TemplateResult<1>;
17
+ private setContentLocale;
18
+ protected updated(props: PropertyValues): void;
19
+ }
20
+ export {};
@@ -0,0 +1,88 @@
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, nothing } from "lit";
8
+ import { styles } from "./ft-search-locale-selector.css";
9
+ import { repeat } from "lit/directives/repeat.js";
10
+ import { property, state } from "lit/decorators.js";
11
+ import { withI18n } from "@fluid-topics/ft-i18n";
12
+ import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
13
+ import { redux } from "@fluid-topics/ft-wc-utils";
14
+ import { FtFilter, FtFilterOption } from "@fluid-topics/ft-filter";
15
+ import { FtIcon } from "@fluid-topics/ft-icon";
16
+ import { FtTooltip } from "@fluid-topics/ft-tooltip";
17
+ import { selectorContext, selectorDefaultMessages } from "./SearchLocaleSelectorMessages";
18
+ class FtSearchLocaleSelector extends withI18n(FtSearchComponent) {
19
+ constructor() {
20
+ super();
21
+ this.warningTooltipPosition = "left";
22
+ this.addI18nContext(selectorContext, selectorDefaultMessages);
23
+ }
24
+ render() {
25
+ var _a;
26
+ return html `
27
+ <ft-filter
28
+ exportpartsPrefix="filter"
29
+ label="${selectorContext.messages.label()}"
30
+ hideClearButton
31
+ @change=${(e) => this.setContentLocale(e)}
32
+ >
33
+ ${this.currentSearchLocale == null ? html `
34
+ <ft-tooltip slot="label"
35
+ part="warning-tooltip"
36
+ position="${this.warningTooltipPosition}"
37
+ text="${selectorContext.messages.allLanguagesWarningMessage()}">
38
+ <ft-icon value="warning" part="warning-icon"></ft-icon>
39
+ </ft-tooltip>
40
+ ` : nothing}
41
+ ${repeat(((_a = this.locales) !== null && _a !== void 0 ? _a : []), locale => locale.lang, locale => html `
42
+ <ft-filter-option label="${locale.label}"
43
+ .value=${locale.lang}
44
+ ?selected=${locale.lang == this.selectedSearchLocale}></ft-filter-option>
45
+ `)}
46
+ </ft-filter>
47
+ `;
48
+ }
49
+ setContentLocale(e) {
50
+ this.selectedSearchLocale = e.detail[0];
51
+ setTimeout(() => {
52
+ var _a;
53
+ if (e.detail.length > 0) {
54
+ this.selectedSearchLocale = (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setContentLocale(e.detail[0]);
55
+ }
56
+ else {
57
+ this.selectedSearchLocale = this.currentSearchLocale;
58
+ }
59
+ }, 0);
60
+ }
61
+ updated(props) {
62
+ super.updated(props);
63
+ if (props.has("currentSearchLocale")) {
64
+ this.selectedSearchLocale = this.currentSearchLocale;
65
+ this.dispatchEvent(new CustomEvent("current-search-locale-change", { detail: this.currentSearchLocale }));
66
+ }
67
+ }
68
+ }
69
+ FtSearchLocaleSelector.elementDefinitions = {
70
+ "ft-icon": FtIcon,
71
+ "ft-tooltip": FtTooltip,
72
+ "ft-filter": FtFilter,
73
+ "ft-filter-option": FtFilterOption
74
+ };
75
+ FtSearchLocaleSelector.styles = styles;
76
+ __decorate([
77
+ property()
78
+ ], FtSearchLocaleSelector.prototype, "warningTooltipPosition", void 0);
79
+ __decorate([
80
+ redux()
81
+ ], FtSearchLocaleSelector.prototype, "locales", void 0);
82
+ __decorate([
83
+ redux({ selector: (state) => state.request.contentLocale })
84
+ ], FtSearchLocaleSelector.prototype, "currentSearchLocale", void 0);
85
+ __decorate([
86
+ state()
87
+ ], FtSearchLocaleSelector.prototype, "selectedSearchLocale", void 0);
88
+ export { FtSearchLocaleSelector };