-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(layout): optional middle-click tab close + perf and housekeeping #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -177,23 +177,21 @@ export const TabSet = (props: ITabSetProps) => { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| let leading : React.ReactNode = undefined; | ||||||
| let stickyButtons: React.ReactNode[] = []; | ||||||
| let buttons: React.ReactNode[] = []; | ||||||
| const baseHeader = React.useMemo(() => { | ||||||
| const rs: ITabSetRenderValues = { leading: undefined, stickyButtons: [], buttons: [], overflowPosition: undefined }; | ||||||
| layout.customizeTabSet(node, rs); | ||||||
| return rs; | ||||||
| // depend on node identity and callback identity | ||||||
| }, [node, (layout as any).props?.onRenderTabSet]); | ||||||
|
||||||
| }, [node, (layout as any).props?.onRenderTabSet]); | |
| }, [node, layout.onRenderTabSet]); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,35 +10,44 @@ export function isDesktop() { | |||||
| return desktop; | ||||||
| } | ||||||
| /** @internal */ | ||||||
| const tabRenderCache: WeakMap<TabNode, { key: string; base: { leading: React.ReactNode; content: React.ReactNode; name: string; buttons: any[] } }> = new WeakMap(); | ||||||
|
||||||
|
|
||||||
| export function getRenderStateEx( | ||||||
| layout: LayoutInternal, | ||||||
| node: TabNode, | ||||||
| iconAngle?: number | ||||||
| ) { | ||||||
| let leadingContent = undefined; | ||||||
| const titleContent: React.ReactNode = node.getName(); | ||||||
| const name = node.getName(); | ||||||
| if (iconAngle === undefined) { | ||||||
| iconAngle = 0; | ||||||
| } | ||||||
|
|
||||||
| if (leadingContent === undefined && node.getIcon() !== undefined) { | ||||||
| if (iconAngle !== 0) { | ||||||
| leadingContent = <img style={{ width: "1em", height: "1em", transform: "rotate(" + iconAngle + "deg)" }} src={node.getIcon()} alt="leadingContent" />; | ||||||
| } else { | ||||||
| leadingContent = <img style={{ width: "1em", height: "1em" }} src={node.getIcon()} alt="leadingContent" />; | ||||||
| const icon = node.getIcon(); | ||||||
| const angle = iconAngle ?? 0; | ||||||
| const onRenderRef = (layout as any).props?.onRenderTab; // function identity | ||||||
| const cacheKey = `${name}|${icon ?? ''}|${angle}|${onRenderRef ? onRenderRef : 'no'}`; | ||||||
|
||||||
| const cacheKey = `${name}|${icon ?? ''}|${angle}|${onRenderRef ? onRenderRef : 'no'}`; | |
| const cacheKey = `${name}|${icon ?? ''}|${angle}|${onRenderRef ? (onRenderRef.name || 'anon') : 'no'}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion
(layout as any)should be avoided. Consider properly typing the layout props or accessing the callback through a typed interface.