Skip to content

Commit

Permalink
Merge branch 'master' into wuxh/site
Browse files Browse the repository at this point in the history
* master:
  fix: Table should not warn DefaultProps (ant-design#39571)
  type: Button type optimization (ant-design#39533)
  docs: Add Form prefix demo (ant-design#39580)
  site: icon update (ant-design#39534)
  demo: update demo (ant-design#39576)
  fix: segmented icon margin (ant-design#39575)
  type: add FloatButtonGroupProps (ant-design#39553)
  fix: add img cdn link for site (ant-design#39554)
  docs: Tree conduction (ant-design#39566)
  • Loading branch information
Wxh16144 committed Dec 15, 2022
2 parents fa8e30b + 359eaa6 commit e8a832c
Show file tree
Hide file tree
Showing 52 changed files with 1,570 additions and 261 deletions.
7 changes: 5 additions & 2 deletions .dumi/pages/index/components/Banner.tsx
Expand Up @@ -7,7 +7,6 @@ import SiteContext from '../../../theme/slots/SiteContext';
import useSiteToken from '../../../hooks/useSiteToken';
import { GroupMask } from './Group';
import * as utils from '../../../theme/utils';
import topicImage from './images/topic.png';

const locales = {
cn: {
Expand Down Expand Up @@ -69,7 +68,11 @@ export default function Banner({ children }: BannerProps) {
<>
{/* Banner Placeholder Motion */}
{isMobile ? (
<img src={topicImage} alt="" style={{ width: '100%' }} />
<img
src="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*JmlaR5oQn3MAAAAAAAAAAAAADrJ8AQ/original"
style={{ width: '100%' }}
alt=""
/>
) : (
<div
style={{
Expand Down
Binary file removed .dumi/pages/index/components/images/topic.png
Binary file not shown.
75 changes: 46 additions & 29 deletions .dumi/theme/common/ThemeSwitch/index.tsx
@@ -1,7 +1,10 @@
import React from 'react';
import { FloatButton } from 'antd';
import { FormattedMessage } from 'dumi';
import { FormattedMessage, Link, useLocation } from 'dumi';
import { DarkTheme, CompactTheme } from 'antd-token-previewer/es/icons';
import { BgColorsOutlined } from '@ant-design/icons';
import useSiteToken from '../../../hooks/useSiteToken';
import { getLocalizedPathname, isZhCN } from '../../utils';
import ThemeIcon from './ThemeIcon';

export type ThemeName = 'light' | 'dark' | 'compact';
Expand All @@ -11,33 +14,47 @@ export type ThemeSwitchProps = {
onChange: (value: ThemeName[]) => void;
};

const ThemeSwitch: React.FC<ThemeSwitchProps> = ({ value = ['light'], onChange }) => (
<FloatButton.Group trigger="click" icon={<ThemeIcon />}>
<FloatButton
icon={<DarkTheme />}
type={value.includes('dark') ? 'primary' : 'default'}
onClick={() => {
if (value.includes('dark')) {
onChange(value.filter((theme) => theme !== 'dark'));
} else {
onChange([...value, 'dark']);
}
}}
tooltip={<FormattedMessage id="app.theme.switch.dark" />}
/>
<FloatButton
icon={<CompactTheme />}
type={value.includes('compact') ? 'primary' : 'default'}
onClick={() => {
if (value.includes('compact')) {
onChange(value.filter((theme) => theme !== 'compact'));
} else {
onChange([...value, 'compact']);
}
}}
tooltip={<FormattedMessage id="app.theme.switch.compact" />}
/>
</FloatButton.Group>
);
const ThemeSwitch: React.FC<ThemeSwitchProps> = (props: ThemeSwitchProps) => {
const { value = ['light'], onChange } = props;
const { token } = useSiteToken();
const { pathname, search } = useLocation();
return (
<FloatButton.Group trigger="click" icon={<ThemeIcon />}>
<Link
to={getLocalizedPathname('/theme-editor', isZhCN(pathname), search)}
style={{ display: 'block', marginBottom: token.margin }}
>
<FloatButton
icon={<BgColorsOutlined />}
tooltip={<FormattedMessage id="app.footer.theme" />}
/>
</Link>
<FloatButton
icon={<DarkTheme />}
type={value.includes('dark') ? 'primary' : 'default'}
onClick={() => {
if (value.includes('dark')) {
onChange(value.filter((theme) => theme !== 'dark'));
} else {
onChange([...value, 'dark']);
}
}}
tooltip={<FormattedMessage id="app.theme.switch.dark" />}
/>
<FloatButton
icon={<CompactTheme />}
type={value.includes('compact') ? 'primary' : 'default'}
onClick={() => {
if (value.includes('compact')) {
onChange(value.filter((theme) => theme !== 'compact'));
} else {
onChange([...value, 'compact']);
}
}}
tooltip={<FormattedMessage id="app.theme.switch.compact" />}
/>
</FloatButton.Group>
);
};

export default ThemeSwitch;
2 changes: 1 addition & 1 deletion .dumi/theme/utils.tsx
Expand Up @@ -129,7 +129,7 @@ export function getLocalizedPathname(
},
) {
const pathname = path.startsWith('/') ? path : `/${path}`;
let fullPath;
let fullPath: string;
if (!zhCN) {
// to enUS
fullPath = /\/?index-cn/.test(pathname) ? '/' : pathname.replace('-cn', '');
Expand Down
4 changes: 2 additions & 2 deletions components/_util/ActionButton.tsx
Expand Up @@ -65,7 +65,7 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
);
};

const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {
const onClick = (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => {
const { actionFn } = props;
if (clickedRef.current) {
return;
Expand All @@ -75,7 +75,7 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
onInternalClose();
return;
}
let returnValueOfOnOk;
let returnValueOfOnOk: PromiseLike<any>;
if (props.emitEvent) {
returnValueOfOnOk = actionFn(e);
if (props.quitOnNullishReturnValue && !isThenable(returnValueOfOnOk)) {
Expand Down
16 changes: 11 additions & 5 deletions components/button/button.tsx
Expand Up @@ -119,13 +119,13 @@ export interface BaseButtonProps {
export type AnchorButtonProps = {
href: string;
target?: string;
onClick?: React.MouseEventHandler<HTMLElement>;
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
} & BaseButtonProps &
Omit<React.AnchorHTMLAttributes<any>, 'type' | 'onClick'>;

export type NativeButtonProps = {
htmlType?: ButtonHTMLType;
onClick?: React.MouseEventHandler<HTMLElement>;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
} & BaseButtonProps &
Omit<React.ButtonHTMLAttributes<any>, 'type' | 'onClick'>;

Expand All @@ -141,7 +141,10 @@ type CompoundedComponent = React.ForwardRefExoticComponent<

type Loading = number | boolean;

const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (props, ref) => {
const InternalButton: React.ForwardRefRenderFunction<
HTMLButtonElement | HTMLAnchorElement,
ButtonProps
> = (props, ref) => {
const {
loading = false,
prefixCls: customizePrefixCls,
Expand Down Expand Up @@ -175,7 +178,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
const groupSize = React.useContext(GroupSizeContext);
const [innerLoading, setLoading] = React.useState<Loading>(!!loading);
const [hasTwoCNChar, setHasTwoCNChar] = React.useState(false);
const buttonRef = (ref as any) || React.createRef<HTMLElement>();
const buttonRef = (ref as any) || React.createRef<HTMLAnchorElement | HTMLButtonElement>();
const isNeedInserted = () =>
React.Children.count(children) === 1 && !icon && !isUnBorderedButtonType(type);

Expand Down Expand Up @@ -316,7 +319,10 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
return wrapSSR(buttonNode);
};

const Button = React.forwardRef<unknown, ButtonProps>(InternalButton) as CompoundedComponent;
const Button = React.forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(
InternalButton,
) as CompoundedComponent;

if (process.env.NODE_ENV !== 'production') {
Button.displayName = 'Button';
}
Expand Down
2 changes: 1 addition & 1 deletion components/button/index.en-US.md
Expand Up @@ -64,7 +64,7 @@ Different button styles can be generated by setting Button properties. The recom
| size | Set the size of button | `large` \| `middle` \| `small` | `middle` | |
| target | Same as target attribute of a, works when href is specified | string | - | |
| type | Can be set to `primary` `ghost` `dashed` `link` `text` `default` | string | `default` | |
| onClick | Set the handler to handle `click` event | (event) => void | - | |
| onClick | Set the handler to handle `click` event | (event: MouseEvent) => void | - | |

It accepts all props which native buttons support.

Expand Down
2 changes: 1 addition & 1 deletion components/button/index.zh-CN.md
Expand Up @@ -69,7 +69,7 @@ group:
| size | 设置按钮大小 | `large` \| `middle` \| `small` | `middle` | |
| target | 相当于 a 链接的 target 属性,href 存在时生效 | string | - | |
| type | 设置按钮类型 | `primary` \| `ghost` \| `dashed` \| `link` \| `text` \| `default` | `default` | |
| onClick | 点击按钮时的回调 | (event) => void | - | |
| onClick | 点击按钮时的回调 | (event: MouseEvent) => void | - | |

支持原生 button 的其他所有属性。

Expand Down
Expand Up @@ -26612,6 +26612,7 @@ exports[`ConfigProvider components Table configProvider 1`] = `
<th
aria-label="this column's title is Name,this column is sortable"
class="config-table-cell config-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -26917,6 +26918,7 @@ exports[`ConfigProvider components Table configProvider componentDisabled 1`] =
<th
aria-label="this column's title is Name,this column is sortable"
class="config-table-cell config-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -27224,6 +27226,7 @@ exports[`ConfigProvider components Table configProvider componentSize large 1`]
<th
aria-label="this column's title is Name,this column is sortable"
class="config-table-cell config-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -27529,6 +27532,7 @@ exports[`ConfigProvider components Table configProvider componentSize middle 1`]
<th
aria-label="this column's title is Name,this column is sortable"
class="config-table-cell config-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -27834,6 +27838,7 @@ exports[`ConfigProvider components Table configProvider virtual and dropdownMatc
<th
aria-label="this column's title is Name,this column is sortable"
class="ant-table-cell ant-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -28139,6 +28144,7 @@ exports[`ConfigProvider components Table normal 1`] = `
<th
aria-label="this column's title is Name,this column is sortable"
class="ant-table-cell ant-table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down Expand Up @@ -28444,6 +28450,7 @@ exports[`ConfigProvider components Table prefixCls 1`] = `
<th
aria-label="this column's title is Name,this column is sortable"
class="prefix-Table-cell prefix-Table-column-has-sorters"
scope="col"
tabindex="0"
>
<div
Expand Down
Expand Up @@ -1468,16 +1468,19 @@ exports[`renders ./components/descriptions/demo/text.tsx extend context correctl
<tr>
<th
class="ant-table-cell"
scope="col"
>
姓名
</th>
<th
class="ant-table-cell"
scope="col"
>
年龄
</th>
<th
class="ant-table-cell"
scope="col"
>
住址
</th>
Expand Down
Expand Up @@ -1468,16 +1468,19 @@ exports[`renders ./components/descriptions/demo/text.tsx correctly 1`] = `
<tr>
<th
class="ant-table-cell"
scope="col"
>
姓名
</th>
<th
class="ant-table-cell"
scope="col"
>
年龄
</th>
<th
class="ant-table-cell"
scope="col"
>
住址
</th>
Expand Down
2 changes: 1 addition & 1 deletion components/dropdown/dropdown-button.tsx
Expand Up @@ -20,7 +20,7 @@ export interface DropdownButtonProps extends ButtonGroupProps, DropdownProps {
danger?: boolean;
disabled?: boolean;
loading?: ButtonProps['loading'];
onClick?: React.MouseEventHandler<HTMLButtonElement>;
onClick?: React.MouseEventHandler<HTMLElement>;
icon?: React.ReactNode;
href?: string;
children?: React.ReactNode;
Expand Down
Expand Up @@ -1039,11 +1039,13 @@ exports[`renders ./components/empty/demo/config-provider.tsx extend context corr
<tr>
<th
class="ant-table-cell"
scope="col"
>
Name
</th>
<th
class="ant-table-cell"
scope="col"
>
Age
</th>
Expand Down
2 changes: 2 additions & 0 deletions components/empty/__tests__/__snapshots__/demo.test.ts.snap
Expand Up @@ -588,11 +588,13 @@ exports[`renders ./components/empty/demo/config-provider.tsx correctly 1`] = `
<tr>
<th
class="ant-table-cell"
scope="col"
>
Name
</th>
<th
class="ant-table-cell"
scope="col"
>
Age
</th>
Expand Down

0 comments on commit e8a832c

Please sign in to comment.