-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO CHANGELOG][Add Funds Widget] Add FiatOption component (#2233)
- Loading branch information
1 parent
21699c3
commit 89d87d7
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/checkout/widgets-lib/src/widgets/add-funds/components/FiatOption.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { IconProps, MenuItem, MenuItemSize } from '@biom3/react'; | ||
import { ReactElement } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { FiatOptionType } from '../types'; | ||
|
||
export interface FiatOptionProps<RC extends ReactElement | undefined = undefined> { | ||
rc?: RC; | ||
type: FiatOptionType; | ||
onClick?: (type: FiatOptionType) => void; | ||
disabled?: boolean; | ||
size?: MenuItemSize; | ||
} | ||
|
||
export function FiatOption<RC extends ReactElement | undefined = undefined>({ | ||
type, | ||
onClick, | ||
disabled = false, | ||
size, | ||
rc = <span />, | ||
}: FiatOptionProps<RC>) { | ||
const { t } = useTranslation(); | ||
|
||
const icon: Record<FiatOptionType, IconProps['icon']> = { | ||
[FiatOptionType.DEBIT]: 'BankCard', | ||
[FiatOptionType.CREDIT]: 'BankCard', | ||
}; | ||
|
||
const handleClick = () => { | ||
if (onClick) { | ||
onClick(type); | ||
} | ||
}; | ||
|
||
const menuItemProps = { | ||
disabled, | ||
emphasized: true, | ||
onClick: disabled ? undefined : handleClick, | ||
}; | ||
|
||
return ( | ||
<MenuItem | ||
rc={rc} | ||
size={size || 'medium'} | ||
sx={{ | ||
marginBottom: 'base.spacing.x1', | ||
userSelect: 'none', | ||
...(disabled && { | ||
filter: 'opacity(0.5)', | ||
cursor: 'not-allowed !important', | ||
}), | ||
}} | ||
{...menuItemProps} | ||
> | ||
<MenuItem.FramedIcon icon={icon[type]} /> | ||
<MenuItem.Label size="medium"> | ||
{t(`views.ADD_FUNDS.drawer.options.${type}.heading`)} | ||
</MenuItem.Label> | ||
{!disabled && <MenuItem.IntentIcon />} | ||
<MenuItem.Caption> | ||
{ t( | ||
`views.ADD_FUNDS.drawer.options.${type}.${ | ||
disabled ? 'disabledCaption' : 'caption' | ||
}`, | ||
)} | ||
</MenuItem.Caption> | ||
</MenuItem> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters