@@ -7,19 +7,25 @@ import { assert } from "tsafe/assert";
77import type { Equals } from "tsafe" ;
88
99export type ButtonProps = ButtonProps . Anchor | ButtonProps . Button ;
10-
1110export namespace ButtonProps {
1211 type Common = {
1312 className ?: string ;
1413 label : string ;
15- icon ?: {
16- iconId : FrIconClassName | RiIconClassName ;
17- position ?: "left" | "right" ;
18- } ;
1914 /** Default primary */
2015 priority ?: "primary" | "secondary" | "tertiary" ;
2116 /** Default medium */
2217 size ?: "small" | "medium" | "large" ;
18+ } & ( WithIcon | WithoutIcon ) ;
19+
20+ export type WithIcon = {
21+ iconId : FrIconClassName | RiIconClassName ;
22+ /** Default left */
23+ iconPosition ?: "left" | "right" ;
24+ } ;
25+
26+ export type WithoutIcon = {
27+ iconId ?: never ;
28+ iconPosition ?: never ;
2329 } ;
2430
2531 export type Anchor = Common & {
@@ -40,9 +46,10 @@ export namespace ButtonProps {
4046export const Button = memo (
4147 forwardRef < HTMLButtonElement | HTMLAnchorElement , ButtonProps > ( ( props , ref ) => {
4248 const {
43- className,
49+ className : prop_className ,
4450 label,
45- icon,
51+ iconId,
52+ iconPosition = "left" ,
4653 priority = "primary" ,
4754 size = "medium" ,
4855 linkProps,
@@ -56,7 +63,7 @@ export const Button = memo(
5663
5764 const { Link } = useLink ( ) ;
5865
59- const buttonClassName = cx (
66+ const className = cx (
6067 fr . cx ( "fr-btn" ) ,
6168 priority !== "primary" && fr . cx ( `fr-btn--${ priority } ` ) ,
6269 size !== "medium" &&
@@ -70,24 +77,20 @@ export const Button = memo(
7077 }
7178 } ) ( ) } `
7279 ) ,
73- icon !== undefined &&
74- cx (
75- fr . cx ( icon . iconId ) ,
76- icon . position !== undefined && fr . cx ( `fr-btn--icon-${ icon . position } ` )
77- ) ,
78- className
80+ iconId !== undefined && fr . cx ( iconId , `fr-btn--icon-${ iconPosition } ` ) ,
81+ prop_className
7982 ) ;
8083 const Component = linkProps ? (
8184 < Link
8285 { ...linkProps }
83- className = { buttonClassName }
86+ className = { className }
8487 ref = { ref as React . ForwardedRef < HTMLAnchorElement > }
8588 >
8689 { label }
8790 </ Link >
8891 ) : (
8992 < button
90- className = { buttonClassName }
93+ className = { className }
9194 type = { type }
9295 onClick = { onClick }
9396 disabled = { disabled }
0 commit comments