You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LiteTodo/lite.todo/components/todo-list.tsx

85 lines
2.5 KiB

2 weeks ago
import { Todo } from "@/store/useTodos";
import { FlatList } from "react-native";
import { VStack } from "./ui/vstack";
import { Text } from "./ui/text";
import { HStack } from "./ui/hstack";
import {
Checkbox,
CheckboxIcon,
CheckboxIndicator,
CheckboxLabel,
} from "./ui/checkbox";
import { Button, ButtonText } from "./ui/button";
import { GS } from "./ui/gluestack-ui-provider/gluestack-ui-token";
2 weeks ago
import { CheckIcon, CloseIcon, Icon } from "@/components/ui/icon";
2 weeks ago
import * as Animatable from "react-native-animatable";
2 weeks ago
type Props = {
data: Todo[];
onToggle: (id: string) => void;
onRemove?: (id: string) => void;
2 weeks ago
className?: string;
2 weeks ago
};
2 weeks ago
export default function TodoList({
data,
onToggle,
onRemove,
className,
}: Props) {
2 weeks ago
return (
<FlatList
2 weeks ago
className={className}
2 weeks ago
data={data}
keyExtractor={(it) => it.id}
contentContainerStyle={{ paddingBottom: 80 }}
2 weeks ago
renderItem={({ item }) => {
return (
<HStack className="items-center justify-between py-2 hover:bg-secondary-200">
<Checkbox
isChecked={item.done}
onChange={(_isChecked) => onToggle(item.id)}
value={item.title}
2 weeks ago
>
2 weeks ago
<Animatable.View
animation={item.done ? "bounce" : undefined}
duration={300}
useNativeDriver
>
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
</Animatable.View>
2 weeks ago
<CheckboxLabel className="data-[checked=true]:line-through">
{item.title}
</CheckboxLabel>
</Checkbox>
{onRemove ? (
<Button
className="pl-2"
variant={GS.variant.link}
action={GS.action.secondary}
onPress={() => onRemove(item.id)}
>
<HStack className="flex justify-center items-center">
<Icon
as={CloseIcon}
size={GS.size.xs}
className="text-secondary-950"
/>
<ButtonText size={GS.size.xs}></ButtonText>
</HStack>
</Button>
) : null}
</HStack>
);
}}
2 weeks ago
ListEmptyComponent={
<Text className="text-neutral-400 mt-6 text-center">
.
</Text>
}
/>
);
}