Skip to content

Commit

Permalink
Convert function to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpens committed Oct 25, 2024
1 parent 520b4c4 commit 91cc77f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/react/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ export const Button = forwardRef(
ref: ForwardedRef<HTMLButtonElement>,
) => {
const content = (): ReactNode => {
if (!icon) return children

if (iconOnly) {
return [
<Icon key={1} svg={icon} size="level-5" square={true} />,
<span className="ams-visually-hidden" key={2}>
{children}
</span>,
]
switch (true) {
case !icon:
return children
case iconBefore:
return [<Icon svg={icon} size="level-5" />, children]
case iconOnly:
return [
<Icon key={1} svg={icon} size="level-5" square={true} />,
<span className="ams-visually-hidden" key={2}>
{children}
</span>,
]
default:
return [children, <Icon svg={icon} size="level-5" />]
}

if (iconBefore) return [<Icon svg={icon} size="level-5" />, children]

return [children, <Icon svg={icon} size="level-5" />]
}

return (
Expand Down

0 comments on commit 91cc77f

Please sign in to comment.