Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rui/max balance token input #952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/component-library/CTA/BaseCTA.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, HTMLAttributes } from 'react';
import { StyledComponent } from 'styled-components';

import { CTAVariants, ElementTypeProp, Sizes } from '../utils/prop-types';
import { CTASizes, CTAVariants, ElementTypeProp } from '../utils/prop-types';
import { OutlinedCTA, PrimaryCTA, SecondaryCTA, StyledCTAProps, TextCTA } from './CTA.style';

const ctaElements: Record<CTAVariants, StyledComponent<'button', any, StyledCTAProps, never>> = {
Expand All @@ -14,7 +14,7 @@ const ctaElements: Record<CTAVariants, StyledComponent<'button', any, StyledCTAP
type Props = {
variant?: CTAVariants;
fullWidth?: boolean;
size?: Sizes;
size?: CTASizes;
disabled?: boolean;
isFocusVisible?: boolean;
};
Expand Down
4 changes: 2 additions & 2 deletions src/component-library/CTA/CTA.style.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import styled from 'styled-components';

import { theme } from '../theme';
import { Sizes } from '../utils/prop-types';
import { CTASizes } from '../utils/prop-types';

interface StyledCTAProps {
$fullWidth: boolean;
$size: Sizes;
$size: CTASizes;
$isFocusVisible?: boolean;
}

Expand Down
7 changes: 4 additions & 3 deletions src/component-library/CTA/CTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import { ButtonHTMLAttributes, forwardRef } from 'react';

import { LoadingSpinner } from '../LoadingSpinner';
import { useDOMRef } from '../utils/dom';
import { Sizes } from '../utils/prop-types';
import { CTASizes } from '../utils/prop-types';
import { BaseCTA, BaseCTAProps } from './BaseCTA';
import { LoadingWrapper } from './CTA.style';

const loadingSizes: Record<Sizes, number> = {
const loadingSizes: Record<CTASizes, number> = {
'x-small': 14,
small: 16,
medium: 18,
large: 20
};

type Props = {
fullWidth?: boolean;
size?: Sizes;
size?: CTASizes;
loading?: boolean;
onPress?: (e: PressEvent) => void;
};
Expand Down
9 changes: 3 additions & 6 deletions src/component-library/TokenInput/TokenInput.style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ type StyledClickableProps = {
$isClickable: boolean;
};

type StyledTokenInputBalanceValueProps = {
type StyledUSDAdornmentProps = {
$isDisabled?: boolean;
$isFocusVisible: boolean;
};

type StyledListItemSelectedLabelProps = {
Expand All @@ -27,7 +26,7 @@ const StyledTicker = styled.span`
text-overflow: ellipsis;
`;

const StyledUSDAdornment = styled.span<Pick<StyledTokenInputBalanceValueProps, '$isDisabled'>>`
const StyledUSDAdornment = styled.span<StyledUSDAdornmentProps>`
display: block;
font-size: ${theme.text.xs};
line-height: ${theme.lineHeight.s};
Expand Down Expand Up @@ -68,11 +67,9 @@ const StyledTokenInputBalanceLabel = styled.dt`
}
`;

const StyledTokenInputBalanceValue = styled.span<StyledTokenInputBalanceValueProps>`
const StyledTokenInputBalanceValue = styled.span`
display: block;
color: ${theme.colors.textSecondary};
cursor: ${({ $isDisabled }) => !$isDisabled && 'pointer'};
outline: ${({ $isFocusVisible }) => !$isFocusVisible && 'none'};
`;

const StyledListItemLabel = styled(Span)<StyledListItemSelectedLabelProps>`
Expand Down
24 changes: 7 additions & 17 deletions src/component-library/TokenInput/TokenInputBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useFocusRing } from '@react-aria/focus';
import { usePress } from '@react-aria/interactions';
import { mergeProps } from '@react-aria/utils';
import { ReactNode } from 'react';

import { CTA } from '../CTA';
import {
StyledTokenInputBalanceLabel,
StyledTokenInputBalanceValue,
Expand All @@ -23,28 +21,20 @@ const TokenInputBalance = ({
value,
onClickBalance,
className,
isDisabled,
isDisabled: isDisabledProp,
label = 'Balance'
}: TokenInputBalanceProps): JSX.Element => {
const { pressProps } = usePress({ onPress: onClickBalance, isDisabled: isDisabled });
const { focusProps, isFocusVisible } = useFocusRing();
const balanceValueProps = isDisabled
? {}
: {
role: 'button',
tabIndex: 0,
'aria-label': 'apply balance',
...mergeProps(pressProps, focusProps)
};
const isDisabled = isDisabledProp || !ticker || value === 0;

return (
<StyledTokenInputBalanceWrapper className={className}>
<StyledTokenInputBalanceLabel>{label}</StyledTokenInputBalanceLabel>
<dd>
<StyledTokenInputBalanceValue $isDisabled={isDisabled} $isFocusVisible={isFocusVisible} {...balanceValueProps}>
{ticker ? value : 0}
</StyledTokenInputBalanceValue>
<StyledTokenInputBalanceValue>{ticker ? value : 0}</StyledTokenInputBalanceValue>
</dd>
<CTA onPress={onClickBalance} disabled={isDisabled} size='x-small'>
MAX
</CTA>
</StyledTokenInputBalanceWrapper>
);
};
Expand Down
6 changes: 6 additions & 0 deletions src/component-library/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ const theme = {
text: 'var(--colors-cta-text-text)',
bgHover: 'var(--colors-cta-text-hover)'
},
'x-small': {
padding: 'var(--spacing-1)',
text: 'var(--text-xs)',
// TODO: revist on redesign
lineHeight: '1'
},
small: {
padding: 'var(--spacing-2)',
text: 'var(--text-xs)',
Expand Down
2 changes: 2 additions & 0 deletions src/component-library/utils/prop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export type Variants = typeof variant[number];

export type CTAVariants = typeof ctaVariant[number];

export type CTASizes = 'x-small' | 'small' | 'medium' | 'large';

export type Status = typeof status[number];

export type Sizes = typeof sizes[number];
Expand Down