// Copyright 2019-2020 @polkadot/extension-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 import React, { useCallback } from 'react'; import styled from 'styled-components'; import Label from './Label'; import { Input } from './TextInputs'; interface Props { className?: string; defaultValue?: string | null; disabled?: boolean; isError?: boolean; isFocused?: boolean; isReadOnly?: boolean; label: string; onBlur?: () => 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, placeholder, type = 'text', value, withoutMargin }: Props): React.ReactElement { const _checkEnter = useCallback( (event: React.KeyboardEvent): void => { onEnter && event.key === 'Enter' && onEnter(); }, [onEnter] ); const _onChange = useCallback( ({ target: { value } }: React.ChangeEvent): void => { onChange && onChange(value); }, [onChange] ); return ( ); } export default styled(InputWithLabel)` margin-bottom: 16px; &.withoutMargin { margin-bottom: 0px; } `;