Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 101 additions & 63 deletions suites-experimental/responsive-design/dist/app.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class AppRibbon extends LightDOMLitElement {
static properties = {
buttons: { type: Array },
visibleButtons: { type: Array },
_isOverflowOpen: { type: Boolean },
};

constructor() {
super();
this.buttons = ribbonButtons;
this.visibleButtons = this.buttons;
this._isOverflowOpen = false;
this._resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.contentBoxSize && entry.contentBoxSize[0])
Expand Down Expand Up @@ -41,7 +43,7 @@ class AppRibbon extends LightDOMLitElement {
this._resizeObserver.disconnect();
}

_updateVisibleButtons(width) {
async _updateVisibleButtons(width) {
const breakpoints = [
{ minWidth: 1134, buttons: 12 },
{ minWidth: 1069, buttons: 11 },
Expand All @@ -60,8 +62,34 @@ class AppRibbon extends LightDOMLitElement {
const breakpoint = breakpoints.find((bp) => width >= bp.minWidth);
const newButtonCount = breakpoint ? breakpoint.buttons : 2;

if (this.visibleButtons.length !== newButtonCount)
if (this.visibleButtons.length !== newButtonCount) {
const overflowTrigger = this.querySelector('[aria-controls="overflow-navigation"]');
const overflowPanel = this.querySelector("#overflow-navigation");
const activeElement = this.getRootNode().activeElement;
const visibleButtons = [...this.querySelectorAll("ribbon-button button")];
const focusedButtonIndex = visibleButtons.indexOf(activeElement);
const shouldRestoreFocus =
activeElement === overflowTrigger ||
overflowPanel?.contains(activeElement) ||
focusedButtonIndex >= newButtonCount;
this.visibleButtons = this.buttons.slice(0, newButtonCount);
this._isOverflowOpen = false;
if (shouldRestoreFocus) {
await this.updateComplete;
const nextOverflowTrigger = this.querySelector('[aria-controls="overflow-navigation"]');
const visibleButtons = this.querySelectorAll("ribbon-button button");
(nextOverflowTrigger ?? visibleButtons[visibleButtons.length - 1])?.focus();
}
}
}

async _toggleOverflow() {
const wasOpen = this._isOverflowOpen;
this._isOverflowOpen = !this._isOverflowOpen;
if (wasOpen) {
await this.updateComplete;
this.querySelector('[aria-controls="overflow-navigation"]')?.focus();
}
}

_getVisibleButtonsTemplate() {
Expand All @@ -73,16 +101,53 @@ class AppRibbon extends LightDOMLitElement {
);
}

_getOverflowTemplate() {
const hiddenButtons = this.buttons.slice(this.visibleButtons.length);
if (!hiddenButtons.length)
return null;

return html`
<div class="relative ml-auto">
<button
@click="${this._toggleOverflow}"
aria-controls="overflow-navigation"
aria-expanded="${this._isOverflowOpen}"
aria-label="More navigation options"
title="More navigation options"
class="mx-1 inline-flex items-center justify-center rounded-md bg-teal-700 px-2 py-1 text-white shadow-md ring-1 ring-inset ring-gray-300 hover:bg-teal-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-teal-700"
>
<svg aria-hidden="true" class="h-6 w-6" fill="currentColor" viewBox="0 0 24 24">
<circle cx="5" cy="12" r="1.5" />
<circle cx="12" cy="12" r="1.5" />
<circle cx="19" cy="12" r="1.5" />
</svg>
</button>
${when(
this._isOverflowOpen,
() => html`
<div id="overflow-navigation" class="min-w-40 absolute right-1 top-full z-20 mt-1 rounded-md bg-white p-1 shadow-lg ring-1 ring-gray-300">
${hiddenButtons.map(
(button) => html`
<button
@click="${this._toggleOverflow}"
class="focus-visible:outline-inset block w-full rounded px-3 py-2 text-left text-sm font-medium text-gray-800 hover:bg-teal-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-teal-700"
>
${button.text}
</button>
`
)}
</div>
`
)}
</div>
`;
}

render() {
return html`
<nav class="mt-1 flex items-center justify-between p-1">
<nav class="relative mt-1 flex items-center justify-between p-1">
<div class="flex flex-nowrap items-baseline overflow-x-hidden">${this._getVisibleButtonsTemplate()}</div>
<div class="3xl:hidden">
<button class="mx-1 inline-flex rounded-md bg-gray-200 px-2 py-1 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-300">
<!-- Heroicons are MIT licensed. See https://github.com/tailwindlabs/heroicons/blob/master/LICENSE -->
<span class="h-6 w-6" style="background: url(./public/images/icons-outline.webp); background-position: -96px 0px;"></span>
</button>
</div>
${this._getOverflowTemplate()}
</nav>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ChatInput extends LightDOMLitElement {
@keydown="${this._handleKeyDown}"
>
</textarea>
<button @click="${this._sendMessage}" class="ml-2 rounded-md bg-teal-500 px-3 py-1 text-white hover:bg-teal-600 focus:outline-none">Send</button>
<button @click="${this._sendMessage}" class="ml-2 rounded-md bg-teal-700 px-3 py-1 text-white hover:bg-teal-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-teal-700">Send</button>
</div>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ChatMessages extends LightDOMLitElement {
<li class="${message.user ? "justify-end" : "justify-start"} flex items-start">
${message.user
? html` <div class="flex items-center space-x-2">
<div class="text-pretty rounded-md bg-teal-600 px-3 py-2 text-xs text-white lg:text-base">
<div class="text-pretty rounded-md bg-teal-700 px-3 py-2 text-xs text-white lg:text-base">
${message.user} ${when(message.imageUrl, () => html`<img src="${message.imageUrl}" alt="${message.imageAlt}" class="mt-2 h-32 w-full rounded-md" />`)}
</div>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 flex-shrink-0 text-teal-600" fill="currentColor" viewBox="0 0 24 24">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ class ChatWindow extends LitElement {
_getOptionsTemplate() {
return html`
<div class="flex flex-1 flex-col items-center justify-center gap-4 self-center p-4">
<button id="resume-previous-chat-btn" @click="${this._resumePreviousChat}" class="w-full rounded-md bg-teal-600/50 px-4 py-2 text-white hover:bg-teal-600 focus:outline-none">Resume Previous Chat</button>
<button @click="${this._startNewChat}" class="w-full rounded-md bg-orange-500/50 px-4 py-2 text-white hover:bg-orange-500 focus:outline-none">Start a New Conversation</button>
<button
id="resume-previous-chat-btn"
@click="${this._resumePreviousChat}"
class="w-full rounded-md bg-teal-700 px-4 py-2 text-white hover:bg-teal-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-teal-700"
>
Resume Previous Chat
</button>
<button @click="${this._startNewChat}" class="w-full rounded-md bg-orange-700 px-4 py-2 text-white hover:bg-orange-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-orange-700">
Start a New Conversation
</button>
</div>
`;
}
Expand All @@ -83,9 +91,15 @@ class ChatWindow extends LitElement {
render() {
return html`
<div id="chat-window" class="${this._isExpanded ? "h-[440px]" : "h-12"} bottom-2 right-2 m-auto flex flex-col rounded-lg border-2 border-solid bg-gray-50 shadow-lg sm:sticky sm:w-full md:fixed md:w-1/3">
<div class="${this._isExpanded ? "rounded-t-lg" : "rounded-lg"} flex items-center justify-between bg-teal-600/75 px-4 py-2 text-white shadow-md">
<div class="${this._isExpanded ? "rounded-t-lg" : "rounded-lg"} flex items-center justify-between bg-teal-700 px-4 py-2 text-white shadow-md">
<p class="text-lg font-semibold">Chef AI</p>
<button id="expand-chat-btn" @click="${this._toggleExpand}" class="rounded-full bg-white px-2 py-1 text-sm text-teal-600/75 hover:bg-teal-100 focus:outline-none">${this._isExpanded ? "Collapse" : "Expand"}</button>
<button
id="expand-chat-btn"
@click="${this._toggleExpand}"
class="rounded-full bg-white px-2 py-1 text-sm text-teal-700 hover:bg-teal-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
${this._isExpanded ? "Collapse" : "Expand"}
</button>
</div>
${this._getContentTemplate()}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NewsletterSignup extends LightDOMLitElement {
<form class="mt-4">
<label for="email" class="sr-only">Enter your email</label>
<input id="email" type="email" placeholder="Enter your email" class="w-full rounded-md border border-gray-300 p-2" />
<button type="submit" class="mt-2 w-full rounded-md bg-orange-500 p-2 text-white hover:bg-orange-600">Subscribe</button>
<button type="submit" class="mt-2 w-full rounded-md bg-orange-700 p-2 text-white hover:bg-orange-800">Subscribe</button>
</form>
</div>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class RecipeCard extends LightDOMLitElement {
<!-- Tags in compact mode -->
<div class="mt-2 flex flex-wrap gap-1">${this.recipe.tags.map((tag) => html`<span class="${this._getPillColor(tag)} inline-block rounded-full border px-2 py-0.5 text-xs font-medium">${tag}</span> `)}</div>
</div>
<button class="show-more-btn flex-shrink-0 text-sm text-blue-500 hover:text-blue-700" @click="${this._toggleExpand}">${this.isExpanded ? "Less" : "More"}</button>
<button class="show-more-btn flex-shrink-0 text-sm text-blue-600 hover:text-blue-700" @click="${this._toggleExpand}">${this.isExpanded ? "Less" : "More"}</button>
</div>
${when(this.isExpanded, () => this._getExpandedTemplate())}
</div>
Expand All @@ -163,7 +163,7 @@ class RecipeCard extends LightDOMLitElement {
<div class="grid-rows-subgrid row-span-6 grid rounded-lg bg-gradient-to-br from-blue-50 to-green-50 text-left shadow-md">
<img src="${this.recipe.image}" alt="${this.recipe.text}" class="row-start-1 h-24 w-full rounded-t-lg object-cover" />
<h3 class="row-start-2 px-1 text-sm">${this.recipe.text}</h3>
<div class="max-w-40 row-start-3 flex justify-between px-2 pb-2 pt-0.5 text-xs text-gray-400">
<div class="max-w-40 row-start-3 flex justify-between px-2 pb-2 pt-0.5 text-xs text-gray-600">
<p>${this.recipe.time}</p>
|
<p>${this.recipe.calories}</p>
Expand All @@ -175,7 +175,7 @@ class RecipeCard extends LightDOMLitElement {
${this.recipe.tags.map((tag) => html`<span class="${this._getPillColor(tag)} inline-flex items-center rounded-full border p-1 text-xs font-medium">${tag}</span> `)}
</div>
${when(this.isExpanded, () => this._getExpandedTemplate())}
<button @click="${this._toggleExpand}" class="show-more-btn w-28 justify-self-end border-none bg-transparent p-1 text-sm text-blue-400 hover:text-blue-900">${this.isExpanded ? "Show Less" : "Show More..."}</button>
<button @click="${this._toggleExpand}" class="show-more-btn w-28 justify-self-end border-none bg-transparent p-1 text-sm text-blue-600 hover:text-blue-900">${this.isExpanded ? "Show Less" : "Show More..."}</button>
</div>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RibbonButton extends LightDOMLitElement {
}

render() {
const colorClass = this.variant === "primary" ? "bg-orange-400 hover:bg-orange-500" : "bg-teal-600 hover:bg-teal-800";
const colorClass = this.variant === "primary" ? "bg-orange-700 hover:bg-orange-800" : "bg-teal-700 hover:bg-teal-800";
return html`
<button class="${colorClass} mx-1 inline-flex items-center rounded-md px-2 py-1 text-sm font-semibold text-white shadow-md ring-1 ring-inset ring-gray-300">
<!-- Heroicons are MIT licensed. See https://github.com/tailwindlabs/heroicons/blob/master/LICENSE -->
Expand Down
Loading