mg-library 1.0.705 → 1.0.707
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 +107 -2
- package/package.json +1 -1
package/components.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
|
+
import { Platform, Animated } from "react-native";
|
|
2
3
|
import { Box, Text, Divider, Button, ButtonText, ButtonIcon, Icon, Popover, PopoverTrigger, PopoverContent, PopoverArrow, PopoverCloseButton, PopoverBody, PopoverFooter } from '@gluestack-ui/themed';
|
|
3
4
|
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
|
4
5
|
|
|
@@ -71,7 +72,7 @@ export function MGCard({ children, header = null, footer = null, style = {}, ...
|
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
export function MGButton({
|
|
75
|
+
/* export function MGButton({
|
|
75
76
|
title,
|
|
76
77
|
icon,
|
|
77
78
|
callback,
|
|
@@ -146,6 +147,110 @@ export function MGButton({
|
|
|
146
147
|
</Button>
|
|
147
148
|
);
|
|
148
149
|
}
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
export function MGButton({
|
|
153
|
+
title,
|
|
154
|
+
icon,
|
|
155
|
+
callback,
|
|
156
|
+
variant = "solid",
|
|
157
|
+
action = "primary",
|
|
158
|
+
isDisabled,
|
|
159
|
+
disabled,
|
|
160
|
+
isLoading,
|
|
161
|
+
style,
|
|
162
|
+
textProps = {},
|
|
163
|
+
size = "lg",
|
|
164
|
+
py,
|
|
165
|
+
minHeight,
|
|
166
|
+
iconSpacing = "$2",
|
|
167
|
+
iconSize,
|
|
168
|
+
iconColor,
|
|
169
|
+
...rest
|
|
170
|
+
}) {
|
|
171
|
+
const scale = useRef(new Animated.Value(1)).current;
|
|
172
|
+
|
|
173
|
+
const animateIn = () =>
|
|
174
|
+
Animated.spring(scale, {
|
|
175
|
+
toValue: 0.97,
|
|
176
|
+
friction: 7,
|
|
177
|
+
useNativeDriver: true,
|
|
178
|
+
}).start();
|
|
179
|
+
|
|
180
|
+
const animateOut = () =>
|
|
181
|
+
Animated.spring(scale, {
|
|
182
|
+
toValue: 1,
|
|
183
|
+
friction: 7,
|
|
184
|
+
useNativeDriver: true,
|
|
185
|
+
}).start();
|
|
186
|
+
|
|
187
|
+
const effectiveDisabled = !!(isDisabled || disabled || isLoading);
|
|
188
|
+
const isSolid = variant === "solid" || variant === "filled";
|
|
189
|
+
const gsVariant = variant === "ghost" ? "link" : variant;
|
|
190
|
+
|
|
191
|
+
const textColor = isSolid ? "$white" : `$${action}700`;
|
|
192
|
+
if (iconColor === undefined) iconColor = textColor;
|
|
193
|
+
const bgColor = isSolid ? `$${action}500` : "$white"; // 👈 fondo blanco explícito
|
|
194
|
+
const borderColor = `$${action}500`;
|
|
195
|
+
|
|
196
|
+
const SIZE_MAP = {
|
|
197
|
+
sm: { pyToken: "$2", icon: 16 },
|
|
198
|
+
md: { pyToken: "$3", icon: 18 },
|
|
199
|
+
lg: { pyToken: "$4", icon: 20 },
|
|
200
|
+
xl: { pyToken: "$5", icon: 22 },
|
|
201
|
+
};
|
|
202
|
+
const { pyToken, icon: defaultIconSize } = SIZE_MAP[size] || SIZE_MAP.lg;
|
|
203
|
+
const resolvedPy = py !== undefined ? py : pyToken;
|
|
204
|
+
const resolvedIconSize = iconSize ?? defaultIconSize;
|
|
205
|
+
|
|
206
|
+
// 🎯 Diferenciar pressed según tipo
|
|
207
|
+
const pressedStyles = isSolid
|
|
208
|
+
? { bg: `$${action}600`, opacity: 0.9 }
|
|
209
|
+
: { bg: "$gray200", opacity: 0.95, borderColor: `$${action}600` };
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<Animated.View style={[{ transform: [{ scale }] }]}>
|
|
213
|
+
<Button
|
|
214
|
+
action={action}
|
|
215
|
+
variant={gsVariant}
|
|
216
|
+
isDisabled={effectiveDisabled}
|
|
217
|
+
onPress={callback}
|
|
218
|
+
onPressIn={animateIn}
|
|
219
|
+
onPressOut={animateOut}
|
|
220
|
+
bg={bgColor}
|
|
221
|
+
borderColor={borderColor}
|
|
222
|
+
size={size}
|
|
223
|
+
minHeight={minHeight}
|
|
224
|
+
isLoading={!!isLoading}
|
|
225
|
+
style={[!effectiveDisabled && { opacity: 1 }, style]}
|
|
226
|
+
_pressed={pressedStyles}
|
|
227
|
+
{...rest}
|
|
228
|
+
>
|
|
229
|
+
{icon ? (
|
|
230
|
+
<ButtonIcon
|
|
231
|
+
as={MaterialCommunityIcons}
|
|
232
|
+
name={icon}
|
|
233
|
+
color={iconColor}
|
|
234
|
+
mr={title ? iconSpacing : 0}
|
|
235
|
+
size={resolvedIconSize}
|
|
236
|
+
/>
|
|
237
|
+
) : null}
|
|
238
|
+
|
|
239
|
+
{title ? (
|
|
240
|
+
<ButtonText
|
|
241
|
+
color={textColor}
|
|
242
|
+
size="md"
|
|
243
|
+
fontWeight="$semibold"
|
|
244
|
+
textTransform="none"
|
|
245
|
+
{...textProps}
|
|
246
|
+
>
|
|
247
|
+
{title}
|
|
248
|
+
</ButtonText>
|
|
249
|
+
) : null}
|
|
250
|
+
</Button>
|
|
251
|
+
</Animated.View>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
149
254
|
|
|
150
255
|
export function MGPopover(props) {
|
|
151
256
|
const [visible, setVisible] = useState(false);
|