Skip to content

Commit

Permalink
refactor duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
tlabaj committed Apr 22, 2024
1 parent 1c7d0ca commit 68f8342
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const ToggleGroupItem: React.FunctionComponent<ToggleGroupItemProps> = ({
console.warn('An accessible aria-label is required when using the toggle group item icon variant.');
}

const toggleGroupIcon = <ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>;

return (
<div className={css(styles.toggleGroupItem, className)} {...props}>
<button
Expand All @@ -56,13 +58,9 @@ export const ToggleGroupItem: React.FunctionComponent<ToggleGroupItemProps> = ({
disabled={isDisabled}
id={buttonId}
>
{icon && iconPosition === 'start' && (
<ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>
)}
{icon && iconPosition === 'start' && toggleGroupIcon}
{text && <ToggleGroupItemElement variant={ToggleGroupItemVariant.text}>{text}</ToggleGroupItemElement>}
{icon && iconPosition === 'end' && (
<ToggleGroupItemElement variant={ToggleGroupItemVariant.icon}>{icon}</ToggleGroupItemElement>
)}
{icon && iconPosition === 'end' && toggleGroupIcon}
</button>
</div>
);
Expand Down

0 comments on commit 68f8342

Please sign in to comment.