From 2db40a5dfed7c8743da2ff2cce78e86e557a0aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20V=C3=A1clav=C3=ADk?= Date: Tue, 21 Jan 2025 13:50:27 +0100 Subject: [PATCH] fix(suite): Fix firmware update progress bar (#16417) (cherry picked from commit df170dc9600e643ba0b7424169007d063df03b09) --- .../loaders/ProgressBar/ProgressBar.tsx | 49 ++++++++--- packages/components/src/utils/frameProps.tsx | 2 +- .../firmware/FirmwareProgressBar.tsx | 84 ++++++------------- 3 files changed, 64 insertions(+), 71 deletions(-) diff --git a/packages/components/src/components/loaders/ProgressBar/ProgressBar.tsx b/packages/components/src/components/loaders/ProgressBar/ProgressBar.tsx index 4643011df04..d29a1f76a65 100644 --- a/packages/components/src/components/loaders/ProgressBar/ProgressBar.tsx +++ b/packages/components/src/components/loaders/ProgressBar/ProgressBar.tsx @@ -1,7 +1,9 @@ -import styled from 'styled-components'; +import styled, { useTheme } from 'styled-components'; -const Wrapper = styled.div` - background: ${({ theme }) => theme.backgroundNeutralSubdued}; +import { CSSColor } from '@trezor/theme'; + +const Wrapper = styled.div<{ $color: CSSColor }>` + background: ${({ $color }) => $color}; width: 100%; overflow: hidden; `; @@ -9,27 +11,48 @@ const Wrapper = styled.div` type ValueProps = { $max: number; $value: number; + $color: CSSColor; }; const Value = styled.div` - background: ${({ theme }) => theme.iconPrimaryDefault}; + background: ${({ $color }) => $color}; height: 5px; max-width: 100%; - width: 1%; - transform: ${({ $max, $value }) => `scaleX(${(100 / $max) * $value})`}; - transform-origin: left; - transition: transform 0.5s; + width: ${({ $max, $value }) => `calc((100% / ${$max}) * ${$value})`}; + transition: width 0.5s; `; export type ProgressBarProps = { max?: number; value: number; + backgroundColor?: CSSColor; + foregroundColor?: CSSColor; + 'data-testid'?: string; + /** + * @deprecated Legacy prop - do not add non-standard properties + */ + className?: string; }; -export const ProgressBar = ({ max = 100, value, ...props }: ProgressBarProps) => ( - - - -); +export const ProgressBar = ({ + max = 100, + value, + backgroundColor, + foregroundColor, + className, + 'data-testid': dataTestId, +}: ProgressBarProps) => { + const theme = useTheme(); + + return ( + + + + ); +}; ProgressBar.Value = Value; diff --git a/packages/components/src/utils/frameProps.tsx b/packages/components/src/utils/frameProps.tsx index 5181ec0c53c..c56095337d4 100644 --- a/packages/components/src/utils/frameProps.tsx +++ b/packages/components/src/utils/frameProps.tsx @@ -80,7 +80,7 @@ export type FramePropsKeys = keyof FrameProps; type TransientFrameProps = TransientProps; const getValueWithUnit = (value: string | number) => - typeof value === 'string' ? value : `${value}px`; + typeof value === 'number' ? `${value}px` : value; export const pickAndPrepareFrameProps = ( props: Record, diff --git a/packages/suite/src/components/firmware/FirmwareProgressBar.tsx b/packages/suite/src/components/firmware/FirmwareProgressBar.tsx index 97ba8eb8afd..102e041c21d 100644 --- a/packages/suite/src/components/firmware/FirmwareProgressBar.tsx +++ b/packages/suite/src/components/firmware/FirmwareProgressBar.tsx @@ -1,54 +1,15 @@ import styled, { useTheme } from 'styled-components'; -import { Icon, ProgressBar, variables } from '@trezor/components'; -import { borders, spacingsPx } from '@trezor/theme'; +import { Box, Column, Icon, ProgressBar, Row, Text } from '@trezor/components'; +import { spacings } from '@trezor/theme'; import { TranslationKey } from '@suite-common/intl-types'; import { FirmwareOperationStatus, useFirmwareInstallation } from '@suite-common/firmware'; import { Translation } from '../suite'; -const Wrapper = styled.div` - display: flex; - border-radius: ${borders.radii.xs}; - padding: ${spacingsPx.lg} ${spacingsPx.xl}; - width: 100%; - font-size: ${variables.FONT_SIZE.SMALL}; - color: ${({ theme }) => theme.legacy.TYPE_LIGHT_GREY}; - align-items: center; - - ${variables.SCREEN_QUERY.ABOVE_LAPTOP} { - &:last-child { - border-radius: 0 0 ${borders.radii.md} ${borders.radii.md}; - } - } -`; - -const Label = styled.div` - display: flex; - margin-right: ${spacingsPx.lg}; - font-weight: ${variables.FONT_WEIGHT.MEDIUM}; -`; - -// eslint-disable-next-line local-rules/no-override-ds-component -const StyledProgressBar = styled(ProgressBar)` - display: flex; - margin-right: ${spacingsPx.lg}; - border-radius: ${borders.radii.xxs}; - background: ${({ theme }) => theme.legacy.STROKE_GREY_ALT}; - flex: 1; - - ${ProgressBar.Value} { - height: 3px; - position: relative; - border-radius: ${borders.radii.xxs}; - } -`; const Percentage = styled.div` - display: flex; - margin-left: ${spacingsPx.sm}; - font-weight: ${variables.FONT_WEIGHT.DEMI_BOLD}; font-variant-numeric: tabular-nums; - height: ${spacingsPx.xl}; + width: 30px; `; const mapOperationToTransaltionId: Record< @@ -68,20 +29,29 @@ export const FirmwareProgressBar = () => { const isDone = progress === 100; return ( - - {operation && ( - - )} - - - {isDone ? ( - - ) : ( - `${progress} %` - )} - - + + + + {operation ? : ' '} + + + + + + {isDone ? ( + + ) : ( + + {progress} + {'\u00A0'}% + + )} + + + + ); };