feat(Section): add id prop and pass it to onTitleStatusChange callback
This commit is contained in:
@@ -14,6 +14,10 @@ import {
|
|||||||
import { Footnote } from '..';
|
import { Footnote } from '..';
|
||||||
|
|
||||||
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
interface Props extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
||||||
|
/**
|
||||||
|
* ID of the section
|
||||||
|
*/
|
||||||
|
id?: string;
|
||||||
/**
|
/**
|
||||||
* Additional CSS classes to apply to the section container.
|
* Additional CSS classes to apply to the section container.
|
||||||
*/
|
*/
|
||||||
@@ -40,16 +44,22 @@ interface Props extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|||||||
* @param index - Index of the section
|
* @param index - Index of the section
|
||||||
* @param isPast - Whether the section is past the current scroll position
|
* @param isPast - Whether the section is past the current scroll position
|
||||||
* @param title - Snippet for a title itself
|
* @param title - Snippet for a title itself
|
||||||
|
* @param id - ID of the section
|
||||||
* @returns Cleanup callback
|
* @returns Cleanup callback
|
||||||
*/
|
*/
|
||||||
onTitleStatusChange?: (index: number, isPast: boolean, title?: Snippet<[{ className?: string }]>) => () => void;
|
onTitleStatusChange?: (
|
||||||
|
index: number,
|
||||||
|
isPast: boolean,
|
||||||
|
title?: Snippet<[{ className?: string }]>,
|
||||||
|
id?: string,
|
||||||
|
) => () => void;
|
||||||
/**
|
/**
|
||||||
* Snippet for the section content
|
* Snippet for the section content
|
||||||
*/
|
*/
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { class: className, title, icon, description, index = 0, onTitleStatusChange, children }: Props = $props();
|
const { class: className, title, icon, description, index = 0, onTitleStatusChange, id, children }: Props = $props();
|
||||||
|
|
||||||
let titleContainer = $state<HTMLElement>();
|
let titleContainer = $state<HTMLElement>();
|
||||||
const flyParams: FlyParams = { y: 0, x: -50, duration: 300, easing: cubicOut, opacity: 0.2 };
|
const flyParams: FlyParams = { y: 0, x: -50, duration: 300, easing: cubicOut, opacity: 0.2 };
|
||||||
@@ -68,7 +78,7 @@ $effect(() => {
|
|||||||
|
|
||||||
if (isPast !== isScrolledPast) {
|
if (isPast !== isScrolledPast) {
|
||||||
isScrolledPast = isPast;
|
isScrolledPast = isPast;
|
||||||
cleanup = onTitleStatusChange?.(index, isPast, title);
|
cleanup = onTitleStatusChange?.(index, isPast, title, id);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
// Set threshold to 0 to trigger exactly when the last pixel leaves
|
// Set threshold to 0 to trigger exactly when the last pixel leaves
|
||||||
@@ -84,6 +94,7 @@ $effect(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section
|
<section
|
||||||
|
id={id}
|
||||||
class={cn(
|
class={cn(
|
||||||
'flex flex-col',
|
'flex flex-col',
|
||||||
className,
|
className,
|
||||||
|
|||||||
Reference in New Issue
Block a user