Skip to content
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

Enable container overrides with CSS custom properties #9441

Merged
merged 2 commits into from
Nov 14, 2023

Conversation

mxdvl
Copy link
Contributor

@mxdvl mxdvl commented Nov 8, 2023

What does this change?

Create a wrapper component similar to FormatBoundary that allows to create container overrides for existing palette colours.

Why?

This is a requirement as part of our move to the new palette and progressing with #9110

Screenshots

See Chromatic. There’s a demo of it in the new CardHeadline story:

image

@mxdvl mxdvl requested a review from a team as a code owner November 8, 2023 14:13
@mxdvl mxdvl changed the base branch from main to darkmode/split-theme-decorator-fix November 8, 2023 14:13
Copy link

github-actions bot commented Nov 8, 2023

Size Change: -12.6 kB (-2%)

Total Size: 696 kB

Filename Size Change
dotcom-rendering/dist/3653.web.********************.js 0 B -12.8 kB (removed) 🏆
dotcom-rendering/dist/LatestLinks-importable.web.********************.js 1.17 kB +205 B (+21%) 🚨
ℹ️ View Unchanged
Filename Size Change
dotcom-rendering/dist/1076.web.********************.js 3.08 kB 0 B
dotcom-rendering/dist/1149.web.********************.js 2.92 kB 0 B
dotcom-rendering/dist/1226.web.********************.js 3.66 kB 0 B
dotcom-rendering/dist/1244.web.********************.js 865 B 0 B
dotcom-rendering/dist/1294.web.********************.js 5.36 kB 0 B
dotcom-rendering/dist/1406.web.********************.js 5.09 kB 0 B
dotcom-rendering/dist/1418.web.********************.js 10.2 kB 0 B
dotcom-rendering/dist/1465.web.********************.js 3.32 kB 0 B
dotcom-rendering/dist/1486.web.********************.js 744 B 0 B
dotcom-rendering/dist/1521.web.********************.js 5.48 kB 0 B
dotcom-rendering/dist/1659.web.********************.js 518 B 0 B
dotcom-rendering/dist/1848.web.********************.js 644 B 0 B
dotcom-rendering/dist/1959.web.********************.js 29.5 kB 0 B
dotcom-rendering/dist/1987.web.********************.js 3.12 kB 0 B
dotcom-rendering/dist/1997.web.********************.js 744 B 0 B
dotcom-rendering/dist/2071.web.********************.js 745 B 0 B
dotcom-rendering/dist/2096.web.********************.js 12.9 kB 0 B
dotcom-rendering/dist/21.web.********************.js 758 B 0 B
dotcom-rendering/dist/2126.web.********************.js 884 B 0 B
dotcom-rendering/dist/2133.web.********************.js 4.46 kB 0 B
dotcom-rendering/dist/2201.web.********************.js 778 B 0 B
dotcom-rendering/dist/2228.web.********************.js 899 B 0 B
dotcom-rendering/dist/2339.web.********************.js 778 B 0 B
dotcom-rendering/dist/2351.web.********************.js 3.34 kB 0 B
dotcom-rendering/dist/2394.web.********************.js 2.12 kB 0 B
dotcom-rendering/dist/2467.web.********************.js 2.08 kB 0 B
dotcom-rendering/dist/2494.web.********************.js 774 B 0 B
dotcom-rendering/dist/2546.web.********************.js 3.72 kB 0 B
dotcom-rendering/dist/275.web.********************.js 697 B 0 B
dotcom-rendering/dist/3024.web.********************.js 621 B 0 B
dotcom-rendering/dist/3146.web.********************.js 6.53 kB 0 B
dotcom-rendering/dist/3358.web.********************.js 637 B 0 B
dotcom-rendering/dist/356.web.********************.js 826 B 0 B
dotcom-rendering/dist/3960.web.********************.js 619 B 0 B
dotcom-rendering/dist/3968.web.********************.js 3.79 kB 0 B
dotcom-rendering/dist/4113.web.********************.js 757 B 0 B
dotcom-rendering/dist/4265.web.********************.js 2.79 kB 0 B
dotcom-rendering/dist/4306.web.********************.js 6.46 kB 0 B
dotcom-rendering/dist/4591.web.********************.js 404 B 0 B
dotcom-rendering/dist/4593.web.********************.js 1.74 kB 0 B
dotcom-rendering/dist/4734.web.********************.js 759 B 0 B
dotcom-rendering/dist/480.web.********************.js 524 B 0 B
dotcom-rendering/dist/5021.web.********************.js 963 B 0 B
dotcom-rendering/dist/5071.web.********************.js 941 B 0 B
dotcom-rendering/dist/5211.web.********************.js 2.92 kB 0 B
dotcom-rendering/dist/5225.web.********************.js 6.67 kB 0 B
dotcom-rendering/dist/5474.web.********************.js 620 B 0 B
dotcom-rendering/dist/5688.web.********************.js 3.79 kB 0 B
dotcom-rendering/dist/5967.web.********************.js 2.37 kB 0 B
dotcom-rendering/dist/5974.web.********************.js 742 B 0 B
dotcom-rendering/dist/6118.web.********************.js 682 B 0 B
dotcom-rendering/dist/6126.web.********************.js 2.23 kB 0 B
dotcom-rendering/dist/640.web.********************.js 711 B 0 B
dotcom-rendering/dist/6437.web.********************.js 867 B 0 B
dotcom-rendering/dist/6534.web.********************.js 575 B 0 B
dotcom-rendering/dist/6541.web.********************.js 811 B 0 B
dotcom-rendering/dist/657.web.********************.js 2.46 kB 0 B
dotcom-rendering/dist/6623.web.********************.js 3.65 kB 0 B
dotcom-rendering/dist/7133.web.********************.js 699 B 0 B
dotcom-rendering/dist/7305.web.********************.js 886 B 0 B
dotcom-rendering/dist/7401.web.********************.js 689 B 0 B
dotcom-rendering/dist/7569.web.********************.js 4.94 kB 0 B
dotcom-rendering/dist/7650.web.********************.js 23 kB 0 B
dotcom-rendering/dist/7688.web.********************.js 814 B 0 B
dotcom-rendering/dist/786.web.********************.js 477 B 0 B
dotcom-rendering/dist/8085.web.********************.js 2.59 kB 0 B
dotcom-rendering/dist/8112.web.********************.js 3.37 kB 0 B
dotcom-rendering/dist/8165.web.********************.js 926 B 0 B
dotcom-rendering/dist/8170.web.********************.js 490 B 0 B
dotcom-rendering/dist/8172.web.********************.js 2.53 kB 0 B
dotcom-rendering/dist/818.web.********************.js 2.85 kB 0 B
dotcom-rendering/dist/8268.web.********************.js 5.44 kB 0 B
dotcom-rendering/dist/8439.web.********************.js 4.97 kB 0 B
dotcom-rendering/dist/8447.web.********************.js 963 B 0 B
dotcom-rendering/dist/8505.web.********************.js 556 B 0 B
dotcom-rendering/dist/8555.web.********************.js 690 B 0 B
dotcom-rendering/dist/8622.web.********************.js 858 B 0 B
dotcom-rendering/dist/8638.web.********************.js 831 B 0 B
dotcom-rendering/dist/9422.web.********************.js 614 B 0 B
dotcom-rendering/dist/9490.web.********************.js 825 B 0 B
dotcom-rendering/dist/9568.web.********************.js 5.37 kB 0 B
dotcom-rendering/dist/9597.web.********************.js 3.25 kB 0 B
dotcom-rendering/dist/9724.web.********************.js 5.02 kB 0 B
dotcom-rendering/dist/AdPortals-importable.web.********************.js 4.08 kB 0 B
dotcom-rendering/dist/AlreadyVisited-importable.web.********************.js 412 B 0 B
dotcom-rendering/dist/AppEmailSignUp-importable.web.********************.js 7.21 kB 0 B
dotcom-rendering/dist/AppsEpic-importable.web.********************.js 3.96 kB 0 B
dotcom-rendering/dist/AppsFooter-importable.web.********************.js 3.37 kB 0 B
dotcom-rendering/dist/AppsLightboxImage-importable.web.********************.js 2.82 kB 0 B
dotcom-rendering/dist/AudioAtomWrapper-importable.web.********************.js 3.27 kB 0 B
dotcom-rendering/dist/AustralianTerritorySwitcher-importable.web.********************.js 4.86 kB 0 B
dotcom-rendering/dist/Branding-importable.web.********************.js 2.2 kB 0 B
dotcom-rendering/dist/braze-web-sdk-core.web.********************.js 36.9 kB 0 B
dotcom-rendering/dist/BrazeMessaging-importable.web.********************.js 5.55 kB 0 B
dotcom-rendering/dist/CalloutBlockComponent-importable.web.********************.js 6.47 kB 0 B
dotcom-rendering/dist/CalloutEmbedBlockComponent-importable.web.********************.js 5.82 kB 0 B
dotcom-rendering/dist/CardCommentCount-importable.web.********************.js 2.69 kB 0 B
dotcom-rendering/dist/Carousel-importable.web.********************.js 7.75 kB 0 B
dotcom-rendering/dist/CarouselForNewsletters-importable.web.********************.js 5.6 kB 0 B
dotcom-rendering/dist/ChartAtom-importable.web.********************.js 500 B 0 B
dotcom-rendering/dist/CommentCount-importable.web.********************.js 2.85 kB 0 B
dotcom-rendering/dist/DiscussionContainer-importable.web.********************.js 23.9 kB 0 B
dotcom-rendering/dist/DiscussionMeta-importable.web.********************.js 3.75 kB 0 B
dotcom-rendering/dist/DocumentBlockComponent-importable.web.********************.js 3.3 kB 0 B
dotcom-rendering/dist/EmbedBlockComponent-importable.web.********************.js 3.84 kB 0 B
dotcom-rendering/dist/EnhancePinnedPost-importable.web.********************.js 1.95 kB 0 B
dotcom-rendering/dist/FetchOnwardsData-importable.web.********************.js 2.5 kB 0 B
dotcom-rendering/dist/FilterKeyEventsToggle-importable.web.********************.js 3.31 kB 0 B
dotcom-rendering/dist/FocusStyles-importable.web.********************.js 607 B 0 B
dotcom-rendering/dist/FollowWrapper-importable.web.********************.js 3.83 kB 0 B
dotcom-rendering/dist/FooterLabel-importable.web.********************.js 336 B 0 B
dotcom-rendering/dist/frameworks.web.********************.js 20.8 kB 0 B
dotcom-rendering/dist/GetCricketScoreboard-importable.web.********************.js 3.26 kB 0 B
dotcom-rendering/dist/GetMatchNav-importable.web.********************.js 12.6 kB 0 B
dotcom-rendering/dist/GetMatchStats-importable.web.********************.js 355 B 0 B
dotcom-rendering/dist/GetMatchTabs-importable.web.********************.js 2.31 kB 0 B
dotcom-rendering/dist/guardian-braze-components-banner.web.********************.js 13.4 kB 0 B
dotcom-rendering/dist/guardian-braze-components-end-of-article.web.********************.js 9 kB 0 B
dotcom-rendering/dist/GuideAtomWrapper-importable.web.********************.js 790 B 0 B
dotcom-rendering/dist/HeaderTopBar-importable.web.********************.js 11 kB 0 B
dotcom-rendering/dist/index.web.********************.js 37.8 kB -5 B (0%)
dotcom-rendering/dist/InstagramBlockComponent-importable.web.********************.js 3.38 kB 0 B
dotcom-rendering/dist/InteractiveBlockComponent-importable.web.********************.js 5.81 kB 0 B
dotcom-rendering/dist/InteractiveContentsBlockComponent-importable.web.********************.js 3.79 kB 0 B
dotcom-rendering/dist/InteractiveSupportButton-importable.web.********************.js 4.12 kB 0 B
dotcom-rendering/dist/KeyEventsCarousel-importable.web.********************.js 2.72 kB 0 B
dotcom-rendering/dist/KnowledgeQuizAtom-importable.web.********************.js 3.52 kB 0 B
dotcom-rendering/dist/LightboxHash-importable.web.********************.js 430 B 0 B
dotcom-rendering/dist/LightboxJavascript-importable.web.********************.js 4.43 kB 0 B
dotcom-rendering/dist/LiveBlogEpic-importable.web.********************.js 3.04 kB 0 B
dotcom-rendering/dist/Liveness-importable.web.********************.js 3.34 kB 0 B
dotcom-rendering/dist/ManyNewsletterSignUp-importable.web.********************.js 4.98 kB 0 B
dotcom-rendering/dist/MapEmbedBlockComponent-importable.web.********************.js 5.36 kB 0 B
dotcom-rendering/dist/Metrics-importable.web.********************.js 2.39 kB -5 B (0%)
dotcom-rendering/dist/MostViewedFooter-importable.web.********************.js 5.38 kB 0 B
dotcom-rendering/dist/MostViewedFooterData-importable.web.********************.js 7.7 kB 0 B
dotcom-rendering/dist/MostViewedRightWrapper-importable.web.********************.js 3.9 kB 0 B
dotcom-rendering/dist/OnwardsUpper-importable.web.********************.js 4.17 kB 0 B
dotcom-rendering/dist/PersonalityQuizAtom-importable.web.********************.js 3.66 kB 0 B
dotcom-rendering/dist/ProfileAtom-importable.web.********************.js 547 B 0 B
dotcom-rendering/dist/ProfileAtomWrapper-importable.web.********************.js 810 B 0 B
dotcom-rendering/dist/PulsingDot-importable.web.********************.js 744 B 0 B
dotcom-rendering/dist/QandaAtom-importable.web.********************.js 542 B 0 B
dotcom-rendering/dist/ReaderRevenueDev-importable.web.********************.js 485 B 0 B
dotcom-rendering/dist/readerRevenueDevUtils.web.********************.js 2.98 kB 0 B
dotcom-rendering/dist/ReaderRevenueLinks-importable.web.********************.js 4.98 kB 0 B
dotcom-rendering/dist/RecipeMultiplier-importable.web.********************.js 3.16 kB 0 B
dotcom-rendering/dist/RelativeTime-importable.web.********************.js 1.92 kB 0 B
dotcom-rendering/dist/RichLinkComponent-importable.web.********************.js 6.34 kB 0 B
dotcom-rendering/dist/SecureSignupIframe-importable.web.********************.js 4.93 kB 0 B
dotcom-rendering/dist/SendAMessage-importable.web.********************.js 4.38 kB 0 B
dotcom-rendering/dist/SendTargetingParams-importable.web.********************.js 2.04 kB 0 B
dotcom-rendering/dist/sentry.web.********************.js 773 B 0 B
dotcom-rendering/dist/SetABTests-importable.web.********************.js 3.46 kB -10 B (0%)
dotcom-rendering/dist/SetAdTargeting-importable.web.********************.js 481 B 0 B
dotcom-rendering/dist/shimport.web.********************.js 2.78 kB 0 B
dotcom-rendering/dist/ShowHideContainers-importable.web.********************.js 642 B 0 B
dotcom-rendering/dist/ShowMore-importable.web.********************.js 5.59 kB 0 B
dotcom-rendering/dist/SignInGateMain.web.********************.js 3.86 kB 0 B
dotcom-rendering/dist/SignInGateMainCheckoutComplete.web.********************.js 4.93 kB 0 B
dotcom-rendering/dist/SignInGateSelector-importable.web.********************.js 3.57 kB 0 B
dotcom-rendering/dist/SlotBodyEnd-importable.web.********************.js 8.78 kB 0 B
dotcom-rendering/dist/Snow-importable.web.********************.js 3.02 kB 0 B
dotcom-rendering/dist/SpotifyBlockComponent-importable.web.********************.js 5.21 kB 0 B
dotcom-rendering/dist/StickyBottomBanner-importable.web.********************.js 5.92 kB 0 B
dotcom-rendering/dist/SubNav-importable.web.********************.js 2.36 kB 0 B
dotcom-rendering/dist/SupportTheG-importable.web.********************.js 5.09 kB 0 B
dotcom-rendering/dist/TableOfContents-importable.web.********************.js 2.96 kB 0 B
dotcom-rendering/dist/TimelineAtom-importable.web.********************.js 1.22 kB 0 B
dotcom-rendering/dist/TweetBlockComponent-importable.web.********************.js 1.01 kB 0 B
dotcom-rendering/dist/UnsafeEmbedBlockComponent-importable.web.********************.js 3.38 kB 0 B
dotcom-rendering/dist/VideoFacebookBlockComponent-importable.web.********************.js 5.37 kB 0 B
dotcom-rendering/dist/VineBlockComponent-importable.web.********************.js 3.23 kB 0 B
dotcom-rendering/dist/WeatherWrapper-importable.web.********************.js 5.42 kB 0 B
dotcom-rendering/dist/YoutubeBlockComponent-importable.web.********************.js 3.88 kB 0 B

