@slurp-ui/react 1.1.1 → 1.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/CHANGELOG.md +42 -0
- package/dist/Bloom/Bloom.js +3 -2
- package/dist/Bloom/Bloom.js.map +1 -1
- package/dist/Calendar/Calendar.d.ts +42 -0
- package/dist/Calendar/Calendar.js +178 -0
- package/dist/Calendar/Calendar.js.map +1 -0
- package/dist/Calendar/dates.d.ts +3 -0
- package/dist/Calendar/dates.js +46 -0
- package/dist/Calendar/dates.js.map +1 -0
- package/dist/Calendar/index.d.ts +3 -0
- package/dist/Calendar/index.js +2 -0
- package/dist/Carousel/Carousel.js +2 -0
- package/dist/Carousel/Carousel.js.map +1 -1
- package/dist/Choice/Choice.js +2 -0
- package/dist/Choice/Choice.js.map +1 -1
- package/dist/Code/Code.d.ts +38 -0
- package/dist/Code/Code.js +82 -0
- package/dist/Code/Code.js.map +1 -0
- package/dist/Code/index.d.ts +3 -0
- package/dist/Code/index.js +2 -0
- package/dist/Contents/Contents.d.ts +35 -0
- package/dist/Contents/Contents.js +63 -0
- package/dist/Contents/Contents.js.map +1 -0
- package/dist/Contents/index.d.ts +3 -0
- package/dist/Contents/index.js +2 -0
- package/dist/DateField/DateField.d.ts +29 -0
- package/dist/DateField/DateField.js +118 -0
- package/dist/DateField/DateField.js.map +1 -0
- package/dist/DateField/index.d.ts +3 -0
- package/dist/DateField/index.js +2 -0
- package/dist/Dialog/Dialog.js +73 -25
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dock/Dock.d.ts +5 -0
- package/dist/Dock/Dock.js +13 -2
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
- package/dist/ErrorSummary/ErrorSummary.js +68 -0
- package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
- package/dist/ErrorSummary/index.d.ts +3 -0
- package/dist/ErrorSummary/index.js +2 -0
- package/dist/FileDrop/FileDrop.d.ts +34 -0
- package/dist/FileDrop/FileDrop.js +145 -0
- package/dist/FileDrop/FileDrop.js.map +1 -0
- package/dist/FileDrop/index.d.ts +3 -0
- package/dist/FileDrop/index.js +2 -0
- package/dist/Filters/Filters.js +2 -0
- package/dist/Filters/Filters.js.map +1 -1
- package/dist/Footer/Footer.d.ts +37 -0
- package/dist/Footer/Footer.js +63 -0
- package/dist/Footer/Footer.js.map +1 -0
- package/dist/Footer/index.d.ts +3 -0
- package/dist/Footer/index.js +2 -0
- package/dist/Hairline/Hairline.d.ts +16 -0
- package/dist/Hairline/Hairline.js +23 -0
- package/dist/Hairline/Hairline.js.map +1 -0
- package/dist/Hairline/index.d.ts +3 -0
- package/dist/Hairline/index.js +2 -0
- package/dist/Hint/Hint.js +20 -1
- package/dist/Hint/Hint.js.map +1 -1
- package/dist/Kbd/Kbd.d.ts +7 -0
- package/dist/Kbd/Kbd.js +20 -0
- package/dist/Kbd/Kbd.js.map +1 -0
- package/dist/Kbd/index.d.ts +3 -0
- package/dist/Kbd/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +5 -1
- package/dist/ListRow/ListRow.js +5 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Media/Media.d.ts +28 -0
- package/dist/Media/Media.js +65 -0
- package/dist/Media/Media.js.map +1 -0
- package/dist/Media/index.d.ts +3 -0
- package/dist/Media/index.js +2 -0
- package/dist/Notice/Notice.js +2 -0
- package/dist/Notice/Notice.js.map +1 -1
- package/dist/NumberField/NumberField.d.ts +32 -0
- package/dist/NumberField/NumberField.js +126 -0
- package/dist/NumberField/NumberField.js.map +1 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +2 -0
- package/dist/PageNav/PageNav.d.ts +25 -0
- package/dist/PageNav/PageNav.js +57 -0
- package/dist/PageNav/PageNav.js.map +1 -0
- package/dist/PageNav/index.d.ts +3 -0
- package/dist/PageNav/index.js +2 -0
- package/dist/Pages/Pages.js +2 -0
- package/dist/Pages/Pages.js.map +1 -1
- package/dist/PinField/PinField.d.ts +26 -0
- package/dist/PinField/PinField.js +73 -0
- package/dist/PinField/PinField.js.map +1 -0
- package/dist/PinField/index.d.ts +3 -0
- package/dist/PinField/index.js +2 -0
- package/dist/Prose/Prose.d.ts +15 -0
- package/dist/Prose/Prose.js +25 -0
- package/dist/Prose/Prose.js.map +1 -0
- package/dist/Prose/index.d.ts +3 -0
- package/dist/Prose/index.js +2 -0
- package/dist/Quote/Quote.d.ts +19 -0
- package/dist/Quote/Quote.js +52 -0
- package/dist/Quote/Quote.js.map +1 -0
- package/dist/Quote/index.d.ts +3 -0
- package/dist/Quote/index.js +2 -0
- package/dist/Rail/Rail.d.ts +37 -0
- package/dist/Rail/Rail.js +61 -0
- package/dist/Rail/Rail.js.map +1 -0
- package/dist/Rail/index.d.ts +3 -0
- package/dist/Rail/index.js +2 -0
- package/dist/Rating/Rating.js +2 -0
- package/dist/Rating/Rating.js.map +1 -1
- package/dist/Search/Search.js +2 -0
- package/dist/Search/Search.js.map +1 -1
- package/dist/SecretField/SecretField.d.ts +17 -0
- package/dist/SecretField/SecretField.js +59 -0
- package/dist/SecretField/SecretField.js.map +1 -0
- package/dist/SecretField/index.d.ts +3 -0
- package/dist/SecretField/index.js +2 -0
- package/dist/Settings/Settings.js +2 -0
- package/dist/Settings/Settings.js.map +1 -1
- package/dist/SkipLink/SkipLink.d.ts +22 -0
- package/dist/SkipLink/SkipLink.js +32 -0
- package/dist/SkipLink/SkipLink.js.map +1 -0
- package/dist/SkipLink/index.d.ts +3 -0
- package/dist/SkipLink/index.js +2 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
- package/dist/SlurpProvider/SlurpProvider.js +14 -6
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
- package/dist/Steps/Steps.js +2 -0
- package/dist/Steps/Steps.js.map +1 -1
- package/dist/Suggest/Suggest.js +2 -0
- package/dist/Suggest/Suggest.js.map +1 -1
- package/dist/Table/Table.js +2 -0
- package/dist/Table/Table.js.map +1 -1
- package/dist/Tag/Tag.d.ts +14 -0
- package/dist/Tag/Tag.js +26 -0
- package/dist/Tag/Tag.js.map +1 -0
- package/dist/Tag/index.d.ts +3 -0
- package/dist/Tag/index.js +2 -0
- package/dist/Toast/Toast.js +31 -7
- package/dist/Toast/Toast.js.map +1 -1
- package/dist/index.d.ts +45 -4
- package/dist/index.js +23 -1
- package/dist/internal/labels.js +12 -0
- package/dist/internal/labels.js.map +1 -0
- package/dist/lib/labels.d.ts +175 -0
- package/dist/lib/labels.js +116 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/theme.d.ts +98 -3
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +1367 -111
- package/dist/tokens.css +9 -0
- package/dist/utils/focus.d.ts +1 -1
- package/dist/utils/focus.js +2 -2
- package/dist/utils/focus.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/useClipboard.d.ts +14 -0
- package/dist/utils/useClipboard.js +30 -0
- package/dist/utils/useClipboard.js.map +1 -0
- package/dist/utils/useScrollSpy.d.ts +14 -0
- package/dist/utils/useScrollSpy.js +27 -0
- package/dist/utils/useScrollSpy.js.map +1 -0
- package/package.json +5 -5
package/dist/tokens.css
CHANGED
|
@@ -38,6 +38,15 @@
|
|
|
38
38
|
--slurp-blur-goo: 12px;
|
|
39
39
|
--slurp-blob-opacity-light: 0.42;
|
|
40
40
|
--slurp-blob-opacity-dark: 0.3;
|
|
41
|
+
--slurp-ease-settle: cubic-bezier(0.2, 0.8, 0.2, 1);
|
|
42
|
+
--slurp-duration-press: 120ms;
|
|
43
|
+
--slurp-duration-quick: 200ms;
|
|
44
|
+
--slurp-duration-base: 250ms;
|
|
45
|
+
--slurp-duration-move: 350ms;
|
|
46
|
+
--slurp-duration-panel: 450ms;
|
|
47
|
+
--slurp-duration-surface: 600ms;
|
|
48
|
+
--slurp-duration-signature: 650ms;
|
|
49
|
+
--slurp-duration-tint: 900ms;
|
|
41
50
|
--slurp-font-family-display: Poppins, system-ui, sans-serif;
|
|
42
51
|
--slurp-font-family-sans: Poppins, system-ui, sans-serif;
|
|
43
52
|
--slurp-font-family-mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
|
package/dist/utils/focus.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { KeyboardEvent as KeyboardEvent$1 } from "react";
|
|
3
3
|
/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */
|
|
4
4
|
export declare const FOCUSABLE = "button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])";
|
|
5
|
-
/** Focuses the active choice
|
|
5
|
+
/** Focuses `[data-autofocus]` inside root, else the active choice, else its first enabled control (a panel opens). */
|
|
6
6
|
export declare function focusFirst(root: HTMLElement | null): HTMLElement | null;
|
|
7
7
|
export interface MoveFocusOptions {
|
|
8
8
|
/** `vertical` (default): ArrowUp / ArrowDown. `horizontal`: ArrowLeft / ArrowRight (flipped in RTL). `both`. */
|
package/dist/utils/focus.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
const FOCUSABLE = "button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])";
|
|
5
5
|
/** The active choice of a panel: a pressed chip, a checked radio, a selected option or tab. */
|
|
6
6
|
const ACTIVE_CHOICE = "[aria-pressed=\"true\"], [aria-selected=\"true\"], [aria-checked=\"true\"], input[type=\"radio\"]:checked";
|
|
7
|
-
/** Focuses the active choice
|
|
7
|
+
/** Focuses `[data-autofocus]` inside root, else the active choice, else its first enabled control (a panel opens). */
|
|
8
8
|
function focusFirst(root) {
|
|
9
|
-
const el = root?.querySelector(ACTIVE_CHOICE) ?? root?.querySelector("button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])");
|
|
9
|
+
const el = root?.querySelector("[data-autofocus]") ?? root?.querySelector(ACTIVE_CHOICE) ?? root?.querySelector("button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])");
|
|
10
10
|
el?.focus({ preventScroll: true });
|
|
11
11
|
return el ?? null;
|
|
12
12
|
}
|
package/dist/utils/focus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus.js","names":[],"sources":["../../src/utils/focus.ts"],"sourcesContent":["import type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */\nexport const FOCUSABLE =\n 'button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])';\n\n/** The active choice of a panel: a pressed chip, a checked radio, a selected option or tab. */\nconst ACTIVE_CHOICE =\n '[aria-pressed=\"true\"], [aria-selected=\"true\"], [aria-checked=\"true\"], input[type=\"radio\"]:checked';\n\n/** Focuses the active choice
|
|
1
|
+
{"version":3,"file":"focus.js","names":[],"sources":["../../src/utils/focus.ts"],"sourcesContent":["import type { KeyboardEvent as ReactKeyboardEvent } from 'react';\n\n/** Elements that take focus with Tab (enabled controls, links, explicit tab stops). */\nexport const FOCUSABLE =\n 'button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex=\"-1\"])';\n\n/** The active choice of a panel: a pressed chip, a checked radio, a selected option or tab. */\nconst ACTIVE_CHOICE =\n '[aria-pressed=\"true\"], [aria-selected=\"true\"], [aria-checked=\"true\"], input[type=\"radio\"]:checked';\n\n/** Focuses `[data-autofocus]` inside root, else the active choice, else its first enabled control (a panel opens). */\nexport function focusFirst(root: HTMLElement | null): HTMLElement | null {\n // An element can claim first focus (a calendar's current day); else the active choice, else the first control.\n const el =\n root?.querySelector<HTMLElement>('[data-autofocus]') ??\n root?.querySelector<HTMLElement>(ACTIVE_CHOICE) ??\n root?.querySelector<HTMLElement>(FOCUSABLE);\n el?.focus({ preventScroll: true });\n return el ?? null;\n}\n\nexport interface MoveFocusOptions {\n /** `vertical` (default): ArrowUp / ArrowDown. `horizontal`: ArrowLeft / ArrowRight (flipped in RTL). `both`. */\n orientation?: 'vertical' | 'horizontal' | 'both';\n /** From the last item to the first and back. Default false. */\n loop?: boolean;\n /** ArrowUp (or ArrowLeft) from the first item, when not looping: e.g. back to the field above the list. */\n onExitStart?: () => void;\n}\n\n/**\n * Arrow keys in a list of controls: to the next / previous `selector` inside root; Home / End to the ends once focus is\n * in the list. Disabled items are skipped. Returns the element focused, or null when the key was not handled.\n */\nexport function moveFocus(\n e: ReactKeyboardEvent | KeyboardEvent,\n root: HTMLElement | null,\n selector: string,\n options: MoveFocusOptions | (() => void) = {},\n): HTMLElement | null {\n const {\n orientation = 'vertical',\n loop = false,\n onExitStart,\n } = typeof options === 'function' ? { onExitStart: options } : options;\n const items = root\n ? [...root.querySelectorAll<HTMLElement>(selector)].filter(\n (el) => !el.matches(':disabled, [aria-disabled=\"true\"]'),\n )\n : [];\n if (!items.length) return null;\n const rtl = root ? getComputedStyle(root).direction === 'rtl' : false;\n const vertical = orientation !== 'horizontal';\n const horizontal = orientation !== 'vertical';\n const at = items.indexOf(document.activeElement as HTMLElement);\n let step = 0;\n if (vertical && e.key === 'ArrowDown') step = 1;\n else if (vertical && e.key === 'ArrowUp') step = -1;\n else if (horizontal && e.key === 'ArrowRight') step = rtl ? -1 : 1;\n else if (horizontal && e.key === 'ArrowLeft') step = rtl ? 1 : -1;\n let to: number;\n if (step) to = at + step;\n else if (e.key === 'Home' && at >= 0) to = 0;\n else if (e.key === 'End' && at >= 0) to = items.length - 1;\n else return null;\n e.preventDefault();\n if (to < 0) {\n if (!loop) {\n onExitStart?.();\n return null;\n }\n to = items.length - 1;\n }\n if (to >= items.length) to = loop ? 0 : items.length - 1;\n const next = items[to] ?? null;\n next?.focus();\n return next;\n}\n"],"mappings":";;;AAGA,MAAa,YACX;;AAGF,MAAM,gBACJ;;AAGF,SAAgB,WAAW,MAA8C;CAEvE,MAAM,KACJ,MAAM,cAA2B,kBAAkB,KACnD,MAAM,cAA2B,aAAa,KAC9C,MAAM,cAAA,wIAAoC;CAC5C,IAAI,MAAM,EAAE,eAAe,KAAK,CAAC;CACjC,OAAO,MAAM;AACf;;;;;AAeA,SAAgB,UACd,GACA,MACA,UACA,UAA2C,CAAC,GACxB;CACpB,MAAM,EACJ,cAAc,YACd,OAAO,OACP,gBACE,OAAO,YAAY,aAAa,EAAE,aAAa,QAAQ,IAAI;CAC/D,MAAM,QAAQ,OACV,CAAC,GAAG,KAAK,iBAA8B,QAAQ,CAAC,CAAC,CAAC,QAC/C,OAAO,CAAC,GAAG,QAAQ,qCAAmC,CACzD,IACA,CAAC;CACL,IAAI,CAAC,MAAM,QAAQ,OAAO;CAC1B,MAAM,MAAM,OAAO,iBAAiB,IAAI,CAAC,CAAC,cAAc,QAAQ;CAChE,MAAM,WAAW,gBAAgB;CACjC,MAAM,aAAa,gBAAgB;CACnC,MAAM,KAAK,MAAM,QAAQ,SAAS,aAA4B;CAC9D,IAAI,OAAO;CACX,IAAI,YAAY,EAAE,QAAQ,aAAa,OAAO;MACzC,IAAI,YAAY,EAAE,QAAQ,WAAW,OAAO;MAC5C,IAAI,cAAc,EAAE,QAAQ,cAAc,OAAO,MAAM,KAAK;MAC5D,IAAI,cAAc,EAAE,QAAQ,aAAa,OAAO,MAAM,IAAI;CAC/D,IAAI;CACJ,IAAI,MAAM,KAAK,KAAK;MACf,IAAI,EAAE,QAAQ,UAAU,MAAM,GAAG,KAAK;MACtC,IAAI,EAAE,QAAQ,SAAS,MAAM,GAAG,KAAK,MAAM,SAAS;MACpD,OAAO;CACZ,EAAE,eAAe;CACjB,IAAI,KAAK,GAAG;EACV,IAAI,CAAC,MAAM;GACT,cAAc;GACd,OAAO;EACT;EACA,KAAK,MAAM,SAAS;CACtB;CACA,IAAI,MAAM,MAAM,QAAQ,KAAK,OAAO,IAAI,MAAM,SAAS;CACvD,MAAM,OAAO,MAAM,OAAO;CAC1B,MAAM,MAAM;CACZ,OAAO;AACT"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ import { useForkRef } from "./useForkRef.js";
|
|
|
7
7
|
import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery.js";
|
|
8
8
|
import { RovingFocusOptions, useRovingFocus } from "./useRovingFocus.js";
|
|
9
9
|
import { FindInPage, focusHit, useFindInPage } from "./useFindInPage.js";
|
|
10
|
-
|
|
10
|
+
import { UseClipboardOptions, useClipboard } from "./useClipboard.js";
|
|
11
|
+
import { UseScrollSpyOptions, useScrollSpy } from "./useScrollSpy.js";
|
|
12
|
+
export { COMPACT_QUERY, type ControlledOptions, type DismissOptions, FOCUSABLE, type FindInPage, type MoveFocusOptions, type RovingFocusOptions, type UseClipboardOptions, type UseScrollSpyOptions, focusFirst, focusHit, matchRanges, matchesAll, moveFocus, normalizeText, useClipboard, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useScrollSpy };
|
package/dist/utils/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { FOCUSABLE, focusFirst, moveFocus } from "./focus.js";
|
|
|
5
5
|
import { useRovingFocus } from "./useRovingFocus.js";
|
|
6
6
|
import { useDismiss } from "./useDismiss.js";
|
|
7
7
|
import { matchRanges, matchesAll, normalizeText } from "../lib/layout.js";
|
|
8
|
+
import { useClipboard } from "./useClipboard.js";
|
|
9
|
+
import { useScrollSpy } from "./useScrollSpy.js";
|
|
8
10
|
import { COMPACT_QUERY, useMediaQuery } from "./useMediaQuery.js";
|
|
9
11
|
import { focusHit, useFindInPage } from "./useFindInPage.js";
|
|
10
|
-
export { COMPACT_QUERY, FOCUSABLE, focusFirst, focusHit, matchRanges, matchesAll, moveFocus, normalizeText, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus };
|
|
12
|
+
export { COMPACT_QUERY, FOCUSABLE, focusFirst, focusHit, matchRanges, matchesAll, moveFocus, normalizeText, useClipboard, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useScrollSpy };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
export interface UseClipboardOptions {
|
|
3
|
+
/** ms the `copied` state lasts. Default 2000. */
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Copies text to the clipboard. `copied` is true for `timeout` ms after a copy that succeeded, so the control can say
|
|
8
|
+
* so; `copy` resolves to false when the browser refuses (no permission, insecure page).
|
|
9
|
+
*/
|
|
10
|
+
export declare function useClipboard({ timeout }?: UseClipboardOptions): {
|
|
11
|
+
copy: (text: string) => Promise<boolean>;
|
|
12
|
+
copied: boolean;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useClipboard.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
// src/utils/useClipboard.ts
|
|
4
|
+
/**
|
|
5
|
+
* Copies text to the clipboard. `copied` is true for `timeout` ms after a copy that succeeded, so the control can say
|
|
6
|
+
* so; `copy` resolves to false when the browser refuses (no permission, insecure page).
|
|
7
|
+
*/
|
|
8
|
+
function useClipboard({ timeout = 2e3 } = {}) {
|
|
9
|
+
const [copied, setCopied] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!copied) return;
|
|
12
|
+
const t = setTimeout(() => setCopied(false), timeout);
|
|
13
|
+
return () => clearTimeout(t);
|
|
14
|
+
}, [copied, timeout]);
|
|
15
|
+
return {
|
|
16
|
+
copy: useCallback(async (text) => {
|
|
17
|
+
try {
|
|
18
|
+
await navigator.clipboard.writeText(text);
|
|
19
|
+
setCopied(true);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}, []),
|
|
25
|
+
copied
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { useClipboard };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=useClipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClipboard.js","names":[],"sources":["../../src/utils/useClipboard.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nexport interface UseClipboardOptions {\n /** ms the `copied` state lasts. Default 2000. */\n timeout?: number;\n}\n\n/**\n * Copies text to the clipboard. `copied` is true for `timeout` ms after a copy that succeeded, so the control can say\n * so; `copy` resolves to false when the browser refuses (no permission, insecure page).\n */\nexport function useClipboard({ timeout = 2000 }: UseClipboardOptions = {}) {\n const [copied, setCopied] = useState(false);\n useEffect(() => {\n if (!copied) return;\n const t = setTimeout(() => setCopied(false), timeout);\n return () => clearTimeout(t);\n }, [copied, timeout]);\n const copy = useCallback(async (text: string) => {\n try {\n await navigator.clipboard.writeText(text);\n setCopied(true);\n return true;\n } catch {\n return false;\n }\n }, []);\n return { copy, copied };\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,aAAa,EAAE,UAAU,QAA8B,CAAC,GAAG;CACzE,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;CAC1C,gBAAgB;EACd,IAAI,CAAC,QAAQ;EACb,MAAM,IAAI,iBAAiB,UAAU,KAAK,GAAG,OAAO;EACpD,aAAa,aAAa,CAAC;CAC7B,GAAG,CAAC,QAAQ,OAAO,CAAC;CAUpB,OAAO;EAAE,MATI,YAAY,OAAO,SAAiB;GAC/C,IAAI;IACF,MAAM,UAAU,UAAU,UAAU,IAAI;IACxC,UAAU,IAAI;IACd,OAAO;GACT,QAAQ;IACN,OAAO;GACT;EACF,GAAG,CAAC,CACQ;EAAG;CAAO;AACxB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
export interface UseScrollSpyOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Band of the viewport where a heading counts as "being read", as an IntersectionObserver rootMargin. Default the
|
|
5
|
+
* top 35%: `0px 0px -65% 0px`.
|
|
6
|
+
*/
|
|
7
|
+
rootMargin?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The id, among `ids`, of the section being read: the first of those elements inside the reading band. Stays on the
|
|
11
|
+
* last one seen while you scroll through a long section. `undefined` until one shows (and during SSR).
|
|
12
|
+
*/
|
|
13
|
+
export declare function useScrollSpy(ids: readonly string[], { rootMargin }?: UseScrollSpyOptions): string | undefined;
|
|
14
|
+
//# sourceMappingURL=useScrollSpy.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
// src/utils/useScrollSpy.ts
|
|
4
|
+
/**
|
|
5
|
+
* The id, among `ids`, of the section being read: the first of those elements inside the reading band. Stays on the
|
|
6
|
+
* last one seen while you scroll through a long section. `undefined` until one shows (and during SSR).
|
|
7
|
+
*/
|
|
8
|
+
function useScrollSpy(ids, { rootMargin = "0px 0px -65% 0px" } = {}) {
|
|
9
|
+
const [active, setActive] = useState();
|
|
10
|
+
const key = ids.join("\0");
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (typeof IntersectionObserver === "undefined") return;
|
|
13
|
+
const els = key.split("\0").map((id) => document.getElementById(id)).filter((el) => el !== null);
|
|
14
|
+
const visible = /* @__PURE__ */ new Map();
|
|
15
|
+
const io = new IntersectionObserver((records) => {
|
|
16
|
+
for (const r of records) visible.set(r.target.id, r.isIntersecting);
|
|
17
|
+
const first = els.find((el) => visible.get(el.id));
|
|
18
|
+
if (first) setActive(first.id);
|
|
19
|
+
}, { rootMargin });
|
|
20
|
+
for (const el of els) io.observe(el);
|
|
21
|
+
return () => io.disconnect();
|
|
22
|
+
}, [key, rootMargin]);
|
|
23
|
+
return active;
|
|
24
|
+
}
|
|
25
|
+
export { useScrollSpy };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=useScrollSpy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScrollSpy.js","names":[],"sources":["../../src/utils/useScrollSpy.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface UseScrollSpyOptions {\n /**\n * Band of the viewport where a heading counts as \"being read\", as an IntersectionObserver rootMargin. Default the\n * top 35%: `0px 0px -65% 0px`.\n */\n rootMargin?: string;\n}\n\n/**\n * The id, among `ids`, of the section being read: the first of those elements inside the reading band. Stays on the\n * last one seen while you scroll through a long section. `undefined` until one shows (and during SSR).\n */\nexport function useScrollSpy(\n ids: readonly string[],\n { rootMargin = '0px 0px -65% 0px' }: UseScrollSpyOptions = {},\n): string | undefined {\n const [active, setActive] = useState<string>();\n const key = ids.join('\\u0000');\n useEffect(() => {\n if (typeof IntersectionObserver === 'undefined') return;\n const els = key\n .split('\\u0000')\n .map((id) => document.getElementById(id))\n .filter((el): el is HTMLElement => el !== null);\n const visible = new Map<string, boolean>();\n const io = new IntersectionObserver(\n (records) => {\n for (const r of records) visible.set(r.target.id, r.isIntersecting);\n const first = els.find((el) => visible.get(el.id));\n if (first) setActive(first.id);\n },\n { rootMargin },\n );\n for (const el of els) io.observe(el);\n return () => io.disconnect();\n }, [key, rootMargin]);\n return active;\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,aACd,KACA,EAAE,aAAa,uBAA4C,CAAC,GACxC;CACpB,MAAM,CAAC,QAAQ,aAAa,SAAiB;CAC7C,MAAM,MAAM,IAAI,KAAK,IAAQ;CAC7B,gBAAgB;EACd,IAAI,OAAO,yBAAyB,aAAa;EACjD,MAAM,MAAM,IACT,MAAM,IAAQ,CAAC,CACf,KAAK,OAAO,SAAS,eAAe,EAAE,CAAC,CAAC,CACxC,QAAQ,OAA0B,OAAO,IAAI;EAChD,MAAM,0BAAU,IAAI,IAAqB;EACzC,MAAM,KAAK,IAAI,sBACZ,YAAY;GACX,KAAK,MAAM,KAAK,SAAS,QAAQ,IAAI,EAAE,OAAO,IAAI,EAAE,cAAc;GAClE,MAAM,QAAQ,IAAI,MAAM,OAAO,QAAQ,IAAI,GAAG,EAAE,CAAC;GACjD,IAAI,OAAO,UAAU,MAAM,EAAE;EAC/B,GACA,EAAE,WAAW,CACf;EACA,KAAK,MAAM,MAAM,KAAK,GAAG,QAAQ,EAAE;EACnC,aAAa,GAAG,WAAW;CAC7B,GAAG,CAAC,KAAK,UAAU,CAAC;CACpB,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slurp-ui/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Slurp UI: ready-made React components of the Slurp design system, with optional collapse/expand motion.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
{
|
|
65
65
|
"name": "@slurp-ui/react (everything)",
|
|
66
66
|
"path": "dist/index.js",
|
|
67
|
-
"limit": "
|
|
67
|
+
"limit": "55 kB",
|
|
68
68
|
"gzip": true
|
|
69
69
|
}
|
|
70
70
|
],
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"react-dom": ">=19"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@slurp-ui/icons": "^1.
|
|
76
|
+
"@slurp-ui/icons": "^1.2.0",
|
|
77
77
|
"@slurp-ui/motion": "^1.0.1",
|
|
78
|
-
"@slurp-ui/tokens": "^1.
|
|
78
|
+
"@slurp-ui/tokens": "^1.2.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
"tsdown": "^0.23.1",
|
|
97
97
|
"typescript": "~6.0.3",
|
|
98
98
|
"vitest": "^5.0.5",
|
|
99
|
-
"@slurp-ui/tsconfig": "0.0.0",
|
|
100
99
|
"@slurp-ui/tsdown-config": "0.0.0",
|
|
100
|
+
"@slurp-ui/tsconfig": "0.0.0",
|
|
101
101
|
"@slurp-ui/utils": "0.0.0"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|