Skip to content

Commit

Permalink
Aizad/WALL-2439/Created Icon Button Component (binary-com#11153)
Browse files Browse the repository at this point in the history
* feat: Created Icon Button for wallets package

* fix: added ref and remove unnecessary imports
  • Loading branch information
aizad-deriv committed Nov 3, 2023
1 parent fd32b57 commit 641035b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
92 changes: 92 additions & 0 deletions packages/wallets/src/components/Base/IconButton/IconButton.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
$color-map: (
'primary': (
backgroundcolor: #ff444f,
hover: #eb3e48,
),
'white': (
backgroundcolor: #fff,
hover: #d6dadb,
),
'black': (
backgroundcolor: #0e0e0e,
hover: #323738,
),
'transparent': (
backgroundcolor: transparent,
hover: #d6dadb,
),
);

$size-map: (
sm: (
padding: 0.4rem,
height: 2.4rem,
),
md: (
padding: 0.8rem,
height: 3.2rem,
),
lg: (
padding: 1.2rem,
height: 4rem,
),
);

$border-radius-map: (
sm: 0.4rem,
md: 6.4rem,
lg: 50%,
);

.wallets-icon-button {
display: grid;
place-content: center;
border: none;

&:hover {
cursor: pointer;
}

&:disabled {
display: none;
}

&__border-radius {
&--round {
border-radius: 50%;
}

&--default {
border-radius: 0.4rem;
}
}

@each $color, $values in $color-map {
&__color--#{$color} {
background-color: map-get($values, backgroundcolor);
&:hover {
background-color: map-get($values, hover);
}
}
}

@each $size, $values in $size-map {
&__size--#{$size} {
padding: map-get($values, padding);
height: map-get($values, height);
}
}

@each $size, $values in $border-radius-map {
&__border-radius--#{$size} {
border-radius: ($values);
}
}

&__icon {
display: grid;
place-content: center;
width: 1.6rem;
height: 1.6rem;
}
}
36 changes: 36 additions & 0 deletions packages/wallets/src/components/Base/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { ButtonHTMLAttributes, ComponentProps, forwardRef, Ref } from 'react';
import classNames from 'classnames';
import { TGenericSizes } from '../types';
import './IconButton.scss';

interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
color?: 'black' | 'primary' | 'transparent' | 'white';
icon: React.ReactNode;
isRound?: boolean;
onClick?: ComponentProps<'button'>['onClick'];
size?: Extract<TGenericSizes, 'lg' | 'md' | 'sm'>;
}

const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
(
{ className, color = 'primary', disabled, icon, isRound, onClick, size = 'sm', ...rest },
ref: Ref<HTMLButtonElement>
) => {
const iconButtonClassNames = classNames(
'wallets-icon-button',
`wallets-icon-button__size--${size}`,
`wallets-icon-button__color--${color}`,
`wallets-icon-button__border-radius--${isRound ? 'round' : 'default'}`,
className
);

return (
<button className={iconButtonClassNames} disabled={disabled} onClick={onClick} ref={ref} {...rest}>
<div className='wallets-icon-button__icon'>{icon}</div>
</button>
);
}
);

IconButton.displayName = 'IconButton';
export default IconButton;
1 change: 1 addition & 0 deletions packages/wallets/src/components/Base/IconButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as IconButton } from './IconButton';
1 change: 1 addition & 0 deletions packages/wallets/src/components/Base/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './Divider';
export * from './IconButton';
export * from './InlineMessage';
export * from './ModalStepWrapper';
export * from './ModalWrapper';
Expand Down

0 comments on commit 641035b

Please sign in to comment.