-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: auto layout hasSider (#45361)
* enhance: auto layout hasSider * test: update snapshot
- Loading branch information
Showing
6 changed files
with
69 additions
and
26 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
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,15 @@ | ||
import * as React from 'react'; | ||
|
||
export interface LayoutContextProps { | ||
siderHook: { | ||
addSider: (id: string) => void; | ||
removeSider: (id: string) => void; | ||
}; | ||
} | ||
|
||
export const LayoutContext = React.createContext<LayoutContextProps>({ | ||
siderHook: { | ||
addSider: () => null, | ||
removeSider: () => null, | ||
}, | ||
}); |
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,22 @@ | ||
import type * as React from 'react'; | ||
import toArray from 'rc-util/lib/Children/toArray'; | ||
|
||
import Sider from '../Sider'; | ||
|
||
export default function useHasSider( | ||
siders: string[], | ||
children?: React.ReactNode, | ||
hasSider?: boolean, | ||
) { | ||
if (typeof hasSider === 'boolean') { | ||
return hasSider; | ||
} | ||
|
||
if (siders.length) { | ||
return true; | ||
} | ||
|
||
const childNodes = toArray(children); | ||
|
||
return childNodes.some((node) => node.type === Sider); | ||
} |
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