import { useCallback, useState, Fragment } from 'react' import { InputAction, InputComponentProps, SettingComponentProps, } from '@janhq/core' import { Input } from '@janhq/joi' import { CheckIcon, CopyIcon, EyeIcon, EyeOffIcon, FolderOpenIcon, } from 'lucide-react' import { Marked, Renderer } from 'marked' type Props = { settingProps: SettingComponentProps onValueChanged?: (e: string) => void } const marked: Marked = new Marked({ renderer: { link: (href, title, text) => Renderer.prototype.link ?.apply(this, [href, title, text]) .replace( ' { const { value, type, placeholder, textAlign, inputActions } = settingProps.controllerProps as InputComponentProps const [obscure, setObscure] = useState(type === 'password') const [copied, setCopied] = useState(false) const description = marked.parse(settingProps.description ?? '', { async: false, }) const toggleObscure = useCallback(() => { setObscure((prev) => !prev) }, []) const copy = useCallback(() => { navigator.clipboard.writeText(value) if (value.length > 0) { setCopied(true) } setTimeout(() => setCopied(false), 2000) // Reset icon after 2 seconds }, [value]) const onAction = useCallback( (action: InputAction) => { switch (action) { case 'copy': copy() break case 'unobscure': toggleObscure() break default: break } }, [toggleObscure, copy] ) return (

{settingProps.title}

onValueChanged?.(e.target.value)} className="!pr-20" suffixIcon={ } />
) } type InputActionProps = { actions: InputAction[] onAction: (action: InputAction) => void copied: boolean obscure: boolean } const InputExtraActions: React.FC = ({ actions, onAction, copied, obscure, }) => { if (actions.length === 0) return return (
{actions.map((action) => { switch (action) { case 'copy': return copied ? ( onAction('copy')} className="text-green-600" /> ) : ( onAction('copy')} /> ) case 'unobscure': return obscure ? ( onAction('unobscure')} /> ) : ( onAction('unobscure')} /> ) default: return } })}
) } export default SettingDetailTextInputItem