-
Notifications
You must be signed in to change notification settings - Fork 324
Add new options to Money and useMoney #1215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
38cb5c4
Upgraded to SFAPI 2022-07
frehner cd68476
Add new options to Money and useMoney
frehner bcac989
add money changeset
frehner 50b558e
Update docs/components/primitive/money.md
frehner 77a680b
Update packages/hydrogen/src/components/Money/Money.client.tsx
frehner d24500b
Update packages/hydrogen/src/components/Money/Money.client.tsx
frehner f79d491
Update docs/hooks/primitive/usemoney.md
frehner babeb3b
Update packages/hydrogen/src/hooks/useMoney/hooks.tsx
frehner 1e25d0a
Update packages/hydrogen/src/hooks/useMoney/hooks.tsx
frehner d767923
Merge branch 'v1.x-2022-07' into money-updates
frehner 9f35e30
Add example to docs
frehner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,7 @@ | ||
| --- | ||
| '@shopify/hydrogen': patch | ||
| --- | ||
|
|
||
| `useMoney` now returns two additional properties: `withoutTraillingZeros` and `withoutTrailingZerosAndCurrency` | ||
|
|
||
| `<Money />` now has two additional and optional props: `withoutMoney` and `withoutCurrency`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -37,4 +37,43 @@ describe('<Money />', () => { | |
|
|
||
| expect(component).toContainReactComponent(Link, {to: '/test'}); | ||
| }); | ||
|
|
||
| it(`removes trailing zeros when the prop is passed`, () => { | ||
| const money = getPrice({ | ||
| currencyCode: CurrencyCode.Eur, | ||
| amount: '19.00', | ||
| }); | ||
| const component = mountWithProviders( | ||
| <Money data={money} withoutTrailingZeros /> | ||
| ); | ||
|
|
||
| expect(component).not.toContainReactText(`€${money.amount}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just hard code the 19.00 here. |
||
| expect(component).toContainReactText(`€${19}`); | ||
| }); | ||
|
|
||
| it(`removes the currency symbol when the prop is passed`, () => { | ||
| const money = getPrice({ | ||
| currencyCode: CurrencyCode.Eur, | ||
| }); | ||
| const component = mountWithProviders( | ||
| <Money data={money} withoutCurrency /> | ||
| ); | ||
|
|
||
| expect(component).not.toContainReactText(`€${money.amount}`); | ||
| expect(component).toContainReactText(`${money.amount}`); | ||
| }); | ||
|
|
||
| it(`removes the currency symbol and trailing zeros when the props are both passed`, () => { | ||
| const money = getPrice({ | ||
| currencyCode: CurrencyCode.Eur, | ||
| amount: '19.00', | ||
| }); | ||
| const component = mountWithProviders( | ||
| <Money data={money} withoutCurrency withoutTrailingZeros /> | ||
| ); | ||
|
|
||
| expect(component).not.toContainReactText(`€${money.amount}`); | ||
| expect(component).not.toContainReactText(`${money.amount}`); | ||
| expect(component).toContainReactText(`19`); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it is verbose, but I suggest specifying the prop (ie: when the withoutTrailingZeros prop is passed)