mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 06:03:38 +08:00
commit
9c45647556
@ -8,26 +8,26 @@ import type { Project } from '@stackblitz/sdk';
|
||||
import stackblitzSdk from '@stackblitz/sdk';
|
||||
import { Alert, Badge, Space, Tooltip } from 'antd';
|
||||
import classNames from 'classnames';
|
||||
import LZString from 'lz-string';
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import type { IPreviewerProps } from 'dumi';
|
||||
import { FormattedMessage, useSiteData } from 'dumi';
|
||||
import Prism from 'prismjs';
|
||||
import JsonML from 'jsonml.js/lib/utils';
|
||||
import toReactElement from 'jsonml-to-react-element';
|
||||
import { ping } from '../../utils';
|
||||
import ClientOnly from '../../common/ClientOnly';
|
||||
import JsonML from 'jsonml.js/lib/utils';
|
||||
import LZString from 'lz-string';
|
||||
import Prism from 'prismjs';
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
import useLocation from '../../../hooks/useLocation';
|
||||
import BrowserFrame from '../../common/BrowserFrame';
|
||||
import EditButton from '../../common/EditButton';
|
||||
import ClientOnly from '../../common/ClientOnly';
|
||||
import CodePenIcon from '../../common/CodePenIcon';
|
||||
import CodePreview from '../../common/CodePreview';
|
||||
import CodeSandboxIcon from '../../common/CodeSandboxIcon';
|
||||
import RiddleIcon from '../../common/RiddleIcon';
|
||||
import EditButton from '../../common/EditButton';
|
||||
import ExternalLinkIcon from '../../common/ExternalLinkIcon';
|
||||
import RiddleIcon from '../../common/RiddleIcon';
|
||||
import type { SiteContextProps } from '../../slots/SiteContext';
|
||||
import SiteContext from '../../slots/SiteContext';
|
||||
import useLocation from '../../../hooks/useLocation';
|
||||
import { ping } from '../../utils';
|
||||
|
||||
const { ErrorBoundary } = Alert;
|
||||
|
||||
@ -103,6 +103,7 @@ const CodePreviewer: React.FC<IPreviewerProps> = (props) => {
|
||||
compact,
|
||||
background,
|
||||
filePath,
|
||||
version,
|
||||
} = props;
|
||||
|
||||
const { pkg } = useSiteData();
|
||||
@ -209,17 +210,17 @@ const CodePreviewer: React.FC<IPreviewerProps> = (props) => {
|
||||
</html>
|
||||
`;
|
||||
|
||||
const tsconfig = `
|
||||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
}
|
||||
}
|
||||
`;
|
||||
const tsconfig = {
|
||||
compilerOptions: {
|
||||
target: 'esnext',
|
||||
module: 'esnext',
|
||||
esModuleInterop: true,
|
||||
moduleResolution: 'node',
|
||||
jsx: 'react',
|
||||
jsxFactory: 'React.createElement',
|
||||
jsxFragmentFactory: 'React.Fragment',
|
||||
},
|
||||
};
|
||||
|
||||
const suffix = codeType === 'tsx' ? 'tsx' : 'js';
|
||||
|
||||
@ -367,8 +368,9 @@ createRoot(document.getElementById('container')).render(<Demo />);
|
||||
'index.html': html,
|
||||
},
|
||||
};
|
||||
|
||||
if (suffix === 'tsx') {
|
||||
stackblitzPrefillConfig.files['tsconfig.json'] = tsconfig;
|
||||
stackblitzPrefillConfig.files['tsconfig.json'] = JSON.stringify(tsconfig, null, 2);
|
||||
}
|
||||
|
||||
const backgroundGrey = theme.includes('dark') ? '#303030' : '#f0f2f5';
|
||||
@ -541,9 +543,9 @@ createRoot(document.getElementById('container')).render(<Demo />);
|
||||
</section>
|
||||
);
|
||||
|
||||
if (pkg.version) {
|
||||
if (version) {
|
||||
return (
|
||||
<Badge.Ribbon text={pkg.version} color={pkg.version.includes('<') ? 'red' : null}>
|
||||
<Badge.Ribbon text={version} color={version.includes('<') ? 'red' : null}>
|
||||
{codeBox}
|
||||
</Badge.Ribbon>
|
||||
);
|
||||
|
@ -220,7 +220,9 @@ const Content: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
</Space>
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
{meta.frontmatter.description !== meta.texts[0]?.value && meta.frontmatter.description}
|
||||
{pathname.startsWith('/components') &&
|
||||
meta.frontmatter.description !== meta.texts[0]?.value &&
|
||||
meta.frontmatter.description}
|
||||
{children}
|
||||
{meta.frontmatter.filename && (
|
||||
<ContributorsList
|
||||
|
@ -21,6 +21,7 @@ const genMessageStyle: GenerateStyle<MessageToken> = (token) => {
|
||||
componentCls,
|
||||
iconCls,
|
||||
boxShadow,
|
||||
colorText,
|
||||
colorBgElevated,
|
||||
colorSuccess,
|
||||
colorError,
|
||||
@ -69,6 +70,7 @@ const genMessageStyle: GenerateStyle<MessageToken> = (token) => {
|
||||
{
|
||||
[componentCls]: {
|
||||
...resetComponent(token),
|
||||
color: colorText,
|
||||
position: 'fixed',
|
||||
top: marginXS,
|
||||
width: '100%',
|
||||
|
@ -359,8 +359,8 @@ function InternalTable<RecordType extends object = any>(
|
||||
|
||||
const [mergedPagination, resetPagination] = usePagination(
|
||||
mergedData.length,
|
||||
pagination,
|
||||
onPaginationChange,
|
||||
pagination,
|
||||
);
|
||||
|
||||
changeEventInfo.pagination =
|
||||
@ -400,17 +400,20 @@ function InternalTable<RecordType extends object = any>(
|
||||
]);
|
||||
|
||||
// ========================== Selections ==========================
|
||||
const [transformSelectionColumns, selectedKeySet] = useSelection<RecordType>(rowSelection, {
|
||||
prefixCls,
|
||||
data: mergedData,
|
||||
pageData,
|
||||
getRowKey,
|
||||
getRecordByKey,
|
||||
expandType,
|
||||
childrenColumnName,
|
||||
locale: tableLocale,
|
||||
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
||||
});
|
||||
const [transformSelectionColumns, selectedKeySet] = useSelection<RecordType>(
|
||||
{
|
||||
prefixCls,
|
||||
data: mergedData,
|
||||
pageData,
|
||||
getRowKey,
|
||||
getRecordByKey,
|
||||
expandType,
|
||||
childrenColumnName,
|
||||
locale: tableLocale,
|
||||
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
||||
},
|
||||
rowSelection,
|
||||
);
|
||||
|
||||
const internalRowClassName = (record: RecordType, index: number, indent: number) => {
|
||||
let mergedRowClassName: string;
|
||||
|
@ -575,6 +575,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-thead"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="col"
|
||||
>
|
||||
RowHead
|
||||
</th>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="col"
|
||||
@ -609,6 +615,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="1"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
1
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -641,6 +653,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="2"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
2
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
colspan="5"
|
||||
@ -654,6 +672,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="3"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
3
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -686,6 +710,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="4"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
4
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -719,6 +749,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx extend context corr
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="5"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
5
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
|
@ -575,6 +575,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-thead"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="col"
|
||||
>
|
||||
RowHead
|
||||
</th>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="col"
|
||||
@ -609,6 +615,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="1"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
1
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -641,6 +653,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="2"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
2
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
colspan="5"
|
||||
@ -654,6 +672,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="3"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
3
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -686,6 +710,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="4"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
4
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
@ -719,6 +749,12 @@ exports[`renders ./components/table/demo/colspan-rowspan.tsx correctly 1`] = `
|
||||
class="ant-table-row ant-table-row-level-0"
|
||||
data-row-key="5"
|
||||
>
|
||||
<th
|
||||
class="ant-table-cell"
|
||||
scope="row"
|
||||
>
|
||||
5
|
||||
</th>
|
||||
<td
|
||||
class="ant-table-cell"
|
||||
>
|
||||
|
@ -22,6 +22,11 @@ const sharedOnCell = (_: DataType, index: number) => {
|
||||
};
|
||||
|
||||
const columns: ColumnsType<DataType> = [
|
||||
{
|
||||
title: 'RowHead',
|
||||
dataIndex: 'key',
|
||||
rowScope: 'row',
|
||||
},
|
||||
{
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useState } from 'react';
|
||||
import type { PaginationProps } from '../../pagination';
|
||||
import type { TablePaginationConfig } from '../interface';
|
||||
import extendsObject from '../../_util/extendsObject';
|
||||
import type { TablePaginationConfig } from '../interface';
|
||||
|
||||
export const DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
@ -13,10 +13,11 @@ export function getPaginationParam(
|
||||
current: mergedPagination.current,
|
||||
pageSize: mergedPagination.pageSize,
|
||||
};
|
||||
|
||||
const paginationObj = pagination && typeof pagination === 'object' ? pagination : {};
|
||||
|
||||
Object.keys(paginationObj).forEach((pageProp) => {
|
||||
const value = (mergedPagination as any)[pageProp];
|
||||
Object.keys(paginationObj).forEach((pageProp: keyof typeof paginationObj) => {
|
||||
const value = mergedPagination[pageProp];
|
||||
|
||||
if (typeof value !== 'function') {
|
||||
param[pageProp] = value;
|
||||
@ -26,22 +27,21 @@ export function getPaginationParam(
|
||||
return param;
|
||||
}
|
||||
|
||||
export default function usePagination(
|
||||
function usePagination(
|
||||
total: number,
|
||||
pagination: TablePaginationConfig | false | undefined,
|
||||
onChange: (current: number, pageSize: number) => void,
|
||||
): [TablePaginationConfig, () => void] {
|
||||
pagination?: TablePaginationConfig | false,
|
||||
): readonly [TablePaginationConfig, () => void] {
|
||||
const { total: paginationTotal = 0, ...paginationObj } =
|
||||
pagination && typeof pagination === 'object' ? pagination : {};
|
||||
|
||||
const [innerPagination, setInnerPagination] = useState<{
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
}>(() => ({
|
||||
current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
|
||||
pageSize:
|
||||
'defaultPageSize' in paginationObj ? paginationObj.defaultPageSize : DEFAULT_PAGE_SIZE,
|
||||
}));
|
||||
const [innerPagination, setInnerPagination] = useState<{ current?: number; pageSize?: number }>(
|
||||
() => ({
|
||||
current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
|
||||
pageSize:
|
||||
'defaultPageSize' in paginationObj ? paginationObj.defaultPageSize : DEFAULT_PAGE_SIZE,
|
||||
}),
|
||||
);
|
||||
|
||||
// ============ Basic Pagination Config ============
|
||||
const mergedPagination = extendsObject<Partial<TablePaginationConfig>>(
|
||||
@ -75,7 +75,7 @@ export default function usePagination(
|
||||
};
|
||||
|
||||
if (pagination === false) {
|
||||
return [{}, () => {}];
|
||||
return [{}, () => {}] as const;
|
||||
}
|
||||
|
||||
return [
|
||||
@ -84,5 +84,7 @@ export default function usePagination(
|
||||
onChange: onInternalChange,
|
||||
},
|
||||
refreshPagination,
|
||||
];
|
||||
] as const;
|
||||
}
|
||||
|
||||
export default usePagination;
|
||||
|
@ -68,10 +68,10 @@ function flattenData<RecordType>(childrenColumnName: string, data?: RecordType[]
|
||||
return list;
|
||||
}
|
||||
|
||||
export default function useSelection<RecordType>(
|
||||
rowSelection: TableRowSelection<RecordType> | undefined,
|
||||
function useSelection<RecordType>(
|
||||
config: UseSelectionConfig<RecordType>,
|
||||
): [TransformColumns<RecordType>, Set<Key>] {
|
||||
rowSelection?: TableRowSelection<RecordType>,
|
||||
): readonly [TransformColumns<RecordType>, Set<Key>] {
|
||||
const {
|
||||
preserveSelectedRowKeys,
|
||||
selectedRowKeys,
|
||||
@ -716,5 +716,7 @@ export default function useSelection<RecordType>(
|
||||
],
|
||||
);
|
||||
|
||||
return [transformColumns, derivedSelectedKeySet];
|
||||
return [transformColumns, derivedSelectedKeySet] as const;
|
||||
}
|
||||
|
||||
export default useSelection;
|
||||
|
@ -14,7 +14,10 @@ const genBorderedStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
[`&${componentCls}-${size}`]: {
|
||||
[`> ${componentCls}-container`]: {
|
||||
[`> ${componentCls}-content, > ${componentCls}-body`]: {
|
||||
'> table > tbody > tr > td': {
|
||||
[`
|
||||
> table > tbody > tr > th,
|
||||
> table > tbody > tr > td
|
||||
`]: {
|
||||
[`> ${componentCls}-expanded-row-fixed`]: {
|
||||
margin: `-${paddingVertical}px -${paddingHorizontal + token.lineWidth}px`,
|
||||
},
|
||||
@ -47,6 +50,7 @@ const genBorderedStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
// ============================= Cell =============================
|
||||
[`
|
||||
> thead > tr > th,
|
||||
> tbody > tr > th,
|
||||
> tbody > tr > td,
|
||||
> tfoot > tr > th,
|
||||
> tfoot > tr > td
|
||||
@ -77,7 +81,10 @@ const genBorderedStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
},
|
||||
|
||||
// ========================== Expandable ==========================
|
||||
'> tbody > tr > td': {
|
||||
[`
|
||||
> tbody > tr > th,
|
||||
> tbody > tr > td
|
||||
`]: {
|
||||
[`> ${componentCls}-expanded-row-fixed`]: {
|
||||
margin: `-${token.tablePaddingVertical}px -${
|
||||
token.tablePaddingHorizontal + token.lineWidth
|
||||
@ -114,7 +121,7 @@ const genBorderedStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
> tr${componentCls}-expanded-row,
|
||||
> tr${componentCls}-placeholder
|
||||
`]: {
|
||||
'> td': {
|
||||
[`> th, > td`]: {
|
||||
borderInlineEnd: 0,
|
||||
},
|
||||
},
|
||||
|
@ -11,7 +11,10 @@ const genEmptyStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
textAlign: 'center',
|
||||
color: token.colorTextDisabled,
|
||||
|
||||
'&:hover > td': {
|
||||
[`
|
||||
&:hover > th,
|
||||
&:hover > td,
|
||||
`]: {
|
||||
background: token.colorBgContainer,
|
||||
},
|
||||
},
|
||||
|
@ -123,7 +123,7 @@ const genExpandStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
|
||||
[`tr${componentCls}-expanded-row`]: {
|
||||
'&, &:hover': {
|
||||
'> td': {
|
||||
[`> th, > td`]: {
|
||||
background: tableExpandedRowBg,
|
||||
},
|
||||
},
|
||||
|
@ -117,6 +117,7 @@ const genTableStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
// ============================= Cell =============================
|
||||
[`
|
||||
${componentCls}-thead > tr > th,
|
||||
${componentCls}-tbody > tr > th,
|
||||
${componentCls}-tbody > tr > td,
|
||||
tfoot > tr > th,
|
||||
tfoot > tr > td
|
||||
@ -171,7 +172,7 @@ const genTableStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
// ============================ Body ============================
|
||||
[`${componentCls}-tbody`]: {
|
||||
'> tr': {
|
||||
'> td': {
|
||||
[`> th, > td`]: {
|
||||
transition: `background ${motionDurationMid}, border-color ${motionDurationMid}`,
|
||||
borderBottom: tableBorder,
|
||||
|
||||
@ -195,19 +196,31 @@ const genTableStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
},
|
||||
},
|
||||
|
||||
'> th': {
|
||||
position: 'relative',
|
||||
color: tableHeaderTextColor,
|
||||
fontWeight: fontWeightStrong,
|
||||
textAlign: 'start',
|
||||
background: tableHeaderBg,
|
||||
borderBottom: tableBorder,
|
||||
transition: `background ${motionDurationMid} ease`,
|
||||
},
|
||||
|
||||
[`
|
||||
&${componentCls}-row:hover > th,
|
||||
&${componentCls}-row:hover > td,
|
||||
> th${componentCls}-cell-row-hover
|
||||
> td${componentCls}-cell-row-hover
|
||||
`]: {
|
||||
background: tableRowHoverBg,
|
||||
},
|
||||
|
||||
[`&${componentCls}-row-selected`]: {
|
||||
'> td': {
|
||||
[`> th, > td`]: {
|
||||
background: tableSelectedRowBg,
|
||||
},
|
||||
|
||||
'&:hover > td': {
|
||||
[`&:hover > th, &:hover > td`]: {
|
||||
background: tableSelectedRowHoverBg,
|
||||
},
|
||||
},
|
||||
|
@ -16,6 +16,7 @@ const genSizeStyle: GenerateStyle<TableToken, CSSObject> = (token) => {
|
||||
${componentCls}-title,
|
||||
${componentCls}-footer,
|
||||
${componentCls}-thead > tr > th,
|
||||
${componentCls}-tbody > tr > th,
|
||||
${componentCls}-tbody > tr > td,
|
||||
tfoot > tr > th,
|
||||
tfoot > tr > td
|
||||
|
Loading…
Reference in New Issue
Block a user