-
Notifications
You must be signed in to change notification settings - Fork 266
Copilot guided conversion to SCSS Modules #13013
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
base: latest
Are you sure you want to change the base?
Conversation
| "puppeteer": "24.10.2", | ||
| "retry": "0.13.1", | ||
| "sass": "1.89.2", | ||
| "sass-loader": "16.0.5", |
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.
copilot recommended packages to support SCSS
| @@ -0,0 +1,223 @@ | |||
| // fontFaces.module.scss | |||
| // SCSS mixins for @font-face rules, matching the fontFaces.ts constants | |||
| // Usage: @include reith-serif-regular-face; etc. | |||
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.
seems a pretty direct conversion from the ts constants: https://github.com/bbc/simorgh/blob/latest/src/app/components/ThemeProvider/fontFaces.ts
src/app/components/ThemeProviderSCSSModules/fontFacesLazy.module.scss
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,22 @@ | |||
| // fontFamilies.module.scss | |||
| // SCSS variables for font-family stacks, matching fontFamilies.ts | |||
| // Usage: font-family: $reith-sans; | |||
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.
| @@ -0,0 +1,14 @@ | |||
| // fontMediaQueries.module.scss | |||
| // SCSS variables for font media query breakpoints, matching fontMediaQueries.ts | |||
| // These are static values representing only the media query condition (no @media, no quotes). | |||
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.
After some back and forth with Copilot it told me that you can't have constants that contain full media queries like the original file
You can get very close though with the condition being encapsulating in a variable
| $values: map-get(map-get($font-sizes, $scale), $group); | ||
| font-size: map-get($values, font-size); | ||
| line-height: map-get($values, line-height); | ||
| } |
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.
This was a really difficult conversion, the theme dictates the font size and line height so it seemed sensible for these be declared as global variables to set at runtime by JS based on the service theme. In theory the algorithm otherwise works the same as the ts version: https://github.com/bbc/simorgh/blob/latest/src/app/components/ThemeProvider/fontSizes.ts
| $storm: #404040; | ||
| $success-core: #148A00; | ||
| $weather-blue: #067EB3; | ||
| $white: #FFFFFF; |
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.
| $margin-below-400px: $full; | ||
| $gutter-below-600px: $full; | ||
| $margin-above-400px: $double; | ||
| $gutter-above-600px: $double; |
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.
Quite a good comparison to the just CSS Modules equivalent, pretty much all the imperative logic is retained from the original: https://github.com/bbc/simorgh/blob/latest/src/app/components/ThemeProvider/spacings.ts
| use: ['style-loader', 'css-loader', 'sass-loader'], | ||
| }, | ||
| ], | ||
| }, |
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.
Copilot contributed webpack config for SCSS
| use: ['style-loader', 'css-loader', 'sass-loader'], | ||
| }, | ||
| ], | ||
| }, |
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.
Copilot contributed webpack config for SCSS
| 'brand-logo': 'var(--white)', | ||
| 'brand-foreground': 'var(--ghost)', | ||
| 'brand-highlight': 'var(--white)', | ||
| 'brand-border': 'var(--postbox-30)', |
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.
First example pulling in custom properties dynamically based on theme, this should reflect current behaviour
c3a0d1d to
8821093
Compare
8821093 to
0a8dcd6
Compare
package.json
Outdated
| "jest-serializer-html": "7.1.0", | ||
| "jest-silent-reporter": "0.6.0", | ||
| "jsdom": "26.1.0", | ||
| "mini-css-extract-plugin": "2.9.2", |
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.
Copilot claims this enables extraction of css into seperate chunks based on usage
| $ratio: if($cropped-height != 0, $cropped-width / $cropped-height, 1); | ||
|
|
||
| :root { | ||
| --brand-logo-ratio: #{$ratio}; |
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.
It's a bit of a stretch but in principle this algorithm will set this custom css property to refer to when putting the css together for the brand here:
| const svgRatio = brandSVG && brandSVG.ratio; |
| @@ -0,0 +1,30 @@ | |||
| @mixin build-logo( | |||
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.
This meant to be roughly functional equivalent to: https://github.com/bbc/simorgh/blob/latest/src/app/components/ThemeProvider/chameleonLogos/index.tsx#L5
it compute values to use elsewhere for the brand and provides a suitable css class to use for styles
| stroke: #000; | ||
| stroke-width: 0.335; | ||
| /* Optionally, set stroke via custom property or theme */ | ||
| } No newline at end of file |
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 think this needs moving to the :root declaration above to make it global for use elsewhere
|
|
||
| .mundoLogoTheme { | ||
| @include logo.build-logo(1738, 425); | ||
| } |
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.
Applies mundo specific config to logo and actually executes the function, adding the suitably populated custom properties to the page
| import '../../../fontVariants/reith.module.scss'; | ||
| import './palette.module.scss'; | ||
| import '../../../fontScripts/latinWithDiacritics.module.scss'; | ||
| import '../../../chameleonLogos/mundoLogo.module.scss'; |
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.
Quite important implementation detail here, these scss modules are imported and applied to the page, but because this is dynamically imported via loadable the theory is this css is correctly chunked with mundo only i.e. only css for the chosen theme is loaded
| :root { | ||
| --brand-background: var(--postbox); | ||
| --brand-logo: var(--white); | ||
| --brand-foreground: var(--ghost); | ||
| --brand-highlight: var(--white); | ||
| --brand-border: var(--postbox-30); | ||
| } |
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.
| :root { | |
| --brand-background: var(--postbox); | |
| --brand-logo: var(--white); | |
| --brand-foreground: var(--ghost); | |
| --brand-highlight: var(--white); | |
| --brand-border: var(--postbox-30); | |
| } |
This file was moved, should be deleted
| :root { | ||
| --brand-background: var(--postbox); | ||
| --brand-logo: var(--white); | ||
| --brand-foreground: var(--ghost); | ||
| --brand-highlight: var(--white); | ||
| --brand-border: var(--postbox-30); | ||
| } |
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.
Equivalent of:
| palette: { |
| }; | ||
|
|
||
|
|
||
| export default ThemeProvider; No newline at end of file |
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.
Equivalent of
| const withThemeProvider = ( |
This is simplified for now and obviously creates its own Provider rather than use emotion
| }; | ||
| }; | ||
|
|
||
| export default buildLogo; |
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.
Existing logic for brand svg unchanged by move to SCSS modules
| import '../../../fontFaces/reith-serif-light.module.scss'; | ||
| import '../../../fontVariants/reith.module.scss'; | ||
| import './palette.module.scss'; | ||
| import '../../../fontScripts/latinWithDiacritics.module.scss'; |
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.
Quite important implementation detail here, these scss modules are imported and applied to the page, but because this is dynamically imported via loadable the theory is this css is correctly chunked with mundo only i.e. only css for the chosen theme is loaded
| import '../../fontFaces/reith-serif-light.module.scss'; | ||
| import '../../fontVariants/reith.module.scss'; | ||
| import './palette.module.scss'; | ||
| import '../../fontScripts/latinWithDiacritics.module.scss'; |
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.
Quite important implementation detail here, these scss modules are imported and applied to the page, but because this is dynamically imported via loadable the theory is this css is correctly chunked with mundo only i.e. only css for the chosen theme is loaded
403d74b to
a5a4f48
Compare
73f6f80 to
db50f52
Compare
| : Fragment; | ||
| return ( | ||
| <h2 css={styles.h2} id={id}> | ||
| <h2 className="h2" id={id}> |
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.
needs integrating properly
f14cc43 to
74fe3ff
Compare
b0b0fdc to
152a72f
Compare
Resolves JIRA:
Summary
A very high-level summary of easily-reproducible changes that can be understood by non-devs, and why these changes where made.
Code changes
Developer Checklist
Testing
Ready-For-Test, Local)Ready-For-Test, Test)Ready-For-Test, Preview)Ready-For-Test, Live)Additional Testing Steps
Useful Links