feat: fix responsive layout, add theme switcher

This commit is contained in:
2024-08-17 00:21:23 +07:00
parent 43af9c8658
commit f503b261f5
22 changed files with 349 additions and 100 deletions
+4 -3
View File
@@ -1,5 +1,5 @@
import { cn } from "@/lib/utils";
import { ComponentPropsWithoutRef } from "react";
import { ComponentPropsWithoutRef, forwardRef } from "react";
import BaseSelect from "react-select";
import Creatable from "react-select/creatable";
@@ -8,11 +8,12 @@ type Props = ComponentPropsWithoutRef<typeof BaseSelect> & {
onCreateOption?: (inputValue: string) => void;
};
const Select = ({ creatable, ...props }: Props) => {
const Select = forwardRef<any, Props>(({ creatable, ...props }, ref) => {
const Comp = creatable ? Creatable : BaseSelect;
return (
<Comp
ref={ref}
unstyled
classNames={{
control: (p) =>
@@ -42,6 +43,6 @@ const Select = ({ creatable, ...props }: Props) => {
{...props}
/>
);
};
});
export default Select;
+51
View File
@@ -0,0 +1,51 @@
import React, { forwardRef } from "react";
import { Toggle as BaseToggle } from "react-daisyui";
import FormControl from "./form-control";
import { FieldValues } from "react-hook-form";
type ToggleProps = Omit<
React.ComponentPropsWithoutRef<typeof BaseToggle>,
"form"
> & { label?: string };
const Toggle = forwardRef<HTMLInputElement, ToggleProps>(
({ label, ...props }, ref) => {
return (
<label className="inline-flex justify-start label label-text gap-2 cursor-pointer">
<BaseToggle ref={ref} {...props} />
{label}
</label>
);
}
);
type ToggleFieldProps<T extends FieldValues> = Omit<
React.ComponentPropsWithoutRef<typeof FormControl<T>>,
"render"
> &
ToggleProps & {
inputClassName?: string;
};
export const ToggleField = <T extends FieldValues>({
form,
name,
title,
className,
inputClassName,
...props
}: ToggleFieldProps<T>) => {
return (
<FormControl
form={form}
name={name}
title={title}
className={className}
render={(field) => (
<Toggle {...props} {...field} className={inputClassName} />
)}
/>
);
};
export default Toggle;