-
Notifications
You must be signed in to change notification settings - Fork 9
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
95 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import MPopup, {MPopupProps} from '../Popup' | ||
import Taro, {useEffect, useState} from '@tarojs/taro' | ||
import {functionalComponent} from '../component' | ||
import {MBottomSheetDefaultProps, MBottomSheetProps} from './props' | ||
import {View} from '@tarojs/components' | ||
|
||
function MBottomSheet(props: MBottomSheetProps) { | ||
const [visible, setVisible] = useState<boolean>(false) | ||
|
||
useEffect( | ||
() => { | ||
setVisible(props.visible) | ||
}, | ||
[props.visible], | ||
) | ||
|
||
const handleVisibleChange: MPopupProps['onVisibleChange'] = visible => { | ||
setVisible(visible) | ||
props.onVisibleChange(visible) | ||
} | ||
|
||
function handleTriggerClick() { | ||
handleVisibleChange(!visible) | ||
} | ||
|
||
return props.disabled ? props.children : ( | ||
<View className={props.className}> | ||
<View onClick={handleTriggerClick}> | ||
{props.children} | ||
</View> | ||
<MPopup | ||
position='bottom' | ||
visible={visible} | ||
maskClosable={props.maskClosable} | ||
onVisibleChange={handleVisibleChange}> | ||
{props.renderMain} | ||
</MPopup> | ||
</View> | ||
) | ||
} | ||
|
||
export {MBottomSheetProps} | ||
|
||
export default functionalComponent(MBottomSheetDefaultProps)(MBottomSheet) |
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 {createProps, RequiredProp} from '../component' | ||
import {MPopupDefaultProps} from '../Popup/props' | ||
import {partial, pick} from 'vtils' | ||
|
||
export const MBottomSheetDefaultProps = { | ||
...partial(pick( | ||
MPopupDefaultProps, | ||
['visible', 'onVisibleChange'], | ||
)), | ||
...createProps({ | ||
/** | ||
* 主体内容。 | ||
*/ | ||
renderMain: null as any as RequiredProp<React.ReactNode>, | ||
|
||
/** | ||
* 是否可点击遮罩关闭。 | ||
* | ||
* @default true | ||
*/ | ||
maskClosable: true as boolean, | ||
|
||
/** | ||
* 是否禁用。 | ||
* | ||
* @default false | ||
*/ | ||
disabled: false as boolean, | ||
}), | ||
} | ||
|
||
export type MBottomSheetProps = typeof MBottomSheetDefaultProps |
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