-
-
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
ad0afa3
commit 441999e
Showing
16 changed files
with
539 additions
and
140 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.
199 changes: 199 additions & 0 deletions
199
...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,199 @@ | ||
import styled, { css, DefaultTheme, useTheme } from 'styled-components'; | ||
import { useDevice } from '../../../../../../../hooks/suite'; | ||
import { ComponentWithSubIcon, getIconSize, Icon, IconSize, iconSizes } from '@trezor/components'; | ||
import { QuickActionButton } from '../QuickActionButton'; | ||
import { UpdateIconGroup } from './UpdateIconGroup'; | ||
import { borders, Color, CSSColor } from '@trezor/theme'; | ||
import { useUpdateStatus } from './useUpdateStatus'; | ||
import { UpdateTooltip } from './UpdateTooltip'; | ||
import { | ||
mapTrezorModelToIcon, | ||
mapUpdateStatusToIcon, | ||
mapUpdateStatusToVariant, | ||
UpdateStatus, | ||
UpdateVariant, | ||
} from './updateQuickActionTypes'; | ||
import { isDesktop } from '@trezor/env-utils'; | ||
import { useDispatch } from 'react-redux'; | ||
import { goto } from 'src/actions/suite/routerActions'; | ||
import { SettingsAnchor } from '../../../../../../../constants/suite/anchors'; | ||
|
||
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 HighlightedProps = { $isHighlighted: boolean }; | ||
|
||
const highlighted = css<HighlightedProps>` | ||
${({ $isHighlighted }) => | ||
$isHighlighted | ||
? '' | ||
: css` | ||
opacity: 50%; | ||
`} | ||
`; | ||
|
||
const Highlighted = styled.div<HighlightedProps>` | ||
${highlighted} | ||
`; | ||
|
||
type SuiteIconRectangle = { | ||
$variant: UpdateVariant; | ||
$isHighlighted: boolean; | ||
$size: IconSize; | ||
}; | ||
|
||
const SuiteIconRectangle = styled.div<SuiteIconRectangle>` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding-left: 0.5px; | ||
width: ${({ $size }) => getIconSize($size)}px; | ||
height: ${({ $size }) => getIconSize($size)}px; | ||
border-radius: ${borders.radii.xxs}; | ||
background-color: ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })}; | ||
${highlighted} | ||
`; | ||
|
||
const Relative = styled.div<{ $size: IconSize }>` | ||
position: relative; | ||
width: ${({ $size }) => getIconSize($size)}px; | ||
height: ${({ $size }) => getIconSize($size)}px; | ||
`; | ||
|
||
type UsbCableFroTrezorIcon = { | ||
$variant: UpdateVariant; | ||
$size: IconSize; | ||
}; | ||
|
||
const UsbCableFroTrezorIcon = styled.div<UsbCableFroTrezorIcon>` | ||
border-left: 2px solid ${({ $variant, theme }) => mapVariantToIconColor({ $variant, theme })}; | ||
height: 5px; | ||
position: absolute; | ||
bottom: -4px; | ||
left: ${({ $size }) => getIconSize($size) / 2}px; | ||
`; | ||
|
||
type DeviceUpdateIconProps = { | ||
iconSize: IconSize; | ||
updateStatus: UpdateStatus; | ||
variant: UpdateVariant; | ||
}; | ||
|
||
const DeviceUpdateIcon = ({ iconSize, updateStatus, variant }: DeviceUpdateIconProps) => { | ||
const { device } = useDevice(); | ||
|
||
if (device?.features === undefined) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Highlighted $isHighlighted={updateStatus !== '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> | ||
); | ||
}; | ||
|
||
type SuiteUpdateIconProps = { | ||
iconSize: IconSize; | ||
updateStatus: UpdateStatus; | ||
variant: UpdateVariant; | ||
}; | ||
|
||
const SuiteUpdateIcon = ({ iconSize, updateStatus, variant }: SuiteUpdateIconProps) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<SuiteIconRectangle | ||
$variant={variant} | ||
$isHighlighted={updateStatus !== 'up-to-date'} | ||
$size={iconSize} | ||
> | ||
<Highlighted $isHighlighted={updateStatus !== 'up-to-date'}> | ||
<Icon name="trezor" size={iconSizes.small} color={theme['iconDefaultInverted']} /> | ||
</Highlighted> | ||
</SuiteIconRectangle> | ||
); | ||
}; | ||
|
||
export const Update = () => { | ||
const theme = useTheme(); | ||
|
||
const { updateStatus, updateStatusDevice, updateStatusSuite } = useUpdateStatus(); | ||
const { device } = useDevice(); | ||
const dispatch = useDispatch(); | ||
|
||
const updateSubIcon = mapUpdateStatusToIcon[updateStatus]; | ||
const variant = mapUpdateStatusToVariant[updateStatus]; | ||
const iconSize: IconSize = 'medium'; | ||
|
||
const isDesktopSuite = isDesktop(); | ||
|
||
if (device?.features === undefined) { | ||
return null; | ||
} | ||
|
||
const handleOnclick = () => { | ||
if (updateStatusSuite === 'update-available') { | ||
dispatch(goto('settings-index', { anchor: SettingsAnchor.VersionWithUpdate })); | ||
} else if (updateStatusDevice === 'update-available') { | ||
dispatch(goto('settings-device', { anchor: SettingsAnchor.FirmwareVersion })); | ||
} | ||
}; | ||
|
||
return ( | ||
<QuickActionButton | ||
tooltip={ | ||
<UpdateTooltip | ||
updateStatusDevice={updateStatusDevice} | ||
updateStatusSuite={updateStatusSuite} | ||
/> | ||
} | ||
onClick={handleOnclick} | ||
> | ||
<ComponentWithSubIcon | ||
variant={variant} | ||
subIconProps={{ | ||
name: updateSubIcon, | ||
color: theme.iconDefaultInverted, | ||
size: iconSizes.extraSmall, | ||
}} | ||
> | ||
<UpdateIconGroup $variant={variant}> | ||
<DeviceUpdateIcon | ||
iconSize={iconSize} | ||
updateStatus={updateStatusDevice} | ||
variant={variant} | ||
/> | ||
{isDesktopSuite && ( | ||
<SuiteUpdateIcon | ||
iconSize={iconSize} | ||
updateStatus={updateStatusDevice} | ||
variant={variant} | ||
/> | ||
)} | ||
</UpdateIconGroup> | ||
</ComponentWithSubIcon> | ||
</QuickActionButton> | ||
); | ||
}; |
Oops, something went wrong.