diff --git a/src/components/catForm/catForm.stories.tsx b/src/components/catForm/catForm.stories.tsx new file mode 100644 index 0000000..3b0dcb3 --- /dev/null +++ b/src/components/catForm/catForm.stories.tsx @@ -0,0 +1,26 @@ +import type { Meta, StoryObj } from '@storybook/react'; + +import { CatForm, transformProps } from './catForm.tsx'; + +const meta: Meta = { + component: CatForm, + argTypes: { + add: {description: "Edit or Add", + control: "boolean"} + }, + render: (args: transformProps) => , +} + +export default meta; +type Story = StoryObj; + + + +/* + *👇 Render functions are a framework specific feature to allow you control on how the component renders. + * See https://storybook.js.org/docs/api/csf + * to learn how to use render functions. + */ +export const Primary: Story = { + render: (args) => , +}; diff --git a/src/components/catForm/catForm.tsx b/src/components/catForm/catForm.tsx new file mode 100644 index 0000000..23db033 --- /dev/null +++ b/src/components/catForm/catForm.tsx @@ -0,0 +1,112 @@ +import { useState } from "react" + +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { Textarea } from "@/components/ui/textarea" +import { Button } from "@/components/ui/button"; +import { ImageIcon } from "lucide-react" + +export interface transformProps { + add: boolean +} +const transform = (add: boolean | transformProps) => { + if (add == true) { + return "Edit Cat" + } + else { + return `+ Add a Cat` + } +} +export function CatForm(props: transformProps) { + const [avatar, setAvatar] = useState(null); + + const handleAvatarChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + + if (file) { + const imageUrl = URL.createObjectURL(file); + setAvatar(imageUrl); + } + }; + + + const removeAvatar = (): void => { + setAvatar(null); + }; + + const disableButton = (): boolean => { + return avatar === null; + }; + + + return <> + + {transform(props.add)} + + + {transform(props.add)} + +
+ {avatar ? ( +
+ Avatar +
+ ) : ( +
+ + +
+ )} + + + + + + + + + + + +
+
+
+ +} diff --git a/src/components/ui/textarea.tsx b/src/components/ui/textarea.tsx new file mode 100644 index 0000000..9f9a6dc --- /dev/null +++ b/src/components/ui/textarea.tsx @@ -0,0 +1,24 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +export interface TextareaProps + extends React.TextareaHTMLAttributes {} + +const Textarea = React.forwardRef( + ({ className, ...props }, ref) => { + return ( +