@digital-realty/ix-search-bar 2.1.2 → 2.1.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 CHANGED
@@ -23,45 +23,6 @@ npm i @digital-realty/ix-search-bar
23
23
  import { IxSearchBar } from '@digital-realty/ix-search-bar/IxSearchBar'
24
24
  </script>
25
25
  ```
26
- ## Linting and formatting
26
+ ## Demo and Documentation
27
27
 
28
- To scan the project for linting and formatting errors, run
29
-
30
- ```bash
31
- npm run lint
32
- ```
33
-
34
- To automatically fix linting and formatting errors, run
35
-
36
- ```bash
37
- npm run format
38
- ```
39
-
40
- ## Testing with Web Test Runner
41
-
42
- To execute a single test run:
43
-
44
- ```bash
45
- npm run test
46
- ```
47
-
48
- To run the tests in interactive watch mode run:
49
-
50
- ```bash
51
- npm run test:watch
52
- ```
53
-
54
-
55
- ## Tooling configs
56
-
57
- For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
58
-
59
- If you customize the configuration a lot, you can consider moving them to individual files.
60
-
61
- ## Local Demo with `web-dev-server`
62
-
63
- ```bash
64
- npm start
65
- ```
66
-
67
- To run a local development server that serves the basic demo located in `demo/index.html`
28
+ Full documentation and demo are available at [DLR Component Gallery](https://inxn-p1-uicomponentgallery.azurewebsites.net/?path=/story/inxn-ix-search-bar--default).
@@ -0,0 +1,22 @@
1
+ import { LitElement } from 'lit';
2
+ import '@digital-realty/ix-textbox';
3
+ import { Item } from './types/index.js';
4
+ export declare class IxSearchBar extends LitElement {
5
+ value: string;
6
+ items: Item[];
7
+ searchFields: string[];
8
+ foundItems: Item[];
9
+ static get styles(): import("lit").CSSResult[];
10
+ connectedCallback(): void;
11
+ resetResults(): void;
12
+ get itemsCount(): number;
13
+ get itemsLabel(): "item" | "items";
14
+ _dispatchEvent(items: Item[]): void;
15
+ filterItems(value: string): void;
16
+ render(): import("lit-html").TemplateResult<1>;
17
+ }
18
+ declare global {
19
+ interface HTMLElementTagNameMap {
20
+ 'ix-search-bar': IxSearchBar;
21
+ }
22
+ }
@@ -0,0 +1,86 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement } from 'lit';
3
+ import { property } from 'lit/decorators.js';
4
+ import '@digital-realty/ix-textbox';
5
+ import { IxSearchBarStyle } from './ix-search-bar-styles.js';
6
+ export class IxSearchBar extends LitElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.value = '';
10
+ this.items = [];
11
+ this.searchFields = [];
12
+ this.foundItems = [];
13
+ }
14
+ static get styles() {
15
+ return [IxSearchBarStyle];
16
+ }
17
+ connectedCallback() {
18
+ super.connectedCallback();
19
+ this.resetResults();
20
+ }
21
+ resetResults() {
22
+ this.foundItems = this.items;
23
+ }
24
+ get itemsCount() {
25
+ if (Array.isArray(this.foundItems) && this.foundItems.length) {
26
+ return this.foundItems.length;
27
+ }
28
+ return 0;
29
+ }
30
+ get itemsLabel() {
31
+ return this.itemsCount === 1 ? 'item' : 'items';
32
+ }
33
+ _dispatchEvent(items) {
34
+ const resultsEvent = new CustomEvent('onResultsFound', {
35
+ detail: { items },
36
+ composed: true,
37
+ });
38
+ this.dispatchEvent(resultsEvent);
39
+ }
40
+ filterItems(value) {
41
+ this.value = value;
42
+ if (value === '') {
43
+ this.resetResults();
44
+ this._dispatchEvent(this.items);
45
+ return;
46
+ }
47
+ const results = [];
48
+ for (const item of this.items) {
49
+ for (const field of this.searchFields) {
50
+ if (field in item) {
51
+ if (item[field]
52
+ .toLocaleLowerCase()
53
+ .includes(this.value.toLocaleLowerCase())) {
54
+ results.push(item);
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ this.foundItems = results;
61
+ this._dispatchEvent(results);
62
+ }
63
+ render() {
64
+ return html `
65
+ <ix-textbox
66
+ type="search"
67
+ @textChange="${(e) => this.filterItems(e.detail.value)}"
68
+ ></ix-textbox>
69
+
70
+ <div class="items-count">${this.itemsCount} ${this.itemsLabel}</div>
71
+ `;
72
+ }
73
+ }
74
+ __decorate([
75
+ property({ type: String })
76
+ ], IxSearchBar.prototype, "value", void 0);
77
+ __decorate([
78
+ property({ type: Array })
79
+ ], IxSearchBar.prototype, "items", void 0);
80
+ __decorate([
81
+ property({ type: Array })
82
+ ], IxSearchBar.prototype, "searchFields", void 0);
83
+ __decorate([
84
+ property({ type: Array })
85
+ ], IxSearchBar.prototype, "foundItems", void 0);
86
+ //# sourceMappingURL=IxSearchBar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxSearchBar.js","sourceRoot":"","sources":["../src/IxSearchBar.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,MAAM,OAAO,WAAY,SAAQ,UAAU;IAA3C;;QAC8B,UAAK,GAAG,EAAE,CAAC;QAEZ,UAAK,GAAW,EAAE,CAAC;QAEnB,iBAAY,GAAa,EAAE,CAAC;QAE5B,eAAU,GAAW,EAAE,CAAC;IA0ErD,CAAC;IAxEC,MAAM,KAAK,MAAM;QACf,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5B,CAAC;IAED,iBAAiB;QACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAED,YAAY;QACV,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC;IAED,IAAI,UAAU;QACZ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YAC5D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;SAC/B;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,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C;CACF;AAhF6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CAAY;AAEZ;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;0CAAoB;AAEnB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;iDAA6B;AAE5B;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;+CAAyB","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport '@digital-realty/ix-textbox';\nimport { IxSearchBarStyle } from './ix-search-bar-styles.js';\nimport { Item, TextChangeEvent } from './types/index.js';\n\nexport class IxSearchBar extends LitElement {\n @property({ type: String }) value = '';\n\n @property({ type: Array }) items: Item[] = [];\n\n @property({ type: Array }) searchFields: string[] = [];\n\n @property({ type: Array }) foundItems: Item[] = [];\n\n static get styles() {\n return [IxSearchBarStyle];\n }\n\n connectedCallback() {\n super.connectedCallback();\n this.resetResults();\n }\n\n resetResults() {\n this.foundItems = this.items;\n }\n\n get itemsCount() {\n if (Array.isArray(this.foundItems) && this.foundItems.length) {\n return this.foundItems.length;\n }\n return 0;\n }\n\n get itemsLabel() {\n return this.itemsCount === 1 ? 'item' : 'items';\n }\n\n _dispatchEvent(items: Item[]): void {\n const resultsEvent = new CustomEvent('onResultsFound', {\n detail: { items },\n composed: true,\n });\n this.dispatchEvent(resultsEvent);\n }\n\n filterItems(value: string) {\n this.value = value;\n if (value === '') {\n this.resetResults();\n this._dispatchEvent(this.items);\n return;\n }\n\n const results: Item[] = [];\n\n for (const item of this.items) {\n for (const field of this.searchFields) {\n if (field in item) {\n if (\n item[field]\n .toLocaleLowerCase()\n .includes(this.value.toLocaleLowerCase())\n ) {\n results.push(item);\n break;\n }\n }\n }\n }\n\n this.foundItems = results;\n this._dispatchEvent(results);\n }\n\n render() {\n return html`\n <ix-textbox\n type=\"search\"\n @textChange=\"${(e: TextChangeEvent) =>\n this.filterItems(e.detail.value)}\"\n ></ix-textbox>\n\n <div class=\"items-count\">${this.itemsCount} ${this.itemsLabel}</div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'ix-search-bar': IxSearchBar;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { IxSearchBar } from './IxSearchBar.js';\n"]}
@@ -0,0 +1 @@
1
+ export declare const IxSearchBarStyle: import("lit").CSSResult;
@@ -1,6 +1,5 @@
1
1
  import { css } from 'lit';
