@lotics/ui 1.3.0 → 1.4.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/package.json +2 -1
- package/src/dom_portal.ts +20 -0
- package/src/dom_portal.web.ts +8 -0
- package/src/icon_button.tsx +5 -0
- package/src/info_popover.tsx +49 -0
- package/src/portal.tsx +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lotics/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./tokens": "./src/tokens.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"./menu_list_item": "./src/menu_list_item.tsx",
|
|
31
31
|
"./pressable_highlight": "./src/pressable_highlight.tsx",
|
|
32
32
|
"./icon_button": "./src/icon_button.tsx",
|
|
33
|
+
"./info_popover": "./src/info_popover.tsx",
|
|
33
34
|
"./badge": "./src/badge.tsx",
|
|
34
35
|
"./divider": "./src/divider.tsx",
|
|
35
36
|
"./spacer": "./src/spacer.tsx",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode, ReactPortal } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Native stand-in for `react-dom`'s `createPortal`.
|
|
5
|
+
*
|
|
6
|
+
* `Portal` only calls `createPortal` inside its web (`isWeb`) branch, so on
|
|
7
|
+
* React Native this is never invoked. The file exists purely so the shared
|
|
8
|
+
* `portal.tsx` can `import { createPortal }` statically without pulling
|
|
9
|
+
* `react-dom` — which has no native build — into the Metro native bundle.
|
|
10
|
+
*
|
|
11
|
+
* Web targets resolve `dom_portal.web.ts` instead (Metro's `.web` extension
|
|
12
|
+
* resolution; Vite's `resolve.extensions`).
|
|
13
|
+
*/
|
|
14
|
+
export function createPortal(
|
|
15
|
+
_children: ReactNode,
|
|
16
|
+
_container: Element | DocumentFragment,
|
|
17
|
+
_key?: string | null,
|
|
18
|
+
): ReactPortal | null {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web variant: the real `react-dom` portal. Isolated into its own module so
|
|
3
|
+
* the native bundle (which resolves `dom_portal.ts`) never references
|
|
4
|
+
* `react-dom`. Imported statically by `portal.tsx` — no `require`, so it
|
|
5
|
+
* works under pure-ESM bundlers (Vite, used by custom-code apps) as well as
|
|
6
|
+
* Metro.
|
|
7
|
+
*/
|
|
8
|
+
export { createPortal } from "react-dom";
|
package/src/icon_button.tsx
CHANGED
|
@@ -13,6 +13,8 @@ export interface IconButtonProps {
|
|
|
13
13
|
iconColor?: string;
|
|
14
14
|
tooltip?: string;
|
|
15
15
|
tooltipSide?: TooltipSide;
|
|
16
|
+
/** Accessible name for the button. Falls back to `tooltip` when omitted. */
|
|
17
|
+
accessibilityLabel?: string;
|
|
16
18
|
onPress?: (event: GestureResponderEvent) => void;
|
|
17
19
|
style?: StyleProp<ViewStyle>;
|
|
18
20
|
disabled?: boolean;
|
|
@@ -28,6 +30,7 @@ export function IconButton(props: IconButtonProps) {
|
|
|
28
30
|
color = "none",
|
|
29
31
|
tooltip,
|
|
30
32
|
tooltipSide,
|
|
33
|
+
accessibilityLabel,
|
|
31
34
|
disabled,
|
|
32
35
|
style,
|
|
33
36
|
} = props;
|
|
@@ -45,6 +48,8 @@ export function IconButton(props: IconButtonProps) {
|
|
|
45
48
|
testID={testID}
|
|
46
49
|
tooltip={tooltip}
|
|
47
50
|
tooltipSide={tooltipSide}
|
|
51
|
+
accessibilityRole="button"
|
|
52
|
+
accessibilityLabel={accessibilityLabel ?? tooltip}
|
|
48
53
|
style={[styles.button, styles[color], disabled && styles.disabled, style]}
|
|
49
54
|
onPress={handlePress}
|
|
50
55
|
disabled={disabled}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { Popover, PopoverTrigger, PopoverContent } from "./popover";
|
|
3
|
+
import type { PopoverSide, PopoverAlign } from "./popover";
|
|
4
|
+
import { IconButton } from "./icon_button";
|
|
5
|
+
import { Text } from "./text";
|
|
6
|
+
import { colors } from "./colors";
|
|
7
|
+
|
|
8
|
+
export interface InfoPopoverProps {
|
|
9
|
+
/** Explanatory text shown when the popover opens. */
|
|
10
|
+
text: string;
|
|
11
|
+
/** Accessible name for the trigger button. */
|
|
12
|
+
accessibilityLabel?: string;
|
|
13
|
+
/** Popover placement relative to the trigger. */
|
|
14
|
+
side?: PopoverSide;
|
|
15
|
+
/** Popover alignment along the trigger edge. */
|
|
16
|
+
align?: PopoverAlign;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A "?" icon button that opens a popover explaining something — a metric, a
|
|
21
|
+
* field, a setting. The middle ground between Tooltip (a short hover label)
|
|
22
|
+
* and composing Popover directly (rich, interactive content): a labeled,
|
|
23
|
+
* keyboard-accessible help affordance for a sentence or two of text.
|
|
24
|
+
*/
|
|
25
|
+
export function InfoPopover(props: InfoPopoverProps) {
|
|
26
|
+
const { text, accessibilityLabel = "More information", side = "bottom", align = "end" } = props;
|
|
27
|
+
return (
|
|
28
|
+
<Popover side={side} align={align}>
|
|
29
|
+
<PopoverTrigger>
|
|
30
|
+
<IconButton
|
|
31
|
+
icon="message-circle-question-mark"
|
|
32
|
+
iconColor={colors.zinc[500]}
|
|
33
|
+
accessibilityLabel={accessibilityLabel}
|
|
34
|
+
/>
|
|
35
|
+
</PopoverTrigger>
|
|
36
|
+
<PopoverContent style={styles.content} disableBodyScroll>
|
|
37
|
+
<Text size="sm" color="muted">
|
|
38
|
+
{text}
|
|
39
|
+
</Text>
|
|
40
|
+
</PopoverContent>
|
|
41
|
+
</Popover>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const styles = StyleSheet.create({
|
|
46
|
+
content: {
|
|
47
|
+
width: 280,
|
|
48
|
+
},
|
|
49
|
+
});
|
package/src/portal.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
ReactNode,
|
|
12
12
|
} from "react";
|
|
13
13
|
import { Platform, View, StyleSheet } from "react-native";
|
|
14
|
+
import { createPortal } from "./dom_portal";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Cross-platform portal system inspired by Base UI and @gorhom/portal.
|
|
@@ -137,8 +138,6 @@ export function Portal({ children }: { children: ReactNode }) {
|
|
|
137
138
|
return null;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
141
|
-
const { createPortal } = require("react-dom");
|
|
142
141
|
return createPortal(children, target);
|
|
143
142
|
}
|
|
144
143
|
|