// License: LGPL-3.0-or-later import * as React from 'react'; import { Money } from '../../common/money'; import { useEffect } from 'react'; import { Formik, Field, useFormikContext } from 'formik'; import { MoneyTextField } from './index'; import { action } from '@storybook/addon-actions'; function FormikInner(props: { onChange:(args:{value:Money})=> void}) { const context = useFormikContext<{value:Money}>(); const {value} = context.values; const {onChange} = props; useEffect(() => { onChange({value}); }, [value, onChange]); return <>
{value.amount}{value.currency}
; } function FormikHandler(props: { onChange:(args:{value:Money})=> void, value: Money}) { const {value, ...innerFormikProps} = props; return ( { console.log("submitted");}} enableReinitialize={true}> ); } FormikHandler.defaultProps = { // eslint-disable-next-line @typescript-eslint/no-empty-function onChange: () => {}, locale: 'en', }; export default { title: 'MoneyTextField' }; export function usd100() { const usd100 = Money.fromCents(100, 'usd'); return ; } export function jpy100() { const jpy100 = Money.fromCents(100, 'jpy'); return ; }