diff --git a/packages/raystack/components/image/image.tsx b/packages/raystack/components/image/image.tsx index 57b5c04b9..ae9e5cff9 100644 --- a/packages/raystack/components/image/image.tsx +++ b/packages/raystack/components/image/image.tsx @@ -1,7 +1,7 @@ 'use client'; -import { type VariantProps, cva } from 'class-variance-authority'; -import { ImgHTMLAttributes } from 'react'; +import { cva, type VariantProps } from 'class-variance-authority'; +import { ComponentProps, SyntheticEvent } from 'react'; import styles from './image.module.css'; @@ -25,12 +25,8 @@ const image = cva(styles.image, { } }); -interface ImageProps - extends ImgHTMLAttributes, - VariantProps { +interface ImageProps extends ComponentProps<'img'>, VariantProps { fallback?: string; - width?: string | number; - height?: string | number; } export function Image({ @@ -47,9 +43,7 @@ export function Image({ decoding = 'async', ...props }: ImageProps) { - const handleError = ( - event: React.SyntheticEvent - ) => { + const handleError = (event: SyntheticEvent) => { if (fallback) { event.currentTarget.src = fallback; } diff --git a/packages/raystack/components/indicator/indicator.tsx b/packages/raystack/components/indicator/indicator.tsx index 8fbc0a660..d78f82688 100644 --- a/packages/raystack/components/indicator/indicator.tsx +++ b/packages/raystack/components/indicator/indicator.tsx @@ -1,61 +1,55 @@ -import { cva, VariantProps } from "class-variance-authority"; -import { ComponentPropsWithoutRef, ReactNode } from "react"; +import { cva, VariantProps } from 'class-variance-authority'; +import { ComponentProps, ReactNode } from 'react'; import styles from './indicator.module.css'; const indicator = cva(styles.indicator, { variants: { variant: { - accent: styles["indicator-variant-accent"], - warning: styles["indicator-variant-warning"], - danger: styles["indicator-variant-danger"], - success: styles["indicator-variant-success"], - neutral: styles["indicator-variant-neutral"], + accent: styles['indicator-variant-accent'], + warning: styles['indicator-variant-warning'], + danger: styles['indicator-variant-danger'], + success: styles['indicator-variant-success'], + neutral: styles['indicator-variant-neutral'] } }, defaultVariants: { - variant: "accent", - }, + variant: 'accent' + } }); export interface IndicatorProps - extends ComponentPropsWithoutRef<"div">, + extends ComponentProps<'div'>, VariantProps { label?: string; children?: ReactNode; - "aria-label"?: string; + 'aria-label'?: string; } -export const Indicator = ({ - className, - variant, - label, - children, - "aria-label": ariaLabel, - ...props +export const Indicator = ({ + className, + variant, + label, + children, + 'aria-label': ariaLabel, + ...props }: IndicatorProps) => { const accessibilityLabel = ariaLabel || label || `${variant} indicator`; return (
{children} -
{label ? ( - + {label} ) : ( -
diff --git a/packages/raystack/components/input-field/input-field.tsx b/packages/raystack/components/input-field/input-field.tsx index d5b5847b3..026c29931 100644 --- a/packages/raystack/components/input-field/input-field.tsx +++ b/packages/raystack/components/input-field/input-field.tsx @@ -2,12 +2,7 @@ import { InfoCircledIcon } from '@radix-ui/react-icons'; import { cva, cx, type VariantProps } from 'class-variance-authority'; -import { - ComponentPropsWithoutRef, - forwardRef, - ReactNode, - RefObject -} from 'react'; +import { ComponentProps, ReactNode, RefObject } from 'react'; import { Chip } from '../chip'; import { Tooltip } from '../tooltip'; import styles from './input-field.module.css'; @@ -32,7 +27,7 @@ const inputWrapper = cva(styles.inputWrapper, { }); export interface InputFieldProps - extends Omit, 'error' | 'size'>, + extends Omit, 'error' | 'size'>, VariantProps { label?: string; helperText?: string; @@ -51,124 +46,118 @@ export interface InputFieldProps containerRef?: RefObject; } -export const InputField = forwardRef( - ( - { - className, - disabled, - label, - helperText, - placeholder, - error, - leadingIcon, - trailingIcon, - optional, - prefix, - suffix, - width, - chips, - maxChipsVisible = 2, - size, - infoTooltip, - variant = 'default', - containerRef, - ...props - }, - ref - ) => { - return ( -
- {label && ( -
- - {infoTooltip && ( - - - - - } - /> - {infoTooltip} - - )} -
- )} -
- {leadingIcon && ( -
{leadingIcon}
+export function InputField({ + className, + disabled, + label, + helperText, + placeholder, + error, + leadingIcon, + trailingIcon, + optional, + prefix, + suffix, + width, + chips, + maxChipsVisible = 2, + size, + infoTooltip, + variant = 'default', + containerRef, + ...props +}: InputFieldProps) { + return ( +
+ {label && ( +
+ + {infoTooltip && ( + + + + + } + /> + {infoTooltip} + )} - {prefix &&
{prefix}
} - -
- {chips?.slice(0, maxChipsVisible).map((chip, index) => ( - - {chip.label} - - ))} - {chips && chips.length > maxChipsVisible && ( - - +{chips.length - maxChipsVisible} - - )} - -
+
+ )} +
+ {leadingIcon && ( +
{leadingIcon}
+ )} + {prefix &&
{prefix}
} - {suffix &&
{suffix}
} - {trailingIcon && ( -
{trailingIcon}
+
+ {chips?.slice(0, maxChipsVisible).map((chip, index) => ( + + {chip.label} + + ))} + {chips && chips.length > maxChipsVisible && ( + + +{chips.length - maxChipsVisible} + )} -
- {(error || helperText) && ( - - {error || helperText} - + aria-invalid={!!error} + placeholder={placeholder} + disabled={disabled} + {...props} + /> +
+ + {suffix &&
{suffix}
} + {trailingIcon && ( +
{trailingIcon}
)}
- ); - } -); + {(error || helperText) && ( + + {error || helperText} + + )} +
+ ); +} InputField.displayName = 'InputField'; diff --git a/packages/raystack/components/label/label.tsx b/packages/raystack/components/label/label.tsx index 40c8e59eb..e50f36959 100644 --- a/packages/raystack/components/label/label.tsx +++ b/packages/raystack/components/label/label.tsx @@ -1,40 +1,41 @@ -import { cva, type VariantProps } from "class-variance-authority"; -import { HTMLAttributes, PropsWithChildren } from "react"; +import { cva, type VariantProps } from 'class-variance-authority'; +import { ComponentProps, PropsWithChildren } from 'react'; -import styles from "./label.module.css"; +import styles from './label.module.css'; const label = cva(styles.label, { variants: { size: { - small: styles["label-small"], - medium: styles["label-medium"], - large: styles["label-large"], + small: styles['label-small'], + medium: styles['label-medium'], + large: styles['label-large'] }, required: { - true: styles["label-required"], + true: styles['label-required'] } }, defaultVariants: { - size: "small", - required: false, - }, + size: 'small', + required: false + } }); -interface LabelProps extends PropsWithChildren>, - Omit, 'required'> { +interface LabelProps + extends PropsWithChildren>, + Omit, 'required'> { required?: boolean; requiredIndicator?: string; htmlFor?: string; } -export function Label({ - children, - className, - size, - required, - requiredIndicator = "*", +export function Label({ + children, + className, + size, + required, + requiredIndicator = '*', htmlFor, - ...props + ...props }: LabelProps) { return (