jb-textarea 3.3.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ /* eslint-disable no-inner-declarations */
2
+ import React, { useRef, useEffect, useImperativeHandle, useState, CSSProperties } from 'react';
3
+ import 'jb-textarea';
4
+ // eslint-disable-next-line no-duplicate-imports
5
+ import {JBTextareaWebComponent, type ValidationValue} from 'jb-textarea';
6
+ import { useBindEvent } from '../../../../common/hooks/use-event.js';
7
+ import { type ValidationItem } from "jb-validation";
8
+ declare global {
9
+ // eslint-disable-next-line @typescript-eslint/no-namespace
10
+ namespace JSX {
11
+ interface IntrinsicElements {
12
+ 'jb-textarea': JBTextareaType;
13
+ }
14
+ interface JBTextareaType extends React.DetailedHTMLProps<React.HTMLAttributes<JBTextareaWebComponent>, JBTextareaWebComponent> {
15
+ class?:string,
16
+ label?: string,
17
+ name?:string,
18
+ message?:string,
19
+ placeholder?:string,
20
+ // ref:React.RefObject<JBDateInputWebComponent>,
21
+ }
22
+ }
23
+ }
24
+ // eslint-disable-next-line react/display-name
25
+ const JBTextarea = React.forwardRef((props:JBTextareaProps, ref) => {
26
+ {
27
+ //we set this state so when ref change we have a render and our event listener will be updated
28
+ const [refChangeCount , refChangeCountSetter] = useState(0);
29
+ const element = useRef<JBTextareaWebComponent>(null);
30
+ useImperativeHandle(
31
+ ref,
32
+ () => (element ? element.current : {}),
33
+ [element],
34
+ );
35
+ useEffect(()=>{
36
+ refChangeCountSetter(refChangeCount+1);
37
+ },[element.current]);
38
+ function onChange(e:JBTextareaEventType<Event>) {
39
+ if (props.onChange) {
40
+ props.onChange(e);
41
+ }
42
+ }
43
+ function onKeydown(e:JBTextareaEventType<KeyboardEvent>) {
44
+ if (props.onKeydown) {
45
+ props.onKeydown(e);
46
+ }
47
+ }
48
+ function onInput(e:JBTextareaEventType<InputEvent>) {
49
+ if (props.onInput) {
50
+ props.onInput(e);
51
+ }
52
+ }
53
+ function onKeyup(e:JBTextareaEventType<KeyboardEvent>) {
54
+ if (props.onKeyup) {
55
+ props.onKeyup(e);
56
+ }
57
+ }
58
+ function onFocus(e:JBTextareaEventType<FocusEvent>) {
59
+ if (props.onFocus && e instanceof FocusEvent) {
60
+ props.onFocus(e);
61
+ }
62
+ }
63
+ function onBlur(e:JBTextareaEventType<FocusEvent>) {
64
+ if (props.onBlur && e instanceof FocusEvent) {
65
+ props.onBlur(e);
66
+ }
67
+ }
68
+ useEffect(() => {
69
+ const value:string = props.value || '';
70
+ if(element.current){
71
+ element.current.value = value;
72
+ }
73
+ }, [props.value]);
74
+
75
+ useEffect(() => {
76
+ if(element.current){
77
+ element.current.validation.list = props.validationList || [];
78
+ }
79
+ }, [props.validationList]);
80
+ useEffect(() => {
81
+ if(element.current && props.required!== undefined){
82
+ props.required?element.current.setAttribute("required",''):element.current.removeAttribute("required");
83
+ }
84
+ }, [props.required]);
85
+
86
+ useEffect(() => {
87
+ if(element.current){
88
+ element.current.autoHeight = props.autoHeight || false;
89
+ }
90
+ }, [props.autoHeight]);
91
+ useBindEvent(element, 'change', onChange);
92
+ useBindEvent(element, 'keydown', onKeydown);
93
+ useBindEvent(element, 'input', onInput);
94
+ useBindEvent(element, 'keyup', onKeyup);
95
+ useBindEvent(element, 'focus', onFocus);
96
+ useBindEvent(element, 'blur', onBlur);
97
+ return (
98
+ <jb-textarea placeholder={props.placeholder} class={props.className} style={props.style} ref={element} label={props.label} message={props.message} name={props.name}></jb-textarea>
99
+ );
100
+ }
101
+ });
102
+ export type JBTextareaEventType<T> = T & {
103
+ target: JBTextareaWebComponent
104
+ }
105
+ type JBTextareaProps = {
106
+ label?: string,
107
+ value?: string | null | undefined,
108
+ onChange?: (e:JBTextareaEventType<Event>)=>void,
109
+ onFocus?:(e:JBTextareaEventType<FocusEvent>)=>void,
110
+ onBlur?:(e:JBTextareaEventType<FocusEvent>)=>void,
111
+ onKeydown?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
112
+ onKeyup?: (e:JBTextareaEventType<KeyboardEvent>)=>void,
113
+ onInput?: (e:JBTextareaEventType<InputEvent>)=>void,
114
+ onBeforeinput?: (e:JBTextareaEventType<InputEvent>)=>void,
115
+ placeholder?:string,
116
+ className?: string,
117
+ style?:CSSProperties,
118
+ validationList?:ValidationItem<ValidationValue>[],
119
+ autoHeight?: boolean,
120
+ message?:string,
121
+ name?:string,
122
+ required?:boolean
123
+ }
124
+ export {JBTextarea};
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "jb-textarea-react",
3
+ "description": "textarea react component",
4
+ "type": "module",
5
+ "author": {
6
+ "name": "mohammad javad bathaei",
7
+ "email": "javadbat@gmail.com"
8
+ },
9
+ "keywords": [
10
+ "jb",
11
+ "jb-textarea",
12
+ "textarea",
13
+ "long input",
14
+ "multiline input",
15
+ "react component"
16
+ ],
17
+ "version": "3.2.0",
18
+ "bugs": "https://github.com/javadbat/jb-textarea/issues",
19
+ "license": "MIT",
20
+ "files": [
21
+ "LICENSE",
22
+ "README.md",
23
+ "lib/",
24
+ "dist/"
25
+ ],
26
+ "main": "index.js",
27
+ "types": "./dist/web-component/jb-textarea/react/lib/JBTextarea.d.ts",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git@github.com:javadbat/jb-textarea.git"
31
+ },
32
+ "dependencies": {
33
+ "jb-textarea": ">=3.2.0"
34
+ }
35
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "."
4
+ },
5
+ "include": [
6
+ "../../../common/scripts/**/*.ts",
7
+ "../../../common/hooks/**/*.ts",
8
+ "../../../common/hooks/**/*.js",
9
+ "lib/**/*.ts",
10
+ "lib/**/*.tsx"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "**/*.spec.ts",
15
+ "dist",
16
+ ],
17
+ "extends":"../../tsconfig-react.json"
18
+ }