Skip to content

Commit

Permalink
Merge pull request #44 from vtex-apps/feat/product-quantity
Browse files Browse the repository at this point in the history
Add product quantity component
  • Loading branch information
lucasecdb authored Mar 6, 2020
2 parents f313637 + ffab47f commit e0f20eb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- New component `ProductQuantity`.
- Prop `showListPrice` to `Price` component.

## [0.17.0] - 2020-01-29
### Added
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ In order to apply CSS customizations in this and other blocks, follow the instru
| `productPriceContainer` |
| `productPriceCurrency` |
| `productPrice` |
| `productQuantityUnit` |
| `productVariationsContainer` |
| `productVariationsItem` |
| `quantityDropdownContainer` |
Expand Down
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"store/product-list.message.cantBeDelivered": "This product cannot be delivered to the address provided.",
"store/product-list.message.noLongerAvailable": "This product is no longer available.",
"store/product-list.message.remove": "remove",
"store/product-list.quantity-selector.remove": "Remove"
"store/product-list.quantity-selector.remove": "Remove",
"store/product-list.quantity-units": "{quantity} un."
}
3 changes: 2 additions & 1 deletion messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"store/product-list.message.cantBeDelivered": "Este producto no se puede entregar en la dirección proporcionada.",
"store/product-list.message.noLongerAvailable": "Este producto no está disponible actualmente.",
"store/product-list.message.remove": "retirar",
"store/product-list.quantity-selector.remove": "Retirar"
"store/product-list.quantity-selector.remove": "Retirar",
"store/product-list.quantity-units": "{quantity} un."
}
3 changes: 2 additions & 1 deletion messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"store/product-list.message.cantBeDelivered": "Este produto não pode ser entregue no endereço fornecido.",
"store/product-list.message.noLongerAvailable": "Este produto não está mais disponível.",
"store/product-list.message.remove": "remover",
"store/product-list.quantity-selector.remove": "Remover"
"store/product-list.quantity-selector.remove": "Remover",
"store/product-list.quantity-units": "{quantity} un."
}
17 changes: 10 additions & 7 deletions react/Price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ const CSS_HANDLES = [
'productPrice',
] as const

const Price: StorefrontFunctionComponent<TextAlignProp> = ({ textAlign }) => {
type PriceProps = TextAlignProp & {
showListPrice: boolean
}

const Price: StorefrontFunctionComponent<PriceProps> = ({
textAlign = 'left',
showListPrice = true,
}) => {
const { item, loading } = useItemContext()
const handles = useCssHandles(CSS_HANDLES)

Expand All @@ -29,7 +36,7 @@ const Price: StorefrontFunctionComponent<TextAlignProp> = ({ textAlign }) => {
handles.productPriceContainer
} ${parseTextAlign(textAlign)}`}
>
{item.listPrice !== item.price && (
{item.listPrice !== item.price && showListPrice && (
<div
id={`list-price-${item.id}`}
className={`${handles.productPriceCurrency} c-muted-1 strike t-mini mb2`}
Expand All @@ -47,15 +54,11 @@ const Price: StorefrontFunctionComponent<TextAlignProp> = ({ textAlign }) => {
)
}

Price.defaultProps = {
textAlign: 'left',
}

Price.schema = {
properties: {
textAlign: {
type: 'string',
default: Price.defaultProps.textAlign,
default: 'left',
isLayout: true,
},
},
Expand Down
23 changes: 23 additions & 0 deletions react/ProductQuantity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { useCssHandles } from 'vtex.css-handles'

import { useItemContext } from './components/ItemContext'

const CSS_HANDLES = ['productQuantityUnit'] as const

const ProductQuantity: React.FC = () => {
const { item } = useItemContext()
const cssHandles = useCssHandles(CSS_HANDLES)

return (
<span className={`${cssHandles.productQuantityUnit} c-muted-1 t-body`}>
<FormattedMessage
id="store/product-list.quantity-units"
values={{ quantity: item.quantity }}
/>
</span>
)
}

export default ProductQuantity
3 changes: 3 additions & 0 deletions store/interfaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"product-variations": {
"component": "ProductVariations"
},
"product-quantity": {
"component": "ProductQuantity"
},
"quantity-selector": {
"component": "QuantitySelector",
"preview": {
Expand Down

0 comments on commit e0f20eb

Please sign in to comment.