Thinking on ways to solve a MORPHING BUTTON
Skills:
UI Design80%Prompt Craft60%Advanced Prompting60%Prompt Systems Engineering60%Tool Use & Function Calling60%
Key Takeaways
The video demonstrates how to create a morphing button using the View Transitions API, with a focus on progressively enhancing a multi-state button to morph between states. The API is used in conjunction with HTML, CSS, and JavaScript to create a seamless transition between the button's states.
Full Transcript
welcome to another episode of kui challenges where I build interfaces my way then I challenge you to do it your way because with our creative minds combined we will find multiple ways to solve these interfaces and expand the diversity of our skills and in today's GUI challenge we're building a morphing button one of those kinds of buttons where like you submit a payment or you say hey start crunching this image or do this AI work or whatever it is and you hit a button it goes into another state it transitions to another state and then eventually goes back to the state that it was in in the beginning so we have a multi-state button that needs to kind of morph and adapt to these different amount of contents that it has it's a perfect use case for view Transitions and so that's what I used today can't wait to show you let's dig into the code [Music] background about view transitions let's just assume you've never heard about them at all this is a great starting place this is an article by Jake Archibald covers all of the different things that you can do with this API called view Transitions and it was previously called shared element transitions now what this allows you to do is tell the browser that you're about to change something on the page so why don't you look at the state of all the elements and then I'm going to change the page and when my function is done go ahead and uh seamlessly transition from where that element was or many elements were to where these new elements are and I've showed a couple in the GUI Snippets that how you can use this to do things like animate display none you can animate text replace it has so many super powers and so today I'm using it to apply some Styles and transitions to a button so here we have our button that doesn't have the view transition work applied also looks like it's well it's missing a whole bunch of styles we'll get into that soon but I wanted to give you a little bit of background on view transitions give you a reference to a nice resource but let's dive into how I achieved this in this button today so the first thing that I'm just going to show you is that I've set up a SVG element here with style display none and I've put a symbol inside that has all the different spinner path information and I give it in a nice name and that becomes really handy because then I can use that with this use tag and I can just say hey use icon dot spinner and so in my JavaScript where I'm kind of injecting new contents when you hit this button you can see that that spinner gets set up here and that's where it's coming from so I like the used technique for SVG I think it makes it kind of nice but it's up to you so anyway that was where the icon is coming from and stuff like that and then just here I have a lonely demo I have a lonely button with an idea of demo and it starts out as do some hard work so that's the HTML that's sort of supporting this I've got some Styles in here so first off I'm loading in open props in the normal eyes that's why I have like a dark background here right now so that's you automatically get the light in the dark theme but let's import the buttons and get a nice style button so now we get a nice light and dark style button here kind of cool it has a nice little clicky effect and we have some support styles that just put this demo in the center probably even get rid of the Gap don't need the Gap there's not more than one element in this demo so we'll just Crush that and the next thing we're going to add is this morphing button concept well let's do that in a minute let's look at what the JavaScript is doing I have three states which is Idle State we can see it's right here and that do some uh hard work phase uh in the next one it moves into sending which has the spinner and the working text and here we'll just click that button and see it there it is working and then we have the done state which you know looks really happy and it probably could add another spinning successful check mark uh animation right here if you wanted to I just need another icon no big deal so what happens though is when we click the button we're going to set the state to sending which is going to add the spinner in the working State we set a timeout so this is just like a really cheap State machine we set a timeout for 4 000 seconds or four thousand milliseconds which is going to be four seconds anyway it sets a new state and then eventually after six seconds sets the state back to idle so this entire animation takes six seconds it has four seconds of working two seconds of done and then it goes back to its regular State now you can kind of already see that there's a Crossfade Happening Here you see how it like it crossfades between the different states that is because we're using the API for view transitions down here and we're also doing it as an additive bonus so while this demo currently only works in Chrome it will eventually work in any browser that supports view transitions but what's nice is we're only calling this view transition function and doing this morphing if the browser can do it otherwise it's just going to change States immediately and it's no big deal but what I want to come back to is that by using this API at all you get crossfades between your animations which or between your States and I think that's really nice as a default so that's why we're getting crossfades is I'm calling start view transition and so then the other way that this works is just so that we break it down sort of again conceptually at a high level view transitions in this single page application model where I'm using JavaScript to invoke them you need to tell the browser I'm about to do some work and that way it can look at the current state of your button in this case and then after you do some work like in this case set the inner HTML to something new your function will complete and the browser will take another screenshot of that element and then allow you to morph between the two so um that is the extent of using the API and the rest of it kind of comes down to some CSS so let's dig into the CSS that kind of makes that happen and we'll undo our uh comment here that's commenting out the morphing button Styles go look at what's happening inside of here and um even take some out let's take out this and let's see what happens when we just give it a view transition name of by button so again we've got our button we have our Styles we have our JavaScript that's going to call that function and you can see it morphing between our different states now there's going to be some awkward morphing happening look at how it's sort of like ghosted out the one of the past and it also was kind of large in a lot of ways or it's oversized um and that's because the browser is really optimized for maintaining the aspect ratio of something in these Transitions and that's essentially what these Styles here do they say I see you browser trying to keep the aspect ratio on this buy button element but I don't want that I'm kind of opting into a squish effect and so here let me save these Styles and you can see watch as the animation happens this time and you can see some squishing happening in fact let's just open up the dev tools go down to animations and slow the animation down and also move this under yeah here we go so we've got a 10 animation going we're going to really see the squishing happening there nice did you see that we'll go back to kind of fast and another one is it squishes so normally it's not good to squish your text um I would almost always advise against that but in this particular case where we have this morphing button it's kind of super duper convenient for us and the effect happens so fast um I don't think there's a whole lot of you know visual loss happening there so here let's just see this again so it goes so I'm squishing and that's because again we're forcing the height and the width of the old image and the new image to be combined together to be squished into the space of the element as it is naturally in the Dom so when we reference view transition old by button we're looking at the image of the old button and when we reference view transition new by button we're referencing the new um image that's coming in so the browser when it does these view transitions it's working with bitmaps it's working with like textured images and that's important to note because that's how we achieved our effect is by kind of squishing it into space and now we get a nice little nothing button right kind of cool and we can add as many new States in here as we want like let's go from sending to um registering yes because that's probably going to happen here registering registering and then in here we'll say you're going to go from done to registering well here I think we should actually do registering first at two okay so now we should have a whole new state coming in here let's see working registering and we're done let's even make registering have a whole bunch of text registering your new thingy all right more working yes registering your new thingy and it's done so what's especially neat here is the browser uses actual layout of the new state and then the actual layout of the Old State and it's all contextual so if we were in a right to left language if we had you know translation happening here all of that stuff would still apply just as much as it would have before because the browser is very naive here and we've given very light amount of instructions about what to do so that is how I made a morphing button I really just gave it a name and this is important with view transitions if you want to customize the way that the transition is happening Remember by default it's just a Crossfade I give it a name and then I can reference the old ends the new so there's other demos where I've shared where I make the old one scale out and Fade Out and the new one gets to slide in there's all sorts of opportunity to handle and customize how the old one goes out and the new one comes in it's really really fun really powerful API and I love that this just sort of Simply upgrades to a morphed animation whereas by default it'll just happen instantly and I don't think there's a whole lot of experience lost there the content is still there the screen readers still report all the changes that are happening to this button which is really nice the only thing we're adding is a visual affordance of some morphing I hope you liked this GUI Challenge and I'll see on the next one y'all enjoy view transitions [Music]
Original Description
In today's GUI Challenge, @AdamArgyleInk progressively enhances a multi-state button to morph between states using the super rad View Transitions api.
Chapters:
0:00 - Introduction
0:49 - View Transitions review
1:35 - HTML
2:34 - Support CSS
3:04 - JS
4:42 - startViewTransition()
5:25 - Morph CSS
6:25 - Animation Inspection
7:55 - More button states
8:41 - Effect recap
9:54 - Outro
Resources:
Try a demo → https://goo.gle/43xmXi0
Get the source → https://goo.gle/44IILrH
View Transitions → https://goo.gle/44D8yBu
More about View Transitions on Adam's blog → https://goo.gle/41MzE89
Watch more GUI Challenges → https://goo.gle/GUIchallenges
Subscribe to Google Chrome Developers → https://goo.gle/ChromeDevs
#GUIchallenges
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Chrome for Developers · Chrome for Developers · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
Web Directions Code 2015 round up
Chrome for Developers
Maintainable Code - HTTP203
Chrome for Developers
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
The Guardian - Supercharged
Chrome for Developers
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
The Future of JavaScript - HTTP203
Chrome for Developers
Data Binding 101 -- Polycasts #28
Chrome for Developers
The Guardian part 2 - Supercharged
Chrome for Developers
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
Binding to Objects -- Polycasts #30
Chrome for Developers
Player FM - Supercharged
Chrome for Developers
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
Jake Beats Wikipedia - HTTP203
Chrome for Developers
Supercharged Observers! -- Polycasts #32
Chrome for Developers
Jai's Web blog - Supercharged
Chrome for Developers
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
Google+ Performance Improvement Comparison
Chrome for Developers
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
Binding to Arrays -- Polycasts #35
Chrome for Developers
HTTP2 - HTTP203
Chrome for Developers
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
Call For Submissions - Supercharged
Chrome for Developers
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
Highlights from Chrome Dev Summit 2015
Chrome for Developers
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers
More on: UI Design
View skill →Related Reads
📰
📰
📰
📰
Inside the Wayfair Frontend SDE-2 Interview: A Complete Breakdown
Medium · Programming
I Spent Two Years Maintaining a React SPA. HTMX Rebuilt It in a Week
Medium · Programming
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Medium · Programming
Browser-Based PDF Editing with Vue 3 and pdf-lib
Dev.to · sunshey
Chapters (11)
Introduction
0:49
View Transitions review
1:35
HTML
2:34
Support CSS
3:04
JS
4:42
startViewTransition()
5:25
Morph CSS
6:25
Animation Inspection
7:55
More button states
8:41
Effect recap
9:54
Outro
🎓
Tutor Explanation
DeepCamp AI