Creating a Flexible Astro Component

Sdílet
Vložit
  • čas přidán 31. 05. 2024
  • Join the early access list for my course! learnastro.dev
    Astro provides tremendous helps for building robust components. We’ll explore them with a simple Astro Button component.
    🔗 Key Links 🔗
    - Github: github.com/coding-in-public/a...
    ---------------------------------------
    📹 Related Videos 📹
    - Astro Crash Course: • Astro Crash Course in ...
    ---------------------------------------
    ⏲️ Timestamps ⏲️
    0:00 Introduction
    1:36 Setup
    3:30 Why use components?
    4:45 Button Component HTML
    16:22 Button CSS
    27:11 CSS class scoping
    30:22 Client-side JS
    31:36 Adding TypeScript
    ---------------------------------------
    🎨 VSCode Theming
    - Font: Cascadia Code: github.com/microsoft/cascadia...
    - Theme: marketplace.visualstudio.com/...
    - Icons: marketplace.visualstudio.com/...
    ---------------------------------------
    🌐 Connect With Me 🌐
    - Website: codinginpublic.dev
    - Blog: chrispennington.blog
    - Twitter: / cpenned
    - Patreon: / coding_in_public
    - Buy Me a Coffee: www.buymeacoffee.com/chrispen...
  • Jak na to + styl

Komentáře • 48

  • @cspjdbh
    @cspjdbh Před 11 měsíci +7

    You're teaching me so much about Astro. You inspire me to help others as well. Keep them coming!

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci +2

      So glad you’ve enjoyed the content! More coming next week!!

  • @phucnguyen0110
    @phucnguyen0110 Před 11 měsíci +2

    Yes, there we go! Lovely to see another developer tackling this subject :D
    (Shoutout to Mr. Kevin Powell aka The CSS King)

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci

      Glad you enjoyed it! Did Kevin do something on an Astro button?

    • @phucnguyen0110
      @phucnguyen0110 Před 11 měsíci

      @@CodinginPublic he basically did a video exploring components in Astro, Chris. Not buttons specifically => watch?v=acgIGT0J99U

  • @toppirl
    @toppirl Před 11 měsíci +4

    Really starting to enjoy learning Astro and only got started because of your videos! Thanks for the great video as always

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci +1

      That’s so encouraging to hear! Thanks for taking the time to comment!

  • @mattythebatty1
    @mattythebatty1 Před 8 měsíci +3

    🎯 Key Takeaways for quick navigation:
    00:00 🌟 Astro combines static HTML simplicity with dynamic flexibility.
    03:33 🧩 Astro components allow prop customization and reusability.
    08:17 🎨 Use slots for content in Astro components.
    13:08 🔄 Dynamically add classes with `classlist` in Astro.
    15:57 📜 Spread HTML attributes using `...rest` for flexibility.
    17:50 🎨 Define variables in front matter for dynamic CSS in Astro.
    19:41 🧩 Pass CSS variables with the `Define vars` feature.
    20:21 📐 Set default styles with CSS variables for theme-based adaptability.
    22:38 📏 Use relative units like `em` for dynamic padding.
    23:36 🖱️ Add interactivity to Astro components with JavaScript.
    32:12 🚀 Enhance Astro components with TypeScript for auto-completion and type safety.
    Made with HARPA AI

  • @lvekua
    @lvekua Před 11 měsíci

    Awesome guide Chris! Typescript was cherry on top. Thank you! ❤

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci

      Glad it was a help! Thanks for taking the time to say something!

  • @BG-xu8be
    @BG-xu8be Před 9 měsíci +1

    Amazing stuff, a real master class tutorial, thank you!

  • @felipegutierrez2944
    @felipegutierrez2944 Před 11 měsíci

    Awesome content as always! keep the good work!

  • @user-fi7lb4oh2z
    @user-fi7lb4oh2z Před 9 měsíci +1

    Thank you so much for your videos. It helps a lot!

  • @fallen_turbo
    @fallen_turbo Před 8 měsíci +1

    Your astro course is amazing

  • @latch909
    @latch909 Před 8 měsíci

    Fantastic - `class:list` so helpful!

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci

      Agreed! They did make some small changes to it recently so that it now uses CLSX. That basically just means you can't use sets, I think? But still basically the same and super helpful!

  • @MarcKronberg
    @MarcKronberg Před 6 měsíci

    Super Thanks!

  • @hamza201183
    @hamza201183 Před 8 měsíci +1

    Many thanks!
    Is there a way to encapsulate the 'onClick' logic inside the button? Instead of a query-selector and a script tag outside of the button...

    • @CodinginPublic
      @CodinginPublic  Před 7 měsíci

      It's possible, but I've found it's cleaner to have in-line scripts for these items. I've changed my pattern here for components. I'd definitely use a slot these days. In that case, you could fairly easily have a slot for a script that could run whatever function you needed. Hopefully that makes sense?

    • @dharyelsantoshonorio5890
      @dharyelsantoshonorio5890 Před 3 měsíci +1

      @@CodinginPublic can you detail more how to do it?

  • @MarcKronberg
    @MarcKronberg Před 6 měsíci

    Danke!

  • @johnner5735
    @johnner5735 Před 5 měsíci

    My first time learning Astro =)

  • @realJZ
    @realJZ Před 8 měsíci

    What is the terminal/shell you are using? I would like to know how you have "intellisense" like menu for folders

    • @CodinginPublic
      @CodinginPublic  Před 8 měsíci

      The autocomplete is a tool called Fig! At fig.io :)

  • @danicmaxime9003
    @danicmaxime9003 Před 11 měsíci

    Love exploring astro with you ! 🙌
    I was wondering what's the avantages to use astro with react ? Since react and astro are based on component , how to use astro and react together then ?

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci

      I think for me, it comes down to complexity. If the UI/UX required is complex, it's likely worth it to load react (or if it's behind auth). Otherwise, I tend towards vanilla JS and Astro components. Does that help?

  • @LeandroVilanovaDev
    @LeandroVilanovaDev Před 11 měsíci

    10/10

  • @moneyfr
    @moneyfr Před 11 měsíci

    amazing i learned so much but what about the accesibility ?

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci

      Awesome! Well, that’s the cool thing. Since we spread in the …rest, you can add an aria-label=“whatever” and it’ll get added to the button! So that should handle most all of your accessibility needs with a button!

  • @viophile
    @viophile Před 11 měsíci +1

    I would use a CSS library such as Bulma instead.

  • @DanteMishima
    @DanteMishima Před 11 měsíci

    This is cool....
    But what happened to your other video Chris?

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci +2

      I published it too early :) It'll be back up Friday!

    • @DanteMishima
      @DanteMishima Před 11 měsíci

      @@CodinginPublic I had my editor ready to follow along, then boom gone 😂

    • @phucnguyen0110
      @phucnguyen0110 Před 11 měsíci

      @@CodinginPublic Yes, I was wondering about that too lol - okay, noted that on Friday then.

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci +1

      @@DanteMishima Sorry! It's up now here: czcams.com/video/wkxPpGXAoes/video.html

    • @CodinginPublic
      @CodinginPublic  Před 11 měsíci +1

      @@phucnguyen0110 Sorry! It's up now here: czcams.com/video/wkxPpGXAoes/video.html

  • @robertostringa9254
    @robertostringa9254 Před 5 měsíci

    Why so many props for a component that could easily be CSS classes ? I don't see its usefulness.

    • @CodinginPublic
      @CodinginPublic  Před 5 měsíci

      I don't remember all the choices I made here, but looking at the code, I agree with you. I'm wondering if I was just trying to show different options? But I think I'd tend to just use classes here.