Modal.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { View, Text } from '@tarojs/components'
  2. import './Modal.scss'
  3. import React from 'react';
  4. import { ModalType } from '@/utils/types';
  5. import Box from './Box';
  6. export default function Modal(props: {
  7. children: React.ReactNode,
  8. testInfo?: React.ReactNode,
  9. title?: string, dismiss: Function,
  10. confirm: Function,
  11. themeColor?: string,
  12. modalType?: ModalType
  13. }) {
  14. //阻止中间内容点击事件穿透
  15. function click(e) {
  16. e.stopPropagation();
  17. }
  18. switch (props.modalType) {
  19. case ModalType.center:
  20. return <View className='modal modal_center_container' catchMove onClick={() => props.dismiss()}>
  21. <View className='center_modal_detail'>
  22. <Box><View onClick={click}>
  23. {
  24. props.children
  25. }
  26. </View>
  27. </Box>
  28. </View>
  29. </View>
  30. }
  31. return <View className='modal' catchMove>
  32. <View style={{ flex: 1 }} onClick={() => props.dismiss()}>
  33. {
  34. props.testInfo ? props.testInfo : null
  35. }
  36. </View>
  37. <View className='modal_bottom_content'>
  38. {/* <Text className='modal_title' style={{ color: color }}>{props.title ? props.title : '测试标题 '}</Text> */}
  39. {
  40. props.children
  41. }
  42. {/* <View className='modal_operate'>
  43. <View className='modal_btn' style={{ backgroundColor: color+alpha }} onClick={() => props.dismiss()}>
  44. <Text className='modal_cancel_text' style={{color:color}}>取消</Text>
  45. </View>
  46. <View className='btn_space' />
  47. <View className='modal_btn' style={{ backgroundColor: color }} onClick={() => props.confirm()}>
  48. <Text className='modal_confirm_text' style={{color:'#000'}}>确定</Text>
  49. </View>
  50. </View> */}
  51. </View>
  52. </View>
  53. }