-
Notifications
You must be signed in to change notification settings - Fork 21
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
Showing
7 changed files
with
102 additions
and
94 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,43 @@ | ||
import { useContext } from 'react' | ||
import classNames from 'classnames'; | ||
import { isNumber, isString } from 'lodash-es'; | ||
|
||
import Context from '../common/context'; | ||
import { LayoutContextProps } from '../types'; | ||
|
||
// 通过判断容器 props 值,给容器设置class,由 class 控制容器 flex 样式 | ||
const useFlexClassNames = (props: any) => { | ||
const { autoFit, width, height, style } = props | ||
|
||
const { prefix } = useContext<LayoutContextProps>(Context); | ||
const clsPrefix = `${prefix}flex-item`; | ||
|
||
const validWidth = width || style?.width; | ||
const validHeight = isNumber(height) || (isString(height) && height !== '') ? height : undefined; | ||
const validMinHeight = style?.minHeight; | ||
|
||
let isDefault = false; | ||
let isAutoFit = false; | ||
let isValidWidth = false; | ||
let isValidHeight = false; | ||
|
||
if(autoFit) { | ||
isAutoFit = true | ||
} else if(validHeight || validMinHeight || validWidth) { | ||
isValidHeight = validHeight || validMinHeight | ||
isValidWidth = validWidth | ||
} else { | ||
isDefault = true | ||
} | ||
|
||
const classes = classNames({ | ||
[`${clsPrefix}-default`]: isDefault, | ||
[`${clsPrefix}-auto-fit`]: isAutoFit, | ||
[`${clsPrefix}-valid-width`]: isValidWidth, | ||
[`${clsPrefix}-valid-height`]: isValidHeight | ||
}) | ||
|
||
return classes | ||
} | ||
|
||
export default useFlexClassNames |
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