diff --git a/package.json b/package.json index 922b6cd..161a466 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@schemavaults/ui", - "version": "0.14.2", + "version": "0.14.3", "private": false, "license": "UNLICENSED", "description": "React.js UI components for SchemaVaults frontend applications", diff --git a/src/components/ui/input/Input.stories.tsx b/src/components/ui/input/Input.stories.tsx index 27bc6c6..a582ca3 100644 --- a/src/components/ui/input/Input.stories.tsx +++ b/src/components/ui/input/Input.stories.tsx @@ -1,18 +1,18 @@ +import { useState, type ReactElement } from "react"; import type { Meta, StoryObj } from "@storybook/react"; -import Input from "./input"; import { fn } from "@storybook/test"; +import { Dices, KeyRound } from "lucide-react"; + +import Input from "./input"; +import { Button } from "@/components/ui/button"; -// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export const meta = { title: "Components/Input", component: Input, parameters: { - // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout layout: "centered", }, - // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs tags: ["autodocs"], - // More on argTypes: https://storybook.js.org/docs/api/argtypes argTypes: { placeholder: { type: "string", @@ -26,7 +26,6 @@ const meta = { }, }, }, - // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args args: { onChange: (): void => { fn(); @@ -37,7 +36,6 @@ const meta = { export default meta; type Story = StoryObj; -// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args export const DefaultTextInput: Story = { args: {}, }; @@ -62,3 +60,29 @@ export const WithPlaceholder: Story = { placeholder: "This text input has placeholder text!", }, }; + +function UUIDWithRandomizeRenderer(): ReactElement { + const [value, setValue] = useState(crypto.randomUUID()); + return ( + setValue(e.target.value)} + rightButton={ + + } + /> + ); +} + +export const UUIDWithRandomize: Story = { + render: (): ReactElement => , +}; diff --git a/src/components/ui/input/input.tsx b/src/components/ui/input/input.tsx index 2eda34d..1fd3a42 100644 --- a/src/components/ui/input/input.tsx +++ b/src/components/ui/input/input.tsx @@ -1,22 +1,49 @@ "use client"; -import type { InputHTMLAttributes, ReactElement } from "react"; +import type { InputHTMLAttributes, ReactElement, ReactNode } from "react"; +import type { LucideIcon } from "lucide-react"; import { cn } from "@/lib/utils"; -export interface InputProps extends InputHTMLAttributes {} +export interface InputProps extends InputHTMLAttributes { + icon?: LucideIcon; + rightButton?: ReactNode; +} -const Input = ({ className, type, ...props }: InputProps): ReactElement => { - return ( +const Input = ({ + className, + type, + icon: Icon, + rightButton, + ...props +}: InputProps): ReactElement => { + const hasAdornments = Icon || rightButton; + + const inputElement = ( ); + + if (!hasAdornments) return inputElement; + + return ( +
+ {Icon && ( + + )} + {inputElement} + {rightButton} +
+ ); }; Input.displayName = "Input";