Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 40f62a1

Browse files
authored
feat: exports changes (#123)
* fix: gitcoin-ui exports * chore: improve select component * fix: round dates validation
1 parent 9f7743c commit 40f62a1

File tree

20 files changed

+143
-37
lines changed

20 files changed

+143
-37
lines changed

package.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,25 @@
3333
"import": "./dist/client.js",
3434
"require": "./dist/client.js"
3535
},
36-
"./hooks": {
37-
"types": "./dist/hooks.d.ts",
38-
"import": "./dist/hooks.js",
39-
"require": "./dist/hooks.js"
36+
"./hooks/useCredentialVerification": {
37+
"types": "./dist/use-credential-verification.d.ts",
38+
"import": "./dist/use-credential-verification.js",
39+
"require": "./dist/use-credential-verification.js"
40+
},
41+
"./hooks/useIndexedDB": {
42+
"types": "./dist/use-indexed-db.d.ts",
43+
"import": "./dist/use-indexed-db.js",
44+
"require": "./dist/use-indexed-db.js"
45+
},
46+
"./hooks/usePersistForm": {
47+
"types": "./dist/use-persist-form.d.ts",
48+
"import": "./dist/use-persist-form.js",
49+
"require": "./dist/use-persist-form.js"
50+
},
51+
"./hooks/useToast": {
52+
"types": "./dist/use-toast.d.ts",
53+
"import": "./dist/use-toast.js",
54+
"require": "./dist/use-toast.js"
4055
},
4156
"./icons": {
4257
"types": "./dist/icons.d.ts",

src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export * from "./primitives/Accordion";
2-
export * from "./primitives/Markdown";
32
export * from "./primitives/MarkdownEditor";
43
export * from "./components/Form";
54
export * from "./components/GenericProgressForm";
65
export * from "./components/MultipleSelect";
76
export * from "./features/pool/components/PoolList";
87
export * from "./features/program/components/ProgramList";
8+
export * from "./components/ProgressModal";

src/components/Form/FormControllers/SelectFormController/SelectFormController.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface SelectFormControllerProps extends SelectProps {
1212
export const SelectFormController: React.FC<any> = ({
1313
name,
1414
options,
15+
defaultValue,
1516
placeholder,
1617
className,
1718
size,
@@ -26,7 +27,8 @@ export const SelectFormController: React.FC<any> = ({
2627
render={({ field }) => (
2728
<Select
2829
options={options}
29-
defaultValue={field.value}
30+
defaultValue={defaultValue}
31+
value={field.value}
3032
onValueChange={field.onChange}
3133
placeholder={placeholder}
3234
className={className}

src/components/Form/utils/validations/validateRoundDates.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export const validateRoundDates = (data: RoundDatesData, ctx: z.RefinementCtx) =
8686
});
8787
}
8888

89-
// Ensure application dates are within round dates
90-
if (roundStart && appStart && appStart < roundStart) {
89+
// Ensure application dates are before round dates
90+
if (roundStart && appStart && appStart > roundStart) {
9191
ctx.addIssue({
9292
code: z.ZodIssueCode.custom,
93-
message: "Application start date must not be before the round start date",
93+
message: "Application start date must not be after the round start date",
9494
path: ["applications", "start"],
9595
});
9696
}

src/components/ProgressModal/ProgressModal.stories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from "react";
22

33
import type { Meta, StoryObj } from "@storybook/react";
44

5+
import { ProgressStatus, Step } from "@/types";
6+
57
import { ProgressModal } from "./ProgressModal";
6-
import { ProgressStatus, Step } from "./types";
78

89
const meta: Meta<typeof ProgressModal> = {
910
title: "Components/ProgressModal",

src/components/ProgressModal/ProgressModal.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import { Check, X } from "lucide-react";
44

55
import { Modal } from "@/primitives/Modal";
6+
import { ProgressStatus, Step } from "@/types";
67
import { Dialog, DialogHeader, DialogTitle, DialogDescription } from "@/ui-shadcn/dialog";
78

8-
import { ProgressStatus, Step } from "./types";
9-
109
export interface ProgressModalProps {
1110
steps: Step[];
1211
isOpen?: boolean;

src/components/ProgressModal/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "./ProgressModal";
22
export * from "./utils";
3-
export * from "./types";

src/components/ProgressModal/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Step, ProgressStatus } from "./types";
1+
import { ProgressStatus, Step } from "@/types";
22

33
export const getOnchainEvaluationProgressSteps = ({
44
contractUpdatingStatus,

src/features/checker/apps/Checker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Hex } from "viem";
44

5-
import { Step } from "@/components/ProgressModal";
5+
import { Step } from "@/types";
66

77
import { CheckerRouter } from "~checker/routers";
88
import { CheckerProvider } from "~checker/store";

src/features/checker/hooks/usePerformOnChainReview.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { useState, useEffect, useMemo } from "react";
44

55
import { useMutation } from "@tanstack/react-query";
66

7-
import { ProgressStatus, getOnchainEvaluationProgressSteps } from "@/components/ProgressModal";
7+
import { getOnchainEvaluationProgressSteps } from "@/components/ProgressModal";
8+
import { ProgressStatus } from "@/types";
89

910
import { ReviewBody } from "../types";
1011

src/features/checker/pages/SubmitFinalEvaluationPage/SubmitFinalEvaluationModal.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import { Check, X } from "lucide-react";
44

5-
import { ProgressModal, Step } from "@/components/ProgressModal";
5+
import { ProgressModal } from "@/components/ProgressModal";
66
import { Button } from "@/primitives/Button";
77
import { Modal } from "@/primitives/Modal";
8+
import { Step } from "@/types";
89
import { Dialog, DialogHeader, DialogTitle } from "@/ui-shadcn/dialog";
910

1011
export interface SubmitFinalEvaluationModalProps {

src/features/checker/pages/SubmitFinalEvaluationPage/SubmitFinalEvaluationPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { useState, useMemo, useEffect } from "react";
55
import { useQueryClient } from "@tanstack/react-query";
66
import { match } from "ts-pattern";
77

8-
import { Step } from "@/components/ProgressModal";
98
import { useToast } from "@/hooks/useToast";
109
import { Button } from "@/primitives/Button";
1110
import { Icon, IconType } from "@/primitives/Icon";
1211
import { StatCardGroup } from "@/primitives/StatCardGroup";
12+
import { Step } from "@/types";
1313

1414
import { ProjectEvaluationList } from "~checker/components";
1515
import { useGetApplicationsFinalEvaluationPage } from "~checker/hooks";

src/features/checker/routers/CheckerRouter.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { useEffect } from "react";
55
import { match, P } from "ts-pattern";
66
import { Hex } from "viem";
77

8-
import { Step } from "@/components/ProgressModal";
98
import { useCheckerContext } from "@/features/checker/store/hooks/useCheckerContext";
9+
import { Step } from "@/types";
1010

1111
import { useInitialize } from "~checker/hooks";
1212
import {

src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export * from "./primitives/Checkbox";
2727

2828
export * from "./components/CreateButton";
2929
export * from "./components/IconLabel";
30-
export * from "./components/ProgressModal";
3130
export * from "./components/RadioGroupList";
3231
export * from "./components/SideNav";
3332
export * from "./components/Toaster";

src/primitives/Markdown/Markdown.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import MarkdownPreview from "@uiw/react-markdown-preview";
44

5-
export const Markdown = ({ children }: { children: string }) => {
5+
import { withSSR } from "@/lib/withSSR";
6+
7+
const MarkdownComponent = ({ children }: { children: string }) => {
68
return (
79
<MarkdownPreview
810
source={children}
@@ -12,3 +14,5 @@ export const Markdown = ({ children }: { children: string }) => {
1214
/>
1315
);
1416
};
17+
18+
export const Markdown = withSSR(MarkdownComponent);

src/primitives/Select/Label.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { cn } from "@/lib/utils";
2+
3+
export interface LabelProps {
4+
icon?: React.ReactNode;
5+
label: string;
6+
className?: string;
7+
iconPosition?: "left" | "right";
8+
}
9+
10+
export const Label = ({ icon, label, className, iconPosition }: LabelProps) => {
11+
return (
12+
<div className={cn("flex items-center gap-2", className)}>
13+
{icon && iconPosition === "left" && icon}
14+
<p className={className}>{label}</p>
15+
{icon && iconPosition === "right" && icon}
16+
</div>
17+
);
18+
};

src/primitives/Select/Select.tsx

+75-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as React from "react";
55
import { SelectGroup } from "@radix-ui/react-select";
66
import { tv } from "tailwind-variants";
77

8+
import { cn } from "@/lib/utils";
89
import { IconType } from "@/primitives/Icon";
910
import {
1011
Select as ShadcnSelect,
@@ -13,9 +14,10 @@ import {
1314
SelectLabel,
1415
SelectItem,
1516
SelectSeparator,
16-
SelectValue,
1717
} from "@/ui-shadcn/select";
1818

19+
import { Label } from "./Label";
20+
1921
export interface SelectProps {
2022
options: {
2123
groupLabel?: string;
@@ -30,6 +32,7 @@ export interface SelectProps {
3032
}[];
3133
placeholder?: React.ReactNode;
3234
onValueChange?: (value: string) => void;
35+
value?: string;
3336
defaultValue?: string;
3437
variant?: "default" | "outlined" | "filled";
3538
size?: "sm" | "md" | "lg";
@@ -38,16 +41,47 @@ export interface SelectProps {
3841

3942
const selectStyles = tv({
4043
base: "h-10 rounded-md border text-sm",
44+
slots: {
45+
trigger: "h-10 rounded-md border text-sm",
46+
item: "",
47+
label: "",
48+
},
4149
variants: {
4250
variant: {
43-
default: "border-transparent bg-white ",
44-
outlined: "border-transparent bg-transparent",
45-
filled: "bg-grey-200",
51+
default: {
52+
trigger: "border-transparent bg-white ",
53+
content: "",
54+
item: "",
55+
label: "",
56+
},
57+
outlined: {
58+
trigger: "border-transparent bg-transparent",
59+
item: "",
60+
label: "",
61+
},
62+
filled: {
63+
trigger: " bg-grey-200 text-grey-900",
64+
content: "",
65+
item: "",
66+
label: "",
67+
},
4668
},
4769
size: {
48-
sm: "h-8 text-xs",
49-
md: "h-10 text-sm",
50-
lg: "h-12 text-base",
70+
sm: {
71+
trigger: "h-8 gap-1 text-xs",
72+
item: "h-8 text-xs",
73+
label: "text-xs",
74+
},
75+
md: {
76+
trigger: "h-10 px-3 py-2 text-sm",
77+
item: "text-sm",
78+
label: "text-sm",
79+
},
80+
lg: {
81+
trigger: "h-12 gap-2 text-base",
82+
item: "text-base",
83+
label: "",
84+
},
5185
},
5286
},
5387
defaultVariants: {
@@ -56,33 +90,59 @@ const selectStyles = tv({
5690
},
5791
});
5892

93+
export const getSelectedItem = (
94+
options: SelectProps["options"],
95+
value?: string,
96+
defaultValue?: string,
97+
onValueChange?: (value: string) => void,
98+
) => {
99+
const itemValue = value || defaultValue;
100+
const item = options
101+
.find((option) => option.items.find((item) => item.value === itemValue))
102+
?.items.find((item) => item.value === itemValue);
103+
if (item) {
104+
onValueChange?.(item.value);
105+
}
106+
return item;
107+
};
108+
59109
export const Select = ({
60110
options,
61111
placeholder = "Select an option",
62112
onValueChange,
63113
defaultValue,
114+
value,
64115
variant,
65116
size,
66117
className,
67118
}: SelectProps) => {
119+
const item = getSelectedItem(options, value, defaultValue, onValueChange);
120+
const { trigger, item: selectItem, label } = selectStyles({ variant, size, className });
68121
return (
69-
<ShadcnSelect defaultValue={defaultValue} onValueChange={onValueChange}>
70-
<SelectTrigger className={selectStyles({ variant, size, className })}>
71-
<SelectValue placeholder={defaultValue ?? placeholder} />
122+
<ShadcnSelect
123+
defaultValue={defaultValue}
124+
onValueChange={onValueChange}
125+
value={value || defaultValue}
126+
>
127+
<SelectTrigger className={cn(trigger(), className)}>
128+
{item ? <Label {...item} /> : placeholder}
72129
</SelectTrigger>
73130
<SelectContent>
74131
{options.map((group, index) => (
75132
<React.Fragment key={index}>
76133
{group.groupLabel && (
77134
<SelectGroup>
78-
<SelectLabel>{group.groupLabel}</SelectLabel>
135+
<SelectLabel className={label()}>{group.groupLabel}</SelectLabel>
79136
</SelectGroup>
80137
)}
81138
{group.items.map((item) => (
82-
<SelectItem key={item.value} value={item.value} className="flex items-center gap-2">
83-
{item.icon && item.iconPosition === "left" && item.icon}
84-
{item.label}
85-
{item.icon && item.iconPosition === "right" && item.icon}
139+
<SelectItem key={item.value} value={item.value}>
140+
<Label
141+
label={item.label}
142+
icon={item.icon}
143+
iconPosition={item.iconPosition}
144+
className={selectItem()}
145+
/>
86146
</SelectItem>
87147
))}
88148
{group.separator && <SelectSeparator />}

src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./indexedDB";
33
export * from "./markdown";
44
export * from "./onClickProps";
55
export * from "./pool";
6+
export * from "./progressModal";
File renamed without changes.

vite.config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ export default defineConfig({
1414
entry: {
1515
index: resolve(__dirname, "./src/index.ts"),
1616
client: resolve(__dirname, "./src/client.ts"),
17-
hooks: resolve(__dirname, "./src/hooks/index.ts"),
1817
icons: resolve(__dirname, "./src/assets/icons/index.ts"),
1918
lib: resolve(__dirname, "./src/lib/index.ts"),
2019
logos: resolve(__dirname, "./src/assets/logos/index.ts"),
2120
mocks: resolve(__dirname, "./src/mocks/handlers.ts"),
2221
types: resolve(__dirname, "./src/types/index.ts"),
2322
theme: resolve(__dirname, "./src/theme/index.ts"),
23+
"use-credential-verification": resolve(
24+
__dirname,
25+
"./src/hooks/useCredentialVerification.ts",
26+
),
27+
"use-indexed-db": resolve(__dirname, "./src/hooks/useIndexedDB.ts"),
28+
"use-persist-form": resolve(__dirname, "./src/hooks/usePersistForm.ts"),
29+
"use-toast": resolve(__dirname, "./src/hooks/useToast.ts"),
2430

2531
// features
2632
application: resolve(__dirname, "./src/features/application/index.ts"),

0 commit comments

Comments
 (0)