Skip to content

Commit

Permalink
Merge pull request #48735 from ant-design/feature
Browse files Browse the repository at this point in the history
chore: merge feature to master
  • Loading branch information
li-jia-nan committed May 2, 2024
2 parents 15c7e68 + 7b30c80 commit 2f304d1
Show file tree
Hide file tree
Showing 156 changed files with 4,525 additions and 1,063 deletions.
2 changes: 1 addition & 1 deletion .dumi/pages/index/components/Theme/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const ThemeColorPicker: React.FC<ColorPickerProps> = ({ value, onChange, id }) =
}, [value]);

return (
<Flex gap="large" align="center" wrap="wrap">
<Flex gap="large" align="center" wrap>
<Input
value={typeof value === 'string' ? value : value?.toHexString()}
onChange={(event) => onChange?.(event.target.value)}
Expand Down
2 changes: 1 addition & 1 deletion .dumi/pages/index/components/Theme/ThemePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ThemePicker: React.FC<ThemePickerProps> = (props) => {
const { styles } = useStyle();
const [locale] = useLocale(locales);
return (
<Flex gap="large" wrap="wrap">
<Flex gap="large" wrap>
{(Object.keys(THEMES) as (keyof typeof THEMES)[]).map<React.ReactNode>((theme, index) => (
<Flex vertical gap="small" justify="center" align="center" key={theme}>
<label
Expand Down
3 changes: 1 addition & 2 deletions .dumi/theme/builtins/Previewer/CodePreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ createRoot(document.getElementById('container')).render(<Demo />);
dangerouslySetInnerHTML={{ __html: description }}
/>
)}

<Flex wrap="wrap" gap="middle" className="code-box-actions">
<Flex wrap gap="middle" className="code-box-actions">
{showOnlineUrl && (
<Tooltip title={<FormattedMessage id="app.demo.online" />}>
<a
Expand Down
129 changes: 69 additions & 60 deletions .dumi/theme/common/styles/Common.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,86 @@
import { css, Global } from '@emotion/react';
import React from 'react';
import { css, Global } from '@emotion/react';
import { useTheme } from 'antd-style';
import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS';

export default () => {
const { anchorTop } = useTheme();

React.useInsertionEffect(() => {
updateCSS(`@layer global, antd;`, 'site-global', {
prepend: true,
});
}, []);

return (
<Global
styles={css`
body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
code,
form,
fieldset,
legend,
input,
textarea,
p,
blockquote,
th,
td,
hr,
button,
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
margin: 0;
padding: 0;
}
@layer global {
body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
code,
form,
fieldset,
legend,
input,
textarea,
p,
blockquote,
th,
td,
hr,
button,
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
margin: 0;
padding: 0;
}
ul,
ol {
list-style: none;
}
ul,
ol {
list-style: none;
}
img {
vertical-align: middle;
border-style: none;
}
img {
vertical-align: middle;
border-style: none;
}
[id] {
scroll-margin-top: ${anchorTop}px;
}
[id] {
scroll-margin-top: ${anchorTop}px;
}
[data-prefers-color='dark'] {
color-scheme: dark;
}
[data-prefers-color='dark'] {
color-scheme: dark;
}
[data-prefers-color='light'] {
color-scheme: light;
}
`}
[data-prefers-color='light'] {
color-scheme: light;
}
}
`}
/>
);
};
1 change: 1 addition & 0 deletions .dumi/theme/layouts/GlobalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const GlobalLayout: React.FC = () => {
<StyleProvider
cache={styleCache}
linters={[legacyNotSelectorLinter, parentSelectorLinter, NaNLinter]}
layer
>
<SiteContext.Provider value={siteContextValue}>
<SiteThemeProvider theme={themeConfig}>
Expand Down
3 changes: 2 additions & 1 deletion .dumi/theme/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ const RoutesPlugin = (api: IApi) => {
const matchRegex = /<style data-type="antd-cssinjs">([\S\s]+?)<\/style>/;
const matchList = file.content.match(matchRegex) || [];

let antdStyle = '';
// Init to order the `@layer`
let antdStyle = '@layer global, antd;';

matchList.forEach((text) => {
file.content = file.content.replace(text, '');
Expand Down
7 changes: 4 additions & 3 deletions components/_util/transButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import * as React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';

interface TransButtonProps extends React.HTMLAttributes<HTMLDivElement> {
onClick?: (e?: React.MouseEvent<HTMLDivElement>) => void;
onClick?: (e?: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
noStyle?: boolean;
autoFocus?: boolean;
disabled?: boolean;
tabIndex?: number;
}

const inlineStyle: React.CSSProperties = {
Expand All @@ -37,7 +38,7 @@ const TransButton = React.forwardRef<HTMLDivElement, TransButtonProps>((props, r
}
};

const { style, noStyle, disabled, ...restProps } = props;
const { style, noStyle, disabled, tabIndex = 0, ...restProps } = props;

let mergedStyle: React.CSSProperties = {};

Expand All @@ -59,7 +60,7 @@ const TransButton = React.forwardRef<HTMLDivElement, TransButtonProps>((props, r
return (
<div
role="button"
tabIndex={0}
tabIndex={tabIndex}
ref={ref}
{...restProps}
onKeyDown={onKeyDown}
Expand Down
21 changes: 17 additions & 4 deletions components/alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { devUseWarning } from '../_util/warning';
import { ConfigContext } from '../config-provider';
import useStyle from './style';

export interface AlertRef {
nativeElement: HTMLDivElement;
}

export interface AlertProps {
/** Type of Alert styles, options:`success`, `info`, `warning`, `error` */
type?: 'success' | 'info' | 'warning' | 'error';
Expand Down Expand Up @@ -48,6 +52,8 @@ export interface AlertProps {
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onClick?: React.MouseEventHandler<HTMLDivElement>;

id?: string;
}

const iconMapFilled = {
Expand Down Expand Up @@ -102,7 +108,7 @@ const CloseIconNode: React.FC<CloseIconProps> = (props) => {
) : null;
};

const Alert: React.FC<AlertProps> = (props) => {
const Alert = React.forwardRef<AlertRef, AlertProps>((props, ref) => {
const {
description,
prefixCls: customizePrefixCls,
Expand All @@ -120,6 +126,7 @@ const Alert: React.FC<AlertProps> = (props) => {
closeText,
closeIcon,
action,
id,
...otherProps
} = props;

Expand All @@ -130,7 +137,12 @@ const Alert: React.FC<AlertProps> = (props) => {
warning.deprecated(!closeText, 'closeText', 'closable.closeIcon');
}

const ref = React.useRef<HTMLDivElement>(null);
const internalRef = React.useRef<HTMLDivElement>(null);

React.useImperativeHandle(ref, () => ({
nativeElement: internalRef.current!,
}));

const { getPrefixCls, direction, alert } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('alert', customizePrefixCls);

Expand Down Expand Up @@ -224,7 +236,8 @@ const Alert: React.FC<AlertProps> = (props) => {
>
{({ className: motionClassName, style: motionStyle }) => (
<div
ref={ref}
id={id}
ref={internalRef}
data-show={!closed}
className={classNames(alertCls, motionClassName)}
style={{ ...alert?.style, ...style, ...motionStyle }}
Expand Down Expand Up @@ -258,7 +271,7 @@ const Alert: React.FC<AlertProps> = (props) => {
)}
</CSSMotion>,
);
};
});

if (process.env.NODE_ENV !== 'production') {
Alert.displayName = 'Alert';
Expand Down
4 changes: 3 additions & 1 deletion components/alert/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface ErrorBoundaryProps {
message?: React.ReactNode;
description?: React.ReactNode;
children?: React.ReactNode;
id?: string;
}

interface ErrorBoundaryStates {
Expand All @@ -28,14 +29,15 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
}

render() {
const { message, description, children } = this.props;
const { message, description, id, children } = this.props;
const { error, info } = this.state;
const componentStack = info && info.componentStack ? info.componentStack : null;
const errorMessage = typeof message === 'undefined' ? (error || '').toString() : message;
const errorDescription = typeof description === 'undefined' ? componentStack : description;
if (error) {
return (
<Alert
id={id}
type="error"
message={errorMessage}
description={
Expand Down
10 changes: 10 additions & 0 deletions components/alert/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { act, render, screen, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
import Popconfirm from '../../popconfirm';
import Tooltip from '../../tooltip';
import type { AlertRef } from '../Alert';

const { ErrorBoundary } = Alert;

Expand Down Expand Up @@ -192,4 +193,13 @@ describe('Alert', () => {

warnSpy.mockRestore();
});

it('should support id and ref', () => {
const alertRef = React.createRef<AlertRef>();
const { container } = render(<Alert id="test-id" ref={alertRef} />);
const element = container.querySelector<HTMLDivElement>('#test-id');
expect(element).toBeTruthy();
expect(alertRef.current?.nativeElement).toBeTruthy();
expect(alertRef.current?.nativeElement).toBe(element);
});
});
5 changes: 1 addition & 4 deletions components/alert/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type React from 'react';

import type { AlertProps } from './Alert';
import InternalAlert from './Alert';
import ErrorBoundary from './ErrorBoundary';

export type { AlertProps } from './Alert';

type CompoundedComponent = React.FC<AlertProps> & {
type CompoundedComponent = typeof InternalAlert & {
ErrorBoundary: typeof ErrorBoundary;
};

Expand Down

0 comments on commit 2f304d1

Please sign in to comment.