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.
Files changed (47) hide show
  1. package/README.md +3 -3
  2. package/dist/jb-textarea.cjs.js +2 -2
  3. package/dist/jb-textarea.cjs.js.br +0 -0
  4. package/dist/jb-textarea.cjs.js.gz +0 -0
  5. package/dist/jb-textarea.cjs.js.map +1 -1
  6. package/dist/jb-textarea.d.ts +38 -0
  7. package/dist/jb-textarea.d.ts.map +1 -0
  8. package/dist/jb-textarea.js +2 -2
  9. package/dist/jb-textarea.js.br +0 -0
  10. package/dist/jb-textarea.js.gz +0 -0
  11. package/dist/jb-textarea.js.map +1 -1
  12. package/dist/jb-textarea.umd.js +2 -2
  13. package/dist/jb-textarea.umd.js.br +0 -0
  14. package/dist/jb-textarea.umd.js.gz +0 -0
  15. package/dist/jb-textarea.umd.js.map +1 -1
  16. package/dist/lib/jb-textarea.d.ts +37 -0
  17. package/dist/lib/types.d.ts +10 -0
  18. package/dist/types.d.ts +11 -0
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/web-component/jb-textarea/lib/jb-textarea.d.ts +1 -2
  21. package/dist/web-component/jb-textarea/lib/types.d.ts +3 -0
  22. package/index.js +0 -1
  23. package/lib/global.d.ts +15 -0
  24. package/lib/jb-textarea.scss +9 -15
  25. package/lib/jb-textarea.ts +18 -6
  26. package/lib/types.ts +5 -0
  27. package/lib/variables.css +14 -0
  28. package/package.json +5 -4
  29. package/react/README.md +2 -2
  30. package/react/dist/JBTextarea.cjs.js +2 -95
  31. package/react/dist/JBTextarea.cjs.js.map +1 -1
  32. package/react/dist/JBTextarea.d.ts +36 -0
  33. package/react/dist/JBTextarea.js +2 -93
  34. package/react/dist/JBTextarea.js.map +1 -1
  35. package/react/dist/JBTextarea.umd.js +2 -98
  36. package/react/dist/JBTextarea.umd.js.map +1 -1
  37. package/react/dist/attributes-hook.d.ts +11 -0
  38. package/react/dist/events-hook.d.ts +20 -0
  39. package/react/dist/lib/JBTextarea.d.ts +44 -0
  40. package/react/dist/lib/events-hook.d.ts +20 -0
  41. package/react/dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts +14 -12
  42. package/react/dist/web-component/jb-textarea/react/lib/events-hook.d.ts +20 -0
  43. package/react/lib/JBTextarea.tsx +11 -85
  44. package/react/lib/attributes-hook.ts +45 -0
  45. package/react/lib/events-hook.ts +32 -0
  46. package/react/package.json +1 -1
  47. package/react/tsconfig.json +4 -5
@@ -1,93 +1,2 @@
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
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":["../../../../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,SAAA;;AAED,QAAA,OAAO,SAAS,OAAO,GAAA;AACrB,YAAA,IAAG,GAAG,EAAC;gBACL,GAAG,CAAC,m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C,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 (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
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":["../../../../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,G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EJ,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<JBTextareaProps & React.RefAttributes<unknown>>;
20
- export type JBTextareaEventType<T> = T & {
21
- target: JBTextareaWebComponent;
22
- };
23
- type JBTextareaProps = {
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;
@@ -1,10 +1,10 @@
1
1
  /* eslint-disable no-inner-declarations */
2
- import React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';
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, type ValidationValue} from 'jb-textarea';
6
- import { useBindEvent } from '../../../../common/hooks/use-event.js';
7
- import { type ValidationItem } from "jb-validation";
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:JBTextareaProps, ref) => {
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
- 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);
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
- export type JBTextareaEventType<T> = T & {
103
- target: JBTextareaWebComponent
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
+ }
@@ -24,7 +24,7 @@
24
24
  "dist/"
25
25
  ],
26
26
  "main": "index.js",
27
- "types": "./dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts",
27
+ "types": "./dist/JBTextarea.d.ts",
28
28
  "repository": {
29
29
  "type": "git",
30
30
  "url": "git@github.com:javadbat/jb-textarea.git"