Skip to content

Commit

Permalink
✨ feat: ActionGroup add comman OnClick & add Divder Config
Browse files Browse the repository at this point in the history
  • Loading branch information
ONLY-yours committed Aug 29, 2023
1 parent 2576f1c commit 234ef98
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/ActionGroup/demos/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default () => {
},
label: '缩小!',
},
{
type: 'divider',
},
{
icon: <DragOutlined />,
onClick: () => {
Expand Down
24 changes: 23 additions & 1 deletion src/ActionGroup/demos/type.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CopyOutlined, DragOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
import { ActionGroup } from '@ant-design/pro-editor';
import { InputNumber, Segmented, Space } from 'antd';
import { useState } from 'react';
Expand All @@ -24,7 +25,28 @@ export default () => {
)}

<Segmented options={['row', 'column']} value={direction} onChange={setDirection} />
<ActionGroup type={type} size={size === 'number' ? number : size} direction={direction} />
<ActionGroup
type={type}
size={size === 'number' ? number : size}
direction={direction}
items={[
{
icon: <CopyOutlined />,
},
{
icon: <ZoomInOutlined />,
},
{
icon: <ZoomOutOutlined />,
},
{
type: 'divider',
},
{
icon: <DragOutlined />,
},
]}
/>
</Space>
);
};
45 changes: 30 additions & 15 deletions src/ActionGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
UndoOutlined,
} from '@ant-design/icons';
import { ActionIcon, getPrefixCls } from '@ant-design/pro-editor';
import { Dropdown, DropdownProps } from 'antd';
import { Divider, Dropdown, DropdownProps } from 'antd';
import { useStyle } from './style';

type ActionIconGroupItem = {
Expand Down Expand Up @@ -47,7 +47,7 @@ interface ActionGroupProps {
/**
* @description 生成按钮的配置config
*/
items?: Array<ActionIconGroupItem>;
items?: Array<ActionIconGroupItem | { type: 'divider' }>;
/**
* @description 生成 drowDownMenuList 内容的 config
*/
Expand All @@ -64,9 +64,13 @@ interface ActionGroupProps {
* @description 用于渲染自定义能力的render方法
*/
render?: (
config: Array<ActionIconGroupItem>,
config: Array<ActionIconGroupItem | { type: 'divider' }>,
dropdownMenu?: Array<ActionIconGroupItem | { type: 'divider' }>,
) => React.ReactNode;
/**
* @description 通用的 Click 触发
*/
onClick?: (key?: string) => void;
/**
* @description 全屏按钮点击的回掉
*/
Expand Down Expand Up @@ -109,6 +113,7 @@ const ActionGroup = (props: ActionGroupProps) => {
render,
dropdownMenu,
items,
onClick = () => {},
onFullScreenClick,
onUndoClick,
onRedoClick,
Expand All @@ -119,28 +124,38 @@ const ActionGroup = (props: ActionGroupProps) => {
const prefixCls = getPrefixCls('action-group');
const { styles, cx } = useStyle({ prefixCls, direction, type });

const config = items
? items
: [
{ icon: <FullscreenOutlined />, onClick: onFullScreenClick },
{ icon: <UndoOutlined />, onClick: onUndoClick },
{ icon: <RedoOutlined />, onClick: onRedoClick },
{ icon: <DeleteOutlined />, onClick: onDeleteClick },
];
const DefalutItemConfig = [
{ icon: <FullscreenOutlined />, onClick: onFullScreenClick },
{ icon: <UndoOutlined />, onClick: onUndoClick },
{ icon: <RedoOutlined />, onClick: onRedoClick },
{ icon: <DeleteOutlined />, onClick: onDeleteClick },
];

const config = items || DefalutItemConfig;

const ActionDomList = () => {
const defalutDom = (
<>
{config.map((item: ActionIconGroupItem, index) => {
{config.map((item, index) => {
if (item?.type)
return (
<Divider
type={direction === 'row' ? 'vertical' : 'horizontal'}
style={{
margin: `${direction === 'row' ? '0 4px' : '4px 0'}`,
}}
/>
);
return (
<ActionIcon
key={`action-btn-${index}`}
title={item?.label}
size={size}
{...item}
onClick={() => {
alert('触发动作');
item?.onClick();
onClick(item?.key);
}}
{...item}
/>
);
})}
Expand All @@ -161,7 +176,7 @@ const ActionGroup = (props: ActionGroupProps) => {
{...dropdownProps}
menu={{
items: dropdownMenu.map((item: any) => {
if (item.type) return item;
if (item?.type) return item;
return {
...item,
icon: item.icon,
Expand Down
1 change: 1 addition & 0 deletions src/ActionGroup/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useStyle = createStyles(({ token, css, cx }, { prefixCls, type, dir
display: flex;
flex-direction: ${direction};
border-radius: ${token.borderRadius}px;
align-items: center;
`,
),
button: cx(
Expand Down

0 comments on commit 234ef98

Please sign in to comment.