@korsolutions/ui 0.0.37 → 0.0.39
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/dist/module/components/alert-dialog/alert-dialog.js +41 -0
- package/dist/module/components/alert-dialog/alert-dialog.js.map +1 -0
- package/dist/module/components/alert-dialog/async-alert-dialog.js +117 -0
- package/dist/module/components/alert-dialog/async-alert-dialog.js.map +1 -0
- package/dist/module/components/alert-dialog/index.js +6 -0
- package/dist/module/components/alert-dialog/index.js.map +1 -0
- package/dist/module/components/alert-dialog/variants/default.js +93 -0
- package/dist/module/components/alert-dialog/variants/default.js.map +1 -0
- package/dist/module/components/alert-dialog/variants/index.js +7 -0
- package/dist/module/components/alert-dialog/variants/index.js.map +1 -0
- package/dist/module/components/autocomplete/autocomplete.js +31 -0
- package/dist/module/components/autocomplete/autocomplete.js.map +1 -0
- package/dist/module/components/autocomplete/variants/default.js +88 -0
- package/dist/module/components/autocomplete/variants/default.js.map +1 -0
- package/dist/module/components/autocomplete/variants/index.js +7 -0
- package/dist/module/components/autocomplete/variants/index.js.map +1 -0
- package/dist/module/components/index.js +2 -0
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/components/input/numeric-input.js +7 -6
- package/dist/module/components/input/numeric-input.js.map +1 -1
- package/dist/module/index.js +2 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/primitives/alert-dialog/alert-dialog-action.js +34 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-action.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-cancel.js +34 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-cancel.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-content.js +23 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-content.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-description.js +23 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-description.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-footer.js +23 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-footer.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-overlay.js +26 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-overlay.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-portal.js +20 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-portal.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-root.js +22 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-root.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-title.js +23 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-title.js.map +1 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-trigger.js +28 -0
- package/dist/module/primitives/alert-dialog/alert-dialog-trigger.js.map +1 -0
- package/dist/module/primitives/alert-dialog/context.js +12 -0
- package/dist/module/primitives/alert-dialog/context.js.map +1 -0
- package/dist/module/primitives/alert-dialog/index.js +26 -0
- package/dist/module/primitives/alert-dialog/index.js.map +1 -0
- package/dist/module/primitives/alert-dialog/types.js +4 -0
- package/dist/module/primitives/alert-dialog/types.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-content.js +33 -0
- package/dist/module/primitives/autocomplete/autocomplete-content.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-empty.js +17 -0
- package/dist/module/primitives/autocomplete/autocomplete-empty.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-input.js +73 -0
- package/dist/module/primitives/autocomplete/autocomplete-input.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-option.js +54 -0
- package/dist/module/primitives/autocomplete/autocomplete-option.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-overlay.js +20 -0
- package/dist/module/primitives/autocomplete/autocomplete-overlay.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-portal.js +25 -0
- package/dist/module/primitives/autocomplete/autocomplete-portal.js.map +1 -0
- package/dist/module/primitives/autocomplete/autocomplete-root.js +69 -0
- package/dist/module/primitives/autocomplete/autocomplete-root.js.map +1 -0
- package/dist/module/primitives/autocomplete/context.js +12 -0
- package/dist/module/primitives/autocomplete/context.js.map +1 -0
- package/dist/module/primitives/autocomplete/index.js +20 -0
- package/dist/module/primitives/autocomplete/index.js.map +1 -0
- package/dist/module/primitives/autocomplete/types.js +4 -0
- package/dist/module/primitives/autocomplete/types.js.map +1 -0
- package/dist/module/primitives/dropdown-menu/dropdown-menu-divider.js +2 -2
- package/dist/module/primitives/dropdown-menu/dropdown-menu-divider.js.map +1 -1
- package/dist/module/primitives/dropdown-menu/dropdown-menu-trigger.js +3 -7
- package/dist/module/primitives/dropdown-menu/dropdown-menu-trigger.js.map +1 -1
- package/dist/module/primitives/index.js +2 -0
- package/dist/module/primitives/index.js.map +1 -1
- package/dist/module/primitives/input/input.js +3 -4
- package/dist/module/primitives/input/input.js.map +1 -1
- package/dist/module/primitives/popover/popover-portal.js +1 -1
- package/dist/module/primitives/popover/popover-portal.js.map +1 -1
- package/dist/module/primitives/popover/popover-trigger.js +3 -7
- package/dist/module/primitives/popover/popover-trigger.js.map +1 -1
- package/dist/module/primitives/portal/portal.js +4 -35
- package/dist/module/primitives/portal/portal.js.map +1 -1
- package/dist/module/primitives/select/context.js.map +1 -1
- package/dist/module/primitives/select/select-content.js +16 -5
- package/dist/module/primitives/select/select-content.js.map +1 -1
- package/dist/module/primitives/select/select-root.js +7 -3
- package/dist/module/primitives/select/select-root.js.map +1 -1
- package/dist/module/primitives/select/select-trigger.js +16 -11
- package/dist/module/primitives/select/select-trigger.js.map +1 -1
- package/dist/module/utils/normalize-layout.js +17 -0
- package/dist/module/utils/normalize-layout.js.map +1 -1
- package/dist/typescript/src/components/alert-dialog/alert-dialog.d.ts +15 -0
- package/dist/typescript/src/components/alert-dialog/alert-dialog.d.ts.map +1 -0
- package/dist/typescript/src/components/alert-dialog/async-alert-dialog.d.ts +19 -0
- package/dist/typescript/src/components/alert-dialog/async-alert-dialog.d.ts.map +1 -0
- package/dist/typescript/src/components/alert-dialog/index.d.ts +4 -0
- package/dist/typescript/src/components/alert-dialog/index.d.ts.map +1 -0
- package/dist/typescript/src/components/alert-dialog/variants/default.d.ts +3 -0
- package/dist/typescript/src/components/alert-dialog/variants/default.d.ts.map +1 -0
- package/dist/typescript/src/components/alert-dialog/variants/index.d.ts +4 -0
- package/dist/typescript/src/components/alert-dialog/variants/index.d.ts.map +1 -0
- package/dist/typescript/src/components/autocomplete/autocomplete.d.ts +11 -0
- package/dist/typescript/src/components/autocomplete/autocomplete.d.ts.map +1 -0
- package/dist/typescript/src/components/autocomplete/variants/default.d.ts +3 -0
- package/dist/typescript/src/components/autocomplete/variants/default.d.ts.map +1 -0
- package/dist/typescript/src/components/autocomplete/variants/index.d.ts +5 -0
- package/dist/typescript/src/components/autocomplete/variants/index.d.ts.map +1 -0
- package/dist/typescript/src/components/index.d.ts +2 -0
- package/dist/typescript/src/components/index.d.ts.map +1 -1
- package/dist/typescript/src/components/input/numeric-input.d.ts +2 -1
- package/dist/typescript/src/components/input/numeric-input.d.ts.map +1 -1
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-action.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-action.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-cancel.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-cancel.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-content.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-content.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-description.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-description.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-footer.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-footer.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-overlay.d.ts +7 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-overlay.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-portal.d.ts +7 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-portal.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-root.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-root.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-title.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-title.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-trigger.d.ts +8 -0
- package/dist/typescript/src/primitives/alert-dialog/alert-dialog-trigger.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/context.d.ts +10 -0
- package/dist/typescript/src/primitives/alert-dialog/context.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/index.d.ts +33 -0
- package/dist/typescript/src/primitives/alert-dialog/index.d.ts.map +1 -0
- package/dist/typescript/src/primitives/alert-dialog/types.d.ts +13 -0
- package/dist/typescript/src/primitives/alert-dialog/types.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-content.d.ts +8 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-content.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-empty.d.ts +9 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-empty.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-input.d.ts +7 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-input.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-option.d.ts +11 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-option.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-overlay.d.ts +10 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-overlay.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-portal.d.ts +6 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-portal.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-root.d.ts +24 -0
- package/dist/typescript/src/primitives/autocomplete/autocomplete-root.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/context.d.ts +30 -0
- package/dist/typescript/src/primitives/autocomplete/context.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/index.d.ts +25 -0
- package/dist/typescript/src/primitives/autocomplete/index.d.ts.map +1 -0
- package/dist/typescript/src/primitives/autocomplete/types.d.ts +21 -0
- package/dist/typescript/src/primitives/autocomplete/types.d.ts.map +1 -0
- package/dist/typescript/src/primitives/dropdown-menu/dropdown-menu-divider.d.ts.map +1 -1
- package/dist/typescript/src/primitives/dropdown-menu/dropdown-menu-trigger.d.ts.map +1 -1
- package/dist/typescript/src/primitives/index.d.ts +2 -0
- package/dist/typescript/src/primitives/index.d.ts.map +1 -1
- package/dist/typescript/src/primitives/input/input.d.ts +1 -2
- package/dist/typescript/src/primitives/input/input.d.ts.map +1 -1
- package/dist/typescript/src/primitives/popover/popover-trigger.d.ts.map +1 -1
- package/dist/typescript/src/primitives/portal/portal.constants.d.ts +6 -2
- package/dist/typescript/src/primitives/portal/portal.constants.d.ts.map +1 -1
- package/dist/typescript/src/primitives/portal/portal.d.ts +2 -5
- package/dist/typescript/src/primitives/portal/portal.d.ts.map +1 -1
- package/dist/typescript/src/primitives/select/context.d.ts +5 -2
- package/dist/typescript/src/primitives/select/context.d.ts.map +1 -1
- package/dist/typescript/src/primitives/select/select-content.d.ts.map +1 -1
- package/dist/typescript/src/primitives/select/select-root.d.ts.map +1 -1
- package/dist/typescript/src/primitives/select/select-trigger.d.ts +0 -5
- package/dist/typescript/src/primitives/select/select-trigger.d.ts.map +1 -1
- package/dist/typescript/src/types/element.types.d.ts +10 -3
- package/dist/typescript/src/types/element.types.d.ts.map +1 -1
- package/dist/typescript/src/utils/normalize-layout.d.ts +3 -1
- package/dist/typescript/src/utils/normalize-layout.d.ts.map +1 -1
- package/package.json +8 -5
- package/scripts/build.sh +2 -2
- package/src/components/alert-dialog/alert-dialog.tsx +38 -0
- package/src/components/alert-dialog/async-alert-dialog.tsx +121 -0
- package/src/components/alert-dialog/index.ts +3 -0
- package/src/components/alert-dialog/variants/default.tsx +82 -0
- package/src/components/alert-dialog/variants/index.ts +5 -0
- package/src/components/autocomplete/autocomplete.tsx +34 -0
- package/src/components/autocomplete/variants/default.tsx +84 -0
- package/src/components/autocomplete/variants/index.ts +5 -0
- package/src/components/index.ts +2 -0
- package/src/components/input/numeric-input.tsx +8 -6
- package/src/index.tsx +2 -0
- package/src/primitives/alert-dialog/alert-dialog-action.tsx +27 -0
- package/src/primitives/alert-dialog/alert-dialog-cancel.tsx +27 -0
- package/src/primitives/alert-dialog/alert-dialog-content.tsx +21 -0
- package/src/primitives/alert-dialog/alert-dialog-description.tsx +21 -0
- package/src/primitives/alert-dialog/alert-dialog-footer.tsx +21 -0
- package/src/primitives/alert-dialog/alert-dialog-overlay.tsx +25 -0
- package/src/primitives/alert-dialog/alert-dialog-portal.tsx +20 -0
- package/src/primitives/alert-dialog/alert-dialog-root.tsx +25 -0
- package/src/primitives/alert-dialog/alert-dialog-title.tsx +21 -0
- package/src/primitives/alert-dialog/alert-dialog-trigger.tsx +27 -0
- package/src/primitives/alert-dialog/context.ts +18 -0
- package/src/primitives/alert-dialog/index.ts +34 -0
- package/src/primitives/alert-dialog/types.ts +13 -0
- package/src/primitives/autocomplete/autocomplete-content.tsx +38 -0
- package/src/primitives/autocomplete/autocomplete-empty.tsx +19 -0
- package/src/primitives/autocomplete/autocomplete-input.tsx +85 -0
- package/src/primitives/autocomplete/autocomplete-option.tsx +66 -0
- package/src/primitives/autocomplete/autocomplete-overlay.tsx +29 -0
- package/src/primitives/autocomplete/autocomplete-portal.tsx +27 -0
- package/src/primitives/autocomplete/autocomplete-root.tsx +111 -0
- package/src/primitives/autocomplete/context.ts +45 -0
- package/src/primitives/autocomplete/index.ts +27 -0
- package/src/primitives/autocomplete/types.ts +23 -0
- package/src/primitives/dropdown-menu/dropdown-menu-divider.tsx +2 -2
- package/src/primitives/dropdown-menu/dropdown-menu-trigger.tsx +3 -7
- package/src/primitives/index.ts +2 -0
- package/src/primitives/input/input.tsx +3 -6
- package/src/primitives/popover/popover-portal.tsx +1 -1
- package/src/primitives/popover/popover-trigger.tsx +3 -7
- package/src/primitives/portal/portal.constants.tsx +2 -2
- package/src/primitives/portal/portal.tsx +4 -36
- package/src/primitives/select/context.ts +5 -2
- package/src/primitives/select/select-content.tsx +16 -9
- package/src/primitives/select/select-root.tsx +7 -3
- package/src/primitives/select/select-trigger.tsx +19 -21
- package/src/types/element.types.ts +10 -3
- package/src/utils/normalize-layout.ts +22 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
|
|
3
|
+
import { useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveContentProps extends ViewProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AlertDialogContent(props: AlertDialogPrimitiveContentProps) {
|
|
11
|
+
const { children, style, ...viewProps } = props;
|
|
12
|
+
const { styles } = useAlertDialog();
|
|
13
|
+
|
|
14
|
+
const calculatedStyle = [styles?.content, style];
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<View {...viewProps} style={calculatedStyle}>
|
|
18
|
+
{children}
|
|
19
|
+
</View>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text, type StyleProp, type TextProps, type TextStyle } from "react-native";
|
|
3
|
+
import { useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveDescriptionProps extends TextProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
style?: StyleProp<TextStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AlertDialogDescription(props: AlertDialogPrimitiveDescriptionProps) {
|
|
11
|
+
const { children, style, ...textProps } = props;
|
|
12
|
+
const { styles } = useAlertDialog();
|
|
13
|
+
|
|
14
|
+
const calculatedStyle = [styles?.description, style];
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Text {...textProps} style={calculatedStyle}>
|
|
18
|
+
{children}
|
|
19
|
+
</Text>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
|
|
3
|
+
import { useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveFooterProps extends ViewProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AlertDialogFooter(props: AlertDialogPrimitiveFooterProps) {
|
|
11
|
+
const { children, style, ...viewProps } = props;
|
|
12
|
+
const { styles } = useAlertDialog();
|
|
13
|
+
|
|
14
|
+
const calculatedStyle = [styles?.footer, style];
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<View {...viewProps} style={calculatedStyle}>
|
|
18
|
+
{children}
|
|
19
|
+
</View>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pressable, type PressableProps, type StyleProp, type ViewStyle } from "react-native";
|
|
3
|
+
import { useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveOverlayProps extends PressableProps {
|
|
6
|
+
style?: StyleProp<ViewStyle>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function AlertDialogOverlay(props: AlertDialogPrimitiveOverlayProps) {
|
|
10
|
+
const { style, ...pressableProps } = props;
|
|
11
|
+
const { styles, setIsOpen } = useAlertDialog();
|
|
12
|
+
|
|
13
|
+
const calculatedStyle = [styles?.overlay, style];
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Pressable
|
|
17
|
+
{...pressableProps}
|
|
18
|
+
style={calculatedStyle}
|
|
19
|
+
onPress={() => setIsOpen(false)}
|
|
20
|
+
accessible={true}
|
|
21
|
+
accessibilityRole="button"
|
|
22
|
+
accessibilityLabel="Close alert dialog"
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Portal } from "../portal";
|
|
3
|
+
import { AlertDialogPrimitiveContext, useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
interface AlertDialogPortalProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function AlertDialogPortal(props: AlertDialogPortalProps) {
|
|
10
|
+
const alertDialog = useAlertDialog();
|
|
11
|
+
|
|
12
|
+
if (!alertDialog.isOpen) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return (
|
|
16
|
+
<Portal name="alert-dialog-content">
|
|
17
|
+
<AlertDialogPrimitiveContext.Provider value={alertDialog}>{props.children}</AlertDialogPrimitiveContext.Provider>
|
|
18
|
+
</Portal>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useMemo, useState } from "react";
|
|
2
|
+
import { AlertDialogPrimitiveContext } from "./context";
|
|
3
|
+
import type { AlertDialogStyles } from "./types";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveRootProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
|
|
8
|
+
styles?: AlertDialogStyles;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function AlertDialogRoot(props: AlertDialogPrimitiveRootProps) {
|
|
12
|
+
const { children, styles } = props;
|
|
13
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
+
|
|
15
|
+
const contextValue = useMemo(
|
|
16
|
+
() => ({
|
|
17
|
+
isOpen,
|
|
18
|
+
setIsOpen,
|
|
19
|
+
styles,
|
|
20
|
+
}),
|
|
21
|
+
[isOpen, styles]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return <AlertDialogPrimitiveContext.Provider value={contextValue}>{children}</AlertDialogPrimitiveContext.Provider>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text, type StyleProp, type TextProps, type TextStyle } from "react-native";
|
|
3
|
+
import { useAlertDialog } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogPrimitiveTitleProps extends TextProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
style?: StyleProp<TextStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AlertDialogTitle(props: AlertDialogPrimitiveTitleProps) {
|
|
11
|
+
const { children, style, ...textProps } = props;
|
|
12
|
+
const { styles } = useAlertDialog();
|
|
13
|
+
|
|
14
|
+
const calculatedStyle = [styles?.title, style];
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Text {...textProps} style={calculatedStyle}>
|
|
18
|
+
{children}
|
|
19
|
+
</Text>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ViewRef } from "@/types/element.types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { type PressableProps } from "react-native";
|
|
4
|
+
import { useAlertDialog } from "./context";
|
|
5
|
+
|
|
6
|
+
export interface AlertDialogPrimitiveTriggerProps extends PressableProps {
|
|
7
|
+
children: React.ReactElement<React.RefAttributes<ViewRef> & PressableProps>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AlertDialogTrigger(props: AlertDialogPrimitiveTriggerProps): React.ReactElement {
|
|
11
|
+
const { onPress } = props;
|
|
12
|
+
const { isOpen, setIsOpen } = useAlertDialog();
|
|
13
|
+
|
|
14
|
+
const handlePress: PressableProps["onPress"] = (event) => {
|
|
15
|
+
onPress?.(event);
|
|
16
|
+
setIsOpen(true);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return React.cloneElement(props.children, {
|
|
20
|
+
onPress: handlePress,
|
|
21
|
+
role: "button",
|
|
22
|
+
accessible: true,
|
|
23
|
+
accessibilityRole: "button",
|
|
24
|
+
accessibilityState: { expanded: isOpen },
|
|
25
|
+
...props.children.props,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { createContext, useContext, type Dispatch } from "react";
|
|
2
|
+
import type { AlertDialogStyles } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface AlertDialogPrimitiveContextValue {
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
setIsOpen: Dispatch<React.SetStateAction<boolean>>;
|
|
7
|
+
styles?: AlertDialogStyles;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const AlertDialogPrimitiveContext = createContext<AlertDialogPrimitiveContextValue | null>(null);
|
|
11
|
+
|
|
12
|
+
export const useAlertDialog = () => {
|
|
13
|
+
const context = useContext(AlertDialogPrimitiveContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error("AlertDialog compound components must be used within AlertDialogPrimitive.Root");
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AlertDialogAction } from "./alert-dialog-action";
|
|
2
|
+
import { AlertDialogCancel } from "./alert-dialog-cancel";
|
|
3
|
+
import { AlertDialogContent } from "./alert-dialog-content";
|
|
4
|
+
import { AlertDialogDescription } from "./alert-dialog-description";
|
|
5
|
+
import { AlertDialogFooter } from "./alert-dialog-footer";
|
|
6
|
+
import { AlertDialogOverlay } from "./alert-dialog-overlay";
|
|
7
|
+
import { AlertDialogPortal } from "./alert-dialog-portal";
|
|
8
|
+
import { AlertDialogRoot } from "./alert-dialog-root";
|
|
9
|
+
import { AlertDialogTitle } from "./alert-dialog-title";
|
|
10
|
+
import { AlertDialogTrigger } from "./alert-dialog-trigger";
|
|
11
|
+
|
|
12
|
+
export const AlertDialogPrimitive = {
|
|
13
|
+
Root: AlertDialogRoot,
|
|
14
|
+
Trigger: AlertDialogTrigger,
|
|
15
|
+
Portal: AlertDialogPortal,
|
|
16
|
+
Overlay: AlertDialogOverlay,
|
|
17
|
+
Content: AlertDialogContent,
|
|
18
|
+
Title: AlertDialogTitle,
|
|
19
|
+
Description: AlertDialogDescription,
|
|
20
|
+
Footer: AlertDialogFooter,
|
|
21
|
+
Action: AlertDialogAction,
|
|
22
|
+
Cancel: AlertDialogCancel,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type { AlertDialogPrimitiveActionProps } from "./alert-dialog-action";
|
|
26
|
+
export type { AlertDialogPrimitiveCancelProps } from "./alert-dialog-cancel";
|
|
27
|
+
export type { AlertDialogPrimitiveContentProps } from "./alert-dialog-content";
|
|
28
|
+
export type { AlertDialogPrimitiveDescriptionProps } from "./alert-dialog-description";
|
|
29
|
+
export type { AlertDialogPrimitiveFooterProps } from "./alert-dialog-footer";
|
|
30
|
+
export type { AlertDialogPrimitiveOverlayProps } from "./alert-dialog-overlay";
|
|
31
|
+
export type { AlertDialogPrimitiveRootProps } from "./alert-dialog-root";
|
|
32
|
+
export type { AlertDialogPrimitiveTitleProps } from "./alert-dialog-title";
|
|
33
|
+
export type { AlertDialogPrimitiveTriggerProps } from "./alert-dialog-trigger";
|
|
34
|
+
export * from "./types";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
export interface AlertDialogStyles {
|
|
4
|
+
overlay?: StyleProp<ViewStyle>;
|
|
5
|
+
content?: StyleProp<ViewStyle>;
|
|
6
|
+
title?: StyleProp<TextStyle>;
|
|
7
|
+
description?: StyleProp<TextStyle>;
|
|
8
|
+
footer?: StyleProp<ViewStyle>;
|
|
9
|
+
action?: StyleProp<ViewStyle>;
|
|
10
|
+
actionText?: StyleProp<TextStyle>;
|
|
11
|
+
cancel?: StyleProp<ViewStyle>;
|
|
12
|
+
cancelText?: StyleProp<TextStyle>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useRelativePosition } from "@/hooks/use-relative-position";
|
|
2
|
+
import { calculateComposedStyles } from "@/utils/calculate-styles";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ScrollView, type StyleProp, type ViewStyle } from "react-native";
|
|
5
|
+
import { useAutocomplete } from "./context";
|
|
6
|
+
|
|
7
|
+
export interface AutocompleteContentProps {
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AutocompleteContent(props: AutocompleteContentProps) {
|
|
13
|
+
const autocomplete = useAutocomplete();
|
|
14
|
+
const composedStyles = calculateComposedStyles(autocomplete.styles, autocomplete.state, "content", props.style);
|
|
15
|
+
|
|
16
|
+
const positionStyle = useRelativePosition({
|
|
17
|
+
align: "start",
|
|
18
|
+
avoidCollisions: true,
|
|
19
|
+
triggerPosition: autocomplete.inputPosition,
|
|
20
|
+
contentLayout: autocomplete.contentLayout,
|
|
21
|
+
alignOffset: 0,
|
|
22
|
+
side: "bottom",
|
|
23
|
+
sideOffset: 0,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<ScrollView
|
|
28
|
+
style={[positionStyle, composedStyles, { width: autocomplete.inputPosition.width }]}
|
|
29
|
+
onLayout={(e) => {
|
|
30
|
+
autocomplete.setContentLayout(e.nativeEvent.layout);
|
|
31
|
+
}}
|
|
32
|
+
pointerEvents="box-none"
|
|
33
|
+
keyboardShouldPersistTaps="handled"
|
|
34
|
+
>
|
|
35
|
+
{props.children}
|
|
36
|
+
</ScrollView>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { calculateComposedStyles } from "@/utils/calculate-styles";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { type StyleProp, Text, type TextStyle } from "react-native";
|
|
4
|
+
import { useAutocomplete } from "./context";
|
|
5
|
+
|
|
6
|
+
export interface AutocompleteEmptyProps {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
style?: StyleProp<TextStyle>;
|
|
9
|
+
render?: (props: AutocompleteEmptyProps) => React.ReactElement;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AutocompleteEmpty(props: AutocompleteEmptyProps) {
|
|
13
|
+
const autocomplete = useAutocomplete();
|
|
14
|
+
|
|
15
|
+
const composedStyles = calculateComposedStyles(autocomplete.styles, autocomplete.state, "empty", props.style);
|
|
16
|
+
|
|
17
|
+
const Component = props.render ?? Text;
|
|
18
|
+
return <Component style={composedStyles}>{props.children}</Component>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { TextInputRef } from "@/types/element.types";
|
|
2
|
+
import { measureLayoutPosition } from "@/utils/normalize-layout";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
+
import { StyleSheet, TextInput, type StyleProp, type TextInputProps, type TextStyle } from "react-native";
|
|
5
|
+
import { useFieldOptional } from "../field/context";
|
|
6
|
+
import { useAutocomplete } from "./context";
|
|
7
|
+
|
|
8
|
+
export interface AutocompleteInputProps extends Omit<TextInputProps, "onChange" | "value"> {
|
|
9
|
+
style?: StyleProp<TextStyle>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const AutocompleteInput = forwardRef<TextInputRef, AutocompleteInputProps>((props, ref) => {
|
|
13
|
+
const autocomplete = useAutocomplete();
|
|
14
|
+
const field = useFieldOptional();
|
|
15
|
+
const inputRef = useRef<TextInputRef>(null);
|
|
16
|
+
const blurTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
|
|
17
|
+
|
|
18
|
+
const composedStyles = [autocomplete.styles?.input?.default, autocomplete.styles?.input?.[autocomplete.state], props.style];
|
|
19
|
+
|
|
20
|
+
const handleFocus: TextInputProps["onFocus"] = (e) => {
|
|
21
|
+
// Clear any pending blur timeout
|
|
22
|
+
if (blurTimeoutRef.current) {
|
|
23
|
+
clearTimeout(blurTimeoutRef.current);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Measure layout position and open dropdown
|
|
27
|
+
if (autocomplete.openOnFocus && !autocomplete.isDisabled) {
|
|
28
|
+
measureLayoutPosition(inputRef.current, (layout) => {
|
|
29
|
+
autocomplete.setInputPosition(layout);
|
|
30
|
+
autocomplete.setIsOpen(true);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
props.onFocus?.(e);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const handleBlur: TextInputProps["onBlur"] = (e) => {
|
|
38
|
+
blurTimeoutRef.current = setTimeout(() => {
|
|
39
|
+
autocomplete.setIsOpen(false);
|
|
40
|
+
}, 150);
|
|
41
|
+
|
|
42
|
+
props.onBlur?.(e);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const handleChangeText = (text: string) => {
|
|
46
|
+
autocomplete.setInputValue?.(text);
|
|
47
|
+
|
|
48
|
+
// Open dropdown when typing
|
|
49
|
+
if (!autocomplete.isOpen && text.trim() && autocomplete.openOnFocus) {
|
|
50
|
+
measureLayoutPosition(inputRef.current, (layout) => {
|
|
51
|
+
autocomplete.setInputPosition(layout);
|
|
52
|
+
autocomplete.setIsOpen(true);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
props.onChangeText?.(text);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
useImperativeHandle(ref, () => inputRef.current!);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
autocomplete.setBlurInput(() => () => {
|
|
62
|
+
inputRef.current?.blur();
|
|
63
|
+
});
|
|
64
|
+
autocomplete.setInputDisplayValueSetter(() => (v: string) => {
|
|
65
|
+
inputRef.current?.setNativeProps({ text: v });
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<TextInput
|
|
71
|
+
{...props}
|
|
72
|
+
ref={inputRef}
|
|
73
|
+
id={field?.id}
|
|
74
|
+
value={autocomplete.inputValue}
|
|
75
|
+
placeholder={autocomplete.placeholder}
|
|
76
|
+
onChangeText={handleChangeText}
|
|
77
|
+
onFocus={handleFocus}
|
|
78
|
+
onBlur={handleBlur}
|
|
79
|
+
editable={!autocomplete.isDisabled}
|
|
80
|
+
style={StyleSheet.flatten(composedStyles)}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
AutocompleteInput.displayName = "AutocompleteInput";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { calculateComposedStyles } from "@/utils/calculate-styles";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { type StyleProp, Text, type TextStyle } from "react-native";
|
|
4
|
+
import { useAutocomplete } from "./context";
|
|
5
|
+
import type { AutocompleteOptionState, AutocompleteState } from "./types";
|
|
6
|
+
|
|
7
|
+
export interface AutocompleteOptionProps {
|
|
8
|
+
children: string;
|
|
9
|
+
value: string;
|
|
10
|
+
onMouseEnter?: () => void;
|
|
11
|
+
onMouseLeave?: () => void;
|
|
12
|
+
render?: (props: AutocompleteOptionProps) => React.ReactElement;
|
|
13
|
+
style?: StyleProp<TextStyle>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const calculateState = (autocompleteState: AutocompleteState, hovered: boolean, selected: boolean): AutocompleteOptionState => {
|
|
17
|
+
if (autocompleteState === "disabled") {
|
|
18
|
+
return "disabled";
|
|
19
|
+
}
|
|
20
|
+
if (selected) {
|
|
21
|
+
return "selected";
|
|
22
|
+
}
|
|
23
|
+
if (hovered) {
|
|
24
|
+
return "hovered";
|
|
25
|
+
}
|
|
26
|
+
return "default";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function AutocompleteOption(props: AutocompleteOptionProps) {
|
|
30
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
31
|
+
const autocomplete = useAutocomplete();
|
|
32
|
+
const isSelected = autocomplete.value === props.value;
|
|
33
|
+
|
|
34
|
+
const optionState = calculateState(autocomplete.state, isHovered, isSelected);
|
|
35
|
+
const composedStyles = calculateComposedStyles(autocomplete.styles, optionState, "option", props.style);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
autocomplete.setOptions((prev) => {
|
|
39
|
+
if (prev.find((option) => option.value === props.value)) {
|
|
40
|
+
return prev;
|
|
41
|
+
}
|
|
42
|
+
return [...prev, { value: props.value, label: props.children }];
|
|
43
|
+
});
|
|
44
|
+
}, [props.value, props.children]);
|
|
45
|
+
|
|
46
|
+
const handlePress = () => {
|
|
47
|
+
autocomplete.onChange?.(props.value);
|
|
48
|
+
autocomplete.setInputValue?.("");
|
|
49
|
+
autocomplete.setInputDisplayValue(props.children);
|
|
50
|
+
autocomplete.setIsOpen(false);
|
|
51
|
+
autocomplete.blurInput();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const Component = props.render ?? Text;
|
|
55
|
+
return (
|
|
56
|
+
<Component
|
|
57
|
+
value={props.value}
|
|
58
|
+
onPress={handlePress}
|
|
59
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
60
|
+
onMouseLeave={() => setIsHovered(false)}
|
|
61
|
+
style={composedStyles}
|
|
62
|
+
>
|
|
63
|
+
{props.children}
|
|
64
|
+
</Component>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { calculateComposedStyles } from "@/utils/calculate-styles";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Pressable, type StyleProp, StyleSheet, type ViewStyle } from "react-native";
|
|
4
|
+
import { useAutocomplete } from "./context";
|
|
5
|
+
|
|
6
|
+
export interface AutocompleteOverlayProps {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
onPress?: () => void;
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
render?: (props: AutocompleteOverlayProps) => React.ReactElement;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AutocompleteOverlay(props: AutocompleteOverlayProps) {
|
|
14
|
+
const autocomplete = useAutocomplete();
|
|
15
|
+
|
|
16
|
+
const composedStyles = calculateComposedStyles(autocomplete.styles, autocomplete.state, "overlay", props.style);
|
|
17
|
+
|
|
18
|
+
const Component = props.render ?? Pressable;
|
|
19
|
+
return (
|
|
20
|
+
<Component
|
|
21
|
+
onPress={() => {
|
|
22
|
+
autocomplete.setIsOpen(false);
|
|
23
|
+
}}
|
|
24
|
+
style={[StyleSheet.absoluteFill, composedStyles]}
|
|
25
|
+
>
|
|
26
|
+
{props.children}
|
|
27
|
+
</Component>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { Portal } from "../portal";
|
|
3
|
+
import { useAutocomplete, AutocompleteContext } from "./context";
|
|
4
|
+
|
|
5
|
+
export interface AutocompletePortalProps {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function AutocompletePortal(props: AutocompletePortalProps) {
|
|
10
|
+
const autocomplete = useAutocomplete();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
return () => {
|
|
14
|
+
autocomplete.setOptions([]);
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
if (!autocomplete.isOpen) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Portal name="autocomplete-portal">
|
|
24
|
+
<AutocompleteContext.Provider value={autocomplete}>{props.children}</AutocompleteContext.Provider>
|
|
25
|
+
</Portal>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DEFAULT_LAYOUT, DEFAULT_POSITION, type LayoutPosition } from "@/hooks";
|
|
2
|
+
import { calculateComposedStyles } from "@/utils/calculate-styles";
|
|
3
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { type LayoutRectangle, type StyleProp, View, type ViewStyle } from "react-native";
|
|
5
|
+
import { AutocompleteContext } from "./context";
|
|
6
|
+
import type { AutocompleteOption, AutocompleteState, AutocompleteStyles } from "./types";
|
|
7
|
+
|
|
8
|
+
interface AutocompleteRootInjectedProps {
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AutocompleteRootBaseProps {
|
|
13
|
+
value?: string;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
|
+
inputValue?: string;
|
|
16
|
+
setInputValue?: (value: string) => void;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
isDisabled?: boolean;
|
|
19
|
+
openOnFocus?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AutocompleteRootProps extends AutocompleteRootBaseProps {
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
render?: (props: AutocompleteRootInjectedProps) => React.ReactElement;
|
|
25
|
+
styles?: AutocompleteStyles;
|
|
26
|
+
style?: StyleProp<ViewStyle>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const calculateState = (props: AutocompleteRootProps, isFocused: boolean): AutocompleteState => {
|
|
30
|
+
if (props.isDisabled) {
|
|
31
|
+
return "disabled";
|
|
32
|
+
}
|
|
33
|
+
if (isFocused) {
|
|
34
|
+
return "focused";
|
|
35
|
+
}
|
|
36
|
+
return "default";
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function AutocompleteRoot(props: AutocompleteRootProps) {
|
|
40
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
41
|
+
const [contentLayout, setContentLayout] = useState<LayoutRectangle>(DEFAULT_LAYOUT);
|
|
42
|
+
const [inputPosition, setInputPosition] = useState<LayoutPosition>(DEFAULT_POSITION);
|
|
43
|
+
const [options, setOptions] = useState<Array<AutocompleteOption>>([]);
|
|
44
|
+
const [blurInput, setBlurInput] = useState<() => void>(() => () => {});
|
|
45
|
+
const [setInputDisplayValue, setInputDisplayValueSetter] = useState<(value: string) => void>(() => () => {});
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (props.value) {
|
|
49
|
+
const selectedOption = options.find((opt) => opt.value === props.value);
|
|
50
|
+
if (selectedOption) {
|
|
51
|
+
props.setInputValue?.(selectedOption.label);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
props.setInputValue?.("");
|
|
55
|
+
}
|
|
56
|
+
}, [props.value, options]);
|
|
57
|
+
|
|
58
|
+
const state = calculateState(props, isOpen);
|
|
59
|
+
const composedStyles = calculateComposedStyles(props.styles, state, "root", props.style);
|
|
60
|
+
|
|
61
|
+
const contextValue = useMemo(
|
|
62
|
+
() =>
|
|
63
|
+
({
|
|
64
|
+
value: props.value,
|
|
65
|
+
onChange: props.onChange,
|
|
66
|
+
placeholder: props.placeholder,
|
|
67
|
+
inputValue: props.inputValue,
|
|
68
|
+
setInputValue: props.setInputValue,
|
|
69
|
+
isOpen,
|
|
70
|
+
setIsOpen,
|
|
71
|
+
inputPosition,
|
|
72
|
+
setInputPosition,
|
|
73
|
+
contentLayout,
|
|
74
|
+
setContentLayout,
|
|
75
|
+
options,
|
|
76
|
+
setOptions,
|
|
77
|
+
openOnFocus: props.openOnFocus ?? true,
|
|
78
|
+
blurInput,
|
|
79
|
+
setBlurInput,
|
|
80
|
+
setInputDisplayValue,
|
|
81
|
+
setInputDisplayValueSetter,
|
|
82
|
+
state,
|
|
83
|
+
isDisabled: props.isDisabled ?? false,
|
|
84
|
+
styles: props.styles ?? null,
|
|
85
|
+
}) satisfies AutocompleteContext,
|
|
86
|
+
[
|
|
87
|
+
props.value,
|
|
88
|
+
props.onChange,
|
|
89
|
+
props.placeholder,
|
|
90
|
+
props.openOnFocus,
|
|
91
|
+
props.isDisabled,
|
|
92
|
+
props.styles,
|
|
93
|
+
props.inputValue,
|
|
94
|
+
props.setInputValue,
|
|
95
|
+
isOpen,
|
|
96
|
+
inputPosition,
|
|
97
|
+
contentLayout,
|
|
98
|
+
options,
|
|
99
|
+
blurInput,
|
|
100
|
+
setInputDisplayValue,
|
|
101
|
+
state,
|
|
102
|
+
],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const Component = props.render ?? View;
|
|
106
|
+
return (
|
|
107
|
+
<AutocompleteContext.Provider value={contextValue}>
|
|
108
|
+
<Component style={composedStyles}>{props.children}</Component>
|
|
109
|
+
</AutocompleteContext.Provider>
|
|
110
|
+
);
|
|
111
|
+
}
|