Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Collapse grayed lines in code block - #206

Merged
colleenmcginnis merged 9 commits into
masterfrom
collapse-code-block
Dec 24, 2019
Merged

colleenmcginnis merged 9 commits into
masterfrom
collapse-code-block

Conversation

@colleenmcginnis

@colleenmcginnis colleenmcginnis commented Dec 16, 2019 •

Copy link
Copy Markdown
Contributor

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

Screen Shot 2019-12-16 at 2 33 45 PM

After clicking "Show all lines"

Screen Shot 2019-12-16 at 2 34 12 PM

@mapbox/docs thoughts?

@colleenmcginnis
colleenmcginnis requested a review from a team December 16, 2019 22:40

@katydecorah katydecorah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really love this feature! I left a few (minor) suggestions!

copyElement.style.opacity = '1';
}
}, 300);
}, 10);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I have an idea. 💡

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@colleenmcginnis your solution is super smooth! Looks good to me!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🏄‍♀

@katydecorah

katydecorah commented Dec 18, 2019 •

Copy link
Copy Markdown
Contributor

Noticing one small issue on smaller screens where the code overflows:

image

One quick idea is to add word-break: break-all; to pre

@colleenmcginnis
colleenmcginnis marked this pull request as ready for review December 20, 2019 20:10

@katydecorah katydecorah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯

@colleenmcginnis

Copy link
Copy Markdown
Contributor Author

@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 colleenmcginnis changed the title [WIP] Collapse grayed lines in code block Collapse grayed lines in code block Dec 23, 2019
@katydecorah

Copy link
Copy Markdown
Contributor

@colleenmcginnis should the code snippet scroll to the highlighted code? I'm not seeing it do that for this example: image

@colleenmcginnis

Copy link
Copy Markdown
Contributor Author

You know. It's weird. When I comment out these lines for the basic test

testCases.basic = {
component: NumberedCodeSnippet,
description: 'Basic',
props: {
code: code,
highlightedCode: highlightSwift(code),
maxHeight: 450,
highlightThemeCss: highlightTheme,
copyRanges: [[6, 17]],
onCopy: () => {}
}
};
so the second test case is the only one on the page, it works as expected. I'm not sure if it's an issue specific to how we're setting up test cases or if there's something else going on that we should be concerned about.

@katydecorah

Copy link
Copy Markdown
Contributor

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.

Comment on lines 89 to 96
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);

@katydecorah katydecorah Dec 23, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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()

@colleenmcginnis
colleenmcginnis merged commit cd4aaa1 into master Dec 24, 2019
@colleenmcginnis
colleenmcginnis deleted the collapse-code-block branch December 24, 2019 00:31
katydecorah pushed a commit that referenced this pull request Jan 2, 2020
* master:
  Collapse grayed lines in code block (#206)
katydecorah pushed a commit that referenced this pull request Jan 2, 2020
* 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)
katydecorah pushed a commit that referenced this pull request Jan 3, 2020
* 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
katydecorah pushed a commit that referenced this pull request Jan 7, 2020
* 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)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants