exploring drupal 8 frontend landscape through polymer
play

Exploring Drupal 8 FrontEnd Landscape through Polymer ~Saket & - PowerPoint PPT Presentation

Exploring Drupal 8 FrontEnd Landscape through Polymer ~Saket & Piyuesh Drupalcon New Orleans History of Web Drupalcon New Orleans Front End World - We have a plethora of tools, frameworks, languages, abstractions etc. Drupalcon New


  1. Exploring Drupal 8 FrontEnd Landscape through Polymer ~Saket & Piyuesh Drupalcon New Orleans

  2. History of Web Drupalcon New Orleans

  3. Front End World - We have a plethora of tools, frameworks, languages, abstractions etc. Drupalcon New Orleans

  4. Choice Paralysis Drupalcon New Orleans

  5. Drupalcon New Orleans

  6. They all share this notion of components, but they do it differently and don’t work together. Drupalcon New Orleans

  7. Drupalcon New Orleans

  8. Custom Elements define new HTML/DOM HTML Template native client-side templating Shadow DOM scoping, composition HTML Imports loading web components Drupalcon New Orleans

  9. Traditional HTML With Web Components Hello DrupalCon! <input type="text" name="textbox" value=" Hello DrupalCon!"> <search-textbox text-placeholder="Search this site" search-icon="search.png"> </search-textbox> <div class="search"> <input type="text" name="textbox" placeholder="Search this site"> <input type="button" name="search"> </div> Drupalcon New Orleans

  10. Web Components ( - Low level APIs )

  11. Drupalcon New Orleans

  12. Applications Existing Frameworks Web Components built with Polymer (or not) Web Platform Drupalcon New Orleans

  13. READY FOR PRODUCTION Drupalcon New Orleans

  14. Over 1.3M pages Drupalcon New Orleans

  15. Let’s create an Element Drupalcon New Orleans

  16. Drupalcon New Orleans

  17. <site-message></site-message> Drupalcon New Orleans

  18. site-message.html <link rel=“import” href=“../polymer/polymer.html”> <dom-module id=“site-message"> <template> </template> <script> Polymer({ is: ‘site-message' }); </script> </dom-module>

  19. site-message.html <link rel=“import” href=“../polymer/polymer.html”> <dom-module id=“site-message"> <template> Import all of our </template> dependencies <script> Polymer({ is: ‘site-message' }); </script> </dom-module>

  20. site-message.html <link rel=“import” href=“../polymer/polymer.html”> <dom-module id=“site-message"> <template> </template> A container for our <script> Polymer({ element definition is: ‘site-message' }); </script> </dom-module>

  21. site-message.html <link rel=“import” href=“../polymer/polymer.html”> <dom-module id=“site-message"> <template> </template> Local DOM is the DOM <script> an elements is in charge of Polymer({ creating and managing is: ‘site-message' }); </script> </dom-module>

  22. site-message.html <link rel=“import” href=“../polymer/polymer.html”> Hey user! Something happened! <dom-module id=“site-message"> <template> <style> .alert { background: green; color: white; } </style> <div class=“alert”> Hey user! Something happened! </div> </template> <script> Polymer({ is: ‘site-message' }); </script> </dom-module>

  23. <header> <div> // header html </div> </header> <site-message></site-message> <content> <div> // content </div> </content> Drupalcon New Orleans

  24. site-message.html index.html <link rel=“import” href=“../polymer/polymer. <header> html”> <div> <dom-module id=“site-message"> // header html <template> <style> </div> .alert { background: green; color: </header> white; } <site-message> </style> <span class=“message”> <div class=“alert”> Success! Your first component! <content select=“.message”></content> </span> </div> </site-message> </template> <script> <content> Polymer({ <div> is: ‘site-message' // content }); </div> </script> </content> </dom-module> Drupalcon New Orleans

  25. Drupalcon New Orleans

  26. site-message.html <link rel=“import” href=“../polymer/polymer.html”> <dom-module id=“site-message"> <template> <style> .alert { background: green; color: white; } </style> <div class=“alert”> <content select=“.message”></content> </div> </template> <script> Polymer({ is: ‘site-message', Properties make your properties: { element configurable shown: { type: Boolean, value: false, notify: true } }); </script> </dom-module>

  27. site-message.html <dom-module id=“site-message"> Bind attributes to the <template> … state of a property <div class=“alert” hidden="{{!shown}}"> <content select=“.message”></content> </div> </template> <script> Polymer({ is: ‘site-message’, properties: { shown: { type: Boolean, value: false, notify: true } }

  28. Results Drupalcon New Orleans

  29. <header> <div> // header html </div> </header> <site-message> <span class=“message”> Success! Your first component! </span> </site-message> <content> <div> // content </div> </content> Drupalcon New Orleans

  30. <header> <div> // header html </div> </header> <site-message shown> <span class=“message”> Success! Your first component! </span> </site-message> <content> <div> // content </div> </content> Drupalcon New Orleans

  31. Elements Building blocks for a better web Drupalcon New Orleans

  32. So adding a new feature in the site is just adding a pre-existing element available. https://customelements.io/ https://elements.polymer-project.org/ Drupalcon New Orleans

  33. Drupal Theme Drupalcon New Orleans

  34. Add a ‘elements’ directory in your theme’s root folder, to keep all the custom elements. Drupalcon New Orleans

  35. If you want to use contributed custom elements, include it in your bower.json Drupalcon New Orleans

  36. Populate all those elements in the elements.html in the elements folder Drupalcon New Orleans

  37. Add webcomponents.js polyfill in theme’s html. html.twig file in the <head> tag <script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script> Drupalcon New Orleans

  38. Add elements.html in theme’s html.html.twig file in the <head> tag <link rel="import" href="elements/elements.html"> Drupalcon New Orleans

  39. html.html.twig webcomponents-lite.js elements.html

  40. GULP INTEGRATION Drupalcon New Orleans

  41. Browser Support With the polyfills, Polymer works in these browsers: Drupalcon New Orleans

  42. See Are We Componentized Yet? and caniuse.com for more information on native browser support for web components. Drupalcon New Orleans

  43. Resources Try it out yourself: https://nola.qed42.net Codebase: https://github.com/qed42/nola_dcp16 Read more about Polymer : https://www.polymer-project.org ● http://webcomponents.org/ ● https://customelements.io/ ● Polycasts by Rob Dodson ● Drupalcon New Orleans

  44. So How Was It? - Tell Us What You Think Evaluate this session - https://events.drupal. org/neworleans2016/sessions/exploring-drupal-8-frontend-landscape-through- polymer Thanks!

Recommend


More recommend