stylesheet.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import {
  2. type ViewStyle,
  3. type TextStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type SelectBoxDynamicStyleType,
  8. type SelectBoxTypes,
  9. type SelectBoxType
  10. } from "./type";
  11. import type {
  12. Mutable
  13. } from "../../types";
  14. export const TEXT_INPUT_TYPE_STYLES: Record<
  15. SelectBoxType,
  16. SelectBoxTypes
  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 getSelectBoxType = ({
  86. type
  87. }: {
  88. type: SelectBoxType;
  89. }) => {
  90. const currentType = TEXT_INPUT_TYPE_STYLES[type];
  91. return currentType;
  92. };
  93. const stylesheet = StyleSheet.create({
  94. cleanButton: {
  95. justifyContent: "center",
  96. alignItems: "center",
  97. alignSelf: "center",
  98. zIndex: 99
  99. },
  100. icon: {
  101. justifyContent: "center",
  102. alignContent: "center",
  103. alignItems: "center",
  104. zIndex: 99
  105. },
  106. rightIcon: {
  107. justifyContent: "center",
  108. alignItems: "center",
  109. alignSelf: "center",
  110. zIndex: 99
  111. },
  112. container: {
  113. flexDirection: "column",
  114. boxSizing: "border-box"
  115. },
  116. contentContainer: {
  117. boxSizing: "border-box",
  118. flexDirection: "row",
  119. borderStyle: "solid",
  120. alignItems: "center",
  121. position: "relative",
  122. minWidth: 200
  123. },
  124. titleContainer: {
  125. flexDirection: "row",
  126. alignItems: "center"
  127. },
  128. hintText: {
  129. flexDirection: "row",
  130. alignItems: "center"
  131. },
  132. overlay: {
  133. position: "absolute",
  134. display: "none",
  135. zIndex: 98,
  136. bottom: 0,
  137. right: 0,
  138. left: 0,
  139. top: 0
  140. },
  141. content: {
  142. width: "100%",
  143. flex: 1,
  144. flexShrink: 1
  145. },
  146. contentText: {
  147. minHeight: 20
  148. },
  149. hintTextIcon: {
  150. },
  151. required: {
  152. },
  153. subTitle: {
  154. },
  155. title: {
  156. }
  157. });
  158. export const useStyles = ({
  159. CustomPrefixComponent,
  160. spreadBehaviour,
  161. inlineSpaces,
  162. currentType,
  163. isDisabled,
  164. isActive,
  165. radiuses,
  166. borders,
  167. colors,
  168. spaces,
  169. type
  170. }: SelectBoxDynamicStyleType) => {
  171. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  172. const styles = {
  173. contentContainer: {
  174. backgroundColor: colors.content.container[currentType.containerColor],
  175. borderColor: colors.content.container[currentType.containerColor],
  176. paddingBottom: spaces.spacingMd,
  177. paddingRight: spaces.spacingMd,
  178. borderRadius: radiuses.actions,
  179. paddingLeft: spaces.spacingMd,
  180. paddingTop: spaces.spacingMd,
  181. borderWidth: borders.line
  182. } as Mutable<ViewStyle>,
  183. required: {
  184. marginRight: inlineSpaces.required
  185. } as Mutable<ViewStyle>,
  186. overlay: {
  187. borderRadius: radiuses.actions - 1
  188. } as Mutable<ViewStyle>,
  189. subTitle: {
  190. marginLeft: inlineSpaces.subTitle
  191. } as Mutable<TextStyle>,
  192. titleContainer: {
  193. marginBottom: spaces.spacingSm
  194. } as Mutable<ViewStyle>,
  195. icon: {
  196. marginRight: spaces.spacingSm
  197. } as Mutable<ViewStyle>,
  198. hintTextIcon: {
  199. marginRight: spaces.spacingXs
  200. } as Mutable<ViewStyle>,
  201. cleanButton: {
  202. marginLeft: spaces.spacingSm
  203. } as Mutable<ViewStyle>,
  204. rightIcon: {
  205. marginLeft: spaces.spacingSm
  206. } as Mutable<ViewStyle>,
  207. hintText: {
  208. marginTop: spaces.spacingSm
  209. } as Mutable<TextStyle>,
  210. container: {
  211. alignSelf: "auto"
  212. } as Mutable<ViewStyle>,
  213. content: {
  214. } as Mutable<ViewStyle>,
  215. contentText: {
  216. } as Mutable<TextStyle>,
  217. title: {
  218. } as Mutable<TextStyle>
  219. };
  220. if(isDisabled) {
  221. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  222. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  223. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  224. }
  225. if (spreadBehaviour === "baseline") {
  226. styles.container.alignSelf = spreadBehaviour;
  227. styles.container.width = "auto";
  228. }
  229. if (spreadBehaviour === "stretch") {
  230. styles.container.alignSelf = spreadBehaviour;
  231. styles.container.justifyContent = "center";
  232. styles.container.flexShrink = 1;
  233. styles.container.width = "100%";
  234. }
  235. if(isActive) {
  236. styles.contentContainer.borderColor = colors.content.border.emphasized;
  237. }
  238. if(CustomPrefixComponent) {
  239. styles.content.marginLeft = spaces.spacingSm;
  240. }
  241. return styles;
  242. };
  243. export default stylesheet;