Skip to content

Commit

Permalink
Bug 1839965 - Create default shopping card. r=shopping-reviewers,flue…
Browse files Browse the repository at this point in the history
…nt-reviewers,flod,kpatenio,jhirsch

Differential Revision: https://phabricator.services.mozilla.com/D182250

UltraBlame original commit: 0ad42d8961e77a5704876c869b2c501869810f61
  • Loading branch information
marco-c committed Jul 16, 2023
1 parent 8daa3cf commit 685c14f
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 31 deletions.
17 changes: 0 additions & 17 deletions browser/components/shopping/content/highlights.css

This file was deleted.

21 changes: 10 additions & 11 deletions browser/components/shopping/content/highlights.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { MozLitElement } from "chrome://global/content/lit-utils.mjs";

// eslint-disable-next-line import/no-unassigned-import
import "chrome://browser/content/shopping/highlight-item.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "chrome://browser/content/shopping/shopping-card.mjs";

const { ShoppingUtils } = ChromeUtils.importESModule(
"chrome://browser/content/shopping/ShoppingUtils.sys.mjs"
Expand Down Expand Up @@ -108,17 +110,14 @@ class ReviewHighlights extends MozLitElement {
highlightsTemplate.push(highlightEl);
}
return html`
<link
rel="stylesheet"
href="chrome://browser/content/shopping/highlights.css"
/>
<div id="review-highlights-wrapper">
<h2
id="review-highlights-heading"
data-l10n-id="shopping-highlights-heading"
></h2>
<dl id="review-highlights-list">${highlightsTemplate}</dl>
</div>
<shopping-card
data-l10n-id="shopping-highlights-label"
data-l10n-attrs="label"
>
<div slot="content" id="review-highlights-wrapper">
<dl id="review-highlights-list">${highlightsTemplate}</dl>
</div>
</shopping-card>
`;
}
}
Expand Down
80 changes: 80 additions & 0 deletions browser/components/shopping/content/shopping-card.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@import url("chrome://global/skin/in-content/common.css");

:host {
display: block;
width: 288px;
border: 1px solid var(--in-content-box-border-color);
border-radius: 8px;
background-color: var(--in-content-page-background);
box-shadow: var(--shadow-10);
}

.shopping-card {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
padding: 12px;
}

button {
margin: 0;
}

#shopping-details {
width: 100%;
}

#label-wrapper {
display: flex;
justify-content: space-between;
align-self: stretch;
}

:host([type="accordion"]) #label-wrapper {
cursor: pointer;
}

#header {
color: var(--in-content-text-color);
font-size: 1em;
font-weight: 600;
}

#footer {
display: flex;
align-items: center;
justify-content: center;
padding: 8px 0;
border-top: 1px solid var(--in-content-box-border-color);
}

details > summary {
list-style: none;
}

details > summary:focus-visible {
outline: var(--in-content-focus-outline);
}

.chevron-icon {
background-image: url("chrome://global/skin/icons/arrow-down.svg");
background-position: center;
background-repeat: no-repeat;
-moz-context-properties: fill;
fill: currentColor;
width: 24px;
height: 24px;
min-width: 24px;
min-height: 24px;
padding: 0;
flex-shrink: 0;
}

details[open] .chevron-icon {
background-image: url("chrome://global/skin/icons/arrow-up.svg");
}
93 changes: 93 additions & 0 deletions browser/components/shopping/content/shopping-card.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { html, ifDefined } from "chrome://global/content/vendor/lit.all.mjs";
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";

window.MozXULElement.insertFTLIfNeeded("preview/shopping.ftl");

