-
Notifications
You must be signed in to change notification settings - Fork 30
Refactor banner component #15166
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
Open
juabara
wants to merge
14
commits into
main
Choose a base branch
from
jm/feat-refactor-banner-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor banner component #15166
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3c14be4
refactor(wip): designable banner v2 using compound pattern
687aeb8
refactor(designable-banner-v2): add close handling, tracking integrat…
6adfdf9
refactor(designable-banner-v2): improve mobile layout and conditional…
e168376
refactor(designable-banner-v2): replace context with prop drilling fo…
a14449f
Merge branch 'main' into jm/feat-refactor-banner-component
juabara 72eca7c
refactor(designable-banner-v2): rename index.ts to exports.ts and upd…
77a3e09
Merge branch 'jm/feat-refactor-banner-component' of github.com:guardi…
41a8819
refactor(designable-banner-v2): add explicit return type to getCompon…
11cbd67
refactor(designable-banner-v2): extract banner model logic into custo…
aa6e117
Merge branch 'main' into jm/feat-refactor-banner-component
juabara 0607ad0
Merge branch 'main' into jm/feat-refactor-banner-component
juabara c8d446b
refactor: remove unused children prop from CloseableBannerProps inter…
5c60503
refactor: remove legacy designable banner import path
01fae3a
Merge branch 'main' into jm/feat-refactor-banner-component
juabara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
290 changes: 290 additions & 0 deletions
290
dotcom-rendering/src/components/marketing/banners/designableBanner/v2/Banner.tsx
This file contains hidden or 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,290 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { | ||
| between, | ||
| from, | ||
| neutral, | ||
| space, | ||
| until, | ||
| } from '@guardian/source/foundations'; | ||
| import { useEffect, useRef } from 'react'; | ||
| import { | ||
| bannerWrapper, | ||
| validatedBannerWrapper, | ||
| } from '../../common/BannerWrapper'; | ||
| import type { BannerRenderProps } from '../../common/types'; | ||
| import { BannerArticleCount } from './components/BannerArticleCount'; | ||
| import { BannerBody } from './components/BannerBody'; | ||
| import { BannerChoiceCards } from './components/BannerChoiceCards'; | ||
| import { BannerCloseButton } from './components/BannerCloseButton'; | ||
| import { BannerContent } from './components/BannerContent'; | ||
| import { BannerCtas } from './components/BannerCtas'; | ||
| import { BannerHeader } from './components/BannerHeader'; | ||
| import { BannerLogo } from './components/BannerLogo'; | ||
| import { BannerTicker } from './components/BannerTicker'; | ||
| import { BannerVisual } from './components/BannerVisual'; | ||
| import { useDesignableBannerModel } from './useDesignableBannerModel'; | ||
|
|
||
| const phabletContentMaxWidth = '492px'; | ||
|
|
||
| const styles = { | ||
| outerContainer: (background: string, textColor: string = 'inherit') => css` | ||
| background: ${background}; | ||
| color: ${textColor}; | ||
| bottom: 0px; | ||
| max-height: 65vh; | ||
| max-height: 65svh; | ||
|
|
||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| ${from.phablet} { | ||
| border-top: 1px solid ${neutral[0]}; | ||
| } | ||
| b, | ||
| strong { | ||
| font-weight: bold; | ||
| } | ||
| padding: 0 auto; | ||
| `, | ||
| layoutOverrides: (cardsImageOrSpaceTemplateString: string) => css` | ||
| display: grid; | ||
| background: inherit; | ||
| position: relative; | ||
| bottom: 0px; | ||
|
|
||
| /* mobile first */ | ||
| ${until.phablet} { | ||
| max-width: 660px; | ||
| margin: 0 auto; | ||
| padding: ${space[3]}px ${space[3]}px 0 ${space[3]}px; | ||
| grid-template-columns: auto max(${phabletContentMaxWidth} auto); | ||
| grid-template-areas: | ||
| '. . .' | ||
| '. copy-container close-button' | ||
| '. ${cardsImageOrSpaceTemplateString} ${cardsImageOrSpaceTemplateString}' | ||
| '. cta-container cta-container'; | ||
| } | ||
| ${from.phablet} { | ||
| max-width: 740px; | ||
| margin: 0 auto; | ||
| padding: ${space[3]}px ${space[3]}px 0 ${space[3]}px; | ||
| grid-template-columns: minmax(0, 0.5fr) ${phabletContentMaxWidth} max-content minmax( | ||
| 0, | ||
| 0.5fr | ||
| ); | ||
| grid-template-rows: auto auto auto; | ||
| grid-template-areas: | ||
| '. copy-container close-button close-button' | ||
| '. ${cardsImageOrSpaceTemplateString} ${cardsImageOrSpaceTemplateString} .' | ||
| '. cta-container cta-container .'; | ||
| } | ||
| ${from.desktop} { | ||
| max-width: 980px; | ||
| align-self: stretch; | ||
| padding: ${space[3]}px ${space[1]}px 0 ${space[3]}px; | ||
| grid-template-columns: auto 380px auto; | ||
| grid-template-rows: auto auto; | ||
|
|
||
| grid-template-areas: | ||
| 'copy-container ${cardsImageOrSpaceTemplateString} close-button' | ||
| 'cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| ${from.leftCol} { | ||
| max-width: 1140px; | ||
| bottom: 0px; | ||
| /* the vertical line aligns with that of standard article */ | ||
| grid-column-gap: 10px; | ||
| grid-template-columns: 140px 1px min(460px) min(380px) auto; | ||
| grid-template-rows: auto auto; | ||
| grid-template-areas: | ||
| 'logo vert-line copy-container ${cardsImageOrSpaceTemplateString} close-button' | ||
| '. vert-line cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| ${from.wide} { | ||
| max-width: 1300px; | ||
| /* the vertical line aligns with that of standard article */ | ||
| grid-template-columns: 219px 1px min(460px) min(380px) auto; | ||
| grid-template-rows: auto auto; | ||
| grid-template-areas: | ||
| 'logo vert-line copy-container ${cardsImageOrSpaceTemplateString} close-button' | ||
| '. vert-line cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| `, | ||
| collapsedLayoutOverrides: (cardsImageOrSpaceTemplateString: string) => css` | ||
| display: grid; | ||
| background: inherit; | ||
| position: relative; | ||
| bottom: 0px; | ||
|
|
||
| /* mobile first */ | ||
| ${until.phablet} { | ||
| max-width: 660px; | ||
| margin: 0 auto; | ||
| padding: ${space[2]}px ${space[3]}px 0 ${space[3]}px; | ||
| grid-template-columns: auto max(${phabletContentMaxWidth} auto); | ||
| grid-template-areas: ${` | ||
| '. . .' | ||
| '. copy-container close-button' | ||
| '. ${cardsImageOrSpaceTemplateString} ${cardsImageOrSpaceTemplateString}' | ||
| '. cta-container cta-container' | ||
| `}; | ||
| } | ||
| ${from.phablet} { | ||
| max-width: 740px; | ||
| margin: 0 auto; | ||
| padding: ${space[2]}px ${space[3]}px 0 ${space[3]}px; | ||
| grid-template-columns: | ||
| minmax(0, 0.5fr) | ||
| ${phabletContentMaxWidth} | ||
| 1fr | ||
| 0; | ||
| grid-template-rows: auto auto; | ||
| grid-template-areas: | ||
| '. copy-container close-button .' | ||
| '. ${cardsImageOrSpaceTemplateString} ${cardsImageOrSpaceTemplateString} .' | ||
| '. cta-container cta-container .'; | ||
| } | ||
| ${from.desktop} { | ||
| max-width: 980px; | ||
| padding: ${space[1]}px ${space[1]}px 0 ${space[3]}px; | ||
| grid-template-columns: auto 380px minmax(100px, auto); | ||
| grid-template-rows: auto auto; | ||
|
|
||
| grid-template-areas: | ||
| 'copy-container ${cardsImageOrSpaceTemplateString} close-button' | ||
| 'cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| ${from.leftCol} { | ||
| max-width: 1140px; | ||
| bottom: 0px; | ||
| /* the vertical line aligns with that of standard article */ | ||
| grid-column-gap: 10px; | ||
| grid-template-columns: 140px 1px min(460px) min(380px) auto; | ||
| grid-template-rows: auto auto; | ||
| grid-template-areas: | ||
| 'logo vert-line copy-container ${cardsImageOrSpaceTemplateString} close-button ' | ||
| '. vert-line cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| ${from.wide} { | ||
| max-width: 1300px; | ||
| /* the vertical line aligns with that of standard article */ | ||
| grid-template-columns: 219px 1px min(460px) min(380px) auto; | ||
| grid-template-rows: auto auto; | ||
| grid-template-areas: | ||
| 'logo vert-line copy-container ${cardsImageOrSpaceTemplateString} close-button ' | ||
| '. vert-line cta-container ${cardsImageOrSpaceTemplateString} .'; | ||
| } | ||
| `, | ||
| bannerVisualContainer: css` | ||
| grid-area: main-image; | ||
|
|
||
| margin-left: ${space[2]}px; | ||
| margin-right: ${space[2]}px; | ||
|
|
||
| ${from.phablet} { | ||
| max-width: ${phabletContentMaxWidth}; | ||
| justify-self: center; | ||
| } | ||
| ${from.desktop} { | ||
| margin-top: ${space[6]}px; | ||
| padding-left: ${space[2]}px; | ||
| justify-self: end; | ||
| } | ||
| ${between.desktop.and.wide} { | ||
| max-width: 380px; | ||
| } | ||
| ${from.wide} { | ||
| max-width: 485px; | ||
| align-self: start; | ||
| } | ||
| `, | ||
| verticalLine: css` | ||
| grid-area: vert-line; | ||
| pointer-events: none; | ||
|
|
||
| ${until.leftCol} { | ||
| display: none; | ||
| } | ||
| ${from.leftCol} { | ||
| background-color: ${neutral[0]}; | ||
| width: 1px; | ||
| opacity: 0.2; | ||
| margin: ${space[6]}px ${space[2]}px 0 ${space[2]}px; | ||
| } | ||
| `, | ||
| }; | ||
|
|
||
| const Banner = (props: BannerRenderProps): JSX.Element | null => { | ||
| const bannerRef = useRef<HTMLDivElement>(null); | ||
| const { isOpen, bannerData } = useDesignableBannerModel(props); | ||
|
|
||
| useEffect(() => { | ||
| if (bannerRef.current) { | ||
| bannerRef.current.focus(); | ||
| } | ||
| }, []); | ||
|
|
||
| if (!isOpen || !bannerData) { | ||
| return null; | ||
| } | ||
|
|
||
| const contextClassName = | ||
| bannerData.isCollapsible || | ||
| bannerData.tracking.abTestVariant.includes('COLLAPSABLE_V2_MAYBE_LATER') | ||
| ? 'maybe-later' | ||
| : ''; | ||
|
|
||
| const cardsImageOrSpaceTemplateString = bannerData.settings | ||
| .choiceCardSettings | ||
| ? 'choice-cards-container' | ||
| : bannerData.settings.imageSettings | ||
| ? 'main-image' | ||
| : '.'; | ||
|
|
||
| return ( | ||
| <div | ||
| ref={bannerRef} | ||
| role="alert" | ||
| tabIndex={-1} | ||
| css={styles.outerContainer( | ||
| bannerData.settings.containerSettings.backgroundColour, | ||
| bannerData.settings.containerSettings.textColor ?? 'inherit', | ||
| )} | ||
| className={contextClassName} | ||
| > | ||
| <div | ||
| css={ | ||
| bannerData.isCollapsible && bannerData.isCollapsed | ||
| ? styles.collapsedLayoutOverrides( | ||
| cardsImageOrSpaceTemplateString, | ||
| ) | ||
| : styles.layoutOverrides( | ||
| cardsImageOrSpaceTemplateString, | ||
| ) | ||
| } | ||
| > | ||
| <div css={styles.verticalLine} /> | ||
| <BannerLogo bannerData={bannerData} /> | ||
| <BannerContent bannerData={bannerData}> | ||
| <BannerHeader bannerData={bannerData} /> | ||
| <BannerArticleCount bannerData={bannerData} /> | ||
| <BannerTicker bannerData={bannerData} /> | ||
| <BannerBody bannerData={bannerData} /> | ||
| </BannerContent> | ||
| <BannerChoiceCards bannerData={bannerData} /> | ||
| <BannerCtas bannerData={bannerData} /> | ||
| <BannerVisual bannerData={bannerData} /> | ||
| <BannerCloseButton bannerData={bannerData} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const unvalidated = bannerWrapper(Banner, 'designable-banner'); | ||
| const validated = validatedBannerWrapper(Banner, 'designable-banner'); | ||
|
|
||
| export { | ||
| Banner as BannerComponent, | ||
| unvalidated as DesignableBannerUnvalidated, | ||
| validated as DesignableBanner, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.