Merge branch 'next-compose-form-buttons' into 'next'

Next: improve ComposeForm buttons

See merge request soapbox-pub/soapbox-fe!1125
This commit is contained in:
Alex Gleason 2022-03-21 22:45:45 +00:00
commit 526afe6779
10 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,34 @@
import classNames from 'classnames';
import React from 'react';
import { IconButton } from 'soapbox/components/ui';
interface IComposeFormButton {
icon: string,
title?: string,
active?: boolean,
disabled?: boolean,
onClick: () => void,
}
const ComposeFormButton: React.FC<IComposeFormButton> = ({
icon,
title,
active,
disabled,
onClick,
}) => {
return (
<div>
<IconButton
className={classNames('text-gray-400 hover:text-gray-600', { 'text-gray-600': active })}
src={icon}
title={title}
disabled={disabled}
onClick={onClick}
/>
</div>
);
};
export default ComposeFormButton;

View file

@ -0,0 +1,30 @@
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import ComposeFormButton from './compose_form_button';
const messages = defineMessages({
marked: { id: 'compose_form.markdown.marked', defaultMessage: 'Post markdown enabled' },
unmarked: { id: 'compose_form.markdown.unmarked', defaultMessage: 'Post markdown disabled' },
});
interface IMarkdownButton {
active?: boolean,
onClick: () => void,
}
const MarkdownButton: React.FC<IMarkdownButton> = ({ active, onClick }) => {
const intl = useIntl();
return (
<ComposeFormButton
icon={require('@tabler/icons/icons/markdown.svg')}
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
active={active}
onClick={onClick}
/>
);
};
export default MarkdownButton;

View file

@ -0,0 +1,36 @@
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import ComposeFormButton from './compose_form_button';
const messages = defineMessages({
add_poll: { id: 'poll_button.add_poll', defaultMessage: 'Add a poll' },
remove_poll: { id: 'poll_button.remove_poll', defaultMessage: 'Remove poll' },
});
interface IPollButton {
disabled?: boolean,
unavailable?: boolean,
active?: boolean,
onClick: () => void,
}
const PollButton: React.FC<IPollButton> = ({ active, unavailable, disabled, onClick }) => {
const intl = useIntl();
if (unavailable) {
return null;
}
return (
<ComposeFormButton
icon={require('@tabler/icons/icons/chart-bar.svg')}
title={intl.formatMessage(active ? messages.remove_poll : messages.add_poll)}
active={active}
disabled={disabled}
onClick={onClick}
/>
);
};
export default PollButton;

View file

@ -0,0 +1,29 @@
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import ComposeFormButton from './compose_form_button';
const messages = defineMessages({
marked: { id: 'compose_form.spoiler.marked', defaultMessage: 'Text is hidden behind warning' },
unmarked: { id: 'compose_form.spoiler.unmarked', defaultMessage: 'Text is not hidden' },
});
interface ISpoilerButton {
active?: boolean,
onClick: () => void,
}
const SpoilerButton: React.FC<ISpoilerButton> = ({ active, onClick }) => {
const intl = useIntl();
return (
<ComposeFormButton
icon={require('@tabler/icons/icons/alert-triangle.svg')}
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
active={active}
onClick={onClick}
/>
);
};
export default SpoilerButton;