aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/portal/menu.tsx
blob: e8353a3b021316bc884e1c851fdff8f80e29476c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Styles } from '@0xproject/react-shared';
import * as _ from 'lodash';
import * as React from 'react';
import { MenuItem } from 'ts/components/ui/menu_item';
import { Environments, WebsitePaths } from 'ts/types';
import { colors } from 'ts/utils/colors';
import { configs } from 'ts/utils/configs';

export interface MenuTheme {
    paddingLeft: number;
    textColor: string;
    iconColor: string;
    selectedIconColor: string;
    selectedBackgroundColor: string;
}

export interface MenuItemEntry {
    to: string;
    labelText: string;
    iconName: string;
}

export interface MenuProps {
    selectedPath?: string;
    theme?: MenuTheme;
    menuItemEntries?: MenuItemEntry[];
}

export const defaultMenuItemEntries: MenuItemEntry[] = [
    {
        to: `${WebsitePaths.Portal}/account`,
        labelText: 'Account overview',
        iconName: 'zmdi-balance-wallet',
    },
    {
        to: `${WebsitePaths.Portal}/trades`,
        labelText: 'Trade history',
        iconName: 'zmdi-format-list-bulleted',
    },
    {
        to: `${WebsitePaths.Portal}/weth`,
        labelText: 'Wrapped ETH',
        iconName: 'zmdi-circle-o',
    },
    {
        to: `${WebsitePaths.Portal}/direct`,
        labelText: 'Trade direct',
        iconName: 'zmdi-swap',
    },
];

const DEFAULT_MENU_THEME: MenuTheme = {
    paddingLeft: 30,
    textColor: colors.white,
    iconColor: colors.white,
    selectedIconColor: colors.white,
    selectedBackgroundColor: colors.menuItemDefaultSelectedBackground,
};

export const Menu: React.StatelessComponent<MenuProps> = (props: MenuProps) => {
    return (
        <div>
            {_.map(props.menuItemEntries, entry => {
                const selected = entry.to === props.selectedPath;
                return (
                    <MenuItem key={entry.to} to={entry.to}>
                        <MenuItemLabel
                            title={entry.labelText}
                            iconName={entry.iconName}
                            selected={selected}
                            theme={props.theme}
                        />
                    </MenuItem>
                );
            })}
        </div>
    );
};
Menu.defaultProps = {
    theme: DEFAULT_MENU_THEME,
    menuItemEntries: defaultMenuItemEntries,
};

interface MenuItemLabelProps {
    title: string;
    iconName: string;
    selected: boolean;
    theme: MenuTheme;
}
const MenuItemLabel: React.StatelessComponent<MenuItemLabelProps> = (props: MenuItemLabelProps) => {
    const styles: Styles = {
        root: {
            backgroundColor: props.selected ? props.theme.selectedBackgroundColor : undefined,
            paddingLeft: props.theme.paddingLeft,
        },
        icon: {
            color: props.selected ? props.theme.selectedIconColor : props.theme.iconColor,
            fontSize: 20,
        },
        text: {
            color: props.theme.textColor,
            fontWeight: props.selected ? 'bold' : 'normal',
            fontSize: 16,
        },
    };
    return (
        <div className="flex py2" style={styles.root}>
            <div className="pr1">
                <i style={styles.icon} className={`zmdi ${props.iconName}`} />
            </div>
            <div className="pl1" style={styles.text}>
                {props.title}
            </div>
        </div>
    );
};