if (typeof action === 'function') {
e.preventDefault();
- action();
+ action(e);
} else if (to) {
e.preventDefault();
this.context.router.history.push(to);
return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
}
- const { text, href = '#' } = option;
+ const { text, href = '#', target = '_blank', method } = option;
return (
<li className='dropdown-menu__item' key={`${text}-${i}`}>
- <a href={href} target='_blank' rel='noopener noreferrer' role='button' tabIndex='0' ref={i === 0 ? this.setFocusRef : null} onClick={this.handleClick} onKeyPress={this.handleItemKeyPress} data-index={i}>
+ <a href={href} target={target} data-method={method} rel='noopener noreferrer' role='button' tabIndex='0' ref={i === 0 ? this.setFocusRef : null} onClick={this.handleClick} onKeyPress={this.handleItemKeyPress} data-index={i}>
{text}
</a>
</li>
// It should not be transformed when mounting because the resulting
// size will be used to determine the coordinate of the menu by
// react-overlays
- <div className='dropdown-menu' style={{ ...style, opacity: opacity, transform: mounted ? `scale(${scaleX}, ${scaleY})` : null }} ref={this.setRef}>
+ <div className={`dropdown-menu ${placement}`} style={{ ...style, opacity: opacity, transform: mounted ? `scale(${scaleX}, ${scaleY})` : null }} ref={this.setRef}>
<div className={`dropdown-menu__arrow ${placement}`} style={{ left: arrowOffsetLeft, top: arrowOffsetTop }} />
<ul>
}
}
- handleItemClick = (i, e) => {
+ handleItemClick = e => {
+ const i = Number(e.currentTarget.getAttribute('data-index'));
const { action, to } = this.props.items[i];
this.handleClose();
(item, i) => item ? {
...item,
name: `${item.text}-${i}`,
- onClick: item.action ? ((e) => { return onItemClick(i, e) }) : null,
} : null
),
+ onClick: onItemClick,
}) : openDropdownMenu(id, dropdownPlacement, keyboard, scrollKey));
},
+
onClose(id) {
dispatch(closeModal('ACTIONS'));
dispatch(closeDropdownMenu(id));
const active = (name === (this.props.value || this.state.value));
- const computedClass = classNames('composer--options--dropdown--content--item', {
- active,
- lengthy: meta,
- 'toggled-off': !on && on !== null && typeof on !== 'undefined',
- 'toggled-on': on,
- 'with-icon': icon,
- });
+ const computedClass = classNames('composer--options--dropdown--content--item', { active });
let prefix = null;
import DisplayName from 'flavours/glitch/components/display_name';
import classNames from 'classnames';
import Icon from 'flavours/glitch/components/icon';
-import Link from 'flavours/glitch/components/link';
import Toggle from 'react-toggle';
export default class ActionsModal extends ImmutablePureComponent {
static propTypes = {
status: ImmutablePropTypes.map,
+ onClick: PropTypes.func,
actions: PropTypes.arrayOf(PropTypes.shape({
active: PropTypes.bool,
href: PropTypes.string,
return (
<li key={name || i}>
- <Link
- className={classNames('link', { active })}
- href={href}
- onClick={on !== null && typeof on !== 'undefined' && onPassiveClick || onClick}
- role={onClick ? 'button' : null}
- >
- {function () {
-
- // We render a `<Toggle>` if we were provided an `on`
- // property, and otherwise show an `<Icon>` if available.
- switch (true) {
- case on !== null && typeof on !== 'undefined':
- return (
- <Toggle
- checked={on}
- onChange={onPassiveClick || onClick}
- />
- );
- case !!icon:
- return (
- <Icon
- className='icon'
- fixedWidth
- id={icon}
- />
- );
- default:
- return null;
- }
- }()}
+ <a href={href} target='_blank' rel='noopener noreferrer' onClick={on !== null && typeof on !== 'undefined' && onPassiveClick || onClick || this.props.onClick} data-index={i} className={classNames('link', { active })}>
+ {on !== null && typeof on !== 'undefined' && (
+ <Toggle
+ checked={on}
+ onChange={onPassiveClick || onClick}
+ />
+ )}
+ {icon && (
+ <Icon
+ className='icon'
+ fixedWidth
+ id={icon}
+ />
+ )}
{meta ? (
<div>
<strong>{text}</strong>
{meta}
</div>
) : <div>{text}</div>}
- </Link>
+ </a>
</li>
);
}