Skip to content

Commit

Permalink
fix(suite): restructure SettingsSection to properly display explanato…
Browse files Browse the repository at this point in the history
…ry tooltips
  • Loading branch information
vojtatranta committed Feb 12, 2025
1 parent e925744 commit c770f64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
5 changes: 4 additions & 1 deletion packages/components/src/components/InfoItem/InfoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Container = styled.div<ContainerProps>`

export type InfoItemProps = AllowedFrameProps &
AllowedTextProps & {
allowTextWrap?: boolean;
children?: ReactNode;
direction?: FlexDirection;
iconName?: IconName;
Expand All @@ -56,6 +57,7 @@ export type InfoItemProps = AllowedFrameProps &
};

export const InfoItem = ({
allowTextWrap = false,
children,
label,
direction = 'column',
Expand All @@ -79,6 +81,7 @@ export const InfoItem = ({
gap={gap ?? (isRow ? spacings.md : mapTypographyStyleToLabelGap(typographyStyle))}
>
<Row
alignItems="start"
gap={mapTypographyStyleToIconGap(typographyStyle)}
width={labelWidth}
flex={labelWidth ? '0 0 auto' : '1 0 auto'}
Expand All @@ -94,7 +97,7 @@ export const InfoItem = ({
variant={variant}
typographyStyle={typographyStyle}
as="div"
ellipsisLineCount={1}
ellipsisLineCount={allowTextWrap ? undefined : 1}
>
{label}
</Text>
Expand Down
26 changes: 23 additions & 3 deletions packages/suite/src/components/settings/SettingsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import React, { ReactNode } from 'react';

import { Card, Column, IconName, InfoItem, useMediaQuery, variables } from '@trezor/components';
import {
Card,
Column,
Icon,
IconName,
InfoItem,
Tooltip,
useMediaQuery,
variables,
} from '@trezor/components';
import { spacings } from '@trezor/theme';

type SettingsSectionProps = {
title: ReactNode;
icon?: IconName;
className?: string;
children?: ReactNode;
tooltipText?: ReactNode;
};

export const SettingsSection = ({ title, icon, children }: SettingsSectionProps) => {
export const SettingsSection = ({ title, icon, children, tooltipText }: SettingsSectionProps) => {
const isBelowLaptop = useMediaQuery(`(max-width: ${variables.SCREEN_SIZE.LG})`);

return (
<InfoItem
allowTextWrap
direction={isBelowLaptop ? 'column' : 'row'}
labelWidth={250}
iconName={icon}
label={title}
label={
<>
{title}
{tooltipText && (
<Tooltip isInline content={tooltipText}>
<Icon name="question" size="medium" />
</Tooltip>
)}
</>
}
variant="default"
typographyStyle="titleSmall"
verticalAlignment="top"
Expand Down
17 changes: 4 additions & 13 deletions packages/suite/src/views/settings/SettingsCoins/SettingsCoins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,8 @@ export const SettingsCoins = () => {
</SettingsSection>

<SettingsSection
title={
<Tooltip content={<Translation id="TR_TESTNET_COINS_DESCRIPTION" />} hasIcon>
<Translation id="TR_TESTNET_COINS" />
</Tooltip>
}
tooltipText={<Translation id="TR_TESTNET_COINS_DESCRIPTION" />}
title={<Translation id="TR_TESTNET_COINS" />}
icon="coin"
>
<SettingsSectionItem anchorId={SettingsAnchor.TestnetCrypto}>
Expand All @@ -142,14 +139,8 @@ export const SettingsCoins = () => {

{showUnsupportedCoins && (
<SettingsSection
title={
<Tooltip
content={<Translation id="TR_UNSUPPORTED_COINS_DESCRIPTION" />}
hasIcon
>
<Translation id="TR_UNSUPPORTED_COINS" />
</Tooltip>
}
tooltipText={<Translation id="TR_UNSUPPORTED_COINS_DESCRIPTION" />}
title={<Translation id="TR_UNSUPPORTED_COINS" />}
icon="coin"
>
<SettingsSectionItem anchorId={SettingsAnchor.UnsupportedCrypto}>
Expand Down

0 comments on commit c770f64

Please sign in to comment.