Introduction to Building Custom Web Components

Поділитися
Вставка
  • Опубліковано 2 жов 2024
  • This video explains the fundamentals of creating custom Web Components for your web sites. Topics covered are:
    classes that extend HTMLElement;
    customElements.define method;
    templates and slots;
    shadowRoots and why we need them.
    Github Repo with code from video: github.com/pro...
    Using HTML5 Templates - • Using HTML5 Templates
    cloneNodes and creating HTML Templates - • cloneNode Method and C...

КОМЕНТАРІ • 66

  • @heshanwijerathna
    @heshanwijerathna Рік тому +14

    Your channel is a gold mine. And some day this channel will become every ones favorite. I learned lot from you.

  • @mohamedelkhalil1288
    @mohamedelkhalil1288 8 місяців тому +1

    Great video! I gotta ask, how can I build js headless packages?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  8 місяців тому

      The only tutorial I have on anything headless is this one - ua-cam.com/video/nIJV-LbV_vM/v-deo.html

  • @ranathedev
    @ranathedev Рік тому +2

    Thanks a bunch, sir! Your explanation is just amazing. This is the first video I've watched of yours and already subscribed to complete all of the series you've made free for us to learn. Thank you for your efforts! 🙏

  • @jeanmarcpourchel307
    @jeanmarcpourchel307 Рік тому +2

    i agree with Heshan wijerathna!.....biggest gold mine ever!!!
    Very good idea, very good explanations!
    it's very usefull before learning frameworks such as angular ( even though it's typescript) or vuejs!
    And as always....thanks for teaching and sharing!!!

  • @Aquilesxd
    @Aquilesxd 2 місяці тому

    Amazing video! My coleague and I has been studying this subject, and you are the only one who got that deep into it! Just one question: is there any way to document our web components so that the IDE can help whoever is using them?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 місяці тому +2

      @@Aquilesxd a great way to do this is to make them into a public repo on github and add the Readme.md file at the root where you provide all the information.
      Also include demo code or an example webpage using the component

    • @Aquilesxd
      @Aquilesxd 2 місяці тому

      @@SteveGriffith-Prof3ssorSt3v3 I see, thanks a lot! Again, amazing work man, keep it up!

  • @bxlbjorn
    @bxlbjorn Рік тому

    finally, a fantastic explanation!!!

  • @AniishAu
    @AniishAu Рік тому +1

    Bah! I thought you could only do that in React!

  • @fernandoarnaldovilanculo8286
    @fernandoarnaldovilanculo8286 3 місяці тому

    Thank you sir! Keep it up!

  • @emirmasinovic
    @emirmasinovic 9 місяців тому

    Is using innnerHTML safe in this case? If yes, then what would be the point of using a framework? What would other strong points for it be?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  9 місяців тому +1

      innerHTML is only ever safe if the values that you are putting into it are completely controlled by the developer and not using user provided content.

  • @Bengadeer
    @Bengadeer 4 місяці тому

    I've built the various web components in this series and they worked great...in VS Code. Why don't they work when I open the index.html in a native browser? The CSS and active JS don't seem to wake up.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 місяці тому

      Are you importing the module for the component?

    • @Bengadeer
      @Bengadeer 4 місяці тому +1

      @@SteveGriffith-Prof3ssorSt3v3 I figured it out. First: yep module called. The issue is Chome called me out on a CORS violation for this code loading directly to the browser.

  • @ROSSNKUNGA
    @ROSSNKUNGA 7 місяців тому +1

    Steve you are a gift, i am so lucky to have you as my JS professor in my school program and program coordinator, you are so dedicated, 🔶, I understand this concept in a simple way wow! Be blessed Steve i love you and what you do for us and the rest of the world 🙌🦾

  • @Anonymouzee
    @Anonymouzee Рік тому

    good info... ?where is the link for the video on templates?

  • @OK-qy3ir
    @OK-qy3ir 8 місяців тому

    Great video! A question about the web components. How does the search engine read the web components, it is a shadow-root ... Is the rendered content indexed? How does the search engine handle it? Thanks a lot Steve!

  • @fahdfuhaid573
    @fahdfuhaid573 3 місяці тому

    Thanks ... very helpful series. i hope we see multi components put together to make a web app.

  • @chhavimanichoubey9437
    @chhavimanichoubey9437 Рік тому

    this was absolutely weird concept for me.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому +1

      It is become a more common practice with large companies so they can standardize building their sites. There are many libraries of components available too.

    • @chhavimanichoubey9437
      @chhavimanichoubey9437 Рік тому +1

      @@SteveGriffith-Prof3ssorSt3v3 thanks for the head's up.

  • @zerqs
    @zerqs Рік тому

    I was searching your channel for a guide last night for web components , wow :D

  • @sinamobasheri
    @sinamobasheri 6 місяців тому

    Beautiful Beautiful ❤ Thanks Steve

  • @ssikarim
    @ssikarim Рік тому

    Thanks Steve,
    Is it a good practice to build html elements in js with template literals ?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому

      If you are building web components yes. Much easier that creating elements and slots individually through the script and appending them to the shadow root

  • @abulabbas1581
    @abulabbas1581 Рік тому

    Hi thanks for this knowledge great learning .. Where can i get the whole documentation about this web components ? Kindly share the link if possible Thanks

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому +1

      Here is my full playlist for Web Components - ua-cam.com/video/j0qG-afD244/v-deo.html
      The mozilla developer network site has lots of notes about web components.
      So does the google web.dev site.
      www.w3.org/TR/components-intro/ - is the official spec for web components.

  • @tomatescript
    @tomatescript Рік тому

    Thanks for the video Steve, your explanation is really good and direct to the point!

  • @aileenchan3741
    @aileenchan3741 Рік тому

    Wow, what a great video! Thank you for making this video and so happy I found it! Is this the same approach React is doing when creating components? Like when in React we pass {children} to a parent component, but in Vanilla JS it is with ? I feel like I don't know Vanilla JS well enough, wow!!! Excellent video!

  • @RajibAhmad
    @RajibAhmad Рік тому

    Thanks a lot Steve for all those priceless tutorials.... simply amazing

  • @johnm8358
    @johnm8358 Рік тому

    when should i use web components over React/Vue components?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому +3

      They are two separate things. With the frameworks you are building components that work within the one site that you are currently building with that specific framework.
      Web Components are something that you can build and then reuse on any site that you want with or without a framework.

  • @jezza10181
    @jezza10181 Рік тому

    Nice explanation

  • @sovereignlivingsoul
    @sovereignlivingsoul Рік тому

    excellent video, nice explanations, I have just started looking into web components and this was an excellent resource, look forward to your other videos.

  • @komkwam
    @komkwam Рік тому

    Wasn't this what xhtml was all about, to make your own tags?

  • @cristian702
    @cristian702 6 місяців тому

    LOVE IT!

  • @D7460N
    @D7460N 9 місяців тому

    Thank you for this video. Very straightforward. Look forward to watching your other videos.
    Is shadowdom required for native web components?
    Also, is JavaScript registration of the custom HTML tag required to display content?
    Or is JavaScript registration necessary to display dynamic content?
    Thanks again!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  9 місяців тому

      shadowdom is how custom elements are added to the dom to create a "safe space" for them to have contained CSS that doesn't impact the rest of the page.
      To use a custom element you do need to register it. If you don't then the browser will treat your like a span with no CSS or behaviour.

    • @D7460N
      @D7460N 9 місяців тому

      @SteveGriffith-Prof3ssorSt3v3
      Thank you for the reply. Apologies for my ignorance, but in light of keeping things simple if possible, isn't it easier to simply target the custom HTML tag for styling rather than taking on additional complexity with shadowdom? What am I missing?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  9 місяців тому

      @@D7460N The ShadowDOM is automatically there around any custom element. The purpose of the shadowDOM is to isolate and protect the page from the element and the element from the page. We don't want styles from one transferring to the other and impacting the appearance of other things. There are a few basic styles that cascade down from the page to the HTML inside the custom element but not many.
      You wouldn't want to define a component with wild colours and have that leak out on to every website that uses the component.

  • @ahmedsalahabdullah2317
    @ahmedsalahabdullah2317 Рік тому

    thank you

  • @whitehat4u
    @whitehat4u Рік тому

    excellent!, add about ShadowCSS and it's perfect ;)

  • @hericklenin
    @hericklenin Рік тому

    Great material, thank you for this. Why main.js is the parent of the bigbang.js?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому +1

      It's not. main.js is there just to prove the point that you do NOT need to import bigbang.js
      It just needs to be loaded and run. the customElements.define() command is the part that does all the work.

    • @hericklenin
      @hericklenin Рік тому +1

      @@SteveGriffith-Prof3ssorSt3v3 Awesome! Thank you.

  • @derekfarealz
    @derekfarealz Рік тому

    steve you are the gem of js. never stop!

  • @mohammedabdulaziz3658
    @mohammedabdulaziz3658 Рік тому

    Nice

  • @RemzM
    @RemzM Рік тому

    Such a great explanation as always, thank you Steve. I still hope and believe we will see your big Vue course in the future 🙂

  • @amankumarraj5090
    @amankumarraj5090 Рік тому

    Hey Steve Sir. I am going through your video tutorials. They are really wall made, appreciate it.
    I have a question which would like you to address. I am willing to create an html page using Javascript function which will be stored in the Website's database and has a link address to access the created page. The Javascript function will be linked to a button which when clicked, a page is created.
    Do answer this query of mine.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому

      What website database are you talking about? The .hosts file? IndexedDB? Cache API? Web SQL? something else? Really not sure what you are asking. Not something I can really answer in a comment though.

    • @amankumarraj5090
      @amankumarraj5090 Рік тому

      @@SteveGriffith-Prof3ssorSt3v3 I am referring to any database which can store the newly created html pages in it.
      The functionality i am talking about is that => A button will be provided in a website and whenever the button is clicked by a user, it will automatically generate a new page with the extension .html which will be stored in the website's server or database and has a website link to access it thereafter.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Рік тому

      @@amankumarraj5090 so basically you are asking how to build a content management system.
      Not something anyone could answer in a comment

    • @amankumarraj5090
      @amankumarraj5090 Рік тому

      @@SteveGriffith-Prof3ssorSt3v3 Where will I get the solution for this Sir? Would be great if you can make up a tutorial on it using Javascript. Earnestly looking forward to your approach on it.

  • @arunkaiser
    @arunkaiser Рік тому

    Please change the thumbnail design it is not much attractive