Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
196 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Product Summary Name | ||
|
||
## Description | ||
|
||
`ProductSummarySKUSelector` is a VTEX Component that renders the product's name. | ||
This Component can be imported and used by any VTEX App. | ||
|
||
:loudspeaker: **Disclaimer:** Don't fork this project; use, contribute, or open issue with your feature request. | ||
|
||
## Table of Contents | ||
- [Usage](#usage) | ||
- [Blocks API](#blocks-api) | ||
- [Configuration](#configuration) | ||
- [Styles API](#styles-api) | ||
|
||
## Usage | ||
|
||
You should follow the usage instruction in the main [README](https://github.com/vtex-apps/product-summary/blob/master/README.md#usage). | ||
|
||
Then, add `product-summary-sku-selector` block into your app theme, as we do in our [Product Summary app](https://github.com/vtex-apps/product-summary/blob/master/store/blocks.json). | ||
|
||
### Blocks API | ||
|
||
This component has an interface that describes which rules must be implemented by a block when you want to use the `ProductSummarySKUSelector`. | ||
|
||
```json | ||
"product-summary-sku-selector": { | ||
"component": "ProductSummarySKUSelector" | ||
} | ||
``` | ||
|
||
### Configuration | ||
|
||
You can't configure anything of this component through Site Etor at the moment, only using the block of it. | ||
|
||
You can find all options available in [Store Components SKU Selector app](https://github.com/vtex-apps/store-components/blob/master/docs/SKUSelector.md). | ||
|
||
### Styles API | ||
|
||
This app provides some CSS classes as an API for style customization. | ||
|
||
To use this CSS API, you must add the `styles` builder and create an app styling CSS file. | ||
|
||
1. Add the `styles` builder to your `manifest.json`: | ||
|
||
```json | ||
"builders": { | ||
"styles": "1.x" | ||
} | ||
``` | ||
|
||
2. Create a file called `vtex.product-summary.css` inside the `styles/css` folder. Add your custom styles: | ||
|
||
```css | ||
.SKUSelectorContainer { | ||
margin-top: 10px; | ||
} | ||
``` | ||
|
||
#### CSS namespaces | ||
|
||
Below, we describe the namespaces that are defined in the menu. | ||
|
||
| Token name | Description | Component Source | | ||
| ------------ | ---------------------------------------------------- | ------------------------------------ | | ||
| `SKUSelectorContainer` | The main container of SKUSelector | [index](/react/components/ProductSummarySKUSelector/index.js) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ProductSummarySKUSelector from './components/ProductSummarySKUSelector' | ||
|
||
export default ProductSummarySKUSelector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React, { createContext } from 'react' | ||
|
||
const ProductContext = createContext({}) | ||
|
||
export const ProductContextProvider = ({ product, query, ...rest }) => { | ||
return <ProductContext.Provider value={{ product, query }} {...rest} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
import { head } from 'ramda' | ||
import { SKUSelector } from 'vtex.store-components' | ||
import productSummary from '../../productSummary.css' | ||
import { | ||
useProductSummaryDispatch, | ||
useProductSummary, | ||
} from 'vtex.product-summary-context/ProductSummaryContext' | ||
|
||
function ProductSummarySKUSelector(props) { | ||
const stopBubblingUp = e => { | ||
e.preventDefault() | ||
e.stopPropagation() | ||
} | ||
const dispatch = useProductSummaryDispatch() | ||
const { product } = useProductSummary() | ||
|
||
const handleSKUSelected = skuId => { | ||
const selectedItem = | ||
product.items && product.items.find(item => item.itemId === skuId) | ||
|
||
const sku = { | ||
...selectedItem, | ||
image: head(selectedItem.images), | ||
seller: head(selectedItem.sellers), | ||
} | ||
|
||
const newProduct = { | ||
...product, | ||
selectedItem, | ||
sku, | ||
} | ||
|
||
dispatch({ | ||
type: 'SET_PRODUCT', | ||
args: { product: newProduct }, | ||
}) | ||
|
||
dispatch({ | ||
type: 'SET_PRODUCT_QUERY', | ||
args: { query: `skuId=${skuId}` }, | ||
}) | ||
} | ||
|
||
return ( | ||
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions | ||
<div | ||
className={productSummary.SKUSelectorContainer} | ||
onClick={stopBubblingUp} | ||
> | ||
<SKUSelector onSKUSelected={handleSKUSelected} {...props} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default ProductSummarySKUSelector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ | |
.priceContainer { | ||
} | ||
|
||
.SKUSelectorContainer {} | ||
|
||
.attachmentListContainer { | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters