stylesheet.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {
  2. type TextStyle,
  3. type ViewStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type RadioButtonDynamicStyleType,
  8. type RadioButtonTypeConstantType,
  9. type RadioButtonTypes,
  10. type RadioButtonType
  11. } from "./type";
  12. import type {
  13. Mutable
  14. } from "../../types";
  15. export const RADIO_BUTTON_TYPE_STYLES: Record<
  16. RadioButtonType,
  17. {
  18. containerColor: keyof NCoreUIKit.ContainerContentColors;
  19. indicatorColor: keyof NCoreUIKit.IconContentColors;
  20. subTitleColor: keyof NCoreUIKit.TextContentColors;
  21. borderColor: keyof NCoreUIKit.BorderContentColors;
  22. titleColor: keyof NCoreUIKit.TextContentColors;
  23. }
  24. > = {
  25. primary: {
  26. indicatorColor: "emphasized",
  27. borderColor: "emphasized",
  28. containerColor: "mid",
  29. subTitleColor: "low",
  30. titleColor: "mid"
  31. },
  32. danger: {
  33. subTitleColor: "dangerLow",
  34. indicatorColor: "danger",
  35. containerColor: "danger",
  36. borderColor: "danger",
  37. titleColor: "danger"
  38. },
  39. success: {
  40. subTitleColor: "successLow",
  41. indicatorColor: "success",
  42. containerColor: "success",
  43. borderColor: "success",
  44. titleColor: "success"
  45. },
  46. warning: {
  47. subTitleColor: "warningLow",
  48. indicatorColor: "warning",
  49. containerColor: "warning",
  50. borderColor: "warning",
  51. titleColor: "warning"
  52. },
  53. info: {
  54. subTitleColor: "infoLow",
  55. indicatorColor: "info",
  56. containerColor: "info",
  57. borderColor: "info",
  58. titleColor: "info"
  59. },
  60. neutral: {
  61. indicatorColor: "emphasized",
  62. containerColor: "mid",
  63. borderColor: "subtle",
  64. subTitleColor: "low",
  65. titleColor: "mid"
  66. }
  67. };
  68. export const getRadioButtonType = ({
  69. type
  70. }: RadioButtonTypeConstantType): RadioButtonTypes => {
  71. const currentType = RADIO_BUTTON_TYPE_STYLES[type];
  72. return currentType;
  73. };
  74. const stylesheet = StyleSheet.create({
  75. container: {
  76. backgroundColor: "transparent",
  77. borderColor: "transparent",
  78. flexDirection: "row",
  79. borderStyle: "solid",
  80. alignItems: "center",
  81. display: "flex"
  82. },
  83. indicatorContainer: {
  84. position: "relative"
  85. },
  86. indicator: {
  87. borderStyle: "solid"
  88. },
  89. contentContainer: {
  90. justifyContent: "center",
  91. flexDirection: "column"
  92. },
  93. titleContainer: {
  94. justifyContent: "flex-start",
  95. flexDirection: "row",
  96. alignItems: "center"
  97. },
  98. title: {
  99. textAlign: "left",
  100. margin: 0
  101. },
  102. subTitle: {
  103. textAlign: "left"
  104. },
  105. loading: {},
  106. overlay: {
  107. position: "absolute",
  108. display: "none",
  109. zIndex: 999,
  110. bottom: -2,
  111. right: -2,
  112. left: -2,
  113. top: -2
  114. }
  115. });
  116. export const useStyles = ({
  117. displayBehaviourWhileLoading,
  118. RADIO_INDICATOR_SIZE,
  119. spreadBehaviour,
  120. inlineSpaces,
  121. currentType,
  122. isDisabled,
  123. isLoading,
  124. isChecked,
  125. radiuses,
  126. borders,
  127. colors,
  128. isFlip,
  129. spaces,
  130. type
  131. }: RadioButtonDynamicStyleType) => {
  132. const styleType = type === "danger" ? "error" : type;
  133. const styles = {
  134. container: {
  135. padding: spaces.spacingSm
  136. } as Mutable<ViewStyle>,
  137. indicatorContainer: {
  138. borderRadius: (RADIO_INDICATOR_SIZE + (spaces.spacingXs * 2) + (borders.line * 2)) / 2,
  139. backgroundColor: colors.content.container[currentType.containerColor],
  140. borderColor: colors.content.border[currentType.borderColor],
  141. borderWidth: borders.line,
  142. padding: spaces.spacingXs
  143. } as Mutable<ViewStyle>,
  144. indicator: {
  145. backgroundColor: colors.content.icon[currentType.indicatorColor],
  146. borderRadius: RADIO_INDICATOR_SIZE / 2,
  147. height: RADIO_INDICATOR_SIZE,
  148. width: RADIO_INDICATOR_SIZE
  149. } as Mutable<ViewStyle>,
  150. contentContainer: {
  151. marginLeft: spaces.spacingSm
  152. } as Mutable<ViewStyle>,
  153. titleContainer: {
  154. } as Mutable<ViewStyle>,
  155. title: {
  156. } as Mutable<TextStyle>,
  157. subTitle: {
  158. } as Mutable<TextStyle>,
  159. loading: {
  160. } as Mutable<ViewStyle>,
  161. overlay: {
  162. borderRadius: radiuses.actions
  163. } as Mutable<ViewStyle>,
  164. optionalText: {
  165. marginLeft: inlineSpaces.subTitle
  166. } as Mutable<TextStyle>
  167. };
  168. if(styleType === "neutral") {
  169. styles.indicatorContainer.borderColor = colors.content.border.default;
  170. }
  171. if (isLoading) {
  172. if (displayBehaviourWhileLoading === "disabled") {
  173. styles.indicatorContainer.borderColor = colors.system.state.overlay.disabled[styleType];
  174. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
  175. styles.overlay.display = "flex";
  176. }
  177. }
  178. if (isFlip) {
  179. styles.contentContainer.marginRight = spaces.spacingSm;
  180. styles.titleContainer.justifyContent = "flex-end";
  181. styles.contentContainer.marginLeft = 0;
  182. styles.subTitle.textAlign = "right";
  183. styles.title.textAlign = "right";
  184. }
  185. if (spreadBehaviour === "baseline") {
  186. styles.container.alignSelf = spreadBehaviour;
  187. styles.container.width = "auto";
  188. } else if (spreadBehaviour === "stretch") {
  189. styles.contentContainer.alignSelf = spreadBehaviour;
  190. styles.container.alignSelf = spreadBehaviour;
  191. styles.container.justifyContent = "center";
  192. styles.contentContainer.flexShrink = 1;
  193. styles.contentContainer.width = "100%";
  194. styles.container.flexShrink = 1;
  195. styles.container.width = "100%";
  196. }
  197. if(isChecked) {
  198. if(styleType === "neutral") {
  199. styles.indicatorContainer.backgroundColor = colors.content.container.selected;
  200. styles.indicatorContainer.borderColor = colors.content.border.emphasized;
  201. }
  202. }
  203. if (isDisabled) {
  204. if(styleType === "neutral" && isChecked) {
  205. styles.indicatorContainer.backgroundColor = colors.system.state.border.disabled.primary;
  206. styles.indicatorContainer.borderColor = colors.system.state.border.disabled.primary;
  207. } else {
  208. styles.indicatorContainer.borderColor = colors.system.state.border.disabled[styleType];
  209. }
  210. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
  211. styles.overlay.display = "flex";
  212. }
  213. return styles;
  214. };
  215. export default stylesheet;