-
-
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): quick-action refactotring, simplification of the UI and …
…adding a update icon
- Loading branch information
1 parent
517ee09
commit a88acab
Showing
20 changed files
with
372 additions
and
109 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/components/src/components/ComponentWithSubIcon/ComponentWithSubIcon.stories.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,36 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { allowedIconFrameProps } from '../Icon/Icon'; | ||
import { | ||
ComponentWithSubIcon as ComponentWithSubIconComponent, | ||
ComponentWithSubIconProps, | ||
} from './ComponentWithSubIcon'; | ||
import { IconName, icons } from '@suite-common/icons/src/icons'; | ||
import { getFramePropsStory } from '../../utils/frameProps'; | ||
import { Icon } from '@suite-common/icons'; | ||
|
||
const meta: Meta = { | ||
title: 'IconWithSubIcon', | ||
component: ComponentWithSubIconComponent, | ||
} as Meta; | ||
export default meta; | ||
|
||
const iconNames = Object.keys(icons) as IconName[]; | ||
|
||
export const ComponentWithSubIcon: StoryObj<ComponentWithSubIconProps> = { | ||
args: { | ||
name: 'check', | ||
subIconBackground: { | ||
variant: 'destructive', | ||
}, | ||
children: <Icon name="tor" />, | ||
}, | ||
argTypes: { | ||
name: { | ||
options: iconNames, | ||
control: { | ||
type: 'select', | ||
}, | ||
}, | ||
...getFramePropsStory(allowedIconFrameProps).argTypes, | ||
}, | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/components/src/components/ComponentWithSubIcon/ComponentWithSubIcon.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,62 @@ | ||
import styled, { useTheme } from 'styled-components'; | ||
import { ExclusiveColorOrVariant, getColorForIconVariant, Icon, IconProps } from '../Icon/Icon'; | ||
import { borders, spacingsPx } from '@trezor/theme'; | ||
import { makePropsTransient, TransientProps } from '../../utils/transientProps'; | ||
import { getIconSize } from '@suite-common/icons'; | ||
import { ReactNode } from 'react'; | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
`; | ||
|
||
type SubIconWrapperProps = TransientProps<ExclusiveColorOrVariant> & { | ||
$subIconColor: string; | ||
$subIconSize: number; | ||
}; | ||
|
||
const SubIconWrapper = styled.div<SubIconWrapperProps>` | ||
position: absolute; | ||
right: -${({ $subIconSize }) => $subIconSize / 2}px; | ||
top: -${({ $subIconSize }) => $subIconSize / 2}px; | ||
background-color: ${({ theme, $variant, $color }) => | ||
getColorForIconVariant({ theme, variant: $variant, color: $color })}; | ||
border-radius: ${borders.radii.full}; | ||
border: 1px solid ${({ $subIconColor }) => $subIconColor}; | ||
padding: ${spacingsPx.xxxs}; | ||
`; | ||
|
||
export type ComponentWithSubIconProps = IconProps & { | ||
subIconBackground: ExclusiveColorOrVariant; | ||
children: ReactNode; | ||
}; | ||
|
||
export const ComponentWithSubIcon = ({ | ||
subIconBackground, | ||
children, | ||
...subIconProps | ||
}: ComponentWithSubIconProps) => { | ||
const theme = useTheme(); | ||
|
||
const iconColor = getColorForIconVariant({ | ||
theme, | ||
color: subIconProps.color, | ||
variant: subIconProps.variant, | ||
}); | ||
|
||
const subIconSize = getIconSize(subIconProps.size ?? 12); | ||
|
||
return ( | ||
<Container> | ||
{children} | ||
<SubIconWrapper | ||
{...makePropsTransient(subIconBackground)} | ||
$subIconColor={iconColor} | ||
$subIconSize={subIconSize} | ||
> | ||
<Icon {...subIconProps} size={subIconSize} /> | ||
</SubIconWrapper> | ||
</Container> | ||
); | ||
}; |
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
91 changes: 0 additions & 91 deletions
91
packages/suite/src/components/suite/layouts/SuiteLayout/Sidebar/HelperIcons.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...ges/suite/src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/CustomBackend.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,32 @@ | ||
import { useTheme } from 'styled-components'; | ||
import { useTranslation } from '../../../../../../hooks/suite'; | ||
import { useEnabledBackends } from '../../utils'; | ||
import { ComponentWithSubIcon, Icon } from '@trezor/components'; | ||
import { NavBackends } from './NavBackends'; | ||
import { QuickActionButton } from './QuickActionButton'; | ||
import { iconSizes } from '@suite-common/icons'; | ||
|
||
export const CustomBackend = () => { | ||
const theme = useTheme(); | ||
const { translationString } = useTranslation(); | ||
|
||
const enabledBackends = useEnabledBackends(); | ||
const isCustomBackendIconVisible = enabledBackends.length > 0; | ||
|
||
return ( | ||
isCustomBackendIconVisible && ( | ||
<NavBackends customBackends={enabledBackends}> | ||
<QuickActionButton tooltip={translationString('TR_CUSTOM_BACKEND')}> | ||
<ComponentWithSubIcon | ||
subIconBackground={{ variant: 'primary' }} | ||
name="check" | ||
color={theme['iconDefaultInverted']} | ||
size={iconSizes.extraSmall} | ||
> | ||
<Icon name="backend" size={iconSizes.medium} /> | ||
</ComponentWithSubIcon> | ||
</QuickActionButton> | ||
</NavBackends> | ||
) | ||
); | ||
}; |
64 changes: 64 additions & 0 deletions
64
...te/src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/DebugAndExperimental.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,64 @@ | ||
import { Icon } from '@trezor/components'; | ||
import { useDispatch, useSelector, useTranslation } from 'src/hooks/suite'; | ||
import { goto } from 'src/actions/suite/routerActions'; | ||
import { SettingsAnchor } from 'src/constants/suite/anchors'; | ||
import { QuickActionButton } from './QuickActionButton'; | ||
import styled from 'styled-components'; | ||
import { getIconSize, iconSizes } from '@suite-common/icons'; | ||
|
||
const Relative = styled.div<{ $size: number }>` | ||
position: relative; | ||
width: ${({ $size }) => $size}px; | ||
height: ${({ $size }) => $size}px; | ||
`; | ||
|
||
const Absolute = styled.div` | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
`; | ||
|
||
export const DebugAndExperimental = () => { | ||
const isEapEnabled = useSelector(state => state.desktopUpdate.allowPrerelease); | ||
const isExperimental = useSelector(state => state.suite.settings.experimental !== undefined); | ||
const isDebugMode = useSelector(state => state.suite.settings.debug.showDebugMenu); | ||
|
||
const { translationString } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
|
||
const handleEapClick = () => { | ||
dispatch(goto('settings-index', { anchor: SettingsAnchor.EarlyAccess })); | ||
}; | ||
|
||
if (!isEapEnabled && !isExperimental && !isDebugMode) return null; | ||
|
||
const tooltip = ( | ||
<> | ||
{isDebugMode && <p>Debug mode active</p>} | ||
{isEapEnabled && <p>{translationString('TR_EARLY_ACCESS')}</p>} | ||
{isExperimental && <p>{translationString('TR_EXPERIMENTAL_FEATURES')}</p>} | ||
</> | ||
); | ||
|
||
return ( | ||
<QuickActionButton tooltip={tooltip} onClick={handleEapClick}> | ||
<Relative $size={getIconSize(iconSizes.medium)}> | ||
{isDebugMode && ( | ||
<Absolute> | ||
<Icon name="debug" variant="destructive" size={iconSizes.medium} /> | ||
</Absolute> | ||
)} | ||
{isExperimental && ( | ||
<Absolute> | ||
<Icon name="experimental" variant="primary" size={iconSizes.medium} /> | ||
</Absolute> | ||
)} | ||
{isEapEnabled && ( | ||
<Absolute> | ||
<Icon name="eap" variant="warning" size={iconSizes.medium} /> | ||
</Absolute> | ||
)} | ||
</Relative> | ||
</QuickActionButton> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
...ages/suite/src/components/suite/layouts/SuiteLayout/Sidebar/QuickActions/HideBalances.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,29 @@ | ||
import { Icon } from '@trezor/components'; | ||
import { setDiscreetMode } from '../../../../../../actions/settings/walletSettingsActions'; | ||
import { useDispatch, useSelector, useTranslation } from '../../../../../../hooks/suite'; | ||
import { selectIsDiscreteModeActive } from '../../../../../../reducers/wallet/settingsReducer'; | ||
import { QuickActionButton } from './QuickActionButton'; | ||
import { iconSizes } from '@suite-common/icons'; | ||
|
||
export const HideBalances = () => { | ||
const dispatch = useDispatch(); | ||
const { translationString } = useTranslation(); | ||
|
||
const isDiscreetModeActive = useSelector(selectIsDiscreteModeActive); | ||
const translationLabel = isDiscreetModeActive ? 'TR_SHOW_BALANCES' : 'TR_HIDE_BALANCES'; | ||
|
||
const handleDiscreetModeClick = () => dispatch(setDiscreetMode(!isDiscreetModeActive)); | ||
|
||
return ( | ||
<QuickActionButton | ||
tooltip={translationString(translationLabel)} | ||
onClick={handleDiscreetModeClick} | ||
> | ||
<Icon | ||
name={isDiscreetModeActive ? 'hide' : 'show'} | ||
variant="tertiary" | ||
size={iconSizes.medium} | ||
/> | ||
</QuickActionButton> | ||
); | ||
}; |
Oops, something went wrong.