Skip to content

Commit

Permalink
feat(suite-native): Improve colors in account label hint
Browse files Browse the repository at this point in the history
  • Loading branch information
jbazant authored and vytick committed Jan 13, 2025
1 parent 288bf6c commit 272cc2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions suite-native/accounts/src/components/AccountLabelFieldHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ import { Control, useWatch } from 'react-hook-form';
import { Box, Text } from '@suite-native/atoms';
import { Translation } from '@suite-native/intl';

import { AccountFormValues, MAX_ACCOUNT_LABEL_LENGTH } from '../hooks/useAccountLabelForm';
import {
AccountFormValues,
ALMOST_MAX_ACCOUNT_LABEL_LENGTH,
MAX_ACCOUNT_LABEL_LENGTH,
} from '../hooks/useAccountLabelForm';

type AccountLabelFieldHintProps = {
formControl: Control<AccountFormValues>;
};

function getTextColor(accountLabelLength: number) {
if (accountLabelLength > MAX_ACCOUNT_LABEL_LENGTH) {
return 'textAlertRed';
}

if (accountLabelLength > ALMOST_MAX_ACCOUNT_LABEL_LENGTH) {
return 'textAlertYellow';
}

return 'textSubdued';
}

export const AccountLabelFieldHint = ({ formControl }: AccountLabelFieldHintProps) => {
const { accountLabel } = useWatch({ control: formControl });

const accountLabelLength = accountLabel ? accountLabel.length : 0;

return (
<Box paddingLeft="sp8">
<Text variant="label" color="textSubdued">
<Text variant="label" color={getTextColor(accountLabelLength)}>
<Translation
id="accounts.accountLabelFieldHint.letterCount"
values={{
Expand Down
1 change: 1 addition & 0 deletions suite-native/accounts/src/hooks/useAccountLabelForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { yup } from '@suite-common/validators';
import { useForm } from '@suite-native/forms';

export const MAX_ACCOUNT_LABEL_LENGTH = 30;
export const ALMOST_MAX_ACCOUNT_LABEL_LENGTH = MAX_ACCOUNT_LABEL_LENGTH - 5;

export type AccountFormValues = yup.InferType<typeof accountFormValidationSchema>;

Expand Down

0 comments on commit 272cc2d

Please sign in to comment.