stylesheet.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import {
  2. type ViewStyle,
  3. type TextStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type SelectBoxDynamicStyleType,
  8. type SelectBoxTypes,
  9. type SelectBoxType
  10. } from "./type";
  11. import type {
  12. Mutable
  13. } from "../../types";
  14. export const TEXT_INPUT_TYPE_STYLES: Record<
  15. SelectBoxType,
  16. SelectBoxTypes
  17. > = {
  18. default: {
  19. focusBorderColor: "emphasized",
  20. borderColor: "emphasized",
  21. hintTextIconColor: "mid",
  22. placeholderColor: "low",
  23. containerColor: "mid",
  24. hintTextColor: "mid",
  25. titleColor: "high",
  26. inputColor: "mid",
  27. iconColor: "mid"
  28. },
  29. question: {
  30. focusBorderColor: "emphasized",
  31. borderColor: "emphasized",
  32. hintTextIconColor: "mid",
  33. placeholderColor: "low",
  34. containerColor: "mid",
  35. hintTextColor: "mid",
  36. titleColor: "mid",
  37. inputColor: "mid",
  38. iconColor: "mid"
  39. },
  40. success: {
  41. placeholderColor: "successLow",
  42. hintTextIconColor: "success",
  43. focusBorderColor: "success",
  44. containerColor: "success",
  45. hintTextColor: "success",
  46. borderColor: "success",
  47. titleColor: "success",
  48. inputColor: "success",
  49. iconColor: "success"
  50. },
  51. warning: {
  52. placeholderColor: "warningLow",
  53. hintTextIconColor: "warning",
  54. focusBorderColor: "warning",
  55. containerColor: "warning",
  56. hintTextColor: "warning",
  57. borderColor: "warning",
  58. titleColor: "warning",
  59. inputColor: "warning",
  60. iconColor: "warning"
  61. },
  62. danger: {
  63. placeholderColor: "dangerLow",
  64. hintTextIconColor: "danger",
  65. focusBorderColor: "danger",
  66. containerColor: "danger",
  67. hintTextColor: "danger",
  68. borderColor: "danger",
  69. titleColor: "danger",
  70. inputColor: "danger",
  71. iconColor: "danger"
  72. },
  73. info: {
  74. placeholderColor: "infoLow",
  75. hintTextIconColor: "info",
  76. focusBorderColor: "info",
  77. containerColor: "info",
  78. hintTextColor: "info",
  79. borderColor: "info",
  80. titleColor: "info",
  81. inputColor: "info",
  82. iconColor: "info"
  83. }
  84. };
  85. export const getSelectBoxType = ({
  86. type
  87. }: {
  88. type: SelectBoxType;
  89. }) => {
  90. const currentType = TEXT_INPUT_TYPE_STYLES[type];
  91. return currentType;
  92. };
  93. const stylesheet = StyleSheet.create({
  94. cleanButton: {
  95. justifyContent: "center",
  96. alignItems: "center",
  97. alignSelf: "center",
  98. zIndex: 99
  99. },
  100. icon: {
  101. justifyContent: "center",
  102. alignContent: "center",
  103. alignItems: "center",
  104. zIndex: 99
  105. },
  106. rightIcon: {
  107. justifyContent: "center",
  108. alignItems: "center",
  109. alignSelf: "center",
  110. zIndex: 99
  111. },
  112. container: {
  113. flexDirection: "column",
  114. boxSizing: "border-box"
  115. },
  116. contentContainer: {
  117. boxSizing: "border-box",
  118. flexDirection: "row",
  119. borderStyle: "solid",
  120. alignItems: "center",
  121. position: "relative",
  122. minWidth: 200
  123. },
  124. titleContainer: {
  125. flexDirection: "row",
  126. alignItems: "center"
  127. },
  128. hintText: {
  129. flexDirection: "row",
  130. alignItems: "center"
  131. },
  132. overlay: {
  133. position: "absolute",
  134. display: "none",
  135. zIndex: 98,
  136. bottom: 0,
  137. right: 0,
  138. left: 0,
  139. top: 0
  140. },
  141. content: {
  142. width: "100%",
  143. flex: 1,
  144. flexShrink: 1
  145. },
  146. contentText: {
  147. minHeight: 20
  148. },
  149. hintTextIcon: {
  150. },
  151. required: {
  152. },
  153. subTitle: {
  154. },
  155. title: {
  156. }
  157. });
  158. export const useStyles = ({
  159. spreadBehaviour,
  160. inlineSpaces,
  161. currentType,
  162. isDisabled,
  163. isActive,
  164. radiuses,
  165. borders,
  166. colors,
  167. spaces,
  168. type
  169. }: SelectBoxDynamicStyleType) => {
  170. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  171. const styles = {
  172. contentContainer: {
  173. backgroundColor: colors.content.container[currentType.containerColor],
  174. borderColor: colors.content.container[currentType.containerColor],
  175. paddingBottom: spaces.spacingMd,
  176. paddingRight: spaces.spacingMd,
  177. borderRadius: radiuses.actions,
  178. paddingLeft: spaces.spacingMd,
  179. paddingTop: spaces.spacingMd,
  180. borderWidth: borders.line
  181. } as Mutable<ViewStyle>,
  182. required: {
  183. marginRight: inlineSpaces.required
  184. } as Mutable<ViewStyle>,
  185. overlay: {
  186. borderRadius: radiuses.actions - 1
  187. } as Mutable<ViewStyle>,
  188. subTitle: {
  189. marginLeft: inlineSpaces.subTitle
  190. } as Mutable<TextStyle>,
  191. titleContainer: {
  192. marginBottom: spaces.spacingSm
  193. } as Mutable<ViewStyle>,
  194. icon: {
  195. marginRight: spaces.spacingSm
  196. } as Mutable<ViewStyle>,
  197. hintTextIcon: {
  198. marginRight: spaces.spacingXs
  199. } as Mutable<ViewStyle>,
  200. cleanButton: {
  201. marginLeft: spaces.spacingSm
  202. } as Mutable<ViewStyle>,
  203. rightIcon: {
  204. marginLeft: spaces.spacingSm
  205. } as Mutable<ViewStyle>,
  206. hintText: {
  207. marginTop: spaces.spacingSm
  208. } as Mutable<TextStyle>,
  209. container: {
  210. alignSelf: "auto"
  211. } as Mutable<ViewStyle>,
  212. content: {
  213. } as Mutable<ViewStyle>,
  214. contentText: {
  215. } as Mutable<TextStyle>,
  216. title: {
  217. } as Mutable<TextStyle>
  218. };
  219. if(isDisabled) {
  220. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  221. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  222. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  223. }
  224. if (spreadBehaviour === "baseline") {
  225. styles.container.alignSelf = spreadBehaviour;
  226. styles.container.width = "auto";
  227. }
  228. if (spreadBehaviour === "stretch") {
  229. styles.container.alignSelf = spreadBehaviour;
  230. styles.container.justifyContent = "center";
  231. styles.container.flexShrink = 1;
  232. styles.container.width = "100%";
  233. }
  234. if(isActive) {
  235. styles.contentContainer.borderColor = colors.content.border.emphasized;
  236. }
  237. return styles;
  238. };
  239. export default stylesheet;