Skip to content

Commit

Permalink
feat(button): add prop to choose icon position
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Dec 11, 2024
1 parent 85abe1d commit e735899
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/components/button/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface ButtonProps<T extends HTMLTag = "button">
* This can be any valid React node, allowing integration of icons or custom SVG components.
*/
icon?: React.ReactNode;
/** Defines where icon should be placed */
iconPosition?: "before" | "after";
/** Ref for the root element */
rootRef?: React.ForwardedRef<HTMLButtonElement>;
/** Make button occupy whole available horizontal space */
Expand All @@ -45,6 +47,7 @@ export const Button = <T extends HTMLTag>({
skinVariation = "default",
size = "m",
icon,
iconPosition = "after",
children,
className,
rootRef,
Expand Down Expand Up @@ -89,8 +92,16 @@ export const Button = <T extends HTMLTag>({
className,
),
}}>
{icon && iconPosition === "before" && !isIconOnly ? (
<span className={styles.icon}>{icon}</span>
) : null}

{children}
{icon && !isIconOnly ? <span className={styles.icon}>{icon}</span> : null}

{icon && iconPosition === "after" && !isIconOnly ? (
<span className={styles.icon}>{icon}</span>
) : null}

{isIconOnly ? icon : null}
</PolymorphicComponent>
);
Expand Down

0 comments on commit e735899

Please sign in to comment.