stylesheet.ts 6.6 KB

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