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

fix: notification style width #45681

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions components/notification/PurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as React from 'react';
import { ConfigContext } from '../config-provider';
import type { IconType } from './interface';
import useStyle from './style';
import PurePanelStyle from './style/pure-panel';

export const TypeIcon = {
info: <InfoCircleFilled />,
Expand Down Expand Up @@ -99,6 +100,7 @@ const PurePanel: React.FC<PurePanelProps> = (props) => {

return (
<div className={classNames(`${noticePrefixCls}-pure-panel`, hashId, className)}>
<PurePanelStyle prefixCls={prefixCls} />
<Notice
{...restProps}
prefixCls={prefixCls}
Expand Down
19 changes: 19 additions & 0 deletions components/notification/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ describe('notification', () => {

expect(document.querySelectorAll('[role="status"]').length).toBe(1);
});

it('should hide close btn when closeIcon setting to null or false', async () => {
notification.config({
closeIcon: undefined,
Expand Down Expand Up @@ -348,4 +349,22 @@ describe('notification', () => {
expect(document.querySelectorAll('.with-null .ant-notification-notice-close').length).toBe(0);
expect(document.querySelectorAll('.with-false .ant-notification-notice-close').length).toBe(0);
});

it('style.width could be overrided', async () => {
act(() => {
notification.open({
message: 'Notification Title',
duration: 0,
style: {
width: 600,
},
className: 'with-style',
});
});
await awaitPromise();
expect(document.querySelector('.with-style')).toHaveStyle({ width: '600px' });
expect(
document.querySelector('.ant-notification-notice-wrapper:has(.width-style)'),
).toHaveStyle({ width: '' });
});
});
108 changes: 59 additions & 49 deletions components/notification/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CSSObject } from '@ant-design/cssinjs';
import { Keyframes } from '@ant-design/cssinjs';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import type { FullToken, GenerateStyle, AliasToken } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import genNotificationPlacementStyle from './placement';
import genStackStyle from './stack';
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface NotificationToken extends FullToken<'Notification'> {
notificationStackLayer: number;
}

const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
export const genNoticeStyle = (token: NotificationToken): CSSObject => {
const {
iconCls,
componentCls, // .ant-notification
Expand All @@ -49,8 +49,6 @@ const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
notificationBg,
notificationPadding,
notificationMarginEdge,
motionDurationMid,
motionEaseInOut,
fontSize,
lineHeight,
width,
Expand All @@ -60,25 +58,8 @@ const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {

const noticeCls = `${componentCls}-notice`;

const fadeOut = new Keyframes('antNotificationFadeOut', {
'0%': {
maxHeight: token.animationMaxHeight,
marginBottom: notificationMarginBottom,
},

'100%': {
maxHeight: 0,
marginBottom: 0,
paddingTop: 0,
paddingBottom: 0,
opacity: 0,
},
});

const noticeStyle: CSSObject = {
return {
position: 'relative',
width,
maxWidth: `calc(100vw - ${notificationMarginEdge * 2}px)`,
marginBottom: notificationMarginBottom,
marginInlineStart: 'auto',
background: notificationBg,
Expand All @@ -87,6 +68,8 @@ const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {

[noticeCls]: {
padding: notificationPadding,
width,
maxWidth: `calc(100vw - ${notificationMarginEdge * 2}px)`,
overflow: 'hidden',
lineHeight,
wordWrap: 'break-word',
Expand Down Expand Up @@ -172,6 +155,33 @@ const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
marginTop: token.marginSM,
},
};
};

const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
const {
componentCls, // .ant-notification
notificationMarginBottom,
notificationMarginEdge,
motionDurationMid,
motionEaseInOut,
} = token;

const noticeCls = `${componentCls}-notice`;

const fadeOut = new Keyframes('antNotificationFadeOut', {
'0%': {
maxHeight: token.animationMaxHeight,
marginBottom: notificationMarginBottom,
},

'100%': {
maxHeight: 0,
marginBottom: 0,
paddingTop: 0,
paddingBottom: 0,
opacity: 0,
},
});

return [
// ============================ Holder ============================
Expand Down Expand Up @@ -236,48 +246,48 @@ const genNotificationStyle: GenerateStyle<NotificationToken> = (token) => {
{
[componentCls]: {
[`${noticeCls}-wrapper`]: {
...noticeStyle,
...genNoticeStyle(token),
},
},
},

// ============================= Pure =============================
{
[`${noticeCls}-pure-panel`]: {
...noticeStyle,
margin: 0,
},
},
];
};

// ============================== Export ==============================
export const prepareComponentToken = (token: AliasToken) => ({
zIndexPopup: token.zIndexPopupBase + 50,
width: 384,
});

export const prepareNotificationToken = (token: AliasToken) => {
const notificationPaddingVertical = token.paddingMD;
const notificationPaddingHorizontal = token.paddingLG;
const notificationToken = mergeToken<NotificationToken>(token, {
notificationBg: token.colorBgElevated,
notificationPaddingVertical,
notificationPaddingHorizontal,
notificationIconSize: token.fontSizeLG * token.lineHeightLG,
notificationCloseButtonSize: token.controlHeightLG * 0.55,
notificationMarginBottom: token.margin,
notificationPadding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`,
notificationMarginEdge: token.marginLG,
animationMaxHeight: 150,
notificationStackLayer: 3,
});

return notificationToken;
};

export default genComponentStyleHook(
'Notification',
(token) => {
const notificationPaddingVertical = token.paddingMD;
const notificationPaddingHorizontal = token.paddingLG;
const notificationToken = mergeToken<NotificationToken>(token, {
notificationBg: token.colorBgElevated,
notificationPaddingVertical,
notificationPaddingHorizontal,
notificationIconSize: token.fontSizeLG * token.lineHeightLG,
notificationCloseButtonSize: token.controlHeightLG * 0.55,
notificationMarginBottom: token.margin,
notificationPadding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`,
notificationMarginEdge: token.marginLG,
animationMaxHeight: 150,
notificationStackLayer: 3,
});
const notificationToken = prepareNotificationToken(token);

return [
genNotificationStyle(notificationToken),
genNotificationPlacementStyle(notificationToken),
genStackStyle(notificationToken),
];
},
(token) => ({
zIndexPopup: token.zIndexPopupBase + 50,
width: 384,
}),
prepareComponentToken,
);
20 changes: 20 additions & 0 deletions components/notification/style/pure-panel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { genSubStyleComponent } from '../../theme/internal';
import { prepareComponentToken, genNoticeStyle, prepareNotificationToken } from '.';

export default genSubStyleComponent(
['Notification', 'PurePanel'],
(token) => {
const noticeCls = `${token.componentCls}-notice`;
const notificationToken = prepareNotificationToken(token);

return {
[`${noticeCls}-pure-panel`]: {
...genNoticeStyle(notificationToken),
width: notificationToken.width,
maxWidth: `calc(100vw - ${notificationToken.notificationMarginEdge * 2}px)`,
margin: 0,
},
};
},
prepareComponentToken,
);
1 change: 0 additions & 1 deletion components/notification/style/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const genStackStyle: GenerateStyle<NotificationToken> = (token) => {
[`& > ${componentCls}-notice-wrapper`]: {
'&:not(:nth-last-child(-n + 1))': {
opacity: 1,
width: token.width,
overflow: 'unset',
color: 'inherit',
pointerEvents: 'auto',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@
"size-limit": [
{
"path": "./dist/antd.min.js",
"limit": "401 KiB"
"limit": "402 KiB"
},
{
"path": "./dist/antd-with-locales.min.js",
"limit": "460 KiB"
"limit": "461 KiB"
}
],
"title": "Ant Design",
Expand Down