stylesheet.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. danger: {
  30. placeholderColor: "dangerLow",
  31. hintTextIconColor: "danger",
  32. focusBorderColor: "danger",
  33. containerColor: "danger",
  34. hintTextColor: "danger",
  35. borderColor: "danger",
  36. titleColor: "danger",
  37. inputColor: "danger",
  38. iconColor: "danger"
  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. info: {
  63. placeholderColor: "infoLow",
  64. hintTextIconColor: "info",
  65. focusBorderColor: "info",
  66. containerColor: "info",
  67. hintTextColor: "info",
  68. borderColor: "info",
  69. titleColor: "info",
  70. inputColor: "info",
  71. iconColor: "info"
  72. },
  73. question: {
  74. focusBorderColor: "emphasized",
  75. borderColor: "emphasized",
  76. hintTextIconColor: "mid",
  77. placeholderColor: "low",
  78. containerColor: "mid",
  79. hintTextColor: "mid",
  80. titleColor: "mid",
  81. inputColor: "mid",
  82. iconColor: "mid"
  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. container: {
  95. flexDirection: "column",
  96. boxSizing: "border-box",
  97. display: "flex"
  98. },
  99. content: {
  100. alignItems: "flex-start",
  101. boxSizing: "border-box",
  102. flexDirection: "row",
  103. borderStyle: "solid",
  104. position: "relative",
  105. display: "flex",
  106. minWidth: 250
  107. },
  108. input: {
  109. backgroundColor: "transparent",
  110. borderColor: "transparent",
  111. textAlignVertical: "top",
  112. paddingBottom: 0,
  113. paddingRight: 0,
  114. paddingLeft: 0,
  115. borderWidth: 0,
  116. paddingTop: 0,
  117. minHeight: 55,
  118. zIndex: 99
  119. },
  120. cleanButton: {
  121. justifyContent: "center",
  122. alignSelf: "flex-start",
  123. alignItems: "center",
  124. display: "flex",
  125. zIndex: 99
  126. },
  127. hideTextIconContainer: {
  128. justifyContent: "center",
  129. alignItems: "center",
  130. alignSelf: "center",
  131. display: "flex",
  132. zIndex: 99,
  133. height: 18
  134. },
  135. titleContainer: {
  136. flexDirection: "row",
  137. alignItems: "center"
  138. },
  139. title: {
  140. },
  141. icon: {
  142. justifyContent: "center",
  143. alignContent: "center",
  144. alignItems: "center",
  145. display: "flex",
  146. zIndex: 99
  147. },
  148. required: {
  149. },
  150. hintTextIcon: {
  151. },
  152. hintText: {
  153. flexDirection: "row",
  154. alignItems: "center",
  155. display: "flex"
  156. },
  157. subTitle: {
  158. },
  159. overlay: {
  160. position: "absolute",
  161. zIndex: 98,
  162. bottom: 0,
  163. right: 0,
  164. left: 0,
  165. top: 0
  166. },
  167. rightIcon: {
  168. justifyContent: "center",
  169. alignItems: "center",
  170. alignSelf: "center",
  171. display: "flex",
  172. zIndex: 99
  173. },
  174. lengthLimiterContainer: {
  175. justifyContent: "flex-end",
  176. flexDirection: "row"
  177. },
  178. inputContainer: {
  179. flexDirection: "column",
  180. flex: 1
  181. }
  182. });
  183. export const useStyles = ({
  184. spreadBehaviour,
  185. inlineSpaces,
  186. currentType,
  187. typography,
  188. isDisabled,
  189. isFocused,
  190. maxHeight,
  191. radiuses,
  192. borders,
  193. colors,
  194. spaces,
  195. type
  196. }: TextAreaInputDynamicStyleType) => {
  197. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  198. const styles = {
  199. container: {
  200. } as Mutable<ViewStyle>,
  201. content: {
  202. backgroundColor: colors.content.container[currentType.containerColor],
  203. borderColor: colors.content.container[currentType.containerColor],
  204. paddingBottom: spaces.spacingMd,
  205. paddingRight: spaces.spacingMd,
  206. borderRadius: radiuses.actions,
  207. paddingLeft: spaces.spacingMd,
  208. paddingTop: spaces.spacingMd,
  209. borderWidth: borders.line
  210. } as Mutable<ViewStyle>,
  211. input: {
  212. ...typography.labelLargeSize,
  213. color: colors.content.text[currentType.inputColor],
  214. maxHeight: maxHeight
  215. } as Mutable<TextStyle>,
  216. cleanButton: {
  217. marginLeft: spaces.spacingSm
  218. } as Mutable<ViewStyle>,
  219. hintTextIconContainer: {
  220. marginLeft: spaces.spacingSm
  221. } as Mutable<ViewStyle>,
  222. titleContainer: {
  223. marginBottom: spaces.spacingSm
  224. } as Mutable<ViewStyle>,
  225. title: {
  226. } as Mutable<TextStyle>,
  227. icon: {
  228. marginRight: spaces.spacingSm
  229. } as Mutable<ViewStyle>,
  230. required: {
  231. marginRight: inlineSpaces.required
  232. } as Mutable<ViewStyle>,
  233. hintTextIcon: {
  234. marginRight: spaces.spacingXs
  235. } as Mutable<ViewStyle>,
  236. hintText: {
  237. marginTop: spaces.spacingSm
  238. } as Mutable<TextStyle>,
  239. subTitle: {
  240. marginLeft: inlineSpaces.subTitle
  241. } as Mutable<TextStyle>,
  242. overlay: {
  243. borderRadius: radiuses.actions - 1
  244. } as Mutable<ViewStyle>,
  245. rightIcon: {
  246. marginLeft: spaces.spacingSm
  247. } as Mutable<ViewStyle>,
  248. lengthLimiterContainer: {
  249. } as Mutable<ViewStyle>,
  250. inputContainer: {
  251. } as Mutable<ViewStyle>
  252. };
  253. if(isDisabled) {
  254. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  255. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  256. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  257. styles.input.color = colors.content.text.disabled;
  258. }
  259. if (spreadBehaviour === "baseline") {
  260. styles.container.alignSelf = spreadBehaviour;
  261. styles.container.width = "auto";
  262. }
  263. if (spreadBehaviour === "stretch") {
  264. styles.container.alignSelf = spreadBehaviour;
  265. styles.container.justifyContent = "center";
  266. styles.container.flexShrink = 1;
  267. styles.container.width = "100%";
  268. }
  269. if(isFocused && !isDisabled) {
  270. if(type === "question" || type === "default") {
  271. styles.content.borderColor = colors.content.border.emphasized;
  272. } else {
  273. styles.content.borderColor = colors.content.border[type];
  274. }
  275. }
  276. return styles;
  277. };
  278. export default stylesheet;