@addsign/moje-agenda-shared-lib 1.0.1 → 1.0.2
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.
|
@@ -109,9 +109,9 @@ function InputField({
|
|
|
109
109
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
110
110
|
"input",
|
|
111
111
|
{
|
|
112
|
-
className:
|
|
112
|
+
className: `text-gray-900 text-sm font-normal leading-normal text-ellipsis overflow-hidden w-full `,
|
|
113
113
|
id: name,
|
|
114
|
-
|
|
114
|
+
disabled,
|
|
115
115
|
value: inputValue || "",
|
|
116
116
|
type,
|
|
117
117
|
...rest,
|
|
@@ -138,12 +138,13 @@ function InputField({
|
|
|
138
138
|
{
|
|
139
139
|
className: `self-stretch w-full px-3 py-1 bg-white border justify-start items-center gap-0 inline-flex outline-none
|
|
140
140
|
${isFocused ? "outline-4 outline-indigo-200 outline-offset-0 border-indigo-300 " : ""}
|
|
141
|
-
${rounded ? " rounded-lg " : " rounded-none "}
|
|
141
|
+
${rounded ? " rounded-lg " : " rounded-none "}
|
|
142
|
+
${disabled ? "!bg-gray-100 " : ""}`,
|
|
142
143
|
onClick: handleSetFocus,
|
|
143
144
|
children: [
|
|
144
145
|
/* @__PURE__ */ jsx("div", { className: "grow shrink basis-0 min-h-[32px] justify-start items-center gap-0 flex whitespace-nowrap w-[calc(100%-40px)] ", children: renderInput() }),
|
|
145
146
|
inputIsChanging === true && /* @__PURE__ */ jsx(SpinnerIcon, { icon: /* @__PURE__ */ jsx(FaSpinner, {}) }),
|
|
146
|
-
value && /* @__PURE__ */ jsxs(
|
|
147
|
+
value && !disabled && /* @__PURE__ */ jsxs(
|
|
147
148
|
"div",
|
|
148
149
|
{
|
|
149
150
|
className: "w-6 h-6 relative cursor-pointer ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputField.js","sources":["../../../lib/components/form/InputField.tsx"],"sourcesContent":["import * as React from \"react\";\r\nimport { IFormFieldGlobalProps } from \"../../types\";\r\nimport { MdClose } from \"react-icons/md\";\r\nimport { useClickAway } from \"react-use\";\r\nimport { FaSpinner } from \"react-icons/fa\";\r\nimport SpinnerIcon from \"../SpinnerIcon\";\r\n\r\nexport interface IInputFieldProps extends IFormFieldGlobalProps {\r\n maxLength?: number;\r\n debounceTimeout?: number;\r\n}\r\n\r\nexport default function InputField({\r\n label,\r\n name,\r\n value,\r\n description,\r\n onInputChange,\r\n placeholder,\r\n className,\r\n register,\r\n type,\r\n disabled,\r\n maxLength,\r\n errors = {},\r\n rounded = true,\r\n debounceTimeout,\r\n}: IInputFieldProps) {\r\n const wrapperRef = React.useRef(null);\r\n const [isFocused, setIsFocused] = React.useState(false);\r\n const [inputValue, setInputValue] = React.useState(value); // Local state for input value\r\n const debounceTimeoutRef = React.useRef<NodeJS.Timeout | null>(null); // Ref to hold the debounce timeout\r\n const [inputIsChanging, setInputIsChanging] = React.useState(false);\r\n const handleClear = (e: any) => {\r\n setInputValue(\"\"); // Clear local state\r\n onInputChange({\r\n ...e,\r\n target: {\r\n value: \"\",\r\n name: name,\r\n },\r\n });\r\n };\r\n const fallbackRef = React.useRef(null);\r\n const {\r\n ref: registeredRef = fallbackRef,\r\n onBlur: formOnBlur = () => {} /* default function */,\r\n ...rest\r\n } = register ? register(name) : {};\r\n\r\n const ref = registeredRef || fallbackRef;\r\n const handleSetFocus = () => {\r\n setIsFocused(true);\r\n ref.current.focus();\r\n };\r\n useClickAway(wrapperRef, () => {\r\n if (isFocused) {\r\n setIsFocused(false);\r\n }\r\n });\r\n\r\n const handleDebouncedChange = React.useCallback(\r\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\r\n const { value } = e.target;\r\n setInputValue(value); // Update local state\r\n setInputIsChanging(true);\r\n console.log(\r\n \"%clibcomponents\\formInputField.tsx:67 setInputIsChanging\",\r\n \"color: #007acc;\",\r\n inputIsChanging\r\n );\r\n if (debounceTimeout) {\r\n // Clear any previous debounce timeout\r\n if (debounceTimeoutRef.current)\r\n clearTimeout(debounceTimeoutRef.current);\r\n\r\n // Set a new debounce timeout\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }, debounceTimeout);\r\n } else {\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }\r\n },\r\n [debounceTimeout, debounceTimeoutRef, onInputChange, setInputValue]\r\n );\r\n\r\n const handleBlur = (\r\n e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>\r\n ) => {\r\n formOnBlur(e); // Call React Hook Form's onBlur\r\n setIsFocused(false); // Then call your custom onBlur logic\r\n\r\n if (debounceTimeoutRef.current && inputIsChanging) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }\r\n };\r\n\r\n const renderInput = () => {\r\n switch (type) {\r\n case \"textarea\":\r\n return (\r\n <textarea\r\n id={name}\r\n className=\"grow shrink basis-0 text-gray-900 text-sm font-normal leading-tight focus:border-none \"\r\n disabled={disabled}\r\n value={inputValue || \"\"}\r\n rows={3}\r\n {...rest} // Spread the rest of register's return value\r\n ref={ref}\r\n onChange={(e) => handleDebouncedChange(e)}\r\n onFocus={() => setIsFocused(true)}\r\n maxLength={maxLength || 4000}\r\n onBlur={handleBlur}\r\n />\r\n );\r\n default:\r\n return (\r\n <>\r\n <input\r\n className
|
|
1
|
+
{"version":3,"file":"InputField.js","sources":["../../../lib/components/form/InputField.tsx"],"sourcesContent":["import * as React from \"react\";\r\nimport { IFormFieldGlobalProps } from \"../../types\";\r\nimport { MdClose } from \"react-icons/md\";\r\nimport { useClickAway } from \"react-use\";\r\nimport { FaSpinner } from \"react-icons/fa\";\r\nimport SpinnerIcon from \"../SpinnerIcon\";\r\n\r\nexport interface IInputFieldProps extends IFormFieldGlobalProps {\r\n maxLength?: number;\r\n debounceTimeout?: number;\r\n}\r\n\r\nexport default function InputField({\r\n label,\r\n name,\r\n value,\r\n description,\r\n onInputChange,\r\n placeholder,\r\n className,\r\n register,\r\n type,\r\n disabled,\r\n maxLength,\r\n errors = {},\r\n rounded = true,\r\n debounceTimeout,\r\n}: IInputFieldProps) {\r\n const wrapperRef = React.useRef(null);\r\n const [isFocused, setIsFocused] = React.useState(false);\r\n const [inputValue, setInputValue] = React.useState(value); // Local state for input value\r\n const debounceTimeoutRef = React.useRef<NodeJS.Timeout | null>(null); // Ref to hold the debounce timeout\r\n const [inputIsChanging, setInputIsChanging] = React.useState(false);\r\n const handleClear = (e: any) => {\r\n setInputValue(\"\"); // Clear local state\r\n onInputChange({\r\n ...e,\r\n target: {\r\n value: \"\",\r\n name: name,\r\n },\r\n });\r\n };\r\n const fallbackRef = React.useRef(null);\r\n const {\r\n ref: registeredRef = fallbackRef,\r\n onBlur: formOnBlur = () => {} /* default function */,\r\n ...rest\r\n } = register ? register(name) : {};\r\n\r\n const ref = registeredRef || fallbackRef;\r\n const handleSetFocus = () => {\r\n setIsFocused(true);\r\n ref.current.focus();\r\n };\r\n useClickAway(wrapperRef, () => {\r\n if (isFocused) {\r\n setIsFocused(false);\r\n }\r\n });\r\n\r\n const handleDebouncedChange = React.useCallback(\r\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\r\n const { value } = e.target;\r\n setInputValue(value); // Update local state\r\n setInputIsChanging(true);\r\n console.log(\r\n \"%clibcomponents\\formInputField.tsx:67 setInputIsChanging\",\r\n \"color: #007acc;\",\r\n inputIsChanging\r\n );\r\n if (debounceTimeout) {\r\n // Clear any previous debounce timeout\r\n if (debounceTimeoutRef.current)\r\n clearTimeout(debounceTimeoutRef.current);\r\n\r\n // Set a new debounce timeout\r\n debounceTimeoutRef.current = setTimeout(() => {\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }, debounceTimeout);\r\n } else {\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }\r\n },\r\n [debounceTimeout, debounceTimeoutRef, onInputChange, setInputValue]\r\n );\r\n\r\n const handleBlur = (\r\n e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>\r\n ) => {\r\n formOnBlur(e); // Call React Hook Form's onBlur\r\n setIsFocused(false); // Then call your custom onBlur logic\r\n\r\n if (debounceTimeoutRef.current && inputIsChanging) {\r\n clearTimeout(debounceTimeoutRef.current);\r\n onInputChange(e);\r\n setInputIsChanging(false);\r\n }\r\n };\r\n\r\n const renderInput = () => {\r\n switch (type) {\r\n case \"textarea\":\r\n return (\r\n <textarea\r\n id={name}\r\n className=\"grow shrink basis-0 text-gray-900 text-sm font-normal leading-tight focus:border-none \"\r\n disabled={disabled}\r\n value={inputValue || \"\"}\r\n rows={3}\r\n {...rest} // Spread the rest of register's return value\r\n ref={ref}\r\n onChange={(e) => handleDebouncedChange(e)}\r\n onFocus={() => setIsFocused(true)}\r\n maxLength={maxLength || 4000}\r\n onBlur={handleBlur}\r\n />\r\n );\r\n default:\r\n return (\r\n <>\r\n <input\r\n className={`text-gray-900 text-sm font-normal leading-normal text-ellipsis overflow-hidden w-full `}\r\n id={name}\r\n disabled={disabled}\r\n value={inputValue || \"\"}\r\n type={type}\r\n {...rest} // Spread the rest of register's return value\r\n ref={ref}\r\n placeholder={placeholder}\r\n onChange={(e) => handleDebouncedChange(e)}\r\n onFocus={() => setIsFocused(true)}\r\n onBlur={handleBlur}\r\n />\r\n </>\r\n );\r\n }\r\n };\r\n\r\n return (\r\n <>\r\n <div\r\n className={\r\n \"min-h-30 flex-col justify-start items-start gap-1.5 w-full relative \" +\r\n className\r\n }\r\n ref={wrapperRef}\r\n id=\"component\"\r\n >\r\n <div className=\"self-stretch flex-col justify-start items-start gap-1.5 flex\">\r\n {label && (\r\n <div className=\"text-slate-700 text-sm font-medium leading-tight\">\r\n {label}\r\n </div>\r\n )}\r\n <div\r\n className={`self-stretch w-full px-3 py-1 bg-white border justify-start items-center gap-0 inline-flex outline-none \r\n ${isFocused ? \"outline-4 outline-indigo-200 outline-offset-0 border-indigo-300 \" : \"\"}\r\n ${rounded ? \" rounded-lg \" : \" rounded-none \"}\r\n ${disabled ? \"!bg-gray-100 \" : \"\"}`}\r\n onClick={handleSetFocus}\r\n >\r\n <div className=\"grow shrink basis-0 min-h-[32px] justify-start items-center gap-0 flex whitespace-nowrap w-[calc(100%-40px)] \">\r\n {renderInput()}\r\n </div>\r\n {inputIsChanging === true && <SpinnerIcon icon={<FaSpinner />} />}\r\n {value && !disabled && (\r\n <div\r\n className=\"w-6 h-6 relative cursor-pointer \"\r\n onClick={handleClear}\r\n >\r\n <div className=\"absolute inset-0 flex items-center justify-center hover:bg-gray-100 w-6 rounded-full text-lg\">\r\n <MdClose />\r\n </div>{\" \"}\r\n </div>\r\n )}\r\n </div>\r\n </div>\r\n {description && !isFocused && (\r\n <div className=\"self-stretch text-slate-600 text-sm font-normal leading-tight\">\r\n {description}\r\n </div>\r\n )}{\" \"}\r\n {errors[name] && (\r\n <div className=\"HintText self-stretch text-red-600 text-sm font-normal leading-tight\">\r\n {errors[name]?.message}\r\n </div>\r\n )}\r\n </div>\r\n </>\r\n );\r\n}\r\n"],"names":["value"],"mappings":";;;;;;AAYA,SAAwB,WAAW;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,CAAC;AAAA,EACV,UAAU;AAAA,EACV;AACF,GAAqB;;AACb,QAAA,aAAa,MAAM,OAAO,IAAI;AACpC,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,KAAK;AACtD,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,KAAK;AAClD,QAAA,qBAAqB,MAAM,OAA8B,IAAI;AACnE,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,MAAM,SAAS,KAAK;AAC5D,QAAA,cAAc,CAAC,MAAW;AAC9B,kBAAc,EAAE;AACF,kBAAA;AAAA,MACZ,GAAG;AAAA,MACH,QAAQ;AA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