-
Notifications
You must be signed in to change notification settings - Fork 508
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
feat(macros/EmbedInteractiveExample): use height from height-data.json #7679
Conversation
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.
Thank you, just some nits (moving complexity out of the macro, add types).
const heightData = await mdn.fetchInteractiveExampleHeightData(); | ||
|
||
if ($0.includes('/js/')) { | ||
heightClass = 'is-js-height'; | ||
} | ||
|
||
if ($1) { | ||
let supportedHeights = ['shorter', 'taller', 'tabbed-shorter', 'tabbed-standard', 'tabbed-taller']; | ||
let heightIsSupported = (supportedHeights.indexOf($1) > -1); | ||
|
||
if (heightIsSupported) { | ||
heightClass = 'is-' + $1 + '-height'; | ||
} else { | ||
throw new Error(`An unrecognized second size parameter to EmbedInteractiveExample ('${$1}')`); | ||
} | ||
let height; | ||
if (heightData[$0]) { | ||
height = heightData[$0]; | ||
} else if ($0.includes('/js/')) { | ||
height = 'js'; | ||
} else { | ||
height = 'default'; | ||
} | ||
const heightClass = 'is-' + height + '-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.
Let's extract this whole section as mdn.getInteractiveExampleHeightClass(path)
, so that this macro knows nothing about where the height comes from.
Also, let's keep the $1 parameter for now and pass it to this method, to use as a fallback as long as the height-data.json
is not available.
Once the height-data.json
is available, we can deprecate the 2nd parameter.
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 have moved the whole section to getInteractiveExampleHeight
. Thanks
Since there was no reply for a long time, I have moved the exact height information to height-data.json. Old classes are no longer compatible, so I didn't apply the second suggestion.
kumascript/src/api/mdn.ts
Outdated
|
||
// Module level caching for repeat calls to fetchWebExtExamples(). | ||
let webExtExamples: any = null; | ||
|
||
let interactiveExampleHeightData: object = null; |
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.
let interactiveExampleHeightData: object = null; | |
type InteractiveExamplesHeight = 'shorter' | 'taller' | 'tabbed-shorter' | 'tabbed-standard' | 'tabbed-taller'; | |
type InteractiveExamplesHeightData = Record<string, InteractiveExamplesHeight>; | |
let interactiveExampleHeightData: InteractiveExamplesHeightData = null; |
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 added the correct type instead of the object. I have moved it to interactive-example.tsx though, so the whole logic is located in a single place. In the future I will port BOB to TS, so we can remove the types from here.
kumascript/src/api/mdn.ts
Outdated
async fetchInteractiveExampleHeightData() { | ||
if (!interactiveExampleHeightData) { | ||
try { | ||
interactiveExampleHeightData = await got( |
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.
interactiveExampleHeightData = await got( | |
interactiveExampleHeightData = await got<InteractiveExamplesHeightData>( |
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.
Added, thank you
@caugner All of that sounds good, I will add a commit with those changes later. I realized now that there is a better way to tackle this problem. Currently, heights are hardcoded in interactive-examples.scss in YARI and distributed across multiple CSS files in BOB. I could make "pages/tabbed/audio.html": {
"landscape-height": "421px",
"portrait-height": "548px"
} The file would get a bit bigger, but it would allow more complex height adjustments. For JavaScript examples, we could make height calculated by the formula |
This pull request has merge conflicts that must be resolved before it can be merged. |
Hey @NiedziolkaMichal, a friendly ping. This one has a conflict that needs to be resolved. Thanks! |
f711daf
to
363f73f
Compare
@schalkneethling It's done :) Tests seem to be failing because |
This pull request has merge conflicts that must be resolved before it can be merged. |
This pull request has merge conflicts that must be resolved before it can be merged. |
c2d7082
to
d00560a
Compare
I have rechecked everything and the code is working fine, but |
Hi @NiedziolkaMichal, I wonder if we couldn't just fix yari to listen to this height event: |
I was thinking about it, but there is a significant drawback to this. Individual examples usually load 2-3 seconds after the rest of the content on my PC, where I have high-speed internet. If we send height information through an event, we will have a significant reflow after those few seconds, which would annoy the users. |
This pull request has merge conflicts that must be resolved before it can be merged. |
This pull request has merge conflicts that must be resolved before it can be merged. |
Sorry for not addressing this in time. I see the issue, but we don't want to set height in JS here. We'll address this later this year. |
This is the second part of PR mdn/bob#839 in BOB, which makes
height-data.json
be created while building interactive examples. That file contains the height of every interactive example, so that height no longer needs to be provided fromcontent
repository and we can also remove the height of each interactive editor type from here.The height of the editor is now calculated by JS code in interactive-examples.tsx. During build, iframe of example is created, together with
data-heights
attribute, which contains information about the height of the editor. This is an exemplary value:The component will use the last
height
, for which the value ofminFrameWidth
was greater or equal to the calculated width of the iframe. This works just like media queries, but we don't use the width of the window in here, which gives incorrect results because of interference from the rest of the UI.I changed the key of the Prose component to the following because the paragraph under iframe was causing duplicated react key exception(both having null value).
If this gets merged, I will make the next PR to remove the second argument(height class) from every usage of
EmbedInteractiveExample
in the content repository.This PR depends on mdn/bob#839 and shouldn't be merged until BOB update is deployed.
Tests are failing because iframe cannot be shown, until #839 is merged