Skip to content

Commit

Permalink
feat: pregressbar width changes on task completed
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseCSG committed Apr 9, 2024
1 parent 761b127 commit ddbe92b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
13 changes: 11 additions & 2 deletions app/pip/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client";
import NavigationBar from "@/components/NavigationBar";
import PipResource from "@/components/PipResource";
import PipTask from "@/components/PipTask";
import ProgressBar from "@/components/Progressbar";
import { useState } from "react";

const PIP = () => {
const tasks = [
const [tasks, setTasks] = useState([
{
id: 1,
title: "Ir con el psicólogo",
Expand Down Expand Up @@ -65,7 +67,7 @@ const PIP = () => {
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
isDone: false,
},
];
]);

const resources = [
{
Expand Down Expand Up @@ -96,6 +98,12 @@ const PIP = () => {
(tasks.filter((task) => task.isDone).length / tasks.length) * 100,
);

const handleCheckTask = (index: number) => {
const newTasks = [...tasks];
newTasks[index].isDone = !newTasks[index].isDone;
setTasks(newTasks);
};

return (
<main className="overflow-y-hidden">
<NavigationBar />
Expand All @@ -113,6 +121,7 @@ const PIP = () => {
title={task.title}
description={task.description}
isDone={task.isDone}
handleCheck={() => handleCheckTask(index)}
key={index}
/>
))}
Expand Down
14 changes: 9 additions & 5 deletions components/PipTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ interface InterfacePipTask {
title: string;
description: string;
isDone: boolean;
handleCheck: () => void;
}

const PipTask = ({ title, description, isDone }: InterfacePipTask) => {
const [done, setIsDone] = useState<boolean>(isDone);
const handleDone = () => {
setIsDone(!done);
};
const PipTask = ({
title,
description,
isDone,
handleCheck,
}: InterfacePipTask) => {
return (
<div className="box-border h-48 w-52 shrink-0 rounded-xl bg-white px-2 py-9 shadow-lg">
<header className="flex items-center">
Expand All @@ -23,7 +25,9 @@ const PipTask = ({ title, description, isDone }: InterfacePipTask) => {
>
<input
type="checkbox"
onChange={handleCheck}
className="h-6 w-6 cursor-pointer appearance-none rounded-full border border-primary border-primary/80 bg-primary-light/20 outline-primary transition-all checked:bg-primary checked:before:bg-primary hover:scale-105"
checked={isDone}
id="checkbox-pip-input"
/>
</label>
Expand Down
2 changes: 1 addition & 1 deletion components/Progressbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ProgressBar = ({ width, height }: InterfaceProgressBar) => {
return (
<div className="w-100 rounded-full bg-gray-200 p-1.5">
<div
className={`h-${height} rounded-full bg-gradient-to-r from-primary to-secondary`}
className={`h-${height} rounded-full bg-gradient-to-r from-primary to-secondary transition-all delay-100 ease-linear`}
style={{ width: `${width}%` }}
/>
</div>
Expand Down

0 comments on commit ddbe92b

Please sign in to comment.