|
@@ -2,7 +2,10 @@ import {
|
|
|
useImperativeHandle,
|
|
useImperativeHandle,
|
|
|
forwardRef,
|
|
forwardRef,
|
|
|
useReducer,
|
|
useReducer,
|
|
|
- type Ref
|
|
|
|
|
|
|
+ useEffect,
|
|
|
|
|
+ useState,
|
|
|
|
|
+ type Ref,
|
|
|
|
|
+ useRef
|
|
|
} from "react";
|
|
} from "react";
|
|
|
import {
|
|
import {
|
|
|
TouchableOpacity,
|
|
TouchableOpacity,
|
|
@@ -28,6 +31,9 @@ import {
|
|
|
type NCoreUIKitIcon
|
|
type NCoreUIKitIcon
|
|
|
} from "../../types";
|
|
} from "../../types";
|
|
|
import type ITextProps from "../text/type";
|
|
import type ITextProps from "../text/type";
|
|
|
|
|
+import {
|
|
|
|
|
+ CheckIcon
|
|
|
|
|
+} from "lucide-react-native";
|
|
|
import {
|
|
import {
|
|
|
BadgeQuestionMarkIcon,
|
|
BadgeQuestionMarkIcon,
|
|
|
BadgeSuccessIcon,
|
|
BadgeSuccessIcon,
|
|
@@ -36,6 +42,10 @@ import {
|
|
|
BadgeInfoIcon,
|
|
BadgeInfoIcon,
|
|
|
CleanIcon
|
|
CleanIcon
|
|
|
} from "../../assets/svg";
|
|
} from "../../assets/svg";
|
|
|
|
|
+import {
|
|
|
|
|
+ uuid
|
|
|
|
|
+} from "../../utils";
|
|
|
|
|
+import BottomSheet from "../bottomSheet";
|
|
|
import Text from "../text";
|
|
import Text from "../text";
|
|
|
|
|
|
|
|
const SelectBoxTypeIcon: Record<Exclude<SelectBoxType, "default">, NCoreUIKitIcon> = {
|
|
const SelectBoxTypeIcon: Record<Exclude<SelectBoxType, "default">, NCoreUIKitIcon> = {
|
|
@@ -66,6 +76,7 @@ function SelectBox<T>({
|
|
|
variant = "text",
|
|
variant = "text",
|
|
|
type = "default",
|
|
type = "default",
|
|
|
rightIconOnPress,
|
|
rightIconOnPress,
|
|
|
|
|
+ renderOptionIcon,
|
|
|
rightIconStyle,
|
|
rightIconStyle,
|
|
|
isShowSubTitle,
|
|
isShowSubTitle,
|
|
|
cleanIconStyle,
|
|
cleanIconStyle,
|
|
@@ -76,6 +87,7 @@ function SelectBox<T>({
|
|
|
iconOnPress,
|
|
iconOnPress,
|
|
|
isOptional,
|
|
isOptional,
|
|
|
validation,
|
|
validation,
|
|
|
|
|
+ customKey,
|
|
|
iconStyle,
|
|
iconStyle,
|
|
|
onChange,
|
|
onChange,
|
|
|
hintText,
|
|
hintText,
|
|
@@ -95,6 +107,8 @@ function SelectBox<T>({
|
|
|
localize
|
|
localize
|
|
|
} = NCoreUIKitLocalize.useContext();
|
|
} = NCoreUIKitLocalize.useContext();
|
|
|
|
|
|
|
|
|
|
+ const selectBoxKey = useRef(customKey ? customKey : uuid());
|
|
|
|
|
+
|
|
|
const currentType = getSelectBoxType({
|
|
const currentType = getSelectBoxType({
|
|
|
type
|
|
type
|
|
|
});
|
|
});
|
|
@@ -148,7 +162,7 @@ function SelectBox<T>({
|
|
|
const [
|
|
const [
|
|
|
isActive,
|
|
isActive,
|
|
|
setIsActive
|
|
setIsActive
|
|
|
- ] = useState(); --> continue
|
|
|
|
|
|
|
+ ] = useState(false);
|
|
|
|
|
|
|
|
const [
|
|
const [
|
|
|
selectedItems,
|
|
selectedItems,
|
|
@@ -169,6 +183,14 @@ function SelectBox<T>({
|
|
|
[]
|
|
[]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if(isActive) {
|
|
|
|
|
+ if(onFocus) onFocus();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if(onBlur) onBlur();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [isActive]);
|
|
|
|
|
+
|
|
|
const titleProps: ITextProps = {
|
|
const titleProps: ITextProps = {
|
|
|
color: currentType.titleColor,
|
|
color: currentType.titleColor,
|
|
|
variant: "bodyLargeSize"
|
|
variant: "bodyLargeSize"
|
|
@@ -184,11 +206,11 @@ function SelectBox<T>({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const blur = () => {
|
|
const blur = () => {
|
|
|
- // inputRef.current?.blur();
|
|
|
|
|
|
|
+ setIsActive(false);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const focus = () => {
|
|
const focus = () => {
|
|
|
- // inputRef.current?.focus();
|
|
|
|
|
|
|
+ setIsActive(true);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const cleanSelections = () => {
|
|
const cleanSelections = () => {
|
|
@@ -423,7 +445,7 @@ function SelectBox<T>({
|
|
|
]}
|
|
]}
|
|
|
onPress={() => {
|
|
onPress={() => {
|
|
|
if(!isDisabled) {
|
|
if(!isDisabled) {
|
|
|
-
|
|
|
|
|
|
|
+ focus();
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
@@ -488,6 +510,40 @@ function SelectBox<T>({
|
|
|
/>;
|
|
/>;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const renderBottomSheetContent = () => {
|
|
|
|
|
+ return data.map((item: T, index: number) => {
|
|
|
|
|
+ return <TouchableOpacity>
|
|
|
|
|
+ {renderOptionIcon ? renderOptionIcon({
|
|
|
|
|
+ item,
|
|
|
|
|
+ index
|
|
|
|
|
+ }) : null}
|
|
|
|
|
+ <Text></Text>
|
|
|
|
|
+ <View>
|
|
|
|
|
+ <CheckIcon/>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </TouchableOpacity>;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const renderBottomSheet = () => {
|
|
|
|
|
+ return <BottomSheet
|
|
|
|
|
+ customKey={selectBoxKey.current}
|
|
|
|
|
+ isActive={isActive}
|
|
|
|
|
+ onClose={() => {
|
|
|
|
|
+ setIsActive(false);
|
|
|
|
|
+ }}
|
|
|
|
|
+ renderHeader={() => {
|
|
|
|
|
+ return <View>
|
|
|
|
|
+ <Text>
|
|
|
|
|
+ {title}
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ </View>;
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ {renderBottomSheetContent()}
|
|
|
|
|
+ </BottomSheet>;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return <View
|
|
return <View
|
|
|
style={[
|
|
style={[
|
|
|
style,
|
|
style,
|
|
@@ -506,7 +562,7 @@ function SelectBox<T>({
|
|
|
]}
|
|
]}
|
|
|
onPress={() => {
|
|
onPress={() => {
|
|
|
if(!isDisabled) {
|
|
if(!isDisabled) {
|
|
|
-
|
|
|
|
|
|
|
+ focus();
|
|
|
}
|
|
}
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
@@ -521,6 +577,7 @@ function SelectBox<T>({
|
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
{renderHintText()}
|
|
{renderHintText()}
|
|
|
|
|
+ {renderBottomSheet()}
|
|
|
</View>;
|
|
</View>;
|
|
|
};
|
|
};
|
|
|
export default forwardRef(SelectBox) as unknown as SelectBoxComponent;
|
|
export default forwardRef(SelectBox) as unknown as SelectBoxComponent;
|