@financial-times/o-autocomplete 1.3.2 → 1.6.0

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.
@@ -0,0 +1,8 @@
1
+ printWidth = 80
2
+ trailingComma = "es5"
3
+ semi = true
4
+ singleQuote = true
5
+ useTabs = true
6
+ bracketSpacing = false
7
+ jsxBracketSameLine = true
8
+ arrowParens = "avoid"
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.0](https://www.github.com/Financial-Times/origami/compare/o-autocomplete-v1.5.0...o-autocomplete-v1.6.0) (2021-12-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * support internal brand on o-autocomplete ([f519cf8](https://www.github.com/Financial-Times/origami/commit/f519cf8b668304ece9e0cc5e64940ad4295343ce))
9
+
10
+ ## [1.5.0](https://www.github.com/Financial-Times/origami/compare/o-autocomplete-v1.4.1...o-autocomplete-v1.5.0) (2021-11-24)
11
+
12
+
13
+ ### Features
14
+
15
+ * allow npm 8 in engines config ([eeb1cae](https://www.github.com/Financial-Times/origami/commit/eeb1cae6e7f0379e647f2b41240b1f294997d528))
16
+
17
+ ### [1.4.1](https://www.github.com/Financial-Times/origami/compare/o-autocomplete-v1.4.0...o-autocomplete-v1.4.1) (2021-11-08)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * pin components to latest o-brand, or greater ([3a6ccea](https://www.github.com/Financial-Times/origami/commit/3a6ccea1e838e4a2003322ca1f855d0b87b26b60))
23
+
24
+ ## [1.4.0](https://www.github.com/Financial-Times/origami/compare/o-autocomplete-v1.3.2...o-autocomplete-v1.4.0) (2021-11-08)
25
+
26
+
27
+ ### Features
28
+
29
+ * Rename master brand in component origami.json ([f642faf](https://www.github.com/Financial-Times/origami/commit/f642faf0574d84ea8185b56e6090c8015def27e6))
30
+
3
31
  ### [1.3.2](https://www.github.com/Financial-Times/origami/compare/o-autocomplete-v1.3.1...o-autocomplete-v1.3.2) (2021-11-02)
4
32
 
5
33
 
@@ -2,20 +2,19 @@ import Autocomplete from '../../../main.js';
2
2
  import {data} from './data.js';
3
3
 
4
4
  /**
5
- * @typedef {Object} CustomOption
6
- * @property {String} Continent_Code
7
- * @property {String} Continent_Name
8
- * @property {String} Country_Name
9
- * @property {Number} Country_Number
10
- * @property {String} Three_Letter_Country_Code
11
- * @property {String} Two_Letter_Country_Code
5
+ * @typedef {object} CustomOption
6
+ * @property {string} Continent_Code - 2 letter continent code
7
+ * @property {string} Continent_Name - name of continent
8
+ * @property {string} Country_Name - name of country
9
+ * @property {number} Country_Number - id of country
10
+ * @property {string} Three_Letter_Country_Code - three letter country code
11
+ * @property {string} Two_Letter_Country_Code - two letter country code
12
12
  */
13
13
 
14
-
15
14
  /**
16
15
  * @param {CustomOption|undefined} option - The option to transform into a suggestion string
17
16
  * @returns {string} The string to display in the suggestions dropdown for this option
18
- */
17
+ */
19
18
  function mapOptionToSuggestedValue(option) {
20
19
  if (option) {
21
20
  return option.Country_Name;
@@ -57,6 +56,7 @@ new Autocomplete(document.querySelector('[data-o-component="o-autocomplete"]'),
57
56
  source: customSuggestions,
58
57
  mapOptionToSuggestedValue,
59
58
  onConfirm: function (option) {
59
+ // eslint-disable-next-line no-console
60
60
  console.log('You chose option', option);
61
61
  }
62
62
  });
package/main.scss CHANGED
@@ -1,3 +1,4 @@
1
+ @import '@financial-times/math';
1
2
  @import '@financial-times/o-brand/main';
2
3
  @import '@financial-times/o-colors/main';
3
4
  @import '@financial-times/o-grid/main';
package/origami.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "origamiType": "component",
3
3
  "origamiVersion": "2.0",
4
4
  "brands": [
5
- "master"
5
+ "core",
6
+ "internal"
6
7
  ],
7
8
  "support": "https://github.com/Financial-Times/origami/issues/new?labels=o-autocomplete,components",
8
9
  "supportContact": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/o-autocomplete",
3
- "version": "1.3.2",
3
+ "version": "1.6.0",
4
4
  "description": "An origami component for autocomplete inputs",
5
5
  "keywords": [
6
6
  "autocomplete",
@@ -25,10 +25,11 @@
25
25
  "lint": "bash ../../scripts/component/lint.bash"
26
26
  },
27
27
  "engines": {
28
- "npm": ">=7"
28
+ "npm": "^7 || ^8"
29
29
  },
30
30
  "peerDependencies": {
31
- "@financial-times/o-brand": "^4.0.2",
31
+ "@financial-times/math": "^1.0.0",
32
+ "@financial-times/o-brand": "^4.1.0",
32
33
  "@financial-times/o-colors": "^6.0.1",
33
34
  "@financial-times/o-grid": "^6.0.0",
34
35
  "@financial-times/o-icons": "^7.0.1",
@@ -40,5 +41,7 @@
40
41
  },
41
42
  "dependencies": {
42
43
  "@financial-times/accessible-autocomplete": "^2.1.2"
43
- }
44
+ },
45
+ "percy": true,
46
+ "private": false
44
47
  }
@@ -7,10 +7,18 @@
7
7
  // If the above pull-requests are merged and published, then we can stop using our fork
8
8
  import accessibleAutocomplete from '@financial-times/accessible-autocomplete';
9
9
 
10
+ /**
11
+ * @typedef CharacterHighlight - The character and whether it should be highlighted
12
+ * @type {Array}
13
+ * @property {string} 0 - the character in the suggestion
14
+ * @property {boolean} 1 - should it be highlighted?
15
+ */
16
+
17
+
10
18
  /**
11
19
  * @param {string} suggestion - Text which is going to be suggested to the user
12
20
  * @param {string} query - Text which was typed into the autocomplete by the user
13
- * @returns {[string, boolean][]} An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.
21
+ * @returns {CharacterHighlight[]} An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.
14
22
  */
15
23
  function highlightSuggestion(suggestion, query) {
16
24
  const result = suggestion.split('');
@@ -29,6 +37,7 @@ function highlightSuggestion(suggestion, query) {
29
37
 
30
38
  /**
31
39
  * Create DOM for the loading container.
40
+ *
32
41
  * @returns {HTMLDivElement} The loading container.
33
42
  */
34
43
  function createLoadingContainer() {
@@ -42,7 +51,8 @@ function createLoadingContainer() {
42
51
 
43
52
  /**
44
53
  * Show the loading panel
45
- * @param {AutoComplete} instance The autocomplete instance whose loading panel should be shown
54
+ *
55
+ * @param {Autocomplete} instance The autocomplete instance whose loading panel should be shown
46
56
  * @returns {void}
47
57
  */
48
58
  function showLoadingPane(instance) {
@@ -55,7 +65,8 @@ function showLoadingPane(instance) {
55
65
 
56
66
  /**
57
67
  * Hide the loading panel
58
- * @param {AutoComplete} instance The autocomplete instance whose loading panel should be hidden
68
+ *
69
+ * @param {Autocomplete} instance The autocomplete instance whose loading panel should be hidden
59
70
  * @returns {void}
60
71
  */
61
72
  function hideLoadingPane(instance) {
@@ -71,8 +82,9 @@ function hideLoadingPane(instance) {
71
82
  /**
72
83
  * Create the DOM tree which corresponds to
73
84
  * <button class="o-autocomplete__clear" type="button" aria-controls=${autocompleteEl.id} title="Clear input">
74
- * <span class="o-autocomplete__visually-hidden">Clear input</span>
85
+ * <span class="o-autocomplete__visually-hidden">Clear input</span>
75
86
  * </button>
87
+ *
76
88
  * @param {string} id The id of the autocomplete input to associate the clear button with
77
89
  * @returns {HTMLButtonElement} The clear button DOM tree
78
90
  */
@@ -87,7 +99,8 @@ function createClearButton(id) {
87
99
 
88
100
  /**
89
101
  * Attach the clear button and corresponding event listeners to the o-autocomplete instance
90
- * @param {AutoComplete} instance The autocomplete instance to setup the clear button for
102
+ *
103
+ * @param {Autocomplete} instance The autocomplete instance to setup the clear button for
91
104
  * @returns {void}
92
105
  */
93
106
  function initClearButton(instance) {
@@ -144,22 +157,22 @@ function initClearButton(instance) {
144
157
  * @param {string} query - Text which was typed into the autocomplete by the user
145
158
  * @param {PopulateOptions} populateOptions - Function to call when ready to update the suggestions dropdown
146
159
  * @returns {void}
147
- */
160
+ */
148
161
 
149
162
  /**
150
163
  * @callback MapOptionToSuggestedValue
151
164
  * @param {*} option - The option to transform into a suggestion string
152
165
  * @returns {string} The string to display as the suggestions for this option
153
- */
166
+ */
154
167
 
155
168
  /**
156
169
  * @callback onConfirm
157
170
  * @param {*} option - The option the user selected
158
171
  * @returns {void}
159
- */
172
+ */
160
173
 
161
174
  /**
162
- * @typedef {Object} AutocompleteOptions
175
+ * @typedef {object} AutocompleteOptions
163
176
  * @property {Source} [source] - The function which retrieves the suggestions to display
164
177
  * @property {MapOptionToSuggestedValue} [mapOptionToSuggestedValue] - Function which transforms a suggestion before rendering
165
178
  * @property {onConfirm} [onConfirm] - Function which is called when the user selects an option
@@ -168,6 +181,7 @@ function initClearButton(instance) {
168
181
  class Autocomplete {
169
182
  /**
170
183
  * Class constructor.
184
+ *
171
185
  * @param {HTMLElement} [autocompleteEl] - The component element in the DOM
172
186
  * @param {AutocompleteOptions} [options={}] - An options object for configuring the component
173
187
  */
@@ -214,7 +228,7 @@ class Autocomplete {
214
228
  * @param {string} query - Text which was typed into the autocomplete by the user
215
229
  * @param {PopulateOptions} populateOptions - Function to call when ready to update the suggestions dropdown
216
230
  * @returns {void}
217
- */
231
+ */
218
232
  this.options.source = (query, populateOptions) => {
219
233
  showLoadingPane(this);
220
234
  /**
@@ -256,6 +270,7 @@ class Autocomplete {
256
270
  templates: {
257
271
  /**
258
272
  * Used when rendering suggestions, the return value of this will be used as the innerHTML for a single suggestion.
273
+ *
259
274
  * @param {*} option The suggestion to apply the template with.
260
275
  * @returns {string} HTML string to represent a single suggestion.
261
276
  */
@@ -279,6 +294,7 @@ class Autocomplete {
279
294
  },
280
295
  /**
281
296
  * Used when a suggestion is selected, the return value of this will be used as the value for the input element.
297
+ *
282
298
  * @param {*} option The suggestion which was selected.
283
299
  * @returns {string} String to represent the suggestion.
284
300
  */
@@ -340,13 +356,14 @@ class Autocomplete {
340
356
 
341
357
  /**
342
358
  * Used when rendering suggestions, the return value of this will be used as the innerHTML for a single suggestion.
359
+ *
343
360
  * @param {string} suggestedValue The suggestion to apply the template with.
344
361
  * @returns {string} HTML string to be represent a single suggestion.
345
362
  */
346
363
  suggestionTemplate (suggestedValue) {
347
364
  // o-autocomplete has a UI design to highlight characters in the suggestions.
348
365
  /**
349
- * @type {[string, boolean][]} An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.
366
+ * @type {CharacterHighlight[]} An array of arrays which contain two items, the first is the character in the suggestion, the second is a boolean which indicates whether the character should be highlighted.
350
367
  */
351
368
  const characters = highlightSuggestion(suggestedValue, this.autocompleteEl.querySelector('input').value);
352
369
 
@@ -367,8 +384,9 @@ class Autocomplete {
367
384
  /**
368
385
  * Get the data attributes from the AutocompleteElement. If the element is being set up
369
386
  * declaratively, this method is used to extract the data attributes from the DOM.
387
+ *
370
388
  * @param {HTMLElement} autocompleteEl - The component element in the DOM
371
- * @returns {Object} An options object which can be used for configuring the component
389
+ * @returns {object} An options object which can be used for configuring the component
372
390
  */
373
391
  static getDataAttributes (autocompleteEl) {
374
392
  if (!(autocompleteEl instanceof HTMLElement)) {
@@ -385,8 +403,9 @@ class Autocomplete {
385
403
  }
386
404
  /**
387
405
  * Initialise o-autocomplete component/s.
388
- * @param {(HTMLElement|String)} rootElement - The root element to intialise the component in, or a CSS selector for the root element
389
- * @param {Object} [options={}] - An options object for configuring the component
406
+ *
407
+ * @param {(HTMLElement | string)} rootElement - The root element to intialise the component in, or a CSS selector for the root element
408
+ * @param {object} [options={}] - An options object for configuring the component
390
409
  * @returns {Autocomplete|Autocomplete[]} The newly constructed Autocomplete components
391
410
  */
392
411
  static init (rootElement, options) {
@@ -18,3 +18,12 @@
18
18
  'supports-variants': ()
19
19
  ));
20
20
  }
21
+
22
+ @if oBrandIs('internal') {
23
+ @include oBrandDefine('o-autocomplete', 'internal', (
24
+ 'variables': (
25
+ search-close: oColorsByName('black-80'),
26
+ ),
27
+ 'supports-variants': ()
28
+ ));
29
+ }
@@ -1,3 +1,3 @@
1
1
  $_o-autocomplete-icon-size: 25px;
2
- $_o-autocomplete-icon-size-excess-whitespace: $_o-autocomplete-icon-size / 4;
2
+ $_o-autocomplete-icon-size-excess-whitespace: div($_o-autocomplete-icon-size, 4);
3
3
  $_o-autocomplete-input-space: oSpacingByName("s2"); // match o-forms, without a direct dependency
package/app.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "name": "o-autocomplete",
3
- "scripts": {},
4
- "env": {},
5
- "formation": {},
6
- "addons": [],
7
- "buildpacks": [
8
- {
9
- "url": "heroku/nodejs"
10
- }
11
- ]
12
- }