From 94ed67e339bb5aea726c216a9587c7d37d1f1c08 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 9 Apr 2023 20:22:28 -0700 Subject: [PATCH] Responsive updates. --- components/common/HamburgerButton.js | 20 ++++++------- components/common/MobileMenu.js | 9 ------ components/common/MobileMenu.module.css | 24 ++++------------ components/layout/NavBar.js | 4 +++ components/layout/NavBar.module.css | 11 +++++++- components/layout/Page.module.css | 6 ++++ components/layout/PageHeader.js | 9 ++++-- components/layout/PageHeader.module.css | 8 +++++- components/messages.js | 3 +- components/metrics/MetricCard.js | 3 +- components/metrics/MetricsBar.js | 6 +++- components/metrics/MetricsBar.module.css | 10 +++++-- components/metrics/WebsiteChart.js | 12 ++++---- components/metrics/WebsiteChart.module.css | 28 ++++++++++++------- components/metrics/WebsiteHeader.js | 4 +-- components/metrics/WebsiteHeader.module.css | 10 +++---- components/pages/dashboard/Dashboard.js | 2 +- components/pages/settings/users/UsersTable.js | 2 +- .../pages/settings/websites/WebsitesList.js | 2 +- .../pages/settings/websites/WebsitesTable.js | 4 ++- 20 files changed, 100 insertions(+), 77 deletions(-) diff --git a/components/common/HamburgerButton.js b/components/common/HamburgerButton.js index 97050a2a..77aaae75 100644 --- a/components/common/HamburgerButton.js +++ b/components/common/HamburgerButton.js @@ -3,11 +3,12 @@ import { useState } from 'react'; import MobileMenu from './MobileMenu'; import Icons from 'components/icons'; import useMessages from 'hooks/useMessages'; -import styles from './HamburgerButton.module.css'; +import useConfig from 'hooks/useConfig'; export default function HamburgerButton() { const { formatMessage, labels } = useMessages(); const [active, setActive] = useState(false); + const { cloudMode } = useConfig(); const menuItems = [ { @@ -15,7 +16,7 @@ export default function HamburgerButton() { value: '/dashboard', }, { label: formatMessage(labels.realtime), value: '/realtime' }, - { + !cloudMode && { label: formatMessage(labels.settings), value: '/settings', }, @@ -23,20 +24,15 @@ export default function HamburgerButton() { label: formatMessage(labels.profile), value: '/settings/profile', }, - { label: formatMessage(labels.logout), value: '/logout' }, - ]; + !cloudMode && { label: formatMessage(labels.logout), value: '/logout' }, + ].filter(n => n); - function handleClick() { - setActive(state => !state); - } - - function handleClose() { - setActive(false); - } + const handleClick = () => setActive(state => !state); + const handleClose = () => setActive(false); return ( <> - {active && } diff --git a/components/common/MobileMenu.js b/components/common/MobileMenu.js index 65c69a7b..aa737e7e 100644 --- a/components/common/MobileMenu.js +++ b/components/common/MobileMenu.js @@ -1,19 +1,10 @@ import classNames from 'classnames'; import Link from 'next/link'; -import { Button, Icon } from 'react-basics'; -import Icons from 'components/icons'; import styles from './MobileMenu.module.css'; export default function MobileMenu({ items = [], onClose }) { return (
-
- -
{items.map(({ label, value }) => ( diff --git a/components/common/MobileMenu.module.css b/components/common/MobileMenu.module.css index c8aa9617..aa9aafd0 100644 --- a/components/common/MobileMenu.module.css +++ b/components/common/MobileMenu.module.css @@ -1,6 +1,6 @@ .menu { position: fixed; - top: 0; + top: 60px; left: 0; right: 0; bottom: 0; @@ -13,29 +13,17 @@ } .items { - flex: 1; display: flex; flex-direction: column; - justify-content: center; - align-items: center; } .item { font-size: var(--font-size-lg); + font-weight: 700; + line-height: 80px; + padding: 0 40px; } -.item + .item { - margin-top: 20px; -} - -.item:last-child { - margin-top: 60px; -} - -.header { - display: flex; - justify-content: flex-end; - align-items: center; - height: 100px; - padding: 0 30px; +a.item { + color: var(--base900); } diff --git a/components/layout/NavBar.js b/components/layout/NavBar.js index fac9256b..46eabc9e 100644 --- a/components/layout/NavBar.js +++ b/components/layout/NavBar.js @@ -10,6 +10,7 @@ import styles from './NavBar.module.css'; import useConfig from 'hooks/useConfig'; import useMessages from 'hooks/useMessages'; import { useRouter } from 'next/router'; +import HamburgerButton from '../common/HamburgerButton'; export default function NavBar() { const { pathname } = useRouter(); @@ -52,6 +53,9 @@ export default function NavBar() {
+
+ +
diff --git a/components/layout/NavBar.module.css b/components/layout/NavBar.module.css index b0d546bd..6c2faaaf 100644 --- a/components/layout/NavBar.module.css +++ b/components/layout/NavBar.module.css @@ -59,7 +59,8 @@ border-bottom: 2px solid var(--primary400); } -.actions { +.actions, +.mobile { display: flex; flex-direction: row; align-items: center; @@ -67,9 +68,17 @@ min-width: 0; } +.mobile { + display: none; +} + @media only screen and (max-width: 768px) { .links, .actions { display: none; } + + .mobile { + display: flex; + } } diff --git a/components/layout/Page.module.css b/components/layout/Page.module.css index 225f081f..42aafbe1 100644 --- a/components/layout/Page.module.css +++ b/components/layout/Page.module.css @@ -6,3 +6,9 @@ position: relative; padding: 30px; } + +@media only screen and (max-width: 768px) { + .page { + padding: 10px 0; + } +} diff --git a/components/layout/PageHeader.js b/components/layout/PageHeader.js index 42667750..0d014316 100644 --- a/components/layout/PageHeader.js +++ b/components/layout/PageHeader.js @@ -1,12 +1,15 @@ import React from 'react'; import classNames from 'classnames'; +import { useBreakpoint } from 'react-basics'; import styles from './PageHeader.module.css'; -export default function PageHeader({ title, children, className, style }) { +export default function PageHeader({ title, children }) { + const breakPoint = useBreakpoint(); + return ( -
+
{title}
- {children} +
{children}
); } diff --git a/components/layout/PageHeader.module.css b/components/layout/PageHeader.module.css index 511f1091..d5481727 100644 --- a/components/layout/PageHeader.module.css +++ b/components/layout/PageHeader.module.css @@ -5,7 +5,7 @@ align-content: center; align-self: stretch; margin-bottom: 40px; - height: 50px; + flex-wrap: wrap; } .header a { @@ -22,4 +22,10 @@ font-size: 24px; font-weight: 700; gap: 20px; + line-height: 50px; +} + +.xs .actions, +.sm .actions { + flex-basis: 100%; } diff --git a/components/messages.js b/components/messages.js index feff749d..f0af08f7 100644 --- a/components/messages.js +++ b/components/messages.js @@ -14,7 +14,7 @@ export const labels = defineMessages({ password: { id: 'label.password', defaultMessage: 'Password' }, role: { id: 'label.role', defaultMessage: 'Role' }, user: { id: 'label.user', defaultMessage: 'User' }, - administrator: { id: 'label.administrator', defaultMessage: 'Administrator' }, + admin: { id: 'label.administrator', defaultMessage: 'Administrator' }, confirm: { id: 'label.confirm', defaultMessage: 'Confirm' }, details: { id: 'label.details', defaultMessage: 'Details' }, websites: { id: 'label.websites', defaultMessage: 'Websites' }, @@ -112,6 +112,7 @@ export const labels = defineMessages({ toggleCharts: { id: 'label.toggle-charts', defaultMessage: 'Toggle charts' }, editDashboard: { id: 'label.edit-dashboard', defaultMessage: 'Edit dashboard' }, title: { id: 'label.title', defaultMessage: 'Title' }, + view: { id: 'label.view', defaultMessage: 'View' }, }); export const messages = defineMessages({ diff --git a/components/metrics/MetricCard.js b/components/metrics/MetricCard.js index d4d4e33b..a49aeefc 100644 --- a/components/metrics/MetricCard.js +++ b/components/metrics/MetricCard.js @@ -10,12 +10,13 @@ const MetricCard = ({ reverseColors = false, format = formatNumber, hideComparison = false, + className, }) => { const props = useSpring({ x: Number(value) || 0, from: { x: 0 } }); const changeProps = useSpring({ x: Number(change) || 0, from: { x: 0 } }); return ( -
+
{props.x.to(x => format(x))}
{label} diff --git a/components/metrics/MetricsBar.js b/components/metrics/MetricsBar.js index 5eb225c3..2b94d303 100644 --- a/components/metrics/MetricsBar.js +++ b/components/metrics/MetricsBar.js @@ -6,8 +6,8 @@ import useDateRange from 'hooks/useDateRange'; import usePageQuery from 'hooks/usePageQuery'; import { formatShortTime, formatNumber, formatLongNumber } from 'lib/format'; import MetricCard from './MetricCard'; -import styles from './MetricsBar.module.css'; import useMessages from 'hooks/useMessages'; +import styles from './MetricsBar.module.css'; export default function MetricsBar({ websiteId }) { const { formatMessage, labels } = useMessages(); @@ -58,18 +58,21 @@ export default function MetricsBar({ websiteId }) { {data && !error && isFetched && ( <> - + - - - + +
+ + +
diff --git a/components/metrics/WebsiteChart.module.css b/components/metrics/WebsiteChart.module.css index 5bbb3a44..c9334a27 100644 --- a/components/metrics/WebsiteChart.module.css +++ b/components/metrics/WebsiteChart.module.css @@ -27,23 +27,31 @@ z-index: var(--z-index-above); } -.sticky { - position: sticky; - top: -1px; -} - -.isSticky { - border-bottom: 1px solid var(--base300); -} - .actions { display: flex; + align-items: center; flex-direction: row; justify-content: flex-end; gap: 10px; - flex: 1; } .dropdown { min-width: 200px; } + +@media only screen and (min-width: 992px) { + .sticky { + position: sticky; + top: -1px; + } + + .isSticky { + border-bottom: 1px solid var(--base300); + } +} + +@media only screen and (max-width: 1200px) { + .actions { + margin-top: 40px; + } +} diff --git a/components/metrics/WebsiteHeader.js b/components/metrics/WebsiteHeader.js index 4acea6f8..491068d6 100644 --- a/components/metrics/WebsiteHeader.js +++ b/components/metrics/WebsiteHeader.js @@ -6,11 +6,11 @@ import styles from './WebsiteHeader.module.css'; export default function WebsiteHeader({ websiteId, name, domain, children }) { return ( - + {name} - + {children} diff --git a/components/metrics/WebsiteHeader.module.css b/components/metrics/WebsiteHeader.module.css index 1e1f6111..e5ebcca7 100644 --- a/components/metrics/WebsiteHeader.module.css +++ b/components/metrics/WebsiteHeader.module.css @@ -1,8 +1,4 @@ -.header { - height: 100px; -} - -.name { +.title { display: flex; flex-direction: row; align-items: center; @@ -10,12 +6,14 @@ font-size: 24px; font-weight: 700; overflow: hidden; + height: 100px; } -.body { +.info { display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 30px; + min-height: 0; } diff --git a/components/pages/dashboard/Dashboard.js b/components/pages/dashboard/Dashboard.js index cc0fb013..6497aba4 100644 --- a/components/pages/dashboard/Dashboard.js +++ b/components/pages/dashboard/Dashboard.js @@ -30,7 +30,7 @@ export default function Dashboard({ userId }) { {!editing && hasData && } {!hasData && ( - +