Skip to content

Commit d7d9891

Browse files
authored
Feat/add allocation bar on ballot form (#80)
1 parent c2b1f17 commit d7d9891

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

.changeset/many-carrots-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitcoin/ui": patch
3+
---
4+
5+
feat: adds an allocation bar to the ballot form

packages/ui/src/features/retrofunding/components/BallotForm/BallotForm.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ export const BallotForm: React.FC<BallotFormProps> = ({
180180
() => sortFieldsByOrder(itemsArray, sortOrder || DEFAULT_SORT_ORDER),
181181
[itemsArray, sortOrder],
182182
);
183+
184+
const sumOfAllocations = useMemo(() => {
185+
return getTotalAllocation(items);
186+
}, [items]);
187+
183188
if (!isReady) return null;
184189

185190
return (
@@ -189,7 +194,11 @@ export const BallotForm: React.FC<BallotFormProps> = ({
189194
onShare={onShare}
190195
/>
191196
<div className="w-[720px] space-y-4 rounded-xl border border-grey-300 bg-grey-50 p-10">
192-
<BallotHeader sortOrder={sortOrder ?? DEFAULT_SORT_ORDER} setSortOrder={setSortOrder} />
197+
<BallotHeader
198+
sortOrder={sortOrder ?? DEFAULT_SORT_ORDER}
199+
setSortOrder={setSortOrder}
200+
sumOfAllocations={sumOfAllocations}
201+
/>
193202
<div>
194203
{sortedFields.map((item, idx) => {
195204
const { metricId } = item;

packages/ui/src/features/retrofunding/components/BallotForm/components/BallotHeader.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { tv } from "tailwind-variants";
22

33
import { sortOptions } from "@/features/retrofunding/utils/metricsBallot";
4-
import { Select } from "@/primitives";
4+
import { ProgressBar, Select } from "@/primitives";
55

66
const variants = tv({
77
slots: {
88
container: "flex items-center justify-between text-sm text-grey-500",
99
titleContainer: "flex w-[520px] flex-col justify-start gap-2",
1010
title: "text-lg font-medium text-black",
1111
description: "text-sm font-normal text-grey-900",
12+
progressBarContainer: "flex items-center gap-2",
13+
progressBarLabel: "font-ui-sans text-sm font-normal text-black",
1214
select:
1315
"w-fit shrink-0 px-3 py-2 font-medium ring-0 hover:ring-0 focus:outline-none focus:ring-0 active:ring-0",
1416
},
@@ -18,14 +20,19 @@ const BALLOT_INFO =
1820
"Distribute your votes across the metrics on your ballot as percentages, ensuring they add up to 100% before submission. You can hide metrics if needed and revisit this step anytime before finalizing your ballot.";
1921

2022
interface BallotHeaderProps {
23+
sumOfAllocations: number;
2124
sortOrder: string;
2225
setSortOrder: (value: string) => void;
2326
}
2427

25-
export const BallotHeader = ({ sortOrder, setSortOrder }: BallotHeaderProps) => (
28+
export const BallotHeader = ({ sortOrder, setSortOrder, sumOfAllocations }: BallotHeaderProps) => (
2629
<div className={variants().container()}>
2730
<div className={variants().titleContainer()}>
28-
<span className={variants().title()}>Your Ballot</span>
31+
<div className={variants().progressBarContainer()}>
32+
<span className={variants().title()}>Your Ballot</span>
33+
<ProgressBar variant="green-sm" value={sumOfAllocations} max={100} />
34+
<span className={variants().progressBarLabel()}>{sumOfAllocations}% allocated</span>
35+
</div>
2936
<span className={variants().description()}>{BALLOT_INFO}</span>
3037
</div>
3138
<Select

packages/ui/src/primitives/ProgressBar/ProgressBar.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ProgressBarProps {
1212
withLabel?: boolean;
1313
}
1414

15-
export type ProgressVariants = "default" | "green" | "green-md";
15+
export type ProgressVariants = "default" | "green" | "green-sm" | "green-md";
1616

1717
const progressVariants = tv({
1818
slots: {
@@ -29,6 +29,10 @@ const progressVariants = tv({
2929
root: " bg-grey-100",
3030
indicator: "bg-moss-700",
3131
},
32+
"green-sm": {
33+
root: "h-2 w-[136px] bg-grey-100",
34+
indicator: "bg-moss-700",
35+
},
3236
"green-md": {
3337
root: "w-[228px] bg-grey-100",
3438
indicator: "bg-moss-700",
@@ -43,7 +47,7 @@ const progressVariants = tv({
4347
export const ProgressBar = React.forwardRef<
4448
React.ElementRef<typeof ProgressPrimitive.Root>,
4549
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> & {
46-
variant?: "default" | "green" | "green-md";
50+
variant?: "default" | "green" | "green-sm" | "green-md";
4751
withLabel?: boolean;
4852
}
4953
>(({ className, value, variant = "default", withLabel = false, ...props }, ref) => {

0 commit comments

Comments
 (0)