-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-components-amount): feat, change api, add PureAmount
- Loading branch information
stepancar
committed
Jun 26, 2020
1 parent
b8b4efa
commit f946776
Showing
12 changed files
with
183 additions
and
71 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
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
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
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
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
export * from './component'; | ||
import { Amount as DefaultAmount } from './component'; | ||
import { PureAmount } from './pure/component'; | ||
|
||
type AmountType = typeof DefaultAmount & { Pure: typeof PureAmount }; | ||
// TODO: можно ли с этим что-то придумать? | ||
const Amount: AmountType = DefaultAmount as AmountType; | ||
Amount.Pure = PureAmount; | ||
|
||
export { Amount }; |
14 changes: 14 additions & 0 deletions
14
packages/amount/src/pure/__snapshots__/component.test.tsx.snap
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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PureAmount should match snapshot 1`] = ` | ||
<span | ||
class="component" | ||
data-test-id="test-id" | ||
> | ||
1 | ||
, | ||
00 | ||
₽ | ||
</span> | ||
`; |
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,15 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { PureAmount } from '.'; | ||
|
||
describe('PureAmount', () => { | ||
it('should match snapshot', () => { | ||
const testId = 'test-id'; | ||
|
||
const { getByTestId } = render( | ||
<PureAmount value={100} currency='RUR' minority={100} dataTestId={testId} />, | ||
); | ||
const amount = getByTestId(testId); | ||
expect(amount).toMatchSnapshot(); | ||
}); | ||
}); |
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,40 @@ | ||
import React from 'react'; | ||
import cn from 'classnames'; | ||
|
||
import { formatAmount } from '../utils'; | ||
import { AMOUNT_MAJOR_MINOR_PARTS_SEPARATOR, THINSP } from '../utils/currencyCodes'; | ||
import { AmounProps } from '../types'; | ||
import styles from './index.module.css'; | ||
|
||
/** | ||
* Компонент для отображения суммы, согласно следующему гайдлайну: | ||
* https://design.alfabank.ru/patterns/amount | ||
* Не содержит стилей кроме неразрывности строки | ||
*/ | ||
export const PureAmount: React.FC<AmounProps> = ({ | ||
value, | ||
minority, | ||
currency, | ||
view = 'default', | ||
className, | ||
dataTestId, | ||
}) => { | ||
const { majorPart, minorPart, currencySymbol } = formatAmount({ | ||
value, | ||
currency: { | ||
code: currency, | ||
minority, | ||
}, | ||
withZeroMinorPart: view === 'withZeroMinorPart', | ||
}); | ||
|
||
return ( | ||
<span className={cn(styles.component, className)} data-test-id={dataTestId}> | ||
{majorPart} | ||
{minorPart && AMOUNT_MAJOR_MINOR_PARTS_SEPARATOR} | ||
{minorPart} | ||
{THINSP} | ||
{currencySymbol} | ||
</span> | ||
); | ||
}; |
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,3 @@ | ||
.component { | ||
white-space: nowrap; | ||
} |
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 @@ | ||
export * from './component'; |
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,34 @@ | ||
import { CurrencyCodes } from '../utils/currencyCodes'; | ||
|
||
export type AmounProps = { | ||
/** | ||
* Денежное значение в минорных единицах | ||
*/ | ||
value: number; | ||
|
||
/** | ||
* Валюта | ||
*/ | ||
currency: CurrencyCodes; | ||
|
||
/** | ||
* Идентификатор для систем автоматизированного тестирования | ||
*/ | ||
minority: number; | ||
|
||
/** | ||
* default - не отображаем копейки, если из значение 0 | ||
* withZeroMinorPart - отображаем копейки, даже если их значение равно 0 | ||
*/ | ||
view?: 'default' | 'withZeroMinorPart'; | ||
|
||
/** | ||
* Дополнительный класс | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* Идентификатор для систем автоматизированного тестирования | ||
*/ | ||
dataTestId?: string; | ||
}; |
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