Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add product quantity component #44

Merged
merged 5 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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`.

## [0.17.0] - 2020-01-29
### Added
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
19 changes: 19 additions & 0 deletions react/ProductQuantity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'

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

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

return (
<span className="c-muted-1 t-body">
<FormattedMessage
id="store/product-list.quantity-units"
values={{ quantity: item.quantity }}
/>
</span>
lucasecdb marked this conversation as resolved.
Show resolved Hide resolved
)
}

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