Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Apr 22, 2024
1 parent dc1a160 commit 424bf56
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { isBrowser } from "$lib/internal/utils/browser.js";


/**
* Returns a reactive value that is equal to `document.activeElement`.
* It automatically listens for changes, keeping the reference up to date.
*
* @export
* @returns {{ value: Readonly<Element | null> }}
*/
export function useActiveElement(): { value: Readonly<Element | null> } {
const activeElement = $state({ value: isBrowser() ? document.activeElement : null });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import type { FunctionArgs, ValueOrGetter } from "$lib/internal/types.js";
* The second parameter is the time to wait before calling the original callback.
* Alternatively, it can also be a getter function that returns the time to wait.
*
* @export
* @template {FunctionArgs} Callback
* @param {Callback} callback
* @param {number} wait
*/
export function useDebounce<Callback extends FunctionArgs>(
callback: Callback,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@ type Options = {
box?: "content-box" | "border-box";
};


/**
* Returns a reactive value holding the size of `node`.
*
* @export
* @param {ValueOrGetter<HTMLElement | undefined>} node
* @param {Options} [options={
* box: "border-box",
* }]
* @returns {*}
*/
export function useElementSize(
_node: ValueOrGetter<HTMLElement | undefined>,
node: ValueOrGetter<HTMLElement | undefined>,
options: Options = {
box: "border-box",
}
) {
const node = boxed(_node);
const $node = boxed(node);
const size = $state({
width: options.initialSize?.width ?? 0,
height: options.initialSize?.height ?? 0,
});

$effect(() => {
if (!node.value) return;
if (!$node.value) return;

const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
Expand All @@ -33,7 +44,7 @@ export function useElementSize(
size.height = boxSizeArr.reduce((acc, size) => Math.max(acc, size.blockSize), 0);
}
});
observer.observe(node.value);
observer.observe($node.value);

return () => {
observer.disconnect();
Expand Down

This file was deleted.

0 comments on commit 424bf56

Please sign in to comment.