diff --git a/packages/components/src/components/buttons/Button/Button.tsx b/packages/components/src/components/buttons/Button/Button.tsx index f77d3095552..5d457ea81a6 100644 --- a/packages/components/src/components/buttons/Button/Button.tsx +++ b/packages/components/src/components/buttons/Button/Button.tsx @@ -1,6 +1,6 @@ import { ButtonHTMLAttributes } from 'react'; import styled, { useTheme } from 'styled-components'; -import { borders, spacingsPx, typography } from '@trezor/theme'; +import { borders, Elevation, spacingsPx, typography } from '@trezor/theme'; import { Spinner } from '../../loaders/Spinner/Spinner'; import { ButtonSize, @@ -15,11 +15,13 @@ import { focusStyleTransition, getFocusShadowStyle } from '../../../utils/utils' import { makePropsTransient, TransientProps } from '../../../utils/transientProps'; import { FrameProps, FramePropsKeys, withFrameProps } from '../../../utils/frameProps'; import { Icon, IconName } from '../../Icon/Icon'; +import { useElevation } from '../../ElevationContext/ElevationContext'; export const allowedButtonFrameProps: FramePropsKeys[] = ['margin']; type AllowedFrameProps = Pick; type ButtonContainerProps = TransientProps & { + $elevation: Elevation; $variant: ButtonVariant; $size: ButtonSize; $iconAlignment?: IconAlignment; @@ -46,7 +48,7 @@ export const ButtonContainer = styled.button` border: 1px solid transparent; ${getFocusShadowStyle()} - ${({ $variant, $isSubtle }) => useVariantStyle($variant, $isSubtle)} + ${({ $variant, $isSubtle, $elevation }) => useVariantStyle($variant, $isSubtle, $elevation)} &:disabled { background: ${({ theme }) => theme.backgroundNeutralDisabled}; @@ -139,6 +141,8 @@ export const Button = ({ ); + const { elevation } = useElevation(); + return ( {!isLoading && icon && IconComponent} diff --git a/packages/components/src/components/buttons/buttonStyleUtils.ts b/packages/components/src/components/buttons/buttonStyleUtils.ts index 8b309999318..25c41071ba0 100644 --- a/packages/components/src/components/buttons/buttonStyleUtils.ts +++ b/packages/components/src/components/buttons/buttonStyleUtils.ts @@ -1,8 +1,9 @@ -import { css, useTheme } from 'styled-components'; +import { DefaultTheme, css, useTheme } from 'styled-components'; -import { Colors, spacings, spacingsPx } from '@trezor/theme'; +import { Color, Colors, Elevation, spacings, spacingsPx } from '@trezor/theme'; import type { UIHorizontalAlignment, UISize, UIVariant } from '../../config/types'; import { hexToRgba } from '@suite-common/suite-utils'; +import { capitalizeFirstLetter } from '@trezor/utils'; const SUBTLE_ALPHA = 0.12; const SUBTLE_ALPHA_HOVER = 0.2; @@ -59,6 +60,36 @@ export const getIconColor = ({ } }; +export type ButtonState = 'normal' | 'hover'; + +export const mapElevationToBackgroundToken = ({ $elevation }: { $elevation: Elevation }): Color => + `backgroundSurfaceElevation${$elevation === -1 ? 'Negative' : $elevation}`; + +const mapElevationToButtonBackground = ({ + elevation, + theme, + state, +}: { + elevation: Elevation; + theme: DefaultTheme; + state: ButtonState; +}) => { + const capitalizedState = capitalizeFirstLetter(state); + + const map: Record = { + '-1': `interactionBackgroundTertiaryDefault${capitalizedState}OnElevation3`, // For example left menu is negative elevation + + // Button lies always on elevation so for example Button that lies has elevation 0, lies on elevation -1. + // This is why the values here a shifted by 1. + 0: `interactionBackgroundTertiaryDefault${capitalizedState}OnElevationNegative`, + 1: `interactionBackgroundTertiaryDefault${capitalizedState}OnElevation0`, + 2: `interactionBackgroundTertiaryDefault${capitalizedState}OnElevation1`, + 3: `interactionBackgroundTertiaryDefault${capitalizedState}OnElevation2`, + }; + + return theme[map[elevation]]; +}; + export const getIconSize = (size: ButtonSize) => { switch (size) { case 'large': @@ -78,6 +109,7 @@ export const getIconSize = (size: ButtonSize) => { export const useVariantStyle = ( variant: ButtonVariant, isSubtle: boolean, + elevation: Elevation, ): ReturnType => { const theme = useTheme(); @@ -88,8 +120,16 @@ export const useVariantStyle = ( text: theme.textOnPrimary, }, tertiary: { - background: theme.backgroundTertiaryDefaultOnElevation0, - backgroundHover: theme.backgroundTertiaryPressedOnElevation0, + background: mapElevationToButtonBackground({ + elevation, + theme, + state: 'normal', + }), + backgroundHover: mapElevationToButtonBackground({ + elevation, + theme, + state: 'hover', + }), text: theme.textOnTertiary, }, info: {