feat(web): 账号详情页对齐 Pro Advanced Profile——三卡卡片流、实体标识进页头 content 行左侧
douyin-release-gate / verify (push) Failing after 2m47s
douyin-release-gate / verify (push) Failing after 2m47s
This commit is contained in:
@@ -1,17 +1,31 @@
|
||||
import { createContext, useContext, useEffect } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
// 页头动作槽:页面挂载时把自己的操作按钮注册到布局 PageContainer 的 content(标题下方独立操作行,右侧对齐),
|
||||
// 卸载时自动清除。Layout 提供 Provider,页面只消费 usePageActions。
|
||||
const PageActionsContext = createContext<(node: ReactNode) => void>(() => {});
|
||||
// 页头槽:页面挂载时把自己的内容注册到布局 PageContainer 的 content 行——
|
||||
// info 在左(实体标识/关键状态),actions 在右(操作按钮,右侧对齐),卸载时自动清除。
|
||||
// Layout 提供 Provider,页面只消费 usePageInfo / usePageActions。
|
||||
type SetSlot = (node: ReactNode) => void;
|
||||
const PageHeaderSlotsContext = createContext<{ setInfo: SetSlot; setActions: SetSlot }>({
|
||||
setInfo: () => {},
|
||||
setActions: () => {},
|
||||
});
|
||||
|
||||
export function usePageActions(node: ReactNode, deps: unknown[] = []) {
|
||||
const setPageActions = useContext(PageActionsContext);
|
||||
function useSlot(setSlot: SetSlot, node: ReactNode, deps: unknown[]) {
|
||||
useEffect(() => {
|
||||
setPageActions(node);
|
||||
return () => setPageActions(null);
|
||||
setSlot(node);
|
||||
return () => setSlot(null);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, deps);
|
||||
}
|
||||
|
||||
export { PageActionsContext };
|
||||
export function usePageInfo(node: ReactNode, deps: unknown[] = []) {
|
||||
const { setInfo } = useContext(PageHeaderSlotsContext);
|
||||
useSlot(setInfo, node, deps);
|
||||
}
|
||||
|
||||
export function usePageActions(node: ReactNode, deps: unknown[] = []) {
|
||||
const { setActions } = useContext(PageHeaderSlotsContext);
|
||||
useSlot(setActions, node, deps);
|
||||
}
|
||||
|
||||
export { PageHeaderSlotsContext };
|
||||
|
||||
Reference in New Issue
Block a user