diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index 86ac4c0a3e..cabc443b56 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 new file mode 100644 index 0000000000..e8e1f767b4 --- /dev/null +++ b/packages/ui/src/components/primitives/Input/button.tsx @@ -0,0 +1 @@ +export function WithButton() {} diff --git a/packages/ui/src/components/primitives/Input/index.tsx b/packages/ui/src/components/primitives/Input/index.tsx new file mode 100644 index 0000000000..4309609ddf --- /dev/null +++ b/packages/ui/src/components/primitives/Input/index.tsx @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000000..86403b6661 --- /dev/null +++ b/packages/ui/src/components/primitives/Input/input.tsx @@ -0,0 +1,50 @@ +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 ( +