diff --git a/src/TA.tsx b/src/TA.tsx index f45d19a..cdec2da 100644 --- a/src/TA.tsx +++ b/src/TA.tsx @@ -1,4 +1,4 @@ -import {ReactNode, useCallback, useState} from "react"; +import {ChangeEventHandler, KeyboardEventHandler, ReactNode, useCallback, useEffect, useRef, useState} from "react"; import AsyncSelect from "react-select/async"; import {FixedSizeList as List} from "react-window"; import Select, {createFilter, MenuListProps} from "react-select"; @@ -35,41 +35,6 @@ function MenuList(props: MenuListProps) { ); } -const TestSelect = (vendorOptions: any) => { - const options: { - value: string, - label: string - }[] = []; - for (let i = 0; i < vendorOptions["vendorOptions"].length; i = i + 1) { - options.push({ - value: vendorOptions["vendorOptions"][i], - label: `${vendorOptions["vendorOptions"][i]}` - }); - } - - const loadOptions = (_inputValue: unknown, callback: (options: { - value: string, - label: string - }[]) => void) => { - setTimeout(() => { - callback(options); - }, 1000); - }; - - const TestSelectComponent = () => { - return ( -
- -
- ) - } - - return ( - - ) -} - interface Option { label: string, value: string, @@ -118,13 +83,7 @@ export function LargeSelect() { {selected &&
{selected.data.aliases?.map(alias => (
- - [[ - {selected.label} - | - {alias} - ]] - +
))} @@ -134,7 +93,7 @@ export function LargeSelect() { {selected.label} | - + ]] @@ -144,5 +103,68 @@ export function LargeSelect() { ) } +function CustomAliasField({selected}: { + selected: Option +}) { + const [content, setContent] = useState(''); + const [width, setWidth] = useState(0); + const span = useRef(null); -export default TestSelect + // Reset when selection changes + useEffect(() => { + setContent(''); + }, [selected.value]); + + // Resize on change of content + useEffect(() => { + setWidth(span.current!.offsetWidth); + // setWidth(content.length + 'ch'); + }, [content]); + + const changeHandler: ChangeEventHandler = useCallback(evt => { + setContent(evt.target.value); + }, []); + + const onCustomElementKeyDown: KeyboardEventHandler = useCallback((e) => { + if (e.key == 'Enter') { + navigator.clipboard.writeText(`[[${selected!.label}|${content}]]`); + (e.target as HTMLInputElement).blur() + } + }, [selected.value, selected.label, content]); + + return ( + + {content} + + + ); +} + +function Alias({ + original, + alias + }: { + original: string, + alias: string +}) { + const onClick = useCallback(() => { + navigator.clipboard.writeText(`[[${original}|${alias}]]`) + }, [original, alias]); + + return ( + + [[ + {original} + | + {alias} + ]] + + ); +}