| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- NCoreUIKitTheme,
- PageContainer,
- CodeViewer,
- SelectBox,
- TextInput,
- Button,
- Dialog,
- Header,
- 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 {
- IDialogProps
- } from "ncore-ui-kit";
- const DIALOG_VARIANTS: Array<IDialogProps["variant"]> = [
- "yes-no",
- "ok",
- "info"
- ];
- const DIALOG_VARIANTS_DATA = DIALOG_VARIANTS.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const DialogPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- variantIndex,
- setVariantIndex
- ] = useState<number>(0);
- const [
- isVisible,
- setIsVisible
- ] = useState<boolean>(false);
- const [
- content,
- setContent
- ] = useState<string>("This is a dialog content.");
- const [
- title,
- setTitle
- ] = useState<string>("Dialog Title");
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => <Header
- title={localize("dialog-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("dialog-desc")}
- </Text>
- <View
- style={[
- stylesheet.previewContainer,
- {
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd
- }
- ]}
- >
- <Button
- title={localize("dialog-openDialog")}
- onPress={() => setIsVisible(true)}
- />
- </View>
- <View
- style={{
- marginBottom: spaces.spacingMd
- }}
- >
- <Text
- style={{
- marginBottom: spaces.spacingSm
- }}
- variant="headlineSmallSize"
- >
- {localize("usage")}
- </Text>
- <CodeViewer
- code={"import {\n Dialog\n} from \"ncore-ui-kit\";\n\n<Dialog\n title=\"Dialog Title\"\n content=\"This is a dialog content.\"\n isVisible={isVisible}\n variant=\"yes-no\"\n/>"}
- language="tsx"
- />
- </View>
- <TextInput
- placeholder={localize("dialog-enterText")}
- title={localize("dialog-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <TextInput
- placeholder={localize("dialog-enterContentText")}
- title={localize("dialog-contentLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setContent}
- value={content}
- />
- <View
- style={[
- stylesheet.rowContainer,
- {
- gap: spaces.spacingMd
- }
- ]}
- >
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = DIALOG_VARIANTS.indexOf(
- selectedItems[0]!
- .__key as IDialogProps["variant"],
- );
- if (index !== -1) setVariantIndex(index);
- }
- }}
- initialSelectedItems={
- DIALOG_VARIANTS_DATA[variantIndex]
- ? [
- DIALOG_VARIANTS_DATA[variantIndex]!
- ]
- : []
- }
- title={localize("dialog-changeVariant")}
- titleExtractor={(item) => item.__title}
- keyExtractor={(item) => item.__key}
- data={DIALOG_VARIANTS_DATA}
- spreadBehaviour="free"
- />
- </View>
- </View>
- <Dialog
- variant={DIALOG_VARIANTS[variantIndex]}
- secondaryButtonProps={{
- onPress: ({
- closeAnimation
- }) => {
- closeAnimation();
- }
- }}
- primaryButtonProps={{
- onPress: ({
- closeAnimation
- }) => {
- closeAnimation();
- }
- }}
- onClosed={() => {
- setIsVisible(false);
- }}
- onOverlayPress={({
- closeAnimation
- }) => {
- closeAnimation();
- }}
- isVisible={isVisible}
- content={content}
- title={title}
- />
- </PageContainer>;
- };
- export default DialogPage;
|