stylesheet.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. 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 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. 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. zIndex: 98,
  135. bottom: 0,
  136. right: 0,
  137. left: 0,
  138. top: 0
  139. },
  140. content: {
  141. width: "100%",
  142. flex: 1,
  143. flexShrink: 1
  144. },
  145. contentText: {
  146. minHeight: 20
  147. },
  148. hintTextIcon: {
  149. },
  150. required: {
  151. },
  152. subTitle: {
  153. },
  154. title: {
  155. }
  156. });
  157. export const useStyles = ({
  158. spreadBehaviour,
  159. inlineSpaces,
  160. currentType,
  161. isDisabled,
  162. isActive,
  163. radiuses,
  164. borders,
  165. colors,
  166. spaces,
  167. type
  168. }: DateTimePickerDynamicStyleType) => {
  169. const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;
  170. const styles = {
  171. contentContainer: {
  172. backgroundColor: colors.content.container[currentType.containerColor],
  173. borderColor: colors.content.container[currentType.containerColor],
  174. paddingBottom: spaces.spacingMd,
  175. paddingRight: spaces.spacingMd,
  176. borderRadius: radiuses.actions,
  177. paddingLeft: spaces.spacingMd,
  178. paddingTop: spaces.spacingMd,
  179. borderWidth: borders.line
  180. } as Mutable<ViewStyle>,
  181. required: {
  182. marginRight: inlineSpaces.required
  183. } as Mutable<ViewStyle>,
  184. overlay: {
  185. borderRadius: radiuses.actions - 1
  186. } as Mutable<ViewStyle>,
  187. subTitle: {
  188. marginLeft: inlineSpaces.subTitle
  189. } as Mutable<TextStyle>,
  190. titleContainer: {
  191. marginBottom: spaces.spacingSm
  192. } as Mutable<ViewStyle>,
  193. icon: {
  194. marginRight: spaces.spacingSm
  195. } as Mutable<ViewStyle>,
  196. hintTextIcon: {
  197. marginRight: spaces.spacingXs
  198. } as Mutable<ViewStyle>,
  199. cleanButton: {
  200. marginLeft: spaces.spacingSm
  201. } as Mutable<ViewStyle>,
  202. rightIcon: {
  203. marginLeft: spaces.spacingSm
  204. } as Mutable<ViewStyle>,
  205. hintText: {
  206. marginTop: spaces.spacingSm
  207. } as Mutable<TextStyle>,
  208. container: {
  209. alignSelf: "auto"
  210. } as Mutable<ViewStyle>,
  211. content: {
  212. } as Mutable<ViewStyle>,
  213. contentText: {
  214. } as Mutable<TextStyle>,
  215. title: {
  216. } as Mutable<TextStyle>
  217. };
  218. if(isDisabled) {
  219. const disableStyleType = styleType === "default" ? "neutral" : styleType;
  220. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
  221. styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
  222. }
  223. if (spreadBehaviour === "baseline") {
  224. styles.container.alignSelf = spreadBehaviour;
  225. styles.container.width = "auto";
  226. }
  227. if (spreadBehaviour === "stretch") {
  228. styles.container.alignSelf = spreadBehaviour;
  229. styles.container.justifyContent = "center";
  230. styles.container.flexShrink = 1;
  231. styles.container.width = "100%";
  232. }
  233. if(isActive) {
  234. styles.contentContainer.borderColor = colors.content.border.emphasized;
  235. }
  236. return styles;
  237. };
  238. export default stylesheet;