Skip to content

Conversation

@alizaberger
Copy link
Collaborator

Jira issue

Describe your changes

Adds a "Show/Hide" link to toggle the visibility of code snippets (not the results pane) in the StackSnippetView. This corresponds to how snippets preview worked in the old editor. The link is only rendered when the hide attribute is "true".

PR Checklist

  • All new/changed functionality includes unit and (optionally) e2e tests as appropriate
  • All new/changed functions have /** ... */ docs
  • I've added the bug/enhancement and other labels as appropriate

Environment(s) tested

  • Device: desktop
  • OS: [e.g. iOS]
  • Browser: chrome
  • Version [e.g. 22]

Additional context

TODO: Need to add the same functionality to the preview pane in the MD+P mode.

@changeset-bot
Copy link

changeset-bot bot commented Apr 25, 2025

🦋 Changeset detected

Latest commit: c2da4c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stackoverflow/stacks-editor Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@alizaberger alizaberger added enhancement New feature or request mode - markdown Affects the editor's markdown input mode labels Apr 25, 2025
@netlify
Copy link

netlify bot commented Apr 25, 2025

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit c2da4c4
🔍 Latest deploy log https://app.netlify.com/sites/stacks-editor/deploys/6810e0c8dc0921000808e5b8
😎 Deploy Preview https://deploy-preview-430--stacks-editor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


let toggleContainer: HTMLDivElement;

if (this.snippetMetadata.hide === "true") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This matches current functionality. Out of scope for this PR, but I wonder if we could improve on what's here by always showing the show/hide accordian rather than keying it off of the snippet config (and instead setting the default based on that config value)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also thought this behavior was interesting but I spoke to @KyleMit and it seems like users want to be able to control how the final post will look and if the snippet will have a show/hide link above it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think what @threefjefff is still inline with my use cases (although agreed this matches existing behavior). It wouldn't bug me if the link to be able to show/hide was always visible, but the default respected the value set by the config in the post.

That way OP has first say in whether it should be collapsed or visible, but users could also quickly collapse existing snippets in answers

Copy link
Collaborator

@threefjefff threefjefff left a comment

Choose a reason for hiding this comment

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

Pretty sure this is just a netlify thing, but it looks like the icon isn't being rendered properly in the preview there.

image

Functionality works great. Happy with the testing

@alizaberger
Copy link
Collaborator Author

@threefjefff Can you please take a look at the failing test and see if it has something to do with what I changed? I can't seem to figure it out

@alizaberger
Copy link
Collaborator Author

Pretty sure this is just a netlify thing, but it looks like the icon isn't being rendered properly in the preview there.

image

Functionality works great. Happy with the testing

No, this is happening on my local machine too, but the new snippets icon is acting the same for me locally. @dancormier any idea why the stacks icon is not rendering correctly?

@dancormier
Copy link
Contributor

@alizaberger I'm looking into the icon issue. In the meantime, can you provide instructions on how to test this functionality?

@dancormier
Copy link
Contributor

@alizaberger the editor relies on CSS definitions for icons (as opposed to importing SVGs), and only a small subset of icons are included in the icons CSS (see also https://github.com/StackExchange/Stacks-Icons/blob/production/README.md#using-the-css-icons).

To use this icon, I suggest importing the icon needed in src/styles/icons.css like this:

…
.svg-icon-bg.iconArrowDownSm {
    --bg-icon: url("~@stackoverflow/stacks-icons/src/Icon/ArrowDownSm.svg");
}
…

@alizaberger
Copy link
Collaborator Author

@alizaberger I'm looking into the icon issue. In the meantime, can you provide instructions on how to test this functionality?

@dancormier In the snippets preview paste a valid snippet in markdown mode, with the hide param set to true.

<!-- begin snippet: js hide: true console: true babel: null babelPresetReact: false babelPresetTS: false -->

<!-- language: lang-js -->

    console.log("test");

<!-- language: lang-css -->

    .test {
      position: fixed;
    }

<!-- language: lang-html -->

    <div>test</div>

<!-- end snippet -->

This should enable the show/hide link for the snippet in rich text mode

image

Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @alizaberger. I noticed a minor styling issue and have suggested some changes. Other than that minor issue, this is good to go from my perspective

alizaberger and others added 2 commits April 29, 2025 10:22
Co-authored-by: Dan Cormier <dancormierall@gmail.com>
Co-authored-by: Dan Cormier <dancormierall@gmail.com>
@alizaberger alizaberger requested a review from dancormier April 29, 2025 14:32
@alizaberger alizaberger merged commit 9c9f946 into main Apr 29, 2025
5 checks passed
@alizaberger alizaberger deleted the aberger/snippets-show-hide-link branch April 29, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request mode - markdown Affects the editor's markdown input mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants