mars-v2-frontend/components/Button.tsx

94 lines
3.1 KiB
TypeScript
Raw Normal View History

import classNames from 'classnames'
import React, { ReactNode } from 'react'
import CircularProgress from 'components/CircularProgress'
interface Props {
children?: string | ReactNode
WIP (#12) * osmosis initial setup and nft contract queries/mutations * display errors on ui * fix: create credit account queryMsg and contract * client initialization. loading indicator when pending io * added tx feedback on toast * remove unused wallet store code * fetch credit accounts moved to external hook * navigation copy * file name typo * remove console logs and unused imports * fix: credit accounts query msg * credit manager store. create credit account hook created * delete credit account hook. fees declaration moved to utils * update selected account when a new one is created * type inference for mutation hooks * loading indicator for async actions. onSuccess toast * credit accounts popover * minor improvements credit account slice * credit manager module state and respective markup * fix: credit account list threshold * credit manager component. currency formatter function update * update contract addresses * borrow screen initial setup * error handling mutation queries * update credit account list when address changes * update credit accounts query key to include address * update selected account when nothing is selected * credit manager wip. deposit and listing positions on credit account * FundAccount component moved to different file * removed unused code * lending assets switch * minor refactor injective balance hook to be more generic * style: font size minor adjustments * borrow action initial. display liabilities and borrow positions on credit manager * positions amount formatting * preserve selected account on local storage * prettier custom settings and respective files formatting * credit manager container moved to external file * removed threshold variable. nav elements moved to array declaration * Navigation component naming and minor cleanup * react query keys enum * query keys improvements * initial generated smart contract api type definitions
2022-09-29 19:21:31 +00:00
className?: string
color?: 'primary' | 'secondary' | 'tertiary' | 'quaternary'
WIP (#12) * osmosis initial setup and nft contract queries/mutations * display errors on ui * fix: create credit account queryMsg and contract * client initialization. loading indicator when pending io * added tx feedback on toast * remove unused wallet store code * fetch credit accounts moved to external hook * navigation copy * file name typo * remove console logs and unused imports * fix: credit accounts query msg * credit manager store. create credit account hook created * delete credit account hook. fees declaration moved to utils * update selected account when a new one is created * type inference for mutation hooks * loading indicator for async actions. onSuccess toast * credit accounts popover * minor improvements credit account slice * credit manager module state and respective markup * fix: credit account list threshold * credit manager component. currency formatter function update * update contract addresses * borrow screen initial setup * error handling mutation queries * update credit account list when address changes * update credit accounts query key to include address * update selected account when nothing is selected * credit manager wip. deposit and listing positions on credit account * FundAccount component moved to different file * removed unused code * lending assets switch * minor refactor injective balance hook to be more generic * style: font size minor adjustments * borrow action initial. display liabilities and borrow positions on credit manager * positions amount formatting * preserve selected account on local storage * prettier custom settings and respective files formatting * credit manager container moved to external file * removed threshold variable. nav elements moved to array declaration * Navigation component naming and minor cleanup * react query keys enum * query keys improvements * initial generated smart contract api type definitions
2022-09-29 19:21:31 +00:00
disabled?: boolean
id?: string
showProgressIndicator?: boolean
size?: 'small' | 'medium' | 'large'
text?: string | ReactNode
variant?: 'solid' | 'transparent' | 'round'
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void
}
const colorClasses = {
primary:
'border-none bg-primary hover:bg-primary-highlight active:bg-primary-highlight-10 focus:bg-primary-highlight',
secondary:
'border-none bg-secondary hover:bg-secondary-highlight active:bg-secondary-highlight-10 focus:bg-secondary-highlight',
tertiary:
'border bg-secondary-dark/60 border-white/60 hover:bg-secondary-dark hover:border-white active:bg-secondary-dark-10 active:border-white focus:bg-secondary-dark focus:border-white',
quaternary:
'border bg-transparent text-white/60 border-transparent hover:text-white hover:border-white active:text-white active:border-white',
}
const transparentColorClasses = {
primary:
'border-none text-primary hover:text-primary-highlight active:text-primary-highlight focus:text-primary-highlight',
secondary:
'border-none text-secondary hover:text-secondary-highlight active:text-secondary-highlight focus:text-secondary-highlight',
tertiary:
'text-secondary-dark hover:text-secondary-dark-10 active:text-secondary-dark-10 focus:text-secondary-dark-10',
quaternary:
'border border-transparent text-white/60 hover:text-white hover:border-white active:text-white active:border-white',
}
const roundSizeClasses = {
small: 'h-[32px] w-[32px]',
medium: 'h-[40px] w-[40px]',
large: 'h-[56px] w-[56px]',
}
const sizeClasses = {
small: 'text-sm px-5 py-1.5 min-h-[32px]',
medium: 'text-base px-6 py-2.5 min-h-[40px]',
large: 'text-lg px-6 py-2.5 min-h-[56px]',
WIP (#12) * osmosis initial setup and nft contract queries/mutations * display errors on ui * fix: create credit account queryMsg and contract * client initialization. loading indicator when pending io * added tx feedback on toast * remove unused wallet store code * fetch credit accounts moved to external hook * navigation copy * file name typo * remove console logs and unused imports * fix: credit accounts query msg * credit manager store. create credit account hook created * delete credit account hook. fees declaration moved to utils * update selected account when a new one is created * type inference for mutation hooks * loading indicator for async actions. onSuccess toast * credit accounts popover * minor improvements credit account slice * credit manager module state and respective markup * fix: credit account list threshold * credit manager component. currency formatter function update * update contract addresses * borrow screen initial setup * error handling mutation queries * update credit account list when address changes * update credit accounts query key to include address * update selected account when nothing is selected * credit manager wip. deposit and listing positions on credit account * FundAccount component moved to different file * removed unused code * lending assets switch * minor refactor injective balance hook to be more generic * style: font size minor adjustments * borrow action initial. display liabilities and borrow positions on credit manager * positions amount formatting * preserve selected account on local storage * prettier custom settings and respective files formatting * credit manager container moved to external file * removed threshold variable. nav elements moved to array declaration * Navigation component naming and minor cleanup * react query keys enum * query keys improvements * initial generated smart contract api type definitions
2022-09-29 19:21:31 +00:00
}
const variantClasses = {
solid: 'text-white',
transparent: 'bg-transparent p-0',
round: 'rounded-full p-0',
}
const Button = ({
children,
className = '',
color = 'primary',
disabled,
id = '',
showProgressIndicator,
size = 'small',
text,
variant = 'solid',
onClick,
}: Props) => {
return (
<button
className={classNames(
'cursor-pointer appearance-none break-normal rounded-3xl outline-none transition-colors',
variant === 'round' ? `${sizeClasses[size]} ${roundSizeClasses[size]}` : sizeClasses[size],
variant === 'transparent' ? transparentColorClasses[color] : colorClasses[color],
variantClasses[variant],
disabled && 'pointer-events-none opacity-50',
className,
)}
id={id}
onClick={disabled ? () => {} : onClick}
>
{text && !children && !showProgressIndicator && <span>{text}</span>}
{children && !showProgressIndicator && children}
{showProgressIndicator && (
<CircularProgress size={size === 'small' ? 10 : size === 'medium' ? 12 : 18} />
)}
</button>
)
}
WIP (#12) * osmosis initial setup and nft contract queries/mutations * display errors on ui * fix: create credit account queryMsg and contract * client initialization. loading indicator when pending io * added tx feedback on toast * remove unused wallet store code * fetch credit accounts moved to external hook * navigation copy * file name typo * remove console logs and unused imports * fix: credit accounts query msg * credit manager store. create credit account hook created * delete credit account hook. fees declaration moved to utils * update selected account when a new one is created * type inference for mutation hooks * loading indicator for async actions. onSuccess toast * credit accounts popover * minor improvements credit account slice * credit manager module state and respective markup * fix: credit account list threshold * credit manager component. currency formatter function update * update contract addresses * borrow screen initial setup * error handling mutation queries * update credit account list when address changes * update credit accounts query key to include address * update selected account when nothing is selected * credit manager wip. deposit and listing positions on credit account * FundAccount component moved to different file * removed unused code * lending assets switch * minor refactor injective balance hook to be more generic * style: font size minor adjustments * borrow action initial. display liabilities and borrow positions on credit manager * positions amount formatting * preserve selected account on local storage * prettier custom settings and respective files formatting * credit manager container moved to external file * removed threshold variable. nav elements moved to array declaration * Navigation component naming and minor cleanup * react query keys enum * query keys improvements * initial generated smart contract api type definitions
2022-09-29 19:21:31 +00:00
export default Button