@octanejs/base-ui 0.1.16 → 0.1.18
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/package.json +5 -5
- package/src/index.ts +1 -0
- package/src/toast.ts +2462 -0
- package/src/utils/constants.ts +10 -0
- package/src/utils/generateId.ts +10 -0
- package/src/utils/useOnMount.ts +17 -0
package/src/utils/constants.ts
CHANGED
|
@@ -29,3 +29,13 @@ export const TYPEAHEAD_RESET_MS = 500;
|
|
|
29
29
|
* immediately close the popup it just opened).
|
|
30
30
|
*/
|
|
31
31
|
export const PATIENT_CLICK_THRESHOLD = 500;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Opt-out attributes a consumer puts on an element inside a swipeable surface (Toast, Drawer) so a
|
|
35
|
+
* drag starting there does not begin a swipe — e.g. a slider or a scrollable region.
|
|
36
|
+
*/
|
|
37
|
+
export const BASE_UI_SWIPE_IGNORE_ATTRIBUTE = 'data-base-ui-swipe-ignore';
|
|
38
|
+
export const LEGACY_SWIPE_IGNORE_ATTRIBUTE = 'data-swipe-ignore';
|
|
39
|
+
|
|
40
|
+
export const BASE_UI_SWIPE_IGNORE_SELECTOR = `[${BASE_UI_SWIPE_IGNORE_ATTRIBUTE}]`;
|
|
41
|
+
export const LEGACY_SWIPE_IGNORE_SELECTOR = `[${LEGACY_SWIPE_IGNORE_ATTRIBUTE}]`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Ported verbatim from .base-ui/packages/utils/src/generateId.ts (v1.6.0). Pure.
|
|
2
|
+
//
|
|
3
|
+
// A non-`useId` identifier generator: toasts are created imperatively (from `toastManager.add()`,
|
|
4
|
+
// outside any render), so they cannot get an id from a hook.
|
|
5
|
+
let counter = 0;
|
|
6
|
+
|
|
7
|
+
export function generateId(prefix: string): string {
|
|
8
|
+
counter += 1;
|
|
9
|
+
return `${prefix}-${Math.random().toString(36).slice(2, 6)}-${counter}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Ported from .base-ui/packages/utils/src/useOnMount.ts (v1.6.0), octane-adapted (slot-threaded).
|
|
2
|
+
// A `useEffect` that runs once on mount — the dependency array is a shared frozen empty, so the
|
|
3
|
+
// effect never re-runs even if `fn`'s identity changes.
|
|
4
|
+
//
|
|
5
|
+
// SLOT: plain-`.ts` hook; the trailing arg is the caller's slot.
|
|
6
|
+
import { useEffect } from 'octane';
|
|
7
|
+
|
|
8
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
9
|
+
import { EMPTY_ARRAY } from './empty';
|
|
10
|
+
|
|
11
|
+
export function useOnMount(...args: any[]): void {
|
|
12
|
+
const [user, slotArg] = splitSlot(args);
|
|
13
|
+
const slot = slotArg ?? S('useOnMount');
|
|
14
|
+
const fn = user[0] as () => void | (() => void);
|
|
15
|
+
|
|
16
|
+
useEffect(fn, EMPTY_ARRAY, subSlot(slot, 'e'));
|
|
17
|
+
}
|