cdslibrary 1.0.35 → 1.0.37
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/CDSButton.jsx +43 -27
- package/package.json +1 -1
package/components/CDSButton.jsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { Text, StyleSheet, TouchableOpacity } from "react-native";
|
|
3
3
|
import { Dimensions, Platform } from "react-native";
|
|
4
4
|
import { MaterialIcons } from "@expo/vector-icons";
|
|
5
5
|
import { useTheme } from "../context/CDSThemeContext";
|
|
6
6
|
import { getSemanticTextStyles } from "../tokens/CDSsemanticTextStyles";
|
|
7
7
|
|
|
8
|
-
const { width } = Dimensions.get("window");
|
|
9
|
-
const isMobile = width <= 768
|
|
8
|
+
// const { width } = Dimensions.get("window");
|
|
9
|
+
// const isMobile = width <= 768
|
|
10
10
|
|
|
11
11
|
export const CDSButton = ({
|
|
12
12
|
label,
|
|
@@ -33,30 +33,46 @@ export const CDSButton = ({
|
|
|
33
33
|
? theme.text.neutral.disabled
|
|
34
34
|
: theme.text.neutral.contrast;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
const { width } = Dimensions.get("window");
|
|
37
|
+
|
|
38
|
+
// Estado para manejar el ancho del dispositivo
|
|
39
|
+
const [isMobile, setIsMobile] = useState(width <= 768);
|
|
40
|
+
|
|
41
|
+
// Efecto para detectar cambios en el tamaño de la ventana en la web
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const handleResize = () => {
|
|
44
|
+
const { width } = Dimensions.get("window");
|
|
45
|
+
setIsMobile(width <= 768);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const subscription = Dimensions.addEventListener("change", handleResize);
|
|
49
|
+
return () => subscription?.remove(); // Limpia el listener
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<TouchableOpacity
|
|
54
|
+
onPress={type !== "disabled" ? onPress : null}
|
|
55
|
+
activeOpacity={0.7}
|
|
56
|
+
style={[
|
|
57
|
+
styles.container,
|
|
58
|
+
{ backgroundColor },
|
|
59
|
+
flexend && { justifyContent: "flex-end", paddingHorizontal: 0 },
|
|
60
|
+
{
|
|
61
|
+
paddingHorizontal: type === "icon" ? 12 : 24,
|
|
62
|
+
...(isMobile && { width: "100%" }) // Se aplica full width si es móvil o en la web en modo móvil
|
|
63
|
+
},
|
|
64
|
+
type === "secondary" && {
|
|
65
|
+
borderColor: theme.outline.action.primary,
|
|
66
|
+
borderWidth: 1,
|
|
67
|
+
},
|
|
68
|
+
type === 'link' && {
|
|
69
|
+
paddingHorizontal: 0,
|
|
70
|
+
paddingVertical: 0,
|
|
71
|
+
width: 'auto',
|
|
72
|
+
minWidth: 1,
|
|
73
|
+
}
|
|
74
|
+
]}
|
|
75
|
+
>
|
|
60
76
|
{type !== "icon" && (
|
|
61
77
|
<Text
|
|
62
78
|
style={[
|