stylesheet.ts 7.8 KB

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