ehscan-react-components 0.1.28 → 0.1.29

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.
@@ -7,6 +7,7 @@ type DropDownProps = {
7
7
  addItem: (index: number) => void;
8
8
  searchTerm: string;
9
9
  maxDropDownEntries?: number;
10
+ maxDropDownHeight?: number;
10
11
  };
11
12
  export declare const DropDown: import("react").ForwardRefExoticComponent<DropDownProps & import("react").RefAttributes<DropDownHandle>>;
12
13
  export {};
package/dist/DropDown.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useState, useRef, forwardRef, useImperativeHandle } from "react";
3
- export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm, maxDropDownEntries }, ref) => {
3
+ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm, maxDropDownEntries, maxDropDownHeight }, ref) => {
4
4
  const [position, setPosition] = useState({ top: 0, left: 0, width: 0, maxHeight: 0 });
5
5
  const containerRef = useRef(null);
6
6
  useImperativeHandle(ref, () => ({
@@ -57,7 +57,7 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
57
57
  top: rect.bottom - 10,
58
58
  left: rect.left,
59
59
  width: rect.width,
60
- maxHeight: distanceToBottom - 50
60
+ maxHeight: maxDropDownHeight || distanceToBottom - 50
61
61
  });
62
62
  };
63
63
  useEffect(() => {
@@ -12,6 +12,7 @@ interface Props {
12
12
  placeholder?: string;
13
13
  maxLength?: number;
14
14
  addClass?: string;
15
+ maxDropDownHeight?: number;
15
16
  }
16
17
  export declare const TextAreaDropDown: React.FC<Props>;
17
18
  export default TextAreaDropDown;
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  import { useRef, useState, useId, useEffect } from "react";
12
12
  import { DropDown } from "./DropDown";
13
13
  import './style/input-dropdown.css';
14
- export const TextAreaDropDown = ({ id, tabIndex, label, value, editable = true, required = false, dropdownValue, onChange, placeholder = 'select or create new entry', maxLength = 500, addClass, }) => {
14
+ export const TextAreaDropDown = ({ id, tabIndex, label, value, editable = true, required = false, dropdownValue, onChange, placeholder = 'select or create new entry', maxLength = 500, addClass, maxDropDownHeight = 200 }) => {
15
15
  const childRef = useRef(null);
16
16
  const textareaRef = useRef(null);
17
17
  const searchInput = useRef(null);
@@ -25,10 +25,11 @@ export const TextAreaDropDown = ({ id, tabIndex, label, value, editable = true,
25
25
  const [searchTerm, setSearchTerm] = useState('');
26
26
  const [filterItems, setFilterItem] = useState([]);
27
27
  useEffect(() => {
28
- if (!width)
28
+ if (!width || width === 0)
29
29
  return;
30
30
  console.log('handleResize in TextAreaDropDown vai width');
31
31
  setOpenDropDown(false);
32
+ setWidth(width);
32
33
  }, [width]);
33
34
  useEffect(() => {
34
35
  if (!textareaRef.current)
@@ -36,14 +37,10 @@ export const TextAreaDropDown = ({ id, tabIndex, label, value, editable = true,
36
37
  const handleResize = () => {
37
38
  var _a;
38
39
  const newWidth = (_a = textareaRef === null || textareaRef === void 0 ? void 0 : textareaRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth;
39
- if (newWidth !== width) {
40
- console.log('handleResize in TextAreaDropDown');
40
+ if (newWidth !== width)
41
41
  setWidth(newWidth);
42
- }
43
42
  };
44
- // Initial check
45
43
  handleResize();
46
- // Listen to window resize
47
44
  window.addEventListener('resize', handleResize);
48
45
  return () => {
49
46
  window.removeEventListener('resize', handleResize);
@@ -134,6 +131,6 @@ export const TextAreaDropDown = ({ id, tabIndex, label, value, editable = true,
134
131
  }, [searchTerm]);
135
132
  if (!tags)
136
133
  return null;
137
- return (_jsxs("div", { className: `ext-textarea-wrapper-dropdown ${addClass}`, ref: textareaRef, children: [label && (_jsxs("div", { className: "ext-textarea-label", children: [_jsxs("label", { className: "ext-textarea-label-title", htmlFor: textareaId, children: [label, " ", required && _jsx("span", { className: "required", children: "*" })] }), _jsxs("div", { className: "ext-textarea-label-btns", children: [editable && charCount > 0 && (_jsxs("div", { className: "form-container-count", children: [charCount, " / ", maxLength] })), editable && charCount > 0 && (_jsx("div", { className: "ext-textarea-svg-close", "aria-label": `Clear ${label !== null && label !== void 0 ? label : "text area"}` }))] })] })), _jsx("div", { className: `ext-textarea-box-dropdown${openDropDown ? ' open' : ''}`, onClick: () => setOpenDropDown(true), children: _jsxs("div", { className: "ext-textarea-dropdown-inner", children: [tags.map((item, index) => (_jsxs("div", { className: "textarea-tag loop", children: [_jsx("div", { children: item }), _jsx("div", { className: "textarea-tag-erase", onClick: () => removeTag(tags[index]), children: _jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("line", { x1: "8", y1: "8", x2: "16", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" }), _jsx("line", { x1: "16", y1: "8", x2: "8", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" })] }) })] }, index))), _jsx("div", { className: "search-x-wrapper", children: _jsxs("div", { className: "search-x", children: [_jsx("div", { className: "search-x-input", children: _jsx("input", { type: "text", tabIndex: tabIndex, ref: searchInput, onFocus: () => setOpenDropDown(true), placeholder: placeholder, value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), onKeyDown: handleKeyDown }) }), _jsx("div", { className: `search-x-btn${newBtn ? ' show' : ''}`, onClick: () => createItem(), children: newBtn && 'create new one' })] }) })] }) }), _jsx(DropDown, { ref: childRef, openDropDown: openDropDown, display: filterItems, addItem: addItem, maxDropDownEntries: maxDropDownEntries, searchTerm: searchTerm })] }));
134
+ return (_jsxs("div", { className: `ext-textarea-wrapper-dropdown ${addClass}`, ref: textareaRef, children: [label && (_jsxs("div", { className: "ext-textarea-label", children: [_jsxs("label", { className: "ext-textarea-label-title", htmlFor: textareaId, children: [label, " ", required && _jsx("span", { className: "required", children: "*" })] }), _jsxs("div", { className: "ext-textarea-label-btns", children: [editable && charCount > 0 && (_jsxs("div", { className: "form-container-count", children: [charCount, " / ", maxLength] })), editable && charCount > 0 && (_jsx("div", { className: "ext-textarea-svg-close", "aria-label": `Clear ${label !== null && label !== void 0 ? label : "text area"}` }))] })] })), _jsx("div", { className: `ext-textarea-box-dropdown${openDropDown ? ' open' : ''}`, onClick: () => setOpenDropDown(true), children: _jsxs("div", { className: "ext-textarea-dropdown-inner", children: [tags.map((item, index) => (_jsxs("div", { className: "textarea-tag loop", children: [_jsx("div", { children: item }), _jsx("div", { className: "textarea-tag-erase", onClick: () => removeTag(tags[index]), children: _jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("line", { x1: "8", y1: "8", x2: "16", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" }), _jsx("line", { x1: "16", y1: "8", x2: "8", y2: "16", stroke: "#333", strokeWidth: "1", strokeLinecap: "round" })] }) })] }, index))), _jsx("div", { className: "search-x-wrapper", children: _jsxs("div", { className: "search-x", children: [_jsx("div", { className: "search-x-input", children: _jsx("input", { type: "text", tabIndex: tabIndex, ref: searchInput, onFocus: () => setOpenDropDown(true), placeholder: placeholder, value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), onKeyDown: handleKeyDown }) }), _jsx("div", { className: `search-x-btn${newBtn ? ' show' : ''}`, onClick: () => createItem(), children: newBtn && 'create new one' })] }) })] }) }), _jsx(DropDown, { ref: childRef, maxDropDownHeight: maxDropDownHeight, openDropDown: openDropDown, display: filterItems, addItem: addItem, maxDropDownEntries: maxDropDownEntries, searchTerm: searchTerm })] }));
138
135
  };
139
136
  export default TextAreaDropDown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-components",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",