Skip to content

Commit

Permalink
feat: added FormControl input mask
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Sep 15, 2023
1 parent 3db63e7 commit b1961fa
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 3 deletions.
49 changes: 47 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"react-colorful": "^5.6.1",
"react-dropzone": "^14.2.1",
"react-focus-on": "^3.5.4",
"react-imask": "^7.1.3",
"react-loading-skeleton": "^3.1.0",
"react-popper": "^2.2.5",
"react-proptype-conditional-require": "^1.0.4",
Expand Down
4 changes: 3 additions & 1 deletion src/Form/FormControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import RBFormControl from 'react-bootstrap/FormControl';
import { IMaskInput } from 'react-imask';
import { useFormGroupContext } from './FormGroupContext';
import FormControlFeedback from './FormControlFeedback';
import FormControlDecoratorGroup from './FormControlDecoratorGroup';
Expand All @@ -17,6 +18,7 @@ const FormControl = React.forwardRef(({
floatingLabel,
autoResize,
onChange,
withMask,

Check failure on line 21 in src/Form/FormControl.jsx

View workflow job for this annotation

GitHub Actions / tests

'withMask' is missing in props validation
...props
}, ref) => {
const {
Expand Down Expand Up @@ -71,7 +73,7 @@ const FormControl = React.forwardRef(({
className={className}
>
<RBFormControl
as={as}
as={withMask ? IMaskInput : as}
ref={resolvedRef}
size={size}
isInvalid={isInvalid}
Expand Down
83 changes: 83 additions & 0 deletions src/Form/form-control.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,89 @@ or [select attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element
}
```

## Input phone mask

```jsx live
() => {
const [value, setValue] = useState('');

return (
<Form.Group>
<Form.Control withMask mask="+{7}(000)000-00-00"
leadingElement={<Icon src={FavoriteBorder} />}
trailingElement={<Icon src={Verified} />}
floatingLabel="What kind of cats?"
value={value}
onAccept={
(value, unmaskedValue, mask) => console.log(unmaskedValue)
}
onChange={(e) => setValue(e.target.value)}
/>
</Form.Group>
);
}
```

## Input card number mask

```jsx live
() => {
const [value, setValue] = useState('');
console.log('============ value ===========', value);
return (
<Form.Group>
<Form.Control withMask mask="0000 0000 0000 0000"
leadingElement={<Icon src={FavoriteBorder} />}
trailingElement={<Icon src={Verified} />}
floatingLabel="What kind of cats?"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</Form.Group>
);
}
```

## Input date mask

```jsx live
() => {
const [value, setValue] = useState('');
console.log('============ value ===========', value);
return (
<Form.Group>
<Form.Control withMask mask={Date} min={new Date(1990, 0, 1)} max={new Date(2020, 0, 1)}
leadingElement={<Icon src={FavoriteBorder} />}
trailingElement={<Icon src={Verified} />}
floatingLabel="What kind of cats?"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</Form.Group>
);
}
```

## Input Google-style OTP mask

```jsx live
() => {
const [value, setValue] = useState('');
console.log('============ value ===========', value);
return (
<Form.Group>
<Form.Control withMask mask="G-000000000000"
leadingElement={<Icon src={FavoriteBorder} />}
trailingElement={<Icon src={Verified} />}
floatingLabel="What kind of cats?"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</Form.Group>
);
}
```


## Input types

Expand Down

0 comments on commit b1961fa

Please sign in to comment.