Text input component #30
@ -1,4 +1,4 @@
|
||||
import type { InputHTMLAttributes, ReactNode, CSSProperties } from 'react';
|
||||
import type { InputHTMLAttributes, ReactNode } from 'react';
|
||||
// isValidElement: checks if something is a React element (e.g., <svg>, <MyComponent />)
|
||||
// cloneElement: creates a copy of a React element with modified/additional props
|
||||
import { cloneElement, isValidElement } from 'react';
|
||||
@ -40,16 +40,16 @@ const textClasses: Record<TextInputSize, string> = {
|
||||
lg: 'body-normal-lg',
|
||||
};
|
||||
|
||||
const iconContainerStyles: Record<TextInputSize, CSSProperties> = {
|
||||
sm: { width: 'var(--control-height-sm)', height: 'var(--control-height-sm)' },
|
||||
md: { width: 'var(--control-height-md)', height: 'var(--control-height-md)' },
|
||||
lg: { width: 'var(--control-height-lg)', height: 'var(--control-height-lg)' },
|
||||
const iconContainerSizeClasses: Record<TextInputSize, string> = {
|
||||
sm: 'w-(--control-height-sm) h-(--control-height-sm)',
|
||||
md: 'w-(--control-height-md) h-(--control-height-md)',
|
||||
lg: 'w-(--control-height-lg) h-(--control-height-lg)',
|
||||
};
|
||||
|
||||
const iconStyles: Record<TextInputSize, CSSProperties> = {
|
||||
sm: { width: 'var(--font-size-body-md)', height: 'var(--font-size-body-md)' },
|
||||
md: { width: 'var(--font-size-body-md)', height: 'var(--font-size-body-md)' },
|
||||
lg: { width: 'var(--font-size-body-lg)', height: 'var(--font-size-body-lg)' },
|
||||
const iconSizeClasses: Record<TextInputSize, string> = {
|
||||
sm: 'w-(--font-size-body-md) h-(--font-size-body-md)',
|
||||
md: 'w-(--font-size-body-md) h-(--font-size-body-md)',
|
||||
lg: 'w-(--font-size-body-lg) h-(--font-size-body-lg)',
|
||||
};
|
||||
|
||||
const baseClasses = 'bg-base-canvas border-[length:var(--border-width-sm)] border-base-ink-medium';
|
||||
@ -84,11 +84,10 @@ export default function TextInput({
|
||||
>
|
||||
{icon && (
|
||||
<div
|
||||
className="flex items-center justify-center shrink-0 text-base-ink-placeholder"
|
||||
style={iconContainerStyles[size]}
|
||||
className={`flex items-center justify-center shrink-0 text-base-ink-placeholder ${iconContainerSizeClasses[size]}`}
|
||||
>
|
||||
{isValidElement<{ style?: CSSProperties }>(icon)
|
||||
? cloneElement(icon, { style: iconStyles[size] })
|
||||
{isValidElement<{ className?: string }>(icon)
|
||||
? cloneElement(icon, { className: iconSizeClasses[size] })
|
||||
: icon}
|
||||
</div>
|
||||
)}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user