stylesheet.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. alignSelf: "auto"
  201. } as Mutable<ViewStyle>,
  202. content: {
  203. backgroundColor: colors.content.container[currentType.containerColor],
  204. borderColor: colors.content.container[currentType.containerColor],
  205. paddingBottom: spaces.spacingMd,
  206. paddingRight: spaces.spacingMd,
  207. paddingLeft: spaces.spacingMd,
  208. paddingTop: spaces.spacingMd,
  209. borderRadius: radiuses.form,
  210. borderWidth: borders.line
  211. } as Mutable<ViewStyle>,
  212. input: {
  213. ...typography.labelLargeSize,
  214. color: colors.content.text[currentType.inputColor],
  215. maxHeight: maxHeight
  216. } as Mutable<TextStyle>,
  217. cleanButton: {
  218. marginLeft: spaces.spacingSm
  219. } as Mutable<ViewStyle>,
  220. hintTextIconContainer: {
  221. marginLeft: spaces.spacingSm
  222. } as Mutable<ViewStyle>,
  223. titleContainer: {
  224. marginBottom: spaces.spacingSm
  225. } as Mutable<ViewStyle>,
  226. title: {
  227. } as Mutable<TextStyle>,
  228. icon: {
  229. marginRight: spaces.spacingSm
  230. } as Mutable<ViewStyle>,
  231. required: {
  232. marginRight: inlineSpaces.required
  233. } as Mutable<ViewStyle>,
  234. hintTextIcon: {
  235. marginRight: spaces.spacingXs
  236. } as Mutable<ViewStyle>,
  237. hintText: {
  238. marginTop: spaces.spacingSm
  239. } as Mutable<TextStyle>,
  240. subTitle: {
  241. marginLeft: inlineSpaces.subTitle
  242. } as Mutable<TextStyle>,
  243. overlay: {
  244. borderRadius: radiuses.form - 1
  245. } as Mutable<ViewStyle>,
  246. rightIcon: {
  247. marginLeft: spaces.spacingSm
  248. } as Mutable<ViewStyle>,
  249. lengthLimiterContainer: {
  250. } as Mutable<ViewStyle>,
  251. inputContainer: {
  252. } as Mutable<ViewStyle>
  253. };
  254. if(isDisabled) {
  255. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  256. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  257. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  258. styles.input.color = colors.content.text.disabled;
  259. }
  260. if (spreadBehaviour === "baseline") {
  261. styles.container.alignSelf = spreadBehaviour;
  262. styles.container.width = "auto";
  263. }
  264. if (spreadBehaviour === "stretch") {
  265. styles.container.alignSelf = spreadBehaviour;
  266. styles.container.justifyContent = "center";
  267. styles.container.flexShrink = 1;
  268. styles.container.width = "100%";
  269. }
  270. if(isFocused && !isDisabled) {
  271. if(type === "question" || type === "default") {
  272. styles.content.borderColor = colors.content.border.emphasized;
  273. } else {
  274. styles.content.borderColor = colors.content.border[type];
  275. }
  276. }
  277. return styles;
  278. };
  279. export default stylesheet;