| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- STATUS_CHEAT_SHEET,
- NCoreUIKitTheme,
- PageContainer,
- CodeViewer,
- SelectBox,
- TextInput,
- Avatar,
- 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 {
- ActivityStatusType,
- IAvatarProps
- } from "ncore-ui-kit";
- const AVATAR_SIZES: Array<IAvatarProps["size"]> = [
- "medium",
- "xLarge",
- "xSmall",
- "large",
- "small"
- ];
- const AVATAR_SIZES_DATA = AVATAR_SIZES.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const AVATAR_STATUS_INDICATOR_TYPES = Object.keys(STATUS_CHEAT_SHEET) as Array<ActivityStatusType>;
- const AVATAR_STATUS_INDICATOR_TYPES_DATA = AVATAR_STATUS_INDICATOR_TYPES.map(
- (item) => ({
- __title: item as string,
- __key: item as string
- })
- );
- const AvatarPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- statusIndicatorIndex,
- setStatusIndicatorIndex
- ] = useState<number>(1);
- const [
- sizeIndex,
- setSizeIndex
- ] = useState<number>(3);
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isLoading,
- setIsLoading
- ] = useState<boolean>(false);
- const [
- imageUrl,
- setImageUrl
- ] = useState<string>(
- "https://ncore.nibgat.space/assets/images/ncorelogo.png",
- );
- const [
- title,
- setTitle
- ] = useState<string>("John Doe");
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => <Header
- title={localize("avatar-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />,
- headerShown: true
- });
- }, []);
- return <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- isWorkWithHeaderSpace={false}
- scrollViewStyle={[
- stylesheet.container
- ]}
- isScrollable={true}
- >
- <View
- style={[
- stylesheet.contentContainer
- ]}
- >
- <Text
- style={stylesheet.descText}
- variant="bodyMediumSize"
- color="mid"
- >
- {localize("avatar-desc")}
- </Text>
- <View
- style={[
- stylesheet.previewContainer,
- {
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd
- }
- ]}
- >
- <Avatar
- statusIndicatorType={
- AVATAR_STATUS_INDICATOR_TYPES[statusIndicatorIndex]
- }
- size={AVATAR_SIZES[sizeIndex]}
- isStatusIndicator={true}
- isDisabled={isDisabled}
- isLoading={isLoading}
- imageUrl={imageUrl}
- title={title}
- />
- </View>
- <View
- style={{
- marginBottom: spaces.spacingMd
- }}
- >
- <Text
- style={{
- marginBottom: spaces.spacingSm
- }}
- variant="headlineSmallSize"
- >
- {localize("usage")}
- </Text>
- <CodeViewer
- code={"import {\n Avatar\n} from \"ncore-ui-kit\";\n\n<Avatar\n title=\"John Doe\"\n imageUrl=\"https://ncore.nibgat.space/assets/images/ncorelogo.png\"\n statusIndicatorType=\"online\"\n isStatusIndicator={true}\n size=\"large\"\n/>"}
- language="tsx"
- />
- </View>
- <TextInput
- placeholder={localize("avatar-enterImageUrl")}
- title={localize("avatar-imageUrl")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- onChangeText={setImageUrl}
- spreadBehaviour="stretch"
- value={imageUrl}
- />
- <TextInput
- placeholder={localize("avatar-enterText")}
- title={localize("avatar-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <View
- style={[
- stylesheet.rowContainer,
- {
- gap: spaces.spacingMd
- }
- ]}
- >
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = AVATAR_SIZES.indexOf(
- selectedItems[0]!
- .__key as IAvatarProps["size"],
- );
- if (index !== -1) setSizeIndex(index);
- }
- }}
- initialSelectedItems={
- AVATAR_SIZES_DATA[sizeIndex]
- ? [
- AVATAR_SIZES_DATA[sizeIndex]!
- ]
- : []
- }
- titleExtractor={(item) => item.__title}
- keyExtractor={(item) => item.__key}
- title={localize("change-size")}
- data={AVATAR_SIZES_DATA}
- spreadBehaviour="free"
- />
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index =
- AVATAR_STATUS_INDICATOR_TYPES.indexOf(
- selectedItems[0]!
- .__key as ActivityStatusType,
- );
- if (index !== -1)
- setStatusIndicatorIndex(index);
- }
- }}
- initialSelectedItems={
- AVATAR_STATUS_INDICATOR_TYPES_DATA[
- statusIndicatorIndex
- ]
- ? [
- AVATAR_STATUS_INDICATOR_TYPES_DATA[
- statusIndicatorIndex
- ]!
- ]
- : []
- }
- data={AVATAR_STATUS_INDICATOR_TYPES_DATA}
- title={localize("avatar-changeStatus")}
- titleExtractor={(item) => item.__title}
- keyExtractor={(item) => item.__key}
- spreadBehaviour="free"
- />
- <View
- style={stylesheet.switchesContainer}
- >
- <Switch
- title={localize("avatar-toggleLoading")}
- onPress={() => {
- setIsLoading(!isLoading);
- }}
- spreadBehaviour="free"
- isActive={isLoading}
- />
- <Switch
- title={localize("avatar-toggleDisabled")}
- onPress={() => {
- setIsDisabled(!isDisabled);
- }}
- spreadBehaviour="free"
- isActive={isDisabled}
- />
- </View>
- </View>
- </View>
- </PageContainer>;
- };
- export default AvatarPage;
|