mirror of https://github.com/grafana/grafana.git
Themes: Fix internal border radius of MenuItem to match new outer border radius (#112053)
* Fix internal border radius of MenuItem to match new outer border radius * Add design tokens for Menu border radius and padding to createComponents
This commit is contained in:
parent
9502e23423
commit
8f54a15d8b
|
|
@ -1,5 +1,12 @@
|
||||||
import { ThemeColors } from './createColors';
|
import { ThemeColors } from './createColors';
|
||||||
import { ThemeShadows } from './createShadows';
|
import { ThemeShadows } from './createShadows';
|
||||||
|
import type { Radii } from './createShape';
|
||||||
|
import type { ThemeSpacingTokens } from './createSpacing';
|
||||||
|
|
||||||
|
interface MenuComponentTokens {
|
||||||
|
borderRadius: keyof Radii;
|
||||||
|
padding: ThemeSpacingTokens;
|
||||||
|
}
|
||||||
|
|
||||||
/** @beta */
|
/** @beta */
|
||||||
export interface ThemeComponents {
|
export interface ThemeComponents {
|
||||||
|
|
@ -53,6 +60,7 @@ export interface ThemeComponents {
|
||||||
rowHoverBackground: string;
|
rowHoverBackground: string;
|
||||||
rowSelected: string;
|
rowSelected: string;
|
||||||
};
|
};
|
||||||
|
menu: MenuComponentTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createComponents(colors: ThemeColors, shadows: ThemeShadows): ThemeComponents {
|
export function createComponents(colors: ThemeColors, shadows: ThemeShadows): ThemeComponents {
|
||||||
|
|
@ -71,6 +79,11 @@ export function createComponents(colors: ThemeColors, shadows: ThemeShadows): Th
|
||||||
background: colors.mode === 'dark' ? colors.background.canvas : colors.background.primary,
|
background: colors.mode === 'dark' ? colors.background.canvas : colors.background.primary,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const menu: MenuComponentTokens = {
|
||||||
|
borderRadius: 'default',
|
||||||
|
padding: 0.5,
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
height: {
|
height: {
|
||||||
sm: 3,
|
sm: 3,
|
||||||
|
|
@ -114,5 +127,6 @@ export function createComponents(colors: ThemeColors, shadows: ThemeShadows): Th
|
||||||
rowHoverBackground: colors.action.hover,
|
rowHoverBackground: colors.action.hover,
|
||||||
rowSelected: colors.action.selected,
|
rowSelected: colors.action.selected,
|
||||||
},
|
},
|
||||||
|
menu,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ export interface MenuProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
const MenuComp = React.forwardRef<HTMLDivElement, MenuProps>(
|
const MenuComp = React.forwardRef<HTMLDivElement, MenuProps>(
|
||||||
({ header, children, ariaLabel, onOpen, onClose, onKeyDown, ...otherProps }, forwardedRef) => {
|
({ header, children, ariaLabel, onOpen, onClose, onKeyDown, ...otherProps }, forwardedRef) => {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
|
const componentTokens = useComponentTokens();
|
||||||
|
|
||||||
const localRef = useRef<HTMLDivElement>(null);
|
const localRef = useRef<HTMLDivElement>(null);
|
||||||
useImperativeHandle(forwardedRef, () => localRef.current!);
|
useImperativeHandle(forwardedRef, () => localRef.current!);
|
||||||
|
|
@ -36,12 +37,11 @@ const MenuComp = React.forwardRef<HTMLDivElement, MenuProps>(
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
backgroundColor="elevated"
|
backgroundColor="elevated"
|
||||||
borderRadius="default"
|
borderRadius={componentTokens.borderRadius}
|
||||||
boxShadow="z3"
|
boxShadow="z3"
|
||||||
display="inline-block"
|
display="inline-block"
|
||||||
onKeyDown={handleKeys}
|
onKeyDown={handleKeys}
|
||||||
paddingX={0.5}
|
padding={componentTokens.padding}
|
||||||
paddingY={0.5}
|
|
||||||
ref={localRef}
|
ref={localRef}
|
||||||
role="menu"
|
role="menu"
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
|
|
@ -70,6 +70,18 @@ export const Menu = Object.assign(MenuComp, {
|
||||||
Group: MenuGroup,
|
Group: MenuGroup,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const useComponentTokens = () =>
|
||||||
|
useStyles2((theme: GrafanaTheme2) => {
|
||||||
|
const {
|
||||||
|
components: { menu },
|
||||||
|
} = theme;
|
||||||
|
|
||||||
|
return {
|
||||||
|
padding: menu.padding,
|
||||||
|
borderRadius: menu.borderRadius,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => {
|
const getStyles = (theme: GrafanaTheme2) => {
|
||||||
return {
|
return {
|
||||||
header: css({
|
header: css({
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { GrafanaTheme2, LinkTarget } from '@grafana/data';
|
||||||
import { t } from '@grafana/i18n';
|
import { t } from '@grafana/i18n';
|
||||||
|
|
||||||
import { useStyles2 } from '../../themes/ThemeContext';
|
import { useStyles2 } from '../../themes/ThemeContext';
|
||||||
import { getFocusStyles } from '../../themes/mixins';
|
import { getFocusStyles, getInternalRadius } from '../../themes/mixins';
|
||||||
import { IconName } from '../../types/icon';
|
import { IconName } from '../../types/icon';
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon } from '../Icon/Icon';
|
||||||
import { Stack } from '../Layout/Stack/Stack';
|
import { Stack } from '../Layout/Stack/Stack';
|
||||||
|
|
@ -213,6 +213,8 @@ export const MenuItem = React.memo(
|
||||||
MenuItem.displayName = 'MenuItem';
|
MenuItem.displayName = 'MenuItem';
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => {
|
const getStyles = (theme: GrafanaTheme2) => {
|
||||||
|
const menuPadding = theme.components.menu.padding * theme.spacing.gridSize;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: css({
|
item: css({
|
||||||
background: 'none',
|
background: 'none',
|
||||||
|
|
@ -225,7 +227,7 @@ const getStyles = (theme: GrafanaTheme2) => {
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
padding: theme.spacing(0.5, 1.5),
|
padding: theme.spacing(0.5, 1.5),
|
||||||
minHeight: theme.spacing(4),
|
minHeight: theme.spacing(4),
|
||||||
borderRadius: theme.shape.radius.default,
|
borderRadius: getInternalRadius(theme, menuPadding, { parentBorderWidth: 0 }),
|
||||||
margin: 0,
|
margin: 0,
|
||||||
border: 'none',
|
border: 'none',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue