(
{
variant,
size = ButtonSize.Medium,
color,
className,
icon,
iconPosition = ButtonIconPosition.Left,
iconSecondaryOnHover = false,
loading,
pressed,
inactive,
bold,
useDefaultCursor,
disabled,
children,
onClick,
tag: Tag = 'button',
...props
}: ButtonV2Props<TagName>,
ref?: Ref<ButtonElementType<TagName>>,
)
| 154 | }; |
| 155 | |
| 156 | function ButtonV2Component<TagName extends AllowedTags>( |
| 157 | { |
| 158 | variant, |
| 159 | size = ButtonSize.Medium, |
| 160 | color, |
| 161 | className, |
| 162 | icon, |
| 163 | iconPosition = ButtonIconPosition.Left, |
| 164 | iconSecondaryOnHover = false, |
| 165 | loading, |
| 166 | pressed, |
| 167 | inactive, |
| 168 | bold, |
| 169 | useDefaultCursor, |
| 170 | disabled, |
| 171 | children, |
| 172 | onClick, |
| 173 | tag: Tag = 'button', |
| 174 | ...props |
| 175 | }: ButtonV2Props<TagName>, |
| 176 | ref?: Ref<ButtonElementType<TagName>>, |
| 177 | ): ReactElement { |
| 178 | const childNodes = React.Children.toArray(children); |
| 179 | const hasChildren = childNodes.length > 0; |
| 180 | const shouldWrapLabel = |
| 181 | hasChildren && |
| 182 | childNodes.every( |
| 183 | (child) => typeof child === 'string' || typeof child === 'number', |
| 184 | ); |
| 185 | const iconOnly = !!(icon && !hasChildren); |
| 186 | const getIconWithSize = useGetIconWithSizeV2(size, iconOnly, iconPosition); |
| 187 | const isAnchor = Tag === 'a'; |
| 188 | const anchorClickProps = |
| 189 | isAnchor && onClick |
| 190 | ? combinedClicks<HTMLAnchorElement>( |
| 191 | onClick as React.MouseEventHandler<HTMLAnchorElement>, |
| 192 | ) |
| 193 | : {}; |
| 194 | const isOptionOrQuiz = |
| 195 | variant === ButtonVariant.Option || variant === ButtonVariant.Quiz; |
| 196 | const [isHovering, setIsHovering] = useState(false); |
| 197 | |
| 198 | const ariaDisabled = inactive && !disabled ? true : undefined; |
| 199 | |
| 200 | return ( |
| 201 | <Tag |
| 202 | {...props} |
| 203 | {...(isAnchor ? anchorClickProps : { onClick })} |
| 204 | aria-busy={loading} |
| 205 | aria-pressed={pressed} |
| 206 | aria-disabled={ariaDisabled} |
| 207 | disabled={disabled} |
| 208 | ref={ref} |
| 209 | className={classNames( |
| 210 | 'btn-v2 inline-flex select-none flex-row items-center border no-underline shadow-none', |
| 211 | useDefaultCursor ? 'cursor-default' : 'cursor-pointer', |
| 212 | !isOptionOrQuiz && 'justify-center', |
| 213 | variantFontWeight(variant, bold), |
nothing calls this directly
no test coverage detected