index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import {
  2. useLayoutEffect,
  3. useState
  4. } from "react";
  5. import {
  6. View
  7. } from "react-native";
  8. import stylesheet from "./stylesheet";
  9. import {
  10. NCoreUIKitLocalize,
  11. NCoreUIKitTheme,
  12. PageContainer,
  13. AvatarGroup,
  14. CodeViewer,
  15. SelectBox,
  16. Header,
  17. Switch,
  18. Text
  19. } from "ncore-ui-kit";
  20. import {
  21. useNavigation
  22. } from "@react-navigation/native";
  23. import type RootStackParamList from "../../../navigation/type";
  24. import type {
  25. NativeStackNavigationProp
  26. } from "@react-navigation/native-stack";
  27. import type {
  28. IAvatarGroupProps
  29. } from "ncore-ui-kit";
  30. const AVATAR_GROUP_SIZES: Array<IAvatarGroupProps["size"]> = [
  31. "small",
  32. "medium",
  33. "large",
  34. "xLarge",
  35. "xSmall"
  36. ];
  37. const AVATAR_GROUP_SIZES_DATA = AVATAR_GROUP_SIZES.map((item) => ({
  38. __title: item as string,
  39. __key: item as string
  40. }));
  41. const MOCK_AVATARS = [
  42. {
  43. imageUrl: "https://ncore.nibgat.space/assets/images/ncorelogo.png",
  44. title: "Ncore System"
  45. },
  46. {
  47. title: "Jane Smith"
  48. },
  49. {
  50. title: "Mike Ross"
  51. },
  52. {
  53. title: "John Doe"
  54. }
  55. ];
  56. const AvatarGroupPage = () => {
  57. const {
  58. radiuses,
  59. borders,
  60. spaces,
  61. colors
  62. } = NCoreUIKitTheme.useContext();
  63. const {
  64. localize
  65. } = NCoreUIKitLocalize.useContext();
  66. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  67. const [
  68. sizeIndex,
  69. setSizeIndex
  70. ] = useState<number>(3);
  71. const [
  72. isDisabled,
  73. setIsDisabled
  74. ] = useState<boolean>(false);
  75. const [
  76. isLoading,
  77. setIsLoading
  78. ] = useState<boolean>(false);
  79. useLayoutEffect(() => {
  80. navigation.setOptions({
  81. header: () => <Header
  82. title={localize("avatarGroup-title")}
  83. isWrapSafeareaContext={false}
  84. navigation={navigation}
  85. isGoBackEnable={true}
  86. />,
  87. headerShown: true
  88. });
  89. }, []);
  90. return <PageContainer
  91. scrollViewProps={{
  92. contentContainerStyle: stylesheet.scrollContent
  93. }}
  94. isWorkWithHeaderSpace={false}
  95. scrollViewStyle={[
  96. stylesheet.container
  97. ]}
  98. isScrollable={true}
  99. >
  100. <View
  101. style={[
  102. stylesheet.contentContainer
  103. ]}
  104. >
  105. <Text
  106. style={stylesheet.descText}
  107. variant="bodyMediumSize"
  108. color="mid"
  109. >
  110. {localize("avatarGroup-desc")}
  111. </Text>
  112. <View
  113. style={[
  114. stylesheet.previewContainer,
  115. {
  116. borderColor: colors.content.border.subtle,
  117. marginBottom: spaces.spacingMd,
  118. borderRadius: radiuses.form,
  119. borderWidth: borders.line,
  120. padding: spaces.spacingMd
  121. }
  122. ]}
  123. >
  124. <AvatarGroup
  125. size={AVATAR_GROUP_SIZES[sizeIndex]}
  126. isDisabled={isDisabled}
  127. avatars={MOCK_AVATARS}
  128. isLoading={isLoading}
  129. />
  130. </View>
  131. <View
  132. style={{
  133. marginBottom: spaces.spacingMd
  134. }}
  135. >
  136. <Text
  137. style={{
  138. marginBottom: spaces.spacingSm
  139. }}
  140. variant="headlineSmallSize"
  141. >
  142. {localize("usage")}
  143. </Text>
  144. <CodeViewer
  145. code={"import {\n AvatarGroup\n} from \"ncore-ui-kit\";\n\n<AvatarGroup\n avatars={[\n { title: \"John Doe\" },\n { title: \"Jane Smith\" }\n ]}\n size=\"large\"\n/>"}
  146. language="tsx"
  147. />
  148. </View>
  149. <View
  150. style={[
  151. stylesheet.rowContainer,
  152. {
  153. gap: spaces.spacingMd
  154. }
  155. ]}
  156. >
  157. <SelectBox
  158. onChange={(selectedItems) => {
  159. if (selectedItems.length > 0) {
  160. const index = AVATAR_GROUP_SIZES.indexOf(
  161. selectedItems[0]!
  162. .__key as IAvatarGroupProps["size"],
  163. );
  164. if (index !== -1) setSizeIndex(index);
  165. }
  166. }}
  167. initialSelectedItems={
  168. AVATAR_GROUP_SIZES_DATA[sizeIndex]
  169. ? [
  170. AVATAR_GROUP_SIZES_DATA[sizeIndex]!
  171. ]
  172. : []
  173. }
  174. title={localize("avatarGroup-changeSize")}
  175. titleExtractor={(item) => item.__title}
  176. keyExtractor={(item) => item.__key}
  177. data={AVATAR_GROUP_SIZES_DATA}
  178. spreadBehaviour="free"
  179. />
  180. <View
  181. style={stylesheet.switchesContainer}
  182. >
  183. <Switch
  184. title={localize("avatarGroup-toggleLoading")}
  185. onPress={() => {
  186. setIsLoading(!isLoading);
  187. }}
  188. spreadBehaviour="free"
  189. isActive={isLoading}
  190. />
  191. <Switch
  192. title={localize(
  193. "avatarGroup-toggleDisabled",
  194. )}
  195. onPress={() => {
  196. setIsDisabled(!isDisabled);
  197. }}
  198. spreadBehaviour="free"
  199. isActive={isDisabled}
  200. />
  201. </View>
  202. </View>
  203. </View>
  204. </PageContainer>;
  205. };
  206. export default AvatarGroupPage;