release: v4.1.0

This commit is contained in:
Amruth Pillai
2024-05-05 14:55:06 +02:00
parent 68252c35fc
commit e87b05a93a
282 changed files with 11461 additions and 10713 deletions

View File

@ -1,6 +1,5 @@
import { createContext, useContext } from "react";
import { useFormContext } from "react-hook-form";
import { FieldPath, FieldValues } from "react-hook-form";
import { FieldPath, FieldValues, useFormContext } from "react-hook-form";
type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
@ -14,16 +13,16 @@ type FormItemContextValue = { id: string };
export const FormItemContext = createContext<FormItemContextValue>({} as FormItemContextValue);
export const useFormField = () => {
const fieldContext = useContext(FormFieldContext);
const itemContext = useContext(FormItemContext);
const fieldContext = useContext(FormFieldContext) as FormFieldContextValue | undefined;
const itemContext = useContext(FormItemContext) as FormItemContextValue | undefined;
const { getFieldState, formState } = useFormContext();
const fieldState = getFieldState(fieldContext.name, formState);
if (!fieldContext) {
if (!fieldContext || !itemContext) {
throw new Error("useFormField should be used within <FormField>");
}
const fieldState = getFieldState(fieldContext.name, formState);
const { id } = itemContext;
return {

View File

@ -5,12 +5,12 @@ const COLOR_SCHEME_QUERY = "(prefers-color-scheme: dark)";
type Theme = "system" | "dark" | "light";
interface UseThemeOutput {
type UseThemeOutput = {
theme: Theme;
isDarkMode: boolean;
toggleTheme: () => void;
setTheme: Dispatch<SetStateAction<Theme>>;
}
};
export const useTheme = (): UseThemeOutput => {
const isDarkOS = useMediaQuery(COLOR_SCHEME_QUERY);
@ -23,15 +23,18 @@ export const useTheme = (): UseThemeOutput => {
useEffect(() => {
switch (theme) {
case "light":
case "light": {
setDarkMode(false);
break;
case "system":
}
case "system": {
setDarkMode(isDarkOS);
break;
case "dark":
}
case "dark": {
setDarkMode(true);
break;
}
}
}, [theme, isDarkOS]);