-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite): Implementation of the update icons in QuickActions bar
- Loading branch information
1 parent
d916c7a
commit 0c7cc3b
Showing
16 changed files
with
459 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
packages/suite/src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/Update.tsx
This file was deleted.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
...ges/suite/src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/Update/Update.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import styled, { css, DefaultTheme, useTheme } from 'styled-components'; | ||
import { useDevice } from '../../../../../../../hooks/suite'; | ||
import { ComponentWithSubIcon, getIconSize, Icon, iconSizes, Row } from '@trezor/components'; | ||
import { QuickActionButton } from '../QuickActionButton'; | ||
import { UpdateIconGroup } from './UpdateIconGroup'; | ||
import { borders, Color, CSSColor, spacings } from '@trezor/theme'; | ||
import { useUpdateStatus } from './useUpdateStatus'; | ||
import { UpdateTooltip } from './UpdateTooltip'; | ||
import { | ||
mapTrezorModelToIcon, | ||
mapUpdateStatusToIcon, | ||
mapUpdateStatusToVariant, | ||
UpdateVariant, | ||
} from './updateQuickActionTypes'; | ||
|
||
type MapArgs = { | ||
$variant: UpdateVariant; | ||
theme: DefaultTheme; | ||
}; | ||
|
||
export const mapVariantToIconColor = ({ $variant, theme }: MapArgs): CSSColor => { | ||
const colorMap: Record<UpdateVariant, Color> = { | ||
info: 'iconAlertBlue', | ||
purple: 'iconAlertPurple', | ||
tertiary: 'iconSubdued', | ||
}; | ||
|
||
return theme[colorMap[$variant]]; | ||
}; | ||
|
||
type SuiteIconRectangle = { | ||
$variant: UpdateVariant; | ||
$isHighlighted: boolean; | ||
$size: number; | ||
}; | ||
|
||
const SuiteIconRectangle = styled.div<SuiteIconRectangle>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding-left: 0.5px; | ||
width: ${({ $size }) => $size}px; | ||
height: ${({ $size }) => $size}px; | ||
border-radius: ${borders.radii.xxs}; | ||
background-color: ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })}; | ||
${({ $isHighlighted }) => | ||
$isHighlighted | ||
? '' | ||
: css` | ||
opacity: 50%; | ||
`} | ||
`; | ||
|
||
type HighlightedProps = { $isHighlighted: boolean }; | ||
|
||
const Highlighted = styled.div<HighlightedProps>` | ||
${({ $isHighlighted }) => | ||
$isHighlighted | ||
? '' | ||
: css` | ||
opacity: 50%; | ||
`} | ||
`; | ||
|
||
const Relative = styled.div<{ $size: number }>` | ||
position: relative; | ||
width: ${({ $size }) => $size}px; | ||
height: ${({ $size }) => $size}px; | ||
`; | ||
|
||
type UsbCableFroTrezorIcon = { | ||
$variant: UpdateVariant; | ||
$size: number; | ||
}; | ||
|
||
const UsbCableFroTrezorIcon = styled.div<UsbCableFroTrezorIcon>` | ||
border-left: 2px solid ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })}; | ||
height: 5px; | ||
position: absolute; | ||
bottom: -4px; | ||
left: ${({ $size }) => $size / 2}px; | ||
`; | ||
|
||
export const Update = () => { | ||
const theme = useTheme(); | ||
|
||
const { updateStatus, updateStatusDevice, updateStatusSuite } = useUpdateStatus(); | ||
const { device } = useDevice(); | ||
|
||
const updateSubIcon = mapUpdateStatusToIcon[updateStatus]; | ||
const variant = mapUpdateStatusToVariant[updateStatus]; | ||
const iconSize = getIconSize(iconSizes.medium); | ||
|
||
if (device?.features === undefined) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<QuickActionButton | ||
tooltip={ | ||
<UpdateTooltip | ||
updateStatusDevice={updateStatusDevice} | ||
updateStatusSuite={updateStatusSuite} | ||
/> | ||
} | ||
isOpen | ||
> | ||
<ComponentWithSubIcon | ||
variant={variant} | ||
subIconProps={{ | ||
name: updateSubIcon, | ||
color: theme.iconDefaultInverted, | ||
size: iconSizes.extraSmall, | ||
}} | ||
> | ||
<UpdateIconGroup $variant={variant}> | ||
<Row gap={spacings.xxs}> | ||
<Highlighted $isHighlighted={updateStatusDevice !== 'up-to-date'}> | ||
<Relative $size={iconSize}> | ||
<Icon | ||
name={mapTrezorModelToIcon[device.features.internal_model]} | ||
size={iconSizes.medium} | ||
variant={variant} | ||
/> | ||
<UsbCableFroTrezorIcon $variant={variant} $size={iconSize} /> | ||
</Relative> | ||
</Highlighted> | ||
<SuiteIconRectangle | ||
$variant={variant} | ||
$isHighlighted={updateStatusSuite !== 'up-to-date'} | ||
$size={iconSize} | ||
> | ||
<Highlighted $isHighlighted={updateStatusSuite !== 'up-to-date'}> | ||
<Icon | ||
name="trezor" | ||
size={iconSizes.small} | ||
color={theme['iconDefaultInverted']} | ||
/> | ||
</Highlighted> | ||
</SuiteIconRectangle> | ||
</Row> | ||
</UpdateIconGroup> | ||
</ComponentWithSubIcon> | ||
</QuickActionButton> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
.../src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/Update/UpdateIconGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { spacingsPx } from '@trezor/theme'; | ||
import styled, { css } from 'styled-components'; | ||
import { mapVariantToIconBackground, UpdateVariant } from './updateQuickActionTypes'; | ||
|
||
type UpdateIconGroupProps = { | ||
$variant?: UpdateVariant; | ||
}; | ||
|
||
export const UpdateIconGroup = styled.div<UpdateIconGroupProps>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: ${spacingsPx.xxs} ${spacingsPx.xxs}; | ||
margin: -${spacingsPx.xxs}; | ||
background-color: ${({ $variant, theme }) => | ||
$variant && mapVariantToIconBackground({ $variant, theme })}; | ||
border-radius: 6px; | ||
${({ $variant, theme }) => | ||
$variant === 'tertiary' | ||
? css` | ||
border: 1.5px solid ${theme['borderElevationNegative']}; | ||
` | ||
: ''}; | ||
`; |
Oops, something went wrong.