utils#escapeRegExp TypeScript Examples

The following examples show how to use utils#escapeRegExp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumericalInput.tsx    From interface-v2 with GNU General Public License v3.0 5 votes vote down vote up
Input = React.memo(function InnerInput({
  value,
  onUserInput,
  placeholder,
  fontSize,
  color,
  fontWeight,
  placeholderColor,
  align,
  ...rest
}: {
  value: string | number;
  onUserInput: (input: string) => void;
  error?: boolean;
  fontSize?: number;
  fontWeight?: string | number;
  placeholderColor?: string;
  align?: 'right' | 'left';
} & Omit<React.HTMLProps<HTMLInputElement>, 'ref' | 'onChange' | 'as'>) {
  const classes = useStyles({
    fontSize,
    color,
    fontWeight,
    placeholderColor,
    align,
  });
  const enforcer = (nextUserInput: string) => {
    if (nextUserInput === '' || inputRegex.test(escapeRegExp(nextUserInput))) {
      onUserInput(nextUserInput);
    }
  };

  return (
    <input
      {...rest}
      className={classes.styledInput}
      value={value}
      onChange={(event) => {
        // replace commas with periods, because uniswap exclusively uses period as the decimal separator
        enforcer(event.target.value.replace(/,/g, '.'));
      }}
      // universal input options
      inputMode='decimal'
      autoComplete='off'
      autoCorrect='off'
      // text-specific options
      type='text'
      pattern='^[0-9]*[.,]?[0-9]*$'
      placeholder={placeholder || '0.0'}
      minLength={1}
      maxLength={79}
      spellCheck='false'
    />
  );
})