stylesheet.ts 4.0 KB

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