mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
SingleTopNav: Tweaks for mobile responsiveness (#94188)
tweaks for mobile responsiveness
This commit is contained in:
parent
c7ca2bfcf5
commit
d4bb8122cb
@ -2,7 +2,7 @@ import { css } from '@emotion/css';
|
|||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { reportInteraction } from '@grafana/runtime';
|
import { config, reportInteraction } from '@grafana/runtime';
|
||||||
import { Menu, Dropdown, useStyles2, useTheme2, ToolbarButton } from '@grafana/ui';
|
import { Menu, Dropdown, useStyles2, useTheme2, ToolbarButton } from '@grafana/ui';
|
||||||
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
||||||
import { useSelector } from 'app/types';
|
import { useSelector } from 'app/types';
|
||||||
@ -22,6 +22,8 @@ export const QuickAdd = ({}: Props) => {
|
|||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [isSmallScreen, setIsSmallScreen] = useState(!window.matchMedia(`(min-width: ${breakpoint}px)`).matches);
|
const [isSmallScreen, setIsSmallScreen] = useState(!window.matchMedia(`(min-width: ${breakpoint}px)`).matches);
|
||||||
const createActions = useMemo(() => findCreateActions(navBarTree), [navBarTree]);
|
const createActions = useMemo(() => findCreateActions(navBarTree), [navBarTree]);
|
||||||
|
const isSingleTopNav = config.featureToggles.singleTopNav;
|
||||||
|
const showQuickAdd = createActions.length > 0 && (!isSingleTopNav || !isSmallScreen);
|
||||||
|
|
||||||
useMediaQueryChange({
|
useMediaQueryChange({
|
||||||
breakpoint,
|
breakpoint,
|
||||||
@ -45,7 +47,7 @@ export const QuickAdd = ({}: Props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return createActions.length > 0 ? (
|
return showQuickAdd ? (
|
||||||
<>
|
<>
|
||||||
<Dropdown overlay={MenuActions} placement="bottom-end" onVisibleChange={setIsOpen}>
|
<Dropdown overlay={MenuActions} placement="bottom-end" onVisibleChange={setIsOpen}>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
|
@ -23,7 +23,6 @@ import { TOP_BAR_LEVEL_HEIGHT } from '../types';
|
|||||||
import { SignInLink } from './SignInLink';
|
import { SignInLink } from './SignInLink';
|
||||||
import { TopNavBarMenu } from './TopNavBarMenu';
|
import { TopNavBarMenu } from './TopNavBarMenu';
|
||||||
import { TopSearchBarCommandPaletteTrigger } from './TopSearchBarCommandPaletteTrigger';
|
import { TopSearchBarCommandPaletteTrigger } from './TopSearchBarCommandPaletteTrigger';
|
||||||
import { TopSearchBarSection } from './TopSearchBarSection';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
sectionNav: NavModelItem;
|
sectionNav: NavModelItem;
|
||||||
@ -52,7 +51,7 @@ export const SingleTopBar = memo(function SingleTopBar({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.layout}>
|
<div className={styles.layout}>
|
||||||
<TopSearchBarSection>
|
<Stack minWidth={0} gap={0.5} alignItems="center">
|
||||||
{!menuDockedAndOpen && (
|
{!menuDockedAndOpen && (
|
||||||
<ToolbarButton narrow onClick={onToggleMegaMenu} tooltip={t('navigation.megamenu.open', 'Open menu')}>
|
<ToolbarButton narrow onClick={onToggleMegaMenu} tooltip={t('navigation.megamenu.open', 'Open menu')}>
|
||||||
<Stack gap={0} alignItems="center">
|
<Stack gap={0} alignItems="center">
|
||||||
@ -63,9 +62,9 @@ export const SingleTopBar = memo(function SingleTopBar({
|
|||||||
)}
|
)}
|
||||||
<Breadcrumbs breadcrumbs={breadcrumbs} className={styles.breadcrumbsWrapper} />
|
<Breadcrumbs breadcrumbs={breadcrumbs} className={styles.breadcrumbsWrapper} />
|
||||||
<ScopesSelector />
|
<ScopesSelector />
|
||||||
</TopSearchBarSection>
|
</Stack>
|
||||||
|
|
||||||
<TopSearchBarSection align="right">
|
<Stack gap={0.5} alignItems="center">
|
||||||
<TopSearchBarCommandPaletteTrigger />
|
<TopSearchBarCommandPaletteTrigger />
|
||||||
<QuickAdd />
|
<QuickAdd />
|
||||||
{enrichedHelpNode && (
|
{enrichedHelpNode && (
|
||||||
@ -88,7 +87,7 @@ export const SingleTopBar = memo(function SingleTopBar({
|
|||||||
<ToolbarButton className={styles.kioskToggle} onClick={onToggleKioskMode} narrow aria-label="Enable kiosk mode">
|
<ToolbarButton className={styles.kioskToggle} onClick={onToggleKioskMode} narrow aria-label="Enable kiosk mode">
|
||||||
<Icon name="angle-up" size="xl" />
|
<Icon name="angle-up" size="xl" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
</TopSearchBarSection>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -97,15 +96,15 @@ const getStyles = (theme: GrafanaTheme2, menuDockedAndOpen: boolean) => ({
|
|||||||
layout: css({
|
layout: css({
|
||||||
height: TOP_BAR_LEVEL_HEIGHT,
|
height: TOP_BAR_LEVEL_HEIGHT,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: theme.spacing(1),
|
gap: theme.spacing(2),
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
padding: theme.spacing(0, 1),
|
padding: theme.spacing(0, 1),
|
||||||
paddingLeft: menuDockedAndOpen ? theme.spacing(3.5) : theme.spacing(0.75),
|
paddingLeft: menuDockedAndOpen ? theme.spacing(3.5) : theme.spacing(0.75),
|
||||||
borderBottom: `1px solid ${theme.colors.border.weak}`,
|
borderBottom: `1px solid ${theme.colors.border.weak}`,
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
|
|
||||||
[theme.breakpoints.up('sm')]: {
|
[theme.breakpoints.up('lg')]: {
|
||||||
gridTemplateColumns: '2fr minmax(240px, 1fr)', // TODO probably change these values
|
gridTemplateColumns: '2fr minmax(440px, 1fr)',
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
|
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
@ -115,7 +114,7 @@ const getStyles = (theme: GrafanaTheme2, menuDockedAndOpen: boolean) => ({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
[theme.breakpoints.down('sm')]: {
|
[theme.breakpoints.down('sm')]: {
|
||||||
minWidth: '50%',
|
minWidth: '40%',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
img: css({
|
img: css({
|
||||||
|
@ -3,6 +3,7 @@ import { useKBar, VisualState } from 'kbar';
|
|||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
import { getInputStyles, Icon, Text, ToolbarButton, useStyles2, useTheme2 } from '@grafana/ui';
|
import { getInputStyles, Icon, Text, ToolbarButton, useStyles2, useTheme2 } from '@grafana/ui';
|
||||||
import { focusCss } from '@grafana/ui/src/themes/mixins';
|
import { focusCss } from '@grafana/ui/src/themes/mixins';
|
||||||
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
import { useMediaQueryChange } from 'app/core/hooks/useMediaQueryChange';
|
||||||
@ -11,12 +12,13 @@ import { getModKey } from 'app/core/utils/browser';
|
|||||||
|
|
||||||
export function TopSearchBarCommandPaletteTrigger() {
|
export function TopSearchBarCommandPaletteTrigger() {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
|
const isSingleTopNav = config.featureToggles.singleTopNav;
|
||||||
const { query: kbar } = useKBar((kbarState) => ({
|
const { query: kbar } = useKBar((kbarState) => ({
|
||||||
kbarSearchQuery: kbarState.searchQuery,
|
kbarSearchQuery: kbarState.searchQuery,
|
||||||
kbarIsOpen: kbarState.visualState === VisualState.showing,
|
kbarIsOpen: kbarState.visualState === VisualState.showing,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const breakpoint = theme.breakpoints.values.sm;
|
const breakpoint = isSingleTopNav ? theme.breakpoints.values.lg : theme.breakpoints.values.sm;
|
||||||
|
|
||||||
const [isSmallScreen, setIsSmallScreen] = useState(!window.matchMedia(`(min-width: ${breakpoint}px)`).matches);
|
const [isSmallScreen, setIsSmallScreen] = useState(!window.matchMedia(`(min-width: ${breakpoint}px)`).matches);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user