stylesheet.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {
  2. type TextStyle,
  3. type ViewStyle,
  4. StyleSheet
  5. } from "react-native";
  6. import {
  7. type NotificationIndicatorDynamicStyleType,
  8. type NotificationIndicatorTypeConstantType,
  9. type NotificationIndicatorTypes,
  10. type NotificationIndicatorType
  11. } from "./type";
  12. import type {
  13. Mutable
  14. } from "../../types";
  15. export const NOTIFICATION_INDICATOR_TYPE_STYLES: Record<
  16. NotificationIndicatorType,
  17. {
  18. containerColor: keyof NCoreUIKit.ContainerContentColors;
  19. subTitleColor: keyof NCoreUIKit.TextContentColors;
  20. titleColor: keyof NCoreUIKit.TextContentColors;
  21. }
  22. > = {
  23. primary: {
  24. containerColor: "emphasized",
  25. titleColor: "emphasized",
  26. subTitleColor: "low"
  27. },
  28. danger: {
  29. subTitleColor: "dangerLow",
  30. containerColor: "danger",
  31. titleColor: "danger"
  32. },
  33. success: {
  34. subTitleColor: "successLow",
  35. containerColor: "success",
  36. titleColor: "success"
  37. },
  38. warning: {
  39. subTitleColor: "warningLow",
  40. containerColor: "warning",
  41. titleColor: "warning"
  42. },
  43. info: {
  44. subTitleColor: "infoLow",
  45. containerColor: "info",
  46. titleColor: "info"
  47. },
  48. neutral: {
  49. containerColor: "mid",
  50. subTitleColor: "low",
  51. titleColor: "mid"
  52. }
  53. };
  54. export const getNotificationIndicatorType = ({
  55. type
  56. }: NotificationIndicatorTypeConstantType): NotificationIndicatorTypes => {
  57. const currentType = NOTIFICATION_INDICATOR_TYPE_STYLES[type];
  58. return currentType;
  59. };
  60. const stylesheet = StyleSheet.create({
  61. container: {
  62. backgroundColor: "transparent",
  63. borderColor: "transparent",
  64. position: "relative"
  65. },
  66. indicatorContainer: {
  67. borderStyle: "solid",
  68. position: "absolute",
  69. minHeight: 18,
  70. minWidth: 18
  71. },
  72. titleContainer: {
  73. position: "relative"
  74. },
  75. title: {
  76. },
  77. loading: {
  78. },
  79. overlay: {
  80. position: "absolute",
  81. display: "none",
  82. zIndex: 999,
  83. bottom: 0,
  84. right: 0,
  85. left: 0,
  86. top: 0
  87. }
  88. });
  89. export const useStyles = ({
  90. floorBackgroundColor,
  91. spreadBehaviour,
  92. currentType,
  93. isDisabled,
  94. isLoading,
  95. radiuses,
  96. borders,
  97. colors,
  98. spaces,
  99. type
  100. }: NotificationIndicatorDynamicStyleType) => {
  101. const styleType = type === "danger" ? "error" : type;
  102. const styles = {
  103. container: {
  104. padding: spaces.spacingSm,
  105. alignSelf: "auto"
  106. } as Mutable<ViewStyle>,
  107. indicatorContainer: {
  108. backgroundColor: colors.content.container[currentType.containerColor],
  109. borderColor: colors.content.container[floorBackgroundColor],
  110. paddingHorizontal: spaces.spacingSm,
  111. paddingVertical: spaces.spacingXs,
  112. borderWidth: borders.subtract,
  113. borderRadius: radiuses.full
  114. } as Mutable<ViewStyle>,
  115. titleContainer: {
  116. } as Mutable<ViewStyle>,
  117. title: {
  118. } as Mutable<TextStyle>,
  119. loading: {
  120. } as Mutable<ViewStyle>,
  121. overlay: {
  122. } as Mutable<ViewStyle>
  123. };
  124. if (spreadBehaviour === "baseline") {
  125. styles.container.alignSelf = spreadBehaviour;
  126. styles.container.width = "auto";
  127. } else if (spreadBehaviour === "stretch") {
  128. styles.container.alignSelf = spreadBehaviour;
  129. styles.container.justifyContent = "center";
  130. styles.container.flexShrink = 1;
  131. styles.container.width = "100%";
  132. }
  133. if (isLoading) {
  134. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
  135. styles.overlay.display = "flex";
  136. }
  137. if (isDisabled) {
  138. styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
  139. styles.overlay.display = "flex";
  140. }
  141. return styles;
  142. };
  143. export default stylesheet;