Skip to content

Commit

Permalink
Move IconButton specific styles to a classname
Browse files Browse the repository at this point in the history
  • Loading branch information
Youakeem committed Sep 18, 2024
1 parent 04acb1e commit c357220
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/ui/src/components/Button/Button.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export const buttonSizeStyles = {
},
}

export const iconButtonStyles = style({ aspectRatio: '1', height: 'auto' })

export const childrenWrapper = style({
display: 'flex',
alignItems: 'center',
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const Button: PolymorphicComponent = forwardRef(function Button<
>
<span className={childrenWrapper} style={{ opacity: loading ? 0 : 1 }}>
{iconPosition === 'left' && Icon}
{children && <span className={clsx(textWrapper)}>{children}</span>}
{children && <span className={textWrapper}>{children}</span>}
{iconPosition === 'right' && Icon}
</span>
{hiddenText && hiddenText}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/components/Button/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import clsx from 'clsx'
import { type ComponentProps, forwardRef } from 'react'
import { Button } from './Button'
import { iconButtonStyles } from './Button.css'

type ButtonProps = ComponentProps<typeof Button<'button'>>

export const IconButton = forwardRef<HTMLButtonElement, ButtonProps>(
({ children, ...props }, forwardedRef) => (
({ className, children, ...props }, forwardedRef) => (
<Button
className={clsx(iconButtonStyles, className)}
variant="ghost"
size="icon"
style={{ aspectRatio: '1', height: 'auto' }}
Icon={children}
{...props}
ref={forwardedRef}
Expand Down

0 comments on commit c357220

Please sign in to comment.