Skip to content

Commit

Permalink
fix: fancyProgress step-status width updating accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
mewdev committed Nov 23, 2024
1 parent 7fbe58e commit f46794b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
13 changes: 1 addition & 12 deletions apps/design-system/stories/stepProgressFancy.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => <StepProgressFancy {...args} answerCount={answerCount} />,
render: (args) => <StepProgressFancy {...args} />,
};

export default meta;
30 changes: 21 additions & 9 deletions apps/web/app/[lang]/bottom-bar/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div className="sticky bottom-0 bg-slate-300">
<div className="sticky bottom-0 border border-red-500">
{/* count status wrapper */}
<div className="w-full">
<StepProgressFancy steps={steps} answerCount={answerCount} />
<div className="w-screen">
<StepProgressFancy steps={steps} />
</div>
{/* button wrapper */}
<div className="flex justify-center p-4">
Expand All @@ -48,3 +55,8 @@ export default function Page() {
</div>
);
}

// TODO
// 1. Buttons on mobile wihout texts WIDTH!
// 2. Statuses proper styling (bg) check with live
// 3. Bottom bar positioning
21 changes: 13 additions & 8 deletions packages/design-system/src/ui/progress/stepProgressFancy.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 (
<div className="k1-flex k1-items-center">
<div className="k1-flex k1-items-center k1-justify-start k1-h-1">
{answersData.map((answer, index) => {
return (
<div
style={{ width: `calc(100vw / ${stepCount})` }}
className={`${stepProgressVariants({
status:
answer.status === true
Expand All @@ -52,15 +60,12 @@ const StepProgressFancy = ({ steps, answerCount }: Props): JSX.Element => {
? "none"
: null,
height: currentQuestion === index + 1 ? "active" : "inactive",
// FIX bug with answer Count not updating
})} k1-w-[calc(100vw/${answerCount})]`}
})}`}
></div>
);
})}
</div>
);
};

// TODO: Fix ternary operator with function with switch/case

export { StepProgressFancy };

0 comments on commit f46794b

Please sign in to comment.