diff --git a/libs/ui-toolkit/src/components/button/Button.tsx b/libs/ui-toolkit/src/components/button/button.tsx similarity index 64% rename from libs/ui-toolkit/src/components/button/Button.tsx rename to libs/ui-toolkit/src/components/button/button.tsx index 118681adb..762f91fa0 100644 --- a/libs/ui-toolkit/src/components/button/Button.tsx +++ b/libs/ui-toolkit/src/components/button/button.tsx @@ -1,29 +1,32 @@ +import { + AnchorHTMLAttributes, + ButtonHTMLAttributes, + InputHTMLAttributes, + forwardRef, +} from 'react'; import classNames from 'classnames'; import { Icon, IconName } from '../icon'; -export interface ButtonProps { - tag?: 'a' | 'button'; + +interface CommonProps { children?: React.ReactNode; - onClick?: React.MouseEventHandler & - React.MouseEventHandler; variant?: 'primary' | 'secondary' | 'accent' | 'inline'; - disabled?: boolean; className?: string; prependIconName?: IconName; appendIconName?: IconName; } +export interface ButtonProps + extends ButtonHTMLAttributes, + CommonProps {} -export function Button({ - tag = 'button', - variant = 'primary', - children, - onClick, - disabled, - className, - prependIconName, - appendIconName, -}: ButtonProps) { - const ButtonTag: keyof JSX.IntrinsicElements = tag; - const effectiveClassName = classNames( +export interface AnchorButtonProps + extends AnchorHTMLAttributes, + CommonProps {} + +const getClassName = ( + className: CommonProps['className'], + variant: CommonProps['variant'] +) => + classNames( [ 'inline-flex', 'items-center', @@ -53,7 +56,7 @@ export function Button({ 'border-black/60 dark:border-white/60': variant === 'primary' || variant === 'secondary', 'text-white dark:text-black': variant === 'primary', - 'hover:bg-black/70 dark:hover:bg-white/70': variant === 'primary', + 'hover:bg-black/80 dark:hover:bg-white/80': variant === 'primary', 'active:bg-white dark:active:bg-black': variant === 'primary' || variant === 'accent', 'active:text-black dark:active:text-white': @@ -96,24 +99,66 @@ export function Button({ }, className ); - let icon; + +const getContent = ( + children: React.ReactNode, + prependIconName?: IconName, + appendIconName?: IconName +) => { const iconName = prependIconName || appendIconName; - if (iconName !== undefined) { - const iconClassName = classNames(['fill-current'], { - 'mr-8': prependIconName, - 'ml-8': appendIconName, - }); - icon = ; + if (iconName === undefined) { + return children; } + const iconClassName = classNames(['fill-current'], { + 'mr-8': prependIconName, + 'ml-8': appendIconName, + }); + const icon = ; return ( - + <> {prependIconName && icon} {children} {appendIconName && icon} - + ); -} +}; + +export const Button = forwardRef( + ( + { + variant = 'primary', + children, + className, + prependIconName, + appendIconName, + ...prosp + }, + ref + ) => { + return ( + + ); + } +); + +export const AnchorButton = forwardRef( + ( + { + variant = 'primary', + children, + className, + prependIconName, + appendIconName, + ...prosp + }, + ref + ) => { + return ( + + {getContent(children, prependIconName, appendIconName)} + + ); + } +); diff --git a/libs/ui-toolkit/src/components/input/input.tsx b/libs/ui-toolkit/src/components/input/input.tsx index 8f92038f2..5d6e9009b 100644 --- a/libs/ui-toolkit/src/components/input/input.tsx +++ b/libs/ui-toolkit/src/components/input/input.tsx @@ -11,11 +11,9 @@ interface InputProps extends InputHTMLAttributes { } export const inputClassNames = ({ hasError, - disabled, className, }: { hasError?: boolean; - disabled?: boolean; className?: string; }) => classNames( @@ -23,7 +21,6 @@ export const inputClassNames = ({ 'inline-flex', 'items-center', 'box-border', - 'h-28', 'border', 'bg-clip-padding', 'border-black/60 dark:border-white/60', @@ -71,7 +68,6 @@ export const Input = forwardRef( {...props} ref={ref} className={classNames(inputClassNames({ className, ...props }))} - style={{} /*inputStyle(props)*/} /> ); const iconName = prependIconName || appendIconName; diff --git a/libs/ui-toolkit/src/components/select/select.tsx b/libs/ui-toolkit/src/components/select/select.tsx index 10c68c683..6e0da86a7 100644 --- a/libs/ui-toolkit/src/components/select/select.tsx +++ b/libs/ui-toolkit/src/components/select/select.tsx @@ -1,34 +1,17 @@ +import { SelectHTMLAttributes, forwardRef } from 'react'; import classNames from 'classnames'; -import { inputClassNames, inputStyle } from '../input/input'; +import { inputClassNames } from '../input/input'; /* eslint-disable-next-line */ -export interface TextAreaProps { - onChange?: React.FormEventHandler; +export interface SelectProps extends SelectHTMLAttributes { hasError?: boolean; - disabled?: boolean; className?: string; value?: string | number; children?: React.ReactNode; } -export function Select({ - hasError, - onChange, - disabled, - className, - children, -}: TextAreaProps) { - return ( - - ); -} +export const Select = forwardRef( + (props, ref) => ( + - ); -} +export const TextArea = forwardRef( + (props, ref) =>