stylesheet.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import {
  2. type ViewStyle,
  3. type TextStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type NumericInputDynamicStyleType,
  8. type NumericInputTypes,
  9. type NumericInputType
  10. } from "./type";
  11. import type {
  12. Mutable
  13. } from "../../types";
  14. export const NUMERIC_INPUT_TYPE_STYLES: Record<
  15. NumericInputType,
  16. NumericInputTypes
  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 getNumericInputType = ({
  86. type
  87. }: {
  88. type: NumericInputType;
  89. }) => {
  90. const currentType = NUMERIC_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. boxSizing: "border-box",
  101. flexDirection: "row",
  102. borderStyle: "solid",
  103. alignItems: "center",
  104. position: "relative",
  105. display: "flex"
  106. },
  107. input: {
  108. backgroundColor: "transparent",
  109. textAlignVertical: "center",
  110. borderColor: "transparent",
  111. paddingBottom: 0,
  112. paddingRight: 0,
  113. paddingLeft: 0,
  114. borderWidth: 0,
  115. paddingTop: 0,
  116. minHeight: 20,
  117. zIndex: 99,
  118. flex: 1
  119. },
  120. cleanButton: {
  121. justifyContent: "center",
  122. alignItems: "center",
  123. alignSelf: "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. });
  175. export const useStyles = ({
  176. spreadBehaviour,
  177. inlineSpaces,
  178. currentType,
  179. typography,
  180. isDisabled,
  181. isFocused,
  182. radiuses,
  183. borders,
  184. colors,
  185. spaces,
  186. type
  187. }: NumericInputDynamicStyleType) => {
  188. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  189. const styles = {
  190. container: {
  191. } as Mutable<ViewStyle>,
  192. content: {
  193. minWidth: (typography.labelLargeSize.fontSize * 2) + (spaces.spacingMd * 2),
  194. backgroundColor: colors.content.container[currentType.containerColor],
  195. borderColor: colors.content.container[currentType.containerColor],
  196. paddingBottom: spaces.spacingMd,
  197. paddingRight: spaces.spacingMd,
  198. borderRadius: radiuses.actions,
  199. paddingLeft: spaces.spacingMd,
  200. paddingTop: spaces.spacingMd,
  201. borderWidth: borders.line
  202. } as Mutable<ViewStyle>,
  203. input: {
  204. ...typography.labelLargeSize,
  205. color: colors.content.text[currentType.inputColor]
  206. } as Mutable<TextStyle>,
  207. cleanButton: {
  208. marginLeft: spaces.spacingSm
  209. } as Mutable<ViewStyle>,
  210. hideTextIconContainer: {
  211. marginLeft: spaces.spacingSm
  212. } as Mutable<ViewStyle>,
  213. titleContainer: {
  214. marginBottom: spaces.spacingSm
  215. } as Mutable<ViewStyle>,
  216. title: {
  217. } as Mutable<TextStyle>,
  218. icon: {
  219. marginRight: spaces.spacingSm
  220. } as Mutable<ViewStyle>,
  221. required: {
  222. marginRight: inlineSpaces.required
  223. } as Mutable<ViewStyle>,
  224. hintTextIcon: {
  225. marginRight: spaces.spacingXs
  226. } as Mutable<ViewStyle>,
  227. hintText: {
  228. marginTop: spaces.spacingSm
  229. } as Mutable<TextStyle>,
  230. subTitle: {
  231. marginLeft: inlineSpaces.subTitle
  232. } as Mutable<TextStyle>,
  233. overlay: {
  234. borderRadius: radiuses.actions - 1
  235. } as Mutable<ViewStyle>,
  236. rightIcon: {
  237. marginLeft: spaces.spacingSm
  238. } as Mutable<ViewStyle>
  239. };
  240. if(isDisabled) {
  241. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  242. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  243. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  244. styles.input.color = colors.content.text.disabled;
  245. }
  246. if (spreadBehaviour === "baseline") {
  247. styles.container.alignSelf = spreadBehaviour;
  248. styles.container.width = "auto";
  249. }
  250. if (spreadBehaviour === "stretch") {
  251. styles.container.alignSelf = spreadBehaviour;
  252. styles.container.justifyContent = "center";
  253. styles.container.flexShrink = 1;
  254. styles.container.width = "100%";
  255. }
  256. if(isFocused && !isDisabled) {
  257. if(type === "question" || type === "default") {
  258. styles.content.borderColor = colors.content.border.emphasized;
  259. } else {
  260. styles.content.borderColor = colors.content.border[type];
  261. }
  262. }
  263. return styles;
  264. };
  265. export default stylesheet;