@uibit/scroll-progress 0.1.1 → 0.2.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.
- package/dist/frameworks/angular/index.ts +18 -20
- package/dist/frameworks/astro/index.d.ts +5 -1
- package/dist/frameworks/preact/index.d.ts +1 -0
- package/dist/frameworks/react/index.ts +61 -0
- package/dist/frameworks/stencil/index.d.ts +1 -0
- package/dist/frameworks/svelte/index.svelte +41 -15
- package/dist/frameworks/vue/index.ts +60 -19
- package/package.json +3 -3
- package/dist/frameworks/react/index.d.ts +0 -18
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { Component, ChangeDetectionStrategy, ElementRef, input, effect } from '@angular/core';
|
|
2
2
|
import '@uibit/scroll-progress';
|
|
3
3
|
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
4
|
-
|
|
5
4
|
@Component({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
selector: 'uibit-scroll-progress',
|
|
6
|
+
template: '<ng-content></ng-content>',
|
|
7
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
8
|
+
standalone: true
|
|
10
9
|
})
|
|
11
10
|
export class NgxScrollProgress {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
readonly locale = input<string, any>('');
|
|
11
|
+
constructor(private el: ElementRef<HTMLElementClass>){
|
|
12
|
+
effect(()=>{
|
|
13
|
+
if (this.el.nativeElement) {
|
|
14
|
+
this.el.nativeElement.targetSelector = this.targetSelector();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
effect(()=>{
|
|
18
|
+
if (this.el.nativeElement) {
|
|
19
|
+
this.el.nativeElement.locale = this.locale();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
readonly targetSelector = input<string | undefined>(undefined);
|
|
24
|
+
readonly locale = input<string>('');
|
|
27
25
|
}
|
|
@@ -4,7 +4,11 @@ import '@uibit/scroll-progress';
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace astroHTML.JSX {
|
|
6
6
|
interface IntrinsicElements {
|
|
7
|
-
'uibit-scroll-progress': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes
|
|
7
|
+
'uibit-scroll-progress': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
|
|
8
|
+
targetSelector?: string | undefined;
|
|
9
|
+
locale?: string;
|
|
10
|
+
|
|
11
|
+
};
|
|
8
12
|
}
|
|
9
13
|
}
|
|
10
14
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
+
import '@uibit/scroll-progress';
|
|
4
|
+
const useTypeOfLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
5
|
+
export interface ScrollProgressProps extends Omit<React.HTMLAttributes<HTMLElementClass>, 'targetSelector' | 'locale'> {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
targetSelector?: string | undefined;
|
|
8
|
+
locale?: string;
|
|
9
|
+
}
|
|
10
|
+
export const ScrollProgress = ({ ref, children, ...props }: ScrollProgressProps & {
|
|
11
|
+
ref?: React.Ref<HTMLElementClass>;
|
|
12
|
+
})=>{
|
|
13
|
+
const innerRef = useRef<HTMLElementClass>(null);
|
|
14
|
+
const propsRef = useRef(props);
|
|
15
|
+
propsRef.current = props;
|
|
16
|
+
useImperativeHandle(ref, ()=>innerRef.current!);
|
|
17
|
+
useTypeOfLayoutEffect(()=>{
|
|
18
|
+
const element = innerRef.current;
|
|
19
|
+
if (element && props.targetSelector !== undefined) {
|
|
20
|
+
(element as any).targetSelector = props.targetSelector;
|
|
21
|
+
}
|
|
22
|
+
}, [
|
|
23
|
+
props.targetSelector
|
|
24
|
+
]);
|
|
25
|
+
useTypeOfLayoutEffect(()=>{
|
|
26
|
+
const element = innerRef.current;
|
|
27
|
+
if (element && props.locale !== undefined) {
|
|
28
|
+
(element as any).locale = props.locale;
|
|
29
|
+
}
|
|
30
|
+
}, [
|
|
31
|
+
props.locale
|
|
32
|
+
]);
|
|
33
|
+
const domProps = {
|
|
34
|
+
...props
|
|
35
|
+
};
|
|
36
|
+
const customPropNames = [
|
|
37
|
+
'targetSelector',
|
|
38
|
+
'locale'
|
|
39
|
+
];
|
|
40
|
+
for (const key of customPropNames){
|
|
41
|
+
delete (domProps as any)[key];
|
|
42
|
+
}
|
|
43
|
+
return React.createElement('uibit-scroll-progress', {
|
|
44
|
+
ref: innerRef,
|
|
45
|
+
...domProps
|
|
46
|
+
}, children);
|
|
47
|
+
};
|
|
48
|
+
declare global {
|
|
49
|
+
namespace React {
|
|
50
|
+
namespace JSX {
|
|
51
|
+
interface IntrinsicElements {
|
|
52
|
+
'uibit-scroll-progress': React.ClassAttributes<HTMLElementClass> & React.HTMLAttributes<HTMLElementClass> & {
|
|
53
|
+
children?: React.ReactNode;
|
|
54
|
+
class?: string;
|
|
55
|
+
targetSelector?: string | undefined;
|
|
56
|
+
locale?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,32 +1,58 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import '@uibit/scroll-progress';
|
|
3
3
|
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
targetSelector =
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
targetSelector = $bindable(),
|
|
7
|
+
locale = $bindable(),
|
|
8
|
+
children,
|
|
9
|
+
...restProps
|
|
9
10
|
} = $props<{
|
|
10
|
-
children?:
|
|
11
|
+
children?: import('svelte').Snippet;
|
|
11
12
|
targetSelector?: string | undefined;
|
|
12
13
|
locale?: string;
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
[key: string]: any;
|
|
14
16
|
}>();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (elementRef && targetSelector !== undefined) {
|
|
17
|
+
|
|
18
|
+
let elementRef: HTMLElementClass | null = $state(null);
|
|
19
|
+
|
|
20
|
+
$effect(() => {
|
|
21
|
+
if (elementRef && targetSelector !== undefined && elementRef.targetSelector !== targetSelector) {
|
|
20
22
|
elementRef.targetSelector = targetSelector;
|
|
21
23
|
}
|
|
22
|
-
if (elementRef && locale !== undefined) {
|
|
24
|
+
if (elementRef && locale !== undefined && elementRef.locale !== locale) {
|
|
23
25
|
elementRef.locale = locale;
|
|
24
26
|
}
|
|
25
27
|
});
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
$effect(() => {
|
|
30
|
+
const element = elementRef;
|
|
31
|
+
if (!element) return;
|
|
32
|
+
|
|
33
|
+
const handleEvent = () => {
|
|
34
|
+
if (targetSelector !== element.targetSelector) {
|
|
35
|
+
targetSelector = element.targetSelector as any;
|
|
36
|
+
}
|
|
37
|
+
if (locale !== element.locale) {
|
|
38
|
+
locale = element.locale as any;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const events = ['change', 'input'];
|
|
43
|
+
for (const event of events) {
|
|
44
|
+
element.addEventListener(event, handleEvent);
|
|
45
|
+
}
|
|
46
|
+
return () => {
|
|
47
|
+
for (const event of events) {
|
|
48
|
+
element.removeEventListener(event, handleEvent);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
|
|
27
53
|
</script>
|
|
28
54
|
|
|
29
|
-
<uibit-scroll-progress bind:this={elementRef} {
|
|
55
|
+
<uibit-scroll-progress bind:this={elementRef} {...restProps}>
|
|
30
56
|
|
|
31
57
|
{#if children}
|
|
32
58
|
{@render children()}
|
|
@@ -1,23 +1,64 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
|
1
|
+
import { defineComponent, h, ref, watch } from 'vue';
|
|
2
2
|
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
3
|
import '@uibit/scroll-progress';
|
|
4
|
-
|
|
5
4
|
export const ScrollProgress = defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
name: 'ScrollProgress',
|
|
6
|
+
props: {
|
|
7
|
+
targetSelector: {
|
|
8
|
+
type: [
|
|
9
|
+
String,
|
|
10
|
+
Number,
|
|
11
|
+
Boolean,
|
|
12
|
+
Array,
|
|
13
|
+
Object
|
|
14
|
+
] as any
|
|
15
|
+
},
|
|
16
|
+
locale: {
|
|
17
|
+
type: [
|
|
18
|
+
String,
|
|
19
|
+
Number,
|
|
20
|
+
Boolean,
|
|
21
|
+
Array,
|
|
22
|
+
Object
|
|
23
|
+
] as any
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
emits: [],
|
|
27
|
+
setup (props, { slots, emit }) {
|
|
28
|
+
const elementRef = ref<HTMLElementClass | null>(null);
|
|
29
|
+
if (false) {
|
|
30
|
+
watch(()=>props.modelValue, (newVal)=>{
|
|
31
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
32
|
+
elementRef.value.value = newVal;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
watch(()=>props.value, (newVal)=>{
|
|
36
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
37
|
+
elementRef.value.value = newVal;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
watch(()=>props.targetSelector, (newVal)=>{
|
|
42
|
+
if (elementRef.value && newVal !== undefined) {
|
|
43
|
+
(elementRef.value as any).targetSelector = newVal;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
watch(()=>props.locale, (newVal)=>{
|
|
47
|
+
if (elementRef.value && newVal !== undefined) {
|
|
48
|
+
(elementRef.value as any).locale = newVal;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return ()=>{
|
|
52
|
+
const eventListeners: Record<string, any> = {};
|
|
53
|
+
const mergedProps = {
|
|
54
|
+
...props,
|
|
55
|
+
...eventListeners,
|
|
56
|
+
ref: elementRef
|
|
57
|
+
};
|
|
58
|
+
if (false && props.modelValue !== undefined) {
|
|
59
|
+
(mergedProps as any).value = props.modelValue;
|
|
60
|
+
}
|
|
61
|
+
return h('uibit-scroll-progress', mergedProps, slots.default?.());
|
|
62
|
+
};
|
|
63
|
+
}
|
|
23
64
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibit/scroll-progress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Lightweight, accessible scroll progress indicator. Tracks viewport scrolling by default, or can be targeting a specific scrollable element using selectors.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./custom-elements.json": "./custom-elements.json",
|
|
14
|
-
"./react": "./dist/frameworks/react/index.
|
|
14
|
+
"./react": "./dist/frameworks/react/index.ts",
|
|
15
15
|
"./vue": "./dist/frameworks/vue/index.ts",
|
|
16
16
|
"./svelte": "./dist/frameworks/svelte/index.svelte",
|
|
17
17
|
"./angular": "./dist/frameworks/angular/index.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/node": "^20.19.43",
|
|
51
51
|
"lit": "^3.3.3",
|
|
52
52
|
"typescript": "7.0.2",
|
|
53
|
-
"@uibit/codegen": "0.
|
|
53
|
+
"@uibit/codegen": "0.2.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"lit": "^3.0.0",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes, ClassAttributes } from 'react';
|
|
2
|
-
import type { ScrollProgress as HTMLElementClass } from '@uibit/scroll-progress';
|
|
3
|
-
import '@uibit/scroll-progress';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
namespace React {
|
|
7
|
-
namespace JSX {
|
|
8
|
-
interface IntrinsicElements {
|
|
9
|
-
'uibit-scroll-progress': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
|
|
10
|
-
children?: React.ReactNode;
|
|
11
|
-
class?: string;
|
|
12
|
-
targetSelector?: string | undefined;
|
|
13
|
-
locale?: string;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|