Skip to content

Commit

Permalink
Merge pull request #584 from pixiv/toshusai/replace-as-to-component
Browse files Browse the repository at this point in the history
feat: replace as to component IconButton.
  • Loading branch information
toshusai authored Jul 9, 2024
2 parents 5f91c2a + 786c063 commit 5ee3df4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/react/src/components/IconButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export type IconButtonProps<T extends React.ElementType = 'button'> = {
readonly size?: Size
readonly icon: keyof KnownIconType
readonly isActive?: boolean
as?: T
componentAs?: React.ComponentPropsWithRef<T>['as']
component?: T
} & Omit<React.ComponentPropsWithRef<T>, 'children' | 'as'>

const IconButton = forwardRef(function IconButtonInner<
Expand All @@ -24,20 +23,18 @@ const IconButton = forwardRef(function IconButtonInner<
size = 'M',
icon,
isActive = false,
componentAs,
as,
component,
...rest
}: IconButtonProps<T>,
ref: ForwardedRef<HTMLButtonElement>
) {
validateIconSize(size, icon)
const Component = useMemo(() => as ?? 'button', [as])
const Component = useMemo(() => component ?? 'button', [component])
const classNames = useClassNames('charcoal-icon-button', rest.className)

return (
<Component
{...rest}
as={componentAs}
ref={ref}
className={classNames}
data-size={size}
Expand Down

0 comments on commit 5ee3df4

Please sign in to comment.