-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'plp-strikethrough-price' into vm/promo-callout
- Loading branch information
Showing
6 changed files
with
207 additions
and
130 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/template-retail-react-app/app/components/display-price/current-price.jsx
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,61 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {Text} from '@salesforce/retail-react-app/app/components/shared/ui' | ||
import {useIntl} from 'react-intl' | ||
import msg from '@salesforce/retail-react-app/app/components/display-price/messages' | ||
|
||
/** | ||
* Component that displays current price of a product with a11y | ||
* @param price - price of the product | ||
* @param as - an HTML tag or component to be rendered as | ||
* @param isRange - show price as range or not | ||
* @param currency - currency to show the price in | ||
* @param extraProps - extra props to be passed into Text Component | ||
* @returns {JSX.Element} | ||
*/ | ||
const CurrentPrice = ({price, as, isRange = false, currency, ...extraProps}) => { | ||
const intl = useIntl() | ||
const currentPriceText = intl.formatNumber(price, { | ||
style: 'currency', | ||
currency | ||
}) | ||
return isRange ? ( | ||
<Text | ||
as={as} | ||
{...extraProps} | ||
aria-label={intl.formatMessage(msg.ariaLabelCurrentPriceWithRange, { | ||
currentPrice: currentPriceText | ||
})} | ||
> | ||
{intl.formatMessage(msg.currentPriceWithRange, { | ||
currentPrice: currentPriceText | ||
})} | ||
</Text> | ||
) : ( | ||
<Text | ||
as={as} | ||
{...extraProps} | ||
aria-label={intl.formatMessage(msg.ariaLabelCurrentPrice, { | ||
currentPrice: currentPriceText | ||
})} | ||
> | ||
{currentPriceText} | ||
</Text> | ||
) | ||
} | ||
CurrentPrice.propTypes = { | ||
price: PropTypes.number.isRequired, | ||
currency: PropTypes.string.isRequired, | ||
as: PropTypes.string, | ||
isRange: PropTypes.bool, | ||
extraProps: PropTypes.object | ||
} | ||
|
||
export default CurrentPrice |
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
62 changes: 62 additions & 0 deletions
62
packages/template-retail-react-app/app/components/display-price/list-price.jsx
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,62 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {Text} from '@salesforce/retail-react-app/app/components/shared/ui' | ||
import {useIntl} from 'react-intl' | ||
import msg from '@salesforce/retail-react-app/app/components/display-price/messages' | ||
/** | ||
* Component that displays list price of a product with a11y | ||
* @param price - price of the product | ||
* @param as - an HTML tag or component to be rendered as | ||
* @param isRange - show price as range or not | ||
* @param props - extra props to be passed into Text Component | ||
* @param extraProps - extra props to be passed into Text Component | ||
* @returns {JSX.Element} | ||
*/ | ||
const ListPrice = ({price, isRange = false, as = 's', currency, ...extraProps}) => { | ||
const intl = useIntl() | ||
const listPriceText = intl.formatNumber(price, { | ||
style: 'currency', | ||
currency | ||
}) | ||
|
||
return isRange ? ( | ||
<Text | ||
as={as} | ||
{...extraProps} | ||
aria-label={intl.formatMessage(msg.ariaLabelListPriceWithRange, { | ||
listPrice: listPriceText || '' | ||
})} | ||
color="gray.600" | ||
> | ||
{listPriceText} | ||
</Text> | ||
) : ( | ||
<Text | ||
as={as} | ||
{...extraProps} | ||
aria-label={intl.formatMessage(msg.ariaLabelListPrice, { | ||
listPrice: listPriceText || '' | ||
})} | ||
color="gray.600" | ||
> | ||
{listPriceText} | ||
</Text> | ||
) | ||
} | ||
|
||
ListPrice.propTypes = { | ||
price: PropTypes.number.isRequired, | ||
currency: PropTypes.string.isRequired, | ||
as: PropTypes.string, | ||
isRange: PropTypes.bool, | ||
extraProps: PropTypes.object | ||
} | ||
|
||
export default ListPrice |
35 changes: 35 additions & 0 deletions
35
packages/template-retail-react-app/app/components/display-price/messages.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import {defineMessages} from 'react-intl' | ||
|
||
const messages = defineMessages({ | ||
// price display | ||
currentPriceWithRange: { | ||
id: 'display_price.label.current_price_with_range', | ||
defaultMessage: 'From {currentPrice}' | ||
}, | ||
// aria-label | ||
ariaLabelCurrentPrice: { | ||
id: 'display_price.assistive_msg.current_price', | ||
defaultMessage: `current price {currentPrice}` | ||
}, | ||
ariaLabelCurrentPriceWithRange: { | ||
id: 'display_price.assistive_msg.current_price_with_range', | ||
defaultMessage: `From current price {currentPrice}` | ||
}, | ||
ariaLabelListPrice: { | ||
id: 'display_price.assistive_msg.strikethrough_price', | ||
defaultMessage: `original price {listPrice}` | ||
}, | ||
ariaLabelListPriceWithRange: { | ||
id: 'display_price.assistive_msg.strikethrough_price_with_range', | ||
defaultMessage: `From original price {listPrice}` | ||
} | ||
}) | ||
|
||
export default messages |
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