cpk-ui 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { cloneElement, forwardRef, useImperativeHandle, useState, } from 'react';
|
|
2
|
+
import { cloneElement, forwardRef, useEffect, useImperativeHandle, useState, } from 'react';
|
|
3
3
|
import { Modal, Platform, StyleSheet, TouchableWithoutFeedback, View, } from 'react-native';
|
|
4
4
|
import styled, { css } from '@emotion/native';
|
|
5
5
|
import { useTheme } from '../../../providers/ThemeProvider';
|
|
@@ -37,6 +37,14 @@ function AlertDialog({ style }, ref) {
|
|
|
37
37
|
const [options, setOptions] = useState(null);
|
|
38
38
|
const [visible, setVisible] = useState(false);
|
|
39
39
|
const { theme, themeType } = useTheme();
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!visible) {
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
setOptions(null);
|
|
44
|
+
// Run after modal has finished transition
|
|
45
|
+
}, 200);
|
|
46
|
+
}
|
|
47
|
+
}, [visible]);
|
|
40
48
|
useImperativeHandle(ref, () => ({
|
|
41
49
|
open: (alertDialogOptions) => {
|
|
42
50
|
setVisible(true);
|
|
@@ -46,10 +54,9 @@ function AlertDialog({ style }, ref) {
|
|
|
46
54
|
},
|
|
47
55
|
close: () => {
|
|
48
56
|
setVisible(false);
|
|
49
|
-
setOptions(null);
|
|
50
57
|
},
|
|
51
58
|
}));
|
|
52
|
-
const { backdropOpacity = 0.2, title, body, styles, actions, closeOnTouchOutside = true, } = options ?? {};
|
|
59
|
+
const { backdropOpacity = 0.2, title, body, styles, actions, closeOnTouchOutside = true, showCloseButton = true, } = options ?? {};
|
|
53
60
|
const AlertDialogContent = (_jsx(Container, { style: css `
|
|
54
61
|
background-color: ${themeType === 'light'
|
|
55
62
|
? `rgba(0,0,0,${backdropOpacity})`
|
|
@@ -60,7 +67,7 @@ function AlertDialog({ style }, ref) {
|
|
|
60
67
|
shadowColor: theme.text.basic,
|
|
61
68
|
},
|
|
62
69
|
styles?.container,
|
|
63
|
-
]), children: [_jsxs(TitleRow, { style: styles?.titleContainer, children: [typeof title === 'string' ? (_jsx(Typography.Heading3, { style: styles?.title, children: title })) : (title), _jsx(Button, { onPress: () => setVisible(false), borderRadius: 24, text: _jsx(Icon, { color: theme.text.basic, name: "X", size: 18 }), type: "text" })] }), _jsx(BodyRow, { style: styles?.bodyContainer, children: typeof body === 'string' ? (_jsx(Typography.Body3, { style: styles?.body, children: body })) : (body) }), actions ? (_jsx(ActionRow, { style: styles?.actionContainer, children: actions.map((action, index) => cloneElement(action, {
|
|
70
|
+
]), children: [_jsxs(TitleRow, { style: styles?.titleContainer, children: [typeof title === 'string' ? (_jsx(Typography.Heading3, { style: styles?.title, children: title })) : (title), showCloseButton ? (_jsx(Button, { onPress: () => setVisible(false), borderRadius: 24, text: _jsx(Icon, { color: theme.text.basic, name: "X", size: 18 }), type: "text" })) : null] }), _jsx(BodyRow, { style: styles?.bodyContainer, children: typeof body === 'string' ? (_jsx(Typography.Body3, { style: styles?.body, children: body })) : (body) }), actions ? (_jsx(ActionRow, { style: styles?.actionContainer, children: actions.map((action, index) => cloneElement(action, {
|
|
64
71
|
key: `action-${index}`,
|
|
65
72
|
style: {
|
|
66
73
|
flex: 1,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
cloneElement,
|
|
3
3
|
forwardRef,
|
|
4
|
+
useEffect,
|
|
4
5
|
useImperativeHandle,
|
|
5
6
|
useState,
|
|
6
7
|
} from 'react';
|
|
@@ -70,6 +71,7 @@ export type AlertDialogOptions = {
|
|
|
70
71
|
backdropOpacity?: number;
|
|
71
72
|
closeOnTouchOutside?: boolean;
|
|
72
73
|
actions?: JSX.Element[];
|
|
74
|
+
showCloseButton?: boolean;
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
export type AlertDialogContext = {
|
|
@@ -85,6 +87,15 @@ function AlertDialog(
|
|
|
85
87
|
const [visible, setVisible] = useState(false);
|
|
86
88
|
const {theme, themeType} = useTheme();
|
|
87
89
|
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (!visible) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
setOptions(null);
|
|
94
|
+
// Run after modal has finished transition
|
|
95
|
+
}, 200);
|
|
96
|
+
}
|
|
97
|
+
}, [visible]);
|
|
98
|
+
|
|
88
99
|
useImperativeHandle(ref, () => ({
|
|
89
100
|
open: (alertDialogOptions) => {
|
|
90
101
|
setVisible(true);
|
|
@@ -94,7 +105,6 @@ function AlertDialog(
|
|
|
94
105
|
},
|
|
95
106
|
close: () => {
|
|
96
107
|
setVisible(false);
|
|
97
|
-
setOptions(null);
|
|
98
108
|
},
|
|
99
109
|
}));
|
|
100
110
|
|
|
@@ -105,6 +115,7 @@ function AlertDialog(
|
|
|
105
115
|
styles,
|
|
106
116
|
actions,
|
|
107
117
|
closeOnTouchOutside = true,
|
|
118
|
+
showCloseButton = true,
|
|
108
119
|
} = options ?? {};
|
|
109
120
|
|
|
110
121
|
const AlertDialogContent = (
|
|
@@ -132,12 +143,14 @@ function AlertDialog(
|
|
|
132
143
|
) : (
|
|
133
144
|
title
|
|
134
145
|
)}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
{showCloseButton ? (
|
|
147
|
+
<Button
|
|
148
|
+
onPress={() => setVisible(false)}
|
|
149
|
+
borderRadius={24}
|
|
150
|
+
text={<Icon color={theme.text.basic} name="X" size={18} />}
|
|
151
|
+
type="text"
|
|
152
|
+
/>
|
|
153
|
+
) : null}
|
|
141
154
|
</TitleRow>
|
|
142
155
|
<BodyRow style={styles?.bodyContainer}>
|
|
143
156
|
{typeof body === 'string' ? (
|