- Podcasts
- CodingCat.dev Podcast
- Code with CodingCat.dev: Melting Minds through Melt UI!
Code with CodingCat.dev: Melting Minds through Melt UI!
CodingCat.dev Podcast
- June 30, 2024
- 1 h 30 min
- Season 1, episode 2
About this episodehttps://codingcat.dev/podcast/cwcc-1-2-meltui
https://codingcat.dev/podcast/cwcc-1-2-meltui
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Code with CodingCat.dev: Melting Minds through Melt UI!
It was awesome. Lots of snow. And yeah. I mean, it was super exciting for me because I've already like, I never saw it snowing, only when I was a really little kid and I don't remember it so. That is Oh my gosh. So it. Was oh, I bet that was fantastic. Miracle. It's very novel at first, like when you get to see it as an outsider and you don't have to live in it and like plow your driveway and.
Get your part. That's what I was saying like oh as a terrorist this is great but a bad like day-to-day it must suck especially because it's so hard to walk. I almost fell a couple of times. My girlfriend did fall on the first day. Oh no. Yeah. That I live in has this really cool thing called a snowmelt system downtown.
So it's the largest municipality owned snowmelt in the country. And so all of our sidewalks are heated by underground hot water. And they have a cool little like fireplace thing, right, that you can like collect around. There was a whole article in. Michigan. Holland being like the quintessential Christmas town because you can come here and shop and like, it's like being in a holiday movie.
Oh, that's awesome. So that's on, that's on 8th Street, right? Does that go to the whole like length of downtown? It does. Now it goes all of 8th St. I don't know if they've expanded it off to the side streets but for sure 8th St. Like the main downtown shopping area. I never go downtown though, it's too boutiquey for me except to eat. I go down there to.
Loafs. Irish. Food. I've just. So good there there was this cool little, I'll call it a Speakeasy, even though it's probably not a Speakeasy, but a lounge that's further down towards where they do the farmers market. It's pretty incredible. What's a Speakeasy? Do you know where? The oh, I know what you're talking about, the bar that opened, it's like right by Hopcat.
Yeah, by the movie. Theater right in that area. Cool. Sorry. A Speakeasy. Yeah. So I think this was during Prohibition era era that it happened, at least in the USI don't, I don't, I don't know if other countries have speakeasies. So like back then, if you were drinking illegally, essentially you would have to go into like a door and like you'd have to give a code or like you'd have to know the secret to get in right.
And most of the time these places are like kind of hidden gems, if you will. So like you go into a basement that you think's a basement, all of a sudden it's like this beautiful lounge or like you can sit in in chairs that are awesome and. But they do fancy cocktails there, right? They do like the smoking cocktail and. That looks like a thing out of a James Bond movie I like. It I've been there one time.
So I, I went to a Speakeasy once it's, it's, it actually burned down unfortunately, but it was hidden in this Mexican like restaurant. And the way you entered like it's very like, oh, this isn't fancy at all. There's nothing going on. You go into this hallway and there was a machine that you can buy like chips from.
And if you pick the Pringles one, all of a sudden you push the button and the door would go. And that is very. Magical. It was amazing. Like if I did someone legit try just to get some like oh what's going on I'm not entering there. That's crazy. Yeah. So I love those little places, even if it's not to drink if if it's just like a hidden like place to go, like get food or hang out. I just, I love them.
So Thomas, you've been, you've been building this thing. It's called, it was called something else before, right? What were you calling it, like radical or something? Yeah, Mel 2Y isn't. It is and it isn't the successor of Reddick spelled. But yeah, that was Reddick spelled before. It's kind of funny because we just talked to Pedro Duarte this morning and the podcast isn't out, but we just did that this morning.
So we were talking about and he he said Radix. Radix. How he pronounced it. OK, OK. Yeah, it's kind of one of those gift jif things, you know? Yeah, Radix. Radix. One of the. Creators was Irish. Is that what he said? Yeah, I think the Irish, yeah. Irish and that was how they pronounced it. And so it kind of stuck with him, I guess. I don't know, but I I thought that was cool 'cause you did radix radix felts after that and then that was kind of the predecessor to what is now melt, right? Exactly, exactly.
That's so fun. I would love to to talk to him someday. That must have been amazing. Did you when I was when I was at app right, you guys were still working on or I think they had released pink design system or? Pink Yeah, we still have. Yeah, we still have that. Did you help out build that or I don't remember?
Yes, kind of. It was mostly the website who mostly maintains Bing design since it's it's ACSS framework rather than component library or anything like that. It's a large sector. Our CSS architect, me and the other front end developers do sell modifications here and there, but it's mostly all here. Nice.
And so like with all of that experience that you've had, like what what makes Melt kind of different? And I'm going to show the website while we're chatting. Yeah, I think they're they're actually the opposite of on the component library Spectrum Pink design is like styles and that's it. Let's say styles that you apply to your markup. It doesn't provide you any markup, any JavaScript match the complete opposite.
It doesn't provide you any styles or markup. It provides you all with the functionality. So they really are opposites in that sense. That's really interesting to me. So I'm, I'm eager to like break this out. Do you have kind of an idea of something to build? I mean, yeah, we normally what what I do to showcase it. Sometimes I just build a builder from scratch just I'll I'd love to.
See build. A builder from scratch. It sounds very like Inception Y like high, high level of like a builder, but that's what they call their like components. And it's quintessentially like the headless library. Like you don't need to. It's not the styles you would add on something like Chad CN or just something on top to do the styles but and Chad CN's belt is actually using melt.
Exactly. Actually set CM svelt actually uses bits, which uses melt. It's. Basically so. Hunter help Hunter or Hunter byte helps out a ton with melt UI and then what he did. Melt doesn't ship out spelt component, it ship out just these little functions that in turn return some stars that you can sprinkle around your elements and stuff like that.
We call them builders because you're you normally are going to create build components out of them. And so that's what Hunter did. He created a library that has all the components build it out with Melt. The reason he did that is because for most people, it's much more ergonomic or it's what they're used to, right?
Using components directly. It can be a little less flexible on some on some ends, but most of the time you're not going to need any more than that. So yeah, is. That what? Bit is. Yeah, exactly. OK I had never I I saw that and I was thinking of bit dot dev which is a way to pull in components and I thought he was using bit dot dev but.
Bit is. A library hunter created. Exactly. Exactly. Yeah. OK, I'm gonna so I have been like I will. Clone. Your guys repository and I will just look through the source code like looking for ideas for my components and like how you're doing things and melt is like way beyond like anything I can understand because of these builders that I'm hoping we get to see soon we're gonna. We're gonna understand it right now as we. But for shed CN it's like he pulls in the library bits and I'm like that doesn't show me the root component, I can't see it.
So now I have to go find bits. Yeah, exactly. You could. But the fun thing about shed CN approach, the shed CN approach is that you can if you want to use bits. But if you like no I want more control than what bits gives me, you can just say OK let me copy the mail to I example just for this I'm not installing shed CN spelt, I'm copying it. With a SMI.
So I can I own the component. So if you want to, there are people that do that that you sets in and then switch it off with melt or anything like that. It would be cool to have the option maybe to have a cell I like with bits with melt. I'm going to pitch that idea if. You'll make this full screen so I can watch the builder in action.
Yeah. Let's do this. Are you guys ready? Yeah. All right, talking. How should we do it? So basically, basically the way that code with code and get works. So you're gonna tell me how like a person would use this and I'm gonna start typing and make something. Wait, so do you want me to show you how to use melt or how to create a builder from scratch?
Oh my gosh. Do a builder first and then whatever. Sounds like we want to do a builder. OK, so doing a builder normally with melt we already have all these helpers and stuff like that, so it can be a bit daunting, but you don't need anything any of that. In the end, builders are composed of attributes like HTML attributes that's best in the component and spelt actions to actually put in event listeners and have some control of the node.
Yeah, Mike, can I spell? Is it going to message? Is it going? To ask you about 5 or is it just automatically 5? It asks you as it asks you. I don't know, melt again? I mean, you could go OK, do a skeleton project. I always do that I think. TypeScript please. Please. Not ajs dot fan I'm gathering. SOT 5, it depends.
We can do SOT 5, we can do SOT 4. It's up to you in the end. Let's do SOT 5. We can show how how it would look like with rooms, but I will do it how we do it in. Because SOT 5 is progressive, so you can do it one way on one side and one way in another. Exactly. Exactly why are you using NPM Alex? You should use PNPM you said.
NPM I mean I. Said NPM for the create, I never said you for you to install stuff. Oh OK, NPM install there. Yes, I. I was in the same boat. I'm like. See. And this will just magically work. Because PNPM is the best. I'm going to do this too so we can actually check the the file system as we go here. Why don't you do?
Code. Period. Dash R and it'll open in the same window. What? What I didn't? Know. I didn't know that. Here yeah, code period. Dash R will open it in the same window. If I do, I never use CPS codes terminal. I use like. It won't do anything because you're already in that, but whatever folder you're in, it will open.
That's cool. Awesome. OK, so let's open up that dev server. Should I, should I run this guy? Yeah. You know you don't have to type run with PNPM. What does that mean? Oh, really? PNPM dev will work. You don't need PNPM run dev like NPM does. So you don't need like any of these. You don't have to put run.
Nope. Wow, you know what? It's better. Even you should. Be I'm just. Going to teach you all the tricks. The things I learned. You should use end foos Anthony Foos knee package. Have you heard of it? What is it? Google it, go to end Foo. Like end Foo like. That yeah, I mean it's I'm going to put in the chat so end Foo slash knee. I don't.
Think I've heard of this? Oh yeah, never heard of this. Oh, and Foo is the the person that works on V and exactly. Yeah. So basically it's analyzed, It automatically sees what package log you're using and just runs that. And if no package log is detected or anything like that, it's just going to ask, hey, which one do you want to use? That's cool for you.
Also, you don't have to think about what package manager. Can I brew install anyways? It's a global NPM. Stuff, I feel like that's for another day, yeah. For sure. So let's do, since melt doesn't isn't not a spout component, we can declare we can create a builder file first. OK, let's think do you let's go with a really simple builder. Really simple builder could be maybe a toggle. So on source and Lib we can create our own builders folder. Oh, builders.
Awesome. And there we can create maybe toggle TS. Uppercase. No lowercase. OK. Awesome. Now since it's a builder, normally what I'd call them I always prefix to move create. So I would do export function, create toggle, Awesome. No arguments. We don't need those for now. We're going to do the simplest thing.
So it's going to be a writable and it's going to start with files. We can handle props and parameters later. Cool. Now we need the toggle. There's a toggle element, right? We can call it trigger inside. So trigger. Is this just a? Yeah, exactly. And then it's going to be a derived because yeah, exactly.
Exactly. I think it does. Mel have a Twitter. No, I am the Mel Twitter. OK, I. Tried. I tried finding it earlier, I had no. I'm posting. That I don't know if I should create a Mel Twitter. Maybe it should. Well, what's? The logo. Oh, thank you. Yeah, we actually had a, a designer contribute to it. So it's a, it's a match between the logo that designer came up with and some tweaks I did.
But yeah. Nice. OK. Now we can just return like a data attribute. So we return an object and we're going to do data pressed. It needs to be in quotes since it's going to be data dash pressed. Like data dash pressed like that. Exactly, exactly. And then we're going to do you can just pass in pressed or what we can even do needs to be dollar pressed, sorry. So this is going to be an HTML attribute. Exactly why am I using this data attribute? So we can later style stuff?
That's basically it. But these are just the attributes. Can we rename trigger to trigger attributes? Sure. Thank you. So you can't use active is what I'm thinking, but that's the Tailwind class. Like you can't use the actual active state of something like ACSS. You can't. Yeah. I mean, I'm confused.
Since we're since we're not using all of them, I'm going to do this for a minute. With Tailwind, what we do, it's like we could use the data attribute selector that tailwind has. So data dash then I think it's square brackets pressed two. Points and then you. Would have to. You would have to get the data attribute, but you can't read the state of the element like acss state you could read. Yeah, no, I mean, no exactly.
Since it's just a JavaScript state, the only way we expose it to the HTML attribute, Yeah, we do have access to hover, focus active stuff like that, but that's it. And then what would have to do is just to sync we, we need to do an action. So what we're going to do is construction trigger action. Function.
I like to omit the data attribute whenever it's not present. So instead what we could do on line 7 is we could add a question mark on the end to do a turn of your operator. If it's present, we can do an empty string because that already. All right, if pressed, is present. Yeah, then an empty string, otherwise undefined.
That will make it so that data pressed is only present when pressed is true. Which is yeah, it's not showing in the markup. This is I like, I don't even know what I'm writing right now, so this is pretty exciting for me. I mean, it's we're almost done, so this is cool. So we're triggering an action, yeah. An action is just a function that accepts AHML element as the first parameter, so we can do node. Oh yeah, we can.
Do we can call it whatever you want, yeah. And it's an HML element. We can even restrict it if we want to, like a button or something like that. But at Melt we don't do this normally. Now we just need to add a event listener. So what we're doing to do is function handle click. If you're not restricting it to certain elements and you're type checking it, how are you handling accessibility for that?
So basically that what we do is we already put in some rows like for example. We expect this to work as a button, so we put row button the attribute the HTML row to be. OK, so you're doing you're adding roles rather than type checking it with HTML button element. Exactly. Maybe what we should do is just check if it's a button, then we don't add the role, otherwise we add it. There's there are some enhancements we can do there. Currently we don't, but it's something that that has crossed my mind.
Just keep in mind we only have 60 minutes left to create whatever we're. Doing let's speed around this, we can do press dot update. Sorry, where am I putting that? Yeah, exactly. There. OK. Press dot update then it's a function. So yeah, and Prev or P whatever you want and then you are going to return not P.
I'm going to return, not P. Exactly. And then outside of the function inside trigger action, you're going to do node dot add event listener, click on with quotes, sorry. And then it's going you're going to pass handle, click there, you can just pass it directly. Oh. OK, awesome. And then after that, you're going to return an object.
It's going to destroy. Is the name of the key. It's a function. And inside that function so open the the what what you call it are. You looking for like that? And. No, it's like the. Yeah, it destroys the callback function exactly. So you need to do after the parentheses. You need to do those not square brackets, but the other. Thing curly.
So it's really similar but actually this. Probably has a more technical term I just I'm terrible with. Isn't it a block? I mean in what's inside the curly? Braces. These are brackets, right? And some people call these curly brackets, so I don't know. Well, anyways. Some people call them. Curly boys all.
Right, let's keep going. So here you do node dot remove event listener and you pass in the same parameters as the add event listener. So click and then handle right? Yeah. And now on create toggle we can return both the trigger attributes and trigger action. We we are going to enhance this DX later but this is enough for now so. So we're just returning them down here. Yeah, you create an object and you return both the attributes and the action.
Awesome, now we're going to create. For some reason pressed is not typed even though it should be automatically typed Pressed. Well, you can just type as a boolean. Yeah. Up on the variable on line 4, do a boolean. Oh no, I think that's. A. That's a writable boolean, right? Yeah, that's already, that's already correct.
It's on five, on five, where exactly there you can put it as a that's. Weird, yeah. OK, we can save format, it's already formatted OK and then we can create on Lib a components folder and a toggle components. All right, Lib components, yeah, and A and I know I can do that in one toggle component. No, just toggle is fine too.
Or just toggle OK. Double dot spell. That spell, right? Awesome, let's open that beautiful script tag. We're doing length, yes, Yeah. And then let's import create toggle. It's it needs to be inside curly braces. Oh, nice. And now we're going to call create toggle on script tag on the script tag, and you're going to assign it to an object. So construction open curly braces, oops, exactly equals, and then just get those attributes and action out of there.
Cool. And then you're going to do use. Oh, it needs a dollar sign on the trigger attributes. I almost forgot because since it's a star. Right. Exactly. Let's ignore that that for now and then we're going to do use trigger action. Sorry here no. No as an. Use colon. Yeah, exactly. So space use column trigger action. That makes so much more sense.
Cool. And now inside we can just do click me or something like that. Or how are we can haggle? Exactly. We can do that too. Now let's put that inside our page and let's play around. We're still going to do some changes, but let's just have something to get to get started. Yes. Time we have left for for coding?
What's that? What's how many times do we have left for coding? We have, we have, yeah, one hour to get anything we want done. OK, that's fine. OK. So we're going to import our toggle, which is, yes, that's it. That's the one. Awesome. Let's see. Our results. There we go, cool, very fancy button that I'm sure everyone can see. Now if you if you if you inspect that button on the inspector, what a what HTML attributes do we have? Oh, nobody can see.
That let me bump that. Up too. OK, nine. Now click now. Click that button. What? Now we have data. Press. That's the magic of mount that turn. Now what we're going to. Do is? Can we just? Pause for one second just to walk back through this. So we have this toggle. Basically it's just a button. Then when we, we wrote this, we have some stores that came into play, right?
And this use trigger action if I can go in there. Basically what that's that's pulling out is this HTML attribute essentially at the end of the day, and we're saying if it's, if it's pressed, put something out there, if it's not, don't. But the the the trigger action itself is what causes that click handler to be used.
On style, let's create a style tag. And then we can just. Do button. And then? No, no, don't open the Curry braces yet. Do you like open square bracket? Bracket, Yeah. Yeah. And then do. Data pressed. You don't need the the. Qualitative. Oh, you don't. I don't think. So awesome, now you. Open the Curry braces and do filter invert. Oh, or you could do.
It with I mean we normally have some DX enhancements with melt, so instead of having trigger attributes and action be two separate things, you know what I mean? Sorry, sorry to interrupt you. I was just we got a question. This will work even in Svelt 5 right? Are you guys going to rewrite MELT UI with the new Svelt 5 features exactly? These will work with Svelt 5.
So to answer this question, let's do this by the way. This cat with a light in its mouth is hilarious, so that is incredible. OK, sorry. Yeah, don't worry. So. Let's go to let's create the rooms version. Then I what I would say is you copy that toggle TS file and do a toggle rooms or something like that, or toggle dot rooms.
No, it needs to be toggle dot spelt, right? That's felt dot TS. Wait, are we talking? About the OH. Yeah, it has to be. Dot spelt dot TS first exactly. OK, so toggle dot spelt dot TS exactly, yeah. This will work out of the. Bat, but it's bigger again. Yeah, so. When we set this up, we did. Choose spell 5 too.
So we're already running spell 5 currently. Yeah, yeah. So let's do let's. Change press to use the state room. So that's dollar state right? I always. Forget I only played with it like once really quickly. You don't. Have to do. You have to. Import that. No. Oh, all right. It's magical. I didn't know that.
Cool, and now? We can just call it trigger because slot 5 finally has something I really am eager to show, which is just spreadable event listener. So let's get that. Let's rename it to trigger. Is derived. Going to be an effect, no it. Doesn't need to be. None of it can just be a getter thing. So what we can?
Do. Actually, let's go copy that. Data. Breasts thing that copy line 7 no OK. OK, awesome. Now let's go to line 22. Remove these two. These two, No, don't copy it yet. All right. Sorry. Sorry. No worries. Now do get space trigger, open your parentheses exactly and now curly braces. Now what's going to do you're?
Just going to copy that your based offline I mean and get accessory must return a value, does it? Are we doing? Oh, it needs. To be returned object. Sorry. So you're going to. Return an object, and that's what's going to be inside of, yeah. Exactly and now. You're just going to return press without a dollar sign. Do I have to?
It needs two dots. You can also do onclick parentheses like that. Only one OK. Now. Parentheses. Oh, right, I'm just. Making. I'm sorry you're making. New JavaScript syntax and now you just do pressed equals, not pressed. That's right. Because the state rune is reactive. I mean, that gives you that fine grain reactivity. So wait, where's?
Oh. So. This is runes, huh? This is. Runes no and. Spreadable event listeners, otherwise we would need that action. Wow runes. Is awesome. But spreadable event listeners I just. And those are. Cooler now on. Toggle spout we can do we want to create toggle to create toggle rooms maybe. I'm actually glad you're going.
To create a separate component for this, like copy the current. Yeah, let's do. It OK. So toggle rooms. Or something like that. Cool now. We're going to get create toggle. We're going to switch it up. Let's do create toggle rooms. Where am I? Create toggle rooms from. Toggle. Got felt yeah oh, that got. Weird.
Creates a function. I thought I'd. Put it and I must have removed it. Cool, that's it. Let's try it out. So just. Before I try it out, just talking through this one more time so create. Toggle. Runes is a function that's returning this getter that returns a function of called trigger that is going to return our onclick and our HTML attribute. Yep, OK, that's it.
Cool, let's try it out. I'm not. Sure if it's working. Also I wasn't sure if it's worth it. Doesn't work. That is. Banana. And what we can do? Even we can also return our state. So let's say we wanted the text to change, we could do that with CSS, but let's do it with JavaScript. So going back to our toggle dot TS file, we're going to modify both of them.
It's going to be easy, OK. We're going to return. Pressed and that's it. Down here, yeah, just like that, yeah. And we're going to do the. Same on rooms, but in rooms we need to get her. So in toggle dot felt. I mean, sorry, toggle. Dot, why can't I get there? You're there. That's the right. That's one.
You could do this with classes. Too and we just do other things you can do but. Are you able? To do like so instead of like this whole return piece, can you do like get pressed and then like what's the word I'm looking for just like a function out at the end like. I don't know the like. Getter setter.
I'm not. Sure, I. Think you can like. Get press 2 dots and then do an arrow maybe? I don't think we can. There was something rich had a whole thread on using arrow functions because this isn't like automatically applied in an arrow function. So that's what. I was wondering, OK, good to know, but that's fine, I mean.
On the ambassador's channel, everything knows. This is just like new changes, new changes. Anymore. And what about this? And no, let's change this up. And now it's magical state just works with everything, you know, it's a lot. It's really fun. I like how they called out. Is it keystone JS? Is that the old one that used signals way back in the day in in the right up originally?
Have everyone. In here what gives? We try I. Mean if anyone needs sponsorship, oh I don't know, where am I supposed to put sponsorship in? Maybe he just used. Knockout. He was talking about it in one of his streams, but maybe he didn't create it. Well, he's too awesome. Yes. OK, it's. Got toggle spelt toggle.
Spelt. I'm here the other one. The component, the other. One toggle this one yes, So what we're. Going to do is we're going to get. Pressed. There, Yeah. And then we're. Going to do instead of the toggle text we have right now. Sorry, Curly. Braces. This pressed so. We're going to do an if statement. We can do that.
That's even. Better so if pressed we we can say toggled. This is. Yeah, OK. Otherwise. We're going to do toggle. And then it needs. To be a dollar sign to pressed I. Thank you. Cool. And on rules, we're going. To do the same thing. Anyone know why this is? Griping, by the way. Oh, it's it's. Saying that the type isn't known even though it isn't. I think maybe it's.
I have no idea why. OK, that's fine. I. Was just curious so toggle. Rooms, we're going to do the same thing. So. Wow, we already have it right. So yeah, toggle dot pressed. Toggle. Dot, is this a big or no? Can you just? Can you extract pressed and trigger from toggle there Unfortunately. Not unfortunately.
You could do, you could have some ways around it. You could set the variables. Underneath, I mean, but it's just more lines, yeah, Or like have. A encapsulated thing where instead of being pressed it's like pressed up value and the value is the gather function so press is another could do that. This is one of the challenges.
I'm thinking whenever melt goes to runes how I'm going to do that, but. Yeah, it. Works. But with stars will have the opposite. You can't do toggle dot dollar press. That just doesn't work. And you say hey that's fine, why would I need to do that? Let's say you're using two builders, 2 toggles inside the same component or something like that.
Now you can't do toggle one and toggle two and dot press. No, you need to do pressed one press 2. Toggle trigger. Attributes one trigger attributes 2. It's just I bit halish that's another reason why it's just so better to create components with the builders like instead of just using them raw like that, so. Everything we just walk through, everything gets just dropped my. Christmas tree so.
That's fun. Every year I'm like. Afraid that's going to happen to him? Oh no. So. Everything. We just walk through that was all. Just felt whether it was runes on spell 5 or not. Do you want to go pick it up? I mean my girlfriend. Is going just message her. She's like, oh crap. Yeah, if you need to do.
Anything feel free. No, no worries. I'm I'm taking a look at my cat to see if she's going to do anything worse and she's ready. For. Trooper. Sorry. So, so we walked through 12/4 and 12/5 versions of creating basically just kind of do we call them builders, just generic. OK, so. Builders. But we haven't even touched melt yet, right We? Haven't.
We can't. We can't try and create a brand new builder with Melt. So where does? Yeah, where does melt kind of fit into what's happening next? So basically with melt it's it takes this better that I just showed, but it takes it to the extreme. If you. Want we can we can show a little bit like go to toggle on GitHub, maybe on melts GitHub so we can see a little bit of source code and they can't go over it.
So it's on. Source. Zoom in a lot. Oh, there's no. Guitaco Extension, OH. They have their own now so I don't use it anymore. What? Yeah, once you're. Once you're in there, they just have their own. Doesn't it still refresh? When you click them. No. It's it's barred by React now. Yeah, that's why it's.
So slow. But anyways, so you can. You can go to. You can go to. Lib. I didn't say anything Lib. Builders. I mean. Seriously, if you go to a huge PR it just gets so slow. They didn't optimize this at all. I know it's possible to optimize it for free act, but anyways, now you go to create. And now our.
Toggle just got a whole lot bigger. Let's see how many how many lines of code that is. Not too much. It's not too bad. So you. See that I have a root element. It's the trigger element. We just name it root because it's the only one we have. We also have our pressed state over there. It's just using.
So melt has something. Let's go line by line. Sorry, that's OK. 1st we have our. Imports. Let's ignore our imports now. Then we have our defaults. These are the defaults for the props that we have. In this case we are just choosing the defaults for default pressed and disabled melt builders normally have. A default pressed.
Prop like for every state we have a default prop, but we also have. You can also pass in your own writable. I'm going to show that in a bit. So with defaults, we just get the props, we override the defaults if a prop has been passed, then for each of those props, we convert them to writables, to stars.
Why? Well, we return these options, and then after the creation of the builder, you can still override these options, these props, if you want, programmatically, because sometimes you need to do that. Then on line 2728, that's a much more complex version of Prest, instead of it just being a writable, we have this thing that's called an overwritable. That's a custom star we created in mouth. What does it do basically?
Remember, I said, we have the. Default press prop. We have two others. We can have a pressed prop. You can see that I even have it there with default dot pressed. And we also have an on pressed change prop. This is again confusing I can see, but basically let's say that instead of you just. Choosing.
A default value or just how can I say this? Just receiving the store after creation. Let's say you wanted to use an external store for whatever reason you can you just you can pass that in. So that's what we are doing on line 27. In case that we are passing in a store, we use that, otherwise we create a brand new one and. What?
Overridable does is it gets that store, but it also accepts an on change function. Whenever pressed is changed, we we call in a callback and that callback can change whatever the the new state was going to be. So let's say click toggle pressed was going to be true. But inside my on press change function I return another value that's going to be the actual value of press. This is useful whenever you want to override certain behaviors within melt.
Sorry so. So here you could say instead of on, off, it's something else. Is that what you're saying? No. Not. Exactly. It's just I'm overriding just the value of pressed. So let's say I wanted to click toggle, but let's say I already clicked five times. I had an internal con in my component and say after five times it's not toggling anymore. Like stop.
Like too much. Exactly. So that's what I could do on my on change function then handle toggle is just a function. It's pretty self-explanatory I would say. It's just checking if it's disabled or not before updating. And we have the main part of mouth, the builder helper. It's just a wrapper, a function that accepts a name and some stars the.
Derived function. Return. It's just a wrapper so we know what to use and an action. The cool thing? Is here, we don't have root attributes and root action. We just have the root star and you can even do use root directly. The builder function kind of just wraps it all up for us. Then we just return everything, return the elements, we return our pressed state, and we return the options if you go a little bit down. But I, I.
That automatically deletes that event listeners, but also. Add multi event. Listener does something else it whenever you click it, it also emits a custom event which is M for melt dash click if you prevent default that event nothing happens like the handle toggle just won't run. We normally expose those custom events for any event that we listen to. This is all.
We all have an example of this in the docs if you want to see. Yeah, because I'm. Like a little little confused on that one. Where's that at? Let's go to mount. The website OK. Get started. Or. Yeah. And now we can go to select. There's a lot of builders and now let's go to example components change options with keyboard.
Exactly. So normally, yeah, use your arrow keys now. See how that works? This is custom behavior because if you do that on the component above you, that won't happen. How do we do? This yeah, you can click, click and now keyboard it's just going to open it again. So so the way we had to do this is to override the the keyboard event listener, right?
Yeah, see that's. A lot of code. So we have, we have oops, you can go up a little bit. Says use M as. Or on M key down as the start. Yeah, exactly. This is the custom event we do when when we're doing preventive fault there, we're canceling the default builder behavior. We can also cancel the original event, the original key down because I don't want page scroll to happen and then we just do our custom logic there.
So this is a really underrated feature of mouth in my opinion. It allows you to normally when even when using headless libraries you don't completely own it, you still like. If I don't want a certain behavior, I need to rely on the props that a library has given me. And if there's no props for what I want, then I'm stuck.
Which is not necessarily bad, Design constraints can be good, but Melt allows you to to go a little bit above and beyond if you want. You don't need to. Hey, I'm just going to implement everything myself. Screw melt. I'm uninstalling. You can you can do this. How do either? Of those. Ways affect accessibility?
Like is one more accessible than the other? Because one seems to be the default behaviour I mean. Yeah, you need to be concerned. It depends on what you're doing it. It's not necessarily. This isn't necessarily an accessible if I'm not mistaken. But yeah, you would need to check if the behavior overriding ruins accessible accessibility or not.
It's. Definitely a consideration. To have whenever. Doing this like melt does help you create accessible stuff, but it doesn't prevent you. To me it. Seems. Like the way that this one is functioning with being able to hit the down arrow and go down the list inside of the select box is more accessible, but I just don't know.
Yeah. It's, it's nuance. There's no right thing sometimes. Like they are at the end of the day, the accessibility guidelines we have, there are standards that have been kind of agreed upon. But then again, as you said, there are some stuff that just hasn't been agreed upon yet. There hasn't been some discussion or the discussion hasn't reached like a formal point yet.
Because detail summary. Is not an accordion. Yeah, I mean. Yeah, that's true. Actually they are having like a prop that allows you to like only click one and only be one be open. I think this is not already has it. The standard union has it. Yeah. But yeah, the day of summary is kind of more like the collapsible component we have there, which is a coordinate that's alone. Cool.
So if just another time check we have 34 minutes left, should we actually use melt to create something? We can't do that. OK, we can't do it. Where do we get? Started with melt, so we should probably. Get clone. Oh, wait. OK. Yeah, I thought you. Were going to say like let's create a new builder on melt but.
I I mean we can. I mean that, but that. Would be. Maybe that would be too much. You can use. The same. Repo. You've already got started, that is true. That is. True, let's do. That let's do that. I'm just kind of thinking. Of a person like hey this melt thing sounds cool I want to get started using in my project how yeah let me. Just check.
One thing, that's the toggle. Go to toggle and melt OK. I want to see. If we have. ACSS example for that most of them only have Tailwind. We can install Tailwind. So go to the top. We can do a spelt add. Yeah. Go to. Yeah, let's do that then. I like Tailwind. I think you do too. Yeah, we love Tailwind. Awesome.
Let's. Do spelt add tailwind then it's NPX or PNPMDLXI. Have no idea PNPX. Spelt dash add Spelt dash everything together. No Spelt dash add. No spaces together. Together, Together and then. Face. Tailwind CSS at latest. Isn't that spelt at? The latest no. Oh, awesome. OK, I always. Throw it on there as like AI never know what it's going to grab.
Yeah, I don't even see a. Tailwind in here, so I don't think that's worse. Yeah, maybe remove the. Latest. I always go back to my. Like uncoding cat if you just do tailwind one command. Oh. That's it. It's missing. The latest just remove. The latest, I swear. I always put latest in there but I do but I think it's on. Speltad, I don't think it's on Tailwind. There you go.
Weird whole, I think it's. BMPX speltad at latest and then tailwind. Cool. Let's see. I think we're close. Cool. What do we? Want to throw in a a test just to make sure? Yeah, let's. Let's do that. Oops. I think we're running. Yeah, yeah, yeah. Maybe reset the? Server I mean. Try to restart it though.
Yeah, like B. And our toggle. Looks nothing like a button because of tailwinds. Obnoxious. Reset. Oh oh. That is. Kind of a really bad that's exaggerated. I don't think I've seen that on a button before because I always end up using skeleton right away. I say. I have been using Uno cssa lot and it lets you customize the reset.
I love it. But anyways. We can also go ahead and install Melt, I guess, OK. Let's go to the melt. Website, OK. Go to the. Yeah, you can copy. That command. Uno is also by. Ant food right it. Is. It is, yeah. Uno is amazing. I want to. I wanted to convert the docks to use it but too much of A hassle. And it's going.
And now inside the. Object we can do elements. Trigger I mean. Sorry, column. So elements column, is it column? Yeah, exactly. Curly braces trigger. No, it's root actually. Sorry. Yeah, I should name change that name. Benefits of not having released one point O yet. Cool. And now outside elements, but still inside that object, we're going to do states.
So state. Equals. Here. Yeah, comma. No, not. Comma quotes, quotes, quotes on. Cool. I think that's it. Now let's try. Oh, because you named it. On and off. So it's a data state attribute on and off, right? Exactly. Exactly. So there are some API inconsistencies in mouth due to the sheer volume of filters we have and it's still not being one point O yet.
Basically one. Thing that is curious about it is you see though that use melt action that is not a normal action, that's something that gets converted. So go to the docs real quick, I'm going to show you something. So go to toggle Yeah now. Do you see on the sidebar on the bottom there's a preprocessor switch.
Click on it. Have a helper. So basically. This is what? Melt syntax normally looks like, but to avoid having to write all of this, which can get a little bit annoying when you get with more complexing builders, we ship a preprocessor that gets that use MELT syntax and converts it to what you're seeing right there. So that's.
What that use? Melt is we could just some people ask me why not use just an action from the get go and apply the attributes within the action and the reason is SSR that's it. It's just. So you're saying? This part just remove that. Yeah, like, no, like. Let's say why? Why don't we just do use root? And have and.
Make the action pass in the attributes. Gotcha. The reason? Is because of. SSR actions don't only work with JavaScript, they only work when the browser is actually added and it makes sense. So yeah, there are some libraries that have a similar. Yeah. One thing that I always want to show, like MELT is inspired by other similar approaches to name I feel like Zag JS.
UI. Does do they have one single action at the root, but they also have attributes sprinkled in. So it's the most similar. And Zach, Zach is pretty similar, but they don't have they don't have a scout version. Maybe I had one more. Question about the code to Alex, if you could put that back up the data attribute on the style, is that documented somewhere?
OK. Really down. Yeah, more down roots. There it is. You see data state right? And this? What are you using under the hood for this For this? Manual typing. Oh, you're doing? Manual. Typing there's a a thing. Yeah, we want. To change. It to be automatic, so is it spelled? No, no, no. Because spelled, if I'm not mistaken, is only for spelled components and since we don't use felt components, it's worthless for us what we what Hunter was investigating using Typedoc.
There are some things that work with like type TS doc and then just automatically generate an API reference because they create a Jason and you just use that. I really want that astrodocks do. Something. Oh yeah, I saw a. Typedoc in there Starlight does that. I think I. Think Starlight does, but that's I could be wrong so. Basically, one thing I wanted to to share about Poofmouth is with rooms comes an important decision making. I haven't brought this out in the public, but. You are now.
I am now. So basically there are two. Approaches I have. Discussed this with 102. There are two approaches, so one is the straightforward 1, but really hard one is just. Let's convert the whole code base to Rooms. It's not hard because Rooms is hard. The opposite, Rooms would make the code base quite simpler. I would say it's hard because it's rewriting the entire MELT code base and the other approach would. Be.
To. To. Have an. Adapter logic. So we kind of keep the current logic and then we create an adapter for runes. That could be. Cool, it's something I'm experimenting with. I also. Heard comments like. Hey, why don't you change spelt stars to use nano stars? Nano stars is a library which has a really similar syntax to spelt stars, but it's framework agnostic.
Hunter. Is yeah, he is helping quite a lot, not only with melt. Hunter is kind of a madman. He does so many awesome projects with Smout and just does it all at once. And besides like work, he also is a working a working man. But he has recently done the melt date picker and calendar and stuff like that, which was insane. I know he's quite busy too with making the bits docs just be better in general, like redesigning, writing some more stuff.
Well, cool, happily put it on the screen. Awesome. Let. Me. This is not a screen prepared to be on a podcast. Let me close stuff. I should. There's a Mac App that remember, like present mode that's just closes anything that's not relevant. Yeah, I. Forgot which. One it is, but anyways I don't need that I'm should add a ray cast.
Extension for it. Yeah, that's true. I love Ray cast I'm. I'm going to. That's where Pedro is working now and that's what we talked to Pedro this morning about is Ray cast and building extensions. So that's what you can. Build. Is a Mac present mode extension. Yeah, if it doesn't exist already. Oh, can you all see my?
Screen. Oh, just one. Can see Alex's. Screen. There we go. OK, wait. Can you now see my screen? Yep, awesome. So let me close. So you may have to. Enlarge and zoom quite a bit though, yeah, no worries. So first let me open. What we're playing around with. So I've been playing around with the the notion of agnostic melt.
This is something I call agnostic tree. I've got one one of the builders. That we. Have that's not super complex but it's a bit and I tried to make it work with different frameworks even with vanilla JS. This is using not melt but it's using something that I created using the same logic of mouth and it just works. This is spelt with stars.
I'm going to show the code later. It's a spelt with rooms. It just works. This is solid and I'll prove it to you. This is not just spelt with solid iconic mitosis. From builder IO. Oh yeah, but. Mitosis, what it does right it gets the components and then compiles it this I created what I did is everything is created with an agnostic car so I have the builder here this is the tree builder it's really similar to what we've seen in melt let me zoom in and you see I. Think is that's.
Good. Yeah, that's cool. So we have stuff that's similar, like atoms are the equivalent to writables and stuff like that. Computed objects is the. It's derived and. Then you have make. Elements which is the we have possible dependencies, I'm sorry. This is all nano. This is like. Not all nano like atom is nano stores. This is something I created.
Make elements is also something I created. Gotcha. I created a lot of helpers. I'm a helper guy. So each one. Can have each element can have dependencies, attributes and event listeners. And with this after I created all this I just do the same as in melt. I export it elements, States and helpers and I use it.
So if we go to tree dot. You see that it's? Pretty similar to what we have. We had and in melt. The difference is I don't do create tree and call. It a day. I have to wrap it with an adapter, so I created a svelt adapter for it. Each framework has its own adapter, but I only have to create an adapter once. I don't have to create it for every builder, which means I'm not like redoing a lot of logic, it's just one adapter. This is really similar to Zag JS approach, but the difference is Zag JS doesn't work with svelt, it doesn't work with vanilla JS, It only works with rect, view and solid. This way it could work with potentially everything. If it works with vanilla, it should work with everything I assume.
But we know. That's not. The case sometimes but I will experiment and then I just use it like I would normally like tree it's a it's a star and an action. The way I use it tree and then I can do use tree dot action I guess. So yeah, that's it. And so you don't have your. Helper here, your preprocessor built into that I don't.
But I. Could I could have it? And I even have rooms working too with the same code base. So three dot helpers, 3 dot elements. This is a sub component that also has everything in there. I have the react version working which is just. Oops, I don't like. Looking at React Cool. Use components having to use hooks.
React was the most painful to to create, even though I of course it was. Can you? Yeah, but spell. Fan folks, Yeah. But The thing is, I'm more of a rectator than spelled fan. I'm joking. React is not bad everyone, I just like to kid I've I've I think I've coded more than react in my life than in spell it unfortunately.
I did kind of like a. HTML attribute. Thingy. So what I do is I do data V from vanilla tree and then so that looks like you. Damn. I need to do. Would you know what I should do? I should do this? Vanilla OH. Ice cream. Yes, OK, so vanilla. It could be like this, but yeah it does look like field dev. But when I do these.
HTML attributes and I call it my builders with the vanilla JS adapter it just scans the Dom the not the Dom. But the document and. Done. And then it's. Adds the attributes and stuff like that and the event listeners to it given the HTML attributes. I do this inside here too. I can even add props to the the icon.
So normally in spout, if you wanted to add a specific prop to an element, if you would do. All in the store. It's. Actually a function in. This case, no. Yeah, it's a function and pass in some arguments and here we kind of do the same, but we do it with HML attributes. It does look a bit ugly on the Dom, yeah. So the props actually get added on the Dom, yeah. But it.
I'm using Astro to. Like just be able to write everything all at once. Gotcha. So yeah, with. If. This would be. It would be a have to rewrite them out too, but it's a it's a different approach that I'm willing to try, especially because of agnostic stuff, but I still need to try like one. I don't want to compromise on spouts D DX in order to achieve this.
So one possible approach that me and Hunter discussed was like do the two approaches at the same time, which is kind of insane. So in one end go and write stuff in rooms, but at the same time try the agnostic approach, see which one fares better. Or maybe what I thought is like do the agnostic as a side project, if it works, eventually becomes the main project.
I don't know. It's something I'm willing to try. I have a. Question. Going back a little bit, we were talking about spreading event listeners. Did we show that we did? We did with the rooms. Version SO. It just. Automatically like spreads them exactly it. Does like in the end like If I should I can show it even here so. Here.
On my. Item element I declare my listener, so there's key down, there's click, there's focus and if I go to tree dot rooms. And on tree. Dot inner I can even do like console dot log. Tree. Tree dot elements dot ITA I think. That's it. Yeah, just so I can. See. What's what's going on there when I do that object?
Oh. What do you mean? So it's it's documented like just very vaguely in the spelt documentation. But if you do a comment inside of a scout component, so you're in a scout component now go outside of your markup somewhere, make a comment. I think you might have to be out. I don't know if you can do it inside.
The script tag. Do it like between the script and the start of your markup. This. Like an. HTML comment There you go at component. And then now you can just write. Markdown and that will auto document your component for intellisense and then when you hover over it when you're using it you can see that anything that you write there.
So now go to your tree inner. Component wherever that's used and hover over it. So. I was wondering. What I was getting at is that the spelt documentation, I wish that there was a way for me to write everything about a component for it to take that doc and then parse that into like actual like the documentation page somehow, yeah.
Oh, that would be cool. I won't. I mean, maybe you could, you could just. I think you would you would need. To analyze, have a analyzer, a code analyzer, right? I guess like a build step. Is that? AST. Like something that will converse it. And look for. The AT component and then grab that and yeah, but in the in the end of the day, that's. That's kind of time in the mix, but. That I would.
Love it if that would happen, but this is what I'm using for my documentation and my components right now. OK, this is very. Really cool. This is really cool. I didn't know about this. OK, this is awesome. It's another thing like sometimes about components have all these amazing features and I can't use them in Mouth because Mouth is not a component library, it's a builder library, right?
Yeah. So you. Don't. Actually have the components but like country can use this, yeah. But so I can complain. Because I can just do, yeah. Hunger can. What I can do is. Just like and you could use it in your. Documentation examples too, like somehow. Yeah, one thing I want to. Do with mouth is like mouth's really advanced.
It's a complex library. It's the qualms of it. Being flexible. And The thing is sometimes a lot of people get lost in how do I create components with these and it's not a good sign because it's the main thing you're going to be doing. Like how do I make props reactive and etcetera. So I want to have some componentization examples. But The thing is, as I show like, things are going to change a lot if I go and do like this agnostic thing, the docs are going to be rewritten in Astro, which would mean I'm going to rewrite a lot of ways of how I write docs. And then I can just do this API reference, this automatic stuff from scratch, which would be awesome. So that's the reason why I'm delaying a little bit the D docs enhancement, because I'm not sure which way we're going to go yet.
I'm more focused on like making all the API stable, making tests pass, fixing bugs so we can ship one point O and then go for whatever is going to be Mel's future. So what are you using? For testing, we're using VI. Test with testing library. That's mostly it. We also have some accessibility testers we have with.
Like if I go to, let's go to the mount. Yeah, I'm, I'm. Using V chest and testing library, but I was going to add in playwright for more. They have an experimental component testing, but it doesn't work very well. Yeah, I've tried. I've tried that. With reddix file. Because I had some issues with testing library.
But yeah, it. Had some it's not documented very well yet because it's still in in beta. And yeah, I had some issues too, but just that's good. Vitas is really good. Library. Yeah, one thing I really. Wanted to try is storybook with the new visual testing capability. So Storybook would be awesome because I could show how component is done, let people play around with drops, and if there's testing, like if I can integrate it with VI tests, I can. Well that already covers testing and it would also cover visual testing because sometimes I'm writing something out, I'm trying to debug a test, but I can't see anything. So I have to copy test my code, put it on the spout environment and play around with it.
I completely. Agree. I haven't gotten storybook testing working yet. And I know for visual testing I think you need to have like a chromatic key. So you need to be like bought into chromatic for storybook. Oh, I mean I, I. Know I received like I I've joined a wait list and I received an e-mail like hey, you've been invited and that's it. I don't I haven't tried it out though yet. Oh cool.
If maybe that will go well. I do have storybook integrated so I have visual stuff, but my testing is not inside of storybook yet. I see. I see. But yeah, I want to we. Do have star book we just barely use it like if you see. There's some more. Like stories, we have some, but yeah, we haven't used it extensively.
I wish I had another person to do the testing and stuff for me, because my hardest thing is like when you're building a component library, what do you test? I can test that it functions, it presses the button, it clicks, that happens. The links go to the links. But yeah, what? Else is there to. Test like what am I testing?
Let's see this. Is the accord and this is toggle. Group iPad. Let's see what. We're passing for toggle group. Accessibility. Violations. Tabs does keyboard navigation selection, a lot of stuff. There's a lot of stuff. Accessibility stuff too, like I'm really lacking on. I need to step up my game with that, but time, man. Yeah, for sure.
One thing I do. Normally is like whenever there's a new issue that's hey, something's not working in a component, I fix it and the same PRI tried to create a test for it so doesn't happen again. That's a good way, I say to to. That's exactly. What happened to me? But the bad. I think this is this can only work if like your projects is used by many people.
Thank God. I think you got so excited. Because of being able to talk about this stuff, that's why Exactly how you feel better. I love it, yeah. It's my medicine now. After this podcast, I'm just going to lie. And die from. Sickness. Well, as always. The GitHub repo is up from what we worked on and the links are out and you can check us every week at Code with Coding cat dot dev where we bring on someone and we code for approximately 90 minutes and we create something by the end of it, which we did today. We have two buttons.
Thanks for your work. Thank you. Thank. You doing some awesome stuff. Really appreciate it. Yeah, Thank you. I love. I love. Melt's contributors and people using it are are really, really thankful, and it's something I'm really grateful for, yes. All right. Thank you so much. I usually have a post roll. Oh, OK, OK.
We don't so. We let's. Do away, maybe you know. Maybe we should come up with something like on the podcast I listen to, they always come up with something. Bye. Yeah. Maybe we need? To I. Always say. Later and later nerve. What syntax? Says is later. I think they like. Creatively peace, they say. Peace.
