Skip to content

Commit

Permalink
feat(layout): 增加button组件
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Jun 20, 2021
1 parent dca8102 commit ad0369b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
</Row>
</Col>
<Col flex="0">
<Button :onClick="() => { setStateDate('parent.背包', _filter(parent.背包, (_,i) => i !== _toNumber(props.index))) }">删除</Button>
<Button type="link" :onClick="() => { setStateDate('parent.背包', _filter(parent.背包, (_,i) => i !== _toNumber(props.index))) }">删除</Button>
</Col>
</Row>
</Define>
Expand Down
6 changes: 3 additions & 3 deletions src/shared/components/layout/context/LayoutStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import { TMemo } from '@shared/components/TMemo';
import type { XMLBuilderContext } from '../XMLBuilder';

export const LayoutStateContext = React.createContext<XMLBuilderContext | null>(
null
);
export const LayoutStateContext =
React.createContext<XMLBuilderContext | null>(null);
LayoutStateContext.displayName = 'LayoutStateContext';

export const LayoutStateContextProvider: React.FC<{
state: XMLBuilderContext;
Expand Down
9 changes: 5 additions & 4 deletions src/shared/components/layout/context/LayoutWidthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';

export const LayoutWidthContext = React.createContext(0);
LayoutWidthContext.displayName = 'LayoutWidthContext';

interface LayoutWidthContextProviderProps {
width: number;
}
export const LayoutWidthContextProvider: React.FC<LayoutWidthContextProviderProps> = React.memo(
(props) => {
export const LayoutWidthContextProvider: React.FC<LayoutWidthContextProviderProps> =
React.memo((props) => {
return (
<LayoutWidthContext.Provider value={props.width}>
{props.children}
</LayoutWidthContext.Provider>
);
}
);
});
LayoutWidthContextProvider.displayName = 'LayoutWidthContextProvider';
32 changes: 32 additions & 0 deletions src/shared/components/layout/tags/Button/shared.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useContext } from 'react';
import type { TagComponent } from '../type';
import { TMemo } from '@shared/components/TMemo';
import { Button, ButtonProps } from 'antd';
import { useLayoutChildren } from '../../hooks/useLayoutChildren';
import { LayoutStateContext } from '../../context/LayoutStateContext';

interface TagButtonSharedProps {
showInDetail: boolean;
type: ButtonProps['type'];
danger: ButtonProps['danger'];
onClick: ButtonProps['onClick'];
}
export const TagButtonShared: TagComponent<TagButtonSharedProps> = TMemo(
(props) => {
const { showInDetail = false } = props;
const children = useLayoutChildren(props);
const context = useContext(LayoutStateContext)!;

if (context.layoutType === 'detail' && showInDetail !== true) {
// 详情页不显示按钮(默认)
return null;
}

return (
<Button type={props.type} danger={props.danger} onClick={props.onClick}>
{children}
</Button>
);
}
);
TagButtonShared.displayName = 'TagButtonShared';
3 changes: 3 additions & 0 deletions src/shared/components/layout/tags/__all__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { TagCustomListEdit } from './CustomList/edit';
import { TagCurrMaxEdit } from './CurrMax/edit';
import { TagCurrMaxDetail } from './CurrMax/detail';
import { TagSpaceShared } from './Space/shared';
import { TagButtonShared } from './Button/shared';

// 展示数据组件
registerTag('Template', TagTemplateShared);
Expand Down Expand Up @@ -83,6 +84,8 @@ registerTag('RollBtn', TagRollBtnDetail, TagRollBtnEdit);

registerTag('CurrMax', TagCurrMaxDetail, TagCurrMaxEdit);

registerTag('Button', TagButtonShared, TagButtonShared);

// 高级操作组件
registerTag('Use', TagUseShared);

Expand Down

0 comments on commit ad0369b

Please sign in to comment.