Component
Add : - Checkbox Fix : - Drawer: tinggi bisa auto - AvataraAndOtherHeaderComponent : View pembungkus di hapus Feature : Collaboration Fix: - detail-participant - detail-project-main (fix tampilan) # No Issue
This commit is contained in:
109
components/Checkbox/CheckboxCustom.tsx
Normal file
109
components/Checkbox/CheckboxCustom.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
import React, { useState } from "react";
|
||||
import { View, Text, TouchableOpacity, Animated, Easing } from "react-native";
|
||||
import { MaterialIcons } from "@expo/vector-icons"; // Bisa diganti dengan ikon lain
|
||||
import { checkboxStyles } from "./checkbox-styles";
|
||||
|
||||
|
||||
// Tipe props
|
||||
interface CheckboxProps {
|
||||
label?: string;
|
||||
description?: string;
|
||||
error?: string;
|
||||
value?: boolean;
|
||||
onChange?: (checked: boolean) => void;
|
||||
disabled?: boolean;
|
||||
size?: number; // ukuran checkbox (default: 20)
|
||||
color?: string; // warna utama (default: '#3b82f6' - biru tailwind)
|
||||
style?: object;
|
||||
component?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const CheckboxCustom: React.FC<CheckboxProps> = ({
|
||||
label,
|
||||
description,
|
||||
error,
|
||||
value: controlledValue,
|
||||
onChange,
|
||||
disabled = false,
|
||||
size = 20,
|
||||
color = "#3b82f6",
|
||||
style,
|
||||
component,
|
||||
}) => {
|
||||
const [uncontrolledChecked, setUncontrolledChecked] = useState(false);
|
||||
const isChecked = controlledValue ?? uncontrolledChecked;
|
||||
const scaleValue = new Animated.Value(isChecked ? 1 : 0);
|
||||
|
||||
const toggle = () => {
|
||||
if (disabled) return;
|
||||
|
||||
const newValue = !isChecked;
|
||||
if (onChange) onChange(newValue);
|
||||
if (controlledValue === undefined) {
|
||||
setUncontrolledChecked(newValue);
|
||||
}
|
||||
|
||||
// Animasi scale
|
||||
Animated.spring(scaleValue, {
|
||||
toValue: newValue ? 1 : 0,
|
||||
friction: 7,
|
||||
tension: 40,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
};
|
||||
|
||||
const styles = checkboxStyles({
|
||||
size,
|
||||
color,
|
||||
disabled,
|
||||
error: !!error,
|
||||
});
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
activeOpacity={disabled ? 1 : 0.7}
|
||||
onPress={toggle}
|
||||
style={[styles.container, style]}
|
||||
disabled={disabled}
|
||||
>
|
||||
<View style={styles.innerContainer}>
|
||||
<View style={[styles.box, isChecked && !disabled && styles.checked]}>
|
||||
{isChecked && (
|
||||
<Animated.View
|
||||
style={{
|
||||
transform: [
|
||||
{
|
||||
scale: scaleValue.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [0, 1],
|
||||
}),
|
||||
},
|
||||
],
|
||||
}}
|
||||
>
|
||||
<MaterialIcons name="check" size={size * 0.6} color="#fff" />
|
||||
</Animated.View>
|
||||
)}
|
||||
</View>
|
||||
{component}
|
||||
{(label || description) && (
|
||||
<View style={styles.labelWrapper}>
|
||||
{label ? (
|
||||
<Text style={styles.label} numberOfLines={1}>
|
||||
{label}
|
||||
</Text>
|
||||
) : null}
|
||||
{description ? (
|
||||
<Text style={styles.description} numberOfLines={2}>
|
||||
{description}
|
||||
</Text>
|
||||
) : null}
|
||||
{error ? <Text style={styles.errorText}>{error}</Text> : null}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
export default CheckboxCustom
|
||||
62
components/Checkbox/checkbox-styles.tsx
Normal file
62
components/Checkbox/checkbox-styles.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { StyleSheet } from "react-native";
|
||||
|
||||
export const checkboxStyles = (props: {
|
||||
size: number;
|
||||
color: string;
|
||||
disabled: boolean;
|
||||
error: boolean;
|
||||
}) =>
|
||||
StyleSheet.create({
|
||||
container: {
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
// marginBottom: 12,
|
||||
|
||||
},
|
||||
innerContainer: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
},
|
||||
box: {
|
||||
width: props.size,
|
||||
height: props.size,
|
||||
borderRadius: 6,
|
||||
borderWidth: 2,
|
||||
borderColor: props.error
|
||||
? "#fff"
|
||||
: props.disabled
|
||||
? "#ced4da"
|
||||
: props.color,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginRight: 10,
|
||||
},
|
||||
checked: {
|
||||
backgroundColor: props.color,
|
||||
borderColor: props.color,
|
||||
},
|
||||
checkIcon: {
|
||||
color: MainColor.white,
|
||||
fontWeight: "bold",
|
||||
fontSize: props.size * 0.6,
|
||||
},
|
||||
labelWrapper: {
|
||||
flex: 1,
|
||||
},
|
||||
label: {
|
||||
fontSize: props.size * 0.6,
|
||||
color: props.disabled ? MainColor.disabled : MainColor.white,
|
||||
fontWeight: "500",
|
||||
},
|
||||
description: {
|
||||
fontSize: props.size * 0.5,
|
||||
color: props.disabled ? MainColor.disabled : MainColor.white,
|
||||
marginTop: 2,
|
||||
},
|
||||
errorText: {
|
||||
color: MainColor.red,
|
||||
fontSize: props.size * 0.5,
|
||||
marginTop: 2,
|
||||
},
|
||||
});
|
||||
@@ -9,20 +9,20 @@ import {
|
||||
|
||||
import { AccentColor, MainColor } from "@/constants/color-palet";
|
||||
import { DRAWER_HEIGHT } from "@/constants/constans-value";
|
||||
import { SafeAreaView } from "react-native-safe-area-context";
|
||||
|
||||
interface DrawerCustomProps {
|
||||
children?: React.ReactNode;
|
||||
height?: number;
|
||||
height?: number | "auto";
|
||||
isVisible: boolean;
|
||||
drawerAnim?: Animated.Value;
|
||||
closeDrawer: () => void;
|
||||
// openLogoutAlert: () => void;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param drawerAnim
|
||||
*
|
||||
* @param drawerAnim
|
||||
* @example const drawerAnim = useRef(new Animated.Value(DRAWER_HEIGHT)).current; // mulai di luar bawah layar
|
||||
*/
|
||||
export default function DrawerCustom({
|
||||
@@ -34,7 +34,9 @@ export default function DrawerCustom({
|
||||
}: // openLogoutAlert,
|
||||
DrawerCustomProps) {
|
||||
const drawerAnima = useRef(
|
||||
new Animated.Value(height || DRAWER_HEIGHT)
|
||||
new Animated.Value(
|
||||
height === "auto" ? DRAWER_HEIGHT : height || DRAWER_HEIGHT
|
||||
)
|
||||
).current;
|
||||
// Efek untuk handle open/close drawer
|
||||
useEffect(() => {
|
||||
@@ -46,7 +48,7 @@ DrawerCustomProps) {
|
||||
}).start();
|
||||
} else {
|
||||
Animated.timing(drawerAnima, {
|
||||
toValue: height || DRAWER_HEIGHT,
|
||||
toValue: height === "auto" ? DRAWER_HEIGHT : height || DRAWER_HEIGHT,
|
||||
duration: 300,
|
||||
useNativeDriver: true,
|
||||
}).start();
|
||||
@@ -99,7 +101,7 @@ DrawerCustomProps) {
|
||||
style={[
|
||||
styles.drawer,
|
||||
{
|
||||
height: height || DRAWER_HEIGHT,
|
||||
height: height === "auto" ? "auto" : height || DRAWER_HEIGHT,
|
||||
transform: [{ translateY: drawerAnima }],
|
||||
},
|
||||
]}
|
||||
@@ -110,34 +112,7 @@ DrawerCustomProps) {
|
||||
/>
|
||||
|
||||
{children}
|
||||
|
||||
{/* <TouchableOpacity
|
||||
style={styles.menuItem}
|
||||
onPress={() => {
|
||||
alert("Pilihan 1 diklik");
|
||||
closeDrawer();
|
||||
}}
|
||||
>
|
||||
<Text>Menu Item 1</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
style={styles.menuItem}
|
||||
onPress={() => {
|
||||
alert("Pilihan 2 diklik");
|
||||
closeDrawer();
|
||||
}}
|
||||
>
|
||||
<Text>Menu Item 2</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
|
||||
<TouchableOpacity
|
||||
style={styles.menuItem}
|
||||
onPress={() => alert("Logout via Alert bawaan")}
|
||||
>
|
||||
<Text style={{ color: "red" }}>Keluar</Text>
|
||||
</TouchableOpacity> */}
|
||||
{height === "auto" && <SafeAreaView edges={["bottom"]} />}
|
||||
</Animated.View>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -19,7 +19,6 @@ const AvatarUsernameAndOtherComponent = ({
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<View>
|
||||
<Grid containerStyle={{ zIndex: 10 }}>
|
||||
<Grid.Col span={2}>
|
||||
<AvatarCustom source={avatar} href={avatarHref as any} />
|
||||
@@ -42,6 +41,7 @@ const AvatarUsernameAndOtherComponent = ({
|
||||
)}
|
||||
</Grid>
|
||||
{withBottomLine && <Divider marginTop={0} />}
|
||||
<View>
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user