Repository navigation
Collapse grayed lines in code block - #206
Conversation
katydecorah
left a comment
There was a problem hiding this comment.
I really love this feature! I left a few (minor) suggestions!
| copyElement.style.opacity = '1'; | ||
| } | ||
| }, 300); | ||
| }, 10); |
There was a problem hiding this comment.
@katydecorah when this was set to 300, there was a very noticeable delay of the blue bar on the left side moving to the relevant lines when expanding/collapsing the grayed out lines. Do you think we need to use debounce when expanding/collapsing lines (especially since we won't need to auto scroll to the first active chunk anymore)?
There was a problem hiding this comment.
Oh I have an idea. 💡
There was a problem hiding this comment.
@katydecorah @danswick I think debounce was introduced in the mr-ui code snippet component specifically for recalculating the position of elements when the window is resized. I'm not sure we need to use it when toggling between languages or expanding/collapsing lines since it each of those triggers happen only once. What do you think of an approach like this: 30db2d6?
There was a problem hiding this comment.
@colleenmcginnis your solution is super smooth! Looks good to me!
|
@katydecorah I think there may be some situations in which we don't want to collapse the grayed out lines (thinking about the installation flow) so in 1017285 I added a prop that would give you the option to specify that lines should not be collapsed. Let me know what you think! |
|
@colleenmcginnis should the code snippet scroll to the highlighted code? I'm not seeing it do that for this example: |
|
You know. It's weird. When I comment out these lines for the |
|
I'll take a closer look to see what's up! We want to make sure the test cases work as expected because it's hard to track use cases like this. |
| const theme = this.props.highlightThemeCss; | ||
|
|
||
| // Do not load themes that have already been injected. | ||
| /* Do not load themes that have already been injected. */ | ||
| if (injectedThemes.indexOf(theme) !== -1) return; | ||
| injectedThemes.push(theme); | ||
| const doc = getWindow().document; | ||
| this.styleTag = doc.createElement('style'); | ||
| this.styleTag.innerHTML = `${theme}`; | ||
| doc.head.appendChild(this.styleTag); |
There was a problem hiding this comment.
@colleenmcginnis I think these lines are the culprit and are making componentDidMount return too soon for the second snippet instance to scroll. I recommend moving these lines to is own method:
setTheme = () => {
const theme = this.props.highlightThemeCss;
/* Do not load themes that have already been injected. */
if (injectedThemes.indexOf(theme) !== -1) return;
injectedThemes.push(theme);
const doc = getWindow().document;
this.styleTag = doc.createElement('style');
this.styleTag.innerHTML = `${theme}`;
doc.head.appendChild(this.styleTag);
}
And then referencing that method here: this.setTheme() this will make this method return on if (injectedThemes.indexOf(theme) !== -1) return; but not the entire componentDidMount()
* master: Collapse grayed lines in code block (#206)
* master: Collapse grayed lines in code block (#206) Add a tag component with themes (#216) Add new related page component (#213) Rework Notes themes (#202) Add "tag" option to second and third level headings (#212) Update style of BetaFlag (#207) Add IE11 compatibility for the `Search` component (#203)
* master: Update CHANGELOG.md Update CHANGELOG.md Collapse grayed lines in code block (#206) Add a tag component with themes (#216) Add new related page component (#213) Rework Notes themes (#202) Add "tag" option to second and third level headings (#212) Update style of BetaFlag (#207) allow `feedbackSentryDsn` to accept string (url) or boolean (false) Add IE11 compatibility for the `Search` component (#203) conditionally set `section` and `preferredLanguage`; send along `environment` Prepare 0.24.0 Add groovy highlight option (#201) Push text feedback to Sentry (#198) Prepare 0.23.0 Allow for a configurable connector on search component (#200) Update budo
* master: (32 commits) add missing indices (#219) Create `Edit` and `CodeSnippet` components (#197) Update CHANGELOG.md Update CHANGELOG.md create highlight/theme-css Create themes component to house shared themes for Tag and Note (#217) Update CHANGELOG.md Update CHANGELOG.md Collapse grayed lines in code block (#206) Add a tag component with themes (#216) Add new related page component (#213) Rework Notes themes (#202) Add "tag" option to second and third level headings (#212) Update style of BetaFlag (#207) allow `feedbackSentryDsn` to accept string (url) or boolean (false) Add IE11 compatibility for the `Search` component (#203) conditionally set `section` and `preferredLanguage`; send along `environment` Prepare 0.24.0 Add groovy highlight option (#201) Push text feedback to Sentry (#198) ...


This proposes the ability to collapse or expand the grayed lines not included in
copyRanges. This functionality would be useful in tutorials where we want to show the full code for context, but want to highlight a few lines that are relevant to the step being described in the text.Default state
After clicking "Show all lines"
@mapbox/docs thoughts?