@reservoir0x/relay-kit-ui
Version:
Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.
43 lines • 1.98 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Input } from '../primitives/index.js';
const AmountInput = ({ value, setValue, prefixSymbol, ...inputProps }) => {
return (_jsx(Input, { ...inputProps, type: "text", inputMode: "decimal", autoComplete: "off", autoCorrect: "off", pattern: "^[0-9]+(\\.[0-9]*)?$", ellipsify: true, size: "large", className: "ph-no-capture", css: {
width: '100%',
background: 'none',
backgroundColor: 'transparent',
fontWeight: '600',
fontSize: 32,
px: '0 !important',
py: '1',
_focus: {
boxShadow: 'none',
outline: 'none'
},
_placeholder: {
color: 'gray12'
},
...inputProps.css
}, placeholder: inputProps.placeholder ?? '0', value: prefixSymbol ? `${prefixSymbol}${value}` : value, onChange: inputProps.onChange
? inputProps.onChange
: (e) => {
let newNumericValue = e.target.value;
if (prefixSymbol) {
if (newNumericValue.startsWith(prefixSymbol)) {
newNumericValue = newNumericValue.substring(prefixSymbol.length);
}
// If input is empty or doesn't start with prefix, treat as new numeric value
// The prefix will be re-applied by the `value` prop on re-render
}
// Validate and set the numeric part
const regex = /^[0-9]+(\.[0-9]*)?$/;
if (newNumericValue === '.' || newNumericValue.includes(',')) {
setValue('0.');
}
else if (regex.test(newNumericValue) ||
newNumericValue === '') {
setValue(newNumericValue);
}
} }));
};
export default AmountInput;
//# sourceMappingURL=AmountInput.js.map