stylesheet.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import {
  2. type TextStyle,
  3. type ViewStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import type {
  7. ToastDynamicStyleType,
  8. ToastTypeConstantType,
  9. ToastTypes,
  10. ToastType
  11. } from "./type";
  12. import type {
  13. Mutable
  14. } from "../../types";
  15. export const TOAST_TYPE_STYLES: Record<
  16. ToastType,
  17. {
  18. containerColor: keyof NCoreUIKit.ContainerContentColors;
  19. subTitleColor: keyof NCoreUIKit.TextContentColors;
  20. actionColor: keyof NCoreUIKit.TextContentColors;
  21. titleColor: keyof NCoreUIKit.TextContentColors;
  22. iconColor: keyof NCoreUIKit.IconContentColors;
  23. }
  24. > = {
  25. success: {
  26. subTitleColor: "successLow",
  27. containerColor: "success",
  28. actionColor: "success",
  29. titleColor: "success",
  30. iconColor: "success"
  31. },
  32. warning: {
  33. subTitleColor: "warningLow",
  34. containerColor: "warning",
  35. actionColor: "warning",
  36. titleColor: "warning",
  37. iconColor: "warning"
  38. },
  39. danger: {
  40. subTitleColor: "dangerLow",
  41. containerColor: "danger",
  42. actionColor: "danger",
  43. titleColor: "danger",
  44. iconColor: "danger"
  45. },
  46. info: {
  47. subTitleColor: "infoLow",
  48. containerColor: "info",
  49. actionColor: "info",
  50. titleColor: "info",
  51. iconColor: "info"
  52. },
  53. primary: {
  54. actionColor: "onPrimary",
  55. iconColor: "emphasized",
  56. containerColor: "mid",
  57. subTitleColor: "low",
  58. titleColor: "mid"
  59. },
  60. neutral: {
  61. containerColor: "mid",
  62. subTitleColor: "low",
  63. actionColor: "mid",
  64. titleColor: "mid",
  65. iconColor: "mid"
  66. }
  67. };
  68. export const getToastType = ({
  69. type
  70. }: ToastTypeConstantType): ToastTypes => {
  71. const currentType = TOAST_TYPE_STYLES[type];
  72. return currentType;
  73. };
  74. const stylesheet = StyleSheet.create({
  75. contentContainer: {
  76. justifyContent: "center",
  77. alignItems: "flex-start",
  78. flexDirection: "column",
  79. flexShrink: 1
  80. },
  81. iconContainer: {
  82. justifyContent: "center",
  83. alignItems: "center"
  84. },
  85. container: {
  86. position: "absolute",
  87. alignSelf: "center",
  88. zIndex: 99998
  89. },
  90. containerObject: {
  91. flexDirection: "row",
  92. alignItems: "center"
  93. },
  94. title: {
  95. textAlign: "left"
  96. },
  97. subTitle: {
  98. textAlign: "left"
  99. }
  100. });
  101. export const useStyles = ({
  102. safeAreaBottom,
  103. currentType,
  104. radiuses,
  105. subTitle,
  106. colors,
  107. spaces
  108. }: ToastDynamicStyleType) => {
  109. const styles = {
  110. container: {
  111. backgroundColor: colors.content.container[currentType.containerColor],
  112. bottom: safeAreaBottom + 100,
  113. borderRadius: radiuses.full
  114. } as Mutable<ViewStyle>,
  115. containerObject: {
  116. paddingHorizontal: spaces.spacingLg,
  117. paddingVertical: spaces.spacingMd
  118. } as Mutable<ViewStyle>,
  119. action: {
  120. paddingBottom: spaces.spacingSm,
  121. paddingRight: spaces.spacingSm,
  122. paddingLeft: spaces.spacingMd,
  123. paddingTop: spaces.spacingSm,
  124. marginLeft: spaces.spacingMd
  125. } as Mutable<ViewStyle>,
  126. iconContainer: {
  127. paddingRight: spaces.spacingSm,
  128. marginRight: spaces.spacingSm
  129. } as Mutable<ViewStyle>,
  130. subTitle: {
  131. marginTop: spaces.spacingXs
  132. } as Mutable<TextStyle>,
  133. contentContainer: {
  134. } as Mutable<ViewStyle>,
  135. title: {
  136. } as Mutable<TextStyle>
  137. };
  138. if(subTitle) {
  139. styles.container.borderRadius = radiuses.lg;
  140. }
  141. return styles;
  142. };
  143. export default stylesheet;