-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add inline input * Inline input: disabled is not mandatory Co-authored-by: MaZ <[email protected]> * CR, add test and story * rename to inline money --------- Co-authored-by: MaZ <[email protected]>
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InlineMoney } from './InlineMoney'; | ||
|
||
export default { title: 'Components/InlineMoney' }; | ||
|
||
export const _InlineMoney = { | ||
render: () => ( | ||
<p> | ||
<InlineMoney value="1000000" /> | ||
<br /> | ||
<InlineMoney value="0.00" disabled /> | ||
<br /> | ||
<InlineMoney value="5.55" suffix=" USD" /> | ||
<br /> | ||
<InlineMoney value="5.55" customClass="mas-caption" /> | ||
</p> | ||
), | ||
}; |
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,13 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { InlineMoney } from '.'; | ||
|
||
describe('Components | Fields | InlineMoney', () => { | ||
test('it should render', () => { | ||
render(<InlineMoney value="value" />); | ||
|
||
let inlineMoney = screen.getByTestId('inline-money'); | ||
|
||
expect(inlineMoney).toBeInTheDocument(); | ||
}); | ||
}); |
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,39 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React, { ComponentPropsWithoutRef } from 'react'; | ||
|
||
import { NumberFormatValues, NumericFormat } from 'react-number-format'; | ||
|
||
interface InlineMoneyProps | ||
extends ComponentPropsWithoutRef<typeof NumericFormat> { | ||
value: string; | ||
disabled?: boolean; | ||
suffix?: string; | ||
onValueChange?: (event: NumberFormatValues) => void; | ||
customClass?: string; | ||
} | ||
|
||
export function InlineMoney(props: InlineMoneyProps) { | ||
const { disabled, value, onValueChange, suffix, customClass, ...rest } = | ||
props; | ||
|
||
const underline = disabled ? '' : 'underline'; | ||
|
||
const suffixAttr = suffix ? suffix : ' MAS'; | ||
|
||
return ( | ||
<NumericFormat | ||
data-testid="inline-money" | ||
className={`default-input border-none focus:border-none rounded-none | ||
text-right bg-primary underline-offset-4 ${underline} ${customClass}`} | ||
decimalScale={9} | ||
allowNegative={false} | ||
suffix={suffixAttr} | ||
disabled={disabled} | ||
thousandSeparator="," | ||
value={value} | ||
onValueChange={onValueChange} | ||
{...rest} | ||
/> | ||
); | ||
} |
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 './InlineMoney'; |
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