This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
import type { ReactNode } from 'react';
import React from 'react';
import type { AnyObject, CustomComponent } from '../_util/type';
import type { AppConfig } from './context';
export interface AppProps<P = AnyObject> extends AppConfig {
style?: React.CSSProperties;
className?: string;
rootClassName?: string;
prefixCls?: string;
children?: ReactNode;
component?: CustomComponent<P> | false;
}
declare const App: React.FC<AppProps>;
export default App;
+75
View File
@@ -0,0 +1,75 @@
"use client";
import React, { useContext } from 'react';
import { clsx } from 'clsx';
import { devUseWarning } from '../_util/warning';
import { useComponentConfig } from '../config-provider/context';
import useMessage from '../message/useMessage';
import useModal from '../modal/useModal';
import useNotification from '../notification/useNotification';
import AppContext, { AppConfigContext } from './context';
import useStyle from './style';
const App = props => {
const {
prefixCls: customizePrefixCls,
children,
className,
rootClassName,
message,
notification,
style,
component = 'div'
} = props;
const {
direction,
getPrefixCls,
className: contextClassName,
style: contextStyle
} = useComponentConfig('app');
const prefixCls = getPrefixCls('app', customizePrefixCls);
const [hashId, cssVarCls] = useStyle(prefixCls);
const customClassName = clsx(hashId, prefixCls, className, rootClassName, cssVarCls, {
[`${prefixCls}-rtl`]: direction === 'rtl'
});
const appConfig = useContext(AppConfigContext);
const mergedAppConfig = React.useMemo(() => ({
message: {
...appConfig.message,
...message
},
notification: {
...appConfig.notification,
...notification
}
}), [message, notification, appConfig.message, appConfig.notification]);
const [messageApi, messageContextHolder] = useMessage(mergedAppConfig.message);
const [notificationApi, notificationContextHolder] = useNotification(mergedAppConfig.notification);
const [ModalApi, ModalContextHolder] = useModal();
const memoizedContextValue = React.useMemo(() => ({
message: messageApi,
notification: notificationApi,
modal: ModalApi
}), [messageApi, notificationApi, ModalApi]);
// https://github.com/ant-design/ant-design/issues/48802#issuecomment-2097813526
devUseWarning('App')(!(cssVarCls && component === false), 'usage', 'When using cssVar, ensure `component` is assigned a valid React component string.');
// ============================ Render ============================
const Component = component === false ? React.Fragment : component;
const rootProps = {
className: clsx(contextClassName, customClassName),
style: {
...contextStyle,
...style
}
};
return /*#__PURE__*/React.createElement(AppContext.Provider, {
value: memoizedContextValue
}, /*#__PURE__*/React.createElement(AppConfigContext.Provider, {
value: mergedAppConfig
}, /*#__PURE__*/React.createElement(Component, {
...(component === false ? undefined : rootProps)
}, ModalContextHolder, messageContextHolder, notificationContextHolder, children)));
};
if (process.env.NODE_ENV !== 'production') {
App.displayName = 'App';
}
export default App;
+16
View File
@@ -0,0 +1,16 @@
import React from 'react';
import type { ConfigOptions as MessageConfig, MessageInstance } from '../message/interface';
import type { HookAPI as ModalHookAPI } from '../modal/useModal';
import type { NotificationConfig, NotificationInstance } from '../notification/interface';
export interface AppConfig {
message?: MessageConfig;
notification?: NotificationConfig;
}
export declare const AppConfigContext: React.Context<AppConfig>;
export interface useAppProps {
message: MessageInstance;
notification: NotificationInstance;
modal: ModalHookAPI;
}
declare const AppContext: React.Context<useAppProps>;
export default AppContext;
+8
View File
@@ -0,0 +1,8 @@
import React from 'react';
export const AppConfigContext = /*#__PURE__*/React.createContext({});
const AppContext = /*#__PURE__*/React.createContext({
message: {},
notification: {},
modal: {}
});
export default AppContext;
+9
View File
@@ -0,0 +1,9 @@
import type { AppProps } from './App';
import App_ from './App';
import useApp from './useApp';
export type { AppProps };
type CompoundedComponent = typeof App_ & {
useApp: typeof useApp;
};
declare const App: CompoundedComponent;
export default App;
+7
View File
@@ -0,0 +1,7 @@
"use client";
import App_ from './App';
import useApp from './useApp';
const App = App_;
App.useApp = useApp;
export default App;
+6
View File
@@ -0,0 +1,6 @@
import type { GetDefaultToken } from '../../theme/internal';
export interface ComponentToken {
}
export declare const prepareComponentToken: GetDefaultToken<'App'>;
declare const _default: (prefixCls: string, rootCls?: string) => readonly [string, string];
export default _default;
+25
View File
@@ -0,0 +1,25 @@
import { genStyleHooks } from '../../theme/internal';
// =============================== Base ===============================
const genBaseStyle = token => {
const {
componentCls,
colorText,
fontSize,
lineHeight,
fontFamily
} = token;
return {
[componentCls]: {
color: colorText,
fontSize,
lineHeight,
fontFamily,
[`&${componentCls}-rtl`]: {
direction: 'rtl'
}
}
};
};
export const prepareComponentToken = () => ({});
// ============================== Export ==============================
export default genStyleHooks('App', genBaseStyle, prepareComponentToken);
+3
View File
@@ -0,0 +1,3 @@
import type { useAppProps } from './context';
declare const useApp: () => useAppProps;
export default useApp;
+4
View File
@@ -0,0 +1,4 @@
import React from 'react';
import AppContext from './context';
const useApp = () => React.useContext(AppContext);
export default useApp;