diff --git a/app/soapbox/components/autosuggest_account_input.tsx b/app/soapbox/components/autosuggest_account_input.tsx index 79d247fd9..e8cd63830 100644 --- a/app/soapbox/components/autosuggest_account_input.tsx +++ b/app/soapbox/components/autosuggest_account_input.tsx @@ -7,6 +7,7 @@ import AutosuggestInput, { AutoSuggestion } from 'soapbox/components/autosuggest import { useAppDispatch } from 'soapbox/hooks'; import type { Menu } from 'soapbox/components/dropdown_menu'; +import type { InputThemes } from 'soapbox/components/ui/input/input'; const noOp = () => {}; @@ -19,6 +20,7 @@ interface IAutosuggestAccountInput { autoSelect?: boolean, menu?: Menu, onKeyDown?: React.KeyboardEventHandler, + theme?: InputThemes, } const AutosuggestAccountInput: React.FC = ({ diff --git a/app/soapbox/components/autosuggest_input.tsx b/app/soapbox/components/autosuggest_input.tsx index 744160b2b..277d87f96 100644 --- a/app/soapbox/components/autosuggest_input.tsx +++ b/app/soapbox/components/autosuggest_input.tsx @@ -6,10 +6,12 @@ import ImmutablePureComponent from 'react-immutable-pure-component'; import AutosuggestEmoji, { Emoji } from 'soapbox/components/autosuggest_emoji'; import Icon from 'soapbox/components/icon'; +import { Input } from 'soapbox/components/ui'; import AutosuggestAccount from 'soapbox/features/compose/components/autosuggest_account'; import { isRtl } from 'soapbox/rtl'; import type { Menu, MenuItem } from 'soapbox/components/dropdown_menu'; +import type { InputThemes } from 'soapbox/components/ui/input/input'; type CursorMatch = [ tokenStart: number | null, @@ -59,6 +61,7 @@ interface IAutosuggestInput extends Pick, maxLength?: number, menu?: Menu, resultsPosition: string, + theme?: InputThemes, } export default class AutosuggestInput extends ImmutablePureComponent { @@ -284,7 +287,7 @@ export default class AutosuggestInput extends ImmutablePureComponent - , diff --git a/app/soapbox/components/ui/input/input.tsx b/app/soapbox/components/ui/input/input.tsx index c77ae8169..6be89c2d4 100644 --- a/app/soapbox/components/ui/input/input.tsx +++ b/app/soapbox/components/ui/input/input.tsx @@ -11,7 +11,10 @@ const messages = defineMessages({ hidePassword: { id: 'input.password.hide_password', defaultMessage: 'Hide password' }, }); -interface IInput extends Pick, 'maxLength' | 'onChange' | 'onBlur' | 'type' | 'autoComplete' | 'autoCorrect' | 'autoCapitalize' | 'required' | 'disabled' | 'onClick' | 'readOnly' | 'min' | 'pattern'> { +/** Possible theme names for an Input. */ +type InputThemes = 'normal' | 'search' | 'transparent'; + +interface IInput extends Pick, 'maxLength' | 'onChange' | 'onBlur' | 'type' | 'autoComplete' | 'autoCorrect' | 'autoCapitalize' | 'required' | 'disabled' | 'onClick' | 'readOnly' | 'min' | 'pattern' | 'onKeyDown' | 'onKeyUp' | 'onFocus' | 'style' | 'id'> { /** Put the cursor into the input on mount. */ autoFocus?: boolean, /** The initial text in the input. */ @@ -36,8 +39,8 @@ interface IInput extends Pick, 'maxL prepend?: React.ReactElement, /** An element to display as suffix to input. Cannot be used with password type. */ append?: React.ReactElement, - /** Adds specific styling to denote a searchabe input. */ - isSearch?: boolean, + /** Theme to style the input with. */ + theme?: InputThemes, } /** Form input element. */ @@ -45,7 +48,7 @@ const Input = React.forwardRef( (props, ref) => { const intl = useIntl(); - const { type = 'text', icon, className, outerClassName, hasError, append, prepend, isSearch, ...filteredProps } = props; + const { type = 'text', icon, className, outerClassName, hasError, append, prepend, theme = 'normal', ...filteredProps } = props; const [revealed, setRevealed] = React.useState(false); @@ -59,8 +62,8 @@ const Input = React.forwardRef(
@@ -82,9 +85,10 @@ const Input = React.forwardRef( ref={ref} className={classNames({ 'text-gray-900 dark:text-gray-100 placeholder:text-gray-600 dark:placeholder:text-gray-600 block w-full sm:text-sm dark:ring-1 dark:ring-gray-800 focus:ring-primary-500 focus:border-primary-500 dark:focus:ring-primary-500 dark:focus:border-primary-500': - true, - 'rounded-md bg-white dark:bg-gray-900 border-gray-400 dark:border-gray-800': !isSearch, - 'rounded-full bg-gray-200 border-gray-200 dark:bg-gray-800 dark:border-gray-800 focus:bg-white': isSearch, + ['normal', 'search'].includes(theme), + 'rounded-md bg-white dark:bg-gray-900 border-gray-400 dark:border-gray-800': theme === 'normal', + 'rounded-full bg-gray-200 border-gray-200 dark:bg-gray-800 dark:border-gray-800 focus:bg-white': theme === 'search', + 'bg-transparent border-none': theme === 'transparent', 'pr-7': isPassword || append, 'text-red-600 border-red-600': hasError, 'pl-8': typeof icon !== 'undefined', @@ -127,4 +131,7 @@ const Input = React.forwardRef( }, ); -export default Input; +export { + Input as default, + InputThemes, +}; diff --git a/app/soapbox/features/compose/components/search.tsx b/app/soapbox/features/compose/components/search.tsx index 9402b8785..818080f2f 100644 --- a/app/soapbox/features/compose/components/search.tsx +++ b/app/soapbox/features/compose/components/search.tsx @@ -15,6 +15,7 @@ import { submitSearch, } from 'soapbox/actions/search'; import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input'; +import { Input } from 'soapbox/components/ui'; import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; import { useAppSelector } from 'soapbox/hooks'; @@ -117,7 +118,6 @@ const Search = (props: ISearch) => { const hasValue = value.length > 0 || submitted; const componentProps: any = { - className: 'block w-full pl-3 pr-10 py-2 border border-gray-200 dark:border-gray-800 rounded-full leading-5 bg-gray-200 dark:bg-gray-800 dark:text-white placeholder:text-gray-600 dark:placeholder:text-gray-600 focus:outline-none focus:ring-2 focus:ring-primary-500 sm:text-sm', type: 'text', id: 'search', placeholder: intl.formatMessage(messages.placeholder), @@ -126,6 +126,7 @@ const Search = (props: ISearch) => { onKeyDown: handleKeyDown, onFocus: handleFocus, autoFocus: autoFocus, + theme: 'search', }; if (autosuggest) { @@ -142,7 +143,7 @@ const Search = (props: ISearch) => { {autosuggest ? ( ) : ( - + )}