From f46794b5a0ad56c7423a0bae619e072b598f8059 Mon Sep 17 00:00:00 2001 From: mewdev Date: Sat, 23 Nov 2024 15:17:11 +0100 Subject: [PATCH] fix: fancyProgress step-status width updating accordingly --- .../stories/stepProgressFancy.stories.tsx | 13 +------- apps/web/app/[lang]/bottom-bar/page.tsx | 30 +++++++++++++------ .../src/ui/progress/stepProgressFancy.tsx | 21 ++++++++----- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/apps/design-system/stories/stepProgressFancy.stories.tsx b/apps/design-system/stories/stepProgressFancy.stories.tsx index 9c5f18b..fc20601 100644 --- a/apps/design-system/stories/stepProgressFancy.stories.tsx +++ b/apps/design-system/stories/stepProgressFancy.stories.tsx @@ -19,27 +19,16 @@ const steps = { { answerId: "6", status: true }, // { answerId: "7", status: false }, { answerId: "8", status: undefined }, // step with no sratus (e.g. not visited yet) - { answerId: "1", status: true }, // positive step (e.g. answerInFavour) - { answerId: "2", status: null }, - { answerId: "3", status: null }, // neutral step (e.g. visited / skipped, answerNeutral) - { answerId: "4", status: false }, // negative step (e.g. answerAgainst) - { answerId: "5", status: true }, - { answerId: "6", status: true }, // - { answerId: "7", status: false }, - { answerId: "8", status: undefined }, // step with no sratus (e.g. not visited yet) ], totalQuestion: 4, currentQuestion: 8, }; -const answerCount = steps.answers.length; - export const Fancy: StepProgressStory = { args: { steps, - answerCount, }, - render: (args) => , + render: (args) => , }; export default meta; diff --git a/apps/web/app/[lang]/bottom-bar/page.tsx b/apps/web/app/[lang]/bottom-bar/page.tsx index a7d2803..695899c 100644 --- a/apps/web/app/[lang]/bottom-bar/page.tsx +++ b/apps/web/app/[lang]/bottom-bar/page.tsx @@ -18,24 +18,31 @@ const steps = { { answerId: "2", status: null }, { answerId: "3", status: null }, // neutral step (e.g. visited / skipped, answerNeutral) { answerId: "4", status: false }, // negative step (e.g. answerAgainst) - { answerId: "5", status: true }, - { answerId: "6", status: true }, // - { answerId: "7", status: false }, - { answerId: "8", status: undefined }, // step with no sratus (e.g. not visited yet) + { answerId: "5", status: null }, + { answerId: "6", status: null }, // + { answerId: "7", status: null }, + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) + { answerId: "8", status: null }, // step with no sratus (e.g. not visited yet) ], totalQuestion: 4, currentQuestion: 8, }; -const answerCount = steps.answers.length; - export default function Page() { return ( // main wrapper -
+
{/* count status wrapper */} -
- +
+
{/* button wrapper */}
@@ -48,3 +55,8 @@ export default function Page() {
); } + +// TODO +// 1. Buttons on mobile wihout texts WIDTH! +// 2. Statuses proper styling (bg) check with live +// 3. Bottom bar positioning diff --git a/packages/design-system/src/ui/progress/stepProgressFancy.tsx b/packages/design-system/src/ui/progress/stepProgressFancy.tsx index a5a3dc1..64f06f1 100644 --- a/packages/design-system/src/ui/progress/stepProgressFancy.tsx +++ b/packages/design-system/src/ui/progress/stepProgressFancy.tsx @@ -1,8 +1,7 @@ -import React from "react"; +import React, { useEffect } from "react"; import { cva, VariantProps } from "class-variance-authority"; type Props = { - answerCount: number; steps: { currentQuestion: number; totalQuestion: number; @@ -31,15 +30,24 @@ const stepProgressVariants = cva("", { }, }); -const StepProgressFancy = ({ steps, answerCount }: Props): JSX.Element => { +const StepProgressFancy = ({ steps }: Props): JSX.Element => { + const answerCount = steps.answers.length; + + const [stepCount, setStepCount] = React.useState(answerCount); + + useEffect(() => { + setStepCount(stepCount); + }, [answerCount]); + const answersData = steps.answers; const { currentQuestion } = steps; return ( -
+
{answersData.map((answer, index) => { return (
{ ? "none" : null, height: currentQuestion === index + 1 ? "active" : "inactive", - // FIX bug with answer Count not updating - })} k1-w-[calc(100vw/${answerCount})]`} + })}`} >
); })} @@ -61,6 +68,4 @@ const StepProgressFancy = ({ steps, answerCount }: Props): JSX.Element => { ); }; -// TODO: Fix ternary operator with function with switch/case - export { StepProgressFancy };