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

Commit

Permalink
feat: exports changes (#123)
Browse files Browse the repository at this point in the history
* fix: gitcoin-ui exports

* chore: improve select component

* fix: round dates validation
  • Loading branch information
nijoe1 authored Jan 23, 2025
1 parent 9f7743c commit 40f62a1
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 37 deletions.
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@
"import": "./dist/client.js",
"require": "./dist/client.js"
},
"./hooks": {
"types": "./dist/hooks.d.ts",
"import": "./dist/hooks.js",
"require": "./dist/hooks.js"
"./hooks/useCredentialVerification": {
"types": "./dist/use-credential-verification.d.ts",
"import": "./dist/use-credential-verification.js",
"require": "./dist/use-credential-verification.js"
},
"./hooks/useIndexedDB": {
"types": "./dist/use-indexed-db.d.ts",
"import": "./dist/use-indexed-db.js",
"require": "./dist/use-indexed-db.js"
},
"./hooks/usePersistForm": {
"types": "./dist/use-persist-form.d.ts",
"import": "./dist/use-persist-form.js",
"require": "./dist/use-persist-form.js"
},
"./hooks/useToast": {
"types": "./dist/use-toast.d.ts",
"import": "./dist/use-toast.js",
"require": "./dist/use-toast.js"
},
"./icons": {
"types": "./dist/icons.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from "./primitives/Accordion";
export * from "./primitives/Markdown";
export * from "./primitives/MarkdownEditor";
export * from "./components/Form";
export * from "./components/GenericProgressForm";
export * from "./components/MultipleSelect";
export * from "./features/pool/components/PoolList";
export * from "./features/program/components/ProgramList";
export * from "./components/ProgressModal";
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SelectFormControllerProps extends SelectProps {
export const SelectFormController: React.FC<any> = ({
name,
options,
defaultValue,
placeholder,
className,
size,
Expand All @@ -26,7 +27,8 @@ export const SelectFormController: React.FC<any> = ({
render={({ field }) => (
<Select
options={options}
defaultValue={field.value}
defaultValue={defaultValue}
value={field.value}
onValueChange={field.onChange}
placeholder={placeholder}
className={className}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Form/utils/validations/validateRoundDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export const validateRoundDates = (data: RoundDatesData, ctx: z.RefinementCtx) =
});
}

// Ensure application dates are within round dates
if (roundStart && appStart && appStart < roundStart) {
// Ensure application dates are before round dates
if (roundStart && appStart && appStart > roundStart) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Application start date must not be before the round start date",
message: "Application start date must not be after the round start date",
path: ["applications", "start"],
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProgressModal/ProgressModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from "react";

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

import { ProgressStatus, Step } from "@/types";

import { ProgressModal } from "./ProgressModal";
import { ProgressStatus, Step } from "./types";

const meta: Meta<typeof ProgressModal> = {
title: "Components/ProgressModal",
Expand Down
3 changes: 1 addition & 2 deletions src/components/ProgressModal/ProgressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import { Check, X } from "lucide-react";

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

import { ProgressStatus, Step } from "./types";

export interface ProgressModalProps {
steps: Step[];
isOpen?: boolean;
Expand Down
1 change: 0 additions & 1 deletion src/components/ProgressModal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./ProgressModal";
export * from "./utils";
export * from "./types";
2 changes: 1 addition & 1 deletion src/components/ProgressModal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Step, ProgressStatus } from "./types";
import { ProgressStatus, Step } from "@/types";

export const getOnchainEvaluationProgressSteps = ({
contractUpdatingStatus,
Expand Down
2 changes: 1 addition & 1 deletion src/features/checker/apps/Checker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Hex } from "viem";

import { Step } from "@/components/ProgressModal";
import { Step } from "@/types";

import { CheckerRouter } from "~checker/routers";
import { CheckerProvider } from "~checker/store";
Expand Down
3 changes: 2 additions & 1 deletion src/features/checker/hooks/usePerformOnChainReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { useState, useEffect, useMemo } from "react";

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

import { ProgressStatus, getOnchainEvaluationProgressSteps } from "@/components/ProgressModal";
import { getOnchainEvaluationProgressSteps } from "@/components/ProgressModal";
import { ProgressStatus } from "@/types";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

import { ProgressModal, Step } from "@/components/ProgressModal";
import { ProgressModal } from "@/components/ProgressModal";
import { Button } from "@/primitives/Button";
import { Modal } from "@/primitives/Modal";
import { Step } from "@/types";
import { Dialog, DialogHeader, DialogTitle } from "@/ui-shadcn/dialog";

export interface SubmitFinalEvaluationModalProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useState, useMemo, useEffect } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { match } from "ts-pattern";

import { Step } from "@/components/ProgressModal";
import { useToast } from "@/hooks/useToast";
import { Button } from "@/primitives/Button";
import { Icon, IconType } from "@/primitives/Icon";
import { StatCardGroup } from "@/primitives/StatCardGroup";
import { Step } from "@/types";

import { ProjectEvaluationList } from "~checker/components";
import { useGetApplicationsFinalEvaluationPage } from "~checker/hooks";
Expand Down
2 changes: 1 addition & 1 deletion src/features/checker/routers/CheckerRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useEffect } from "react";
import { match, P } from "ts-pattern";
import { Hex } from "viem";

import { Step } from "@/components/ProgressModal";
import { useCheckerContext } from "@/features/checker/store/hooks/useCheckerContext";
import { Step } from "@/types";

import { useInitialize } from "~checker/hooks";
import {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export * from "./primitives/Checkbox";

export * from "./components/CreateButton";
export * from "./components/IconLabel";
export * from "./components/ProgressModal";
export * from "./components/RadioGroupList";
export * from "./components/SideNav";
export * from "./components/Toaster";
6 changes: 5 additions & 1 deletion src/primitives/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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

export const Markdown = ({ children }: { children: string }) => {
import { withSSR } from "@/lib/withSSR";

const MarkdownComponent = ({ children }: { children: string }) => {
return (
<MarkdownPreview
source={children}
Expand All @@ -12,3 +14,5 @@ export const Markdown = ({ children }: { children: string }) => {
/>
);
};

export const Markdown = withSSR(MarkdownComponent);
18 changes: 18 additions & 0 deletions src/primitives/Select/Label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { cn } from "@/lib/utils";

export interface LabelProps {
icon?: React.ReactNode;
label: string;
className?: string;
iconPosition?: "left" | "right";
}

export const Label = ({ icon, label, className, iconPosition }: LabelProps) => {
return (
<div className={cn("flex items-center gap-2", className)}>
{icon && iconPosition === "left" && icon}
<p className={className}>{label}</p>
{icon && iconPosition === "right" && icon}
</div>
);
};
90 changes: 75 additions & 15 deletions src/primitives/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from "react";
import { SelectGroup } from "@radix-ui/react-select";
import { tv } from "tailwind-variants";

import { cn } from "@/lib/utils";
import { IconType } from "@/primitives/Icon";
import {
Select as ShadcnSelect,
Expand All @@ -13,9 +14,10 @@ import {
SelectLabel,
SelectItem,
SelectSeparator,
SelectValue,
} from "@/ui-shadcn/select";

import { Label } from "./Label";

export interface SelectProps {
options: {
groupLabel?: string;
Expand All @@ -30,6 +32,7 @@ export interface SelectProps {
}[];
placeholder?: React.ReactNode;
onValueChange?: (value: string) => void;
value?: string;
defaultValue?: string;
variant?: "default" | "outlined" | "filled";
size?: "sm" | "md" | "lg";
Expand All @@ -38,16 +41,47 @@ export interface SelectProps {

const selectStyles = tv({
base: "h-10 rounded-md border text-sm",
slots: {
trigger: "h-10 rounded-md border text-sm",
item: "",
label: "",
},
variants: {
variant: {
default: "border-transparent bg-white ",
outlined: "border-transparent bg-transparent",
filled: "bg-grey-200",
default: {
trigger: "border-transparent bg-white ",
content: "",
item: "",
label: "",
},
outlined: {
trigger: "border-transparent bg-transparent",
item: "",
label: "",
},
filled: {
trigger: " bg-grey-200 text-grey-900",
content: "",
item: "",
label: "",
},
},
size: {
sm: "h-8 text-xs",
md: "h-10 text-sm",
lg: "h-12 text-base",
sm: {
trigger: "h-8 gap-1 text-xs",
item: "h-8 text-xs",
label: "text-xs",
},
md: {
trigger: "h-10 px-3 py-2 text-sm",
item: "text-sm",
label: "text-sm",
},
lg: {
trigger: "h-12 gap-2 text-base",
item: "text-base",
label: "",
},
},
},
defaultVariants: {
Expand All @@ -56,33 +90,59 @@ const selectStyles = tv({
},
});

export const getSelectedItem = (
options: SelectProps["options"],
value?: string,
defaultValue?: string,
onValueChange?: (value: string) => void,
) => {
const itemValue = value || defaultValue;
const item = options
.find((option) => option.items.find((item) => item.value === itemValue))
?.items.find((item) => item.value === itemValue);
if (item) {
onValueChange?.(item.value);
}
return item;
};

export const Select = ({
options,
placeholder = "Select an option",
onValueChange,
defaultValue,
value,
variant,
size,
className,
}: SelectProps) => {
const item = getSelectedItem(options, value, defaultValue, onValueChange);
const { trigger, item: selectItem, label } = selectStyles({ variant, size, className });
return (
<ShadcnSelect defaultValue={defaultValue} onValueChange={onValueChange}>
<SelectTrigger className={selectStyles({ variant, size, className })}>
<SelectValue placeholder={defaultValue ?? placeholder} />
<ShadcnSelect
defaultValue={defaultValue}
onValueChange={onValueChange}
value={value || defaultValue}
>
<SelectTrigger className={cn(trigger(), className)}>
{item ? <Label {...item} /> : placeholder}
</SelectTrigger>
<SelectContent>
{options.map((group, index) => (
<React.Fragment key={index}>
{group.groupLabel && (
<SelectGroup>
<SelectLabel>{group.groupLabel}</SelectLabel>
<SelectLabel className={label()}>{group.groupLabel}</SelectLabel>
</SelectGroup>
)}
{group.items.map((item) => (
<SelectItem key={item.value} value={item.value} className="flex items-center gap-2">
{item.icon && item.iconPosition === "left" && item.icon}
{item.label}
{item.icon && item.iconPosition === "right" && item.icon}
<SelectItem key={item.value} value={item.value}>
<Label
label={item.label}
icon={item.icon}
iconPosition={item.iconPosition}
className={selectItem()}
/>
</SelectItem>
))}
{group.separator && <SelectSeparator />}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./indexedDB";
export * from "./markdown";
export * from "./onClickProps";
export * from "./pool";
export * from "./progressModal";
File renamed without changes.
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export default defineConfig({
entry: {
index: resolve(__dirname, "./src/index.ts"),
client: resolve(__dirname, "./src/client.ts"),
hooks: resolve(__dirname, "./src/hooks/index.ts"),
icons: resolve(__dirname, "./src/assets/icons/index.ts"),
lib: resolve(__dirname, "./src/lib/index.ts"),
logos: resolve(__dirname, "./src/assets/logos/index.ts"),
mocks: resolve(__dirname, "./src/mocks/handlers.ts"),
types: resolve(__dirname, "./src/types/index.ts"),
theme: resolve(__dirname, "./src/theme/index.ts"),
"use-credential-verification": resolve(
__dirname,
"./src/hooks/useCredentialVerification.ts",
),
"use-indexed-db": resolve(__dirname, "./src/hooks/useIndexedDB.ts"),
"use-persist-form": resolve(__dirname, "./src/hooks/usePersistForm.ts"),
"use-toast": resolve(__dirname, "./src/hooks/useToast.ts"),

// features
application: resolve(__dirname, "./src/features/application/index.ts"),
Expand Down

0 comments on commit 40f62a1

Please sign in to comment.