| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- NCoreUIKitTheme,
- PageContainer,
- AvatarGroup,
- CodeViewer,
- SelectBox,
- Header,
- Switch,
- Text
- } from "ncore-ui-kit";
- import {
- useNavigation
- } from "@react-navigation/native";
- import type RootStackParamList from "../../../navigation/type";
- import type {
- NativeStackNavigationProp
- } from "@react-navigation/native-stack";
- import type {
- IAvatarGroupProps
- } from "ncore-ui-kit";
- const AVATAR_GROUP_SIZES: Array<IAvatarGroupProps["size"]> = [
- "small",
- "medium",
- "large",
- "xLarge",
- "xSmall"
- ];
- const AVATAR_GROUP_SIZES_DATA = AVATAR_GROUP_SIZES.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const MOCK_AVATARS = [
- {
- imageUrl: "https://ncore.nibgat.space/assets/images/ncorelogo.png",
- title: "Ncore System"
- },
- {
- title: "Jane Smith"
- },
- {
- title: "Mike Ross"
- },
- {
- title: "John Doe"
- }
- ];
- const AvatarGroupPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- sizeIndex,
- setSizeIndex
- ] = useState<number>(3);
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isLoading,
- setIsLoading
- ] = useState<boolean>(false);
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => <Header
- title={localize("avatarGroup-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />,
- headerShown: true
- });
- }, []);
- return <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- scrollViewStyle={[
- stylesheet.container
- ]}
- isWorkWithHeaderSpace={false}
- isScrollable={true}
- >
- <View
- style={[
- stylesheet.contentContainer
- ]}
- >
- <Text
- variant="bodyMediumSize"
- color="mid"
- style={stylesheet.descText}
- >
- {localize("avatarGroup-desc")}
- </Text>
- <View
- style={[
- stylesheet.previewContainer,
- {
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd
- }
- ]}
- >
- <AvatarGroup
- size={AVATAR_GROUP_SIZES[sizeIndex]}
- isDisabled={isDisabled}
- avatars={MOCK_AVATARS}
- isLoading={isLoading}
- />
- </View>
- <View
- style={{
- marginBottom: spaces.spacingMd
- }}
- >
- <Text
- variant="headlineSmallSize"
- style={{
- marginBottom: spaces.spacingSm
- }}
- >
- {localize("usage")}
- </Text>
- <CodeViewer
- 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/>"}
- language="tsx"
- />
- </View>
- <View
- style={[
- stylesheet.rowContainer,
- {
- gap: spaces.spacingMd
- }
- ]}
- >
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = AVATAR_GROUP_SIZES.indexOf(
- selectedItems[0]!
- .__key as IAvatarGroupProps["size"],
- );
- if (index !== -1) setSizeIndex(index);
- }
- }}
- initialSelectedItems={
- AVATAR_GROUP_SIZES_DATA[sizeIndex]
- ? [
- AVATAR_GROUP_SIZES_DATA[sizeIndex]!
- ]
- : []
- }
- title={localize("avatarGroup-changeSize")}
- titleExtractor={(item) => item.__title}
- keyExtractor={(item) => item.__key}
- data={AVATAR_GROUP_SIZES_DATA}
- spreadBehaviour="free"
- />
- <View
- style={stylesheet.switchesContainer}
- >
- <Switch
- onPress={() => {
- setIsLoading(!isLoading);
- }}
- title={localize("avatarGroup-toggleLoading")}
- spreadBehaviour="free"
- isActive={isLoading}
- />
- <Switch
- title={localize(
- "avatarGroup-toggleDisabled",
- )}
- onPress={() => {
- setIsDisabled(!isDisabled);
- }}
- spreadBehaviour="free"
- isActive={isDisabled}
- />
- </View>
- </View>
- </View>
- </PageContainer>;
- };
- export default AvatarGroupPage;
|