cdslibrary 1.2.29 → 1.2.31
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.
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Text, StyleSheet, TouchableOpacity, View, Image } from "react-native";
|
|
3
|
+
import { MaterialIcons } from "@expo/vector-icons";
|
|
4
|
+
import { useTheme } from "../context/CDSThemeContext";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const CDSImageButton = ({ object, isActive, onPress }) => { // 👈 Añadimos isActive
|
|
9
|
+
const { theme } = useTheme();
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<TouchableOpacity
|
|
13
|
+
onPress={onPress}
|
|
14
|
+
style={[
|
|
15
|
+
styles.mainContainer,
|
|
16
|
+
{
|
|
17
|
+
backgroundColor: isActive
|
|
18
|
+
? theme.surface.neutral.primaryVariant // Color cuando está presionado
|
|
19
|
+
: theme.surface.neutral.primary,
|
|
20
|
+
gap: theme.space.xs,
|
|
21
|
+
padding: theme.space.xs,
|
|
22
|
+
// borderColor: isActive
|
|
23
|
+
// ? theme.outline.neutral.primary // Borde de color de marca si está activo
|
|
24
|
+
// : theme.outline.neutral.primary,
|
|
25
|
+
borderRadius: theme.radius.lg,
|
|
26
|
+
// Si está activo, quitamos la sombra o usamos una más pequeña (md)
|
|
27
|
+
...(!isActive && theme.shadows.lg),
|
|
28
|
+
// Si quieres que se vea "hundido", podrías bajar la escala
|
|
29
|
+
transform: [{ scale: isActive ? 0.99 : 1 }]
|
|
30
|
+
},
|
|
31
|
+
]}
|
|
32
|
+
>
|
|
33
|
+
<Image
|
|
34
|
+
source={object.image}
|
|
35
|
+
resizeMode="cover"
|
|
36
|
+
style={{
|
|
37
|
+
width: "100%",
|
|
38
|
+
height: 60,
|
|
39
|
+
}}
|
|
40
|
+
/>
|
|
41
|
+
<Text style={{ fontWeight: isActive ? 'bold' : 'normal' }}>
|
|
42
|
+
{object.label}
|
|
43
|
+
</Text>
|
|
44
|
+
</TouchableOpacity>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const styles = StyleSheet.create ({
|
|
51
|
+
|
|
52
|
+
mainContainer:{
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
flexGrow: 1,
|
|
55
|
+
maxWidth: 200,
|
|
56
|
+
height: 120
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StyleSheet, Text, View, Image } from 'react-native';
|
|
2
|
+
import { CDSImageButton } from './CDSImageButton';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const CDSImageButtonGroup = ({ array, onSelect }) => {
|
|
7
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
8
|
+
|
|
9
|
+
const handlePress = (id) => {
|
|
10
|
+
const nextId = id === selectedId ? null : id;
|
|
11
|
+
setSelectedId(nextId);
|
|
12
|
+
|
|
13
|
+
// Avisamos al padre qué objeto se seleccionó (o null si se deseleccionó)
|
|
14
|
+
if (onSelect) {
|
|
15
|
+
const selectedItem = array.find(item => item.id === nextId);
|
|
16
|
+
onSelect(selectedItem || null);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<View style={{ width: '100%' }}>
|
|
22
|
+
<View style={{
|
|
23
|
+
flexDirection: 'row', gap: 10,
|
|
24
|
+
width: '100%', justifyContent: 'center'
|
|
25
|
+
}}>
|
|
26
|
+
{array.map((item) => (
|
|
27
|
+
<CDSImageButton
|
|
28
|
+
key={item.id}
|
|
29
|
+
object={item}
|
|
30
|
+
isActive={selectedId === item.id}
|
|
31
|
+
onPress={() => handlePress(item.id)}
|
|
32
|
+
/>
|
|
33
|
+
))}
|
|
34
|
+
</View>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
}
|
package/components/CDSSelect.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
-
import {
|
|
3
|
-
View, Text, TouchableOpacity, StyleSheet, FlatList,
|
|
4
|
-
Animated,
|
|
2
|
+
import {
|
|
3
|
+
View, Text, TouchableOpacity, StyleSheet, FlatList,
|
|
4
|
+
Animated, Pressable, Platform
|
|
5
5
|
} from "react-native";
|
|
6
6
|
import { MaterialIcons } from "@expo/vector-icons";
|
|
7
7
|
import { useTheme } from "../context/CDSThemeContext";
|
|
@@ -18,20 +18,20 @@ const SelectOption = ({ item, isSelected, onSelect, theme }) => {
|
|
|
18
18
|
onMouseLeave={() => Platform.OS === 'web' && setIsHovered(false)}
|
|
19
19
|
style={({ pressed }) => [
|
|
20
20
|
styles.optionItem,
|
|
21
|
-
{
|
|
21
|
+
{
|
|
22
22
|
paddingHorizontal: theme.space.xs,
|
|
23
|
-
backgroundColor: (pressed || isHovered)
|
|
24
|
-
? theme.surface.neutral.secondary
|
|
25
|
-
: isSelected ? theme.surface.neutral.tertiary : 'transparent'
|
|
23
|
+
backgroundColor: (pressed || isHovered)
|
|
24
|
+
? theme.surface.neutral.secondary
|
|
25
|
+
: isSelected ? theme.surface.neutral.tertiary : 'transparent'
|
|
26
26
|
}
|
|
27
27
|
]}
|
|
28
28
|
>
|
|
29
29
|
<View style={styles.optionContent}>
|
|
30
30
|
<Text style={[
|
|
31
|
-
theme.typography.regular.sm,
|
|
32
|
-
{
|
|
33
|
-
color: theme.text.neutral.primary,
|
|
34
|
-
fontWeight: isSelected ? '700' : '400'
|
|
31
|
+
theme.typography.regular.sm,
|
|
32
|
+
{
|
|
33
|
+
color: theme.text.neutral.primary,
|
|
34
|
+
fontWeight: isSelected ? '700' : '400'
|
|
35
35
|
}
|
|
36
36
|
]}>
|
|
37
37
|
{item.label}
|
|
@@ -42,13 +42,13 @@ const SelectOption = ({ item, isSelected, onSelect, theme }) => {
|
|
|
42
42
|
);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export const CDSSelect = ({ label, options = [], onSelect,
|
|
45
|
+
export const CDSSelect = ({ label, options = [], onSelect, selectedValue = null }) => {
|
|
46
46
|
const { theme } = useTheme();
|
|
47
47
|
const [isOpen, setIsOpen] = useState(false);
|
|
48
48
|
const [dropdownTop, setDropdownTop] = useState(0);
|
|
49
49
|
const [dropdownWidth, setDropdownWidth] = useState(0);
|
|
50
50
|
const [dropdownLeft, setDropdownLeft] = useState(0);
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
const containerRef = useRef(null);
|
|
53
53
|
const animatedValue = useRef(new Animated.Value(0)).current;
|
|
54
54
|
|
|
@@ -90,55 +90,50 @@ export const CDSSelect = ({ label, options = [], onSelect, placeholder, selected
|
|
|
90
90
|
activeOpacity={0.8}
|
|
91
91
|
style={[
|
|
92
92
|
styles.inputContainer,
|
|
93
|
-
{
|
|
94
|
-
backgroundColor: theme.surface.neutral.primary,
|
|
95
|
-
borderColor: selectedItem ? theme.outline.neutral.tertiaryVariant : theme.outline.neutral.primary,
|
|
96
|
-
borderRadius: theme.radius.sm,
|
|
97
|
-
paddingHorizontal: theme.space.xs
|
|
93
|
+
{
|
|
94
|
+
backgroundColor: theme.surface.neutral.primary,
|
|
95
|
+
borderColor: selectedItem ? theme.outline.neutral.tertiaryVariant : theme.outline.neutral.primary,
|
|
96
|
+
borderRadius: theme.radius.sm,
|
|
97
|
+
paddingHorizontal: theme.space.xs
|
|
98
98
|
}
|
|
99
99
|
]}
|
|
100
100
|
onPress={toggleDropdown}
|
|
101
101
|
>
|
|
102
102
|
<Text style={selectedItem ? theme.typography.inputText.value : theme.typography.inputText.placeholder}>
|
|
103
|
-
{selectedItem ? selectedItem.label :
|
|
103
|
+
{selectedItem ? selectedItem.label : 'Selecciona una opción'}
|
|
104
104
|
</Text>
|
|
105
105
|
<MaterialIcons name={isOpen ? "expand-less" : "expand-more"} size={24} color={theme.text.neutral.primary} />
|
|
106
106
|
</TouchableOpacity>
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)}
|
|
138
|
-
/>
|
|
139
|
-
</Animated.View>
|
|
140
|
-
</Pressable>
|
|
141
|
-
</Modal>
|
|
108
|
+
{isOpen && (
|
|
109
|
+
<View
|
|
110
|
+
style={[
|
|
111
|
+
styles.dropdownInline,
|
|
112
|
+
{
|
|
113
|
+
marginTop: theme.space.xs,
|
|
114
|
+
backgroundColor: theme.surface.neutral.primary,
|
|
115
|
+
borderRadius: theme.radius.sm,
|
|
116
|
+
borderColor: theme.outline.neutral.primary,
|
|
117
|
+
maxHeight: 240,
|
|
118
|
+
}
|
|
119
|
+
]}
|
|
120
|
+
>
|
|
121
|
+
<FlatList
|
|
122
|
+
data={options}
|
|
123
|
+
keyExtractor={(item) => item.value.toString()}
|
|
124
|
+
renderItem={({ item }) => (
|
|
125
|
+
<SelectOption
|
|
126
|
+
item={item}
|
|
127
|
+
isSelected={item.value === selectedValue}
|
|
128
|
+
onSelect={handleSelect}
|
|
129
|
+
theme={theme}
|
|
130
|
+
/>
|
|
131
|
+
)}
|
|
132
|
+
// Importante para que el scroll funcione dentro de la lista expandida
|
|
133
|
+
nestedScrollEnabled={true}
|
|
134
|
+
/>
|
|
135
|
+
</View>
|
|
136
|
+
)}
|
|
142
137
|
</View>
|
|
143
138
|
);
|
|
144
139
|
};
|
|
@@ -146,8 +141,7 @@ export const CDSSelect = ({ label, options = [], onSelect, placeholder, selected
|
|
|
146
141
|
const styles = StyleSheet.create({
|
|
147
142
|
mainContainer: { width: '100%' },
|
|
148
143
|
inputContainer: { height: 48, borderWidth: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' },
|
|
149
|
-
|
|
150
|
-
dropdown: { position: 'absolute', borderWidth: 1, overflow: 'hidden' },
|
|
144
|
+
dropdownInline: { borderWidth: 1},
|
|
151
145
|
optionItem: { height: 48, justifyContent: 'center' },
|
|
152
146
|
optionContent: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }
|
|
153
147
|
});
|
package/package.json
CHANGED
|
@@ -164,26 +164,15 @@ export const CDSPrimitiveSpacing =
|
|
|
164
164
|
|
|
165
165
|
export const CDSPrimitiveShadows = (mode) => ({
|
|
166
166
|
md: {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
height: mode==='dark' ? 8 : 2
|
|
171
|
-
},
|
|
172
|
-
shadowOpacity: mode==='dark' ? 0.4 : 0.1,
|
|
173
|
-
shadowRadius: 6,
|
|
174
|
-
elevation: 3, // Valor aproximado para Android
|
|
167
|
+
// Usamos el formato de string que entiende el nuevo motor
|
|
168
|
+
boxShadow: `0px 2px 4px ${mode === 'dark' ? 'rgba(0,0,0,0.4)' : 'rgba(0,0,0,0.08)'}`,
|
|
169
|
+
elevation: 3, // Indispensable para Android nativo
|
|
175
170
|
},
|
|
176
171
|
|
|
177
|
-
// Basado en tu captura "lg": Y: 4, Blur: 8
|
|
178
172
|
lg: {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
height: mode==='dark' ? 10 : 4
|
|
183
|
-
},
|
|
184
|
-
shadowOpacity: mode==='dark' ? 0.5 : 0.1,
|
|
185
|
-
shadowRadius: 8,
|
|
186
|
-
elevation: 5, // Valor aproximado para Android
|
|
173
|
+
// Sombra más elegante con más blur (8px) y desplazamiento (4px)
|
|
174
|
+
boxShadow: `0px 4px 12px ${mode === 'dark' ? 'rgba(0,0,0,0.6)' : 'rgba(0,0,0,0.15)'}`,
|
|
175
|
+
elevation: 8,
|
|
187
176
|
},
|
|
188
177
|
});
|
|
189
178
|
|