Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: menu support css variable theme #45750

Merged
merged 16 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/menu/SubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useZIndex } from '../_util/hooks/useZIndex';
import { cloneElement, isValidElement } from '../_util/reactNode';
import type { MenuContextProps, MenuTheme } from './MenuContext';
import MenuContext from './MenuContext';
import useCSSVar from './style/cssVar';

interface TitleEventEntity {
key: string;
Expand Down Expand Up @@ -34,6 +35,7 @@ const SubMenu: React.FC<SubMenuProps> = (props) => {
const context = React.useContext(MenuContext);
const { prefixCls, inlineCollapsed, theme: contextTheme } = context;

const wrapCSSVar = useCSSVar(prefixCls);
const parentPath = useFullPath();

let titleNode: React.ReactNode;
Expand Down Expand Up @@ -70,7 +72,7 @@ const SubMenu: React.FC<SubMenuProps> = (props) => {
// ============================ zIndex ============================
const [zIndex] = useZIndex('Menu');

return (
return wrapCSSVar(
kiner-tang marked this conversation as resolved.
Show resolved Hide resolved
<MenuContext.Provider value={contextValue}>
<RcSubMenu
{...omit(props, ['icon'])}
Expand All @@ -84,7 +86,7 @@ const SubMenu: React.FC<SubMenuProps> = (props) => {
zIndex,
}}
/>
</MenuContext.Provider>
</MenuContext.Provider>,
);
};

Expand Down
10 changes: 7 additions & 3 deletions components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type { MenuContextProps, MenuTheme } from './MenuContext';
import MenuContext from './MenuContext';
import OverrideContext from './OverrideContext';
import useStyle from './style';
import useCSSVar from './style/cssVar';
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';

export interface MenuProps extends Omit<RcMenuProps, 'items'> {
theme?: MenuTheme;
Expand Down Expand Up @@ -120,7 +122,9 @@ const InternalMenu = forwardRef<RcMenuRef, InternalMenuProps>((props, ref) => {
};

const prefixCls = getPrefixCls('menu', customizePrefixCls || overrideObj.prefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls, !override);
const [, hashId] = useStyle(prefixCls, !override);
const rootCls = useCSSVarCls(prefixCls);
const wrapCSSVar = useCSSVar(rootCls);
const menuClassName = classNames(`${prefixCls}-${theme}`, menu?.className, className);

// ====================== Expand Icon ========================
Expand Down Expand Up @@ -156,7 +160,7 @@ const InternalMenu = forwardRef<RcMenuRef, InternalMenuProps>((props, ref) => {
);

// ========================= Render ==========================
return wrapSSR(
return wrapCSSVar(
<OverrideContext.Provider value={null}>
<MenuContext.Provider value={contextValue}>
<RcMenu
Expand All @@ -179,7 +183,7 @@ const InternalMenu = forwardRef<RcMenuRef, InternalMenuProps>((props, ref) => {
defaultMotions={defaultMotions}
expandIcon={mergedExpandIcon}
ref={ref}
rootClassName={classNames(rootClassName, hashId, overrideObj.rootClassName)}
rootClassName={classNames(rootClassName, hashId, overrideObj.rootClassName, rootCls)}
>
{mergedChildren}
</RcMenu>
Expand Down
8 changes: 8 additions & 0 deletions components/menu/style/cssVar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { genCSSVarRegister } from '../../theme/internal';
import { prepareComponentToken } from '.';

export default genCSSVarRegister('Menu', prepareComponentToken, {
unitless: {
groupTitleLineHeight: true,
},
});
3 changes: 2 additions & 1 deletion components/menu/style/horizontal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { unit } from '@ant-design/cssinjs';
import type { MenuToken } from '.';
import type { GenerateStyle } from '../../theme/internal';

Expand All @@ -16,7 +17,7 @@ const getHorizontalStyle: GenerateStyle<MenuToken> = (token) => {
[`${componentCls}-horizontal`]: {
lineHeight: horizontalLineHeight,
border: 0,
borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`,
borderBottom: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
boxShadow: 'none',

'&::after': {
Expand Down