Skip to content

Commit

Permalink
feat: an (optional) prefix can be added to the inputCurrency variant
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioFeregrino committed Mar 22, 2023
1 parent 83e3fbd commit a44c99b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Form/Input/CurrencyInput.test.tsx
Expand Up @@ -6,7 +6,7 @@ describe('<CurrencyInput />', () => {
it('formats input value as currency', () => {
const onChange = vi.fn()
const { getByTestId } = render(
<CurrencyInput data-testid="input" onChange={onChange} />
<CurrencyInput data-testid="input" onChange={onChange} prefix="$" />
)
const input = getByTestId('input') as HTMLInputElement

Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/Input/CurrencyInput.tsx
Expand Up @@ -3,7 +3,7 @@ import { getValueWithDecimalFormat, unFormatCurrency } from 'dd360-utils'
import BaseInput, { InputProps } from './BaseInput'

function CurrencyInput(props: InputProps) {
const { onChange, value } = props
const { onChange, value, prefix = '' } = props
const [localValue, setLocalValue] = useState(
getValueWithDecimalFormat(String(value))
)
Expand All @@ -23,7 +23,7 @@ function CurrencyInput(props: InputProps) {
}, [value])

return (
<BaseInput {...props} onChange={handleChange} value={'$' + localValue} />
<BaseInput {...props} onChange={handleChange} value={prefix + localValue} />
)
}

Expand Down
3 changes: 2 additions & 1 deletion src/stories/Input.stories.tsx
Expand Up @@ -44,7 +44,8 @@ InputCurrency.args = {
endAdornment: '$',
startAdornment: '%',
className: 'w-full',
type: 'currency'
type: 'currency',
prefix: '$'
}
export const InputPassword = Template.bind({})
InputPassword.args = {
Expand Down

0 comments on commit a44c99b

Please sign in to comment.