2
-
3
- export const IxSearchBarStyle = css`
2
+ export const IxSearchBarStyle = css `
4
3
  :host {
5
4
  display: flex;
6
5
  justify-content: space-between;
@@ -27,3 +26,4 @@ export const IxSearchBarStyle = css`
27
26
  padding: 0.5em 0;
28
27
  }
29
28
  `;
29
+ //# sourceMappingURL=ix-search-bar-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-search-bar-styles.js","sourceRoot":"","sources":["../src/ix-search-bar-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BlC,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const IxSearchBarStyle = css`\n :host {\n display: flex;\n justify-content: space-between;\n align-items: center;\n border: 1px solid lightgrey;\n border-width: 1px 0;\n padding: 1rem 0;\n flex-wrap: wrap;\n margin-bottom: 1.5rem;\n }\n\n html {\n color: #333;\n }\n\n ix-textbox {\n color: #333;\n flex: 1 0 min(280px, 100%);\n }\n\n .items-count {\n flex: 1000 0 7em;\n text-align: right;\n padding: 0.5em 0;\n }\n`;\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,3 @@
1
1
  import { IxSearchBar } from './IxSearchBar.js';
2
-
3
2
  window.customElements.define('ix-search-bar', IxSearchBar);
3
+ //# sourceMappingURL=ix-search-bar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-search-bar.js","sourceRoot":"","sources":["../src/ix-search-bar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC","sourcesContent":["import { IxSearchBar } from './IxSearchBar.js';\n\nwindow.customElements.define('ix-search-bar', IxSearchBar);\n"]}
@@ -0,0 +1,2 @@
1
+ import { IxSearchBar as LitComp } from '../IxSearchBar.js';
2
+ export declare const IxSearchBar: import("@lit-labs/react").ReactWebComponent<LitComp, {}>;
@@ -1,11 +1,10 @@
1
1
  import React from 'react';
2
2
  import { createComponent } from '@lit-labs/react';
3
3
  import { IxSearchBar as LitComp } from '../IxSearchBar.js';
4
-
5
4
  window.customElements.define('ix-search-bar', LitComp);
6
-
7
5
  export const IxSearchBar = createComponent({
8
- tagName: 'ix-search-bar',
9
- elementClass: LitComp,
10
- react: React,
6
+ tagName: 'ix-search-bar',
7
+ elementClass: LitComp,
8
+ react: React,
11
9
  });
10
+ //# sourceMappingURL=IxSearchBar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxSearchBar.js","sourceRoot":"","sources":["../../src/react/IxSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;IACzC,OAAO,EAAE,eAAe;IACxB,YAAY,EAAE,OAAO;IACrB,KAAK,EAAE,KAAK;CACb,CAAC,CAAC","sourcesContent":["import React from 'react';\nimport { createComponent } from '@lit-labs/react';\nimport { IxSearchBar as LitComp } from '../IxSearchBar.js';\n\nwindow.customElements.define('ix-search-bar', LitComp);\n\nexport const IxSearchBar = createComponent({\n tagName: 'ix-search-bar',\n elementClass: LitComp,\n react: React,\n});\n"]}
@@ -2,11 +2,12 @@
2
2
  * The item being searched for.
3
3
  */
4
4
  export type Item = {
5
- [key: string]: string;
5
+ [key: string]: string;
6
6
  };
7
-
8
7
  /**
9
8
  * An event which is fired when the textfield's value changes.
10
9
  * It passes the value of the textfield.
11
10
  */
12
- export type TextChangeEvent = CustomEvent<{ value: string }>;
11
+ export type TextChangeEvent = CustomEvent<{
12
+ value: string;
13
+ }>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The item being searched for.\n */\nexport type Item = {\n [key: string]: string;\n};\n\n/**\n * An event which is fired when the textfield's value changes.\n * It passes the value of the textfield.\n */\nexport type TextChangeEvent = CustomEvent<{ value: string }>;\n"]}
package/package.json CHANGED
@@ -3,21 +3,18 @@
3
3
  "description": "Webcomponent ix-search-bar following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "Digital Realty",
6
- "version": "2.1.2",
6
+ "version": "2.1.4",
7
7
  "type": "module",
8
- "main": "dist/src/index.js",
9
- "module": "dist/src/index.js",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
10
  "exports": {
11
- ".": "./dist/src/index.js",
12
- "./ix-search-bar.js": "./dist/src/ix-search-bar.js",
13
- "./IxSearchBar": "./dist/src/react/IxSearchBar.js"
11
+ ".": "./dist/index.js",
12
+ "./ix-search-bar.js": "./dist/ix-search-bar.js",
13
+ "./IxSearchBar": "./dist/react/IxSearchBar.js"
14
14
  },
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "files": [
19
- "src"
20
- ],
21
18
  "scripts": {
22
19
  "analyze": "cem analyze --litelement",
23
20
  "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
@@ -29,7 +26,7 @@
29
26
  "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
30
27
  },
31
28
  "dependencies": {
32
- "@digital-realty/ix-textbox": "^2.1.2",
29
+ "@digital-realty/ix-textbox": "^2.1.4",
33
30
  "@lit-labs/react": "^2.0.3",
34
31
  "lit": "^2.0.2",
35
32
  "react": "^18.2.0"
@@ -96,5 +93,12 @@
96
93
  "prettier --write"
97
94
  ]
98
95
  },
