-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Elevation context wrapping #14593
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,14 @@ import { | |
borders, | ||
Elevation, | ||
mapElevationToBackground, | ||
mapElevationToBackgroundToken, | ||
prevElevation, | ||
spacingsPx, | ||
} from '@trezor/theme'; | ||
|
||
import { IconButton } from '../buttons/IconButton/IconButton'; | ||
import { Text } from '../typography/Text/Text'; | ||
import { H3 } from '../typography/Heading/Heading'; | ||
import { ElevationContext } from '../ElevationContext/ElevationContext'; | ||
import { ElevationContext, useElevation } from '../ElevationContext/ElevationContext'; | ||
import { useScrollShadow } from '../../utils/useScrollShadow'; | ||
import { NewModalButton } from './NewModalButton'; | ||
import { NewModalContext } from './NewModalContext'; | ||
|
@@ -131,7 +131,7 @@ type NewModalProps = AllowedFrameProps & { | |
'data-testid'?: string; | ||
}; | ||
|
||
const NewModalBase = ({ | ||
const _NewModalBase = ({ | ||
children, | ||
variant = 'primary', | ||
size = 'medium', | ||
|
@@ -147,7 +147,9 @@ const NewModalBase = ({ | |
const frameProps = pickAndPrepareFrameProps(rest, allowedNewModalFrameProps); | ||
const { scrollElementRef, onScroll, ShadowContainer, ShadowTop, ShadowBottom } = | ||
useScrollShadow(); | ||
const modalBackgroundColor = mapElevationToBackgroundToken({ $elevation: MODAL_ELEVATION }); | ||
|
||
const { elevation } = useElevation(); | ||
|
||
const hasHeader = onBackClick || onCancel || heading || description; | ||
|
||
useEvent('keydown', (e: KeyboardEvent) => { | ||
|
@@ -157,74 +159,78 @@ const NewModalBase = ({ | |
}); | ||
|
||
return ( | ||
<ElevationContext baseElevation={MODAL_ELEVATION}> | ||
<NewModalContext.Provider value={{ variant }}> | ||
<Container | ||
$elevation={MODAL_ELEVATION} | ||
$size={size} | ||
onClick={e => e.stopPropagation()} | ||
data-testid={dataTest} | ||
{...frameProps} | ||
> | ||
{hasHeader && ( | ||
<Header> | ||
{onBackClick && ( | ||
<IconButton | ||
variant="tertiary" | ||
icon="caretLeft" | ||
data-testid="@modal/back-button" | ||
onClick={onBackClick} | ||
size="small" | ||
/> | ||
)} | ||
|
||
<HeadingContainer> | ||
{heading && <Heading>{heading}</Heading>} | ||
{description && ( | ||
<Text variant="tertiary" typographyStyle="hint"> | ||
{description} | ||
</Text> | ||
)} | ||
</HeadingContainer> | ||
|
||
{onCancel && ( | ||
<IconButton | ||
variant="tertiary" | ||
icon="close" | ||
data-testid="@modal/close-button" | ||
onClick={onCancel} | ||
size="small" | ||
/> | ||
)} | ||
</Header> | ||
<Container | ||
$elevation={elevation} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$size={size} | ||
onClick={e => e.stopPropagation()} | ||
data-testid={dataTest} | ||
{...frameProps} | ||
> | ||
{hasHeader && ( | ||
<Header> | ||
{onBackClick && ( | ||
<IconButton | ||
variant="tertiary" | ||
icon="caretLeft" | ||
data-testid="@modal/back-button" | ||
onClick={onBackClick} | ||
size="small" | ||
/> | ||
)} | ||
<ShadowContainer> | ||
<ShadowTop backgroundColor={modalBackgroundColor} /> | ||
<ScrollContainer onScroll={onScroll} ref={scrollElementRef}> | ||
<Body id={NEW_MODAL_CONTENT_ID}> | ||
{icon && ( | ||
<IconWrapper | ||
$variant={variant} | ||
$size={ICON_SIZE} | ||
$isPushedTop={ | ||
!!onCancel && !heading && !description && !onBackClick | ||
} | ||
> | ||
<Icon name={icon} size={ICON_SIZE} variant={variant} /> | ||
</IconWrapper> | ||
)} | ||
{children} | ||
</Body> | ||
</ScrollContainer> | ||
<ShadowBottom backgroundColor={modalBackgroundColor} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem here is, that The fact its wrapped in We have to create new component function, so the new context is created and the correct The reason why it "worked" (kinda), is because In the light of this issue, I kinda think we should remove default behavior and throw error if Defaults are evil. cc @jvaclavik ☝️ |
||
</ShadowContainer> | ||
{bottomContent && <Footer>{bottomContent}</Footer>} | ||
</Container> | ||
</NewModalContext.Provider> | ||
</ElevationContext> | ||
|
||
<HeadingContainer> | ||
{heading && <Heading>{heading}</Heading>} | ||
{description && ( | ||
<Text variant="tertiary" typographyStyle="hint"> | ||
{description} | ||
</Text> | ||
)} | ||
</HeadingContainer> | ||
|
||
{onCancel && ( | ||
<IconButton | ||
variant="tertiary" | ||
icon="close" | ||
data-testid="@modal/close-button" | ||
onClick={onCancel} | ||
size="small" | ||
/> | ||
)} | ||
</Header> | ||
)} | ||
<ShadowContainer> | ||
<ShadowTop /> | ||
<ScrollContainer onScroll={onScroll} ref={scrollElementRef}> | ||
<Body id={NEW_MODAL_CONTENT_ID}> | ||
{icon && ( | ||
<IconWrapper | ||
$variant={variant} | ||
$size={ICON_SIZE} | ||
$isPushedTop={ | ||
!!onCancel && !heading && !description && !onBackClick | ||
} | ||
> | ||
<Icon name={icon} size={ICON_SIZE} variant={variant} /> | ||
</IconWrapper> | ||
)} | ||
{children} | ||
</Body> | ||
</ScrollContainer> | ||
<ShadowBottom /> | ||
</ShadowContainer> | ||
{bottomContent && <Footer>{bottomContent}</Footer>} | ||
</Container> | ||
); | ||
}; | ||
|
||
const NewModalBase = (props: NewModalProps) => ( | ||
<ElevationContext baseElevation={prevElevation[MODAL_ELEVATION]}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the If we want |
||
<NewModalContext.Provider value={{ variant: props.variant }}> | ||
<_NewModalBase {...props} /> | ||
</NewModalContext.Provider> | ||
</ElevationContext> | ||
); | ||
|
||
const NewModal = (props: NewModalProps) => { | ||
const { alignment, onCancel } = props; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like this naming:D There must be something better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to come up with better name / rename it later ;)