Skip to content

Commit

Permalink
feat(add-inputs): Add default inputs and example form page (#136)
Browse files Browse the repository at this point in the history
* update status displays

* update cb urls

* sub type to action type

* things

* status stuff

* more status stuff

* yet even  more status stuff

* status stuff

* yup

* update export

* Add inputs and update styles

* add example form page

* fix lint error

* lint

* lint

* lint

* lint

* style stuff

* pushing pixels
  • Loading branch information
benjaminpaige authored Sep 25, 2023
1 parent b69c8cc commit db99d8e
Show file tree
Hide file tree
Showing 33 changed files with 1,103 additions and 110 deletions.
3 changes: 3 additions & 0 deletions src/services/ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
root: true,
extends: ["custom"],
rules: {
"@typescript-eslint/no-empty-interface": "off",
},
};
16 changes: 16 additions & 0 deletions src/services/ui/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/index.css",
"baseColor": "slate",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
12 changes: 9 additions & 3 deletions src/services/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@emotion/styled": "^11.11.0",
"@heroicons/react": "^2.0.17",
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^3.1.0",
"@hookform/resolvers": "^3.3.1",
"@mui/lab": "^5.0.0-alpha.136",
"@mui/material": "^5.14.1",
"@mui/styled-engine": "^5.13.2",
Expand All @@ -30,9 +30,15 @@
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toggle": "^1.0.3",
"@tanstack/react-query": "^4.29.1",
"@tanstack/react-query-devtools": "^4.29.5",
"@types/file-saver": "^2.0.5",
Expand All @@ -49,12 +55,12 @@
"react": "^18.2.0",
"react-day-picker": "^8.8.1",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-hook-form": "^7.46.2",
"react-loader-spinner": "^5.3.4",
"react-router-dom": "^6.10.0",
"react-select": "^5.7.4",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.6",
"tailwindcss-animate": "^1.0.7",
"uuid": "^9.0.0",
"zod": "^3.21.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/ui/src/components/AttachmentsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import JSZip from "jszip";
import { saveAs } from "file-saver";
import { OsMainSourceItem } from "shared-types";
import { useState } from "react";
import { Button } from "../Button";
import { Button } from "../Inputs/button";
import {
Table,
TableBody,
Expand Down
2 changes: 1 addition & 1 deletion src/services/ui/src/components/ExportButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExportToCsv } from "export-to-csv";
import { getAllSearchData } from "@/api";
import { Button } from "@/components/Button";
import { Button } from "@/components/Inputs";
import { Download, Loader } from "lucide-react";
import { useState } from "react";
import { motion } from "framer-motion";
Expand Down
4 changes: 2 additions & 2 deletions src/services/ui/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = {
export const Footer = ({ email, address }: Props) => {
return (
<footer>
<section className="bg-[#E1F3F8]">
<section className="bg-sky-100">
<div className="grid grid-cols-12 gap-4 px-10 py-4 max-w-screen-xl mx-auto">
<img
src={MedicaidLogo}
Expand All @@ -33,7 +33,7 @@ export const Footer = ({ email, address }: Props) => {
</p>
</div>
</section>
<div className="w-full bg-[#0171BC]">
<div className="w-full bg-primary">
<div className="px-10 py-4 text-white text-[.8rem] flex flex-col items-center sm:flex-row max-w-screen-xl mx-auto">
<div>
Email <strong className="font-bold">{email}</strong> for help or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const buttonVariants = cva(
{
variants: {
variant: {
default: "bg-primary text-slate-50 hover:bg-primary/90",
default:
"bg-primary text-slate-50 hover:bg-accent hover:text-accent-foreground",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { DayPicker } from "react-day-picker";

import { cn } from "@/lib/utils";
import { buttonVariants } from "../Button";
import { buttonVariants } from "./button";

export type CalendarProps = React.ComponentProps<typeof DayPicker> & {
className?: string;
Expand Down
179 changes: 179 additions & 0 deletions src/services/ui/src/components/Inputs/form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import * as React from "react";
import * as LabelPrimitive from "@radix-ui/react-label";
import { Slot } from "@radix-ui/react-slot";
import {
Controller,
ControllerProps,
FieldPath,
FieldValues,
FormProvider,
useFormContext,
} from "react-hook-form";

import { cn } from "@/lib/utils";
import { Label } from "@/components/Inputs/label";

const Form = FormProvider;

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
> = {
name: TName;
};

const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
);

const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
);
};

const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext);
const itemContext = React.useContext(FormItemContext);
const { getFieldState, formState } = useFormContext();

const fieldState = getFieldState(fieldContext.name, formState);

if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>");
}

const { id } = itemContext;

return {
id,
name: fieldContext.name,
formItemId: `${id}-form-item`,
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
};
};

type FormItemContextValue = {
id: string;
};

const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
);

const FormItem = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & { className?: string }
>(({ className, ...props }, ref) => {
const id = React.useId();

return (
<FormItemContext.Provider value={{ id }}>
<div ref={ref} className={cn("space-y-2", className)} {...props} />
</FormItemContext.Provider>
);
});
FormItem.displayName = "FormItem";

const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & {
className?: string;
}
>(({ className, ...props }, ref) => {
const { error, formItemId } = useFormField();

return (
<Label
ref={ref}
className={cn(error && "text-destructive", className)}
htmlFor={formItemId}
{...props}
/>
);
});
FormLabel.displayName = "FormLabel";

const FormControl = React.forwardRef<
React.ElementRef<typeof Slot>,
React.ComponentPropsWithoutRef<typeof Slot>
>(({ ...props }, ref) => {
const { error, formItemId, formDescriptionId, formMessageId } =
useFormField();

return (
<Slot
ref={ref}
id={formItemId}
aria-describedby={
!error
? `${formDescriptionId}`
: `${formDescriptionId} ${formMessageId}`
}
aria-invalid={!!error}
{...props}
/>
);
});
FormControl.displayName = "FormControl";

const FormDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement> & { className?: string }
>(({ className, ...props }, ref) => {
const { formDescriptionId } = useFormField();

return (
<p
ref={ref}
id={formDescriptionId}
className={cn("text-[0.8rem] text-muted-foreground", className)}
{...props}
/>
);
});
FormDescription.displayName = "FormDescription";

const FormMessage = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement> & { className?: string }
>(({ className, children, ...props }, ref) => {
const { error, formMessageId } = useFormField();
const body = error ? String(error?.message) : children;

if (!body) {
return null;
}

return (
<p
ref={ref}
id={formMessageId}
className={cn("text-[0.8rem] font-medium text-destructive", className)}
{...props}
>
{body}
</p>
);
});
FormMessage.displayName = "FormMessage";

export {
useFormField,
Form,
FormItem,
FormLabel,
FormControl,
FormDescription,
FormMessage,
FormField,
};
11 changes: 11 additions & 0 deletions src/services/ui/src/components/Inputs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from "./button";
export * from "./calendar";
export * from "./checkbox";
export * from "./form";
export * from "./input";
export * from "./label";
export * from "./radio-group";
export * from "./select";
export * from "./switch";
export * from "./textarea";
export * from "./toggle";
25 changes: 25 additions & 0 deletions src/services/ui/src/components/Inputs/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react";

import { cn } from "@/lib/utils";

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
);
}
);
Input.displayName = "Input";

export { Input };
24 changes: 24 additions & 0 deletions src/services/ui/src/components/Inputs/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react";
import * as LabelPrimitive from "@radix-ui/react-label";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
);

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
));
Label.displayName = LabelPrimitive.Root.displayName;

export { Label };
Loading

0 comments on commit db99d8e

Please sign in to comment.