Skip to content

Commit

Permalink
fix: refactor error label to align icon and make text consistent size
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed Nov 1, 2023
1 parent e349e0c commit 688e389
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 59 deletions.
39 changes: 23 additions & 16 deletions src/app/components/error-label.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { FiAlertCircle } from 'react-icons/fi';

import { Box, Stack, StackProps, color } from '@stacks/ui';
import { css } from 'leather-styles/css';
import { Box, HStack, HstackProps } from 'leather-styles/jsx';

export function ErrorLabel({ children, ...rest }: StackProps) {
interface ErrorLabelProps extends HstackProps {
dataTestId?: string;
}

export function ErrorLabel({ children, dataTestId }: ErrorLabelProps) {
return (
<Stack
spacing="tight"
color={color('feedback-error')}
isInline
<HStack
gap="tight"
color="error"
alignItems="flex-start"
{...rest}
textAlign="left"
data-testid={dataTestId}
width="100%"
textStyle="body.02"
// lineHeight="20px"
className={css({
'& svg': {
mt: '2px',
},
})}
>
<Box
size="1rem"
color={color('feedback-error')}
as={FiAlertCircle}
position="relative"
strokeWidth={1.5}
/>
<Box>{children}</Box>
</Stack>
<FiAlertCircle size="1rem" />
{children}
</HStack>
);
}
2 changes: 1 addition & 1 deletion src/app/components/field-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function TextInputFieldError(props: { name: string }) {
<Flex mb="tight" width="100%">
<AnimateHeight duration={400} easing="ease-out" height={showHide}>
<Flex height={openHeight + 'px'}>
<ErrorLabel data-testid={SendCryptoAssetSelectors.FormFieldInputErrorLabel} fontSize={1}>
<ErrorLabel data-testid={SendCryptoAssetSelectors.FormFieldInputErrorLabel}>
{meta.error}
</ErrorLabel>
</Flex>
Expand Down
8 changes: 1 addition & 7 deletions src/app/components/request-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ export function RequestPassword({ title, caption, onSuccess }: RequestPasswordPr
value={password}
width="100%"
/>
{error && (
<Box>
<ErrorLabel>
<Text textStyle="caption">{error}</Text>
</ErrorLabel>
</Box>
)}
{error && <ErrorLabel>{error}</ErrorLabel>}
</Stack>
<LeatherButton
data-testid={SettingsSelectors.UnlockWalletBtn}
Expand Down
5 changes: 2 additions & 3 deletions src/app/features/add-network/add-network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ChainID } from '@stacks/transactions';
import { Input, Stack } from '@stacks/ui';
import { NetworkSelectors } from '@tests/selectors/network.selectors';
import { Formik } from 'formik';
import { styled } from 'leather-styles/jsx';
import { token } from 'leather-styles/tokens';

import { DefaultNetworkConfigurations } from '@shared/constants';
Expand Down Expand Up @@ -169,9 +170,7 @@ export function AddNetwork() {
/>
{error ? (
<ErrorLabel>
<Text textStyle="caption" data-testid={NetworkSelectors.ErrorText}>
{error}
</Text>
<styled.span data-testid={NetworkSelectors.ErrorText}>{error}</styled.span>
</ErrorLabel>
) : null}
<LeatherButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export const EditNonceField = memo((props: EditNonceFieldProps) => {
value={field.value}
width="100%"
/>
{meta.error && (
<ErrorLabel>
<styled.span textStyle="caption.02">{meta.error}</styled.span>
</ErrorLabel>
)}
{meta.error && <ErrorLabel>{meta.error}</ErrorLabel>}
</Stack>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useMemo, useState } from 'react';

import { Input, InputGroup, Stack, Text } from '@stacks/ui';
import { useField } from 'formik';
import { styled } from 'leather-styles/jsx';

import { microStxToStx, stxToMicroStx } from '@app/common/money/unit-conversion';
import { ErrorLabel } from '@app/components/error-label';
Expand Down Expand Up @@ -61,13 +62,7 @@ export function IncreaseFeeField(props: IncreaseFeeFieldProps): React.JSX.Elemen
/>
</InputGroup>
</Stack>
{meta.error && (
<ErrorLabel>
<Text textStyle="caption" lineHeight="18px">
{meta.error}
</Text>
</ErrorLabel>
)}
{meta.error && <ErrorLabel>{meta.error}</ErrorLabel>}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export function ConnectLedgerErrorLayout(props: ConnectLedgerErrorLayoutProps) {
{warningText}
</WarningLabel>
) : (
<ErrorLabel fontSize={1} lineHeight={1.4} mt="base">
Unable to connect
</ErrorLabel>
<ErrorLabel>Unable to connect</ErrorLabel>
)}
<Stack borderRadius="12px" gap="space.01" textAlign="left" py="space.05">
<PossibleReasonUnableToConnect text="Check if Ledger Live is open. Close it and try again" />
Expand Down
15 changes: 3 additions & 12 deletions src/app/pages/onboarding/sign-in/mnemonic-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { OnboardingSelectors } from '@tests/selectors/onboarding.selectors';
import { Form, Formik } from 'formik';
import { css } from 'leather-styles/css';
import { Flex, styled } from 'leather-styles/jsx';

import { isEmpty } from '@shared/utils';
Expand Down Expand Up @@ -89,18 +88,10 @@ export function MnemonicForm({ mnemonic, setMnemonic, twentyFourWordMode }: Mnem
</SecretKeyGrid>
<Flex flexDirection="column" justifyContent="center" alignItems="center" gap="space.05">
{(showMnemonicErrors || error) && (
// #4274 TODO migrate ErrorLabel
<ErrorLabel
width="100%"
className={css({
'& svg': {
mt: '3px',
},
})}
>
<styled.p data-testid={OnboardingSelectors.SignInSeedError} textStyle="caption">
<ErrorLabel>
<styled.span data-testid={OnboardingSelectors.SignInSeedError}>
{showMnemonicErrors ? mnemonicErrorMessage : error}
</styled.p>
</styled.span>
</ErrorLabel>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ export function SendInscriptionForm() {
/>
</Flex>
</Box>
{currentError && (
<ErrorLabel textAlign="left" mb="base-loose">
{currentError}
</ErrorLabel>
)}
{currentError && <ErrorLabel>{currentError}</ErrorLabel>}
<LeatherButton type="submit">Continue</LeatherButton>
</Box>
</SendInscriptionFormLoader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { Box, Flex, Input, Stack, Text, color } from '@stacks/ui';
import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors';
import { useField } from 'formik';
import { styled } from 'leather-styles/jsx';
import { token } from 'leather-styles/tokens';

import { STX_DECIMALS, TOKEN_NAME_LENGTH } from '@shared/constants';
Expand Down

0 comments on commit 688e389

Please sign in to comment.