cdslibrary 1.2.16 → 1.2.18
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
CHANGED
|
@@ -18,8 +18,6 @@ export const CDSButton = ({
|
|
|
18
18
|
}) => {
|
|
19
19
|
const { theme } = useTheme();
|
|
20
20
|
|
|
21
|
-
console.log(isMobile)
|
|
22
|
-
|
|
23
21
|
const backgroundColor =
|
|
24
22
|
type === "disabled"
|
|
25
23
|
? theme.surface.action.disabled
|
|
@@ -40,7 +38,7 @@ export const CDSButton = ({
|
|
|
40
38
|
activeOpacity={0.7}
|
|
41
39
|
style={[
|
|
42
40
|
styles.container,
|
|
43
|
-
{
|
|
41
|
+
{ flexGrow: (variant === "fill" || isMobile ? 1 : 0), maxHeight: (variant === "fill" || isMobile ? 48 : 56), alignSelf: (variant === "fill" || isMobile) ? "stretch" : "center", paddingHorizontal: type === "icon" ? theme.space.xs : theme.space.sm, paddingVertical: theme.space.xs, backgroundColor, borderRadius: theme.radius.full, gap: theme.space.xs, },
|
|
44
42
|
flexend && { justifyContent: "flex-end", paddingHorizontal: 0 },
|
|
45
43
|
type === "secondary" && {
|
|
46
44
|
borderColor: theme.outline.action.primary,
|
|
@@ -1,46 +1,54 @@
|
|
|
1
1
|
|
|
2
|
-
import { View, Text, StyleSheet,} from "react-native";
|
|
2
|
+
import { View, Text, StyleSheet, } from "react-native";
|
|
3
3
|
import { useTheme } from "../context/CDSThemeContext";
|
|
4
4
|
import { CDSButton } from "./CDSButton";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
import React, { useState } from "react";
|
|
7
|
+
import React, { useEffect, useState } from "react";
|
|
8
8
|
|
|
9
|
-
export const CDSButtonGroup = ({ options, onSelect, label='Label' }) => {
|
|
9
|
+
export const CDSButtonGroup = ({ options, onSelect, label = 'Label', selected = null }) => {
|
|
10
10
|
const { theme } = useTheme();
|
|
11
|
-
|
|
11
|
+
// Buscamos el índice que coincide con el valor 'selected'
|
|
12
|
+
const initialIndex = options.findIndex(opt => opt.value === selected);
|
|
13
|
+
const [selectedIndex, setSelectedIndex] = useState(initialIndex);
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
// ESCENCIAL: Sincronizar cuando 'selected' cambia desde afuera
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const newIndex = options.findIndex(opt => opt.value === selected);
|
|
18
|
+
setSelectedIndex(newIndex);
|
|
19
|
+
}, [selected, options]);
|
|
20
|
+
|
|
21
|
+
const handlePress = (index, value) => {
|
|
22
|
+
// No actualizamos el índice aquí manualmente para dejar que la prop mande
|
|
23
|
+
if (onSelect) onSelect(value);
|
|
16
24
|
};
|
|
17
|
-
|
|
25
|
+
|
|
18
26
|
return (
|
|
19
27
|
<View style={[styles.container, { gap: theme.space.xs }]}>
|
|
20
|
-
|
|
28
|
+
<Text style={[theme.typography.label]}>{label}</Text>
|
|
21
29
|
<View style={[styles.actionsContainer, { gap: theme.space.xs }]}>
|
|
22
30
|
{options.map((option, index) => (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
<CDSButton
|
|
32
|
+
key={index}
|
|
33
|
+
variant={'fill'}
|
|
34
|
+
label={option.label}
|
|
35
|
+
// Comparamos el valor de la opción con el valor seleccionado
|
|
36
|
+
type={option.value === selected ? "primary" : "secondary"}
|
|
37
|
+
onPress={() => handlePress(index, option.value)}
|
|
38
|
+
/>
|
|
31
39
|
))}
|
|
32
40
|
</View>
|
|
33
41
|
</View>
|
|
34
42
|
);
|
|
35
|
-
}
|
|
43
|
+
};
|
|
36
44
|
|
|
37
45
|
const styles = StyleSheet.create({
|
|
38
|
-
container:{
|
|
46
|
+
container: {
|
|
39
47
|
width: '100%',
|
|
40
48
|
},
|
|
41
49
|
|
|
42
50
|
actionsContainer: {
|
|
43
|
-
flexDirection: 'row',
|
|
51
|
+
flexDirection: 'row',
|
|
44
52
|
alignItems: 'center',
|
|
45
53
|
justifyContent: 'center',
|
|
46
54
|
},
|