stylesheet.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. export const SNACK_BAR_TYPE_STYLES: Record<
  16. SnackBarType,
  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 getSnackBarType = ({
  69. type
  70. }: SnackBarTypeConstantType): SnackBarTypes => {
  71. const currentType = SNACK_BAR_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. flex: 1,
  80. flexShrink: 1
  81. },
  82. iconContainer: {
  83. justifyContent: "center",
  84. alignItems: "center"
  85. },
  86. container: {
  87. position: "absolute",
  88. alignSelf: "center",
  89. zIndex: 99998
  90. },
  91. containerObject: {
  92. flexDirection: "row",
  93. alignItems: "center"
  94. },
  95. title: {
  96. textAlign: "left"
  97. },
  98. subTitle: {
  99. textAlign: "left"
  100. }
  101. });
  102. export const useStyles = ({
  103. isInlineSafeArea,
  104. currentType,
  105. isFullWidth,
  106. safeAreaTop,
  107. radiuses,
  108. colors,
  109. spaces
  110. }: SnackBarDynamicStyleType) => {
  111. const styles = {
  112. container: {
  113. backgroundColor: colors.content.container[currentType.containerColor],
  114. top: safeAreaTop + spaces.spacingSm,
  115. borderRadius: radiuses.lg
  116. } as Mutable<ViewStyle>,
  117. containerObject: {
  118. paddingHorizontal: spaces.spacingLg,
  119. paddingVertical: spaces.spacingMd
  120. } as Mutable<ViewStyle>,
  121. action: {
  122. paddingBottom: spaces.spacingSm,
  123. paddingRight: spaces.spacingSm,
  124. paddingLeft: spaces.spacingMd,
  125. paddingTop: spaces.spacingSm,
  126. marginLeft: spaces.spacingMd
  127. } as Mutable<ViewStyle>,
  128. iconContainer: {
  129. paddingRight: spaces.spacingSm,
  130. marginRight: spaces.spacingSm
  131. } as Mutable<ViewStyle>,
  132. subTitle: {
  133. marginTop: spaces.spacingXs
  134. } as Mutable<TextStyle>,
  135. contentContainer: {
  136. } as Mutable<ViewStyle>,
  137. title: {
  138. } as Mutable<TextStyle>
  139. };
  140. if(isFullWidth) {
  141. styles.container.borderRadius = 0;
  142. }
  143. if(isInlineSafeArea) {
  144. styles.container.paddingTop = safeAreaTop;
  145. styles.container.top = 0;
  146. }
  147. return styles;
  148. };
  149. export default stylesheet;