aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/ui
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-07-02 04:31:43 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-07-02 05:50:55 +0800
commita6f40d418704a8dca8c787663f00b6bcbdf18ba4 (patch)
tree8da4c0c480df8d200b0a39e7945787e95953b1e8 /packages/website/ts/components/ui
parent6daf754f5bb4aa85d0f65bfdaf8910db4401d1cc (diff)
downloaddexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar.gz
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar.bz2
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar.lz
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar.xz
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.tar.zst
dexon-sol-tools-a6f40d418704a8dca8c787663f00b6bcbdf18ba4.zip
Implement correct behavior for menu in the wallet
Diffstat (limited to 'packages/website/ts/components/ui')
-rw-r--r--packages/website/ts/components/ui/drop_down.tsx27
-rw-r--r--packages/website/ts/components/ui/simple_menu.tsx14
2 files changed, 32 insertions, 9 deletions
diff --git a/packages/website/ts/components/ui/drop_down.tsx b/packages/website/ts/components/ui/drop_down.tsx
index 3738e50eb..3f1fec3f4 100644
--- a/packages/website/ts/components/ui/drop_down.tsx
+++ b/packages/website/ts/components/ui/drop_down.tsx
@@ -8,12 +8,13 @@ const DEFAULT_STYLE = {
};
interface DropDownProps {
- hoverActiveNode: React.ReactNode;
+ activeNode: React.ReactNode;
popoverContent: React.ReactNode;
anchorOrigin: MaterialUIPosition;
targetOrigin: MaterialUIPosition;
style?: React.CSSProperties;
zDepth?: number;
+ shouldWaitForClickToActivate?: boolean;
}
interface DropDownState {
@@ -25,6 +26,7 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
public static defaultProps: Partial<DropDownProps> = {
style: DEFAULT_STYLE,
zDepth: 1,
+ shouldWaitForClickToActivate: false,
};
private _isHovering: boolean;
private _popoverCloseCheckIntervalId: number;
@@ -49,7 +51,7 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
// call hoverOff whenever the dropdown receives updated props. This is a hack
// because it will effectively close the dropdown on any prop update, barring
// dropdowns from having dynamic content.
- // this._onHoverOff();
+ this._onHoverOff();
}
public render(): React.ReactNode {
return (
@@ -58,7 +60,7 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
onMouseEnter={this._onHover.bind(this)}
onMouseLeave={this._onHoverOff.bind(this)}
>
- {this.props.hoverActiveNode}
+ <div onClick={this._onActiveNodeClick.bind(this)}>{this.props.activeNode}</div>
<Popover
open={this.state.isDropDownOpen}
anchorEl={this.state.anchorEl}
@@ -69,16 +71,31 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
animated={false}
zDepth={this.props.zDepth}
>
- <div onMouseEnter={this._onHover.bind(this)} onMouseLeave={this._onHoverOff.bind(this)}>
+ <div
+ onMouseEnter={this._onHover.bind(this)}
+ onMouseLeave={this._onHoverOff.bind(this)}
+ onClick={this._closePopover.bind(this)}
+ >
{this.props.popoverContent}
</div>
</Popover>
</div>
);
}
+ private _onActiveNodeClick(event: React.FormEvent<HTMLInputElement>): void {
+ event.stopPropagation();
+ if (this.props.shouldWaitForClickToActivate) {
+ this.setState({
+ isDropDownOpen: true,
+ anchorEl: event.currentTarget,
+ });
+ }
+ }
private _onHover(event: React.FormEvent<HTMLInputElement>): void {
this._isHovering = true;
- this._checkIfShouldOpenPopover(event);
+ if (!this.props.shouldWaitForClickToActivate) {
+ this._checkIfShouldOpenPopover(event);
+ }
}
private _checkIfShouldOpenPopover(event: React.FormEvent<HTMLInputElement>): void {
if (this.state.isDropDownOpen) {
diff --git a/packages/website/ts/components/ui/simple_menu.tsx b/packages/website/ts/components/ui/simple_menu.tsx
index 29445c965..22414d101 100644
--- a/packages/website/ts/components/ui/simple_menu.tsx
+++ b/packages/website/ts/components/ui/simple_menu.tsx
@@ -5,15 +5,17 @@ import { Container } from 'ts/components/ui/container';
import { Text } from 'ts/components/ui/text';
import { colors } from 'ts/style/colors';
-export interface SimpleMenuProps {}
+export interface SimpleMenuProps {
+ minWidth?: number | string;
+}
-export const SimpleMenu: React.StatelessComponent<SimpleMenuProps> = ({ children }) => {
+export const SimpleMenu: React.StatelessComponent<SimpleMenuProps> = ({ children, minWidth }) => {
return (
<Container
marginLeft="16px"
marginRight="16px"
marginBottom="16px"
- minWidth="220px"
+ minWidth={minWidth}
className="flex flex-column"
>
{children}
@@ -26,9 +28,13 @@ export interface SimpleMenuItemProps {
onClick?: () => void;
}
export const SimpleMenuItem: React.StatelessComponent<SimpleMenuItemProps> = ({ text, onClick }) => (
- <Container marginTop="16px" minWidth="220px" className="flex flex-column">
+ <Container marginTop="16px" className="flex flex-column">
<Text fontSize="14px" fontColor={colors.darkGrey} onClick={onClick} hoverColor={colors.mediumBlue}>
{text}
</Text>
</Container>
);
+
+SimpleMenu.defaultProps = {
+ minWidth: '220px',
+};