mg-library 1.0.704 → 1.0.706
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 +113 -9
- 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,
|
|
@@ -94,8 +95,7 @@ export function MGButton({
|
|
|
94
95
|
const isSolid = variant === "solid" || variant === "filled";
|
|
95
96
|
const gsVariant = variant === "ghost" ? "link" : variant;
|
|
96
97
|
const textColor = isSolid ? "$white" : `$${action}700`;
|
|
97
|
-
if (iconColor === undefined)
|
|
98
|
-
iconColor = textColor;
|
|
98
|
+
if (iconColor === undefined) iconColor = textColor;
|
|
99
99
|
const bgColor = isSolid ? `$${action}500` : "transparent";
|
|
100
100
|
const borderColor = `$${action}500`;
|
|
101
101
|
const SIZE_MAP = {
|
|
@@ -107,9 +107,6 @@ export function MGButton({
|
|
|
107
107
|
const { pyToken, icon: defaultIconSize } = SIZE_MAP[size] || SIZE_MAP.lg;
|
|
108
108
|
const resolvedPy = py !== undefined ? py : pyToken;
|
|
109
109
|
const resolvedIconSize = iconSize ?? defaultIconSize;
|
|
110
|
-
const pressedStyles = isSolid
|
|
111
|
-
? { bg: `$${action}600`, opacity: 0.9 }
|
|
112
|
-
: { bg: "$gray200", opacity: 0.95, borderColor: `$${action}600` };
|
|
113
110
|
return (
|
|
114
111
|
<Button
|
|
115
112
|
action={action}
|
|
@@ -120,9 +117,11 @@ export function MGButton({
|
|
|
120
117
|
borderColor={borderColor}
|
|
121
118
|
size={size}
|
|
122
119
|
minHeight={minHeight}
|
|
123
|
-
isLoading={!!isLoading}
|
|
124
|
-
_pressed={pressedStyles}
|
|
125
120
|
style={[!effectiveDisabled && { opacity: 1 }, style]}
|
|
121
|
+
_pressed={{
|
|
122
|
+
bg: isSolid ? `$${action}600` : "$gray100",
|
|
123
|
+
opacity: 0.9,
|
|
124
|
+
}}
|
|
126
125
|
{...rest}
|
|
127
126
|
>
|
|
128
127
|
{icon ? (
|
|
@@ -148,6 +147,111 @@ export function MGButton({
|
|
|
148
147
|
</Button>
|
|
149
148
|
);
|
|
150
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
|
+
py={resolvedPy}
|
|
224
|
+
minHeight={minHeight}
|
|
225
|
+
isLoading={!!isLoading}
|
|
226
|
+
style={[!effectiveDisabled && { opacity: 1 }, style]}
|
|
227
|
+
_pressed={pressedStyles}
|
|
228
|
+
{...rest}
|
|
229
|
+
>
|
|
230
|
+
{icon ? (
|
|
231
|
+
<ButtonIcon
|
|
232
|
+
as={MaterialCommunityIcons}
|
|
233
|
+
name={icon}
|
|
234
|
+
color={iconColor}
|
|
235
|
+
mr={title ? iconSpacing : 0}
|
|
236
|
+
size={resolvedIconSize}
|
|
237
|
+
/>
|
|
238
|
+
) : null}
|
|
239
|
+
|
|
240
|
+
{title ? (
|
|
241
|
+
<ButtonText
|
|
242
|
+
color={textColor}
|
|
243
|
+
size="md"
|
|
244
|
+
fontWeight="$semibold"
|
|
245
|
+
textTransform="none"
|
|
246
|
+
{...textProps}
|
|
247
|
+
>
|
|
248
|
+
{title}
|
|
249
|
+
</ButtonText>
|
|
250
|
+
) : null}
|
|
251
|
+
</Button>
|
|
252
|
+
</Animated.View>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
151
255
|
|
|
152
256
|
export function MGPopover(props) {
|
|
153
257
|
const [visible, setVisible] = useState(false);
|