stylesheet.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {
  2. type ViewStyle,
  3. StyleSheet
  4. } from "react-native";
  5. import type {
  6. AvatarGroupSizeConstantType,
  7. AvatarGroupDynamicStyleType,
  8. AvatarGroupMeasuresKeys,
  9. AvatarGroupSizeType
  10. } from "./type";
  11. import type {
  12. Mutable
  13. } from "../../types";
  14. export const AVATAR_GROUP_SIZES: Record<AvatarGroupSizeType, AvatarGroupMeasuresKeys> = {
  15. xxSmall: {
  16. fontSize: "labelSmallSize",
  17. iconSize: 14,
  18. size: 24
  19. },
  20. xSmall: {
  21. fontSize: "labelMediumSize",
  22. iconSize: 18,
  23. size: 32
  24. },
  25. small: {
  26. fontSize: "labelLargeSize",
  27. iconSize: 22,
  28. size: 40
  29. },
  30. medium: {
  31. fontSize: "bodyLargeSize",
  32. iconSize: 26,
  33. size: 48
  34. },
  35. large: {
  36. fontSize: "headlineSmallSize",
  37. iconSize: 32,
  38. size: 64
  39. },
  40. xLarge: {
  41. fontSize: "headlineMediumSize",
  42. iconSize: 40,
  43. size: 80
  44. },
  45. xxLarge: {
  46. fontSize: "displaySmallSize",
  47. iconSize: 60,
  48. size: 120
  49. },
  50. xxxLarge: {
  51. fontSize: "displayMediumSize",
  52. iconSize: 76,
  53. size: 150
  54. }
  55. };
  56. export const getAvatarGroupSize = ({
  57. size
  58. }: AvatarGroupSizeConstantType): AvatarGroupMeasuresKeys => {
  59. const currentSize = AVATAR_GROUP_SIZES[size];
  60. return {
  61. fontSize: currentSize.fontSize,
  62. iconSize: currentSize.iconSize,
  63. size: currentSize.size
  64. };
  65. };
  66. const stylesheet = StyleSheet.create({
  67. container: {
  68. flexDirection: "row",
  69. position: "relative"
  70. },
  71. iconContainer: {
  72. justifyContent: "center",
  73. alignItems: "center"
  74. },
  75. icon: {
  76. },
  77. moreAvatarsContainer: {
  78. justifyContent: "center",
  79. alignItems: "center"
  80. }
  81. });
  82. export const useStyles = ({
  83. avatarBackgroundColor,
  84. currentSize,
  85. borderColor,
  86. isDisabled,
  87. isLoading,
  88. avatars,
  89. borders,
  90. colors
  91. }: AvatarGroupDynamicStyleType) => {
  92. const styles = {
  93. container: {
  94. } as Mutable<ViewStyle>,
  95. iconContainer: {
  96. borderColor: borderColor ? borderColor === "transparent" ? "transparent" : colors.content.border[borderColor] : avatarBackgroundColor ? colors.content.container[avatarBackgroundColor] : colors.content.container.default,
  97. transform: [{
  98. translateX: avatars && avatars.length === 1 ? 0 : (currentSize.size / 3) * -1
  99. }],
  100. backgroundColor: colors.content.container.subtle,
  101. borderRadius: currentSize.size / 2,
  102. borderWidth: borders.subtract,
  103. height: currentSize.size,
  104. width: currentSize.size
  105. } as Mutable<ViewStyle>,
  106. icon: {
  107. } as Mutable<ViewStyle>,
  108. moreAvatarsContainer: {
  109. borderColor: borderColor ? borderColor === "transparent" ? "transparent" : colors.content.border[borderColor] : avatarBackgroundColor ? colors.content.container[avatarBackgroundColor] : colors.content.container.default,
  110. backgroundColor: colors.content.container.subtle,
  111. transform: [{
  112. translateX: (currentSize.size / 1.5) * -1
  113. }],
  114. borderRadius: currentSize.size / 2,
  115. borderWidth: borders.subtract,
  116. height: currentSize.size,
  117. width: currentSize.size
  118. } as Mutable<ViewStyle>,
  119. avatar: {
  120. } as Mutable<ViewStyle>
  121. };
  122. if(isDisabled) {
  123. styles.container.opacity = 0.33;
  124. }
  125. if(isLoading) {
  126. styles.container.opacity = 0.33;
  127. }
  128. return styles;
  129. };
  130. export default stylesheet;