From 3911ee2843cb3442802f216d227e21ba1b0e5f6e Mon Sep 17 00:00:00 2001 From: icarus Date: Sun, 2 Nov 2025 23:38:49 +0800 Subject: [PATCH] refactor(input): consolidate input components and update exports Move input component files to lowercase directory and simplify structure Remove unused button and password input components Update exports in components index file --- packages/ui/src/components/index.ts | 2 +- .../components/primitives/Input/button.tsx | 1 - .../src/components/primitives/Input/index.tsx | 14 ------ .../src/components/primitives/Input/input.tsx | 50 ------------------- .../components/primitives/Input/password.tsx | 1 - .../ui/src/components/primitives/input.tsx | 45 +++++++++++++++++ 6 files changed, 46 insertions(+), 67 deletions(-) delete mode 100644 packages/ui/src/components/primitives/Input/button.tsx delete mode 100644 packages/ui/src/components/primitives/Input/index.tsx delete mode 100644 packages/ui/src/components/primitives/Input/input.tsx delete mode 100644 packages/ui/src/components/primitives/Input/password.tsx create mode 100644 packages/ui/src/components/primitives/input.tsx diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index cabc443b56..86ac4c0a3e 100644 --- a/packages/ui/src/components/index.ts +++ b/packages/ui/src/components/index.ts @@ -84,7 +84,7 @@ export { Sortable } from './composites/Sortable' export * from './primitives/button' export * from './primitives/command' export * from './primitives/dialog' -export * from './primitives/Input' +export * from './primitives/input' export * from './primitives/popover' export * from './primitives/radioGroup' export * from './primitives/shadcn-io/dropzone' diff --git a/packages/ui/src/components/primitives/Input/button.tsx b/packages/ui/src/components/primitives/Input/button.tsx deleted file mode 100644 index e8e1f767b4..0000000000 --- a/packages/ui/src/components/primitives/Input/button.tsx +++ /dev/null @@ -1 +0,0 @@ -export function WithButton() {} diff --git a/packages/ui/src/components/primitives/Input/index.tsx b/packages/ui/src/components/primitives/Input/index.tsx deleted file mode 100644 index 4309609ddf..0000000000 --- a/packages/ui/src/components/primitives/Input/index.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { WithButton } from './button' -import { Input as InternalInput } from './input' -import { Password } from './password' - -type CompoundedComponent = typeof InternalInput & { - Password: typeof Password - Button: typeof WithButton -} - -const Input: CompoundedComponent = InternalInput as CompoundedComponent -Input.Password = Password -Input.Button = WithButton - -export { Input } diff --git a/packages/ui/src/components/primitives/Input/input.tsx b/packages/ui/src/components/primitives/Input/input.tsx deleted file mode 100644 index 86403b6661..0000000000 --- a/packages/ui/src/components/primitives/Input/input.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { cn } from '@cherrystudio/ui/utils' -import React from 'react' - -interface BaseInputProps extends React.ComponentPropsWithRef<'input'> { - startContent?: React.ReactNode - endContent?: React.ReactNode -} - -interface WithLabel extends BaseInputProps { - label: string - caption?: string -} - -interface WithoutLabel extends BaseInputProps { - label?: never - caption?: never -} - -type InputProps = WithLabel | WithoutLabel - -export function Input({ className, type, required, label, caption, ...props }: InputProps) { - const id = React.useId() - const input = ( - - ) - - if (label !== undefined) { - return ( -
- - {input} - {caption &&
{caption}
} -
- ) - } - - return input -} diff --git a/packages/ui/src/components/primitives/Input/password.tsx b/packages/ui/src/components/primitives/Input/password.tsx deleted file mode 100644 index 82b5c20fc7..0000000000 --- a/packages/ui/src/components/primitives/Input/password.tsx +++ /dev/null @@ -1 +0,0 @@ -export function Password() {} diff --git a/packages/ui/src/components/primitives/input.tsx b/packages/ui/src/components/primitives/input.tsx new file mode 100644 index 0000000000..e542ff474b --- /dev/null +++ b/packages/ui/src/components/primitives/input.tsx @@ -0,0 +1,45 @@ +import { cn } from '@cherrystudio/ui/utils' +import React, { useMemo } from 'react' + +export interface InputProps extends React.ComponentPropsWithRef<'input'> { + startContent?: React.ReactNode + endContent?: React.ReactNode + label?: string + caption?: string +} + +export function Input({ className, type, required, label, caption, ...props }: InputProps) { + const id = React.useId() + + const input = useMemo(() => { + const input = ( + + ) + + return input + }, [className, id, props, required, type]) + + if (label !== undefined) { + return ( +
+ + {input} + {caption &&
{caption}
} +
+ ) + } + + return input +}