Skip to content

Commit

Permalink
Migrate storybook entries of ProductPrice component (woocommerce#5371)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyatasattva authored and jonny-bull committed Dec 16, 2021
1 parent 9ad3e68 commit 8241d0a
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 66 deletions.
116 changes: 107 additions & 9 deletions assets/js/base/components/product-price/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ import type { Currency } from '@woocommerce/types';
import './style.scss';

interface PriceRangeProps {
currency: Currency | Record< string, never >; // Currency configuration object;
/**
* Currency configuration object
*/
currency: Currency | Record< string, never >;
/**
* The maximum price for the range
*/
maxPrice: string | number;
/**
* The minimum price for the range
*/
minPrice: string | number;
/**
* CSS class applied to each of the elements containing the prices
*
* **Note:** this excludes the dash in between the elements
*/
priceClassName?: string;
/**
* Any custom style to be applied to each of the elements containing the prices
*
* **Note:** this excludes the dash in between the elements
*/
priceStyle?: React.CSSProperties;
}

Expand All @@ -26,7 +45,7 @@ const PriceRange = ( {
maxPrice,
minPrice,
priceClassName,
priceStyle,
priceStyle = {},
}: PriceRangeProps ) => {
return (
<>
Expand Down Expand Up @@ -67,12 +86,41 @@ const PriceRange = ( {
};

interface SalePriceProps {
currency: Currency | Record< string, never >; // Currency configuration object.
/**
* Currency configuration object
*/
currency: Currency | Record< string, never >;
/**
* CSS class to be applied to the regular price container
*
* i.e. `<del>` element
*/
regularPriceClassName?: string;
regularPriceStyle?: Record< string, string >;
/**
* Custom style to be applied to the regular price container
*
* i.e. `<del>` element
*/
regularPriceStyle?: React.CSSProperties;
/**
* The regular price before the sale
*/
regularPrice: number | string;
/**
* CSS class to be applied to the sale price container
*
* i.e. `<ins>` element
*/
priceClassName?: string;
priceStyle?: Record< string, string >;
/**
* Custom style to be applied to the regular price container
*
* i.e. `<ins>` element
*/
priceStyle?: React.CSSProperties;
/**
* The new price during the sale
*/
price: number | string;
}

Expand Down Expand Up @@ -128,19 +176,69 @@ const SalePrice = ( {
);
};

interface ProductPriceProps {
export interface ProductPriceProps {
/**
* Where to align the wrapper
*
* Applies the `wc-block-components-product-price--align-${ align }` utility
* class to the wrapper.
*/
align?: 'left' | 'center' | 'right';
/**
* CSS class for the wrapper
*/
className?: string;
currency: Currency | Record< string, never >; // Currency configuration object.
/**
* Currency configuration object
*/
currency: Currency | Record< string, never >;
/**
* The string version of the element to use for the price interpolation
*
* **Note:** It should contain `<price/>` (which is also the default value)
*/
format: string;
/**
* The current price
*/
price: number | string;
/**
* CSS class for the current price wrapper
*/
priceClassName?: string;
priceStyle?: Record< string, string >;
/**
* Custom style for the current price
*/
priceStyle?: React.CSSProperties;
/**
* The maximum price in a range
*
* If both `maxPrice` and `minPrice` are set, the component will be rendered
* as a `PriceRange` component, otherwise, this value will be ignored.
*/
maxPrice?: number | string;
/**
* The minimum price in a range
*
* If both `maxPrice` and `minPrice` are set, the component will be rendered
* as a `PriceRange` component, otherwise, this value will be ignored.
*/
minPrice?: number | string;
/**
* The regular price if the item is currently on sale
*
* If this property exists and is different from the current price, then the
* component will be rendered as a `SalePrice` component.
*/
regularPrice?: number | string;
/**
* CSS class to apply to the regular price wrapper
*/
regularPriceClassName?: string;
regularPriceStyle?: Record< string, string >;
/**
* Custom style to apply to the regular price wrapper.
*/
regularPriceStyle?: React.CSSProperties;
}

const ProductPrice = ( {
Expand Down
57 changes: 0 additions & 57 deletions assets/js/base/components/product-price/stories/index.js

This file was deleted.

47 changes: 47 additions & 0 deletions assets/js/base/components/product-price/stories/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* External dependencies
*/
import { Story, Meta } from '@storybook/react';
import { currencyControl } from '@woocommerce/storybook-controls';

/**
* Internal dependencies
*/
import ProductPrice, { ProductPriceProps } from '..';

const ALLOWED_ALIGN_VALUES = [ 'left', 'center', 'right' ];

export default {
title: 'WooCommerce Blocks/@base-components/ProductPrice',
component: ProductPrice,
argTypes: {
align: {
control: { type: 'radio' },
options: ALLOWED_ALIGN_VALUES,
},
currency: currencyControl,
},
args: {
align: 'left',
format: '<price/>',
price: 3000,
},
} as Meta< ProductPriceProps >;

const Template: Story< ProductPriceProps > = ( args ) => (
<ProductPrice { ...args } />
);

export const Default = Template.bind( {} );
Default.args = {};

export const Sale = Template.bind( {} );
Sale.args = {
regularPrice: 4500,
};

export const Range = Template.bind( {} );
Range.args = {
maxPrice: 5000,
minPrice: 3000,
};

0 comments on commit 8241d0a

Please sign in to comment.