@onsvisual/svelte-components 1.0.52 → 1.0.54
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/decorators/Icon/Icon.svelte +17 -3
- package/dist/decorators/Icon/Icon.svelte.d.ts +6 -2
- package/dist/inputs/Button/Button.svelte +1 -1
- package/dist/inputs/Button/Button.svelte.d.ts +2 -2
- package/dist/wrappers/LazyLoad/LazyLoad.svelte +9 -14
- package/dist/wrappers/LazyLoad/docs/component.md +2 -2
- package/dist/wrappers/Observe/Observe.svelte +8 -8
- package/dist/wrappers/Observe/docs/component.md +5 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
/**
|
|
3
3
|
* Set the type of icon
|
|
4
|
-
* @type {"arrow"|"carret"|"chevron"|"cog"|"cross"|"download"|"expand"|"external"|"pin"|"print"|"search"|"shrink"|"signout"|"tick"}
|
|
4
|
+
* @type {"arrow"|"carret"|"chevron"|"code"|"cog"|"cross"|"download"|"expand"|"external"|"pin"|"print"|"search"|"shrink"|"signout"|"tick"}
|
|
5
5
|
*/
|
|
6
6
|
export let type = "arrow";
|
|
7
7
|
/**
|
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
* @type {number}
|
|
15
15
|
*/
|
|
16
16
|
export let rotation = 0;
|
|
17
|
+
/**
|
|
18
|
+
* (Optional) Provide a custom SVG path string for the icon (overrides "type")
|
|
19
|
+
* @type {string|null}
|
|
20
|
+
*/
|
|
21
|
+
export let svgPath = null;
|
|
22
|
+
/**
|
|
23
|
+
* (Optional) If using a custom SVG path, specify the viewBox of the SVG
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
export let svgViewBox = "0 0 24 24";
|
|
17
27
|
/**
|
|
18
28
|
* Add a small margin on the left of the icon
|
|
19
29
|
* @type {boolean}
|
|
@@ -42,6 +52,10 @@
|
|
|
42
52
|
d: "M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6Z",
|
|
43
53
|
viewBox: "2 2 20 20"
|
|
44
54
|
},
|
|
55
|
+
code: {
|
|
56
|
+
d: "M9.4 16.6 4.8 12l4.6-4.6L8 6l-6 6 6 6zm5.2 0 4.6-4.6-4.6-4.6L16 6l6 6-6 6z",
|
|
57
|
+
viewBox: "2 2 20 20"
|
|
58
|
+
},
|
|
45
59
|
cross: {
|
|
46
60
|
d: "M12 1.2086L10.7914 0L6 4.79155L1.20857 0L0 1.2086L4.79143 6.00015L0 10.7917L1.20857 12.0003L6 7.20875L10.7914 12.0003L12 10.7917L7.20857 6.00015L12 1.2086Z",
|
|
47
61
|
viewBox: "0 0 12 12"
|
|
@@ -90,12 +104,12 @@
|
|
|
90
104
|
class="ons-icon {size ? `ons-icon--${size}` : ''}"
|
|
91
105
|
class:ons-u-ml-2xs={marginLeft}
|
|
92
106
|
class:ons-u-mr-2xs={marginRight}
|
|
93
|
-
viewBox={paths[type].viewBox}
|
|
107
|
+
viewBox={svgPath && svgViewBox ? svgViewBox : paths[type].viewBox}
|
|
94
108
|
xmlns="http://www.w3.org/2000/svg"
|
|
95
109
|
focusable="false"
|
|
96
110
|
fill="currentColor"
|
|
97
111
|
style:transform={rotation ? `rotate(${rotation}deg)` : null}
|
|
98
112
|
>
|
|
99
|
-
<path d={paths[type].d}></path>
|
|
113
|
+
<path d={svgPath || paths[type].d}></path>
|
|
100
114
|
</svg>
|
|
101
115
|
{/if}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} IconEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} IconSlots */
|
|
4
4
|
export default class Icon extends SvelteComponentTyped<{
|
|
5
|
-
type?: "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | undefined;
|
|
5
|
+
type?: "code" | "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | undefined;
|
|
6
6
|
size?: "s" | "m" | "l" | "xl" | "2xl" | "3xl" | null | undefined;
|
|
7
7
|
rotation?: number | undefined;
|
|
8
|
+
svgPath?: string | null | undefined;
|
|
9
|
+
svgViewBox?: string | undefined;
|
|
8
10
|
marginLeft?: boolean | undefined;
|
|
9
11
|
marginRight?: boolean | undefined;
|
|
10
12
|
}, {
|
|
@@ -17,9 +19,11 @@ export type IconSlots = typeof __propDef.slots;
|
|
|
17
19
|
import { SvelteComponentTyped } from "svelte";
|
|
18
20
|
declare const __propDef: {
|
|
19
21
|
props: {
|
|
20
|
-
type?: "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | undefined;
|
|
22
|
+
type?: "code" | "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | undefined;
|
|
21
23
|
size?: "s" | "m" | "l" | "xl" | "2xl" | "3xl" | null | undefined;
|
|
22
24
|
rotation?: number | undefined;
|
|
25
|
+
svgPath?: string | null | undefined;
|
|
26
|
+
svgViewBox?: string | undefined;
|
|
23
27
|
marginLeft?: boolean | undefined;
|
|
24
28
|
marginRight?: boolean | undefined;
|
|
25
29
|
};
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
export let small = false;
|
|
38
38
|
/**
|
|
39
39
|
* Icon on button, eg. "arrow", "search"
|
|
40
|
-
* @type {"arrow"|"carret"|"chevron"|"cog"|"cross"|"download"|"expand"|"external"|"pin"|"print"|"search"|"shrink"|"signout"|"tick"|null}
|
|
40
|
+
* @type {"arrow"|"carret"|"chevron"|"code"|"cog"|"cross"|"download"|"expand"|"external"|"pin"|"print"|"search"|"shrink"|"signout"|"tick"|null}
|
|
41
41
|
*/
|
|
42
42
|
export let icon = null;
|
|
43
43
|
/**
|
|
@@ -10,7 +10,7 @@ export default class Button extends SvelteComponentTyped<{
|
|
|
10
10
|
type?: "button" | "reset" | "submit" | undefined;
|
|
11
11
|
variant?: "secondary" | "primary" | "ghost" | undefined;
|
|
12
12
|
noScroll?: boolean | undefined;
|
|
13
|
-
icon?: "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | null | undefined;
|
|
13
|
+
icon?: "code" | "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | null | undefined;
|
|
14
14
|
iconPosition?: "before" | "after" | undefined;
|
|
15
15
|
iconRotation?: number | undefined;
|
|
16
16
|
disabled?: boolean | undefined;
|
|
@@ -39,7 +39,7 @@ declare const __propDef: {
|
|
|
39
39
|
type?: "button" | "reset" | "submit" | undefined;
|
|
40
40
|
variant?: "secondary" | "primary" | "ghost" | undefined;
|
|
41
41
|
noScroll?: boolean | undefined;
|
|
42
|
-
icon?: "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | null | undefined;
|
|
42
|
+
icon?: "code" | "search" | "expand" | "arrow" | "carret" | "chevron" | "cog" | "cross" | "download" | "external" | "pin" | "print" | "shrink" | "signout" | "tick" | null | undefined;
|
|
43
43
|
iconPosition?: "before" | "after" | undefined;
|
|
44
44
|
iconRotation?: number | undefined;
|
|
45
45
|
disabled?: boolean | undefined;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { onMount, onDestroy } from "svelte";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Bind to this variable to monitor whether the component has entered the viewport (boolean true/false).
|
|
6
4
|
* @type {boolean}
|
|
@@ -17,34 +15,31 @@
|
|
|
17
15
|
*/
|
|
18
16
|
export let rootMargin = 200;
|
|
19
17
|
|
|
20
|
-
let el, observer;
|
|
21
|
-
|
|
22
18
|
const callback = (entries, observer) => {
|
|
23
19
|
entries.forEach((entry) => {
|
|
20
|
+
console.log(entry);
|
|
24
21
|
let intersecting = entry.isIntersecting;
|
|
25
22
|
if (!entered && intersecting) {
|
|
26
|
-
observer.unobserve(
|
|
23
|
+
observer.unobserve(entry.target);
|
|
27
24
|
entered = true;
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
};
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
function initObserver(el) {
|
|
33
30
|
let options = { root: document, rootMargin: `${rootMargin}px` };
|
|
34
31
|
|
|
35
|
-
observer = new IntersectionObserver(callback, options);
|
|
32
|
+
const observer = new IntersectionObserver(callback, options);
|
|
36
33
|
observer.observe(el);
|
|
37
|
-
});
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
35
|
+
return {
|
|
36
|
+
destroy: () => observer?.unobserve?.(el)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
44
39
|
</script>
|
|
45
40
|
|
|
46
41
|
{#if entered}
|
|
47
42
|
<slot />
|
|
48
43
|
{:else}
|
|
49
|
-
<div
|
|
44
|
+
<div use:initObserver style:height="{+initialHeight || 100}px"></div>
|
|
50
45
|
{/if}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
A wrapper component that uses IntersectionObserver to allow the elements it contains to be lazy loaded, ie. to be
|
|
1
|
+
A wrapper component that uses IntersectionObserver to allow the Svelte components or HTML elements it contains to be lazy loaded, ie. to be added to the page (or DOM) only when they enter the viewport.
|
|
2
2
|
|
|
3
|
-
Optionally, you can use the **initialHeight** to set a placeholder height in pixels (default 400), and you can use **rootMargin** to set how many pixels
|
|
3
|
+
Optionally, you can use the **initialHeight** to set a placeholder height in pixels (default 400), and you can use **rootMargin** to set how many pixels before the viewport you want lazy loading to kick in (default 200).
|
|
4
4
|
|
|
5
5
|
<!-- prettier-ignore -->
|
|
6
6
|
```html
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
2
|
+
import { createEventDispatcher } from "svelte";
|
|
3
3
|
|
|
4
4
|
const dispatch = createEventDispatcher();
|
|
5
5
|
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export let rootMargin = 0;
|
|
16
16
|
|
|
17
|
-
let el, observer;
|
|
18
|
-
|
|
19
17
|
const callback = (entries) => {
|
|
20
18
|
entries.forEach((entry) => {
|
|
21
19
|
let intersecting = entry.isIntersecting;
|
|
@@ -30,16 +28,18 @@
|
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
function initObserver(el) {
|
|
34
32
|
let options = { root: document, rootMargin: `${rootMargin}px` };
|
|
35
33
|
|
|
36
|
-
observer = new IntersectionObserver(callback, options);
|
|
34
|
+
const observer = new IntersectionObserver(callback, options);
|
|
37
35
|
observer.observe(el);
|
|
38
|
-
});
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
return {
|
|
38
|
+
destroy: () => observer?.unobserve?.(el)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
41
|
</script>
|
|
42
42
|
|
|
43
|
-
<div
|
|
43
|
+
<div use:initObserver>
|
|
44
44
|
<slot />
|
|
45
45
|
</div>
|
|
@@ -4,16 +4,21 @@ This component can be useful for triggering actions such as lazy loading of data
|
|
|
4
4
|
|
|
5
5
|
This component has **enter** and **exit** events, triggered when it enters or leaves the viewport. It also has a **visible** binding which has a value of **true** when it is within the viewport.
|
|
6
6
|
|
|
7
|
+
In this demo, you can open your browser's developer console (**F12**) to see the logs for elements entering and existing the viewport.
|
|
8
|
+
|
|
7
9
|
<!-- prettier-ignore -->
|
|
8
10
|
```html
|
|
9
11
|
<script>
|
|
10
12
|
import { Observe } from "@onsvisual/svelte-components";
|
|
11
13
|
|
|
14
|
+
let visible;
|
|
15
|
+
|
|
12
16
|
const colors = ["yellow", "green", "blue", "purple", "red", "orange"];
|
|
13
17
|
</script>
|
|
14
18
|
|
|
15
19
|
{#each colors as color}
|
|
16
20
|
<Observe
|
|
21
|
+
bind:visible
|
|
17
22
|
on:enter={() => console.log(`${color} entered`)}
|
|
18
23
|
on:exit={() => console.log(`${color} exited`)}>
|
|
19
24
|
<div class="section" style:background={color} style:height="400px"/>
|