jb-textarea 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 javad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # jb-textarea-react
2
+
3
+ simple textarea react component to input long text
4
+
5
+ - lightweight
6
+ - zero dependancy
7
+ - help you manage validation in easy way
8
+ - config auto height grow ability with max height
9
+
10
+ sample: <https://codepen.io/javadbat/pen/poRZVXe>
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
+ <JBTextarea label="label" value={valueState} message="text under the box"></JBTextarea>
21
+ ```
22
+
23
+ ## get and set value
24
+
25
+ ```jsx
26
+ <JBTextarea label="label" value={valueState} onChange={(e)=>{setValueState(e.target.value)}}></JBTextarea>
27
+ ```
28
+
29
+ ### events
30
+
31
+ ```js
32
+ <JBTextarea onChange={(e)=>{}}></JBTextarea>
33
+ <JBTextarea onKeydown={(e)=>{}}></JBTextarea>
34
+ <JBTextarea onKeyup={(e)=>{}}></JBTextarea>
35
+ <JBTextarea onKeypress={(e)=>{}}></JBTextarea>
36
+ ```
37
+
38
+ ### auto height grow
39
+
40
+ 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
41
+
42
+ ```js
43
+ <JBTextarea autoHeight></JBTextarea>
44
+ ```
45
+
46
+ the good point of set boundary with css variable is you can set different min or max base on device by CSS media queries.
47
+
48
+ ### set custome style
49
+
50
+ in some cases in your project you need to change defualt style of web-component for example you need zero margin or different border-radius and etc.
51
+ 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
52
+ | css variable name | description |
53
+ | ------------- | ------------- |
54
+ | --jb-textarea-margin | web-component margin defualt is `0 12px` |
55
+ | --jb-textarea-border-radius | web-component border-radius defualt is `16px` |
56
+ | --jb-textarea-border-width | web-component border-width defualt is `1px` |
57
+ | --jb-textarea-border-color | border color of select in normal mode |
58
+ | --jb-textarea-border-color-focus | border color of select in normal mode |
59
+ | --jb-textarea-bgcolor | background color of input |
60
+ | --jb-textarea-border-botton-width | border bottom thickness desualt is `3px` |
61
+ | --jb-textarea-label-font-size | font size of input label defualt is `0.8em` |
62
+ | --jb-textarea-value-font-size | font size of input value defualt is `1.1em` |
63
+ | --jb-textarea-value-color | color of value defualt in `initial` |
64
+ | --jb-textarea-message-font-size | font size of message we show under input |
65
+ | --jb-textarea-message-error-color | change color of error we show under input defualt is `red` |
66
+ | --jb-textarea-min-height | minimum height of text area defualt is `80px` |
67
+ | --jb-textarea-max-height | minimum height of text area defualt is `none` |
68
+ | --jb-textarea-placeholder-color | placeholder color defualt is 'initial' |
69
+ | --jb-textarea-placeholder-font-size | placeholder font-size defualt is `initial` |
70
+ | --jb-textarea-label-color | label color defualt is `#1f1735` |
71
+ | --jb-textarea-value-color | value color |
@@ -0,0 +1,82 @@
1
+ import React, { useEffect, useState, useRef, useImperativeHandle } from 'react';
2
+ import 'jb-textarea';
3
+
4
+ function useEvent(dom, event, handler) {
5
+ var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
6
+ useEffect(function () {
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
+ });
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 onKeyup(e) {
42
+ if (props.onKeyup) {
43
+ props.onKeyup(e);
44
+ }
45
+ }
46
+ function onFocus(e) {
47
+ if (props.onFocus && e instanceof FocusEvent) {
48
+ props.onFocus(e);
49
+ }
50
+ }
51
+ function onBlur(e) {
52
+ if (props.onBlur && e instanceof FocusEvent) {
53
+ props.onBlur(e);
54
+ }
55
+ }
56
+ useEffect(() => {
57
+ const value = props.value || '';
58
+ if (element.current) {
59
+ element.current.value = value;
60
+ }
61
+ }, [props.value]);
62
+ useEffect(() => {
63
+ if (element.current) {
64
+ element.current.validationList = props.validationList || [];
65
+ }
66
+ }, [props.validationList]);
67
+ useEffect(() => {
68
+ if (element.current) {
69
+ element.current.autoHeight = props.autoHeight || false;
70
+ }
71
+ }, [props.autoHeight]);
72
+ useEvent(element.current, 'change', onChange);
73
+ useEvent(element.current, 'keydown', onKeydown);
74
+ useEvent(element.current, 'keyup', onKeyup);
75
+ useEvent(element.current, 'focus', onFocus);
76
+ useEvent(element.current, 'blur', onBlur);
77
+ return (React.createElement("jb-textarea", { placeholder: props.placeholder, class: props.className, ref: element, label: props.label, message: props.message }));
78
+ }
79
+ });
80
+
81
+ export { JBTextarea };
82
+ //# sourceMappingURL=JBTextArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JBTextArea.js","sources":["../../custom-hooks/UseEvent.js","../lib/JBTextArea.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom, event, handler, 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}","/* eslint-disable no-inner-declarations */\r\nimport React, { useRef, useEffect, useImperativeHandle, useState } from 'react';\r\nimport 'jb-textarea';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport {JBTextareaValidationItem, JBTextareaWebComponent} from 'jb-textarea';\r\nimport { useEvent } from '../../custom-hooks/UseEvent';\r\n\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 // 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 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.validationList = props.validationList || [];\r\n }\r\n }, [props.validationList]);\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 useEvent(element.current, 'change', onChange);\r\n useEvent(element.current, 'keydown', onKeydown);\r\n useEvent(element.current, 'keyup', onKeyup);\r\n useEvent(element.current, 'focus', onFocus);\r\n useEvent(element.current, 'blur', onBlur);\r\n return (\r\n <jb-textarea placeholder={props.placeholder} class={props.className} ref={element} label={props.label} message={props.message}></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,\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 validationList?:JBTextareaValidationItem[],\r\n autoHeight?: boolean,\r\n message?:string\r\n}\r\nexport {JBTextarea};"],"names":["useEvent","dom","event","handler","passive","arguments","length","undefined","useEffect","addEventListener","cleanup","removeEventListener"],"mappings":";;;AAEO,SAASA,QAAQA,CAACC,GAAG,EAAEC,KAAK,EAAEC,OAAO,EAAmB;AAAA,EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,KAAK,CAAA;AACzDG,EAAAA,SAAS,CAAC,YAAM;AACZ,IAAA,IAAIP,GAAG,EAAE;AACL;MACAA,GAAG,CAACQ,gBAAgB,CAACP,KAAK,EAAEC,OAAO,EAAEC,OAAO,CAAC,CAAA;AACjD,KAAA;AACA;IACA,OAAO,SAASM,OAAOA,GAAG;AACtB,MAAA,IAAGT,GAAG,EAAC;QACHA,GAAG,CAACU,mBAAmB,CAACT,KAAK,EAAEC,OAAO,EAAEC,OAAO,CAAC,CAAA;AACpD,OAAA;KACH,CAAA;AACL,GAAC,CAAC,CAAA;AACN;;ACfA;AAsBA;AACM,MAAA,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,KAAqB,EAAE,GAAG,KAAI;AAC/D,IAAA;;QAEI,MAAM,CAAC,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B,EAC/I;AACL,KAAA;AACL,CAAC;;;;"}
@@ -0,0 +1,93 @@
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 _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
+
11
+ function useEvent(dom, event, handler) {
12
+ var passive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
13
+ React.useEffect(function () {
14
+ if (dom) {
15
+ // initiate the event handler
16
+ dom.addEventListener(event, handler, passive);
17
+ }
18
+ // this will clean up the event every time the component is re-rendered
19
+ return function cleanup() {
20
+ if (dom) {
21
+ dom.removeEventListener(event, handler, passive);
22
+ }
23
+ };
24
+ });
25
+ }
26
+
27
+ /* eslint-disable no-inner-declarations */
28
+ // eslint-disable-next-line react/display-name
29
+ const JBTextarea = React__default["default"].forwardRef((props, ref) => {
30
+ {
31
+ //we set this state so when ref change we have a render and our event listener will be updated
32
+ const [refChangeCount, refChangeCountSetter] = React.useState(0);
33
+ const element = React.useRef(null);
34
+ React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
35
+ React.useEffect(() => {
36
+ refChangeCountSetter(refChangeCount + 1);
37
+ }, [element.current]);
38
+ function onChange(e) {
39
+ if (props.onChange) {
40
+ props.onChange(e);
41
+ }
42
+ }
43
+ function onKeydown(e) {
44
+ if (props.onKeydown) {
45
+ props.onKeydown(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.validationList = props.validationList || [];
72
+ }
73
+ }, [props.validationList]);
74
+ React.useEffect(() => {
75
+ if (element.current) {
76
+ element.current.autoHeight = props.autoHeight || false;
77
+ }
78
+ }, [props.autoHeight]);
79
+ useEvent(element.current, 'change', onChange);
80
+ useEvent(element.current, 'keydown', onKeydown);
81
+ useEvent(element.current, 'keyup', onKeyup);
82
+ useEvent(element.current, 'focus', onFocus);
83
+ useEvent(element.current, 'blur', onBlur);
84
+ return (React__default["default"].createElement("jb-textarea", { placeholder: props.placeholder, class: props.className, ref: element, label: props.label, message: props.message }));
85
+ }
86
+ });
87
+
88
+ exports.JBTextarea = JBTextarea;
89
+
90
+ Object.defineProperty(exports, '__esModule', { value: true });
91
+
92
+ }));
93
+ //# sourceMappingURL=JBTextArea.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JBTextArea.umd.js","sources":["../../custom-hooks/UseEvent.js","../lib/JBTextArea.tsx"],"sourcesContent":["import { useEffect } from \"react\";\r\n\r\nexport function useEvent(dom, event, handler, 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}","/* eslint-disable no-inner-declarations */\r\nimport React, { useRef, useEffect, useImperativeHandle, useState } from 'react';\r\nimport 'jb-textarea';\r\n// eslint-disable-next-line no-duplicate-imports\r\nimport {JBTextareaValidationItem, JBTextareaWebComponent} from 'jb-textarea';\r\nimport { useEvent } from '../../custom-hooks/UseEvent';\r\n\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 // 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 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.validationList = props.validationList || [];\r\n }\r\n }, [props.validationList]);\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 useEvent(element.current, 'change', onChange);\r\n useEvent(element.current, 'keydown', onKeydown);\r\n useEvent(element.current, 'keyup', onKeyup);\r\n useEvent(element.current, 'focus', onFocus);\r\n useEvent(element.current, 'blur', onBlur);\r\n return (\r\n <jb-textarea placeholder={props.placeholder} class={props.className} ref={element} label={props.label} message={props.message}></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,\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 validationList?:JBTextareaValidationItem[],\r\n autoHeight?: boolean,\r\n message?:string\r\n}\r\nexport {JBTextarea};"],"names":["useEvent","dom","event","handler","passive","arguments","length","undefined","useEffect","addEventListener","cleanup","removeEventListener","React","useState","useRef","useImperativeHandle"],"mappings":";;;;;;;;;;IAEO,SAASA,QAAQA,CAACC,GAAG,EAAEC,KAAK,EAAEC,OAAO,EAAmB;IAAA,EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,KAAK,CAAA;IACzDG,EAAAA,eAAS,CAAC,YAAM;IACZ,IAAA,IAAIP,GAAG,EAAE;IACL;UACAA,GAAG,CAACQ,gBAAgB,CAACP,KAAK,EAAEC,OAAO,EAAEC,OAAO,CA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AO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC5C,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAA,QACII,yBAAA,CAAA,aAAA,CAAA,aAAA,EAAA,EAAa,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAA,CAAgB,EAC/I;IACL,KAAA;IACL,CAAC;;;;;;;;;;"}
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import 'jb-textarea';
3
+ import { JBTextareaValidationItem, JBTextareaWebComponent } from 'jb-textarea';
4
+ declare global {
5
+ namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'jb-textarea': JBTextareaType;
8
+ }
9
+ interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {
10
+ class?: string;
11
+ label?: string;
12
+ name?: string;
13
+ message?: string;
14
+ }
15
+ }
16
+ }
17
+ declare const JBTextarea: React.ForwardRefExoticComponent<JBTextareaProps & React.RefAttributes<unknown>>;
18
+ export type JBTextareaEventType<T> = T & {
19
+ target: JBTextareaWebComponent;
20
+ };
21
+ type JBTextareaProps = {
22
+ label?: string;
23
+ value?: string;
24
+ onChange?: (e: JBTextareaEventType<Event>) => void;
25
+ onFocus?: (e: JBTextareaEventType<FocusEvent>) => void;
26
+ onBlur?: (e: JBTextareaEventType<FocusEvent>) => void;
27
+ onKeydown?: (e: JBTextareaEventType<KeyboardEvent>) => void;
28
+ onKeyup?: (e: JBTextareaEventType<KeyboardEvent>) => void;
29
+ onInput?: (e: JBTextareaEventType<InputEvent>) => void;
30
+ onBeforeinput?: (e: JBTextareaEventType<InputEvent>) => void;
31
+ placeholder?: string;
32
+ className?: string;
33
+ validationList?: JBTextareaValidationItem[];
34
+ autoHeight?: boolean;
35
+ message?: string;
36
+ };
37
+ export { JBTextarea };
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export {JBInput} from './dist/JBInput.js';
@@ -0,0 +1,109 @@
1
+ /* eslint-disable no-inner-declarations */
2
+ import React, { useRef, useEffect, useImperativeHandle, useState } from 'react';
3
+ import 'jb-textarea';
4
+ // eslint-disable-next-line no-duplicate-imports
5
+ import {JBTextareaValidationItem, JBTextareaWebComponent} from 'jb-textarea';
6
+ import { useEvent } from '../../custom-hooks/UseEvent';
7
+
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
+ // ref:React.RefObject<JBDateInputWebComponent>,
20
+ }
21
+ }
22
+ }
23
+ // eslint-disable-next-line react/display-name
24
+ const JBTextarea = React.forwardRef((props:JBTextareaProps, 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] = useState(0);
28
+ const element = useRef<JBTextareaWebComponent>(null);
29
+ useImperativeHandle(
30
+ ref,
31
+ () => (element ? element.current : {}),
32
+ [element],
33
+ );
34
+ useEffect(()=>{
35
+ refChangeCountSetter(refChangeCount+1);
36
+ },[element.current]);
37
+ function onChange(e:JBTextareaEventType<Event>) {
38
+ if (props.onChange) {
39
+ props.onChange(e);
40
+ }
41
+ }
42
+ function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {
43
+ if (props.onKeydown) {
44
+ props.onKeydown(e);
45
+ }
46
+ }
47
+ function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {
48
+ if (props.onKeyup) {
49
+ props.onKeyup(e);
50
+ }
51
+ }
52
+ function onFocus(e:JBTextareaEventType<FocusEvent>) {
53
+ if (props.onFocus && e instanceof FocusEvent) {
54
+ props.onFocus(e);
55
+ }
56
+ }
57
+ function onBlur(e:JBTextareaEventType<FocusEvent>) {
58
+ if (props.onBlur && e instanceof FocusEvent) {
59
+ props.onBlur(e);
60
+ }
61
+ }
62
+ useEffect(() => {
63
+ const value:string = props.value || '';
64
+ if(element.current){
65
+ element.current.value = value;
66
+ }
67
+ }, [props.value]);
68
+
69
+ useEffect(() => {
70
+ if(element.current){
71
+ element.current.validationList = props.validationList || [];
72
+ }
73
+ }, [props.validationList]);
74
+
75
+ useEffect(() => {
76
+ if(element.current){
77
+ element.current.autoHeight = props.autoHeight || false;
78
+ }
79
+ }, [props.autoHeight]);
80
+ useEvent(element.current, 'change', onChange);
81
+ useEvent(element.current, 'keydown', onKeydown);
82
+ useEvent(element.current, 'keyup', onKeyup);
83
+ useEvent(element.current, 'focus', onFocus);
84
+ useEvent(element.current, 'blur', onBlur);
85
+ return (
86
+ <jb-textarea placeholder={props.placeholder} class={props.className} ref={element} label={props.label} message={props.message}></jb-textarea>
87
+ );
88
+ }
89
+ });
90
+ export type JBTextareaEventType<T> = T & {
91
+ target: JBTextareaWebComponent
92
+ }
93
+ type JBTextareaProps = {
94
+ label?: string,
95
+ value?: string,
96
+ onChange?: (e:JBTextareaEventType<Event>)=>void,
97
+ onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,
98
+ onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,
99
+ onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
100
+ onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
101
+ onInput?: (e:JBTextareaEventType<InputEvent>)=>void,
102
+ onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,
103
+ placeholder?:string,
104
+ className?: string,
105
+ validationList?:JBTextareaValidationItem[],
106
+ autoHeight?: boolean,
107
+ message?:string
108
+ }
109
+ export {JBTextarea};
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "jb-textarea",
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": "0.1.0",
18
+ "bugs": "https://github.com/javadbat/jb-textarea-react/issues",
19
+ "license": "MIT",
20
+ "files": [
21
+ "LICENSE",
22
+ "README.md",
23
+ "lib/",
24
+ "dist/"
25
+ ],
26
+ "main": "index.js",
27
+ "types": "./dist/jb-textarea/lib/JBTextarea.d.ts",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git@github.com:javadbat/jb-textarea-react.git"
31
+ },
32
+ "dependencies": {
33
+ "jb-textarea": ">=2.1.0"
34
+ }
35
+ }