Skip to content

feat: created generic Codepen Snippet component #548

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

Merged
merged 16 commits into from
Oct 27, 2020

Conversation

ErickPetru
Copy link
Contributor

Description of Problem

Right now, more than 20 files along the documentation have Codepen embeds with small changes on each one, like this:

<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="result" data-user="Vue" data-slug-hash="KKpRVvJ" data-preview="true" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Attribute dynamic binding">
  <span>See the Pen <a href="https://codepen.io/team/Vue/pen/KKpRVvJ">
  Attribute dynamic binding</a> by Vue (<a href="https://codepen.io/Vue">@Vue</a>)
  on <a href="https://codepen.io">CodePen</a>.</span>
</p>
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>

This large block of copied-and-pasted content takes up a lot of space in each place and is hard to maintain.

Also, as a documentation translation maintainer, I feel how it's annoying to keep all embeds translated in the same way when we have different collaborators translating different files.

And last but not least, using Single File Components inside Markdown with VuePress is so cool! Why not take advantage of this tool one more time to improve this scenario?

Proposed Solution

A generic Codepen Snippet component, with props covering all different situations where Codepen embeds are use a little different across the documentation, but with good defaults that cover the majority of the use cases, to keep the usage simple.

Additional Information

I took the liberty of changing all the Codepen embeds currently used in the documentation to use the new component, in order to test its effectiveness (and also to facilitate the work of the core team). I am available to make any additional adjustments to it if necessary.

Copy link
Member

@NataliaTepluhina NataliaTepluhina left a comment

Choose a reason for hiding this comment

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

@ErickPetru I like the idea! I've left one nitpick to codepen component but overall it looks good to me 👍🏻

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

A few suggestions from me.

Copy link
Member

@bencodezen bencodezen 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 work on this @ErickPetru! Your refactoring has shown us that there's some clean up that needs to do in terms of standardizing some things so it's easier to turn into a component. I think we should probably hold on this until those changes are made so you can update the PR.

@ErickPetru
Copy link
Contributor Author

Hi @bencodezen, my intention with this PR was not to change current behavior.

I really forgot some possible adaptations at the first pass, but after @skirtles-code review, I've already sent more commits with everything (I hope) in the same way it was before.

I believe it's secure to merge after the next review phase. Indeed, even future standardization on the embeds will be a lot easier with the new component. Also, feel free to ask for more changes if you want.

@skirtles-code
Copy link
Contributor

@ErickPetru Currently there are conflicts with master.

Given what @bencodezen said, I'm unclear whether more conflicts are coming or if this is now good to proceed.

I'm happy to do another review but I'd rather wait for confirmation that there aren't more conflicts coming first.

@ErickPetru
Copy link
Contributor Author

@skirtles-code and @bencodezen I saw the recent changes on examples/modal.md and examples/grid-component.md adding the updated Codepen URLs. So I just sent these two updated using the CodepenSnippet component.

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

Some more suggestions from me.

I've not made any subjective decisions about whether things matter, I've just reported anything that seems to have changed from what was there previously.

I agree that this component should make it easier to remove the current inconsistencies.

@ErickPetru
Copy link
Contributor Author

Sorry for the delay, hard job weeks here currently.
I've just updated with the corrections after the second @skirtles-code review.

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

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

There's a new CodePen example at the bottom of transitions-enterleave.md.

Usually I'd suggest migrating it post-merge but in this case it seems that the component can't co-exist with non-component CodePens. That new example gets a thick, black border around it as a result.

I did a bit of debugging and it seems to be a consequence of how SSR and the CodePen script interact with each other. So long as everything is using the component it should be fine.

As SSR is involved you can only see the problem by going directly to the right page:

https://deploy-preview-548--vue-docs-next-preview.netlify.app/guide/transitions-enterleave.html#transitioning-between-components

If you navigate there via another page it all behaves.

@ErickPetru
Copy link
Contributor Author

Incredible was your catch about SSR with Codepen embeds without the new component, @skirtles-code!

So as you suggested, I just updated guide/transitions-enterleave.md changing the last embed to also use the component.

Then I just realized that the project could have direct <iframe> embeds to, and I was right. So I changed to use the component also in the files guide/optimizations.md and guide/reactivity.md. While the way it works becomes a little different (from an direct <iframe> to a <p> converted to an <iframe> by https://static.codepen.io/assets/embed/ei.js), in my tests it offers the same experience to the end user and finally standardize all the guide to use the CodepenSnippet component.

Please take a look and talk to me if something more is needed.

Copy link
Member

@bencodezen bencodezen 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 your hard work on this @ErickPetru!

props: {
title: {
type: String,
default: null,
Copy link
Member

Choose a reason for hiding this comment

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

When defining props, it's best to choose either default or required. Otherwise, they basically cancel each other out.

In this case, it should most likely be required with no default property.


slug: {
type: String,
default: null,
Copy link
Member

Choose a reason for hiding this comment

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

Same as above


name: {
type: String,
default: null,
Copy link
Member

Choose a reason for hiding this comment

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

If the type should be String, then we should set the default to '' instead to be consistent.

@bencodezen bencodezen changed the title Created generic Codepen Snippet component feat: created generic Codepen Snippet component Oct 27, 2020
@bencodezen bencodezen merged commit 722b92e into vuejs:master Oct 27, 2020
nick-lai pushed a commit to nick-lai/docs-next that referenced this pull request Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants