-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dca8102
commit ad0369b
Showing
5 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters