File size: 1,771 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# PlanPrice Component
The PlanPrice component is a React component used to display a plan's price with a currency and a discount, if any. It can be used anywhere where a plan's price is required.
If you want to emphasize that a plan's price is discounted, use two `<PlanPrice>` components as below and wrap them in a
flexbox container.
## Usage
PlanPrice can take a `productDisplayPrice` or a `rawPrice` prop.
A `productDisplayPrice` can be retrieved from the `/purchases` or `/plans` REST endpoints and are stored in Redux; for example:
```jsx
function MyComponent( { purchaseId } ) {
const { productDisplayPrice } = useSelector( ( state ) => getByPurchaseId( state, purchaseId ) );
return <PlanPrice productDisplayPrice={ productDisplayPrice } />;
}
```
```jsx
<PlanPrice
productDisplayPrice={ purchase.productDisplayPrice }
taxText={ purchase.taxText }
isOnSale={ !! purchase.saleAmount }
/>;
```
```jsx
<PlanPrice
productDisplayPrice={ purchase.productDisplayPrice }
rawPrice={ getRenewalPrice( purchase ) }
currencyCode={ purchase.currencyCode }
taxText={ purchase.taxText }
isOnSale={ !! purchase.saleAmount }
/>;
```
If you pass an array of two numbers in the `rawPrice` prop, a range of prices will be displayed.
```jsx
import { PlanPrice } from '@automattic/components';
export default class extends React.Component {
static displayName = 'MyPlanPrice';
render() {
return (
<div>
<span className="my-plan-price-with-flexbox">
<PlanPrice rawPrice={ 99 } original />
<PlanPrice rawPrice={ 30 } discounted />
</span>
<span className="my-plan-price-with-flexbox">
<PlanPrice rawPrice={ [ 132.2, 110.4 ] } original />
<PlanPrice rawPrice={ [ 99.99, 87 ] } discounted />
</span>
</div>
);
}
}
```
|