Buttons.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { Button, View, Text } from "@tarojs/components";
  2. import './Buttons.scss'
  3. import { ButtonType, ComponentStatus } from "../../utils/types";
  4. import { Button as RNButton } from 'react-native';
  5. import { AtActivityIndicator } from 'taro-ui';
  6. import "taro-ui/dist/style/components/activity-indicator.scss";
  7. import 'taro-ui/dist/style/components/loading.scss';
  8. /*
  9. export default function Buttons(props: { title: string, type?: ButtonType, status?: ComponentStatus,onClick?:()=>void,style?:any }) {
  10. const myStyle = props.status == ComponentStatus.disable ? { opacity: 0.4 } : {}
  11. return (
  12. <View style={{...myStyle}}>
  13. <Button className={props.type == ButtonType.outline ? 'outline_btn' : 'btn'} style={{...props.style}} onClick={props.onClick}>{props.title}</Button>
  14. </View>
  15. )
  16. }*/
  17. export default function Buttons(props: {
  18. title: string,
  19. type?: ButtonType,
  20. className?: any,
  21. onClick: () => void,
  22. disabled?: boolean,
  23. lowLight?: boolean,
  24. openType?: string,
  25. btnStyle?: any,
  26. showLoading?: boolean,
  27. lightLoading?: boolean
  28. }) {
  29. function onClick(e) {
  30. if (process.env.TARO_ENV == 'weapp') {
  31. e.stopPropagation()
  32. }
  33. if (props.disabled) return
  34. props.onClick()
  35. }
  36. var mainClass = 'elevated'
  37. var textClass = 'elevated_text'
  38. if (props.type == ButtonType.text) {
  39. mainClass = 'texted'
  40. return <View style={{ opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }} onClick={onClick}>
  41. <Text
  42. style={{
  43. ...props.btnStyle,
  44. fontWeight: 'bold',
  45. }} className={props.className ? props.className : ''}>{props.title}</Text>
  46. </View>
  47. }
  48. if (props.type == ButtonType.outline) {
  49. mainClass = 'outlined'
  50. textClass = 'outlined_text'
  51. return (
  52. <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick}>
  53. {
  54. props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
  55. <AtActivityIndicator size={32} color={props.btnStyle.color} />
  56. </View>
  57. }
  58. <Text
  59. style={{
  60. color: props.btnStyle.color,
  61. fontSize: props.btnStyle.fontSize,
  62. fontWeight: 'bold',
  63. marginBottom: 2
  64. }}>{props.title}</Text>
  65. </View>
  66. )
  67. }
  68. // else {
  69. // mainClass = 'puretext'
  70. // textClass = 'puretext_text'
  71. // }
  72. return (
  73. <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick}>
  74. {
  75. props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
  76. <AtActivityIndicator size={32} color={props.lightLoading ? '#999' : '#000'} />
  77. </View>
  78. }
  79. <Text
  80. // onClick={onClick}
  81. style={{
  82. color: props.btnStyle.color,
  83. fontSize: props.btnStyle.fontSize,
  84. fontWeight: 'bold',
  85. marginBottom: 2
  86. }}>{props.title}</Text>
  87. </View>
  88. // <View onClick={onClick}>
  89. // <Text
  90. // style={{
  91. // height: props.btnStyle.height,
  92. // lineHeight: props.btnStyle.height,
  93. // color: props.btnStyle.color,
  94. // fontSize: props.btnStyle.fontSize
  95. // }}>{props.title}</Text>
  96. // </View>
  97. )
  98. }