Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 45 additions & 40 deletions app/javascript/mastodon/components/fold_button.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import React from 'react';
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import classNames from 'classnames';

import spring from 'react-motion/lib/spring';
import { Icon } from '@/mastodon/components/icon';
import ArrowDropDownIcon from '@/material-icons/400-24px/arrow_drop_down.svg?react';

import Motion from '../features/ui/util/optional_motion';
export default class FoldButton extends PureComponent {

import { IconButton } from './icon_button';
static propTypes = {
active: PropTypes.bool,
activeStyle: PropTypes.object,
animate: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
expanded: PropTypes.bool,
inverted: PropTypes.bool,
onClick: PropTypes.func,
overlay: PropTypes.bool,
pressed: PropTypes.bool,
size: PropTypes.number,
style: PropTypes.object,
tabIndex: PropTypes.number,
title: PropTypes.string,
};

export default class FoldButton extends IconButton {
handleClick = (e) => {
e.preventDefault();
if (!this.props.disabled && this.props.onClick) {
this.props.onClick(e);
}
};

render () {
const style = {
Expand All @@ -26,7 +48,6 @@ export default class FoldButton extends IconButton {
className,
disabled,
expanded,
icon,
inverted,
overlay,
pressed,
Expand All @@ -41,42 +62,26 @@ export default class FoldButton extends IconButton {
overlayed: overlay,
});

if (!animate) {
// Perf optimization: avoid unnecessary <Motion> components unless
// we actually need to animate.
return (
<button
aria-label={title}
aria-pressed={pressed}
aria-expanded={expanded}
title={title}
className={classes}
onClick={this.handleClick}
style={style}
tabIndex={tabIndex}
>
<i className={`fa fa-fw fa-${icon}`} aria-hidden='true' />
</button>
);
}
const iconStyle = animate ? {
transform: `rotate(${active ? 180 : 0}deg)`,
transition: 'transform 300ms ease-in-out'
} : {
transform: `rotate(${active ? 180 : 0}deg)`
};

return (
<Motion defaultStyle={{ rotate: this.props.active ? 180 : 0 }} style={{ rotate: this.props.animate ? spring(this.props.active ? 0 : 180) : 0 }}>
{({ rotate }) =>
(<button
aria-label={title}
aria-pressed={pressed}
aria-expanded={expanded}
title={title}
className={classes}
onClick={this.handleClick}
style={style}
tabIndex={tabIndex}
>
<i style={{ transform: `rotate(${rotate}deg)` }} className={`fa fa-fw fa-${icon}`} aria-hidden='true' />
</button>)
}
</Motion>
<button
aria-label={title}
aria-pressed={pressed}
aria-expanded={expanded}
title={title}
className={classes}
onClick={this.handleClick}
style={style}
tabIndex={tabIndex}
>
<Icon id='down' icon={ArrowDropDownIcon} className='compose__extra__header__icon' style={iconStyle} />
</button>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ class FavouriteTags extends React.PureComponent {
<span>{intl.formatMessage(messages.favourite_tags)}</span>
</div>
<div className='compose__extra__header__right'>
<div className='compose__extra__header__icon'>
<a href='/settings/favourite_tags'>
<Icon id='setting_icon' icon={SettingIcon} className='compose__extra__header__icon' />
</a>
</div>
<a href='/settings/favourite_tags' className='compose__extra__header__icon'>
<Icon id='setting_icon' icon={SettingIcon} className='compose__extra__header__icon' />
</a>
<div className='compose__extra__header__fold__icon'>
<FoldButton title={intl.formatMessage(messages.toggle_visible)} icon='caret-up' onClick={onToggle} size={20} animate active={visible} />
</div>
Expand Down
11 changes: 8 additions & 3 deletions app/javascript/styles/imastodon/compose_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@
&__right {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
}

&__icon {
background: transparent;
color: $white;
border: 0;
padding: 0;
margin-right: 8px;
text-align: center;
width: 24px;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
}

&__fold__icon {
position: absolute;
right: 14px;
display: flex;
align-items: center;
}
}

Expand Down
Loading