jb-textarea 3.3.2 → 3.4.0
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/README.md +10 -1
- package/index.js +1 -0
- package/package.json +4 -2
- package/react/README.md +121 -0
- package/react/dist/JBTextarea.cjs.js +95 -0
- package/react/dist/JBTextarea.cjs.js.map +1 -0
- package/react/dist/JBTextarea.js +93 -0
- package/react/dist/JBTextarea.js.map +1 -0
- package/react/dist/JBTextarea.umd.js +98 -0
- package/react/dist/JBTextarea.umd.js.map +1 -0
- package/react/dist/common/hooks/use-event.d.ts +3 -0
- package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/common/hooks/useMobx.d.ts +4 -0
- package/react/dist/common/scripts/device-detection.d.ts +1 -0
- package/react/dist/common/scripts/persian-helper.d.ts +3 -0
- package/react/dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts +42 -0
- package/react/index.js +1 -0
- package/react/lib/JBTextarea.tsx +124 -0
- package/react/package.json +35 -0
- package/react/tsconfig.json +18 -0
package/README.md
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# jb-textarea
|
|
2
2
|
|
|
3
|
+
[](https://www.webcomponents.org/element/jb-textarea)
|
|
4
|
+
[](https://raw.githubusercontent.com/javadbat/jb-textarea/master/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/jb-textarea)
|
|
6
|
+
|
|
3
7
|
simple textarea web component to input long text
|
|
4
8
|
|
|
5
9
|
- lightweight
|
|
6
10
|
- zero dependency
|
|
11
|
+
- advance validation with [jb-validation](https://github.com/javadbat/jb-validation) module
|
|
7
12
|
- help you manage validation in easy way
|
|
8
13
|
- config auto height grow ability with max height
|
|
9
14
|
- web component so you can use it with any framework you need
|
|
10
15
|
|
|
11
16
|
sample: <https://codepen.io/javadbat/pen/poRZVXe>
|
|
12
17
|
|
|
18
|
+
## using with JS frameworks
|
|
19
|
+
|
|
20
|
+
to use this component in **react** see [`jb-textarea/react`](https://github.com/javadbat/jb-textarea/tree/main/react);
|
|
21
|
+
|
|
13
22
|
## installation and setup
|
|
14
23
|
|
|
15
24
|
```bash
|
|
@@ -120,7 +129,7 @@ if you want to set a custom style to this web-component all you need is to set c
|
|
|
120
129
|
|
|
121
130
|
## Other Related Docs:
|
|
122
131
|
|
|
123
|
-
- see [jb-textarea
|
|
132
|
+
- see [`jb-textarea/react`](https://github.com/javadbat/jb-textarea/tree/main/react) if you want to use this component in react.
|
|
124
133
|
|
|
125
134
|
- see [All JB Design system Component List](https://github.com/javadbat/design-system/blob/master/docs/component-list.md) for more components.
|
|
126
135
|
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
"web component",
|
|
14
14
|
"web-component"
|
|
15
15
|
],
|
|
16
|
-
"version": "3.
|
|
16
|
+
"version": "3.4.0",
|
|
17
17
|
"bugs": "https://github.com/javadbat/jb-textarea/issues",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"files": [
|
|
20
20
|
"LICENSE",
|
|
21
21
|
"README.md",
|
|
22
22
|
"lib/",
|
|
23
|
-
"dist/"
|
|
23
|
+
"dist/",
|
|
24
|
+
"react/",
|
|
25
|
+
"react/dist/"
|
|
24
26
|
],
|
|
25
27
|
"main": "index.js",
|
|
26
28
|
"types": "./dist/web-component/jb-textarea/lib/jb-textarea.d.ts",
|
package/react/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# jb-textarea-react
|
|
2
|
+
|
|
3
|
+
simple textarea react component to input long text
|
|
4
|
+
|
|
5
|
+
- lightweight
|
|
6
|
+
- zero dependency
|
|
7
|
+
- help you manage validation in easy way
|
|
8
|
+
- config auto height grow ability with max height
|
|
9
|
+
|
|
10
|
+
Demo : [codeSandbox preview](https://3f63dj.csb.app/samples/jb-textarea) for just see the demo and [codeSandbox editor](https://codesandbox.io/p/sandbox/jb-design-system-3f63dj?file=%2Fsrc%2Fsamples%2FJBTextarea.tsx) if you want to see and play with code
|
|
11
|
+
|
|
12
|
+
## installation and setup
|
|
13
|
+
|
|
14
|
+
```cmd
|
|
15
|
+
npm i jb-textarea-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
import {JBTextarea} from 'jb-textarea/react';
|
|
20
|
+
|
|
21
|
+
<JBTextarea label="label" value={valueState} message="text under the box"></JBTextarea>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## get and set value
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
<JBTextarea label="label" value={valueState} onChange={(e)=>{setValueState(e.target.value)}}></JBTextarea>
|
|
28
|
+
```
|
|
29
|
+
## set validation
|
|
30
|
+
|
|
31
|
+
you can set validation to your input by creating a validationList array and passing in to validationList props:
|
|
32
|
+
|
|
33
|
+
``` javascript
|
|
34
|
+
const validationList = [
|
|
35
|
+
{
|
|
36
|
+
validator: /.{3}/g,
|
|
37
|
+
message: 'description must have 3 char at least'
|
|
38
|
+
},
|
|
39
|
+
//you can use function as a validator too
|
|
40
|
+
{
|
|
41
|
+
validator: (valueString)=>{return valueString == "hello"},
|
|
42
|
+
message: 'you can only type hello in the box'
|
|
43
|
+
},
|
|
44
|
+
//you can also return string in validator if you want custom error message in some edge cases
|
|
45
|
+
{
|
|
46
|
+
validator: (valueString)=>{
|
|
47
|
+
if(valueString.includes("*")){
|
|
48
|
+
return 'you cant write * in your text'
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
message: 'default error when return false'
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
```
|
|
56
|
+
```jsx
|
|
57
|
+
<JBInput validationList={validationList}></JBInput>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## check validation
|
|
61
|
+
|
|
62
|
+
you can check if an input value meet your validation standard by creating a ref of the element using `React.createRef()`.
|
|
63
|
+
```javascript
|
|
64
|
+
const elementRef = React.createRef();
|
|
65
|
+
const isValid = elementRef.current.validation.checkValidity(true).isAllValid;
|
|
66
|
+
```
|
|
67
|
+
if `isValid` is `true` the value of input is valid.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## events
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
<JBTextarea onChange={(e)=>{}}></JBTextarea>
|
|
74
|
+
<JBTextarea onKeydown={(e)=>{}}></JBTextarea>
|
|
75
|
+
<JBTextarea onKeyup={(e)=>{}}></JBTextarea>
|
|
76
|
+
<JBTextarea onKeypress={(e)=>{}}></JBTextarea>
|
|
77
|
+
<JBTextarea onInput={(e)=>{}}></JBTextarea>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## auto height grow
|
|
81
|
+
|
|
82
|
+
you can set `autoHeight` to true so when user type something and text overflow a textarea height component will grow by itself in boundary of `--jb-textarea-min-height` and `--jb-textarea-max-height` that you set by css variable
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
<JBTextarea autoHeight></JBTextarea>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
the good point of set boundary with css variable is you can set different min or max base on device by CSS media queries.
|
|
89
|
+
|
|
90
|
+
## set custom style
|
|
91
|
+
|
|
92
|
+
in some cases in your project you need to change default style of web-component for example you need zero margin or different border-radius and etc.
|
|
93
|
+
if you want to set a custom style to this web-component all you need is to set css variable in parent scope of web-component
|
|
94
|
+
| css variable name | description |
|
|
95
|
+
| ------------- | ------------- |
|
|
96
|
+
| --jb-textarea-margin | web-component margin default is `0 12px` |
|
|
97
|
+
| --jb-textarea-border-radius | web-component border-radius default is `16px` |
|
|
98
|
+
| --jb-textarea-border-width | web-component border-width default is `1px` |
|
|
99
|
+
| --jb-textarea-border-color | border color of select in normal mode |
|
|
100
|
+
| --jb-textarea-border-color-focus | border color of select in normal mode |
|
|
101
|
+
| --jb-textarea-bgcolor | background color of input |
|
|
102
|
+
| --jb-textarea-border-botton-width | border bottom thickness default is `3px` |
|
|
103
|
+
| --jb-textarea-label-font-size | font size of input label default is `0.8em` |
|
|
104
|
+
| --jb-textarea-value-font-size | font size of input value default is `1.1em` |
|
|
105
|
+
| --jb-textarea-value-color | color of value default in `initial` |
|
|
106
|
+
| --jb-textarea-message-font-size | font size of message we show under input |
|
|
107
|
+
| --jb-textarea-message-error-color | change color of error we show under input default is `red` |
|
|
108
|
+
| --jb-textarea-min-height | minimum height of text area default is `80px` |
|
|
109
|
+
| --jb-textarea-max-height | minimum height of text area default is `none` |
|
|
110
|
+
| --jb-textarea-placeholder-color | placeholder color default is 'initial' |
|
|
111
|
+
| --jb-textarea-placeholder-font-size | placeholder font-size default is `initial` |
|
|
112
|
+
| --jb-textarea-label-color | label color default is `#1f1735` |
|
|
113
|
+
| --jb-textarea-value-color | value color |
|
|
114
|
+
|
|
115
|
+
## Other Related Docs:
|
|
116
|
+
|
|
117
|
+
- see [jb-textarea](https://github.com/javadbat/jb-textarea) if you want to use this component as a web-component in other frameworks.
|
|
118
|
+
|
|
119
|
+
- see [All JB Design system Component List](https://github.com/javadbat/design-system/blob/master/docs/component-list.md) for more components.
|
|
120
|
+
|
|
121
|
+
- use [Contribution Guide](https://github.com/javadbat/design-system/blob/master/docs/contribution-guide.md) if you want to contribute in this component.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
require('jb-textarea');
|
|
5
|
+
|
|
6
|
+
function useBindEvent(ref, event, handler, passive = false) {
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const dom = ref.current;
|
|
9
|
+
if (dom) {
|
|
10
|
+
// initiate the event handler
|
|
11
|
+
dom.addEventListener(event, handler, passive);
|
|
12
|
+
}
|
|
13
|
+
// this will clean up the event every time the component is re-rendered
|
|
14
|
+
return function cleanup() {
|
|
15
|
+
if (dom) {
|
|
16
|
+
dom.removeEventListener(event, handler, passive);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}, [ref, event, handler, passive]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* eslint-disable no-inner-declarations */
|
|
23
|
+
// eslint-disable-next-line react/display-name
|
|
24
|
+
const JBTextarea = React.forwardRef((props, ref) => {
|
|
25
|
+
{
|
|
26
|
+
//we set this state so when ref change we have a render and our event listener will be updated
|
|
27
|
+
const [refChangeCount, refChangeCountSetter] = React.useState(0);
|
|
28
|
+
const element = React.useRef(null);
|
|
29
|
+
React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
refChangeCountSetter(refChangeCount + 1);
|
|
32
|
+
}, [element.current]);
|
|
33
|
+
function onChange(e) {
|
|
34
|
+
if (props.onChange) {
|
|
35
|
+
props.onChange(e);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function onKeydown(e) {
|
|
39
|
+
if (props.onKeydown) {
|
|
40
|
+
props.onKeydown(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function onInput(e) {
|
|
44
|
+
if (props.onInput) {
|
|
45
|
+
props.onInput(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function onKeyup(e) {
|
|
49
|
+
if (props.onKeyup) {
|
|
50
|
+
props.onKeyup(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function onFocus(e) {
|
|
54
|
+
if (props.onFocus && e instanceof FocusEvent) {
|
|
55
|
+
props.onFocus(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function onBlur(e) {
|
|
59
|
+
if (props.onBlur && e instanceof FocusEvent) {
|
|
60
|
+
props.onBlur(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const value = props.value || '';
|
|
65
|
+
if (element.current) {
|
|
66
|
+
element.current.value = value;
|
|
67
|
+
}
|
|
68
|
+
}, [props.value]);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (element.current) {
|
|
71
|
+
element.current.validation.list = props.validationList || [];
|
|
72
|
+
}
|
|
73
|
+
}, [props.validationList]);
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
if (element.current && props.required !== undefined) {
|
|
76
|
+
props.required ? element.current.setAttribute("required", '') : element.current.removeAttribute("required");
|
|
77
|
+
}
|
|
78
|
+
}, [props.required]);
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (element.current) {
|
|
81
|
+
element.current.autoHeight = props.autoHeight || false;
|
|
82
|
+
}
|
|
83
|
+
}, [props.autoHeight]);
|
|
84
|
+
useBindEvent(element, 'change', onChange);
|
|
85
|
+
useBindEvent(element, 'keydown', onKeydown);
|
|
86
|
+
useBindEvent(element, 'input', onInput);
|
|
87
|
+
useBindEvent(element, 'keyup', onKeyup);
|
|
88
|
+
useBindEvent(element, 'focus', onFocus);
|
|
89
|
+
useBindEvent(element, 'blur', onBlur);
|
|
90
|
+
return (React.createElement("jb-textarea", { placeholder: props.placeholder, class: props.className, style: props.style, ref: element, label: props.label, message: props.message, name: props.name }));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
exports.JBTextarea = JBTextarea;
|
|
95
|
+
//# sourceMappingURL=JBTextarea.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBTextarea.cjs.js","sources":["../../../../common/hooks/use-event.ts","../lib/JBTextarea.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom:HTMLElement, event:any, handler:any, passive = false) {\r\n useEffect(() => {\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n });\r\n}\r\nexport function useBindEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler:(e:TEvent)=>void, passive = false) {\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","/* eslint-disable no-inner-declarations */\r\nimport React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';\r\nimport 'jb-textarea';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport {JBTextareaWebComponent, type ValidationValue} from 'jb-textarea';\r\nimport { useBindEvent } from '../../../../common/hooks/use-event.js';\r\nimport { type ValidationItem } from \"jb-validation\";\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace JSX {\r\n interface IntrinsicElements {\r\n 'jb-textarea': JBTextareaType;\r\n }\r\n interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {\r\n class?:string,\r\n label?: string,\r\n name?:string,\r\n message?:string,\r\n placeholder?:string,\r\n // ref:React.RefObject<JBDateInputWebComponent>,\r\n }\r\n }\r\n}\r\n// eslint-disable-next-line react/display-name\r\nconst JBTextarea = React.forwardRef((props:JBTextareaProps, ref) => {\r\n {\r\n //we set this state so when ref change we have a render and our event listener will be updated\r\n const [refChangeCount , refChangeCountSetter] = useState(0);\r\n const element = useRef<JBTextareaWebComponent>(null);\r\n useImperativeHandle(\r\n ref,\r\n () => (element ? element.current : {}),\r\n [element],\r\n );\r\n useEffect(()=>{\r\n refChangeCountSetter(refChangeCount+1);\r\n },[element.current]);\r\n function onChange(e:JBTextareaEventType<Event>) {\r\n if (props.onChange) {\r\n props.onChange(e);\r\n }\r\n }\r\n function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeydown) {\r\n props.onKeydown(e);\r\n }\r\n }\r\n function onInput(e:JBTextareaEventType<InputEvent>) {\r\n if (props.onInput) {\r\n props.onInput(e);\r\n }\r\n }\r\n function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeyup) {\r\n props.onKeyup(e);\r\n }\r\n }\r\n function onFocus(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onFocus && e instanceof FocusEvent) {\r\n props.onFocus(e);\r\n }\r\n }\r\n function onBlur(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onBlur && e instanceof FocusEvent) {\r\n props.onBlur(e);\r\n }\r\n }\r\n useEffect(() => {\r\n const value:string = props.value || '';\r\n if(element.current){\r\n element.current.value = value;\r\n }\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.validation.list = props.validationList || [];\r\n }\r\n }, [props.validationList]);\r\n useEffect(() => {\r\n if(element.current && props.required!== undefined){\r\n props.required?element.current.setAttribute(\"required\",''):element.current.removeAttribute(\"required\");\r\n }\r\n }, [props.required]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.autoHeight = props.autoHeight || false;\r\n }\r\n }, [props.autoHeight]);\r\n useBindEvent(element, 'change', onChange);\r\n useBindEvent(element, 'keydown', onKeydown);\r\n useBindEvent(element, 'input', onInput);\r\n useBindEvent(element, 'keyup', onKeyup);\r\n useBindEvent(element, 'focus', onFocus);\r\n useBindEvent(element, 'blur', onBlur);\r\n return (\r\n <jb-textarea placeholder={props.placeholder} class={props.className} style={props.style} ref={element} label={props.label} message={props.message} name={props.name}></jb-textarea>\r\n );\r\n }\r\n});\r\nexport type JBTextareaEventType<T> = T & {\r\n target: JBTextareaWebComponent\r\n}\r\ntype JBTextareaProps = {\r\n label?: string,\r\n value?: string | null | undefined,\r\n onChange?: (e:JBTextareaEventType<Event>)=>void,\r\n onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onInput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n placeholder?:string,\r\n className?: string,\r\n style?:CSSProperties,\r\n validationList?:ValidationItem<ValidationValue>[],\r\n autoHeight?: boolean,\r\n message?:string,\r\n name?:string,\r\n required?:boolean\r\n}\r\nexport {JBTextarea};"],"names":["useEffect","useState","useRef","useImperativeHandle"],"mappings":";;;;;AAgBM,SAAU,YAAY,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAwB,EAAE,OAAO,GAAG,KAAK,EAAA;IAClJA,eAAS,CAAC,MAAK;AACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,GAAG,EAAE;;YAEP,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,SAAA;;AAED,QAAA,OAAO,SAAS,OAAO,GAAA;AACrB,YAAA,IAAG,GAAG,EAAC;gBACL,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAClD,aAAA;AACH,SAAC,CAAC;KACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,CAAC;AACjC;;AC9BA;AAuBA;AACM,MAAA,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAqB,EAAE,GAAG,KAAI;AACjE,IAAA;;QAEE,MAAM,CAAC,cAAc,EAAG,oBAAoB,CAAC,GAAGC,cAAQ,CAAC,CAAC,CAAC,CAAC;AAC5D,QAAA,MAAM,OAAO,GAAGC,YAAM,CAAyB,IAAI,CAAC,CAAC;QACrDC,yBAAmB,CACjB,GAAG,EACH,OAAO,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,EACtC,CAAC,OAAO,CAAC,CACV,CAAC;QACFH,eAAS,CAAC,MAAI;AACZ,YAAA,oBAAoB,CAAC,cAAc,GAAC,CAAC,CAAC,CAAC;AACzC,S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A,EAAA,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAA,CAAgB,EACnL;AACH,KAAA;AACH,CAAC;;;;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef, useImperativeHandle } from 'react';
|
|
2
|
+
import 'jb-textarea';
|
|
3
|
+
|
|
4
|
+
function useBindEvent(ref, event, handler, passive = false) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const dom = ref.current;
|
|
7
|
+
if (dom) {
|
|
8
|
+
// initiate the event handler
|
|
9
|
+
dom.addEventListener(event, handler, passive);
|
|
10
|
+
}
|
|
11
|
+
// this will clean up the event every time the component is re-rendered
|
|
12
|
+
return function cleanup() {
|
|
13
|
+
if (dom) {
|
|
14
|
+
dom.removeEventListener(event, handler, passive);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}, [ref, event, handler, passive]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* eslint-disable no-inner-declarations */
|
|
21
|
+
// eslint-disable-next-line react/display-name
|
|
22
|
+
const JBTextarea = React.forwardRef((props, ref) => {
|
|
23
|
+
{
|
|
24
|
+
//we set this state so when ref change we have a render and our event listener will be updated
|
|
25
|
+
const [refChangeCount, refChangeCountSetter] = useState(0);
|
|
26
|
+
const element = useRef(null);
|
|
27
|
+
useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
refChangeCountSetter(refChangeCount + 1);
|
|
30
|
+
}, [element.current]);
|
|
31
|
+
function onChange(e) {
|
|
32
|
+
if (props.onChange) {
|
|
33
|
+
props.onChange(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function onKeydown(e) {
|
|
37
|
+
if (props.onKeydown) {
|
|
38
|
+
props.onKeydown(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function onInput(e) {
|
|
42
|
+
if (props.onInput) {
|
|
43
|
+
props.onInput(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function onKeyup(e) {
|
|
47
|
+
if (props.onKeyup) {
|
|
48
|
+
props.onKeyup(e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function onFocus(e) {
|
|
52
|
+
if (props.onFocus && e instanceof FocusEvent) {
|
|
53
|
+
props.onFocus(e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function onBlur(e) {
|
|
57
|
+
if (props.onBlur && e instanceof FocusEvent) {
|
|
58
|
+
props.onBlur(e);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const value = props.value || '';
|
|
63
|
+
if (element.current) {
|
|
64
|
+
element.current.value = value;
|
|
65
|
+
}
|
|
66
|
+
}, [props.value]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (element.current) {
|
|
69
|
+
element.current.validation.list = props.validationList || [];
|
|
70
|
+
}
|
|
71
|
+
}, [props.validationList]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (element.current && props.required !== undefined) {
|
|
74
|
+
props.required ? element.current.setAttribute("required", '') : element.current.removeAttribute("required");
|
|
75
|
+
}
|
|
76
|
+
}, [props.required]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (element.current) {
|
|
79
|
+
element.current.autoHeight = props.autoHeight || false;
|
|
80
|
+
}
|
|
81
|
+
}, [props.autoHeight]);
|
|
82
|
+
useBindEvent(element, 'change', onChange);
|
|
83
|
+
useBindEvent(element, 'keydown', onKeydown);
|
|
84
|
+
useBindEvent(element, 'input', onInput);
|
|
85
|
+
useBindEvent(element, 'keyup', onKeyup);
|
|
86
|
+
useBindEvent(element, 'focus', onFocus);
|
|
87
|
+
useBindEvent(element, 'blur', onBlur);
|
|
88
|
+
return (React.createElement("jb-textarea", { placeholder: props.placeholder, class: props.className, style: props.style, ref: element, label: props.label, message: props.message, name: props.name }));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export { JBTextarea };
|
|
93
|
+
//# sourceMappingURL=JBTextarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBTextarea.js","sources":["../../../../common/hooks/use-event.ts","../lib/JBTextarea.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom:HTMLElement, event:any, handler:any, passive = false) {\r\n useEffect(() => {\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n });\r\n}\r\nexport function useBindEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler:(e:TEvent)=>void, passive = false) {\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","/* eslint-disable no-inner-declarations */\r\nimport React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';\r\nimport 'jb-textarea';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport {JBTextareaWebComponent, type ValidationValue} from 'jb-textarea';\r\nimport { useBindEvent } from '../../../../common/hooks/use-event.js';\r\nimport { type ValidationItem } from \"jb-validation\";\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace JSX {\r\n interface IntrinsicElements {\r\n 'jb-textarea': JBTextareaType;\r\n }\r\n interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {\r\n class?:string,\r\n label?: string,\r\n name?:string,\r\n message?:string,\r\n placeholder?:string,\r\n // ref:React.RefObject<JBDateInputWebComponent>,\r\n }\r\n }\r\n}\r\n// eslint-disable-next-line react/display-name\r\nconst JBTextarea = React.forwardRef((props:JBTextareaProps, ref) => {\r\n {\r\n //we set this state so when ref change we have a render and our event listener will be updated\r\n const [refChangeCount , refChangeCountSetter] = useState(0);\r\n const element = useRef<JBTextareaWebComponent>(null);\r\n useImperativeHandle(\r\n ref,\r\n () => (element ? element.current : {}),\r\n [element],\r\n );\r\n useEffect(()=>{\r\n refChangeCountSetter(refChangeCount+1);\r\n },[element.current]);\r\n function onChange(e:JBTextareaEventType<Event>) {\r\n if (props.onChange) {\r\n props.onChange(e);\r\n }\r\n }\r\n function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeydown) {\r\n props.onKeydown(e);\r\n }\r\n }\r\n function onInput(e:JBTextareaEventType<InputEvent>) {\r\n if (props.onInput) {\r\n props.onInput(e);\r\n }\r\n }\r\n function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeyup) {\r\n props.onKeyup(e);\r\n }\r\n }\r\n function onFocus(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onFocus && e instanceof FocusEvent) {\r\n props.onFocus(e);\r\n }\r\n }\r\n function onBlur(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onBlur && e instanceof FocusEvent) {\r\n props.onBlur(e);\r\n }\r\n }\r\n useEffect(() => {\r\n const value:string = props.value || '';\r\n if(element.current){\r\n element.current.value = value;\r\n }\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.validation.list = props.validationList || [];\r\n }\r\n }, [props.validationList]);\r\n useEffect(() => {\r\n if(element.current && props.required!== undefined){\r\n props.required?element.current.setAttribute(\"required\",''):element.current.removeAttribute(\"required\");\r\n }\r\n }, [props.required]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.autoHeight = props.autoHeight || false;\r\n }\r\n }, [props.autoHeight]);\r\n useBindEvent(element, 'change', onChange);\r\n useBindEvent(element, 'keydown', onKeydown);\r\n useBindEvent(element, 'input', onInput);\r\n useBindEvent(element, 'keyup', onKeyup);\r\n useBindEvent(element, 'focus', onFocus);\r\n useBindEvent(element, 'blur', onBlur);\r\n return (\r\n <jb-textarea placeholder={props.placeholder} class={props.className} style={props.style} ref={element} label={props.label} message={props.message} name={props.name}></jb-textarea>\r\n );\r\n }\r\n});\r\nexport type JBTextareaEventType<T> = T & {\r\n target: JBTextareaWebComponent\r\n}\r\ntype JBTextareaProps = {\r\n label?: string,\r\n value?: string | null | undefined,\r\n onChange?: (e:JBTextareaEventType<Event>)=>void,\r\n onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onInput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n placeholder?:string,\r\n className?: string,\r\n style?:CSSProperties,\r\n validationList?:ValidationItem<ValidationValue>[],\r\n autoHeight?: boolean,\r\n message?:string,\r\n name?:string,\r\n required?:boolean\r\n}\r\nexport {JBTextarea};"],"names":[],"mappings":";;;AAgBM,SAAU,YAAY,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAwB,EAAE,OAAO,GAAG,KAAK,EAAA;IAClJ,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,GAAG,EAAE;;YAEP,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,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,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAErB,SAAS,CAAC,MAAK;YACb,IAAG,OAAO,CAAC,OAAO,EAAC;gBACjB,OAAO,CAAC,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC;AACxD,aAAA;AACH,SAAC,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACvB,QAAA,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC1C,QAAA,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC5C,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACxC,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACxC,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACxC,QAAA,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACtC,QAAA,QACE,KAAa,CAAA,aAAA,CAAA,aAAA,EAAA,EAAA,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAA,CAAgB,EACnL;AACH,KAAA;AACH,CAAC;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('jb-textarea')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', 'jb-textarea'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBTextarea = {}, global.React));
|
|
5
|
+
})(this, (function (exports, React) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function useBindEvent(ref, event, handler, passive = false) {
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const dom = ref.current;
|
|
10
|
+
if (dom) {
|
|
11
|
+
// initiate the event handler
|
|
12
|
+
dom.addEventListener(event, handler, passive);
|
|
13
|
+
}
|
|
14
|
+
// this will clean up the event every time the component is re-rendered
|
|
15
|
+
return function cleanup() {
|
|
16
|
+
if (dom) {
|
|
17
|
+
dom.removeEventListener(event, handler, passive);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}, [ref, event, handler, passive]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* eslint-disable no-inner-declarations */
|
|
24
|
+
// eslint-disable-next-line react/display-name
|
|
25
|
+
const JBTextarea = React.forwardRef((props, ref) => {
|
|
26
|
+
{
|
|
27
|
+
//we set this state so when ref change we have a render and our event listener will be updated
|
|
28
|
+
const [refChangeCount, refChangeCountSetter] = React.useState(0);
|
|
29
|
+
const element = React.useRef(null);
|
|
30
|
+
React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
refChangeCountSetter(refChangeCount + 1);
|
|
33
|
+
}, [element.current]);
|
|
34
|
+
function onChange(e) {
|
|
35
|
+
if (props.onChange) {
|
|
36
|
+
props.onChange(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function onKeydown(e) {
|
|
40
|
+
if (props.onKeydown) {
|
|
41
|
+
props.onKeydown(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function onInput(e) {
|
|
45
|
+
if (props.onInput) {
|
|
46
|
+
props.onInput(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function onKeyup(e) {
|
|
50
|
+
if (props.onKeyup) {
|
|
51
|
+
props.onKeyup(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function onFocus(e) {
|
|
55
|
+
if (props.onFocus && e instanceof FocusEvent) {
|
|
56
|
+
props.onFocus(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function onBlur(e) {
|
|
60
|
+
if (props.onBlur && e instanceof FocusEvent) {
|
|
61
|
+
props.onBlur(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
const value = props.value || '';
|
|
66
|
+
if (element.current) {
|
|
67
|
+
element.current.value = value;
|
|
68
|
+
}
|
|
69
|
+
}, [props.value]);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (element.current) {
|
|
72
|
+
element.current.validation.list = props.validationList || [];
|
|
73
|
+
}
|
|
74
|
+
}, [props.validationList]);
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
if (element.current && props.required !== undefined) {
|
|
77
|
+
props.required ? element.current.setAttribute("required", '') : element.current.removeAttribute("required");
|
|
78
|
+
}
|
|
79
|
+
}, [props.required]);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (element.current) {
|
|
82
|
+
element.current.autoHeight = props.autoHeight || false;
|
|
83
|
+
}
|
|
84
|
+
}, [props.autoHeight]);
|
|
85
|
+
useBindEvent(element, 'change', onChange);
|
|
86
|
+
useBindEvent(element, 'keydown', onKeydown);
|
|
87
|
+
useBindEvent(element, 'input', onInput);
|
|
88
|
+
useBindEvent(element, 'keyup', onKeyup);
|
|
89
|
+
useBindEvent(element, 'focus', onFocus);
|
|
90
|
+
useBindEvent(element, 'blur', onBlur);
|
|
91
|
+
return (React.createElement("jb-textarea", { placeholder: props.placeholder, class: props.className, style: props.style, ref: element, label: props.label, message: props.message, name: props.name }));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
exports.JBTextarea = JBTextarea;
|
|
96
|
+
|
|
97
|
+
}));
|
|
98
|
+
//# sourceMappingURL=JBTextarea.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBTextarea.umd.js","sources":["../../../../common/hooks/use-event.ts","../lib/JBTextarea.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom:HTMLElement, event:any, handler:any, passive = false) {\r\n useEffect(() => {\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n });\r\n}\r\nexport function useBindEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler:(e:TEvent)=>void, passive = false) {\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, handler, passive); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, handler, passive);\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","/* eslint-disable no-inner-declarations */\r\nimport React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';\r\nimport 'jb-textarea';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport {JBTextareaWebComponent, type ValidationValue} from 'jb-textarea';\r\nimport { useBindEvent } from '../../../../common/hooks/use-event.js';\r\nimport { type ValidationItem } from \"jb-validation\";\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/no-namespace\r\n namespace JSX {\r\n interface IntrinsicElements {\r\n 'jb-textarea': JBTextareaType;\r\n }\r\n interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {\r\n class?:string,\r\n label?: string,\r\n name?:string,\r\n message?:string,\r\n placeholder?:string,\r\n // ref:React.RefObject<JBDateInputWebComponent>,\r\n }\r\n }\r\n}\r\n// eslint-disable-next-line react/display-name\r\nconst JBTextarea = React.forwardRef((props:JBTextareaProps, ref) => {\r\n {\r\n //we set this state so when ref change we have a render and our event listener will be updated\r\n const [refChangeCount , refChangeCountSetter] = useState(0);\r\n const element = useRef<JBTextareaWebComponent>(null);\r\n useImperativeHandle(\r\n ref,\r\n () => (element ? element.current : {}),\r\n [element],\r\n );\r\n useEffect(()=>{\r\n refChangeCountSetter(refChangeCount+1);\r\n },[element.current]);\r\n function onChange(e:JBTextareaEventType<Event>) {\r\n if (props.onChange) {\r\n props.onChange(e);\r\n }\r\n }\r\n function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeydown) {\r\n props.onKeydown(e);\r\n }\r\n }\r\n function onInput(e:JBTextareaEventType<InputEvent>) {\r\n if (props.onInput) {\r\n props.onInput(e);\r\n }\r\n }\r\n function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {\r\n if (props.onKeyup) {\r\n props.onKeyup(e);\r\n }\r\n }\r\n function onFocus(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onFocus && e instanceof FocusEvent) {\r\n props.onFocus(e);\r\n }\r\n }\r\n function onBlur(e:JBTextareaEventType<FocusEvent>) {\r\n if (props.onBlur && e instanceof FocusEvent) {\r\n props.onBlur(e);\r\n }\r\n }\r\n useEffect(() => {\r\n const value:string = props.value || '';\r\n if(element.current){\r\n element.current.value = value;\r\n }\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.validation.list = props.validationList || [];\r\n }\r\n }, [props.validationList]);\r\n useEffect(() => {\r\n if(element.current && props.required!== undefined){\r\n props.required?element.current.setAttribute(\"required\",''):element.current.removeAttribute(\"required\");\r\n }\r\n }, [props.required]);\r\n\r\n useEffect(() => {\r\n if(element.current){\r\n element.current.autoHeight = props.autoHeight || false;\r\n }\r\n }, [props.autoHeight]);\r\n useBindEvent(element, 'change', onChange);\r\n useBindEvent(element, 'keydown', onKeydown);\r\n useBindEvent(element, 'input', onInput);\r\n useBindEvent(element, 'keyup', onKeyup);\r\n useBindEvent(element, 'focus', onFocus);\r\n useBindEvent(element, 'blur', onBlur);\r\n return (\r\n <jb-textarea placeholder={props.placeholder} class={props.className} style={props.style} ref={element} label={props.label} message={props.message} name={props.name}></jb-textarea>\r\n );\r\n }\r\n});\r\nexport type JBTextareaEventType<T> = T & {\r\n target: JBTextareaWebComponent\r\n}\r\ntype JBTextareaProps = {\r\n label?: string,\r\n value?: string | null | undefined,\r\n onChange?: (e:JBTextareaEventType<Event>)=>void,\r\n onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,\r\n onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,\r\n onInput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,\r\n placeholder?:string,\r\n className?: string,\r\n style?:CSSProperties,\r\n validationList?:ValidationItem<ValidationValue>[],\r\n autoHeight?: boolean,\r\n message?:string,\r\n name?:string,\r\n required?:boolean\r\n}\r\nexport {JBTextarea};"],"names":["useEffect","useState","useRef","useImperativeHandle"],"mappings":";;;;;;EAgBM,SAAU,YAAY,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAwB,EAAE,OAAO,GAAG,KAAK,EAAA;MAClJA,eAAS,CAAC,MAAK;EACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;EACxB,QAAA,IAAI,GAAG,EAAE;;cAEP,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EAC/C,SAAA;;EAED,QAAA,OAAO,SAAS,OAAO,GAAA;EACrB,YAAA,IAAG,GAAG,EAAC;kBACL,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EAClD,aAAA;EACH,SAAC,CAAC;OACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CA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K,CAAC,UAAU,CAAC,CAAC,CAAC;EACvB,QAAA,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;EAC1C,QAAA,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;EAC5C,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EACxC,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EACxC,QAAA,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;EACxC,QAAA,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;EACtC,QAAA,QACE,KAAa,CAAA,aAAA,CAAA,aAAA,EAAA,EAAA,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAA,CAAgB,EACnL;EACH,KAAA;EACH,CAAC;;;;;;;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function useEvent(dom: HTMLElement, event: any, handler: any, passive?: boolean): void;
|
|
3
|
+
export declare function useBindEvent<TRef extends React.MutableRefObject<any | null>, TEvent>(ref: TRef, event: string, handler: (e: TEvent) => void, passive?: boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isMobile: () => boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import 'jb-textarea';
|
|
3
|
+
import { JBTextareaWebComponent, type ValidationValue } from 'jb-textarea';
|
|
4
|
+
import { type ValidationItem } from "jb-validation";
|
|
5
|
+
declare global {
|
|
6
|
+
namespace JSX {
|
|
7
|
+
interface IntrinsicElements {
|
|
8
|
+
'jb-textarea': JBTextareaType;
|
|
9
|
+
}
|
|
10
|
+
interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {
|
|
11
|
+
class?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare const JBTextarea: React.ForwardRefExoticComponent<JBTextareaProps & React.RefAttributes<unknown>>;
|
|
20
|
+
export type JBTextareaEventType<T> = T & {
|
|
21
|
+
target: JBTextareaWebComponent;
|
|
22
|
+
};
|
|
23
|
+
type JBTextareaProps = {
|
|
24
|
+
label?: string;
|
|
25
|
+
value?: string | null | undefined;
|
|
26
|
+
onChange?: (e: JBTextareaEventType<Event>) => void;
|
|
27
|
+
onFocus?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
28
|
+
onBlur?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
29
|
+
onKeydown?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
30
|
+
onKeyup?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
31
|
+
onInput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
32
|
+
onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
className?: string;
|
|
35
|
+
style?: CSSProperties;
|
|
36
|
+
validationList?: ValidationItem<ValidationValue>[];
|
|
37
|
+
autoHeight?: boolean;
|
|
38
|
+
message?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export { JBTextarea };
|
package/react/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/JBTextarea.js';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* eslint-disable no-inner-declarations */
|
|
2
|
+
import React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';
|
|
3
|
+
import 'jb-textarea';
|
|
4
|
+
// eslint-disable-next-line no-duplicate-imports
|
|
5
|
+
import {JBTextareaWebComponent, type ValidationValue} from 'jb-textarea';
|
|
6
|
+
import { useBindEvent } from '../../../../common/hooks/use-event.js';
|
|
7
|
+
import { type ValidationItem } from "jb-validation";
|
|
8
|
+
declare global {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
+
namespace JSX {
|
|
11
|
+
interface IntrinsicElements {
|
|
12
|
+
'jb-textarea': JBTextareaType;
|
|
13
|
+
}
|
|
14
|
+
interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {
|
|
15
|
+
class?:string,
|
|
16
|
+
label?: string,
|
|
17
|
+
name?:string,
|
|
18
|
+
message?:string,
|
|
19
|
+
placeholder?:string,
|
|
20
|
+
// ref:React.RefObject<JBDateInputWebComponent>,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line react/display-name
|
|
25
|
+
const JBTextarea = React.forwardRef((props:JBTextareaProps, ref) => {
|
|
26
|
+
{
|
|
27
|
+
//we set this state so when ref change we have a render and our event listener will be updated
|
|
28
|
+
const [refChangeCount , refChangeCountSetter] = useState(0);
|
|
29
|
+
const element = useRef<JBTextareaWebComponent>(null);
|
|
30
|
+
useImperativeHandle(
|
|
31
|
+
ref,
|
|
32
|
+
() => (element ? element.current : {}),
|
|
33
|
+
[element],
|
|
34
|
+
);
|
|
35
|
+
useEffect(()=>{
|
|
36
|
+
refChangeCountSetter(refChangeCount+1);
|
|
37
|
+
},[element.current]);
|
|
38
|
+
function onChange(e:JBTextareaEventType<Event>) {
|
|
39
|
+
if (props.onChange) {
|
|
40
|
+
props.onChange(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {
|
|
44
|
+
if (props.onKeydown) {
|
|
45
|
+
props.onKeydown(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function onInput(e:JBTextareaEventType<InputEvent>) {
|
|
49
|
+
if (props.onInput) {
|
|
50
|
+
props.onInput(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {
|
|
54
|
+
if (props.onKeyup) {
|
|
55
|
+
props.onKeyup(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function onFocus(e:JBTextareaEventType<FocusEvent>) {
|
|
59
|
+
if (props.onFocus && e instanceof FocusEvent) {
|
|
60
|
+
props.onFocus(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function onBlur(e:JBTextareaEventType<FocusEvent>) {
|
|
64
|
+
if (props.onBlur && e instanceof FocusEvent) {
|
|
65
|
+
props.onBlur(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const value:string = props.value || '';
|
|
70
|
+
if(element.current){
|
|
71
|
+
element.current.value = value;
|
|
72
|
+
}
|
|
73
|
+
}, [props.value]);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if(element.current){
|
|
77
|
+
element.current.validation.list = props.validationList || [];
|
|
78
|
+
}
|
|
79
|
+
}, [props.validationList]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if(element.current && props.required!== undefined){
|
|
82
|
+
props.required?element.current.setAttribute("required",''):element.current.removeAttribute("required");
|
|
83
|
+
}
|
|
84
|
+
}, [props.required]);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if(element.current){
|
|
88
|
+
element.current.autoHeight = props.autoHeight || false;
|
|
89
|
+
}
|
|
90
|
+
}, [props.autoHeight]);
|
|
91
|
+
useBindEvent(element, 'change', onChange);
|
|
92
|
+
useBindEvent(element, 'keydown', onKeydown);
|
|
93
|
+
useBindEvent(element, 'input', onInput);
|
|
94
|
+
useBindEvent(element, 'keyup', onKeyup);
|
|
95
|
+
useBindEvent(element, 'focus', onFocus);
|
|
96
|
+
useBindEvent(element, 'blur', onBlur);
|
|
97
|
+
return (
|
|
98
|
+
<jb-textarea placeholder={props.placeholder} class={props.className} style={props.style} ref={element} label={props.label} message={props.message} name={props.name}></jb-textarea>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
export type JBTextareaEventType<T> = T & {
|
|
103
|
+
target: JBTextareaWebComponent
|
|
104
|
+
}
|
|
105
|
+
type JBTextareaProps = {
|
|
106
|
+
label?: string,
|
|
107
|
+
value?: string | null | undefined,
|
|
108
|
+
onChange?: (e:JBTextareaEventType<Event>)=>void,
|
|
109
|
+
onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,
|
|
110
|
+
onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,
|
|
111
|
+
onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
|
|
112
|
+
onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
|
|
113
|
+
onInput?: (e:JBTextareaEventType<InputEvent>)=>void,
|
|
114
|
+
onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,
|
|
115
|
+
placeholder?:string,
|
|
116
|
+
className?: string,
|
|
117
|
+
style?:CSSProperties,
|
|
118
|
+
validationList?:ValidationItem<ValidationValue>[],
|
|
119
|
+
autoHeight?: boolean,
|
|
120
|
+
message?:string,
|
|
121
|
+
name?:string,
|
|
122
|
+
required?:boolean
|
|
123
|
+
}
|
|
124
|
+
export {JBTextarea};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jb-textarea-react",
|
|
3
|
+
"description": "textarea react component",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "mohammad javad bathaei",
|
|
7
|
+
"email": "javadbat@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"jb",
|
|
11
|
+
"jb-textarea",
|
|
12
|
+
"textarea",
|
|
13
|
+
"long input",
|
|
14
|
+
"multiline input",
|
|
15
|
+
"react component"
|
|
16
|
+
],
|
|
17
|
+
"version": "3.2.0",
|
|
18
|
+
"bugs": "https://github.com/javadbat/jb-textarea/issues",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"files": [
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"README.md",
|
|
23
|
+
"lib/",
|
|
24
|
+
"dist/"
|
|
25
|
+
],
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"types": "./dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git@github.com:javadbat/jb-textarea.git"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"jb-textarea": ">=3.2.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "."
|
|
4
|
+
},
|
|
5
|
+
"include": [
|
|
6
|
+
"../../../common/scripts/**/*.ts",
|
|
7
|
+
"../../../common/hooks/**/*.ts",
|
|
8
|
+
"../../../common/hooks/**/*.js",
|
|
9
|
+
"lib/**/*.ts",
|
|
10
|
+
"lib/**/*.tsx"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules",
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"dist",
|
|
16
|
+
],
|
|
17
|
+
"extends":"../../tsconfig-react.json"
|
|
18
|
+
}
|