mg-library 1.0.720 → 1.0.721
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.
- package/components.js +73 -31
- package/package.json +1 -1
package/components.js
CHANGED
|
@@ -167,54 +167,96 @@ export function MGButton({
|
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export function MGPopover(
|
|
170
|
+
export function MGPopover({
|
|
171
|
+
title,
|
|
172
|
+
icon,
|
|
173
|
+
language,
|
|
174
|
+
callback,
|
|
175
|
+
confirmText = mgFunctionsLib.i18nString("yes", language),
|
|
176
|
+
cancelText = mgFunctionsLib.i18nString("no", language),
|
|
177
|
+
confirmColor = "primary",
|
|
178
|
+
confirmVariant = "solid",
|
|
179
|
+
placement = "bottom",
|
|
180
|
+
isOpen: controlledOpen,
|
|
181
|
+
onOpenChange,
|
|
182
|
+
triggerProps = {},
|
|
183
|
+
contentWidth = 300,
|
|
184
|
+
confirmIcon,
|
|
185
|
+
...rest
|
|
186
|
+
}) {
|
|
171
187
|
const [visible, setVisible] = useState(false);
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
title={mgFunctionsLib.i18nString("no", props.language)}
|
|
186
|
-
action="primary"
|
|
187
|
-
variant="solid"
|
|
188
|
-
py="$4"
|
|
189
|
-
onPress={() => setVisible(false)}
|
|
190
|
-
/>
|
|
191
|
-
</Box>
|
|
192
|
-
);
|
|
188
|
+
const isControlled = controlledOpen !== undefined;
|
|
189
|
+
const open = isControlled ? controlledOpen : visible;
|
|
190
|
+
const setOpen = onOpenChange ?? setVisible;
|
|
191
|
+
const [loading, setLoading] = useState(false);
|
|
192
|
+
const handleConfirm = async () => {
|
|
193
|
+
try {
|
|
194
|
+
setLoading(true);
|
|
195
|
+
await callback?.();
|
|
196
|
+
} finally {
|
|
197
|
+
setLoading(false);
|
|
198
|
+
setOpen(false);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
193
201
|
return (
|
|
194
|
-
<Popover
|
|
202
|
+
<Popover
|
|
203
|
+
isOpen={open}
|
|
204
|
+
onOpenChange={setOpen}
|
|
205
|
+
placement={placement}
|
|
206
|
+
{...rest}
|
|
207
|
+
>
|
|
195
208
|
<PopoverTrigger>
|
|
196
|
-
{(
|
|
197
|
-
<Button
|
|
198
|
-
{
|
|
199
|
-
|
|
209
|
+
{(tp) => (
|
|
210
|
+
<Button
|
|
211
|
+
{...tp}
|
|
212
|
+
action={triggerProps.action ?? "primary"}
|
|
213
|
+
variant={triggerProps.variant ?? "solid"}
|
|
214
|
+
py={triggerProps.py ?? "$4"}
|
|
215
|
+
bg={triggerProps.bg}
|
|
216
|
+
borderColor={triggerProps.borderColor}
|
|
217
|
+
isDisabled={triggerProps.isDisabled}
|
|
218
|
+
>
|
|
219
|
+
{icon ? (
|
|
220
|
+
<Icon as={MaterialCommunityIcons} name={icon} mr="$2" color="$white" />
|
|
200
221
|
) : null}
|
|
201
|
-
<ButtonText>{
|
|
222
|
+
<ButtonText>{title}</ButtonText>
|
|
202
223
|
</Button>
|
|
203
224
|
)}
|
|
204
225
|
</PopoverTrigger>
|
|
205
226
|
<PopoverBackdrop />
|
|
206
|
-
<PopoverContent w={
|
|
227
|
+
<PopoverContent w={contentWidth} bg="$white">
|
|
207
228
|
<PopoverArrow />
|
|
208
229
|
<PopoverCloseButton />
|
|
209
230
|
<PopoverBody>
|
|
210
231
|
<Box alignItems="center" justifyContent="center">
|
|
211
232
|
<Icon as={MaterialCommunityIcons} name="alert-outline" size={16} color="$primary500" mb="$3" />
|
|
212
233
|
<MGText textAlign="center">
|
|
213
|
-
{mgFunctionsLib.i18nString("confirm",
|
|
234
|
+
{mgFunctionsLib.i18nString("confirm", language)}?
|
|
214
235
|
</MGText>
|
|
215
236
|
</Box>
|
|
216
237
|
</PopoverBody>
|
|
217
|
-
<PopoverFooter>
|
|
238
|
+
<PopoverFooter>
|
|
239
|
+
<Box flexDirection="row" justifyContent="space-around" mt="$5" mb="$5">
|
|
240
|
+
<MGButton
|
|
241
|
+
title={confirmText}
|
|
242
|
+
action={confirmColor}
|
|
243
|
+
variant={confirmVariant}
|
|
244
|
+
py="$4"
|
|
245
|
+
icon={confirmIcon}
|
|
246
|
+
isLoading={loading}
|
|
247
|
+
disabled={loading}
|
|
248
|
+
callback={handleConfirm}
|
|
249
|
+
/>
|
|
250
|
+
<MGButton
|
|
251
|
+
title={cancelText}
|
|
252
|
+
action="primary"
|
|
253
|
+
variant="outline"
|
|
254
|
+
py="$4"
|
|
255
|
+
disabled={loading}
|
|
256
|
+
callback={() => setOpen(false)}
|
|
257
|
+
/>
|
|
258
|
+
</Box>
|
|
259
|
+
</PopoverFooter>
|
|
218
260
|
</PopoverContent>
|
|
219
261
|
</Popover>
|
|
220
262
|
);
|