import * as React from "react" import { useEffect, useRef } from "react"; import Tribute from "tributejs"; import { useTags } from "../Map/hooks/useTags"; type TextAreaProps = { labelTitle?: string; labelStyle?: string; containerStyle?: string; dataField?: string; inputStyle?: string; defaultValue: string; placeholder?: string; updateFormValue?: (value: string) => void; } interface KeyValue { [key: string]: string; } export function TextAreaInput({ labelTitle, dataField, labelStyle, containerStyle, inputStyle, defaultValue, placeholder, updateFormValue }: TextAreaProps) { const ref = useRef(null); // prevent react18 from calling useEffect twice const init = useRef(false) const tags = useTags(); let values: KeyValue[] = []; tags.map(tag => { values.push({ key: tag.id, value: tag.id, color: tag.color }) }) var tribute = new Tribute({ containerClass: 'tw-z-500 tw-bg-base-100 tw-p-2 tw-rounded-lg tw-shadow', selectClass: 'tw-font-bold', trigger: "#", values: values, menuShowMinLength: 3, noMatchTemplate: () => { return "" }, menuItemTemplate: function (item) { return `#${item.string}`; } }); useEffect(() => { if (!init.current) { if (ref.current) { tribute.attach(ref.current); } init.current = true; } }, [ref]) return (
{labelTitle ? : ""}
) }