Skip to content

Commit

Permalink
Merge pull request #84 from ACCT-global/feature/code-reference-minicart
Browse files Browse the repository at this point in the history
Feature/code reference minicart
  • Loading branch information
kaisermann authored Nov 12, 2020
2 parents 6d00fef + 10451c6 commit d9db624
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- New component called 'product-reference', where is possible to pull an identifier product information.

## [0.25.0] - 2020-10-27

### Added
Expand Down
12 changes: 11 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ Therefore, in order to customize the `product-list` configuration, you can simpl
| `product-list-content-mobile` | Creates the product list layout for mobile devices. |
| `message` | Renders a message text about the product availability. |
| `product-name` | Renders the product names. |
| `product-reference` | Renders the product reference information. |
| `price` | Renders the product prices. |
| `unit-price` | Renders the price for each product unit added to the cart. |
| `product-list-image` | Renders the product images. |
Expand Down Expand Up @@ -298,6 +299,13 @@ Therefore, in order to customize the `product-list` configuration, you can simpl
| ---------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `width` | `number` | Product image width (in pixels). | `96` |

### `product-reference` props

| Prop name | Type | Description | Default value |
| :------------------: | :---------: | :---------------------------------: | :-------------: |
| `identifierLabel` | `string` | Text label to be displayed to the left of the product reference value. | `undefined` |
| `identifierOption` | `enum` | Desired product reference data i.e. product identifier to be displayed. Possible options are: `ProductId`, `ProductSkuItemId`, `ProductReferenceId`, and `ProductSkuReferenceId`. | `ProductReferenceId` |

### `remove-button` props

| Prop name | Type | Description | Default value |
Expand Down Expand Up @@ -326,6 +334,9 @@ In order to apply CSS customizations in this and other blocks, follow the instru
| `productPriceCurrency` |
| `productPrice` |
| `productQuantityLabel` |
| `productIdentifier` |
| `productIdentifierValue` |
| `productIdentifierLabelValue` |
| `productVariationsContainer` |
| `productVariationsItem` |
| `quantityDropdownContainer` |
Expand All @@ -340,7 +351,6 @@ In order to apply CSS customizations in this and other blocks, follow the instru
| `unitPriceMeasurementUnit` |
| `unitPricePerUnitCurrency` |


<!-- DOCS-IGNORE:start -->

## Contributors ✨
Expand Down
57 changes: 57 additions & 0 deletions react/ProductReference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { FunctionComponent, useMemo } from 'react'
import { Loading } from 'vtex.render-runtime'
import { useCssHandles } from 'vtex.css-handles'

import { useItemContext } from './ItemContext'
import { opaque } from './utils/opaque'
import { IdentifierType } from './constants/Identifiers'

const CSS_HANDLES = [
'productIdentifier',
'productIdentifierValue',
'productIdentifierLabelValue',
] as const

interface Props {
identifierLabel?: string
identifierOption?: string
}

const ProductReference: FunctionComponent<Props> = props => {
const { identifierOption, identifierLabel } = props
const { item, loading } = useItemContext()
const handles = useCssHandles(CSS_HANDLES)

const identifierValue = useMemo(() => {
if (identifierOption === IdentifierType.PRODUCT_REFERENCE_ID)
return item.productRefId
if (identifierOption === IdentifierType.PRODUCT_SKU_REFERENCE_ID)
return item.refId
if (identifierOption === IdentifierType.PRODUCT_SKU_ITEM_ID) return item.id
if (identifierOption === IdentifierType.PRODUCT_ID) return item.productId

return item.productRefId
}, [item.productRefId, identifierOption, item.id, item.productId, item.refId])

if (loading) return <Loading />
if (!identifierValue) return null

return (
<div
className={`c-on-base t-title lh-copy fw6 fw5-m ${
handles.productIdentifier
} ${opaque(item.availability)}`}
>
{identifierLabel && (
<span className={`${handles.productIdentifierLabelValue}`}>
{identifierLabel}
</span>
)}
<span className={`${handles.productIdentifierValue}`}>
{identifierValue}
</span>
</div>
)
}

export default ProductReference
6 changes: 6 additions & 0 deletions react/constants/Identifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const enum IdentifierType {
PRODUCT_ID = 'ProductId',
PRODUCT_SKU_ITEM_ID = 'ProductSkuItemId',
PRODUCT_REFERENCE_ID = 'ProductReferenceId',
PRODUCT_SKU_REFERENCE_ID = 'ProductSkuReferenceId',
}
3 changes: 3 additions & 0 deletions store/interfaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
}
}
},
"product-reference": {
"component": "ProductReference"
},
"product-brand": {
"component": "ProductBrand",
"preview": {
Expand Down

0 comments on commit d9db624

Please sign in to comment.