compressed-size-action

Base automatically changed from darkmode/split-theme-decorator-fix to main November 8, 2023 16:26
@mxdvl mxdvl force-pushed the darkmode/container-overrides branch 2 times, most recently from 2b30917 to edf21e1 Compare November 8, 2023 17:54
@mxdvl mxdvl added the run_chromatic Runs chromatic when label is applied label Nov 8, 2023
abeddow91
abeddow91 previously approved these changes Nov 9, 2023
Copy link
Contributor

@abeddow91 abeddow91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One non-blocking question for my own understanding but otherwise looks great!

dotcom-rendering/src/components/ContainerOverrides.tsx Outdated Show resolved Hide resolved
@mxdvl mxdvl force-pushed the darkmode/container-overrides branch 6 times, most recently from c6aaa41 to d8595db Compare November 9, 2023 18:32
@mxdvl mxdvl dismissed abeddow91’s stale review November 9, 2023 18:52

There have been significant changes since the review

this enables overriding specific palette values in a container,
if there is a special container palette applied to it.

It demonstrates usage with `--headline-colour` usage in CardHeadline,
which is overridden instead of having the three following values:
- text.headline
- text.cardHeadline
- text.dynamoHeadline
@mxdvl mxdvl force-pushed the darkmode/container-overrides branch from d8595db to 7f8c960 Compare November 9, 2023 18:52
@mxdvl mxdvl added this to the DCR for Apps milestone Nov 13, 2023
@JamieB-gu JamieB-gu linked an issue Nov 14, 2023 that may be closed by this pull request

const paletteOverrides = {
'--headline-colour': isDynamo
? text?.dynamoHeadline ?? decidePalette(format).text.dynamoHeadline
Copy link
Contributor

@abeddow91 abeddow91 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan still to remove decidePalette at some point?

Comment on lines 34 to 38
const paletteOverrides = {
'--headline-colour': isDynamo
? text?.dynamoHeadline ?? decidePalette(format).text.dynamoHeadline
: text?.cardHeadline ?? decidePalette(format).text.cardHeadline,
} satisfies Partial<Record<ColourName, string>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this quite tricky to read. I wonder if there's another way we could do this? Maybe bring the logic out into its own function, or create a "fallback" type helper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for flagging! Which part specifically is tricky to read?

A helper function can removed the need for the satisfies Partial<Record<ColourName, string>> but it cannot do away with the inherent complexity of how to pick the headline colour and its fallbacks.

Comment on lines +43 to +44
css={[displayContents]}
style={paletteOverrides}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use both css and style? Is it because of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also because inline styles have the highest specificity. You can clearly see what the colour override is without even having to look at the resulting CSS declaration generated by Emotion.

Comment on lines +555 to +560
declare namespace React {
interface CSSProperties {
// Allow custom properties to be passed to the style prop
[key: `--${string}`]: string | undefined;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why it's here 🤔 but I thought we wanted to avoid using the global types file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this would work in any other file. It think it’s okay to have things that are truly global in there, such as the React namespace. Do you have an idea of where it could go otherwise?

--headline-colour is overriden at the CardHeadline level
@mxdvl mxdvl merged commit 0832237 into main Nov 14, 2023
32 checks passed
@mxdvl mxdvl deleted the darkmode/container-overrides branch November 14, 2023 15:47
@cemms1 cemms1 mentioned this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotcom-rendering run_chromatic Runs chromatic when label is applied
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Handle Container Palettes when using CSS Custom Properties
3 participants