import { useCallback, useState, Fragment } from 'react' import { InputAction, InputComponentProps, SettingComponentProps, } from '@janhq/core' import { Input } from '@janhq/joi' import { CopyIcon, EyeIcon, 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 description = marked.parse(settingProps.description ?? '', { async: false, }) const toggleObscure = useCallback(() => { setObscure((prev) => !prev) }, []) const copy = useCallback(() => { navigator.clipboard.writeText(value) }, [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)} suffixIcon={ } />
) } type InputActionProps = { actions: InputAction[] onAction: (action: InputAction) => void } const InputExtraActions: React.FC = ({ actions, onAction, }) => { if (actions.length === 0) return return (
{actions.map((action) => { switch (action) { case 'copy': return ( onAction(action)} /> ) case 'unobscure': return ( onAction(action)} /> ) default: return } })}
) } export default SettingDetailTextInputItem