π **Day 9 β Toasts, Laughs & Custom Magic!** πβ¨
hive-139531Β·@sagarkothari88Β·
0.000 HBDπ **Day 9 β Toasts, Laughs & Custom Magic!** πβ¨
Hey Hive Community Members! π Welcome back to my wild ReactJS learning ride π’ β and guess what? Weβre already on **Day 9**! If you've missed previous episodes, don't worry. Grab some popcorn πΏ and catch up with the epic saga below: --- ### π **ReactJS Journey So Far** - [π **Day One**](https://peakd.com/hive-139531/@sagarkothari88/integrate-aioha-with-your-react-app-from-scratch-vite--tailwind--daisyui): Fresh React app + AIOHA integration! - [π§ **Day Two**](https://peakd.com/hive-139531/@sagarkothari88/integrating-react-router-my-routing-adventures-with-react): Routing drama & rebellious NavBar π€ - [π οΈ **Day Three**](https://peakd.com/hive-139531/@sagarkothari88/from-navbar-mess-to-react-router-success-fixing-layouts-routing-and-aioha-in-one-go): Fixed Layouts, Routing & AIOHA π₯ - [π§ **Day Four**](https://peakd.com/hive-139531/@sagarkothari88/day-4-reactjs-adventures--distriator-progress-usestate-useeffect-and-env-chaos): useState, useEffect, and .env headaches π - [π§Ή **Day Five**](https://peakd.com/hive-139531/@sagarkothari88/level-up-your-imports-using-path-aliases-for-cleaner-react--typescript-projects): Path Aliases to clean up relative path spaghetti π - [π‘ **Day Six**](https://peakd.com/hive-139531/@sagarkothari88/day-6-learning-reactjs-calling-apis-and-creating-context-providers-or-distriator-feature-update): Create Context Provider & call API - [π **Day Seven**](https://peakd.com/hive-139531/@sagarkothari88/learning-reactjs--vite--ts--aioha-day-7-show-a-toast-message): Show a toast message - [π **Day Eight**](https://peakd.com/hive-139531/@sagarkothari88/day-8-secure-login-with-aioha-and-localstorage-magic): Login with AIOHA & Distriator & LocalStorage magic --- ## π₯³ **Today's Adventure: Custom Toast Component** As highlighted in earlier posts, thereβs a super cool way to show toast messages with the 'sonner' library ([link](https://github.com/emilkowalski/sonner))... **But!** I created my own Toast component. It's my first React babyβhow could I abandon it? π€£ So, today we jazz things up and show how to *customize* our own toast messages and style them like a pro. π§βπ¨ --- ### πΌοΈ Toasty Visuals  --- ### π‘ **Define Custom Enums for Toasts** ``` // ToastType as a string enum export enum ToastType { Error = "error", Warning = "warning", Info = "info", Success = "success" } // ToastStyle as a string enum export enum ToastStyle { Regular = "regular", Soft = "soft", Outline = "outline", Dash = "dash" } ``` Because when life hands you errors, turn them into enums! π --- ### π¨ **SVG Icons for Every Occasion** ``` function errorPath() { return <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />; } function warningPath() { return <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /> } function successPath() { return <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />; } function infoPath() { return <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />; } ``` Why pick *one* mood when you can have four? π --- ### βοΈ **Toast Props Ready for Showbiz** ``` type ToastProps = { message: string; type: ToastType; style: ToastStyle; show: boolean; setShow: React.Dispatch<React.SetStateAction<boolean>>; }; const Toast: React.FC<ToastProps> = ({ message, type, style, show, setShow }) => { ``` Toast gets picky: βI want my message! And my style! And my own show!β --- ### ποΈ **SVG Rendering, Like a Boss** ``` <svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6 shrink-0 stroke-current" fill="none" viewBox="0 0 24 24"> {path()} </svg> ``` Unleashing the right icon for the right momentβ³ ### π§© Path Selector β Icon Power! ``` function path() { switch (type) { case ToastType.Error: return errorPath(); case ToastType.Info: return infoPath(); case ToastType.Warning: return warningPath(); case ToastType.Success: return successPath(); default: return successPath(); } } ``` ### π Dynamic Class Value: Automatic Styling! ``` <div role="alert" className={`alert ${classValue()} shadow-lg px-4 py-2 rounded-md`}> ``` ``` function classValue() { switch (type) { case ToastType.Error: return "alert-error"; case ToastType.Info: return "alert-info"; case ToastType.Warning: return "alert-warning"; case ToastType.Success: return "alert-success"; default: return "alert-success"; } } ``` ### π© Supercharged Toast Display Styles ``` function toastStyle() { switch (style) { case ToastStyle.Dash: return "alert-dash"; case ToastStyle.Soft: return "alert-soft"; case ToastStyle.Outline: return "alert-outline"; case ToastStyle.Regular: return ""; default: return ""; } } ``` Update toast-alert-jsx ``` <div role="alert" className={`alert ${classValue()} ${toastStyle} shadow-lg px-4 py-2 rounded-md`}> ``` ### π Implement Your Toast! like a boss ``` <Toast message={errorMessage} style={toastStyle} type={toastType} show={showToast} setShow={setShowToast} /> ``` Here are the sample screenshots from my project to let you know how it looks.   Now you can send out all the success, error, or info vibes you want! π₯ Cheers & Closing Thatβs it for this post! I hope you had some laughs, learned how to supercharge your own toast component, and got more confident with customizing ReactJS components. π» π Thank you so much for reading my post. More power to Hive Blockchain. More power to Hive community members! Cheers and high fives to YOU for following along. Have a good one! ππ --- ### π Final Note - I asked ChatGPT/AI to help optimize this post to make it more readable and viewer-friendly. - Here is the link where you can find both original content & improvements made by AI - https://www.perplexity.ai/search/d5224674-f110-48f1-8ffb-cb290e0f2eac --- ### π My Contributions to β¦οΈ Hive Ecosystem | Contribution | To | Hive | Ecosystem | |--------------|----|------|-----------| | Hive Witness Node | Hive API Node (in progress) | 3Speak Video Encoder Node Operator (highest number of nodes) | 3Speak Mobile App Developer | | 3Speak Podcast App Developer | 3Speak Shorts App Developer | 3Speak Support & Maintenance Team | [Distriator Developer](https://distriator.com/) | | [CheckinWithXYZ](https://checkinwith.xyz/) | [Hive Inbox](https://hive-inbox.the-hive-mobile.app/) | [HiFind](https://hifind.the-hive-mobile.app/) | [Hive Donate App](https://donate.the-hive-mobile.app/) | | Contributed to HiveAuth Mobile App | Ecency β 3Speak Integration | Ecency β InLeo Integration | Ecency β Actifit Integration | | [Hive Stats App](https://stats.the-hive-mobile.app/) | [Vote for Witness App](https://witness.the-hive-mobile.app/) | [HiveFlutterKit](https://hiveflutterkit.sagarkothari88.one/docs/intro) | [New 3Speak App](https://3speak.sagarkothari88.one/#/?tab=home) | --- ### π Support Back β€οΈ **Appreciate my work? Consider supporting @threespeak & @sagarkothari88!** β€οΈ | Vote | For | Witness | |------|-----|---------| | [](https://witness.the-hive-mobile.app/#/witnesses/@sagarkothari88) | [sagarkothari88](https://witness.the-hive-mobile.app/#/witnesses/@sagarkothari88) | @sagarkothari88 | | [](https://witness.the-hive-mobile.app/#/witnesses/@threespeak) | [threespeak](https://witness.the-hive-mobile.app/#/witnesses/@threespeak) | @threespeak | ---
π threespeakvoter, somecallmejake, knot, betoman, pishio, djblendah, ecoinstats, thecrazygm, accelerator, treasure.hoard, ryosai, thecrazygm.bank, bengy, aakom, a-bot, archon-gov, newhope, steembasicincome, sbi2, sbi3, cocaaladioxine, tikatarot, irisworld, anikys3reasure, sbi4, sbi-tokens, bilpcoinrecords, pokerarema, tub3r0, pof.archon, sbi5, sbi6, piensocrates, tekraze, noloafing, sbi7, sbi-booster, michael561, sbi8, abrockman, monsterrerentals, sbi9, letusbuyhive, josequintana, sbi10, emsenn0, everythingsmgirl, humoalex, oneray, gamer00, voxmortis, tatakai, keithtaylor, hive-lu, penguinpablo, cryptonized, ykretz, hive.friends, ambyr00, kiemis, funnyman, alphacore, hungrybear, balvinder294, jacuzzi, frieder, cubapl, ardina, misticogama, aafeng, daveks, joeyarnoldvn, artonmysleeve, crypticat, tht, sevatar, kolkamkwan, techcoderx, nastapak, nenio, kkingg, nongkamsailucky, nareebun, thaitruck, smartvote, liotes.voter, seckorama, gadrian, achim03, pixiepost, liotes, ifarmgirl, mateodm03, kaibagt, good-karma, esteemapp, esteem.app, ecency, ecency.stats, ecency.waves, mypathtofire, sayee, bhattg, blumela, alessandrawhite, arka1, ctpsb, argo8, jeanlucsr, sandymeyer, aslehansen, johnripper, janaliana, oadissin, bigtakosensei, saboin.ctp, ahlawat, julianhorack, nurfay, carlos13, lolz.byte, yesenia.romero, sunitahive, deepresearch, szukamnemo, techguard, cute-cactus, louis88, szejq, hivelife-pl, magic.byte, tecnotronics, soltecno, hive.pizza, funnel, grocko, fireguardian, ravenmus1c, adamada, nooblogger, vault.tokens, monica-ene, hivetrending, kingneptune, goliathus, rondonshneezy, dadspardan, huzzah, cooperclub, creodas, wizzitywillican, pizzabot, thecbp-hiver, john9inch, szmobacsi, rayius, jam728, onewolfe, banzafahra, h3m4n7, spiritverve, thedoc07, kqaosphreak, cherute, lothbrox, zeclipse, highfist, the-pockets, studio3141, marynn, dalekma, prosocialise, sabajfa, cindynancy, thoth442, masterfarmer, mita3, bhetea01, iaiman, quan45, life7clothing, jazzhero, sgbonus, bestofph, kendallron, pinas, bambukah, gloriaolar, thelogicaldude, andriko, slothlydoesit, slothbuzz, hivelist, blocktunes, agrante, hmvf, slothburn, bulliontool, nyxlabs,