@gemeentenijmegen/web-components 0.0.2-alpha.41 → 0.0.2-alpha.43
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/dist/nijmegen-search.js +133 -0
- package/package.json +3 -3
- package/src/search/search.js +99 -0
- package/src/search/template.html +3 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function styleInject(css, ref) {
|
|
5
|
+
if ( ref === void 0 ) ref = {};
|
|
6
|
+
var insertAt = ref.insertAt;
|
|
7
|
+
|
|
8
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
9
|
+
|
|
10
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
11
|
+
var style = document.createElement('style');
|
|
12
|
+
style.type = 'text/css';
|
|
13
|
+
|
|
14
|
+
if (insertAt === 'top') {
|
|
15
|
+
if (head.firstChild) {
|
|
16
|
+
head.insertBefore(style, head.firstChild);
|
|
17
|
+
} else {
|
|
18
|
+
head.appendChild(style);
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
head.appendChild(style);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (style.styleSheet) {
|
|
25
|
+
style.styleSheet.cssText = css;
|
|
26
|
+
} else {
|
|
27
|
+
style.appendChild(document.createTextNode(css));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var css_248z = "/**\n * @license EUPL-1.2\n * Copyright (c) 2020-2024 Frameless B.V.\n * Copyright (c) 2021-2024 Gemeente Utrecht\n */\n/* stylelint-disable-next-line block-no-empty */\n/**\n * @license EUPL-1.2\n * Copyright (c) 2020-2024 Frameless B.V.\n * Copyright (c) 2021-2024 Gemeente Utrecht\n */\n/* stylelint-disable-next-line block-no-empty */\n/* TODO: Enable ordering properties when the plugin supports logical CSS properties\n * https://github.com/hudochenkov/stylelint-order/pull/162 */\n/* stylelint-disable order/properties-alphabetical-order */\n.nijmegen-search__container {\n display: flex;\n gap: var(--nijmegen-search-input-column-gap);\n inline-size: var(--nijmegen-search-input-max-inline-size);\n max-inline-size: 100%;\n position: relative;\n}\n.nijmegen-search__container .utrecht-button {\n max-block-size: 51px;\n min-block-size: 51px;\n}\n.nijmegen-search__container.nijmegen-search__container--full-width {\n inline-size: 100%;\n}\n\n.nijmegen-search__input-holder {\n flex: 1;\n position: relative;\n}\n\n.nijmegen-search__search-button.nijmegen-search__search-button--dark {\n border-color: var(--nijmegen-search-input-button-border-color) !important;\n}\n@media (width < 576px) {\n .nijmegen-search__search-button svg {\n display: none;\n }\n}\n\n.nijmegen-search__clear-button {\n align-items: center;\n aspect-ratio: 1/1;\n background-color: transparent;\n border: 0;\n cursor: pointer;\n display: flex;\n height: 100%; /* stylelint-disable-line property-disallowed-list */\n justify-content: center;\n position: absolute;\n right: 0; /* stylelint-disable-line property-disallowed-list */\n top: 0; /* stylelint-disable-line property-disallowed-list */\n}\n.nijmegen-search__clear-button.nijmegen-search__clear-button--hide {\n display: none;\n}\n.nijmegen-search__clear-button svg {\n stroke: var(--nijmegen-interaction-color);\n}\n\n.nijmegen-search__input {\n background-color: var(--nijmegen-search-input-background-color);\n border-color: var(--nijmegen-search-input-border-color);\n border-radius: var(--nijmegen-search-input-border-radius);\n border-width: var(--nijmegen-search-input-border-width);\n box-sizing: border-box;\n color: var(--nijmegen-search-input-color);\n font-family: var(--nijmegen-search-input-font-family);\n font-size: var(--nijmegen-search-input-font-size);\n font-weight: var(--nijmegen-search-input-font-weight);\n line-height: var(--nijmegen-search-input-line-height);\n min-block-size: var(--nijmegen-search-input-min-block-size);\n padding-block-end: var(--nijmegen-search-input-padding-block-end);\n padding-block-start: var(--nijmegen-search-input-padding-block-start);\n padding-inline-end: var(--nijmegen-search-input-padding-inline-end);\n padding-inline-start: var(--nijmegen-search-input-padding-inline-start);\n width: 100%; /* stylelint-disable-line property-disallowed-list */\n}\n.nijmegen-search__input:hover, .nijmegen-search__input.nijmegen-search__input--hover {\n background-color: var(--nijmegen-search-input-hover-background-color);\n border-color: var(--nijmegen-search-input-hover-border-color);\n color: var(--nijmegen-search-input-hover-color);\n}\n.nijmegen-search__input:focus, .nijmegen-search__input.nijmegen-search__input--focus {\n background-color: var(--nijmegen-search-input-focus-background-color);\n border-color: var(--nijmegen-search-input-focus-border-color);\n color: var(--nijmegen-search-input-focus-color);\n}\n.nijmegen-search__input:focus-visible, .nijmegen-search__input.nijmegen-search__input--focus {\n /* - The browser default focus ring should apply when these CSS custom properties are not set.\n * - Make the `box-shadow` value available, so components that have their own `box-shadow`\n * can combine it with the focus ring box shadow.\n */\n --_utrecht-focus-ring-box-shadow: 0 0 0 var(--utrecht-focus-outline-width, 0)\n var(--utrecht-focus-inverse-outline-color, transparent);\n box-shadow: var(--_utrecht-focus-ring-box-shadow);\n outline-color: var(--utrecht-focus-outline-color, revert);\n outline-offset: var(--utrecht-focus-outline-offset, revert);\n outline-style: var(--utrecht-focus-outline-style, revert);\n outline-width: var(--utrecht-focus-outline-width, revert);\n z-index: 1;\n background-color: var(--nijmegen-search-input-focus-background-color);\n border-color: var(--nijmegen-search-input-focus-border-color);\n color: var(--nijmegen-search-input-focus-color);\n}\n.nijmegen-search__input:read-only, .nijmegen-search__input.nijmegen-search__input-read-only {\n background-color: var(--nijmegen-search-input-read-only-background-color);\n border-color: var(--nijmegen-search-input-read-only-border-color);\n color: var(--nijmegen-search-input-read-only-color);\n}\n.nijmegen-search__input.nijmegen-search__input--disabled {\n background-color: var(--nijmegen-search-input-disabled-background-color);\n border-color: var(--nijmegen-search-input-disabled-border-color);\n color: var(--nijmegen-search-input-disabled-color);\n cursor: var(--utrecht-action-disabled-cursor, not-allowed);\n}\n.nijmegen-search__input::placeholder {\n color: var(--nijmegen-search-input-placeholder-color);\n}\n\n.nijmegen-search__autocomplete-results {\n display: none;\n margin-block-start: var(--nijmegen-search-input-autocomplete-offset, 8px);\n position: absolute;\n top: var(--nijmegen-search-input-min-block-size); /* stylelint-disable-line property-disallowed-list */\n width: 100%; /* stylelint-disable-line property-disallowed-list */\n}\n.nijmegen-search__autocomplete-results--show-results {\n display: block;\n}";
|
|
32
|
+
styleInject(css_248z);
|
|
33
|
+
|
|
34
|
+
var html = "<form class=\"nijmegen-search\" method=\"GET\" action=\"\" role=\"search\">\n <slot></slot>\n</form>\n";
|
|
35
|
+
|
|
36
|
+
class NijmegenSearch extends HTMLElement {
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
const template = document.createElement('template');
|
|
40
|
+
template.innerHTML = html;
|
|
41
|
+
|
|
42
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
43
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
44
|
+
|
|
45
|
+
const stylesheet = new CSSStyleSheet();
|
|
46
|
+
stylesheet.replaceSync(css_248z);
|
|
47
|
+
shadowRoot.adoptedStyleSheets = [stylesheet];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
const input = this.querySelector('.nijmegen-search__input');
|
|
52
|
+
const clearButton = this.querySelector('.nijmegen-search__clear-button');
|
|
53
|
+
const resultsList = this.querySelector('.nijmegen-listbox__list');
|
|
54
|
+
const resultsContainer = this.querySelector('.nijmegen-search__autocomplete-results');
|
|
55
|
+
|
|
56
|
+
this.#initializeSearch(input, clearButton);
|
|
57
|
+
if (resultsContainer && resultsContainer.classList.contains('nijmegen-search__autocomplete-results--example')) {
|
|
58
|
+
this.#initializeAutocomplete(input, clearButton, resultsList, resultsContainer);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#initializeSearch(input, clearButton) {
|
|
63
|
+
if (input && clearButton) {
|
|
64
|
+
input.addEventListener('input', () => {
|
|
65
|
+
this.#toggleClearButton(input, clearButton);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
clearButton.addEventListener('click', () => {
|
|
69
|
+
input.value = '';
|
|
70
|
+
this.#toggleClearButton(input, clearButton);
|
|
71
|
+
input.focus();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#initializeAutocomplete(input, clearButton, resultsList, resultsContainer) {
|
|
77
|
+
if (input && clearButton && resultsList && resultsContainer) {
|
|
78
|
+
input.addEventListener('input', () => {
|
|
79
|
+
if (input.value.trim().length >= 3) {
|
|
80
|
+
this.#getAutocompleteResults(input.value, (results) => {
|
|
81
|
+
this.#showResults(results, resultsList, resultsContainer);
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
this.#hideResults(resultsList, resultsContainer);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
clearButton.addEventListener('click', () => {
|
|
89
|
+
this.#hideResults(resultsList, resultsContainer);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#toggleClearButton(input, clearButton) {
|
|
95
|
+
if (input.value.trim().length > 0) {
|
|
96
|
+
clearButton.classList.remove('nijmegen-search__clear-button--hide');
|
|
97
|
+
} else {
|
|
98
|
+
clearButton.classList.add('nijmegen-search__clear-button--hide');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#getAutocompleteResults(query, callback) {
|
|
103
|
+
const cleanQuery = this.#cleanAutoCompleteQuery(query);
|
|
104
|
+
const results = [
|
|
105
|
+
{ title: 'Finibus ' + cleanQuery, url: '?q=1_' + cleanQuery },
|
|
106
|
+
{ title: cleanQuery + ' elementum urna', url: '?q=2_' + cleanQuery },
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
callback(results);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#showResults(results, resultsList, resultsContainer) {
|
|
113
|
+
resultsList.innerHTML = results
|
|
114
|
+
.map((result) => `<li><a href="${result.url}" class="nijmegen-listbox__item">${result.title}</a></li>`)
|
|
115
|
+
.join('');
|
|
116
|
+
resultsContainer.classList.add('nijmegen-search__autocomplete-results--show-results');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#hideResults(resultsList, resultsContainer) {
|
|
120
|
+
resultsList.innerHTML = '';
|
|
121
|
+
resultsContainer.classList.remove('nijmegen-search__autocomplete-results--show-results');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#cleanAutoCompleteQuery(query) {
|
|
125
|
+
const p = document.createElement('p');
|
|
126
|
+
p.innerText = query;
|
|
127
|
+
return p.innerHTML;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
customElements.define('nijmegen-search', NijmegenSearch);
|
|
132
|
+
|
|
133
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.2-alpha.
|
|
2
|
+
"version": "0.0.2-alpha.43",
|
|
3
3
|
"author": "gemeente Nijmegen",
|
|
4
4
|
"description": "Web components for the gemeente Nijmegen design system",
|
|
5
5
|
"license": "EUPL-1.2",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"clean": "rimraf dist"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@gemeentenijmegen/components-css": "0.0.1-alpha.
|
|
29
|
+
"@gemeentenijmegen/components-css": "0.0.1-alpha.66",
|
|
30
30
|
"postcss-discard-duplicates": "7.0.1",
|
|
31
31
|
"rollup": "4.12.1",
|
|
32
32
|
"rollup-plugin-html": "0.2.1",
|
|
33
33
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
34
34
|
"rollup-plugin-postcss": "4.0.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d9987e4bca2e19462770aebd18aa36b6a23f1004"
|
|
37
37
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import style from '@gemeentenijmegen/components-css/search/index.scss';
|
|
2
|
+
import html from './template.html';
|
|
3
|
+
|
|
4
|
+
class NijmegenSearch extends HTMLElement {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
const template = document.createElement('template');
|
|
8
|
+
template.innerHTML = html;
|
|
9
|
+
|
|
10
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
11
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
12
|
+
|
|
13
|
+
const stylesheet = new CSSStyleSheet();
|
|
14
|
+
stylesheet.replaceSync(style);
|
|
15
|
+
shadowRoot.adoptedStyleSheets = [stylesheet];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
const input = this.querySelector('.nijmegen-search__input');
|
|
20
|
+
const clearButton = this.querySelector('.nijmegen-search__clear-button');
|
|
21
|
+
const resultsList = this.querySelector('.nijmegen-listbox__list');
|
|
22
|
+
const resultsContainer = this.querySelector('.nijmegen-search__autocomplete-results');
|
|
23
|
+
|
|
24
|
+
this.#initializeSearch(input, clearButton);
|
|
25
|
+
if (resultsContainer && resultsContainer.classList.contains('nijmegen-search__autocomplete-results--example')) {
|
|
26
|
+
this.#initializeAutocomplete(input, clearButton, resultsList, resultsContainer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#initializeSearch(input, clearButton) {
|
|
31
|
+
if (input && clearButton) {
|
|
32
|
+
input.addEventListener('input', () => {
|
|
33
|
+
this.#toggleClearButton(input, clearButton);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
clearButton.addEventListener('click', () => {
|
|
37
|
+
input.value = '';
|
|
38
|
+
this.#toggleClearButton(input, clearButton);
|
|
39
|
+
input.focus();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#initializeAutocomplete(input, clearButton, resultsList, resultsContainer) {
|
|
45
|
+
if (input && clearButton && resultsList && resultsContainer) {
|
|
46
|
+
input.addEventListener('input', () => {
|
|
47
|
+
if (input.value.trim().length >= 3) {
|
|
48
|
+
this.#getAutocompleteResults(input.value, (results) => {
|
|
49
|
+
this.#showResults(results, resultsList, resultsContainer);
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
this.#hideResults(resultsList, resultsContainer);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
clearButton.addEventListener('click', () => {
|
|
57
|
+
this.#hideResults(resultsList, resultsContainer);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#toggleClearButton(input, clearButton) {
|
|
63
|
+
if (input.value.trim().length > 0) {
|
|
64
|
+
clearButton.classList.remove('nijmegen-search__clear-button--hide');
|
|
65
|
+
} else {
|
|
66
|
+
clearButton.classList.add('nijmegen-search__clear-button--hide');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#getAutocompleteResults(query, callback) {
|
|
71
|
+
const cleanQuery = this.#cleanAutoCompleteQuery(query);
|
|
72
|
+
const results = [
|
|
73
|
+
{ title: 'Finibus ' + cleanQuery, url: '?q=1_' + cleanQuery },
|
|
74
|
+
{ title: cleanQuery + ' elementum urna', url: '?q=2_' + cleanQuery },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
callback(results);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#showResults(results, resultsList, resultsContainer) {
|
|
81
|
+
resultsList.innerHTML = results
|
|
82
|
+
.map((result) => `<li><a href="${result.url}" class="nijmegen-listbox__item">${result.title}</a></li>`)
|
|
83
|
+
.join('');
|
|
84
|
+
resultsContainer.classList.add('nijmegen-search__autocomplete-results--show-results');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#hideResults(resultsList, resultsContainer) {
|
|
88
|
+
resultsList.innerHTML = '';
|
|
89
|
+
resultsContainer.classList.remove('nijmegen-search__autocomplete-results--show-results');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#cleanAutoCompleteQuery(query) {
|
|
93
|
+
const p = document.createElement('p');
|
|
94
|
+
p.innerText = query;
|
|
95
|
+
return p.innerHTML;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
customElements.define('nijmegen-search', NijmegenSearch);
|