@impulse-ui-native/popover 0.0.0-stage → 6.3.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/LICENSE +21 -0
- package/README.md +63 -2
- package/dist/components/index.d.mts +19 -0
- package/dist/components/index.js +21 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/popover-close.d.mts +9 -0
- package/dist/components/popover-close.js +38 -0
- package/dist/components/popover-close.js.map +1 -0
- package/dist/components/popover-content.d.mts +9 -0
- package/dist/components/popover-content.js +14 -0
- package/dist/components/popover-content.js.map +1 -0
- package/dist/components/popover-description.d.mts +9 -0
- package/dist/components/popover-description.js +22 -0
- package/dist/components/popover-description.js.map +1 -0
- package/dist/components/popover-root.d.mts +9 -0
- package/dist/components/popover-root.js +38 -0
- package/dist/components/popover-root.js.map +1 -0
- package/dist/components/popover-surface.d.mts +9 -0
- package/dist/components/popover-surface.js +85 -0
- package/dist/components/popover-surface.js.map +1 -0
- package/dist/components/popover-title.d.mts +9 -0
- package/dist/components/popover-title.js +22 -0
- package/dist/components/popover-title.js.map +1 -0
- package/dist/components/popover-trigger.d.mts +9 -0
- package/dist/components/popover-trigger.js +49 -0
- package/dist/components/popover-trigger.js.map +1 -0
- package/dist/components/popover.d.mts +9 -0
- package/dist/components/popover.js +21 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/tooltip.d.mts +9 -0
- package/dist/components/tooltip.js +51 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/constants/popover.constants.d.mts +10 -0
- package/dist/constants/popover.constants.js +14 -0
- package/dist/constants/popover.constants.js.map +1 -0
- package/dist/contexts/popover.context.d.mts +8 -0
- package/dist/contexts/popover.context.js +8 -0
- package/dist/contexts/popover.context.js.map +1 -0
- package/dist/hooks/use-popover-context.hook.d.mts +8 -0
- package/dist/hooks/use-popover-context.hook.js +13 -0
- package/dist/hooks/use-popover-context.hook.js.map +1 -0
- package/dist/hooks/use-popover-position.hook.d.mts +20 -0
- package/dist/hooks/use-popover-position.hook.js +94 -0
- package/dist/hooks/use-popover-position.hook.js.map +1 -0
- package/dist/hooks/use-popover-surface.hook.d.mts +13 -0
- package/dist/hooks/use-popover-surface.hook.js +46 -0
- package/dist/hooks/use-popover-surface.hook.js.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/popover.types.d.mts +73 -0
- package/dist/types/popover.types.js +1 -0
- package/dist/types/popover.types.js.map +1 -0
- package/dist/utils/popover-position.utils.d.mts +11 -0
- package/dist/utils/popover-position.utils.js +102 -0
- package/dist/utils/popover-position.utils.js.map +1 -0
- package/package.json +59 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/tooltip.tsx"],"sourcesContent":["import { memo } from \"react\";\n\nimport {\n useControllableState,\n useEventCallback,\n useTimer,\n} from \"@impulse-ui-native/core\";\n\nimport type { TooltipProps } from \"../types\";\nimport { TooltipDuration } from \"../constants/popover.constants\";\nimport { PopoverContent } from \"./popover-content\";\nimport { PopoverDescription } from \"./popover-description\";\nimport { PopoverRoot } from \"./popover-root\";\nimport { PopoverTrigger } from \"./popover-trigger\";\n\nexport const Tooltip = memo(function Tooltip({\n children,\n content,\n triggerProps,\n open: openProp,\n defaultOpen = false,\n onOpenChange,\n disabled,\n placement = \"top\",\n duration = TooltipDuration,\n ...props\n}: TooltipProps) {\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const dismiss = useEventCallback(() => setOpen(false));\n\n useTimer({ enabled: open && !disabled, duration, callback: dismiss });\n\n return (\n <PopoverRoot\n {...props}\n open={open}\n onOpenChange={setOpen}\n disabled={disabled}\n placement={placement}\n surface=\"inverse\"\n >\n <PopoverTrigger trigger=\"longPress\" {...triggerProps}>\n {children}\n </PopoverTrigger>\n <PopoverContent>\n {typeof content === \"string\" || typeof content === \"number\" ? (\n <PopoverDescription>{content}</PopoverDescription>\n ) : (\n content\n )}\n </PopoverContent>\n </PopoverRoot>\n );\n});\n"],"mappings":"AAsCI,SAQE,KARF;AAtCJ,SAAS,YAAY;AAErB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAExB,MAAM,UAAU,KAAK,SAASA,SAAQ;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAM;AAAA,EACN,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,GAAG;AACL,GAAiB;AACf,QAAM,CAAC,MAAM,OAAO,IAAI,qBAAqB;AAAA,IAC3C,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ,CAAC;AAED,QAAM,UAAU,iBAAiB,MAAM,QAAQ,KAAK,CAAC;AAErD,WAAS,EAAE,SAAS,QAAQ,CAAC,UAAU,UAAU,UAAU,QAAQ,CAAC;AAEpE,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA,SAAQ;AAAA,MAER;AAAA,4BAAC,kBAAe,SAAQ,aAAa,GAAG,cACrC,UACH;AAAA,QACA,oBAAC,kBACE,iBAAO,YAAY,YAAY,OAAO,YAAY,WACjD,oBAAC,sBAAoB,mBAAQ,IAE7B,SAEJ;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["Tooltip"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PopoverPlacement } from '../types/popover.types.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'react-native';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
5
|
+
|
|
6
|
+
declare const AnchorMeasureInterval = 100;
|
|
7
|
+
declare const TooltipDuration = 3000;
|
|
8
|
+
declare const OppositePlacement: Record<PopoverPlacement, PopoverPlacement>;
|
|
9
|
+
|
|
10
|
+
export { AnchorMeasureInterval, OppositePlacement, TooltipDuration };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const AnchorMeasureInterval = 100;
|
|
2
|
+
const TooltipDuration = 3e3;
|
|
3
|
+
const OppositePlacement = {
|
|
4
|
+
top: "bottom",
|
|
5
|
+
bottom: "top",
|
|
6
|
+
left: "right",
|
|
7
|
+
right: "left"
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
AnchorMeasureInterval,
|
|
11
|
+
OppositePlacement,
|
|
12
|
+
TooltipDuration
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=popover.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/popover.constants.ts"],"sourcesContent":["import type { PopoverPlacement } from \"../types\";\n\nexport const AnchorMeasureInterval = 100;\nexport const TooltipDuration = 3000;\nexport const OppositePlacement: Record<PopoverPlacement, PopoverPlacement> = {\n top: \"bottom\",\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n};\n"],"mappings":"AAEO,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,oBAAgE;AAAA,EAC3E,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PopoverContextValue } from '../types/popover.types.mjs';
|
|
3
|
+
import 'react-native';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
5
|
+
|
|
6
|
+
declare const PopoverContext: react.Context<PopoverContextValue | undefined>;
|
|
7
|
+
|
|
8
|
+
export { PopoverContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/contexts/popover.context.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nimport type { PopoverContextValue } from \"../types/popover.types\";\n\nexport const PopoverContext = createContext<PopoverContextValue | undefined>(\n undefined,\n);\n"],"mappings":"AAAA,SAAS,qBAAqB;AAIvB,MAAM,iBAAiB;AAAA,EAC5B;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { PopoverContext } from "../contexts/popover.context";
|
|
3
|
+
function usePopoverContext() {
|
|
4
|
+
const context = useContext(PopoverContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("Popover children must be rendered inside Popover.Root");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
usePopoverContext
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=use-popover-context.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-popover-context.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\n\nimport { PopoverContext } from \"../contexts/popover.context\";\n\nexport function usePopoverContext() {\n const context = useContext(PopoverContext);\n\n if (!context) {\n throw new Error(\"Popover children must be rendered inside Popover.Root\");\n }\n\n return context;\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAE3B,SAAS,sBAAsB;AAExB,SAAS,oBAAoB;AAClC,QAAM,UAAU,WAAW,cAAc;AAEzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { PopoverRect } from '../types/popover.types.mjs';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
5
|
+
|
|
6
|
+
declare function usePopoverPosition(hostRef: RefObject<View | null>): {
|
|
7
|
+
measurement: {
|
|
8
|
+
anchor: PopoverRect;
|
|
9
|
+
host: PopoverRect;
|
|
10
|
+
} | null;
|
|
11
|
+
bounds: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
visible: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { usePopoverPosition };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useWindowDimensions } from "react-native";
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
|
+
import { useComponentsTokens } from "@impulse-ui-native/theme";
|
|
5
|
+
import { AnchorMeasureInterval } from "../constants/popover.constants";
|
|
6
|
+
import { equalRects } from "../utils/popover-position.utils";
|
|
7
|
+
import { usePopoverContext } from "./use-popover-context.hook";
|
|
8
|
+
function usePopoverPosition(hostRef) {
|
|
9
|
+
const { anchorRef } = usePopoverContext();
|
|
10
|
+
const window = useWindowDimensions();
|
|
11
|
+
const insets = useSafeAreaInsets();
|
|
12
|
+
const [measurement, setMeasurement] = useState(null);
|
|
13
|
+
const tokens = useComponentsTokens().popover;
|
|
14
|
+
const bounds = useMemo(() => {
|
|
15
|
+
const host = measurement?.host;
|
|
16
|
+
const x = Math.max(host?.x ?? 0, insets.left) + tokens.edgeOffset;
|
|
17
|
+
const y = Math.max(host?.y ?? 0, insets.top) + tokens.edgeOffset;
|
|
18
|
+
const right = Math.min(
|
|
19
|
+
host ? host.x + host.width : window.width,
|
|
20
|
+
window.width - insets.right
|
|
21
|
+
) - tokens.edgeOffset;
|
|
22
|
+
const bottom = Math.min(
|
|
23
|
+
host ? host.y + host.height : window.height,
|
|
24
|
+
window.height - insets.bottom
|
|
25
|
+
) - tokens.edgeOffset;
|
|
26
|
+
return {
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
width: Math.max(0, right - x),
|
|
30
|
+
height: Math.max(0, bottom - y)
|
|
31
|
+
};
|
|
32
|
+
}, [
|
|
33
|
+
measurement?.host,
|
|
34
|
+
insets,
|
|
35
|
+
window.width,
|
|
36
|
+
window.height,
|
|
37
|
+
tokens.edgeOffset
|
|
38
|
+
]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
let active = true;
|
|
41
|
+
let measuring = false;
|
|
42
|
+
const measure = () => {
|
|
43
|
+
const anchorNode = anchorRef.current;
|
|
44
|
+
const hostNode = hostRef.current;
|
|
45
|
+
if (!anchorNode || !hostNode) {
|
|
46
|
+
setMeasurement(null);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (measuring) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
measuring = true;
|
|
53
|
+
hostNode.measureInWindow((x, y, width, height) => {
|
|
54
|
+
if (!active) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const host = { x, y, width, height };
|
|
58
|
+
anchorNode.measureInWindow((ax, ay, aw, ah) => {
|
|
59
|
+
measuring = false;
|
|
60
|
+
if (!active || anchorRef.current !== anchorNode || hostRef.current !== hostNode) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const anchor2 = { x: ax, y: ay, width: aw, height: ah };
|
|
64
|
+
setMeasurement((previous) => {
|
|
65
|
+
const sameAnchor = equalRects(previous?.anchor ?? null, anchor2);
|
|
66
|
+
const sameHost = equalRects(previous?.host ?? null, host);
|
|
67
|
+
if (sameAnchor && sameHost) {
|
|
68
|
+
return previous;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
anchor: anchor2,
|
|
72
|
+
host: sameHost && previous ? previous.host : host
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
measure();
|
|
79
|
+
const timer = setInterval(measure, AnchorMeasureInterval);
|
|
80
|
+
return () => {
|
|
81
|
+
active = false;
|
|
82
|
+
clearInterval(timer);
|
|
83
|
+
};
|
|
84
|
+
}, [anchorRef, hostRef, window.width, window.height]);
|
|
85
|
+
const anchor = measurement?.anchor;
|
|
86
|
+
const visible = Boolean(
|
|
87
|
+
anchor && anchor.width > 0 && anchor.height > 0 && bounds.width > 0 && bounds.height > 0 && anchor.x + anchor.width > bounds.x && anchor.x < bounds.x + bounds.width && anchor.y + anchor.height > bounds.y && anchor.y < bounds.y + bounds.height
|
|
88
|
+
);
|
|
89
|
+
return { measurement, bounds, visible };
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
usePopoverPosition
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=use-popover-position.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-popover-position.hook.ts"],"sourcesContent":["import type { RefObject } from \"react\";\nimport type { View } from \"react-native\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useWindowDimensions } from \"react-native\";\nimport { useSafeAreaInsets } from \"react-native-safe-area-context\";\n\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\n\nimport type { PopoverRect } from \"../types/popover.types\";\nimport { AnchorMeasureInterval } from \"../constants/popover.constants\";\nimport { equalRects } from \"../utils/popover-position.utils\";\nimport { usePopoverContext } from \"./use-popover-context.hook\";\n\nexport function usePopoverPosition(hostRef: RefObject<View | null>) {\n const { anchorRef } = usePopoverContext();\n const window = useWindowDimensions();\n const insets = useSafeAreaInsets();\n\n const [measurement, setMeasurement] = useState<{\n anchor: PopoverRect;\n host: PopoverRect;\n } | null>(null);\n\n const tokens = useComponentsTokens().popover;\n\n const bounds = useMemo(() => {\n const host = measurement?.host;\n const x = Math.max(host?.x ?? 0, insets.left) + tokens.edgeOffset;\n const y = Math.max(host?.y ?? 0, insets.top) + tokens.edgeOffset;\n const right =\n Math.min(\n host ? host.x + host.width : window.width,\n window.width - insets.right,\n ) - tokens.edgeOffset;\n const bottom =\n Math.min(\n host ? host.y + host.height : window.height,\n window.height - insets.bottom,\n ) - tokens.edgeOffset;\n\n return {\n x,\n y,\n width: Math.max(0, right - x),\n height: Math.max(0, bottom - y),\n };\n }, [\n measurement?.host,\n insets,\n window.width,\n window.height,\n tokens.edgeOffset,\n ]);\n\n useEffect(() => {\n let active = true;\n let measuring = false;\n\n const measure = () => {\n const anchorNode = anchorRef.current;\n const hostNode = hostRef.current;\n\n if (!anchorNode || !hostNode) {\n setMeasurement(null);\n\n return;\n }\n\n if (measuring) {\n return;\n }\n\n measuring = true;\n\n hostNode.measureInWindow((x, y, width, height) => {\n if (!active) {\n return;\n }\n\n const host = { x, y, width, height };\n\n anchorNode.measureInWindow((ax, ay, aw, ah) => {\n measuring = false;\n\n if (\n !active ||\n anchorRef.current !== anchorNode ||\n hostRef.current !== hostNode\n ) {\n return;\n }\n\n const anchor = { x: ax, y: ay, width: aw, height: ah };\n\n setMeasurement((previous) => {\n const sameAnchor = equalRects(previous?.anchor ?? null, anchor);\n const sameHost = equalRects(previous?.host ?? null, host);\n\n if (sameAnchor && sameHost) {\n return previous;\n }\n\n return {\n anchor,\n host: sameHost && previous ? previous.host : host,\n };\n });\n });\n });\n };\n\n measure();\n\n const timer = setInterval(measure, AnchorMeasureInterval);\n\n return () => {\n active = false;\n clearInterval(timer);\n };\n }, [anchorRef, hostRef, window.width, window.height]);\n\n const anchor = measurement?.anchor;\n\n const visible = Boolean(\n anchor &&\n anchor.width > 0 &&\n anchor.height > 0 &&\n bounds.width > 0 &&\n bounds.height > 0 &&\n anchor.x + anchor.width > bounds.x &&\n anchor.x < bounds.x + bounds.width &&\n anchor.y + anchor.height > bounds.y &&\n anchor.y < bounds.y + bounds.height,\n );\n\n return { measurement, bounds, visible };\n}\n"],"mappings":"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","names":["anchor"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { View, LayoutChangeEvent } from 'react-native';
|
|
3
|
+
import { PopoverContentProps, PopoverSurfaceStyleProps } from '../types/popover.types.mjs';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
5
|
+
|
|
6
|
+
declare function usePopoverSurface(onLayout: PopoverContentProps["onLayout"]): {
|
|
7
|
+
hostRef: react.RefObject<View | null>;
|
|
8
|
+
styleProps: PopoverSurfaceStyleProps;
|
|
9
|
+
close: () => void;
|
|
10
|
+
handleLayout: (event: LayoutChangeEvent) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { usePopoverSurface };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useBackHandler, useEventCallback } from "@impulse-ui-native/core";
|
|
3
|
+
import { useComponentsTokens } from "@impulse-ui-native/theme";
|
|
4
|
+
import { getPopoverPosition } from "../utils/popover-position.utils";
|
|
5
|
+
import { usePopoverContext } from "./use-popover-context.hook";
|
|
6
|
+
import { usePopoverPosition } from "./use-popover-position.hook";
|
|
7
|
+
function usePopoverSurface(onLayout) {
|
|
8
|
+
const { surface, placement, setOpen } = usePopoverContext();
|
|
9
|
+
const [size, setSize] = useState({ width: 0, height: 0 });
|
|
10
|
+
const hostRef = useRef(null);
|
|
11
|
+
const tokens = useComponentsTokens().popover;
|
|
12
|
+
const { measurement, bounds, visible } = usePopoverPosition(hostRef);
|
|
13
|
+
const position = useMemo(
|
|
14
|
+
() => measurement ? getPopoverPosition({
|
|
15
|
+
anchor: measurement.anchor,
|
|
16
|
+
bounds,
|
|
17
|
+
...size,
|
|
18
|
+
placement,
|
|
19
|
+
gap: tokens.gap,
|
|
20
|
+
arrowInset: tokens.surfaces[surface].borderRadius + tokens.arrowSize
|
|
21
|
+
}) : null,
|
|
22
|
+
[measurement, bounds, size, placement, surface, tokens]
|
|
23
|
+
);
|
|
24
|
+
const ready = visible && size.width > 0 && size.height > 0;
|
|
25
|
+
const styleProps = useMemo(
|
|
26
|
+
() => ({ surface, bounds, host: measurement?.host, position, ready }),
|
|
27
|
+
[surface, bounds, measurement?.host, position, ready]
|
|
28
|
+
);
|
|
29
|
+
const close = useEventCallback(() => setOpen(false));
|
|
30
|
+
const handleLayout = useEventCallback((event) => {
|
|
31
|
+
const { width, height } = event.nativeEvent.layout;
|
|
32
|
+
setSize(
|
|
33
|
+
(previous) => previous.width === width && previous.height === height ? previous : { width, height }
|
|
34
|
+
);
|
|
35
|
+
onLayout?.(event);
|
|
36
|
+
});
|
|
37
|
+
useBackHandler(() => {
|
|
38
|
+
close();
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
return { hostRef, styleProps, close, handleLayout };
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
usePopoverSurface
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=use-popover-surface.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-popover-surface.hook.ts"],"sourcesContent":["import type { LayoutChangeEvent, View } from \"react-native\";\nimport { useMemo, useRef, useState } from \"react\";\n\nimport { useBackHandler, useEventCallback } from \"@impulse-ui-native/core\";\nimport { useComponentsTokens } from \"@impulse-ui-native/theme\";\n\nimport type { PopoverContentProps } from \"../types\";\nimport type { PopoverSurfaceStyleProps } from \"../types/popover.types\";\nimport { getPopoverPosition } from \"../utils/popover-position.utils\";\nimport { usePopoverContext } from \"./use-popover-context.hook\";\nimport { usePopoverPosition } from \"./use-popover-position.hook\";\n\nexport function usePopoverSurface(onLayout: PopoverContentProps[\"onLayout\"]) {\n const { surface, placement, setOpen } = usePopoverContext();\n\n const [size, setSize] = useState({ width: 0, height: 0 });\n const hostRef = useRef<View>(null);\n\n const tokens = useComponentsTokens().popover;\n const { measurement, bounds, visible } = usePopoverPosition(hostRef);\n\n const position = useMemo(\n () =>\n measurement\n ? getPopoverPosition({\n anchor: measurement.anchor,\n bounds,\n ...size,\n placement,\n gap: tokens.gap,\n arrowInset:\n tokens.surfaces[surface].borderRadius + tokens.arrowSize,\n })\n : null,\n [measurement, bounds, size, placement, surface, tokens],\n );\n\n const ready = visible && size.width > 0 && size.height > 0;\n const styleProps = useMemo<PopoverSurfaceStyleProps>(\n () => ({ surface, bounds, host: measurement?.host, position, ready }),\n [surface, bounds, measurement?.host, position, ready],\n );\n\n const close = useEventCallback(() => setOpen(false));\n\n const handleLayout = useEventCallback((event: LayoutChangeEvent) => {\n const { width, height } = event.nativeEvent.layout;\n\n setSize((previous) =>\n previous.width === width && previous.height === height\n ? previous\n : { width, height },\n );\n\n onLayout?.(event);\n });\n\n useBackHandler(() => {\n close();\n\n return true;\n });\n\n return { hostRef, styleProps, close, handleLayout };\n}\n"],"mappings":"AACA,SAAS,SAAS,QAAQ,gBAAgB;AAE1C,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,2BAA2B;AAIpC,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAE5B,SAAS,kBAAkB,UAA2C;AAC3E,QAAM,EAAE,SAAS,WAAW,QAAQ,IAAI,kBAAkB;AAE1D,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,EAAE,OAAO,GAAG,QAAQ,EAAE,CAAC;AACxD,QAAM,UAAU,OAAa,IAAI;AAEjC,QAAM,SAAS,oBAAoB,EAAE;AACrC,QAAM,EAAE,aAAa,QAAQ,QAAQ,IAAI,mBAAmB,OAAO;AAEnE,QAAM,WAAW;AAAA,IACf,MACE,cACI,mBAAmB;AAAA,MACjB,QAAQ,YAAY;AAAA,MACpB;AAAA,MACA,GAAG;AAAA,MACH;AAAA,MACA,KAAK,OAAO;AAAA,MACZ,YACE,OAAO,SAAS,OAAO,EAAE,eAAe,OAAO;AAAA,IACnD,CAAC,IACD;AAAA,IACN,CAAC,aAAa,QAAQ,MAAM,WAAW,SAAS,MAAM;AAAA,EACxD;AAEA,QAAM,QAAQ,WAAW,KAAK,QAAQ,KAAK,KAAK,SAAS;AACzD,QAAM,aAAa;AAAA,IACjB,OAAO,EAAE,SAAS,QAAQ,MAAM,aAAa,MAAM,UAAU,MAAM;AAAA,IACnE,CAAC,SAAS,QAAQ,aAAa,MAAM,UAAU,KAAK;AAAA,EACtD;AAEA,QAAM,QAAQ,iBAAiB,MAAM,QAAQ,KAAK,CAAC;AAEnD,QAAM,eAAe,iBAAiB,CAAC,UAA6B;AAClE,UAAM,EAAE,OAAO,OAAO,IAAI,MAAM,YAAY;AAE5C;AAAA,MAAQ,CAAC,aACP,SAAS,UAAU,SAAS,SAAS,WAAW,SAC5C,WACA,EAAE,OAAO,OAAO;AAAA,IACtB;AAEA,eAAW,KAAK;AAAA,EAClB,CAAC;AAED,iBAAe,MAAM;AACnB,UAAM;AAEN,WAAO;AAAA,EACT,CAAC;AAED,SAAO,EAAE,SAAS,YAAY,OAAO,aAAa;AACpD;","names":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Popover } from './components/index.mjs';
|
|
2
|
+
export { PopoverCloseProps, PopoverContentProps, PopoverDescriptionProps, PopoverPlacement, PopoverProps, PopoverRootProps, PopoverSurface, PopoverTitleProps, PopoverTriggerProps, TooltipProps } from './types/popover.types.mjs';
|
|
3
|
+
export { Tooltip } from './components/tooltip.mjs';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
6
|
+
import 'react-native';
|
|
7
|
+
import '@impulse-ui-native/primitives';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./types\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PopoverCloseProps, PopoverContentProps, PopoverDescriptionProps, PopoverPlacement, PopoverProps, PopoverRootProps, PopoverSurface, PopoverTitleProps, PopoverTriggerProps, TooltipProps } from './popover.types.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'react-native';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { PressableCoreProps, ViewProps, TextProps } from '@impulse-ui-native/primitives';
|
|
4
|
+
|
|
5
|
+
type PopoverPlacement = "top" | "bottom" | "left" | "right";
|
|
6
|
+
type PopoverSurface = "elevated" | "inverse";
|
|
7
|
+
interface PopoverRootProps extends PropsWithChildren {
|
|
8
|
+
open?: boolean;
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
onOpenChange?: (open: boolean) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
placement?: PopoverPlacement;
|
|
13
|
+
surface?: PopoverSurface;
|
|
14
|
+
portalName?: string;
|
|
15
|
+
}
|
|
16
|
+
interface PopoverTriggerProps extends Omit<PressableCoreProps, "children">, PropsWithChildren {
|
|
17
|
+
trigger?: "press" | "longPress";
|
|
18
|
+
}
|
|
19
|
+
type PopoverContentProps = ViewProps;
|
|
20
|
+
type PopoverTitleProps = TextProps;
|
|
21
|
+
type PopoverDescriptionProps = TextProps;
|
|
22
|
+
type PopoverCloseProps = Omit<PressableCoreProps, "children"> & PropsWithChildren;
|
|
23
|
+
interface PopoverProps extends PopoverRootProps {
|
|
24
|
+
trigger: ReactNode;
|
|
25
|
+
triggerProps?: PopoverTriggerProps;
|
|
26
|
+
contentProps?: PopoverContentProps;
|
|
27
|
+
}
|
|
28
|
+
interface TooltipProps extends Omit<PopoverRootProps, "surface"> {
|
|
29
|
+
content: ReactNode;
|
|
30
|
+
triggerProps?: PopoverTriggerProps;
|
|
31
|
+
/** Milliseconds before dismissal. Zero keeps the hint open. */
|
|
32
|
+
duration?: number;
|
|
33
|
+
}
|
|
34
|
+
interface PopoverContextValue {
|
|
35
|
+
open: boolean;
|
|
36
|
+
disabled: boolean;
|
|
37
|
+
setOpen: (open: boolean) => void;
|
|
38
|
+
anchorRef: RefObject<View | null>;
|
|
39
|
+
placement: PopoverPlacement;
|
|
40
|
+
surface: PopoverSurface;
|
|
41
|
+
portalName?: string;
|
|
42
|
+
}
|
|
43
|
+
interface PopoverRect {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
}
|
|
49
|
+
interface PopoverPosition {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
placement: PopoverPlacement;
|
|
53
|
+
arrowOffset: number;
|
|
54
|
+
showArrow: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface PopoverPositionOptions {
|
|
57
|
+
anchor: PopoverRect;
|
|
58
|
+
bounds: PopoverRect;
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
placement: PopoverPlacement;
|
|
62
|
+
gap: number;
|
|
63
|
+
arrowInset: number;
|
|
64
|
+
}
|
|
65
|
+
interface PopoverSurfaceStyleProps {
|
|
66
|
+
surface: PopoverSurface;
|
|
67
|
+
bounds: PopoverRect;
|
|
68
|
+
host?: PopoverRect;
|
|
69
|
+
position: PopoverPosition | null;
|
|
70
|
+
ready: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type { PopoverCloseProps, PopoverContentProps, PopoverContextValue, PopoverDescriptionProps, PopoverPlacement, PopoverPosition, PopoverPositionOptions, PopoverProps, PopoverRect, PopoverRootProps, PopoverSurface, PopoverSurfaceStyleProps, PopoverTitleProps, PopoverTriggerProps, TooltipProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=popover.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
|
+
import { PopoverRect, PopoverPosition, PopoverPositionOptions } from '../types/popover.types.mjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '@impulse-ui-native/primitives';
|
|
5
|
+
|
|
6
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
7
|
+
declare function equalRects(a: PopoverRect | null, b: PopoverRect): boolean;
|
|
8
|
+
declare function getPopoverPosition({ anchor, bounds, width, height, placement: preferred, gap, arrowInset, }: PopoverPositionOptions): PopoverPosition;
|
|
9
|
+
declare function getArrowStyle(position: PopoverPosition, size: number, color: string, borderWidth: number, borderColor: string): ViewStyle;
|
|
10
|
+
|
|
11
|
+
export { clamp, equalRects, getArrowStyle, getPopoverPosition };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { OppositePlacement } from "../constants/popover.constants";
|
|
2
|
+
function clamp(value, min, max) {
|
|
3
|
+
return Math.min(Math.max(value, min), Math.max(min, max));
|
|
4
|
+
}
|
|
5
|
+
function equalRects(a, b) {
|
|
6
|
+
return a !== null && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
7
|
+
}
|
|
8
|
+
function getPopoverPosition({
|
|
9
|
+
anchor,
|
|
10
|
+
bounds,
|
|
11
|
+
width,
|
|
12
|
+
height,
|
|
13
|
+
placement: preferred,
|
|
14
|
+
gap,
|
|
15
|
+
arrowInset
|
|
16
|
+
}) {
|
|
17
|
+
const right = bounds.x + bounds.width;
|
|
18
|
+
const bottom = bounds.y + bounds.height;
|
|
19
|
+
const available = {
|
|
20
|
+
top: anchor.y - bounds.y - gap,
|
|
21
|
+
bottom: bottom - anchor.y - anchor.height - gap,
|
|
22
|
+
left: anchor.x - bounds.x - gap,
|
|
23
|
+
right: right - anchor.x - anchor.width - gap
|
|
24
|
+
};
|
|
25
|
+
const vertical = preferred === "top" || preferred === "bottom";
|
|
26
|
+
const extent = vertical ? height : width;
|
|
27
|
+
const opposite = OppositePlacement[preferred];
|
|
28
|
+
const placement = available[preferred] < extent && available[opposite] > available[preferred] ? opposite : preferred;
|
|
29
|
+
const centerX = anchor.x + anchor.width / 2;
|
|
30
|
+
const centerY = anchor.y + anchor.height / 2;
|
|
31
|
+
const x = clamp(
|
|
32
|
+
vertical ? centerX - width / 2 : placement === "left" ? anchor.x - width - gap : anchor.x + anchor.width + gap,
|
|
33
|
+
bounds.x,
|
|
34
|
+
right - width
|
|
35
|
+
);
|
|
36
|
+
const y = clamp(
|
|
37
|
+
vertical ? placement === "top" ? anchor.y - height - gap : anchor.y + anchor.height + gap : centerY - height / 2,
|
|
38
|
+
bounds.y,
|
|
39
|
+
bottom - height
|
|
40
|
+
);
|
|
41
|
+
const edgeLength = vertical ? width : height;
|
|
42
|
+
const inset = Math.min(arrowInset, edgeLength / 2);
|
|
43
|
+
const offset = vertical ? centerX - x : centerY - y;
|
|
44
|
+
const facing = placement === "top" ? y + height <= anchor.y : placement === "bottom" ? y >= anchor.y + anchor.height : placement === "left" ? x + width <= anchor.x : x >= anchor.x + anchor.width;
|
|
45
|
+
return {
|
|
46
|
+
x,
|
|
47
|
+
y,
|
|
48
|
+
placement,
|
|
49
|
+
arrowOffset: clamp(offset, inset, edgeLength - inset),
|
|
50
|
+
showArrow: facing && offset >= inset && offset <= edgeLength - inset
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function getArrowStyle(position, size, color, borderWidth, borderColor) {
|
|
54
|
+
const side = size * Math.SQRT2;
|
|
55
|
+
const offset = position.arrowOffset - borderWidth - side / 2;
|
|
56
|
+
const edge = -(side + borderWidth) / 2;
|
|
57
|
+
const shared = {
|
|
58
|
+
width: side,
|
|
59
|
+
height: side,
|
|
60
|
+
backgroundColor: color,
|
|
61
|
+
borderColor,
|
|
62
|
+
transform: [{ rotate: "45deg" }],
|
|
63
|
+
...position.placement === "top" || position.placement === "bottom" ? { left: offset } : { top: offset }
|
|
64
|
+
};
|
|
65
|
+
switch (position.placement) {
|
|
66
|
+
case "top":
|
|
67
|
+
return {
|
|
68
|
+
...shared,
|
|
69
|
+
bottom: edge,
|
|
70
|
+
borderBottomWidth: borderWidth,
|
|
71
|
+
borderRightWidth: borderWidth
|
|
72
|
+
};
|
|
73
|
+
case "bottom":
|
|
74
|
+
return {
|
|
75
|
+
...shared,
|
|
76
|
+
top: edge,
|
|
77
|
+
borderTopWidth: borderWidth,
|
|
78
|
+
borderLeftWidth: borderWidth
|
|
79
|
+
};
|
|
80
|
+
case "left":
|
|
81
|
+
return {
|
|
82
|
+
...shared,
|
|
83
|
+
right: edge,
|
|
84
|
+
borderTopWidth: borderWidth,
|
|
85
|
+
borderRightWidth: borderWidth
|
|
86
|
+
};
|
|
87
|
+
case "right":
|
|
88
|
+
return {
|
|
89
|
+
...shared,
|
|
90
|
+
left: edge,
|
|
91
|
+
borderBottomWidth: borderWidth,
|
|
92
|
+
borderLeftWidth: borderWidth
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
clamp,
|
|
98
|
+
equalRects,
|
|
99
|
+
getArrowStyle,
|
|
100
|
+
getPopoverPosition
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=popover-position.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/popover-position.utils.ts"],"sourcesContent":["import type { ViewStyle } from \"react-native\";\n\nimport type {\n PopoverPlacement,\n PopoverPosition,\n PopoverPositionOptions,\n PopoverRect,\n} from \"../types/popover.types\";\nimport { OppositePlacement } from \"../constants/popover.constants\";\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), Math.max(min, max));\n}\n\nexport function equalRects(a: PopoverRect | null, b: PopoverRect): boolean {\n return (\n a !== null &&\n a.x === b.x &&\n a.y === b.y &&\n a.width === b.width &&\n a.height === b.height\n );\n}\n\nexport function getPopoverPosition({\n anchor,\n bounds,\n width,\n height,\n placement: preferred,\n gap,\n arrowInset,\n}: PopoverPositionOptions): PopoverPosition {\n const right = bounds.x + bounds.width;\n const bottom = bounds.y + bounds.height;\n\n const available: Record<PopoverPlacement, number> = {\n top: anchor.y - bounds.y - gap,\n bottom: bottom - anchor.y - anchor.height - gap,\n left: anchor.x - bounds.x - gap,\n right: right - anchor.x - anchor.width - gap,\n };\n\n const vertical = preferred === \"top\" || preferred === \"bottom\";\n const extent = vertical ? height : width;\n const opposite = OppositePlacement[preferred];\n const placement =\n available[preferred] < extent && available[opposite] > available[preferred]\n ? opposite\n : preferred;\n\n const centerX = anchor.x + anchor.width / 2;\n const centerY = anchor.y + anchor.height / 2;\n const x = clamp(\n vertical\n ? centerX - width / 2\n : placement === \"left\"\n ? anchor.x - width - gap\n : anchor.x + anchor.width + gap,\n bounds.x,\n right - width,\n );\n const y = clamp(\n vertical\n ? placement === \"top\"\n ? anchor.y - height - gap\n : anchor.y + anchor.height + gap\n : centerY - height / 2,\n bounds.y,\n bottom - height,\n );\n\n const edgeLength = vertical ? width : height;\n const inset = Math.min(arrowInset, edgeLength / 2);\n const offset = vertical ? centerX - x : centerY - y;\n const facing =\n placement === \"top\"\n ? y + height <= anchor.y\n : placement === \"bottom\"\n ? y >= anchor.y + anchor.height\n : placement === \"left\"\n ? x + width <= anchor.x\n : x >= anchor.x + anchor.width;\n\n return {\n x,\n y,\n placement,\n arrowOffset: clamp(offset, inset, edgeLength - inset),\n showArrow: facing && offset >= inset && offset <= edgeLength - inset,\n };\n}\n\nexport function getArrowStyle(\n position: PopoverPosition,\n size: number,\n color: string,\n borderWidth: number,\n borderColor: string,\n): ViewStyle {\n const side = size * Math.SQRT2;\n const offset = position.arrowOffset - borderWidth - side / 2;\n const edge = -(side + borderWidth) / 2;\n\n // The inner half covers the panel's border; only the outward edges are outlined.\n const shared: ViewStyle = {\n width: side,\n height: side,\n backgroundColor: color,\n borderColor,\n transform: [{ rotate: \"45deg\" }],\n ...(position.placement === \"top\" || position.placement === \"bottom\"\n ? { left: offset }\n : { top: offset }),\n };\n\n switch (position.placement) {\n case \"top\":\n return {\n ...shared,\n bottom: edge,\n borderBottomWidth: borderWidth,\n borderRightWidth: borderWidth,\n };\n\n case \"bottom\":\n return {\n ...shared,\n top: edge,\n borderTopWidth: borderWidth,\n borderLeftWidth: borderWidth,\n };\n\n case \"left\":\n return {\n ...shared,\n right: edge,\n borderTopWidth: borderWidth,\n borderRightWidth: borderWidth,\n };\n\n case \"right\":\n return {\n ...shared,\n left: edge,\n borderBottomWidth: borderWidth,\n borderLeftWidth: borderWidth,\n };\n }\n}\n"],"mappings":"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","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@impulse-ui-native/popover",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "6.3.0",
|
|
4
|
+
"description": "Portal-rendered tooltips and compound anchored popovers for ImpulseUI Native.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"popover",
|
|
8
|
+
"tooltip",
|
|
9
|
+
"components"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"source": "src/index.ts",
|
|
13
|
+
"module": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.mts",
|
|
15
|
+
"react-native": "src/index.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"react-native": "./src/index.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@impulse-ui-native/core": "6.3.0",
|
|
31
|
+
"@impulse-ui-native/primitives": "6.3.0",
|
|
32
|
+
"@impulse-ui-native/portal": "6.3.0",
|
|
33
|
+
"@impulse-ui-native/theme": "6.3.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "~19.2.14",
|
|
37
|
+
"eslint": "^9.38.0",
|
|
38
|
+
"prettier": "^3.6.2",
|
|
39
|
+
"react": "19.2.3",
|
|
40
|
+
"react-native": "0.86.2",
|
|
41
|
+
"react-native-safe-area-context": "~5.7.0",
|
|
42
|
+
"typescript": "~6.0.3",
|
|
43
|
+
"@impulse-ui-native/eslint-config": "1.0.0",
|
|
44
|
+
"@impulse-ui-native/prettier-config": "1.0.0",
|
|
45
|
+
"@impulse-ui-native/tsconfig": "1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": ">=18",
|
|
49
|
+
"react-native": ">=0.73",
|
|
50
|
+
"react-native-safe-area-context": ">=5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"prettier": "@impulse-ui-native/prettier-config",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup --config tsup.config.ts",
|
|
58
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
59
|
+
"lint": "pnpm exec eslint . --fix",
|
|
60
|
+
"format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md}\" --ignore-path ../../.prettierignore"
|
|
61
|
+
}
|
|
6
62
|
}
|