CheckBox.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { CheckBoxType } from "@/utils/types";
  2. import { View, Image } from "@tarojs/components";
  3. import './CheckBox.scss'
  4. export default function Component(props: {
  5. type: CheckBoxType,
  6. color?: string,
  7. width?: number,
  8. borderWidth?: number,
  9. opacity?: number,
  10. onClick?: Function
  11. }) {
  12. var outerWidth = props.width ? props.width : 16
  13. var iconBorderWidth = props.borderWidth ? props.borderWidth : 1
  14. var innerWidth = outerWidth * 3 / 4
  15. var alpha = props.opacity ? props.opacity : 1
  16. var bgColor = 'transparent'
  17. var borderColor = '#fff'
  18. if (props.type != CheckBoxType.empty) {
  19. if (!props.color) {
  20. bgColor = 'rgba(255,255,255,0.4)'
  21. borderColor = '#fff'
  22. }
  23. else {
  24. bgColor = props.color + '66'
  25. borderColor = props.color
  26. }
  27. }
  28. return <View className="checkbox" style={{
  29. opacity: alpha,
  30. borderWidth: iconBorderWidth,
  31. width: outerWidth,
  32. height: outerWidth,
  33. borderRadius: outerWidth / 2.0,
  34. borderStyle: 'solid',
  35. borderColor: borderColor,
  36. backgroundColor: bgColor
  37. }}>
  38. {
  39. props.type == CheckBoxType.cross &&
  40. <Image src={require('@assets/images/x.png')} style={{ width: innerWidth, height: innerWidth }} />
  41. }
  42. {
  43. props.type == CheckBoxType.check &&
  44. <Image src={require('@assets/images/check.png')} style={{ width: innerWidth, height: innerWidth }} />
  45. }
  46. {
  47. props.type == CheckBoxType.arrow &&
  48. <Image src={require('@assets/images/arrow2.png')} style={{ width: innerWidth, height: innerWidth }} />
  49. }
  50. </View>
  51. }