@kws3/ui 2.2.3 → 2.2.5
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 +6 -0
- package/controls/ToggleButtons.svelte +32 -4
- package/helpers/ScrollableList.svelte +18 -8
- package/package.json +2 -2
package/CHANGELOG.mdx
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# 2.2.3
|
|
2
|
+
- `ScrollableList` - bugfixes, and add support for removing items without affecting scroll position
|
|
3
|
+
|
|
4
|
+
# 2.2.4
|
|
5
|
+
- `ToggleButtons` - add support for count tags, and fix css not applying
|
|
6
|
+
|
|
1
7
|
# 2.2.3
|
|
2
8
|
- `ScrollableList` - add support for custom iteration key for keyed each block
|
|
3
9
|
|
|
@@ -12,6 +12,7 @@ This property can be bound to, to fetch the current value, Default: `null`
|
|
|
12
12
|
- `value`: Value of the button
|
|
13
13
|
- `subtitle`: Optional subtitle
|
|
14
14
|
- `icon`: Optional Icon to display
|
|
15
|
+
- `count`: Optional number to display on top right
|
|
15
16
|
- `active_class`: Custom class to apply when button is active
|
|
16
17
|
- `inactive_class`: Custom class to apply when button is inactive
|
|
17
18
|
|
|
@@ -50,9 +51,10 @@ This property can be bound to, to fetch the current value, Default: `null`
|
|
|
50
51
|
{/if}
|
|
51
52
|
<span class="is-block">{option.name}</span>
|
|
52
53
|
{#if option.subtitle}
|
|
53
|
-
<span
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
<span class="option-subtitle">{option.subtitle}</span>
|
|
55
|
+
{/if}
|
|
56
|
+
{#if option.count}
|
|
57
|
+
<span class="count">{option.count}</span>
|
|
56
58
|
{/if}
|
|
57
59
|
</span>
|
|
58
60
|
</button>
|
|
@@ -61,7 +63,7 @@ This property can be bound to, to fetch the current value, Default: `null`
|
|
|
61
63
|
</div>
|
|
62
64
|
|
|
63
65
|
<style lang="scss">
|
|
64
|
-
.toggle-buttons {
|
|
66
|
+
.kws-toggle-buttons {
|
|
65
67
|
.button,
|
|
66
68
|
.button:focus {
|
|
67
69
|
:global(.icon) {
|
|
@@ -72,6 +74,31 @@ This property can be bound to, to fetch the current value, Default: `null`
|
|
|
72
74
|
box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.3) inset !important;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
77
|
+
.button {
|
|
78
|
+
position: relative;
|
|
79
|
+
.option-subtitle {
|
|
80
|
+
font-size: 0.7em;
|
|
81
|
+
display: block;
|
|
82
|
+
margin-top: -0.3em;
|
|
83
|
+
opacity: 0.7;
|
|
84
|
+
}
|
|
85
|
+
.count {
|
|
86
|
+
position: absolute;
|
|
87
|
+
font-weight: 600;
|
|
88
|
+
font-size: 0.8em;
|
|
89
|
+
border-radius: 999px;
|
|
90
|
+
padding: 0.15em 0.2em;
|
|
91
|
+
min-width: 1.8em;
|
|
92
|
+
min-height: 1.5em;
|
|
93
|
+
top: -0.75em;
|
|
94
|
+
right: 0.2em;
|
|
95
|
+
display: inline-flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: center;
|
|
98
|
+
background: #ca0303;
|
|
99
|
+
color: #fff;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
75
102
|
}
|
|
76
103
|
</style>
|
|
77
104
|
|
|
@@ -102,6 +129,7 @@ This property can be bound to, to fetch the current value, Default: `null`
|
|
|
102
129
|
* - `value`: Value of the button
|
|
103
130
|
* - `subtitle`: Optional subtitle
|
|
104
131
|
* - `icon`: Optional Icon to display
|
|
132
|
+
* - `count`: Optional number to display on top right
|
|
105
133
|
* - `active_class`: Custom class to apply when button is active
|
|
106
134
|
* - `inactive_class`: Custom class to apply when button is inactive
|
|
107
135
|
*
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@param {number} [end=0] - Last item index rendered inside viewport - readonly, Default: `0`
|
|
11
11
|
@param {number} [end_threshold=10] - `end` event will be fired when the list reaches this many items before the end of the list., Default: `10`
|
|
12
12
|
@param {number} [padding_threshold=5] - render 'n' number of items on outside the viewport (top and bottom) to avoid visible glitches on scrolling., Default: `5`
|
|
13
|
+
@param {number} [mutation_threshold=5] - Number of items that can be spliced in or out, before the scroll position resets, helpful for adding/removing list items in-place, Default: `5`
|
|
13
14
|
@param {string} [style=""] - Inline CSS for scroller container, Default: `""`
|
|
14
15
|
@param {string} [class=""] - CSS classes for scroller container, Default: `""`
|
|
15
16
|
|
|
@@ -81,9 +82,8 @@ while more items are loading
|
|
|
81
82
|
</style>
|
|
82
83
|
|
|
83
84
|
<script>
|
|
84
|
-
import {
|
|
85
|
-
import { createEventDispatcher } from "svelte";
|
|
86
|
-
import { resizeObserver, hasResizeObserver } from "@kws3/ui/resizeObserver";
|
|
85
|
+
import { hasResizeObserver, resizeObserver } from "@kws3/ui/resizeObserver";
|
|
86
|
+
import { createEventDispatcher, onMount, tick } from "svelte";
|
|
87
87
|
|
|
88
88
|
const fire = createEventDispatcher();
|
|
89
89
|
/**
|
|
@@ -119,6 +119,10 @@ while more items are loading
|
|
|
119
119
|
* render 'n' number of items on outside the viewport (top and bottom) to avoid visible glitches on scrolling.
|
|
120
120
|
*/
|
|
121
121
|
padding_threshold = 5,
|
|
122
|
+
/**
|
|
123
|
+
* Number of items that can be spliced in or out, before the scroll position resets, helpful for adding/removing list items in-place
|
|
124
|
+
*/
|
|
125
|
+
mutation_threshold = 5,
|
|
122
126
|
/**
|
|
123
127
|
* Inline CSS for scroller container
|
|
124
128
|
*/
|
|
@@ -191,15 +195,16 @@ while more items are loading
|
|
|
191
195
|
const row_height = height_map[i] || average_height;
|
|
192
196
|
if (y + row_height > scrollTop) {
|
|
193
197
|
start = i;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
: y;
|
|
198
|
+
let rhpt = row_height * padding_threshold;
|
|
199
|
+
let diff = y - rhpt;
|
|
200
|
+
top = y > rhpt && diff > i ? diff : y;
|
|
198
201
|
break;
|
|
199
202
|
}
|
|
200
203
|
y += row_height;
|
|
201
204
|
i += 1;
|
|
202
205
|
}
|
|
206
|
+
i = 0;
|
|
207
|
+
y = 0;
|
|
203
208
|
while (i < items.length) {
|
|
204
209
|
y += height_map[i] || average_height;
|
|
205
210
|
i += 1;
|
|
@@ -210,6 +215,7 @@ while more items are loading
|
|
|
210
215
|
average_height = y / end;
|
|
211
216
|
while (i < items.length) height_map[i++] = average_height;
|
|
212
217
|
bottom = remaining * average_height;
|
|
218
|
+
|
|
213
219
|
// prevent jumping if we scrolled up into unknown territory
|
|
214
220
|
if (start < old_start) {
|
|
215
221
|
await tick();
|
|
@@ -249,7 +255,11 @@ while more items are loading
|
|
|
249
255
|
|
|
250
256
|
function reset() {
|
|
251
257
|
if (!mounted) return;
|
|
252
|
-
if (
|
|
258
|
+
if (
|
|
259
|
+
!items.length ||
|
|
260
|
+
(items.length < items_count &&
|
|
261
|
+
items_count - items.length > mutation_threshold)
|
|
262
|
+
) {
|
|
253
263
|
item_height = null;
|
|
254
264
|
start = 0;
|
|
255
265
|
end = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kws3/ui",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "UI components for use with Svelte v3 applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"svelte": "index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"typescript": "^5.0.4"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "7a85c9f2d6e4021ac05477ccda398d54064a4c13"
|
|
39
39
|
}
|