Skip to content

Commit

Permalink
Merge pull request #923 from oceanbase/dengfuping-dev
Browse files Browse the repository at this point in the history
improve(design): Table padding when ProCard bodyStyle.padding is 0
  • Loading branch information
dengfuping authored Jan 10, 2025
2 parents 1164fd1 + b8c6bc5 commit 58dae02
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 20 deletions.
1 change: 1 addition & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default defineConfig({
{
title: 'ProComponents 组件',
children: [
{ title: 'ProCard 高级卡片', link: '/biz-components/pro-card' },
{ title: 'ProTable 高级表格', link: '/biz-components/pro-table' },
{ title: 'LightFilter 轻量筛选', link: '/biz-components/light-filter' },
],
Expand Down
3 changes: 2 additions & 1 deletion packages/design/src/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import classNames from 'classnames';
import React, { useContext } from 'react';
import ConfigProvider from '../config-provider';
import useStyle from './style';
import useStyle, { genTableStyle } from './style';

export * from 'antd/es/card/Card';
export * from 'antd/es/card';
Expand Down Expand Up @@ -97,4 +97,5 @@ if (process.env.NODE_ENV !== 'production') {
export default Object.assign(Card, {
Grid: AntCard.Grid,
Meta: AntCard.Meta,
genTableStyle,
});
2 changes: 1 addition & 1 deletion packages/design/src/card/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type CardToken = FullToken<'Card'> & {
tabsPrefixCls: string;
};

export const genTableStyle = (padding: number, token: CardToken): CSSObject => {
export const genTableStyle = (padding: number, token: Partial<CardToken>): CSSObject => {
const { antCls } = token;
const tableComponentCls = `${antCls}-table`;
return {
Expand Down
17 changes: 15 additions & 2 deletions packages/design/src/table/demo/card-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const App: React.FC = () => {

const [hasBorder, setHasBorder] = useState(true);
const [hasTitle, setHasTitle] = useState(true);
const [hasPadding, setHasPadding] = useState(true);
const [hasDivider, setHasDivider] = useState(true);
const [hasPadding, setHasPadding] = useState(false);
const [expandable, setExpandable] = useState(true);
const [selectable, setSelectable] = useState(true);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
Expand Down Expand Up @@ -51,7 +52,7 @@ const App: React.FC = () => {
}
}
>
<Form layout="inline" style={{ marginBottom: 24 }}>
<Form layout="inline">
<Form.Item label="Card bordered" required={true}>
<Switch
size="small"
Expand All @@ -70,6 +71,15 @@ const App: React.FC = () => {
}}
/>
</Form.Item>
<Form.Item label="Card divided" required={true}>
<Switch
size="small"
value={hasDivider}
onChange={value => {
setHasDivider(value);
}}
/>
</Form.Item>
<Form.Item label="Card body padding" required={true}>
<Switch
size="small"
Expand All @@ -79,6 +89,8 @@ const App: React.FC = () => {
}}
/>
</Form.Item>
</Form>
<Form layout="inline" style={{ marginBottom: 16 }}>
<Form.Item label="Table expandable" required={true}>
<Switch
size="small"
Expand All @@ -100,6 +112,7 @@ const App: React.FC = () => {
</Form>
<Card
bordered={hasBorder}
divided={hasDivider}
title={hasTitle ? 'Title' : ''}
bodyStyle={
hasPadding
Expand Down
139 changes: 139 additions & 0 deletions packages/design/src/table/demo/pro-card-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import React, { useState } from 'react';
import { Form, Switch, Table, theme } from '@oceanbase/design';
import { ProCard } from '@oceanbase/ui';

const App: React.FC = () => {
const { token } = theme.useToken();

const [hasBorder, setHasBorder] = useState(true);
const [hasTitle, setHasTitle] = useState(true);
const [hasPadding, setHasPadding] = useState(false);
const [expandable, setExpandable] = useState(true);
const [selectable, setSelectable] = useState(true);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);

const columns = [
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '年龄',
dataIndex: 'age',
key: 'age',
},
{
title: '住址',
dataIndex: 'address',
key: 'address',
},
];

const dataSource = [];
for (let i = 1; i < 100; i++) {
dataSource.push({
key: i,
name: '胡彦斌' + i,
age: 32,
address: `西湖区湖底公园${i}号`,
});
}

return (
<div
style={
hasBorder
? {}
: {
backgroundColor: token.colorFillContent,
padding: '40px 24px',
margin: '-40px -24px',
}
}
>
<Form layout="inline">
<Form.Item label="Card bordered" required={true}>
<Switch
size="small"
value={hasBorder}
onChange={value => {
setHasBorder(value);
}}
/>
</Form.Item>
<Form.Item label="Card title" required={true}>
<Switch
size="small"
value={hasTitle}
onChange={value => {
setHasTitle(value);
}}
/>
</Form.Item>
<Form.Item label="Card body padding" required={true}>
<Switch
size="small"
value={hasPadding}
onChange={value => {
setHasPadding(value);
}}
/>
</Form.Item>
</Form>
<Form layout="inline" style={{ marginBottom: 16 }}>
<Form.Item label="Table expandable" required={true}>
<Switch
size="small"
value={expandable}
onChange={value => {
setExpandable(value);
}}
/>
</Form.Item>
<Form.Item label="Table selectable" required={true}>
<Switch
size="small"
value={selectable}
onChange={value => {
setSelectable(value);
}}
/>
</Form.Item>
</Form>
<ProCard
bordered={hasBorder}
title={hasTitle ? 'Title' : ''}
bodyStyle={hasPadding ? { padding: 24 } : { padding: 0 }}
>
<Table
columns={columns}
dataSource={dataSource}
rowKey={record => record.key}
expandable={
expandable
? {
expandedRowRender: () => <div>This is expanded content</div>,
}
: undefined
}
rowSelection={
selectable
? {
selectedRowKeys: selectedRowKeys,
onChange: (keys: React.Key[]) => {
setSelectedRowKeys(keys);
},
}
: undefined
}
pagination={{
pageSize: 5,
}}
/>
</ProCard>
</div>
);
};

export default App;
17 changes: 2 additions & 15 deletions packages/design/src/table/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,23 @@ nav:

## 代码演示

<!-- prettier-ignore -->
<code src="./demo/basic.tsx" title="基本"></code>

<code src="./demo/bordered.tsx" title="带边框" description="添加表格边框线"></code>

<code src="./demo/fixed-columns-header-tables.tsx" title="固定头和列"></code>

<code src="./demo/row-selection.tsx" title="选择和操作"></code>

<code src="./demo/nesting-tables.tsx" title="嵌套子表格"></code>

<code src="./demo/multiple-nesting-tables.tsx" title="可选择的嵌套子表格"></code>

<code src="./demo/ellipsis.tsx" title="单元格自动省略" description="设置 `column.ellipsis` 可以让单元格内容根据宽度自动省略,并使用 Tooltip 展示全部内容。`说明`: 列头缩略暂不支持和排序筛选一起使用。"></code>

<code src="./demo/tree-table.tsx" title="树形表格" description="当数据中有 `children` 字段时会自动展示为树形表格,如果不需要或配置为其他字段可以用 childrenColumnName 进行配置。可以通过设置 indentSize 以控制每一层的缩进宽度。"></code>

<code src="./demo/grouping-columns.tsx" title="表头分组" description="columns 可以通过嵌套 children,实现表头分组。"></code>

<code src="./demo/rowspan.tsx" title="行合并" description="通过 onCell 设置单元格属性 rowSpan,可以实现行合并。"></code>

<code src="./demo/colspan-rowspan.tsx" title="行列合并" description="表头只支持列合并,使用 column 里的 colSpan 进行设置。\n表格支持行/列合并,使用 render 里的单元格属性 colSpan 或者 rowSpan 设值为 0 时,设置的表格不会渲染。"></code>

<code src="./demo/edit-row.tsx" title="可编辑行" description="带行编辑功能的表格。"></code>

<code src="./demo/virtual.tsx" title="虚拟滚动" description="通过 `virtual` 开启虚拟滚动,要求设置 `scroll.x` 和 `scroll.y` 且必须为 number 类型。"></code>

<code src="./demo/dynamic-settings.tsx" title="动态控制表格属性" description="选择不同配置组合查看效果。"></code>

<code src="./demo/card-table.tsx" title="和 Card 组合使用"></code>

<code src="./demo/pro-card-table.tsx" title="和 ProCard 组合使用" debug></code>
<code src="./demo/empty.tsx" title="空状态"></code>

## API
Expand Down
59 changes: 59 additions & 0 deletions packages/ui/src/ProCard/demo/basic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState } from 'react';
import { Form, Switch } from '@oceanbase/design';
import { ProCard } from '@oceanbase/ui';

export default () => {
const [hasPadding, setHasPadding] = useState(true);
const bodyStyle: React.CSSProperties = hasPadding ? {} : { padding: 0 };
return (
<>
<Form layout="inline" style={{ marginBottom: 16 }}>
<Form.Item label="ProCard has padding" required={true}>
<Switch
size="small"
value={hasPadding}
onChange={value => {
setHasPadding(value);
}}
/>
</Form.Item>
</Form>
<ProCard
title="默认尺寸"
bordered
extra="extra"
tooltip="这是提示"
style={{ width: 300 }}
bodyStyle={bodyStyle}
>
<div>Card content</div>
<div>Card content</div>
<div>Card content</div>
</ProCard>
<ProCard
title="带卡片阴影"
extra="extra"
tooltip="这是提示"
style={{ width: 300, marginBlockStart: 24 }}
bodyStyle={bodyStyle}
boxShadow
>
<div>Card content</div>
<div>Card content</div>
<div>Card content</div>
</ProCard>
<ProCard
title="小尺寸卡片"
extra="extra"
tooltip="这是提示"
style={{ width: 300, marginBlockStart: 24 }}
bodyStyle={bodyStyle}
size="small"
>
<div>Card content</div>
<div>Card content</div>
<div>Card content</div>
</ProCard>
</>
);
};
18 changes: 18 additions & 0 deletions packages/ui/src/ProCard/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: ProCard 高级卡片
nav:
title: 业务组件
path: /biz-components
---

- 🔥 完全继承 pro-components [ProCard](https://procomponents.ant.design/components/pro-card) 的能力和 API,可无缝切换。
- 💄 定制主题和样式,符合 OceanBase Design 设计规范。

## 代码演示

<!-- prettier-ignore -->
<code src="./demo/basic.tsx" title="基本"></code>

## API

- 详见 pro-components ProCard 文档: https://procomponents.ant.design/components/pro-card
52 changes: 52 additions & 0 deletions packages/ui/src/ProCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useContext } from 'react';
import { ProCard as AntProCard } from '@ant-design/pro-components';
import type { ProCardProps } from '@ant-design/pro-components';
import { ConfigProvider } from '@oceanbase/design';
import classNames from 'classnames';
import useStyle from './style';

export { ProCardProps };

// @ts-ignore
const ProCard: typeof AntProCard = ({
bodyStyle,
prefixCls: customizePrefixCls,
className,
...restProps
}) => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);

const prefixCls = getPrefixCls('pro-card', customizePrefixCls);
const { wrapSSR } = useStyle(prefixCls);

const zeroPaddingList = [0, '0', '0px'];
// ProCard body has no padding
const noBodyPadding = zeroPaddingList.includes(bodyStyle?.padding as string | number);

const proCardCls = classNames(
{
[`${prefixCls}-no-body-padding`]: noBodyPadding,
},
className
);

return wrapSSR(
<AntProCard
prefixCls={customizePrefixCls}
bodyStyle={bodyStyle}
className={proCardCls}
{...restProps}
/>
);
};

if (process.env.NODE_ENV !== 'production') {
ProCard.displayName = AntProCard.displayName;
}

ProCard.isProCard = AntProCard.isProCard;
ProCard.Divider = AntProCard.Divider;
ProCard.TabPane = AntProCard.TabPane;
ProCard.Group = AntProCard.Group;

export default ProCard;
Loading

0 comments on commit 58dae02

Please sign in to comment.