diff --git a/app/soapbox/components/ui/input/input.tsx b/app/soapbox/components/ui/input/input.tsx index d1cf7cf7c..9a4785c7b 100644 --- a/app/soapbox/components/ui/input/input.tsx +++ b/app/soapbox/components/ui/input/input.tsx @@ -20,7 +20,7 @@ interface IInput extends Pick, 'maxL className?: string, /** Extra class names for the outer
element. */ outerClassName?: string, - /** URL to the svg icon. */ + /** URL to the svg icon. Cannot be used with addon. */ icon?: string, /** Internal input name. */ name?: string, @@ -31,9 +31,11 @@ interface IInput extends Pick, 'maxL /** Change event handler for the input. */ onChange?: (event: React.ChangeEvent) => void, /** HTML input type. */ - type: 'text' | 'number' | 'email' | 'tel' | 'password', + type?: 'text' | 'number' | 'email' | 'tel' | 'password', /** Whether to display the input in red. */ hasError?: boolean, + /** An element to display as prefix to input. Cannot be used with icon. */ + addon?: React.ReactElement, } /** Form input element. */ @@ -41,7 +43,7 @@ const Input = React.forwardRef( (props, ref) => { const intl = useIntl(); - const { type = 'text', icon, className, outerClassName, hasError, ...filteredProps } = props; + const { type = 'text', icon, className, outerClassName, hasError, addon, ...filteredProps } = props; const [revealed, setRevealed] = React.useState(false); @@ -52,13 +54,19 @@ const Input = React.forwardRef( }, []); return ( -
+
{icon ? (
) : null} + {addon ? ( +
+ {addon} +
+ ) : null} + ( 'pr-7': isPassword, 'text-red-600 border-red-600': hasError, 'pl-8': typeof icon !== 'undefined', + 'pl-16': typeof addon !== 'undefined', }, className)} /> diff --git a/app/soapbox/components/ui/phone-input/country-code-dropdown.tsx b/app/soapbox/components/ui/phone-input/country-code-dropdown.tsx index fc7b944d6..aaf2b4ac5 100644 --- a/app/soapbox/components/ui/phone-input/country-code-dropdown.tsx +++ b/app/soapbox/components/ui/phone-input/country-code-dropdown.tsx @@ -1,11 +1,7 @@ import React from 'react'; -import { Icon, HStack } from 'soapbox/components/ui'; -import DropdownMenu from 'soapbox/containers/dropdown_menu_container'; import { COUNTRY_CODES, CountryCode } from 'soapbox/utils/phone'; -import type { Menu } from 'soapbox/components/dropdown_menu'; - interface ICountryCodeDropdown { countryCode: CountryCode, onChange(countryCode: CountryCode): void, @@ -13,27 +9,16 @@ interface ICountryCodeDropdown { /** Dropdown menu to select a country code. */ const CountryCodeDropdown: React.FC = ({ countryCode, onChange }) => { - - const handleMenuItem = (code: CountryCode) => { - return () => { - onChange(code); - }; - }; - - const menu: Menu = COUNTRY_CODES.map(code => ({ - text: <>+{code}, - action: handleMenuItem(code), - })); - return ( - - - + ); }; diff --git a/app/soapbox/components/ui/phone-input/phone-input.tsx b/app/soapbox/components/ui/phone-input/phone-input.tsx index 4b48a23e4..89e9778ce 100644 --- a/app/soapbox/components/ui/phone-input/phone-input.tsx +++ b/app/soapbox/components/ui/phone-input/phone-input.tsx @@ -3,7 +3,6 @@ import React, { useState, useEffect } from 'react'; import { CountryCode } from 'soapbox/utils/phone'; -import HStack from '../hstack/hstack'; import Input from '../input/input'; import CountryCodeDropdown from './country-code-dropdown'; @@ -61,23 +60,17 @@ const PhoneInput: React.FC = (props) => { }, [countryCode, nationalNumber]); return ( - -
+ -
- - -
+ } + {...rest} + /> ); };