Skip to content

Commit

Permalink
Merge pull request #12 from adobe/new-features-plp
Browse files Browse the repository at this point in the history
New features PLP
  • Loading branch information
kathleentynan committed Feb 12, 2024
2 parents 0f59516 + 2e2bce8 commit f407d5e
Show file tree
Hide file tree
Showing 151 changed files with 13,140 additions and 6,442 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ const storeDetails = {
displaySearchBox: true,
displayOutOfStock: true,
allowAllProducts: false,
currentCategoryUrlPath?: string;
categoryName: '', // name of category to display
displaySearchBox: false, // display search box
displayOutOfStock: '', // "1" will return from php escapeJs and boolean is returned if called from data-service-graphql
displayMode: '', // "" for search || "PAGE" for category search
locale: '', //add locale for translations
priceSlider: false, //enable slider for price - EXPERIMENTAL, default is false
imageCarousel: false, //enable multiple image carousel - EXPERIMENTAL, default is false
listview: false; //add listview as an option - EXPERIMENTAL, default is false
optimizeImages: true, // optimize images with Fastly
imageBaseWidth: 200,
resolveCartId?: resolveCartId // Luma specific addToCart method. Enabled with the extension
refreshCart?: refreshCart // Luma specific addToCart method. Enabled with the extension
addToCart?: (sku, options, quantity)=>{} // custom add to cart callback function. Called on addToCart action
},
context: {
customerGroup: 'CUSTOMER_GROUP_CODE',
Expand Down Expand Up @@ -185,6 +199,8 @@ You can add your own variables to [tokens.css](./src/styles/tokens.css). Further

### Have tailwind only apply to the nested widget

Now default behavior:

Follow the [tailwind nesting documentation](https://tailwindcss.com/docs/using-with-preprocessors#nesting). Your [postcss.config](./postcss.config.js) will look like this:

```
Expand Down
16 changes: 15 additions & 1 deletion dev-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,28 @@
displaySearchBox: true, // display search box
displayOutOfStock: true,
allowAllProducts: false,
// currentCategoryUrlPath?: '', // current category url path
// categoryName: '', // name of category to display
// displaySearchBox: false, // display search box
// displayOutOfStock: '', // "1" will return from php escapeJs and boolean is returned if called from data-service-graphql
// displayMode: '', // "" for search || "PAGE" for category search
// locale: '', //add locale for translations
// priceSlider: false, //enable slider for price - EXPERIMENTAL, default is false
// imageCarousel: false, //enable multiple image carousel - EXPERIMENTAL, default is false
// listview: false; //add listview as an option - EXPERIMENTAL, default is false
// optimizeImages: true, // optimize images with Fastly
// imageBaseWidth: 200,
// resolveCartId?: resolveCartId, // Luma specific addToCart method. Enabled with the extension
// refreshCart?: refreshCart, // Luma specific addToCart method. Enabled with the extension
// addToCart?: (sku, options, quantity)=>{} // custom add to cart callback function. Called on addToCart action
},
context: {
customerGroup: '',
},
apiKey: '',
environmentType: '',
// searchQuery: 'search_query', // Optional: providing searchQuery will override 'q' query param
// route: ({ sku }) => {
// route: ({ sku, urlKey }) => {
// const storeConfig = JSON.parse(
// document
// .querySelector("meta[name='store-config']")
Expand Down
10,270 changes: 6,055 additions & 4,215 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@adobe/storefront-product-listing-page",
"version": "1.0.2",
"version": "1.1.0",
"license": "Apache-2.0",
"typings": "./dist/@types/index.d.ts",
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('tailwindcss/nesting'),
require('autoprefixer'),
require('tailwindcss'),
require('cssnano'),
],
};
1 change: 1 addition & 0 deletions src/Intro.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ import { h } from "preact";
# Product Listing Widget

This storybook outlines the different components used to create the Storefront Product Listing Widget

8 changes: 8 additions & 0 deletions src/api/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ProductView = `
__typename
sku
name
inStock
url
urlKey
images {
Expand Down Expand Up @@ -86,6 +87,7 @@ const ProductView = `
title
... on ProductViewOptionValueSwatch {
id
inStock
type
value
}
Expand Down Expand Up @@ -122,6 +124,12 @@ const Product = `
product {
__typename
sku
description {
html
}
short_description{
html
}
name
canonical_url
small_image {
Expand Down
16 changes: 16 additions & 0 deletions src/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const graphqlEndpoint = `${window.origin}/graphql`;

async function getGraphQL(query = '', variables = {}, store = '') {
const response = await fetch(graphqlEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Store: store },
body: JSON.stringify({
query,
variables,
}),
}).then((res) => res.json());

return response;
}

export { getGraphQL };
33 changes: 33 additions & 0 deletions src/api/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const CREATE_EMPTY_CART = `
mutation createEmptyCart($input: createEmptyCartInput) {
createEmptyCart(input: $input)
}
`;

const ADD_TO_CART = `
mutation addProductsToCart(
$cartId: String!
$cartItems: [CartItemInput!]!
) {
addProductsToCart(
cartId: $cartId
cartItems: $cartItems
) {
cart {
items {
product {
name
sku
}
quantity
}
}
user_errors {
code
message
}
}
}
`;

export { ADD_TO_CART, CREATE_EMPTY_CART };
20 changes: 19 additions & 1 deletion src/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ const REFINE_PRODUCT_QUERY = `
$sku: String!
) {
refineProduct(
optionIds: $optionIds
optionIds: $optionIds
sku: $sku
) {
__typename
id
sku
name
inStock
url
urlKey
images {
Expand Down Expand Up @@ -176,8 +177,25 @@ const REFINE_PRODUCT_QUERY = `
}
`;

const GET_CUSTOMER_CART = `
query customerCart {
customerCart {
id
items {
id
product {
name
sku
}
quantity
}
}
}
`;

export {
ATTRIBUTE_METADATA_QUERY,
GET_CUSTOMER_CART,
PRODUCT_SEARCH_QUERY,
QUICK_SEARCH_QUERY,
REFINE_PRODUCT_QUERY,
Expand Down
2 changes: 1 addition & 1 deletion src/api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getProductSearch = async ({

variables.filter.push(defaultFilters); //add default visibility filter

const displayInStockOnly = displayOutOfStock !== '1';
const displayInStockOnly = displayOutOfStock != '1'; // '!=' is intentional for conversion

const inStockFilter = {
attribute: 'inStock',
Expand Down
30 changes: 30 additions & 0 deletions src/components/AddToCartButton/AddToCartButton.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
import { action } from '@storybook/addon-actions';
import { AddToCartButton } from '../AddToCartButton';

<Meta
title="PLP/AddToCartButton"
component={AddToCartButton}
parameters={{
layout: 'centered',
}}
/>

export const Template = (args) => <AddToCartButton {...args} />;

# AddToCartButton

```
import { AddToCartButton } from '../AddToCartButton'
```

<Canvas>
<Story
name="AddToCartButton"
args={{
onClick: action('onClick'),
}}
>
{Template.bind({})}
</Story>
</Canvas>
28 changes: 28 additions & 0 deletions src/components/AddToCartButton/AddToCartButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2024 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it.
*/

import { render } from '@testing-library/preact';

import { AddToCartButton } from './AddToCartButton';

describe('WidgetSDK - UIKit/AddToCartButton', () => {
test('renders', () => {
const { container } = render(
<AddToCartButton
onClick={() => {
return;
}}
/>
);

const elem = container.querySelector('.ds-sdk-add-to-cart-button');

expect(!!elem).toEqual(true);
});
});
34 changes: 34 additions & 0 deletions src/components/AddToCartButton/AddToCartButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2024 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it.
*/

import { FunctionComponent } from 'preact';

import CartIcon from '../../icons/cart.svg';

export interface AddToCartButtonProps {
onClick: (e: any) => any;
}
export const AddToCartButton: FunctionComponent<AddToCartButtonProps> = ({
onClick,
}: AddToCartButtonProps) => {
return (
<div className="ds-sdk-add-to-cart-button">
<button
className="flex items-center justify-center text-white text-sm rounded-full h-[32px] w-full p-sm"
style={{
'background-color': `#464646`,
}}
onClick={onClick}
>
<CartIcon className="w-[24px] pr-4" />
Add To Cart
</button>
</div>
);
};
11 changes: 11 additions & 0 deletions src/components/AddToCartButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Copyright 2024 Adobe
All Rights Reserved.
NOTICE: Adobe permits you to use, modify, and distribute this file in
accordance with the terms of the Adobe license agreement accompanying
it.
*/

export * from './AddToCartButton';
export { AddToCartButton as default } from './AddToCartButton';
Loading

0 comments on commit f407d5e

Please sign in to comment.