From bffe24dead0d286a37405b5380f78d1401b4ffc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Wed, 18 Feb 2026 14:59:29 +0100 Subject: [PATCH] nicolium: reduce nesting in button component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- .../pl-fe/src/components/ui/button/index.tsx | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/packages/pl-fe/src/components/ui/button/index.tsx b/packages/pl-fe/src/components/ui/button/index.tsx index 0e365d10b..cd644bb7a 100644 --- a/packages/pl-fe/src/components/ui/button/index.tsx +++ b/packages/pl-fe/src/components/ui/button/index.tsx @@ -10,15 +10,7 @@ import type { ButtonSizes, ButtonThemes } from './useButtonStyles'; type IButton = Pick< React.ComponentProps<'button'>, - | 'children' - | 'className' - | 'disabled' - | 'onClick' - | 'onMouseDown' - | 'onKeyDown' - | 'onKeyPress' - | 'title' - | 'type' + 'children' | 'className' | 'disabled' | 'title' | 'type' > & (LinkOptions | { to?: undefined }) & { /** Whether this button expands the width of its container. */ @@ -37,10 +29,18 @@ type IButton = Pick< href?: string; /** Styles the button visually with a predefined theme. */ theme?: ButtonThemes; + /** Event handler for click events. */ + onClick?: React.MouseEventHandler; + /** Event handler for mouse down events. */ + onMouseDown?: React.MouseEventHandler; + /** Event handler for key down events. */ + onKeyDown?: React.KeyboardEventHandler; + /** Event handler for key press events. */ + onKeyPress?: React.KeyboardEventHandler; }; /** Customizable button element with various themes. */ -const Button = React.forwardRef( +const Button = React.forwardRef( ( { block = false, @@ -58,7 +58,7 @@ const Button = React.forwardRef( className, ...props }, - ref, + ref: React.ForwardedRef, ): JSX.Element => { const body = text ?? children; @@ -68,51 +68,68 @@ const Button = React.forwardRef( size, }); - const handleClick: React.MouseEventHandler = React.useCallback( - (event) => { - if (onClick && !disabled) { - onClick(event); - } - }, - [onClick, disabled], + const handleClick: React.MouseEventHandler = + React.useCallback( + (event) => { + if (onClick && !disabled) { + onClick(event); + } + }, + [onClick, disabled], + ); + + const buttonChildren = ( + <> + {icon ? : null} + + {body && {body}} + + {secondaryIcon ? : null} + ); const renderButton = () => ( ); if (props.to) { return ( } to={props.to} params={props.params} search={props.search} tabIndex={-1} - className='inline-flex' > - {renderButton()} + {buttonChildren} ); } if (href) { return ( - - {renderButton()} + } + href={href} + target='_blank' + rel='noopener' + tabIndex={-1} + > + {buttonChildren} ); }