forked from woocommerce/woocommerce-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook and TS migration of some cart checkout components (woocomme…
…rce#5324) * Migrate stories for `ProductName` to latest Storybook. Also add props documentation and add named export. * Migrate `TotalsFooterItem` to TypeScript and latest Storybook * Add a `LooselyMustHave` utility type. * Export `allSettings` so that they can be manipulated in stories and tests * Implement a way to easily define and reuse Storybook controls Implement a currency control for a common use-case of selecting currencies. It currently implements EUR and USD as they have different properties. * Migrate `TotalsDiscount` to TypeScript and implement stories * Migrate `TotalsCoupon` to TypeScript and fix stories * Change Coupon name within Storybook * Nicer handling of removal of a coupon from Storybook It now dynamically calculates the discount from the actual coupons.
- Loading branch information
1 parent
3449783
commit de8931f
Showing
25 changed files
with
460 additions
and
279 deletions.
There are no files selected for viewing
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
47 changes: 0 additions & 47 deletions
47
assets/js/base/components/cart-checkout/totals/coupon/stories/index.js
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
assets/js/base/components/cart-checkout/totals/coupon/stories/index.tsx
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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useArgs } from '@storybook/client-api'; | ||
import { Story, Meta } from '@storybook/react'; | ||
import { | ||
useValidationContext, | ||
ValidationContextProvider, | ||
} from '@woocommerce/base-context'; | ||
import { INTERACTION_TIMEOUT } from '@woocommerce/storybook-controls'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TotalsCoupon, TotalsCouponProps } from '..'; | ||
|
||
export default { | ||
title: 'WooCommerce Blocks/@base-components/cart-checkout/totals/Coupon', | ||
component: TotalsCoupon, | ||
args: { | ||
initialOpen: true, | ||
}, | ||
} as Meta< TotalsCouponProps >; | ||
|
||
const INVALID_COUPON_ERROR = { | ||
hidden: false, | ||
message: 'Invalid coupon code', | ||
}; | ||
|
||
const Template: Story< TotalsCouponProps > = ( args ) => { | ||
const [ {}, setArgs ] = useArgs(); | ||
|
||
const onSubmit = ( code: string ) => { | ||
args.onSubmit?.( code ); | ||
setArgs( { isLoading: true } ); | ||
|
||
setTimeout( | ||
() => setArgs( { isLoading: false } ), | ||
INTERACTION_TIMEOUT | ||
); | ||
}; | ||
|
||
return <TotalsCoupon { ...args } onSubmit={ onSubmit } />; | ||
}; | ||
|
||
export const Default = Template.bind( {} ); | ||
Default.args = {}; | ||
|
||
export const LoadingState = Template.bind( {} ); | ||
LoadingState.args = { | ||
isLoading: true, | ||
}; | ||
|
||
export const ErrorState: Story< TotalsCouponProps > = ( args ) => { | ||
const { setValidationErrors } = useValidationContext(); | ||
|
||
setValidationErrors( { coupon: INVALID_COUPON_ERROR } ); | ||
|
||
return <TotalsCoupon { ...args } />; | ||
}; | ||
|
||
ErrorState.decorators = [ | ||
( StoryComponent ) => { | ||
return ( | ||
<ValidationContextProvider> | ||
<StoryComponent /> | ||
</ValidationContextProvider> | ||
); | ||
}, | ||
]; |
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
37 changes: 0 additions & 37 deletions
37
assets/js/base/components/cart-checkout/totals/discount/stories/index.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.