stylesheet.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import {
  2. type ViewStyle,
  3. type TextStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type TextInputDynamicStyleType,
  8. type TextInputTypes,
  9. type TextInputType
  10. } from "./type";
  11. import type {
  12. Mutable
  13. } from "../../types";
  14. export const TEXT_INPUT_TYPE_STYLES: Record<
  15. TextInputType,
  16. TextInputTypes
  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 getTextInputType = ({
  86. type
  87. }: {
  88. type: TextInputType;
  89. }) => {
  90. const currentType = TEXT_INPUT_TYPE_STYLES[type];
  91. return currentType;
  92. };
  93. const stylesheet = StyleSheet.create({
  94. input: {
  95. backgroundColor: "transparent",
  96. textAlignVertical: "center",
  97. borderColor: "transparent",
  98. paddingBottom: 0,
  99. paddingRight: 0,
  100. paddingLeft: 0,
  101. borderWidth: 0,
  102. paddingTop: 0,
  103. minHeight: 20,
  104. zIndex: 99,
  105. flex: 1
  106. },
  107. hideTextIconContainer: {
  108. justifyContent: "center",
  109. alignItems: "center",
  110. alignSelf: "center",
  111. display: "flex",
  112. zIndex: 99,
  113. height: 18
  114. },
  115. cleanButton: {
  116. justifyContent: "center",
  117. alignItems: "center",
  118. alignSelf: "center",
  119. display: "flex",
  120. zIndex: 99
  121. },
  122. rightIcon: {
  123. justifyContent: "center",
  124. alignItems: "center",
  125. alignSelf: "center",
  126. display: "flex",
  127. zIndex: 99
  128. },
  129. icon: {
  130. justifyContent: "center",
  131. alignContent: "center",
  132. alignItems: "center",
  133. display: "flex",
  134. zIndex: 99
  135. },
  136. content: {
  137. boxSizing: "border-box",
  138. flexDirection: "row",
  139. borderStyle: "solid",
  140. alignItems: "center",
  141. position: "relative",
  142. display: "flex",
  143. minWidth: 250
  144. },
  145. container: {
  146. flexDirection: "column",
  147. boxSizing: "border-box",
  148. alignSelf: "auto",
  149. display: "flex"
  150. },
  151. hintText: {
  152. flexDirection: "row",
  153. alignItems: "center",
  154. display: "flex"
  155. },
  156. titleContainer: {
  157. flexDirection: "row",
  158. alignItems: "center"
  159. },
  160. overlay: {
  161. position: "absolute",
  162. zIndex: 98
  163. },
  164. hintTextIcon: {
  165. },
  166. required: {
  167. },
  168. subTitle: {
  169. },
  170. title: {
  171. }
  172. });
  173. export const useStyles = ({
  174. customBorderColor,
  175. spreadBehaviour,
  176. inlineSpaces,
  177. currentType,
  178. customColor,
  179. isDisabled,
  180. typography,
  181. isFocused,
  182. radiuses,
  183. borders,
  184. colors,
  185. spaces,
  186. type
  187. }: TextInputDynamicStyleType) => {
  188. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  189. const styles = {
  190. content: {
  191. backgroundColor: colors.content.container[currentType.containerColor],
  192. borderColor: colors.content.container[currentType.containerColor],
  193. paddingBottom: spaces.spacingMd,
  194. paddingRight: spaces.spacingMd,
  195. borderRadius: radiuses.actions,
  196. paddingLeft: spaces.spacingMd,
  197. paddingTop: spaces.spacingMd,
  198. borderWidth: borders.line
  199. } as Mutable<ViewStyle>,
  200. input: {
  201. ...typography.labelLargeSize,
  202. color: colors.content.text[currentType.inputColor]
  203. } as Mutable<TextStyle>,
  204. overlay: {
  205. borderRadius: radiuses.actions - 1,
  206. bottom: -borders.line,
  207. right: -borders.line,
  208. left: -borders.line,
  209. top: -borders.line
  210. } as Mutable<ViewStyle>,
  211. required: {
  212. marginRight: inlineSpaces.required
  213. } as Mutable<ViewStyle>,
  214. subTitle: {
  215. marginLeft: inlineSpaces.subTitle
  216. } as Mutable<TextStyle>,
  217. titleContainer: {
  218. marginBottom: spaces.spacingSm
  219. } as Mutable<ViewStyle>,
  220. hintTextIcon: {
  221. marginRight: spaces.spacingXs
  222. } as Mutable<ViewStyle>,
  223. icon: {
  224. marginRight: spaces.spacingSm
  225. } as Mutable<ViewStyle>,
  226. hideTextIconContainer: {
  227. marginLeft: spaces.spacingSm
  228. } as Mutable<ViewStyle>,
  229. cleanButton: {
  230. marginLeft: spaces.spacingSm
  231. } as Mutable<ViewStyle>,
  232. rightIcon: {
  233. marginLeft: spaces.spacingSm
  234. } as Mutable<ViewStyle>,
  235. hintText: {
  236. marginTop: spaces.spacingSm
  237. } as Mutable<TextStyle>,
  238. container: {
  239. } as Mutable<ViewStyle>,
  240. title: {
  241. } as Mutable<TextStyle>
  242. };
  243. if(isDisabled) {
  244. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  245. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  246. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  247. styles.input.color = colors.content.text.disabled;
  248. }
  249. if (spreadBehaviour === "baseline") {
  250. styles.container.alignSelf = spreadBehaviour;
  251. styles.container.width = "auto";
  252. }
  253. if (spreadBehaviour === "stretch") {
  254. styles.container.alignSelf = spreadBehaviour;
  255. styles.container.justifyContent = "center";
  256. styles.container.flexShrink = 1;
  257. styles.container.width = "100%";
  258. }
  259. if(customBorderColor) {
  260. styles.content.borderColor = customBorderColor;
  261. }
  262. if(isFocused && !isDisabled) {
  263. if(type === "question" || type === "default") {
  264. styles.content.borderColor = colors.content.border.emphasized;
  265. } else {
  266. styles.content.borderColor = colors.content.border[type];
  267. }
  268. }
  269. if(customColor) {
  270. styles.content.backgroundColor = customColor;
  271. }
  272. return styles;
  273. };
  274. export default stylesheet;