@kws3/ui 1.8.1 → 1.8.2

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/CHANGELOG.mdx CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.8.2
2
+ - Usability fixes for `NumberInput`
3
+ - New `input_only`, `force_integer`, `style` and `class` props for `NumberInput`
4
+ - Forward `focus`, `blur` input events for `NumberInput`
5
+ - Use custom version of `fuzzysearch` for `SearchableSelect` and `MultiSelect`
6
+
1
7
  ## 1.8.1
2
8
  - New `ScrollableList` component
3
9
 
@@ -20,52 +20,84 @@ This will be overridden if `min` is higher, or `max` is lower, Default: `0`
20
20
  @param {string} [plus_icon="plus"] - Name of the icon that is to be displayed in the plus button, Default: `"plus"`
21
21
  @param {''|'success'|'primary'|'warning'|'info'|'danger'|'dark'|'light'} [plus_icon_color="success"] - Color of the Plus Icon, Default: `"success"`
22
22
  @param {''|'success'|'primary'|'warning'|'info'|'danger'|'dark'|'light'} [plus_button_color=""] - Color of the Plus Button, Default: `""`
23
+ @param {boolean} [input_only=false] - Show input without controls, Default: `false`
24
+ @param {boolean} [force_integer=false] - Prevent decimal numbers such as `1.5`, Default: `false`
25
+ @param {string} [style=""] - Inline CSS for component, Default: `""`
26
+ @param {string} [class=""] - CSS classes for component, Default: `""`
23
27
 
24
28
  ### Events
25
29
  - `change` - Triggered when value changes
30
+ - `blur`
31
+ - `focus`
26
32
 
27
33
  -->
28
- <div class="field has-addons">
29
- <div class="control">
30
- <button
31
- type="button"
32
- class="button is-{size} is-{minus_button_color}"
33
- style="box-shadow:none;"
34
- on:click={count(-1)}
35
- disabled={disabled || value <= min}>
36
- <Icon
37
- icon={minus_icon}
38
- size="small"
39
- class="has-text-{minus_icon_color}" />
40
- </button>
34
+ {#if input_only}
35
+ <input
36
+ {style}
37
+ data-testid="input"
38
+ class="input has-text-centered {klass} is-{size} is-{value < min ||
39
+ value > max
40
+ ? 'danger'
41
+ : ''}"
42
+ type="number"
43
+ min
44
+ max
45
+ {step}
46
+ {disabled}
47
+ readonly={!typeable}
48
+ bind:value
49
+ on:blur={isBlurred}
50
+ on:blur
51
+ on:focus={isFocused}
52
+ on:focus />
53
+ {:else}
54
+ <div class="field has-addons {klass}" {style}>
55
+ <div class="control">
56
+ <button
57
+ type="button"
58
+ class="button is-{size} is-{minus_button_color}"
59
+ style="box-shadow:none;"
60
+ on:click={count(-1)}
61
+ disabled={disabled || value <= min}>
62
+ <Icon
63
+ icon={minus_icon}
64
+ size="small"
65
+ class="has-text-{minus_icon_color}" />
66
+ </button>
67
+ </div>
68
+ <div class="control is-{fullwidth ? 'expanded' : 'narrow'}">
69
+ <input
70
+ data-testid="input"
71
+ class="input has-text-centered is-{size} is-{value < min || value > max
72
+ ? 'danger'
73
+ : ''}"
74
+ type="number"
75
+ min
76
+ max
77
+ {step}
78
+ {disabled}
79
+ readonly={!typeable}
80
+ bind:value
81
+ on:blur={isBlurred}
82
+ on:blur
83
+ on:focus={isFocused}
84
+ on:focus />
85
+ </div>
86
+ <div class="control">
87
+ <button
88
+ type="button"
89
+ class="button is-{size} is-{plus_button_color}"
90
+ style="box-shadow:none;"
91
+ on:click|preventDefault={count(+1)}
92
+ disabled={disabled || value >= max}>
93
+ <Icon
94
+ icon={plus_icon}
95
+ size="small"
96
+ class="has-text-{plus_icon_color}" />
97
+ </button>
98
+ </div>
41
99
  </div>
