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