Skip to content
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

Share component code cleanup and refactor #848

Merged
merged 34 commits into from
Sep 26, 2018

Conversation

mikemai2awesome
Copy link
Collaborator

@mikemai2awesome mikemai2awesome commented Aug 23, 2018

Jira

http://vjira2:8080/browse/BDS-311

Summary

Refactored share component's code to be more efficient. inline and copyToClipboard have been deprecated. size and opacity have been added as props to allow more flexibility.

Details

  1. Cleaned up the CSS and twig file.
  2. Removed as much overrides as possible.
  3. Followed the Bolt conventions and renamed certain props and variables.
  4. Button version has been removed because it's not being used.
  5. Latest 2.x has been pulled in.
  6. Icon component has been changed: small icon size has been increased and stroke has been decreased.
  7. Copy to clipboard has been changed: misc. code clean ups.
  8. copyToClipboard prop has been renamed to copy_to_clipboard.
  9. inline prop has been removed because button version is not being utilized.
  10. size prop has been added to control text and icon size, and spacing.
  11. opacity prop has been added to control the initial transparency of the share tool.

View demo

screen shot 2018-09-25 at 12 01 38 pm

How to test

Pull down the branch and run locally. Navigate to pattern lab and view the share component. Test all the links and copy to clipboard function.

Notes

  1. It has not been converted to a web component.

@mikemai2awesome mikemai2awesome changed the title Feature/bds 311 share component refactor Share component code cleanup and refactor Aug 23, 2018
@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

Copy link
Collaborator

@remydenton remydenton 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 overall thoughts

  1. I know we said we want to change from camelCase to kebab-case for variable names. I'm wary of handling it the way it's done in this PR though-- technically, this is a breaking change, and while it's relatively minor here (the share component is only used in one place that we know of), I think it sets a bad precedent. I would argue we need:

    • backwards compatibility (e.g. at the top of the file, a section that coverts old variable names to new so nothing breaks)
    • a way of announcing the deprecation and actually making sure it gets updated on the consuming end
    • a plan for removing the deprecated cruft in the next major release.
  2. FYI, it's harder to manage a PR when it includes work from another PR that hasn't been merged yet (e.g. bolt-list in this case). There's no perfect solution and it's better to keep working rather then getting blocked, but when possible avoid it (maybe nag the reviewers on the first PR :) )

{# Share component's custom element wrapper. #}
<bolt-share
{% if display %} display="{{ display }}" {% endif %}
{{ parentAttributes }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

parentAttributes are not defined (and the attributes object isn't used).

I still don't fully understand the decision to split attributes into parentAttributes and attributes that go inside the component. Potentially worth a parking lot discussion today unless @mikemai2awesome or @sghoweri has an answer that can be posted here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Things like hidden/visuallyhidden, margin, and padding overrides need to be on the outer most container for most scenarios to work as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, I get why you need some attributes on the outer container. But do you necessarily need any of them on the inner container?

],
target: source_target
}
})]) %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a long story (see #846), but due to autoescaping to prevent XSS vulnerabilities on the Drupal end, you can't use this syntax. Basically, you can't set a variable to the results of the include function:

{% items = items|merge[include(....)] %}

Instead, you have to print the results of include

{% set item %}
  // add any includes here with either of these:
  {{ include("something.twig") }}
  {% include something.twig %}
{% endset %}
{% items = items|merge[item] %}

It's currently a gotcha that Salem and I are trying to figure out how to address. For now, if you just don't use the include() function in component templates (it's okay to use in Pattern Lab), you should be fine.

I will fix this case and push an update.

{% if copyToClipboard %}
{% set item %}
{% include "@bolt-components-copy-to-clipboard/copy-to-clipboard.twig" with copyToClipboard only %}
{% if copy_to_clipboard %}
Copy link
Contributor

Choose a reason for hiding this comment

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

@mikemai2awesome why don't you just pass in the copy_to_clipboard data directly to that component?

That should eliminate the need to map anything (and would also mean the copy_to_clipboard component could get updates that wouldn't require going back in and updating the share component).

Have you tried something like this?

{% if copy_to_clipboard %}
  {% set copy_to_clipboard_include %}
    <div class="c-bolt-share__copy">
      {% include "@bolt-components-copy-to-clipboard/copy-to-clipboard.twig" with copy_to_clipboard only %}
    </div>
  {% endset %}
  {% set items = items|merge([item]) %}
  {% set items = items|merge([copy_to_clipboard_include]) %}
{% endif %}

That should allow you to then do something like this when you're trying to use it (note the "text" prop is nested inside of the copy_to_clipboard data):

{% include "@bolt-components-share/share.twig" with {
  sources: [
    {
      name: "facebook",
      url: "https://www.facebook.com/sharer/sharer.php?u=https://5abd3062df99537b79e29496--bolt-design-system.netlify.com/pattern-lab/patterns/02-components-action-blocks-05-action-blocks/02-components-action-blocks-05-action-blocks.html&amp;src=sdkpreparse"
    },
    {
      name: "twitter",
      url: "https://twitter.com/intent/tweet?url=https://bolt-design-system.com&text=Sample%20Share%20Text&via=pega&hashtags=boltDesignSystemRocks!"
    },
    {
      name: "linkedin",
      url: "https://www.linkedin.com/shareArticle?url=https://5abd3062df99537b79e29496--bolt-design-system.netlify.com/pattern-lab/patterns/02-components-action-blocks-05-action-blocks/02-components-action-blocks-05-action-blocks.html"
    },
    {
      name: "email",
      url: "mailto:?&body=Sample%20Text%20--%20https%3A//bolt-design-system.com"
    }
  ],
  copy_to_clipboard: {
    url: "http://pega.com",
    text: "Copy share link"
  }
} only %}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But I want to define the text to be Copy share link though, and have it translatable. If it comes from the schema default, it's not translated. Also, in this case, I am wrapping something around the text so I can style some hover animation.

This feels dirty, I need a better way:

{% include "@bolt-components-copy-to-clipboard/copy-to-clipboard.twig" with {
  text: "<span class='c-bolt-share__link-text'>#{copy_to_clipboard_text}</span>",
  url: copy_to_clipboard_url,
  attributes: {
    class: "c-bolt-share__link"
  }
} only %}

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for chrome Passed!

Image of chrome test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ Sauce Labs Test for internet explorer Passed!

Image of internet explorer test
Test Details

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@remydenton remydenton force-pushed the feature/bds-311-share-component-refactor branch from 15a7cf2 to 79330d2 Compare September 21, 2018 18:04
@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@remydenton
Copy link
Collaborator

remydenton commented Sep 25, 2018

When you deprecate something in a PR, it's important to follow all the steps in part I of the deprecation wiki page

Missing pieces here:

  • Update your schema to specifically exclude the old properties. This lets us quickly find any incorrect usages in pattern lab:
not:
  required:
    - copyToClipboard
  • Add a description of the deprecations to your PR description. This will be used by the Drupal guys when pulling this in.

Yes, deprecation is a pain in the butt.

Copy link
Collaborator

@remydenton remydenton left a comment

Choose a reason for hiding this comment

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

Updates look good, nice work.

@bolt-bot
Copy link
Collaborator

⚡ PR built on Travis and deployed a now preview here:

@remydenton remydenton merged commit 021ce6d into master Sep 26, 2018
@remydenton remydenton deleted the feature/bds-311-share-component-refactor branch September 26, 2018 18:37
@remydenton remydenton mentioned this pull request Sep 26, 2018
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