stylesheet.ts 6.2 KB

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