Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Deprecate CartLinePrice (#173)
Browse files Browse the repository at this point in the history
* Deprecate CartLinePrice

* cleanup changelog
  • Loading branch information
frehner committed Feb 7, 2023
1 parent b6e54bd commit 6225d33
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
19 changes: 19 additions & 0 deletions .changeset/selfish-turtles-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@shopify/hydrogen-react': patch
---

Add a deprecation notice to `<CartLinePrice/>`:

Use `Money` instead. To migrate, use the `priceType` prop that matches the corresponding property on the `CartLine` object:

- `regular`: `cartLine.cost.totalAmount`
- `compareAt`: `cartLine.cost.compareAtAmountPerQuantity`

For example:

```jsx
// before
<CartLinePrice data={cartLine} priceType="regular" />
// after
<Money data={cartLine.cost.totalAmount} />
```
2 changes: 1 addition & 1 deletion packages/react/docs/generated/generated_docs_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
"url": "/api/hydrogen-react/components/money"
}
],
"description": "\n The `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or compare at price.\n ",
"description": "\n `@deprecated` Use `Money` instead.\n\nTo migrate, use the `priceType` prop that matches the corresponding property on the `CartLine` object:\n\n- `regular`: `cartLine.cost.totalAmount`\n\n- `compareAt`: `cartLine.cost.compareAtAmountPerQuantity`\n\nFor example\n\nBefore:\n\n`<CartLinePrice data={cartLine} priceType=\"regular\" />`\n\nAfter:\n\n`<Money data={cartLine.cost.totalAmount} />`\n\nThe `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or compare at price.\n ",
"type": "component",
"defaultExample": {
"description": "I am the default example",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/CartLinePrice.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const data: ReferenceEntityTemplateSchema = {
},
],
description: `
The \`CartLinePrice\` component renders a \`Money\` component for the cart line merchandise's price or compare at price.
\`@deprecated\` Use \`Money\` instead.\n\nTo migrate, use the \`priceType\` prop that matches the corresponding property on the \`CartLine\` object:\n\n- \`regular\`: \`cartLine.cost.totalAmount\`\n\n- \`compareAt\`: \`cartLine.cost.compareAtAmountPerQuantity\`\n\nFor example\n\nBefore:\n\n\`<CartLinePrice data={cartLine} priceType="regular" />\`\n\nAfter:\n\n\`<Money data={cartLine.cost.totalAmount} />\`\n\nThe \`CartLinePrice\` component renders a \`Money\` component for the cart line merchandise's price or compare at price.
`,
type: 'component',
defaultExample: {
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/CartLinePrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@ type CartLinePriceProps = Omit<React.ComponentProps<typeof Money>, 'data'> &
CartLinePricePropsBase;

/**
* @deprecated Use `Money` instead. To migrate, use the `priceType` prop that matches the corresponding property on the `CartLine` object:
* - `regular`: `cartLine.cost.totalAmount`
* - `compareAt`: `cartLine.cost.compareAtAmountPerQuantity`
*
* For example:
* ```
* // before
* <CartLinePrice data={cartLine} priceType="regular" />
* // after
* <Money data={cartLine.cost.totalAmount} />
* ```
*
* The `CartLinePrice` component renders a `Money` component for the cart line merchandise's price or compare at price.
*/
export function CartLinePrice(props: CartLinePriceProps) {
if (__HYDROGEN_DEV__) {
console.warn(`<CartLinePrice/> is deprecated; use <Money/> instead.`);
}

const {data: cartLine, priceType = 'regular', ...passthroughProps} = props;

if (cartLine == null) {
Expand Down

0 comments on commit 6225d33

Please sign in to comment.