99
- "gitHead": "1e8e36ae0147d1fb0037ba85c727e3a30daebbc9"
96
+ "files": [
97
+ "/dist",
98
+ "!/dist/test",
99
+ "package.json",
100
+ "README.md",
101
+ "LICENSE"
102
+ ],
103
+ "gitHead": "f487170ac27de967505c921dabf983d2a122e625"
100
104
  }
@@ -1,94 +0,0 @@
1
- import { html, LitElement } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import '@digital-realty/ix-textbox';
4
- import { IxSearchBarStyle } from './ix-search-bar-styles.js';
5
- import { Item, TextChangeEvent } from './types/index.js';
6
-
7
- export class IxSearchBar extends LitElement {
8
- @property({ type: String }) value = '';
9
-
10
- @property({ type: Array }) items: Item[] = [];
11
-
12
- @property({ type: Array }) searchFields: string[] = [];
13
-
14
- @property({ type: Array }) foundItems: Item[] = [];
15
-
16
- static get styles() {
17
- return [IxSearchBarStyle];
18
- }
19
-
20
- connectedCallback() {
21
- super.connectedCallback();
22
- this.resetResults();
23
- }
24
-
25
- resetResults() {
26
- this.foundItems = this.items;
27
- }
28
-
29
- get itemsCount() {
30
- if (Array.isArray(this.foundItems) && this.foundItems.length) {
31
- return this.foundItems.length;
32
- }
33
- return 0;
34
- }
35
-
36
- get itemsLabel() {
37
- return this.itemsCount === 1 ? 'item' : 'items';
38
- }
39
-
40
- _dispatchEvent(items: Item[]): void {
41
- const resultsEvent = new CustomEvent('onResultsFound', {
42
- detail: { items },
43
- composed: true,
44
- });
45
- this.dispatchEvent(resultsEvent);
46
- }
47
-
48
- filterItems(value: string) {
49
- this.value = value;
50
- if (value === '') {
51
- this.resetResults();
52
- this._dispatchEvent(this.items);
53
- return;
54
- }
55
-
56
- const results: Item[] = [];
57
-
58
- for (const item of this.items) {
59
- for (const field of this.searchFields) {
60
- if (field in item) {
61
- if (
62
- item[field]
63
- .toLocaleLowerCase()
64
- .includes(this.value.toLocaleLowerCase())
65
- ) {
66
- results.push(item);
67
- break;
68
- }
69
- }
70
- }
71
- }
72
-
73
- this.foundItems = results;
74
- this._dispatchEvent(results);
75
- }
76
-
77
- render() {
78
- return html`
79
- <ix-textbox
80
- type="search"
81
- @textChange="${(e: TextChangeEvent) =>
82
- this.filterItems(e.detail.value)}"
83
- ></ix-textbox>
84
-
85
- <div class="items-count">${this.itemsCount} ${this.itemsLabel}</div>
86
- `;
87
- }
88
- }
89
-
90
- declare global {
91
- interface HTMLElementTagNameMap {
92
- 'ix-search-bar': IxSearchBar;
93
- }
94
- }
File without changes
File without changes