Buttons.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. }) {
  28. function onClick() {
  29. if (props.disabled) return
  30. props.onClick()
  31. }
  32. var mainClass = 'elevated'
  33. var textClass = 'elevated_text'
  34. if (props.type == ButtonType.text) {
  35. mainClass = 'texted'
  36. return <View style={{ opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }} onClick={onClick}>
  37. <Text
  38. style={{
  39. ...props.btnStyle,
  40. fontWeight: 500,
  41. }} className={props.className ? props.className : ''}>{props.title}</Text>
  42. </View>
  43. }
  44. if (props.type == ButtonType.outline) {
  45. mainClass = 'outlined'
  46. textClass = 'outlined_text'
  47. return (
  48. <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick}>
  49. {
  50. props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
  51. <AtActivityIndicator size={32} color="#000" />
  52. </View>
  53. }
  54. <Text
  55. style={{
  56. color: props.btnStyle.color,
  57. fontSize: props.btnStyle.fontSize,
  58. fontWeight: 500,
  59. marginBottom: 2
  60. }}>{props.title}</Text>
  61. </View>
  62. )
  63. }
  64. // else {
  65. // mainClass = 'puretext'
  66. // textClass = 'puretext_text'
  67. // }
  68. return (
  69. <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick}>
  70. {
  71. props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
  72. <AtActivityIndicator size={32} color="#000" />
  73. </View>
  74. }
  75. <Text
  76. // onClick={onClick}
  77. style={{
  78. color: props.btnStyle.color,
  79. fontSize: props.btnStyle.fontSize,
  80. fontWeight: 500,
  81. marginBottom: 2
  82. }}>{props.title}</Text>
  83. </View>
  84. // <View onClick={onClick}>
  85. // <Text
  86. // style={{
  87. // height: props.btnStyle.height,
  88. // lineHeight: props.btnStyle.height,
  89. // color: props.btnStyle.color,
  90. // fontSize: props.btnStyle.fontSize
  91. // }}>{props.title}</Text>
  92. // </View>
  93. )
  94. }