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

Convert blockquote to web component #984

Merged
merged 68 commits into from
Jan 22, 2019

Conversation

danielamorse
Copy link
Collaborator

@danielamorse danielamorse commented Dec 7, 2018

Jira

Summary

Convert bolt-blockquote to a web component.

Details

Extend bolt-blockquote component so that blockquotes can be rendered both by twig and via web component. Document any changes.

How to test

@bolt-bot
Copy link
Collaborator

bolt-bot commented Dec 7, 2018

⚡ 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:

// return 'bordered-vertical';
// }
// }
validateProps(propData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: this feels about ready to promote to either a JS decorator we can tack on before the Class (like @define is, but perhaps with params for this one) or via adding it to the Bolt base component Class

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sghoweri I moved the validateProps method to the base class in this commit. The way we're calling it in the render function I thought this worked better than a decorator, but perhaps you had more refactoring in mind? Just let me know if you have suggestions. Thanks!

// If the initial <bolt-link> element contains a link, break apart the original HTML so we can retain the a tag but swap out the inner content with slots.

// Make sure the button component ONLY ever reuses any existing HTML ONCE. This, in part, helps to prevent rendering diff errors in HyperHTML after booting up!
if (this._wasInitiallyRendered === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: this also is starting to feel like a common reoccurring pattern to share across multiple types of components dealing with this. my thought would be to abstract this out to being a util function for now that accepts an array of tag names to check for and returns back the pre-processed and normalized child element.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rendered() {
super.rendered(); // ensure any events emitted by the Bolt Base class fire as expected

// re-render if Shadow DOM is supported and enabled; temp workaround to dealing w/ components already rendered, but without slot support
Copy link
Contributor

Choose a reason for hiding this comment

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

@danielamorse are we having to do any extra template logic / CSS classes based on any slotted content? If not, is this extra mutation observer actually needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sghoweri removed, see current version of this file.

"publishConfig": {
"access": "public"
},
"dependencies": {
"ajv": "^6.5.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

@danielamorse same as with the other schema validation comment above -- this dependency should get moved up to Bolt Core as soon as we package up and share schema validation logic at a higher level

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bolt-bot
Copy link
Collaborator

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

foreach ($source as $key => $value) {
// If $key is not in $target, or if $key is in $target and $value in $source is empty, add/overwrite $key in $target
// NOTE: empty() and is_null() do not work in the second half of this statement. Why is that?
if (empty($target[$key]) || (!empty($target[$key]) && $value != "")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your code comment says

If $key is not in $target, or if $key is in $target and $value in $source is empty

Your code does this:

If $key is not in $target, or if $key is in $target and $value in $source is NOT empty

Maybe that had something to do with why empty() wasn't working?

In any case, I would replace the whole thing with the following for clarity. Further reading on the array_merge PHP function.

return new Twig_SimpleFunction('merge_attributes', function($target, $source) {
  return array_merge($target, $source);
}

Copy link
Collaborator

@remydenton remydenton Jan 14, 2019

Choose a reason for hiding this comment

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

And upon further thought, if that's all the custom twig function is doing, we could probably just use the twig merge function instead.

Along those lines, I think it's best to avoid creating custom twig functions that get used within component twig when we can (if they're just used in pattern lab, anything goes) because any custom twig functions also have to work in Drupal. That is, if you pulled the file into Drupal as you have it, it would break with an error about merge_attributes being undefined, and the Drupal team would have to copy this custom function over to their codebase AND maintain it there (i.e. make sure it stays in sync with Bolt's). That problem could potentially be solved by having a system for sharing functions from Bolt to Drupal, but we don't have that AFAIK.

Finally (and sorry to be such a naysayer here), I want to check that merging attribute arrays still results in something that is usable in the same way on the Drupal end. Testing that now.

Copy link
Contributor

@sghoweri sghoweri left a comment

Choose a reason for hiding this comment

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

Very very nice work @danielamorse!

I know we're still iterating on the new pattern for setting up props / prop validation (and we should sneak in a few Jest tests before merging) but this is more than done enough to get my 👍👍

@sghoweri sghoweri merged commit c694979 into master Jan 22, 2019
@sghoweri sghoweri deleted the feature/convert-blockquote-to-web-component branch January 22, 2019 12:20
This was referenced Feb 1, 2019
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.

6 participants