From 99bd9f5e8e41947b78c8c3e9d6cab8aea8aa75c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 5 Nov 2022 11:46:15 +0100 Subject: [PATCH] Add form element on compose area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/ui/hstack/hstack.tsx | 8 ++++++-- app/soapbox/components/ui/stack/stack.tsx | 16 ++++++++++------ .../features/compose/components/compose-form.tsx | 10 +++++++--- .../compose/components/polls/poll-form.tsx | 4 ++-- .../compose/components/spoiler-input.tsx | 4 ++-- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/soapbox/components/ui/hstack/hstack.tsx b/app/soapbox/components/ui/hstack/hstack.tsx index a109da608..996320dea 100644 --- a/app/soapbox/components/ui/hstack/hstack.tsx +++ b/app/soapbox/components/ui/hstack/hstack.tsx @@ -40,6 +40,8 @@ interface IHStack { space?: keyof typeof spaces /** Whether to let the flexbox grow. */ grow?: boolean + /** HTML element to use for container. */ + element?: keyof JSX.IntrinsicElements, /** Extra CSS styles for the
*/ style?: React.CSSProperties /** Whether to let the flexbox wrap onto multiple lines. */ @@ -48,10 +50,12 @@ interface IHStack { /** Horizontal row of child elements. */ const HStack = forwardRef((props, ref) => { - const { space, alignItems, grow, justifyContent, wrap, className, ...filteredProps } = props; + const { space, alignItems, justifyContent, className, grow, element = 'div', wrap, ...filteredProps } = props; + + const Elem = element as 'div'; return ( -
{ - /** Size of the gap between elements. */ - space?: keyof typeof spaces /** Horizontal alignment of children. */ alignItems?: 'center' + /** Extra class names on the element. */ + className?: string /** Vertical alignment of children. */ justifyContent?: keyof typeof justifyContentOptions - /** Extra class names on the
element. */ - className?: string + /** Size of the gap between elements. */ + space?: keyof typeof spaces /** Whether to let the flexbox grow. */ grow?: boolean + /** HTML element to use for container. */ + element?: keyof JSX.IntrinsicElements, } /** Vertical stack of child elements. */ const Stack = React.forwardRef((props, ref: React.LegacyRef | undefined) => { - const { space, alignItems, justifyContent, className, grow, ...filteredProps } = props; + const { space, alignItems, justifyContent, className, grow, element = 'div', ...filteredProps } = props; + + const Elem = element as 'div'; return ( -
({ id, shouldCondense, autoFocus, clickab setComposeFocused(true); }; - const handleSubmit = () => { + const handleSubmit = (e?: React.FormEvent) => { if (text !== autosuggestTextareaRef.current?.textarea?.value) { // Something changed the text inside the textarea (e.g. browser extensions like Grammarly) // Update the state to match the current text @@ -142,6 +142,10 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab // Submit disabled: const fulltext = [spoilerText, countableText(text)].join(''); + if (e) { + e.preventDefault(); + } + if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxTootChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) { return; } @@ -261,7 +265,7 @@ const ComposeForm = ({ id, shouldCondense, autoFocus, clickab } return ( - + {scheduledStatusCount > 0 && ( ({ id, shouldCondense, autoFocus, clickab
)} -
diff --git a/app/soapbox/features/compose/components/polls/poll-form.tsx b/app/soapbox/features/compose/components/polls/poll-form.tsx index 4daf54048..e61f1975f 100644 --- a/app/soapbox/features/compose/components/polls/poll-form.tsx +++ b/app/soapbox/features/compose/components/polls/poll-form.tsx @@ -168,7 +168,7 @@ const PollForm: React.FC = ({ composeId }) => { -
diff --git a/app/soapbox/features/compose/components/spoiler-input.tsx b/app/soapbox/features/compose/components/spoiler-input.tsx index e6f53d04c..873450116 100644 --- a/app/soapbox/features/compose/components/spoiler-input.tsx +++ b/app/soapbox/features/compose/components/spoiler-input.tsx @@ -68,7 +68,7 @@ const SpoilerInput = React.forwardRef(({ />
-
@@ -77,4 +77,4 @@ const SpoilerInput = React.forwardRef(({ ); }); -export default SpoilerInput; \ No newline at end of file +export default SpoilerInput;