42
- <div class="control is-{fullwidth ? 'expanded' : 'narrow'}">
43
- <input
44
- data-testid="input"
45
- class="input has-text-centered is-{size} is-{value < min || value > max
46
- ? 'danger'
47
- : ''}"
48
- type="number"
49
- min
50
- max
51
- step
52
- {disabled}
53
- readonly={!typeable}
54
- bind:value
55
- on:blur={isBlurred()}
56
- on:focus={isFocused()} />
57
- </div>
58
- <div class="control">
59
- <button
60
- type="button"
61
- class="button is-{size} is-{plus_button_color}"
62
- style="box-shadow:none;"
63
- on:click|preventDefault={count(+1)}
64
- disabled={disabled || value >= max}>
65
- <Icon icon={plus_icon} size="small" class="has-text-{plus_icon_color}" />
66
- </button>
67
- </div>
68
- </div>
100
+ {/if}
69
101
 
70
102
  <style>
71
103
  input[type="number"]::-webkit-inner-spin-button,
@@ -158,7 +190,25 @@ This will be overridden if `min` is higher, or `max` is lower, Default: `0`
158
190
  * Color of the Plus Button
159
191
  * @type {''|'success'|'primary'|'warning'|'info'|'danger'|'dark'|'light'}
160
192
  */
161
- plus_button_color = "";
193
+ plus_button_color = "",
194
+ /**
195
+ * Show input without controls
196
+ */
197
+ input_only = false,
198
+ /**
199
+ * Prevent decimal numbers such as `1.5`
200
+ */
201
+ force_integer = false,
202
+ /**
203
+ * Inline CSS for component
204
+ */
205
+ style = "";
206
+
207
+ /**
208
+ * CSS classes for component
209
+ */
210
+ let klass = "";
211
+ export { klass as class };
162
212
 
163
213
  let _has_focus = false,
164
214
  _old_value = null;
@@ -189,6 +239,8 @@ This will be overridden if `min` is higher, or `max` is lower, Default: `0`
189
239
 
190
240
  if (typeof value == "undefined" || value === null) value = min;
191
241
 
242
+ if (force_integer) value = Math.floor(Number(value));
243
+
192
244
  if (value < min) value = min;
193
245
  if (value > max) value = max;
194
246
 
@@ -160,7 +160,7 @@ Default value: `<span>{option[search_key] || option}</span>`
160
160
  import { debounce } from "@kws3/ui/utils";
161
161
  import { createEventDispatcher, onMount, tick } from "svelte";
162
162
  import { createPopper } from "@popperjs/core";
163
- import fuzzysearch from "fuzzysearch";
163
+ import fuzzysearch from "@kws3/ui/utils/fuzzysearch";
164
164
 
165
165
  const sameWidthPopperModifier = {
166
166
  name: "sameWidth",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kws3/ui",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "description": "UI components for use with Svelte v3 applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,10 +25,9 @@
25
25
  "dependencies": {
26
26
  "apexcharts": "3.33.2",
27
27
  "flatpickr": "^4.5.2",
28
- "fuzzysearch": "^1.0.3",
29
28
  "svelte-portal": "^2.1.2",
30
29
  "text-mask-core": "^5.1.2",
31
30
  "tippy.js": "^6.3.1"
32
31
  },
33
- "gitHead": "2fdaba3e13397494f06b5881bf92f68b1c7c695d"
32
+ "gitHead": "9fcbe3d34101490398b7bf571334e84e9ee04aee"
34
33
  }
@@ -0,0 +1,20 @@
1
+ export default function fuzzysearch(needle, haystack) {
2
+ var tlen = haystack.length;
3
+ var qlen = needle.length;
4
+ if (qlen > tlen) {
5
+ return false;
6
+ }
7
+ if (qlen === tlen) {
8
+ return needle === haystack;
9
+ }
10
+ outer: for (var i = 0, j = 0; i < qlen; i++) {
11
+ var nch = needle.charCodeAt(i);
12
+ while (j < tlen) {
13
+ if (haystack.charCodeAt(j++) === nch) {
14
+ continue outer;
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+ return true;
20
+ }