// Copyright 2019-2025 @pezkuwi/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 import React, { useCallback, useState } from 'react'; import { useTranslation } from '../hooks/index.js'; import { styled } from '../styled.js'; import Label from './Label.js'; import { Input } from './TextInputs.js'; import Warning from './Warning.js'; interface Props { className?: string; defaultValue?: string | null; disabled?: boolean; isError?: boolean; isFocused?: boolean; isReadOnly?: boolean; label: string; onBlur?: () => void; onFocus?: () => void; onChange?: (value: string) => void; onEnter?: () => void; placeholder?: string; type?: 'text' | 'password'; value?: string; withoutMargin?: boolean; } function InputWithLabel ({ className, defaultValue, disabled, isError, isFocused, isReadOnly, label = '', onBlur, onChange, onEnter, onFocus, placeholder, type = 'text', value, withoutMargin }: Props): React.ReactElement { const [isCapsLock, setIsCapsLock] = useState(false); const { t } = useTranslation(); const _checkKey = useCallback( (event: React.KeyboardEvent): void => { onEnter && event.key === 'Enter' && onEnter(); if (type === 'password') { if (event.getModifierState('CapsLock')) { setIsCapsLock(true); } else { setIsCapsLock(false); } } }, [onEnter, type] ); const _onChange = useCallback( ({ target: { value } }: React.ChangeEvent): void => { onChange && onChange(value); }, [onChange] ); return ( ); } export default styled(InputWithLabel)` margin-bottom: 16px; &.withoutMargin { margin-bottom: 0px; + .danger { margin-top: 6px; } } `;