Use new Link UI component everywhere, and add complementary ALink type

This commit is contained in:
Fabio Berger
2018-10-02 20:10:59 +01:00
parent 0c99680396
commit c07412a992
20 changed files with 424 additions and 347 deletions

View File

@@ -0,0 +1,51 @@
import * as _ from 'lodash';
import * as React from 'react';
import { Link } from 'ts/components/ui/link';
interface CustomMenuItemProps {
to: string;
style?: React.CSSProperties;
onClick?: () => void;
className?: string;
}
interface CustomMenuItemState {
isHovering: boolean;
}
export class CustomMenuItem extends React.Component<CustomMenuItemProps, CustomMenuItemState> {
public static defaultProps: Partial<CustomMenuItemProps> = {
onClick: _.noop.bind(_),
className: '',
};
public constructor(props: CustomMenuItemProps) {
super(props);
this.state = {
isHovering: false,
};
}
public render(): React.ReactNode {
const menuItemStyles = {
cursor: 'pointer',
opacity: this.state.isHovering ? 0.5 : 1,
};
return (
<Link to={this.props.to} style={this.props.style}>
<div
onClick={this.props.onClick.bind(this)}
className={`mx-auto ${this.props.className}`}
style={menuItemStyles}
onMouseEnter={this._onToggleHover.bind(this, true)}
onMouseLeave={this._onToggleHover.bind(this, false)}
>
{this.props.children}
</div>
</Link>
);
}
private _onToggleHover(isHovering: boolean): void {
this.setState({
isHovering,
});
}
}