/**
* A card container to be used in the shopping sidebar. There are three card types.
* The default type where no type attribute is required and the card will have no extra functionality.
* The "accordion" type will initially not show any content. The card will contain a arrow to expand the
* card so all of the content is visible.
*
* @property {string} label - The label text that will be used for the card header
* @property {string} type - (optional) The type of card. No type specified
* will be the default card. The other available type is "accordion".
*/
class ShoppingCard extends MozLitElement {
static properties = {
label: { type: String },
type: { type: String },
};

static get queries() {
return {
detailsEl: "#shopping-details",
};
}

labelTemplate() {
if (this.label) {
if (this.type === "accordion") {
return html`
<div id="label-wrapper">
<span id="header">${this.label}</span>
<button
tabindex="-1"
class="icon chevron-icon ghost-button"
@click=${this.handleChevronButtonClick}
></button>
</div>
`;
}
return html`
<div id="label-wrapper">
<span id="header">${this.label}</span><slot name="rating"></slot>
</div>
`;
}
return "";
}

cardTemplate() {
if (this.type === "accordion") {
return html`
<details id="shopping-details">
<summary>${this.labelTemplate()}</summary>
<div id="content"><slot name="content"></slot></div>
</details>
`;
}
return html`
${this.labelTemplate()}
<div id="content" aria-describedby="content">
<slot name="content"></slot>
</div>
`;
}

handleChevronButtonClick() {
this.detailsEl.open = !this.detailsEl.open;
}

render() {
return html`
<link
rel="stylesheet"
href="chrome://browser/content/shopping/shopping-card.css"
/>
<article
class="shopping-card"
aria-labelledby="header"
aria-label=${ifDefined(this.label)}
>
${this.cardTemplate()}
</article>
`;
}
}
customElements.define("shopping-card", ShoppingCard);
3 changes: 2 additions & 1 deletion browser/components/shopping/content/shopping.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ shopping-page-title = { -brand-product-name } Shopping
## Strings for the product review snippets card

shopping-highlights-heading = Snippets from recent reviews
shopping-highlights-label =
.label = Snippets from recent reviews
shopping-highlight-price = Price
shopping-highlight-quality = Quality
Expand Down
2 changes: 1 addition & 1 deletion browser/components/shopping/content/shopping.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</head>
<body>
<div id="content">
<review-highlights hidden />
<review-highlights hidden></review-highlights>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion browser/components/shopping/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ browser.jar:
content/browser/shopping/shopping.css (content/shopping.css)
content/browser/shopping/shopping.mjs (content/shopping.mjs)
content/browser/shopping/ShoppingUtils.sys.mjs (content/ShoppingUtils.sys.mjs)
content/browser/shopping/highlights.css (content/highlights.css)
content/browser/shopping/highlights.mjs (content/highlights.mjs)
content/browser/shopping/highlight-item.css (content/highlight-item.css)
content/browser/shopping/highlight-item.mjs (content/highlight-item.mjs)
content/browser/shopping/shopping-card.css (content/shopping-card.css)
content/browser/shopping/shopping-card.mjs (content/shopping-card.mjs)
65 changes: 65 additions & 0 deletions browser/components/storybook/stories/shopping-card.stories.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// eslint-disable-next-line import/no-unresolved
import { html, ifDefined } from "lit.all.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "browser/components/shopping/content/shopping-card.mjs";

// window.MozXULElement.insertFTLIfNeeded("preview/shopping.ftl");

export default {
title: "Domain-specific UI Widgets/Shopping/Shopping Card",
component: "shopping-card",
parameters: {
status: "in-development",
fluent: `
shopping-card-label =
.label = This the label
shopping-show-more-button = Show more
shopping-show-less-button = Show less
`,
},
};

const Template = ({ l10nId, rating, content, type }) => html`
<main style="max-width: 400px">
<shopping-card
type=${ifDefined(type)}
data-l10n-id=${ifDefined(l10nId)}
data-l10n-attrs="label"
>
<div slot="rating">
${rating ? html`<moz-five-star rating="${rating}" />` : ""}
</div>
<div slot="content">${ifDefined(content)}</div>
</shopping-card>
</main>
`;

export const DefaultCard = Template.bind({});
DefaultCard.args = {
l10nId: "shopping-card-label",
content: "This is the content",
};

export const CardWithRating = Template.bind({});
CardWithRating.args = {
...DefaultCard.args,
rating: 3,
};

export const CardOnlyContent = Template.bind({});
CardOnlyContent.args = {
content: "This card only contains content",
};

export const CardTypeAccordion = Template.bind({});
CardTypeAccordion.args = {
...DefaultCard.args,
content: `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nunc velit turpis, mollis a ultricies vitae, accumsan ut augue.
In a eros ac dolor hendrerit varius et at mauris.`,
type: "accordion",
};

0 comments on commit 685c14f

Please sign in to comment.