From 4936d7dc474f170a84dbb87a5c3747e9bf2c9824 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Mar 2026 12:37:59 +0000 Subject: [PATCH] 0.14.3 - Added icon and rightButton props to Input component Extended the Input component to support a left icon (LucideIcon) and an optional right button (ReactNode). When adornments are present, the input is wrapped in a flex container with focus-within ring styling. Added a UUIDWithRandomize story demonstrating a KeyRound icon with a Dices button that randomizes the UUID value. https://claude.ai/code/session_0172x97hKBW9FCEphQEBP2YJ --- package.json | 2 +- src/components/ui/input/Input.stories.tsx | 38 ++++++++++++++++++----- src/components/ui/input/input.tsx | 37 +++++++++++++++++++--- 3 files changed, 64 insertions(+), 13 deletions(-) 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";