status_indicator.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { View } from '@tarojs/components'
  2. import './status_indicator.scss'
  3. import { rpxToPx } from '@/utils/tools'
  4. import { MainColorType } from '@/context/themes/color'
  5. export enum StatusType {
  6. normal = 'normal',
  7. ing = 'ing',
  8. img = 'img',
  9. console = 'console',
  10. big = 'big'
  11. }
  12. export default function StatusIndicator(props: {
  13. type: StatusType,
  14. color: string,
  15. text?: string,
  16. children?: any,
  17. fontColor?: string,
  18. fontSize?: number
  19. defaultSpace?: boolean,
  20. space?: number
  21. }) {
  22. function indicator() {
  23. switch (props.type) {
  24. case StatusType.normal:
  25. return <View style={{
  26. width: rpxToPx(14),
  27. height: rpxToPx(14),
  28. borderRadius: rpxToPx(7),
  29. backgroundColor: props.color
  30. }} />
  31. case StatusType.ing:
  32. return <View className='indicator_circle'
  33. style={{ borderColor: props.color }}
  34. >
  35. <View className='indicator_point' style={{ backgroundColor: props.color }} />
  36. </View>
  37. case StatusType.img:
  38. return <View style={{
  39. width: rpxToPx(26),
  40. height: rpxToPx(26),
  41. borderRadius: rpxToPx(13),
  42. backgroundColor: props.color,
  43. display: 'flex',
  44. alignItems: 'center',
  45. justifyContent: 'center'
  46. }}>
  47. {
  48. props.children
  49. }
  50. </View>
  51. case StatusType.console:
  52. return <View style={{
  53. width: rpxToPx(32),
  54. height: rpxToPx(32),
  55. borderRadius: rpxToPx(16),
  56. backgroundColor: props.color,
  57. marginTop: rpxToPx(2),
  58. display: 'flex',
  59. alignItems: 'center',
  60. justifyContent: 'center'
  61. }}>
  62. {
  63. props.children
  64. }
  65. </View>
  66. case StatusType.big:
  67. return <View style={{
  68. width: rpxToPx(32),
  69. height: rpxToPx(32),
  70. borderRadius: rpxToPx(16),
  71. backgroundColor: props.color,
  72. display: 'flex',
  73. alignItems: 'center',
  74. justifyContent: 'center'
  75. }}>
  76. {
  77. props.children
  78. }
  79. </View>
  80. }
  81. return <View />
  82. }
  83. function marginLeft() {
  84. if (props.type == StatusType.console || props.type == StatusType.big) return rpxToPx(24)
  85. if (props.defaultSpace) return rpxToPx(12)
  86. if (props.space) return props.space
  87. return rpxToPx(6)
  88. }
  89. return <View style={{
  90. display: 'flex',
  91. flexDirection: 'row',
  92. alignItems: 'center',
  93. }}>
  94. <View style={{
  95. width: (props.type == StatusType.console || props.type == StatusType.big) ? rpxToPx(32) : rpxToPx(26),
  96. height: (props.type == StatusType.console || props.type == StatusType.big) ? rpxToPx(32) : rpxToPx(26),
  97. display: 'flex',
  98. alignItems: 'center',
  99. justifyContent: 'center',
  100. }}>
  101. {
  102. indicator()
  103. }
  104. </View>
  105. {
  106. props.text && <View className='h20' style={{
  107. color: props.fontColor ? props.fontColor : MainColorType.g01,
  108. fontSize: props.fontSize ? props.fontSize : rpxToPx(20),
  109. marginLeft: marginLeft()
  110. }}>{props.text}</View>
  111. }
  112. </View>
  113. }