index.tsx 5.1 KB

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