@modul/mbui 0.0.0 → 0.0.1-beta-pv-50534-962f5f9d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -3
- package/src/Base/Input/Input.tsx +23 -0
- package/src/Base/Input/InputClearable.tsx +39 -0
- package/src/Base/Input/index.ts +4 -0
- package/src/Base/Input/types.ts +10 -0
- package/src/index.ts +2 -1
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modul/mbui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-beta-pv-50534-962f5f9d",
|
|
4
4
|
"packageManager": "yarn@3.5.1",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build:demo": "webpack --config ./demo/webpack.config.js",
|
|
8
|
+
"dev:demo": "webpack serve --config ./demo/webpack.config.js --open",
|
|
8
9
|
"demo": "yarn dlx http-server demo/dist -so -c-1"
|
|
9
10
|
},
|
|
10
11
|
"lintConfig": "./.eslintrc.json",
|
|
@@ -12,7 +13,8 @@
|
|
|
12
13
|
"src"
|
|
13
14
|
],
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"react-datepicker": "4.16.0"
|
|
16
|
+
"react-datepicker": "4.16.0",
|
|
17
|
+
"react-imask": "7.1.3"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
18
20
|
"@babel/core": "^7.9.0",
|
|
@@ -52,7 +54,8 @@
|
|
|
52
54
|
"tslib": "^2.5.0",
|
|
53
55
|
"typescript": "4.4.4",
|
|
54
56
|
"webpack": "^5.82.1",
|
|
55
|
-
"webpack-cli": "^5.1.1"
|
|
57
|
+
"webpack-cli": "^5.1.1",
|
|
58
|
+
"webpack-dev-server": "4.15.1"
|
|
56
59
|
},
|
|
57
60
|
"peerDependencies": {
|
|
58
61
|
"classnames": "^2.3.2",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ChangeEvent, ForwardedRef } from 'react'
|
|
2
|
+
import { IMaskInput } from 'react-imask'
|
|
3
|
+
import { IInputProps } from './types'
|
|
4
|
+
|
|
5
|
+
const Input = React.forwardRef<HTMLInputElement, IInputProps>(
|
|
6
|
+
({ onChange, type = 'text', ...props }: IInputProps, ref: ForwardedRef<HTMLInputElement>) => {
|
|
7
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
|
|
8
|
+
const val = event.target.value
|
|
9
|
+
onChange?.(val, event)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<IMaskInput
|
|
14
|
+
type={type}
|
|
15
|
+
ref={ref}
|
|
16
|
+
{...props}
|
|
17
|
+
onChange={handleChange}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export default Input
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { ChangeEvent, ForwardedRef, useState } from 'react'
|
|
2
|
+
import { IMaskInput } from 'react-imask'
|
|
3
|
+
import { IInputProps } from './types'
|
|
4
|
+
|
|
5
|
+
const InputClearable = React.forwardRef<HTMLInputElement, IInputProps>(
|
|
6
|
+
({ onChange, value = '', type = 'text', ...props }: IInputProps, ref: ForwardedRef<HTMLInputElement>) => {
|
|
7
|
+
const [inputValue, setInputValue] = useState(value)
|
|
8
|
+
|
|
9
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
|
|
10
|
+
const val = event.target.value
|
|
11
|
+
setInputValue(val)
|
|
12
|
+
onChange?.(val, event)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const handleClearClick = (): void => {
|
|
16
|
+
setInputValue('')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="input_wrap_clear">
|
|
21
|
+
<IMaskInput
|
|
22
|
+
type={type}
|
|
23
|
+
ref={ref}
|
|
24
|
+
{...props}
|
|
25
|
+
value={inputValue}
|
|
26
|
+
onChange={handleChange}
|
|
27
|
+
/>
|
|
28
|
+
{inputValue && (
|
|
29
|
+
<a
|
|
30
|
+
className="input_clear icon-cancel"
|
|
31
|
+
onClick={handleClearClick}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
export default InputClearable
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ChangeEvent, ChangeEventHandler } from 'react'
|
|
2
|
+
|
|
3
|
+
type CustomChangeEventHandler = (value: string, event: ChangeEvent<HTMLInputElement>) => void
|
|
4
|
+
|
|
5
|
+
type CombinedChangeEventHandler = ChangeEventHandler<HTMLInputElement> & CustomChangeEventHandler
|
|
6
|
+
|
|
7
|
+
export interface IInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
8
|
+
onChange?: CombinedChangeEventHandler
|
|
9
|
+
mask?: string | RegExp | (string | RegExp)[] | NumberConstructor
|
|
10
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Button } from './Base/Buttons'
|
|
2
2
|
import { TextLink } from './Base/Links'
|
|
3
3
|
import { DatePicker } from './DatePicker'
|
|
4
|
+
import { Input, InputClearable } from './Base/Input'
|
|
4
5
|
|
|
5
|
-
export { Button, TextLink, DatePicker }
|
|
6
|
+
export { Button, TextLink, DatePicker, Input, InputClearable }
|