tera-system-ui 0.0.41 → 0.0.43
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.
|
@@ -4,7 +4,7 @@ export const styles = tv({
|
|
|
4
4
|
base: '',
|
|
5
5
|
dialog: 'bg-transparent text-inherit',
|
|
6
6
|
dialogContainer: 'py-4 rounded-container',
|
|
7
|
-
header: 'font-
|
|
7
|
+
header: 'font-bold px-4 mb-2',
|
|
8
8
|
body: 'px-4',
|
|
9
9
|
footer: 'mt-3 px-4 flex items-center justify-end gap-2.5'
|
|
10
10
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {cn} from "../../../utils/utils";
|
|
2
|
+
import {cn, consoleLog, observeVisibility} from "../../../utils/utils";
|
|
3
3
|
import {getCtx} from "../Tabs";
|
|
4
|
+
import {onMount} from "svelte";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
children,
|
|
@@ -11,7 +12,9 @@
|
|
|
11
12
|
let tabIndicator = $state()
|
|
12
13
|
let tabsList = $state()
|
|
13
14
|
|
|
14
|
-
function updateIndicator(
|
|
15
|
+
function updateIndicator() {
|
|
16
|
+
let button = tabsList?.querySelector(`button[data-value="${context.state.currentTab}"]`)
|
|
17
|
+
|
|
15
18
|
const rect = button.getBoundingClientRect();
|
|
16
19
|
const containerRect = tabsList.getBoundingClientRect();
|
|
17
20
|
|
|
@@ -20,14 +23,27 @@
|
|
|
20
23
|
|
|
21
24
|
tabIndicator.style.left = `${left}px`;
|
|
22
25
|
tabIndicator.style.width = `${width}px`;
|
|
26
|
+
|
|
27
|
+
consoleLog('TabList', 'tabIndicator', tabIndicator)
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
|
|
26
31
|
let context = getCtx()
|
|
27
32
|
|
|
28
33
|
$effect(() => {
|
|
29
|
-
|
|
30
|
-
updateIndicator(
|
|
34
|
+
context.state.currentTab
|
|
35
|
+
updateIndicator();
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
onMount(() => {
|
|
39
|
+
const stopObserving = observeVisibility(tabIndicator, (isVisible, entry) => {
|
|
40
|
+
if (isVisible) {
|
|
41
|
+
consoleLog('Element is visible:', entry.target);
|
|
42
|
+
updateIndicator()
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return () => stopObserving()
|
|
31
47
|
})
|
|
32
48
|
</script>
|
|
33
49
|
|
package/dist/utils/utils.d.ts
CHANGED
package/dist/utils/utils.js
CHANGED
|
@@ -3,3 +3,22 @@ import { twMerge } from "tailwind-merge";
|
|
|
3
3
|
export function cn(...inputs) {
|
|
4
4
|
return twMerge(clsx(inputs));
|
|
5
5
|
}
|
|
6
|
+
export function consoleLog(...params) {
|
|
7
|
+
console.log('tera-system-ui', ...params);
|
|
8
|
+
}
|
|
9
|
+
export function observeVisibility(element, callback) {
|
|
10
|
+
if (!element) {
|
|
11
|
+
throw new Error("Invalid element provided.");
|
|
12
|
+
}
|
|
13
|
+
// Create an Intersection Observer
|
|
14
|
+
const observer = new IntersectionObserver((entries) => {
|
|
15
|
+
entries.forEach((entry) => {
|
|
16
|
+
// Check if the element is visible
|
|
17
|
+
callback(entry.isIntersecting, entry);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
// Start observing the element
|
|
21
|
+
observer.observe(element);
|
|
22
|
+
// Return a function to stop observing
|
|
23
|
+
return () => observer.disconnect();
|
|
24
|
+
}
|