Skip to content

Commit

Permalink
mobile responsive, how-to-human, add more charts, add tooltip icons
Browse files Browse the repository at this point in the history
  • Loading branch information
m00n620 committed Aug 22, 2023
1 parent 06972fb commit 11e96ea
Show file tree
Hide file tree
Showing 23 changed files with 600 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import numeral from 'numeral';
import { FC, ReactElement } from 'react';

import { Container } from '../Container';
import { TooltipIcon } from 'src/components/TooltipIcon';

type TextBlockProps = {
title: string | ReactElement;
Expand All @@ -24,7 +25,7 @@ export const TextBlock: FC<TextBlockProps> = ({
<Typography variant="body2" color="primary" fontWeight={600}>
{title}
</Typography>
<Box display="flex" alignItems="baseline">
<Box display="flex" alignItems="baseline" overflow="hidden">
{component ? (
component
) : (
Expand All @@ -33,7 +34,7 @@ export const TextBlock: FC<TextBlockProps> = ({
color="primary"
lineHeight={1}
marginTop={3}
sx={{ fontSize: { xs: 32, md: 48, lg: 64, xl: 80 } }}
sx={{ fontSize: { xs: 32, md: 42, xl: 60 } }}
>
{Number.isNaN(Number(value))
? value
Expand All @@ -53,6 +54,10 @@ export const TextBlock: FC<TextBlockProps> = ({
</Typography>
)}
</Box>
<TooltipIcon
position="topRight"
title="Sorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eu turpis molestie, dictum est a, mattis tellus. Sed dignissim."
/>
</Container>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ export const HumanAppDataContainer: FC = () => {
useHumanAppData();

return (
<Box id="network" mt={{ xs: 4, md: 8 }}>
<Box id="human-app-data" mt={{ xs: 4, md: 8 }}>
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
flexDirection: { xs: 'column', lg: 'row' },
justifyContent: { xs: 'flex-start', lg: 'space-between' },
alignItems: { xs: 'flex-start', lg: 'center' },
gap: 4,
mb: 4,
}}
>
<ViewTitle title="HUMAN App data" iconUrl={networkSvg} />
<Box sx={{ ml: 'auto' }}>
<Box sx={{ width: '100%', maxWidth: { xs: '100%', lg: '513px' } }}>
<NetworkSelect
value={ChainId.POLYGON_MUMBAI}
supportedChainIds={[ChainId.POLYGON_MUMBAI]}
width="100%"
/>
</Box>
<Box sx={{ ml: 'auto' }}>
<TimeRangeButtons />
<Box sx={{ width: '100%', maxWidth: { xs: '100%', lg: '368px' } }}>
<TimeRangeButtons fullWidth />
</Box>
</Box>
<HumanAppDataView />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Box, ToggleButton, ToggleButtonGroup } from '@mui/material';
import {
Box,
Stack,
ToggleButton,
ToggleButtonGroup,
useMediaQuery,
useTheme,
} from '@mui/material';
import { FC, useState } from 'react';

import { TooltipIcon } from '../TooltipIcon';
import { HMTView } from './views/HMT';
import { PaymentsView } from './views/Payments';
import { TasksView } from './views/Tasks';
Expand All @@ -21,8 +29,21 @@ const VIEW_BUTTONS = [
];

export const HumanAppDataView: FC = () => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(600));
const [viewButton, setViewButton] = useState(ViewButton.Tasks);

if (isMobile) {
return (
<Stack spacing={4}>
<TasksView />
<WorkersView />
<PaymentsView />
<HMTView />
</Stack>
);
}

return (
<Box
sx={{
Expand All @@ -32,6 +53,7 @@ export const HumanAppDataView: FC = () => {
'0px 1px 5px 0px rgba(233, 235, 250, 0.20), 0px 2px 2px 0px rgba(233, 235, 250, 0.50), 0px 3px 1px -2px #E9EBFA;',
py: 5,
px: 4,
position: 'relative',
}}
>
<ToggleButtonGroup
Expand Down Expand Up @@ -62,6 +84,7 @@ export const HumanAppDataView: FC = () => {
{viewButton === ViewButton.Payments && <PaymentsView />}
{viewButton === ViewButton.HMT && <HMTView />}
</Box>
<TooltipIcon title="Sorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eu turpis molestie, dictum est a, mattis tellus. Sed dignissim." />
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { Box, Typography } from '@mui/material';
import dayjs from 'dayjs';
import numeral from 'numeral';
import React from 'react';
import {
Area,
AreaChart,
CartesianGrid,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from 'recharts';

const CustomTooltip = ({ active, payload, label }: any) => {
if (active && payload && payload.length) {
return (
<Box
sx={{
background: '#fff',
border: '1px solid #CBCFE6',
borderRadius: '10px',
padding: '30px',
}}
>
<Typography
color="text.primary"
variant="body2"
fontWeight={600}
mb={2}
>
{dayjs(label).format('MMM D, YYYY')}
</Typography>
{/* <Typography color="text.primary" variant="caption">
{tab Value} Tasks
</Typography> */}
<Typography color="text.primary" variant="h6" fontWeight={500}>
{numeral(payload[0].value).format('0a').toUpperCase()}
</Typography>
</Box>
);
}

return null;
};

export const HumanAppDataChart = ({
data,
minWidth,
minHeight,
}: {
data: any;
minWidth?: number;
minHeight?: number;
}) => {
return (
<ResponsiveContainer
width="100%"
height="100%"
minWidth={minWidth}
minHeight={minHeight}
>
<AreaChart data={data}>
<defs>
<linearGradient
id="paint0_linear_4037_63345"
x1="257"
y1="0"
x2="257"
y2="276.5"
gradientUnits="userSpaceOnUse"
>
<stop offset="0.290598" stopColor="#CACFE8" stopOpacity="0.3" />
<stop offset="1" stopColor="#E9ECFF" stopOpacity="0" />
</linearGradient>
</defs>
<CartesianGrid vertical={false} strokeDasharray={3} />
<XAxis
dataKey="date"
axisLine={false}
tickLine={false}
tick={{
fill: '#320A8D',
fontSize: '14px',
fontFamily: 'Inter',
fontWeight: 500,
}}
tickFormatter={(value: any) => dayjs(value).format('MMM D')}
tickMargin={12}
padding={{ left: 10, right: 10 }}
/>
<YAxis
axisLine={false}
tickLine={false}
tick={{
fill: '#320A8D',
fontSize: '14px',
fontFamily: 'Inter',
fontWeight: 500,
}}
tickFormatter={(value: any) =>
numeral(value).format('0a').toUpperCase()
}
width={40}
/>
<Tooltip cursor={{ fill: '#dadef0' }} content={<CustomTooltip />} />
<Area
type="monotone"
dataKey="value"
stroke="#320A8D"
fill="url(#paint0_linear_4037_63345)"
/>
</AreaChart>
</ResponsiveContainer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import {
Box,
Button,
Menu,
MenuItem,
Tab,
Tabs,
Typography,
useMediaQuery,
useTheme,
} from '@mui/material';
import React, { useState } from 'react';

import { HumanAppDataChart } from '../chart';

type ChartContainerProps = {
data: any;
title: string;
items: Array<{ label: string; value: any }>;
onChange: (value: any) => void;
};

export const ChartContainer = ({
data,
title,
items,
onChange,
}: ChartContainerProps) => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(600));
const [tabValue, setTabValue] = useState(items[0].value);
const [menuValue, setMenuValue] = useState(0);

const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};

if (isMobile) {
return (
<Box
sx={{
borderRadius: '16px',
background: '#FFF',
boxShadow:
'0px 1px 5px 0px rgba(233, 235, 250, 0.20), 0px 2px 2px 0px rgba(233, 235, 250, 0.50), 0px 3px 1px -2px #E9EBFA;',
p: 4,
}}
>
<Typography fontSize={24} color="primary">
{title}
</Typography>
<Button
color="primary"
size="large"
variant="contained"
endIcon={<KeyboardArrowDownIcon />}
fullWidth
sx={{ my: 3 }}
onClick={handleClick}
>
{items[menuValue].label}
</Button>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
MenuListProps={{
sx: { width: anchorEl && anchorEl.offsetWidth },
}}
>
{items.map((item, index) => (
<MenuItem
key={item.value}
onClick={() => {
setMenuValue(index);
onChange(items[index].value);
handleClose();
}}
>
{item.label}
</MenuItem>
))}
</Menu>
{data && <HumanAppDataChart data={data} minHeight={250} />}
</Box>
);
}

return (
<Box
sx={{
width: '100%',
bgcolor: 'background.paper',
display: 'flex',
}}
>
<Tabs
orientation="vertical"
value={tabValue}
onChange={(e, newValue) => {
setTabValue(newValue);
onChange(newValue);
}}
sx={{
'& .MuiTabs-indicator': {
width: '100%',
left: 0,
height: '2px !important',
marginTop: '46px',
},
}}
>
{items.map((item) => (
<Tab
key={item.value}
label={item.label}
value={item.value}
sx={{ alignItems: 'flex-start' }}
/>
))}
</Tabs>
<Box
sx={{
flex: 1,
borderRadius: '8px',
background: '#F6F7FE',
py: { xs: 5, md: 10 },
px: { xs: 2, md: 5 },
ml: { xs: 4, md: 6, xl: 12 },
minHeight: 400,
overflowX: 'auto',
}}
>
{data && (
<HumanAppDataChart data={data} minHeight={300} minWidth={800} />
)}
</Box>
</Box>
);
};
Loading

0 comments on commit 11e96ea

Please sign in to comment.