Add form element on compose area
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
e93603d744
commit
99bd9f5e8e
|
@ -40,6 +40,8 @@ interface IHStack {
|
||||||
space?: keyof typeof spaces
|
space?: keyof typeof spaces
|
||||||
/** Whether to let the flexbox grow. */
|
/** Whether to let the flexbox grow. */
|
||||||
grow?: boolean
|
grow?: boolean
|
||||||
|
/** HTML element to use for container. */
|
||||||
|
element?: keyof JSX.IntrinsicElements,
|
||||||
/** Extra CSS styles for the <div> */
|
/** Extra CSS styles for the <div> */
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
/** Whether to let the flexbox wrap onto multiple lines. */
|
/** Whether to let the flexbox wrap onto multiple lines. */
|
||||||
|
@ -48,10 +50,12 @@ interface IHStack {
|
||||||
|
|
||||||
/** Horizontal row of child elements. */
|
/** Horizontal row of child elements. */
|
||||||
const HStack = forwardRef<HTMLDivElement, IHStack>((props, ref) => {
|
const HStack = forwardRef<HTMLDivElement, IHStack>((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 (
|
return (
|
||||||
<div
|
<Elem
|
||||||
{...filteredProps}
|
{...filteredProps}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={classNames('flex', {
|
className={classNames('flex', {
|
||||||
|
|
|
@ -23,24 +23,28 @@ const alignItemsOptions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
|
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
/** Size of the gap between elements. */
|
|
||||||
space?: keyof typeof spaces
|
|
||||||
/** Horizontal alignment of children. */
|
/** Horizontal alignment of children. */
|
||||||
alignItems?: 'center'
|
alignItems?: 'center'
|
||||||
|
/** Extra class names on the element. */
|
||||||
|
className?: string
|
||||||
/** Vertical alignment of children. */
|
/** Vertical alignment of children. */
|
||||||
justifyContent?: keyof typeof justifyContentOptions
|
justifyContent?: keyof typeof justifyContentOptions
|
||||||
/** Extra class names on the <div> element. */
|
/** Size of the gap between elements. */
|
||||||
className?: string
|
space?: keyof typeof spaces
|
||||||
/** Whether to let the flexbox grow. */
|
/** Whether to let the flexbox grow. */
|
||||||
grow?: boolean
|
grow?: boolean
|
||||||
|
/** HTML element to use for container. */
|
||||||
|
element?: keyof JSX.IntrinsicElements,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vertical stack of child elements. */
|
/** Vertical stack of child elements. */
|
||||||
const Stack = React.forwardRef<HTMLDivElement, IStack>((props, ref: React.LegacyRef<HTMLDivElement> | undefined) => {
|
const Stack = React.forwardRef<HTMLDivElement, IStack>((props, ref: React.LegacyRef<HTMLDivElement> | 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 (
|
return (
|
||||||
<div
|
<Elem
|
||||||
{...filteredProps}
|
{...filteredProps}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={classNames('flex flex-col', {
|
className={classNames('flex flex-col', {
|
||||||
|
|
|
@ -132,7 +132,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
||||||
setComposeFocused(true);
|
setComposeFocused(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = (e?: React.FormEvent<Element>) => {
|
||||||
if (text !== autosuggestTextareaRef.current?.textarea?.value) {
|
if (text !== autosuggestTextareaRef.current?.textarea?.value) {
|
||||||
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
|
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
|
||||||
// Update the state to match the current text
|
// Update the state to match the current text
|
||||||
|
@ -142,6 +142,10 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
||||||
// Submit disabled:
|
// Submit disabled:
|
||||||
const fulltext = [spoilerText, countableText(text)].join('');
|
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)) {
|
if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxTootChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +265,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className='w-full' space={4} ref={formRef} onClick={handleClick}>
|
<Stack className='w-full' space={4} ref={formRef} onClick={handleClick} element='form' onSubmit={handleSubmit}>
|
||||||
{scheduledStatusCount > 0 && (
|
{scheduledStatusCount > 0 && (
|
||||||
<Warning
|
<Warning
|
||||||
message={(
|
message={(
|
||||||
|
@ -339,7 +343,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button theme='primary' text={publishText} onClick={handleSubmit} disabled={disabledButton} />
|
<Button type='submit' theme='primary' text={publishText} disabled={disabledButton} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
@ -168,7 +168,7 @@ const PollForm: React.FC<IPollForm> = ({ composeId }) => {
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<button onClick={handleToggleMultiple} className='text-left'>
|
<button type='button' onClick={handleToggleMultiple} className='text-left'>
|
||||||
<HStack alignItems='center' justifyContent='between'>
|
<HStack alignItems='center' justifyContent='between'>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text weight='medium'>
|
<Text weight='medium'>
|
||||||
|
@ -197,7 +197,7 @@ const PollForm: React.FC<IPollForm> = ({ composeId }) => {
|
||||||
|
|
||||||
{/* Remove Poll */}
|
{/* Remove Poll */}
|
||||||
<div className='text-center'>
|
<div className='text-center'>
|
||||||
<button className='text-danger-500' onClick={onRemovePoll}>
|
<button type='button' className='text-danger-500' onClick={onRemovePoll}>
|
||||||
{intl.formatMessage(messages.removePoll)}
|
{intl.formatMessage(messages.removePoll)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -68,7 +68,7 @@ const SpoilerInput = React.forwardRef<AutosuggestInput, ISpoilerInput>(({
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='text-center'>
|
<div className='text-center'>
|
||||||
<button className='text-danger-500' onClick={handleRemove}>
|
<button type='button' className='text-danger-500' onClick={handleRemove}>
|
||||||
{intl.formatMessage(messages.remove)}
|
{intl.formatMessage(messages.remove)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,4 +77,4 @@ const SpoilerInput = React.forwardRef<AutosuggestInput, ISpoilerInput>(({
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default SpoilerInput;
|
export default SpoilerInput;
|
||||||
|
|
Loading…
Reference in New Issue