Request from Product & Customers: Add Chat to Chalk
Whaaaat?? 🤔
Okay this one’s going to be a challenge!
So how does one take an existing full width layout, with multiple interactive elements, push it aside to make room for a chat column about one fifth of the width, and secondly, has to be outside of the application container?
And then how does this work without distorting the main focus element - the live video display?
The challenge was enough to make me sweat heavily and think thoughts like “this is the end of my career”, “I truly am an imposter”. 😬 😬 But alas — problem solving: break the problem down into bits, deal with the bits one at a time.
Because I no longer have access to the repo, the code, I’m recalling these steps and the code from memory.
First bit; the click event on the chat button, nestled within several components, had to be captured and sent up to the top application level. Then elements assigned to variables, and classes toggled.
// shadowRoot is Lit's way of capturing elements
const chatButton = shadowRoot.querySelector(".container__application button");
const appContainer = shadowRoot.querySelector(".container__application");
const expandChat = shadowRoot.querySelector(".col__chat");
chatButton.addEventListener("click", () => {
appContainer.classList.toggle("chat");
expandChat.classList.toggle("slide-left");
})
Secondly I added a new div to this application level and assigned a display: grid; to the new container and assigned two columns, one collapsed.
.container__application {
display: grid;
grid-template-columns: 1fr 0;
}
Next the class to toggle to create the chat column:
/* hurrah for CSS nesting! */
.container__application {
&.chat {
grid-template-columns: 1fr 325px;
}
}
The new HTML was set up similar to this:
<div class="container__application">
<div class="content__body">
<h1>Application</h1>
<button>Open chat</button>
</div>
<div class="col__chat">
<div>Chat column content</div>
</div>
</div>
Then for the nice user experience, a slide-in animation from left to right:
.slide-left {
animation:
slide-left 0.5s
cubic-bezier(0.250, 0.460, 0.450, 0.940)
both;
}
@keyframes slide-left {
0% {
transform: translateX(0);
}
100% {
transform: translateX(-100px);
}
}
The video capture below is an earlier one that I managed to save before leaving the company. Sorry to say it is sub-par at best. I created it to point to overall functionality. You’ll see that the send button is off-screen at the beginning and the whole video is a little slow. When I was laid-off I didn’t have a lot of time to think about all the things like this recording redo (I’ll have a separate post soon on the big team layoff). I also lost access to the application as it’s behind the company firewall, or, you must have an account to access Chalk.
Every single elemement seen in this application I coded in place, everything.