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:
commit
526afe6779
10 changed files with 143 additions and 144 deletions
|
@ -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;
|
|
@ -1,41 +0,0 @@
|
||||||
import classNames from 'classnames';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
|
||||||
|
|
||||||
import IconButton from '../../../components/icon_button';
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
|
||||||
marked: { id: 'compose_form.markdown.marked', defaultMessage: 'Post markdown enabled' },
|
|
||||||
unmarked: { id: 'compose_form.markdown.unmarked', defaultMessage: 'Post markdown disabled' },
|
|
||||||
});
|
|
||||||
|
|
||||||
export default @injectIntl
|
|
||||||
class MarkdownButton extends React.PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
active: PropTypes.bool,
|
|
||||||
onClick: PropTypes.func.isRequired,
|
|
||||||
intl: PropTypes.object.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
this.props.onClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { intl, active } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='compose-form__markdown-button'>
|
|
||||||
<IconButton
|
|
||||||
className={classNames('compose-form__markdown-button-icon', { active })}
|
|
||||||
src={require('@tabler/icons/icons/markdown.svg')}
|
|
||||||
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
|
|
||||||
onClick={this.handleClick}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
30
app/soapbox/features/compose/components/markdown_button.tsx
Normal file
30
app/soapbox/features/compose/components/markdown_button.tsx
Normal 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;
|
|
@ -1,48 +0,0 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
|
||||||
|
|
||||||
import IconButton from '../../../components/icon_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' },
|
|
||||||
});
|
|
||||||
|
|
||||||
export default
|
|
||||||
@injectIntl
|
|
||||||
class PollButton extends React.PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
disabled: PropTypes.bool,
|
|
||||||
unavailable: PropTypes.bool,
|
|
||||||
active: PropTypes.bool,
|
|
||||||
onClick: PropTypes.func.isRequired,
|
|
||||||
intl: PropTypes.object.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
this.props.onClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { intl, active, unavailable, disabled } = this.props;
|
|
||||||
|
|
||||||
if (unavailable) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='compose-form__poll-button'>
|
|
||||||
<IconButton
|
|
||||||
className={`compose-form__poll-button-icon ${active ? 'active' : ''}`}
|
|
||||||
src={require('@tabler/icons/icons/chart-bar.svg')}
|
|
||||||
title={intl.formatMessage(active ? messages.remove_poll : messages.add_poll)}
|
|
||||||
disabled={disabled}
|
|
||||||
onClick={this.handleClick}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
36
app/soapbox/features/compose/components/poll_button.tsx
Normal file
36
app/soapbox/features/compose/components/poll_button.tsx
Normal 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;
|
|
@ -8,7 +8,7 @@ import Overlay from 'react-overlays/lib/Overlay';
|
||||||
|
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
|
|
||||||
import IconButton from '../../../components/icon_button';
|
import { IconButton } from '../../../components/ui';
|
||||||
import Motion from '../../ui/util/optional_motion';
|
import Motion from '../../ui/util/optional_motion';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
@ -253,7 +253,7 @@ class PrivacyDropdown extends React.PureComponent {
|
||||||
<div className={classNames('privacy-dropdown', placement, { active: open })} onKeyDown={this.handleKeyDown}>
|
<div className={classNames('privacy-dropdown', placement, { active: open })} onKeyDown={this.handleKeyDown}>
|
||||||
<div className={classNames('privacy-dropdown__value', { active: this.options.indexOf(valueOption) === 0 })}>
|
<div className={classNames('privacy-dropdown__value', { active: this.options.indexOf(valueOption) === 0 })}>
|
||||||
<IconButton
|
<IconButton
|
||||||
className='privacy-dropdown__value-icon'
|
className='text-gray-400 hover:text-gray-600'
|
||||||
src={valueOption.icon}
|
src={valueOption.icon}
|
||||||
title={intl.formatMessage(messages.change_privacy)}
|
title={intl.formatMessage(messages.change_privacy)}
|
||||||
expanded={open}
|
expanded={open}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import classNames from 'classnames';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
import { defineMessages, injectIntl } from 'react-intl';
|
||||||
|
|
||||||
import IconButton from '../../../components/icon_button';
|
import ComposeFormButton from './compose_form_button';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
add_schedule: { id: 'schedule_button.add_schedule', defaultMessage: 'Schedule post for later' },
|
add_schedule: { id: 'schedule_button.add_schedule', defaultMessage: 'Schedule post for later' },
|
||||||
|
@ -29,15 +28,13 @@ class ScheduleButton extends React.PureComponent {
|
||||||
const { intl, active, disabled } = this.props;
|
const { intl, active, disabled } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='compose-form__schedule-button'>
|
<ComposeFormButton
|
||||||
<IconButton
|
icon={require('@tabler/icons/icons/calendar-stats.svg')}
|
||||||
className={classNames('compose-form__schedule-button-icon', { active })}
|
title={intl.formatMessage(active ? messages.remove_schedule : messages.add_schedule)}
|
||||||
src={require('@tabler/icons/icons/calendar-stats.svg')}
|
active={active}
|
||||||
title={intl.formatMessage(active ? messages.remove_schedule : messages.add_schedule)}
|
disabled={disabled}
|
||||||
disabled={disabled}
|
onClick={this.handleClick}
|
||||||
onClick={this.handleClick}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import classNames from 'classnames';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
|
||||||
|
|
||||||
import IconButton from '../../../components/icon_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' },
|
|
||||||
});
|
|
||||||
|
|
||||||
export default @injectIntl
|
|
||||||
class SpoilerButton extends React.PureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
active: PropTypes.bool,
|
|
||||||
onClick: PropTypes.func.isRequired,
|
|
||||||
intl: PropTypes.object.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleClick = () => {
|
|
||||||
this.props.onClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { intl, active } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='compose-form__spoiler-button'>
|
|
||||||
<IconButton
|
|
||||||
className={classNames('compose-form__spoiler-button-icon', { active })}
|
|
||||||
src={require('@tabler/icons/icons/alert-triangle.svg')}
|
|
||||||
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
|
|
||||||
onClick={this.handleClick}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
29
app/soapbox/features/compose/components/spoiler_button.tsx
Normal file
29
app/soapbox/features/compose/components/spoiler_button.tsx
Normal 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;
|
|
@ -12,7 +12,10 @@ const mapStateToProps = (state, { intl }) => {
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
dispatch(changeComposeContentType(this.active ? 'text/plain' : 'text/markdown'));
|
dispatch((_, getState) => {
|
||||||
|
const active = getState().getIn(['compose', 'content_type']) === 'text/markdown';
|
||||||
|
dispatch(changeComposeContentType(active ? 'text/plain' : 'text/markdown'));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue