index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import {
  2. type FC
  3. } from "react";
  4. import {
  5. TouchableOpacity,
  6. View
  7. } from "react-native";
  8. import type IRowCardProps from "./type";
  9. import stylesheet, {
  10. useStyles
  11. } from "./stylesheet";
  12. import {
  13. NCoreUIKitTheme
  14. } from "../../core/hooks";
  15. import Text from "../text";
  16. const RowCard: FC<IRowCardProps> = ({
  17. rightSubTitleVariant = "labelLargeSize",
  18. rightTitleVariant = "labelLargeSize",
  19. subTitleVariant = "labelLargeSize",
  20. titleVariant = "labelLargeSize",
  21. rightContentContainerStyle,
  22. rightIcon: CustomRightIcon,
  23. leftContentContainerStyle,
  24. isTransparentBackground,
  25. type = "first-based",
  26. rightContainerStyle,
  27. rightSubTitleStyle,
  28. leftContainerStyle,
  29. rightSubTitleColor,
  30. leftSubTitleStyle,
  31. icon: CustomIcon,
  32. rightTitleColor,
  33. rightTitleStyle,
  34. rightIconStyle,
  35. leftTitleStyle,
  36. subTitleColor,
  37. rightSubTitle,
  38. customTheme,
  39. titleColor,
  40. rightTitle,
  41. iconStyle,
  42. subTitle,
  43. onPress,
  44. style,
  45. title
  46. }) => {
  47. const {
  48. radiuses,
  49. colors,
  50. spaces
  51. } = NCoreUIKitTheme.useContext(customTheme);
  52. const {
  53. rightIconContainer: rightIconContainerDynamicStyle,
  54. rightContainer: rightContainerDynamicStyle,
  55. leftContainer: leftContainerDynamicStyle,
  56. iconContainer: iconContainerDynamicStyle,
  57. rightSubTitle: rightSubTitleDynamicStyle,
  58. rightTitle: rightTitleDynamicStyle,
  59. container: containerDynamicStyle,
  60. subTitle: subTitleDynamicStyle,
  61. title: titleDynamicStyle
  62. } = useStyles({
  63. isTransparentBackground,
  64. radiuses,
  65. subTitle,
  66. spaces,
  67. colors,
  68. type
  69. });
  70. const renderRightIcon = () => {
  71. if(!CustomRightIcon) {
  72. return null;
  73. }
  74. return <View
  75. style={[
  76. rightIconStyle,
  77. stylesheet.rightIconContainer,
  78. rightIconContainerDynamicStyle
  79. ]}
  80. >
  81. <CustomRightIcon
  82. color="default"
  83. size={18}
  84. />
  85. </View>;
  86. };
  87. const renderLeftIcon = () => {
  88. if(!CustomIcon) {
  89. return null;
  90. }
  91. return <View
  92. style={[
  93. iconStyle,
  94. stylesheet.iconContainer,
  95. iconContainerDynamicStyle
  96. ]}
  97. >
  98. <CustomIcon
  99. color="default"
  100. size={18}
  101. />
  102. </View>;
  103. };
  104. const renderLeftSubTitle = () => {
  105. if(!subTitle) {
  106. return null;
  107. }
  108. return <Text
  109. color={subTitleColor ? subTitleColor : "low"}
  110. variant={subTitleVariant}
  111. style={[
  112. leftSubTitleStyle,
  113. stylesheet.subTitle,
  114. subTitleDynamicStyle
  115. ]}
  116. >
  117. {subTitle}
  118. </Text>;
  119. };
  120. const renderLeftContent = () => {
  121. return <View
  122. style={[
  123. leftContentContainerStyle
  124. ]}
  125. >
  126. <Text
  127. variant={titleVariant}
  128. color={titleColor}
  129. style={[
  130. leftTitleStyle,
  131. stylesheet.title,
  132. titleDynamicStyle
  133. ]}
  134. >
  135. {title}
  136. </Text>
  137. {renderLeftSubTitle()}
  138. </View>;
  139. };
  140. const renderLeft = () => {
  141. return <View
  142. style={[
  143. leftContainerStyle,
  144. stylesheet.leftContainer,
  145. leftContainerDynamicStyle
  146. ]}
  147. >
  148. {renderLeftContent()}
  149. </View>;
  150. };
  151. const renderRightSubTitle = () => {
  152. if(!rightSubTitle) {
  153. return null;
  154. }
  155. return <Text
  156. color={rightSubTitleColor? rightSubTitleColor : "low"}
  157. variant={rightSubTitleVariant}
  158. style={[
  159. rightSubTitleStyle,
  160. stylesheet.rightSubTitle,
  161. rightSubTitleDynamicStyle
  162. ]}
  163. >
  164. {rightSubTitle}
  165. </Text>;
  166. };
  167. const renderRightContent = () => {
  168. return <View
  169. style={[
  170. rightContentContainerStyle
  171. ]}
  172. >
  173. <Text
  174. variant={rightTitleVariant}
  175. color={rightTitleColor}
  176. style={[
  177. rightTitleStyle,
  178. stylesheet.rightTitle,
  179. rightTitleDynamicStyle
  180. ]}
  181. >
  182. {rightTitle}
  183. </Text>
  184. {renderRightSubTitle()}
  185. </View>;
  186. };
  187. const renderRight = () => {
  188. return <View
  189. style={[
  190. rightContainerStyle,
  191. stylesheet.rightContainer,
  192. rightContainerDynamicStyle
  193. ]}
  194. >
  195. {renderRightContent()}
  196. </View>;
  197. };
  198. return <TouchableOpacity
  199. style={[
  200. style,
  201. stylesheet.container,
  202. containerDynamicStyle
  203. ]}
  204. onPress={() => {
  205. if(onPress) {
  206. onPress();
  207. }
  208. }}
  209. >
  210. {renderLeftIcon()}
  211. {renderLeft()}
  212. {renderRight()}
  213. {renderRightIcon()}
  214. </TouchableOpacity>;
  215. };
  216. export default RowCard;