jb-textarea 3.4.0 → 3.6.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 +3 -3
- package/dist/jb-textarea.cjs.js +2 -2
- package/dist/jb-textarea.cjs.js.br +0 -0
- package/dist/jb-textarea.cjs.js.gz +0 -0
- package/dist/jb-textarea.cjs.js.map +1 -1
- package/dist/jb-textarea.d.ts +38 -0
- package/dist/jb-textarea.d.ts.map +1 -0
- package/dist/jb-textarea.js +2 -2
- package/dist/jb-textarea.js.br +0 -0
- package/dist/jb-textarea.js.gz +0 -0
- package/dist/jb-textarea.js.map +1 -1
- package/dist/jb-textarea.umd.js +2 -2
- package/dist/jb-textarea.umd.js.br +0 -0
- package/dist/jb-textarea.umd.js.gz +0 -0
- package/dist/jb-textarea.umd.js.map +1 -1
- package/dist/lib/jb-textarea.d.ts +37 -0
- package/dist/lib/types.d.ts +10 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web-component/jb-textarea/lib/jb-textarea.d.ts +1 -2
- package/dist/web-component/jb-textarea/lib/types.d.ts +3 -0
- package/index.js +0 -1
- package/lib/global.d.ts +15 -0
- package/lib/jb-textarea.scss +9 -15
- package/lib/jb-textarea.ts +18 -6
- package/lib/types.ts +5 -0
- package/lib/variables.css +14 -0
- package/package.json +5 -4
- package/react/README.md +2 -2
- package/react/dist/JBTextarea.cjs.js +2 -95
- package/react/dist/JBTextarea.cjs.js.map +1 -1
- package/react/dist/JBTextarea.d.ts +36 -0
- package/react/dist/JBTextarea.js +2 -93
- package/react/dist/JBTextarea.js.map +1 -1
- package/react/dist/JBTextarea.umd.js +2 -98
- package/react/dist/JBTextarea.umd.js.map +1 -1
- package/react/dist/attributes-hook.d.ts +11 -0
- package/react/dist/events-hook.d.ts +20 -0
- package/react/dist/lib/JBTextarea.d.ts +44 -0
- package/react/dist/lib/events-hook.d.ts +20 -0
- package/react/dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts +14 -12
- package/react/dist/web-component/jb-textarea/react/lib/events-hook.d.ts +20 -0
- package/react/lib/JBTextarea.tsx +11 -85
- package/react/lib/attributes-hook.ts +45 -0
- package/react/lib/events-hook.ts +32 -0
- package/react/package.json +1 -1
- package/react/tsconfig.json +4 -5
package/react/dist/JBTextarea.js
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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
|
|
1
|
+
import e,{useEffect as r,useImperativeHandle as t,useRef as o}from"react";import"jb-textarea";import{useEvent as a}from"jb-core/react";let n=e.forwardRef((n,u)=>{{var i;let l=o(null);return t(u,()=>l?l.current:void 0,[l]),r(()=>{let e=i.value||"";l.current&&(l.current.value=e)},[(i=n).value]),r(()=>{l.current&&(l.current.validation.list=i.validationList||[])},[i.validationList]),r(()=>{l.current&&void 0!==i.required&&(i.required?l.current.setAttribute("required",""):l.current.removeAttribute("required"))},[i.required]),r(()=>{l.current&&(l.current.autoHeight=i.autoHeight||!1)},[i.autoHeight]),r(()=>{i.error?l?.current?.setAttribute("error",i.error):l?.current?.removeAttribute("error")},[i.error]),a(l,"load",n.onLoad,!0),a(l,"init",n.onInit,!0),a(l,"change",n.onChange),a(l,"keydown",n.onKeyDown),a(l,"input",n.onInput),a(l,"keyup",n.onKeyUp),a(l,"focus",n.onFocus),a(l,"blur",n.onBlur),e.createElement("jb-textarea",{placeholder:n.placeholder,class:n.className,style:n.style,ref:l,label:n.label,message:n.message,name:n.name})}});export{n as JBTextarea};
|
|
2
|
+
//# sourceMappingURL=JBTextarea.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JBTextarea.js","sources":["
|
|
1
|
+
{"version":3,"file":"JBTextarea.js","names":[],"sources":["../lib/events-hook.ts","../lib/attributes-hook.ts","../lib/JBTextarea.tsx"],"sourcesContent":["","",""],"mappings":";;;;;AAsBM,SAAU,UAAU,SAA4C,OAAiB;AACrF,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,UAAU,MAAM,SAAS;AAC3C,UAAS,SAAS,WAAW,MAAM,UAAU;AAC7C,UAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,UAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,UAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,UAAS,SAAS,QAAQ,MAAM,OAAO;AACzC;;;;ACpBM,SAAU,uBAAuB,SAA4C,OAA2B;AAE5G,WAAU,MAAG;EACX,MAAM,QAAe,MAAM,SAAS;AACpC,MAAG,QAAQ,QACT,SAAQ,QAAQ,QAAQ;CAE3B,GAAE,CAEH,MAAU;WAEN,MAAA;AACF,MAAA,QAAA,QACE,SAAM,QAAc,WAAE,OAAA,MAAA,kBAAA,CAAA;WAGtB;AAEJ,WAAU,MAAA;AAEV,MAAA,QAAe,WAAA,MAAA,aAAA,UACV,OAAA,WAAgB,QAAA,QAAA,aAAA,YAAA,GAAA,GAAA,QAAA,QAAA,gBAAA,WAAA;KAGjB,MAAM,QAEV,EAAA;WACM,MAAM;MACR,QAAO,QACT,SAAA,QAAA,aAAA,MAAA,cAAA;KAEA,MAAA,UACD,EAAA;AACH,WAAA,MAAA;;;;;;;;ACrBA,MAAA,2BAAA,MAAA,WAAA,CAAA,OAAA,QAAA;CACA;EAEI,MAAA,UAAA,OAAA,KAAA;AACA,sBAAgB,KAA+B,MAAK,UAAA,QAAA,UAAA,WAAA,CACpD,OAKA,EAAA;AACA,yBAAkB,SAAM,MAAA;AACxB,YACE,SAAA,MAAA;AAEJ,uBAAA,MAAA,cAAA,eAAA;GACA,aAAA,MAAA;GAUM,OAAU,MAAC"}
|
|
@@ -1,98 +1,2 @@
|
|
|
1
|
-
(function (
|
|
2
|
-
|
|
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
|
|
1
|
+
var e,t;e=this,t=function(e,t,r,u){"use strict";var n=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,c=Object.getPrototypeOf,i=Object.prototype.hasOwnProperty,s=(e,t,r,u)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var n,c=l(t),s=0,f=c.length;s<f;s++)n=c[s],i.call(e,n)||n===r||a(e,n,{get:(e=>t[e]).bind(null,n),enumerable:!(u=o(t,n))||u.enumerable});return e},f=(e,t,r)=>(r=null!=e?n(c(e)):{},s(!t&&e&&e.__esModule?r:a(r,"default",{value:e,enumerable:!0}),e));t=f(t),u=f(u);let d=t.default.forwardRef((e,r)=>{{let n=(0,t.useRef)(null);return(0,t.useImperativeHandle)(r,()=>n?n.current:void 0,[n]),(0,t.useEffect)(()=>{let t=e.value||"";n.current&&(n.current.value=t)},[e.value]),(0,t.useEffect)(()=>{n.current&&(n.current.validation.list=e.validationList||[])},[e.validationList]),(0,t.useEffect)(()=>{n.current&&void 0!==e.required&&(e.required?n.current.setAttribute("required",""):n.current.removeAttribute("required"))},[e.required]),(0,t.useEffect)(()=>{n.current&&(n.current.autoHeight=e.autoHeight||!1)},[e.autoHeight]),(0,t.useEffect)(()=>{e.error?n?.current?.setAttribute("error",e.error):n?.current?.removeAttribute("error")},[e.error]),(0,u.useEvent)(n,"load",e.onLoad,!0),(0,u.useEvent)(n,"init",e.onInit,!0),(0,u.useEvent)(n,"change",e.onChange),(0,u.useEvent)(n,"keydown",e.onKeyDown),(0,u.useEvent)(n,"input",e.onInput),(0,u.useEvent)(n,"keyup",e.onKeyUp),(0,u.useEvent)(n,"focus",e.onFocus),(0,u.useEvent)(n,"blur",e.onBlur),t.default.createElement("jb-textarea",{placeholder:e.placeholder,class:e.className,style:e.style,ref:n,label:e.label,message:e.message,name:e.name})}});e.JBTextarea=d},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("jb-textarea"),require("jb-core/react")):"function"==typeof define&&define.amd?define(["exports","react","jb-textarea","jb-core/react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBTextareaReact={},e.React,e.JBTextarea,e.JBCoreReact);
|
|
2
|
+
//# sourceMappingURL=JBTextarea.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JBTextarea.umd.js","sources":["
|
|
1
|
+
{"version":3,"file":"JBTextarea.umd.js","names":[],"sources":["../lib/events-hook.ts","../lib/attributes-hook.ts","../lib/JBTextarea.tsx"],"sourcesContent":["","",""],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBM,SAAU,UAAU,SAA4C,OAAiB;AACrF,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,UAAU,MAAM,SAAS;AAC3C,6BAAS,SAAS,WAAW,MAAM,UAAU;AAC7C,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,QAAQ,MAAM,OAAO;AACzC;;;;ACpBM,SAAU,uBAAuB,SAA4C,OAA2B;AAE5G,sBAAU,MAAG;EACX,MAAM,QAAe,MAAM,SAAS;AACpC,MAAG,QAAQ,QACT,SAAQ,QAAQ,QAAQ;CAE3B,GAAE,CAEH,MAAU;sBAEN,MAAA;AACF,MAAA,QAAA,QACE,SAAM,QAAc,WAAE,OAAA,MAAA,kBAAA,CAAA;WAGtB;AAEJ,sBAAU,MAAA;AAEV,MAAA,QAAe,WAAA,MAAA,aAAA,UACV,OAAA,WAAgB,QAAA,QAAA,aAAA,YAAA,GAAA,GAAA,QAAA,QAAA,gBAAA,WAAA;KAGjB,MAAM,QAEV,EAAA;sBACM,MAAM;MACR,QAAO,QACT,SAAA,QAAA,aAAA,MAAA,cAAA;KAEA,MAAA,UACD,EAAA;AACH,sBAAA,MAAA;;;;;;;;ACrBA,MAAA,2BAAA,cAAA,WAAA,CAAA,OAAA,QAAA;CACA;EAEI,MAAA,UAAA,kBAAA,KAAA;AACA,iCAAgB,KAA+B,MAAK,UAAA,QAAA,UAAA,WAAA,CACpD,OAKA,EAAA;AACA,yBAAkB,SAAM,MAAA;AACxB,YACE,SAAA,MAAA;AAEJ,uBAAA,cAAA,cAAA,eAAA;GACA,aAAA,MAAA;GAUM,OAAU,MAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JBTextareaWebComponent, type ValidationValue } from "jb-textarea";
|
|
2
|
+
import { type ValidationItem } from "jb-validation";
|
|
3
|
+
import { RefObject } from "react";
|
|
4
|
+
export type JBTextareaAttributes = {
|
|
5
|
+
value?: string | null | undefined;
|
|
6
|
+
validationList?: ValidationItem<ValidationValue>[];
|
|
7
|
+
autoHeight?: boolean;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function useJBTextareaAttribute(element: RefObject<JBTextareaWebComponent>, props: JBTextareaAttributes): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBTextareaWebComponent, JBTextareaEventType } from 'jb-textarea';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
12
|
+
onChange?: (e: JBTextareaEventType<Event>) => void;
|
|
13
|
+
onFocus?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
14
|
+
onBlur?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
15
|
+
onKeyDown?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
16
|
+
onKeyUp?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
17
|
+
onInput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
18
|
+
onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function useEvents(element: RefObject<JBTextareaWebComponent>, props: EventProps): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
import { EventProps } from './events-hook.js';
|
|
6
|
+
declare global {
|
|
7
|
+
namespace JSX {
|
|
8
|
+
interface IntrinsicElements {
|
|
9
|
+
'jb-textarea': JBTextareaType;
|
|
10
|
+
}
|
|
11
|
+
interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {
|
|
12
|
+
class?: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
message?: string;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare const JBTextarea: React.ForwardRefExoticComponent<EventProps & {
|
|
21
|
+
label?: string;
|
|
22
|
+
value?: string | null | undefined;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
validationList?: ValidationItem<ValidationValue>[];
|
|
27
|
+
autoHeight?: boolean;
|
|
28
|
+
message?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
} & React.RefAttributes<unknown>>;
|
|
32
|
+
export type Props = EventProps & {
|
|
33
|
+
label?: string;
|
|
34
|
+
value?: string | null | undefined;
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
validationList?: ValidationItem<ValidationValue>[];
|
|
39
|
+
autoHeight?: boolean;
|
|
40
|
+
message?: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
required?: boolean;
|
|
43
|
+
};
|
|
44
|
+
export { JBTextarea };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBTextareaWebComponent, JBTextareaEventType } from 'jb-textarea';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
12
|
+
onChange?: (e: JBTextareaEventType<Event>) => void;
|
|
13
|
+
onFocus?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
14
|
+
onBlur?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
15
|
+
onKeyDown?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
16
|
+
onKeyUp?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
17
|
+
onInput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
18
|
+
onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function useEvents(element: RefObject<JBTextareaWebComponent>, props: EventProps): void;
|
|
@@ -2,6 +2,7 @@ import React, { CSSProperties } from 'react';
|
|
|
2
2
|
import 'jb-textarea';
|
|
3
3
|
import { JBTextareaWebComponent, type ValidationValue } from 'jb-textarea';
|
|
4
4
|
import { type ValidationItem } from "jb-validation";
|
|
5
|
+
import { EventProps } from './events-hook.js';
|
|
5
6
|
declare global {
|
|
6
7
|
namespace JSX {
|
|
7
8
|
interface IntrinsicElements {
|
|
@@ -16,20 +17,21 @@ declare global {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
declare const JBTextarea: React.ForwardRefExoticComponent<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
declare const JBTextarea: React.ForwardRefExoticComponent<EventProps & {
|
|
21
|
+
label?: string;
|
|
22
|
+
value?: string | null | undefined;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
validationList?: ValidationItem<ValidationValue>[];
|
|
27
|
+
autoHeight?: boolean;
|
|
28
|
+
message?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
} & React.RefAttributes<unknown>>;
|
|
32
|
+
export type Props = EventProps & {
|
|
24
33
|
label?: string;
|
|
25
34
|
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
35
|
placeholder?: string;
|
|
34
36
|
className?: string;
|
|
35
37
|
style?: CSSProperties;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBTextareaWebComponent, JBTextareaEventType } from 'jb-textarea';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBTextareaEventType<CustomEvent>) => void;
|
|
12
|
+
onChange?: (e: JBTextareaEventType<Event>) => void;
|
|
13
|
+
onFocus?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
14
|
+
onBlur?: (e: JBTextareaEventType<FocusEvent>) => void;
|
|
15
|
+
onKeyDown?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
16
|
+
onKeyUp?: (e: JBTextareaEventType<KeyboardEvent>) => void;
|
|
17
|
+
onInput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
18
|
+
onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare function useEvents(element: RefObject<JBTextareaWebComponent>, props: EventProps): void;
|
package/react/lib/JBTextarea.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-inner-declarations */
|
|
2
|
-
import React, { useRef,
|
|
2
|
+
import React, { useRef, useImperativeHandle, CSSProperties } from 'react';
|
|
3
3
|
import 'jb-textarea';
|
|
4
4
|
// eslint-disable-next-line no-duplicate-imports
|
|
5
|
-
import {JBTextareaWebComponent
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import {JBTextareaWebComponent} from 'jb-textarea';
|
|
6
|
+
import { EventProps, useEvents } from './events-hook.js';
|
|
7
|
+
import { JBTextareaAttributes, useJBTextareaAttribute } from './attributes-hook.js';
|
|
8
8
|
declare global {
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
10
|
namespace JSX {
|
|
@@ -22,103 +22,29 @@ declare global {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
// eslint-disable-next-line react/display-name
|
|
25
|
-
const JBTextarea = React.forwardRef((props:
|
|
25
|
+
const JBTextarea = React.forwardRef((props:Props, ref) => {
|
|
26
26
|
{
|
|
27
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
28
|
const element = useRef<JBTextareaWebComponent>(null);
|
|
30
29
|
useImperativeHandle(
|
|
31
30
|
ref,
|
|
32
|
-
() => (element ? element.current :
|
|
31
|
+
() => (element ? element.current : undefined),
|
|
33
32
|
[element],
|
|
34
33
|
);
|
|
35
|
-
|
|
36
|
-
|
|
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);
|
|
34
|
+
useJBTextareaAttribute(element, props);
|
|
35
|
+
useEvents(element,props);
|
|
97
36
|
return (
|
|
98
37
|
<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
38
|
);
|
|
100
39
|
}
|
|
101
40
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
type JBTextareaProps = {
|
|
41
|
+
|
|
42
|
+
export type Props = EventProps & JBTextareaAttributes & {
|
|
106
43
|
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
44
|
placeholder?:string,
|
|
116
45
|
className?: string,
|
|
117
|
-
style?:CSSProperties,
|
|
118
|
-
validationList?:ValidationItem<ValidationValue>[],
|
|
119
|
-
autoHeight?: boolean,
|
|
120
46
|
message?:string,
|
|
47
|
+
style?:CSSProperties,
|
|
121
48
|
name?:string,
|
|
122
|
-
required?:boolean
|
|
123
49
|
}
|
|
124
50
|
export {JBTextarea};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { JBTextareaWebComponent, type ValidationValue } from "jb-textarea";
|
|
2
|
+
import { type ValidationItem } from "jb-validation";
|
|
3
|
+
import { RefObject, useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
export type JBTextareaAttributes = {
|
|
6
|
+
value?: string | null | undefined,
|
|
7
|
+
validationList?:ValidationItem<ValidationValue>[],
|
|
8
|
+
autoHeight?: boolean,
|
|
9
|
+
required?:boolean
|
|
10
|
+
error?: string,
|
|
11
|
+
}
|
|
12
|
+
export function useJBTextareaAttribute(element: RefObject<JBTextareaWebComponent>, props: JBTextareaAttributes) {
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const value:string = props.value || '';
|
|
16
|
+
if(element.current){
|
|
17
|
+
element.current.value = value;
|
|
18
|
+
}
|
|
19
|
+
}, [props.value]);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if(element.current){
|
|
23
|
+
element.current.validation.list = props.validationList || [];
|
|
24
|
+
}
|
|
25
|
+
}, [props.validationList]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if(element.current && props.required!== undefined){
|
|
28
|
+
props.required?element.current.setAttribute("required",''):element.current.removeAttribute("required");
|
|
29
|
+
}
|
|
30
|
+
}, [props.required]);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if(element.current){
|
|
34
|
+
element.current.autoHeight = props.autoHeight || false;
|
|
35
|
+
}
|
|
36
|
+
}, [props.autoHeight]);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (props.error) {
|
|
40
|
+
element?.current?.setAttribute('error', props.error);
|
|
41
|
+
} else {
|
|
42
|
+
element?.current?.removeAttribute('error');
|
|
43
|
+
}
|
|
44
|
+
}, [props.error]);
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEvent } from "jb-core/react";
|
|
2
|
+
import { RefObject } from "react";
|
|
3
|
+
import type { JBTextareaWebComponent, JBTextareaEventType } from 'jb-textarea';
|
|
4
|
+
|
|
5
|
+
export type EventProps = {
|
|
6
|
+
/**
|
|
7
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
8
|
+
*/
|
|
9
|
+
onLoad?: (e: JBTextareaEventType<CustomEvent>) => void,
|
|
10
|
+
/**
|
|
11
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
12
|
+
*/
|
|
13
|
+
onInit?: (e: JBTextareaEventType<CustomEvent>) => void,
|
|
14
|
+
onChange?: (e: JBTextareaEventType<Event>) => void,
|
|
15
|
+
onFocus?: (e: JBTextareaEventType<FocusEvent>) => void,
|
|
16
|
+
onBlur?: (e: JBTextareaEventType<FocusEvent>) => void,
|
|
17
|
+
onKeyDown?: (e: JBTextareaEventType<KeyboardEvent>) => void,
|
|
18
|
+
onKeyUp?: (e: JBTextareaEventType<KeyboardEvent>) => void,
|
|
19
|
+
onInput?: (e: JBTextareaEventType<InputEvent>) => void,
|
|
20
|
+
onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void,
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
export function useEvents(element: RefObject<JBTextareaWebComponent>, props: EventProps) {
|
|
24
|
+
useEvent(element, 'load', props.onLoad, true);
|
|
25
|
+
useEvent(element, 'init', props.onInit, true);
|
|
26
|
+
useEvent(element, 'change', props.onChange);
|
|
27
|
+
useEvent(element, 'keydown', props.onKeyDown);
|
|
28
|
+
useEvent(element, 'input', props.onInput);
|
|
29
|
+
useEvent(element, 'keyup', props.onKeyUp);
|
|
30
|
+
useEvent(element, 'focus', props.onFocus);
|
|
31
|
+
useEvent(element, 'blur', props.onBlur);
|
|
32
|
+
}
|
package/react/package.json
CHANGED