vpt-sebraeds 0.0.27 → 0.0.29
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.
|
@@ -169,6 +169,15 @@ const Dropdown = ({
|
|
|
169
169
|
confirmButtonLabel,
|
|
170
170
|
onConfirm,
|
|
171
171
|
}) => {
|
|
172
|
+
// Estado centralizado para checkboxes
|
|
173
|
+
const [checkedItems, setCheckedItems] = useState({});
|
|
174
|
+
|
|
175
|
+
// Resetar estado quando o modal abre
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (isOpen) {
|
|
178
|
+
setCheckedItems({});
|
|
179
|
+
}
|
|
180
|
+
}, [isOpen]);
|
|
172
181
|
|
|
173
182
|
const handleSelect = (option) => {
|
|
174
183
|
if (onSelect) onSelect(option);
|
|
@@ -245,12 +254,20 @@ const Dropdown = ({
|
|
|
245
254
|
};
|
|
246
255
|
|
|
247
256
|
const RenderItem = ({ item, index }) => {
|
|
248
|
-
|
|
257
|
+
// Usar estado centralizado em vez de estado local
|
|
258
|
+
const isChecked = checkedItems[item.value] || false;
|
|
259
|
+
|
|
260
|
+
const handleCheckboxChange = () => {
|
|
261
|
+
setCheckedItems(prev => ({
|
|
262
|
+
...prev,
|
|
263
|
+
[item.value]: !prev[item.value]
|
|
264
|
+
}));
|
|
265
|
+
};
|
|
249
266
|
|
|
250
267
|
return item.isCheckbox ? (
|
|
251
268
|
<Checkbox
|
|
252
269
|
checked={isChecked}
|
|
253
|
-
onChange={
|
|
270
|
+
onChange={handleCheckboxChange}
|
|
254
271
|
label={item.label || item}
|
|
255
272
|
variant="check-line"
|
|
256
273
|
/>
|
|
@@ -304,11 +321,20 @@ const Dropdown = ({
|
|
|
304
321
|
))}
|
|
305
322
|
</ScrollView>
|
|
306
323
|
|
|
307
|
-
{
|
|
324
|
+
{hasCheckboxes && (
|
|
308
325
|
<View style={styles.buttonContainer}>
|
|
309
326
|
<Button
|
|
310
|
-
label={confirmButtonLabel}
|
|
311
|
-
onPress={
|
|
327
|
+
label={confirmButtonLabel || "Confirmar"}
|
|
328
|
+
onPress={() => {
|
|
329
|
+
// Coletar itens selecionados
|
|
330
|
+
const selectedItems = options.filter(opt => checkedItems[opt.value]);
|
|
331
|
+
|
|
332
|
+
// Enviar para o componente pai
|
|
333
|
+
if (onSelect) onSelect(selectedItems);
|
|
334
|
+
if (onConfirm) onConfirm(selectedItems);
|
|
335
|
+
|
|
336
|
+
setIsOpen(false);
|
|
337
|
+
}}
|
|
312
338
|
size="large"
|
|
313
339
|
variant="filled"
|
|
314
340
|
expand
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Dropdown/index.jsx"],"names":[],"mappings":"AA+FO,yDA6DN;;kBA3JkD,OAAO;AA+J1D;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Dropdown/index.jsx"],"names":[],"mappings":"AA+FO,yDA6DN;;kBA3JkD,OAAO;AA+J1D;;;;;;;;;;sBA4LC"}
|
|
@@ -136,6 +136,14 @@ export const DropdownCommitments = () => {
|
|
|
136
136
|
};
|
|
137
137
|
const { height: screenHeight } = Dimensions.get('window');
|
|
138
138
|
const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen = false, isCheckbox = false, setIsOpen = () => { }, confirmButtonLabel, onConfirm, }) => {
|
|
139
|
+
// Estado centralizado para checkboxes
|
|
140
|
+
const [checkedItems, setCheckedItems] = useState({});
|
|
141
|
+
// Resetar estado quando o modal abre
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (isOpen) {
|
|
144
|
+
setCheckedItems({});
|
|
145
|
+
}
|
|
146
|
+
}, [isOpen]);
|
|
139
147
|
const handleSelect = (option) => {
|
|
140
148
|
if (onSelect)
|
|
141
149
|
onSelect(option);
|
|
@@ -195,8 +203,15 @@ const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen
|
|
|
195
203
|
</TouchableWithoutFeedback>);
|
|
196
204
|
};
|
|
197
205
|
const RenderItem = ({ item, index }) => {
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
// Usar estado centralizado em vez de estado local
|
|
207
|
+
const isChecked = checkedItems[item.value] || false;
|
|
208
|
+
const handleCheckboxChange = () => {
|
|
209
|
+
setCheckedItems(prev => ({
|
|
210
|
+
...prev,
|
|
211
|
+
[item.value]: !prev[item.value]
|
|
212
|
+
}));
|
|
213
|
+
};
|
|
214
|
+
return item.isCheckbox ? (<Checkbox checked={isChecked} onChange={handleCheckboxChange} label={item.label || item} variant="check-line"/>) : (<RippleItem item={item} index={index} onPress={handleSelect}/>);
|
|
200
215
|
};
|
|
201
216
|
const hasCheckboxes = options.some(item => item.isCheckbox);
|
|
202
217
|
return (<View style={styles.wrapper}>
|
|
@@ -218,8 +233,17 @@ const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen
|
|
|
218
233
|
{options.map((item, index) => (<RenderItem key={index.toString()} item={item} index={index}/>))}
|
|
219
234
|
</ScrollView>
|
|
220
235
|
|
|
221
|
-
{
|
|
222
|
-
<Button label={confirmButtonLabel} onPress={
|
|
236
|
+
{hasCheckboxes && (<View style={styles.buttonContainer}>
|
|
237
|
+
<Button label={confirmButtonLabel || "Confirmar"} onPress={() => {
|
|
238
|
+
// Coletar itens selecionados
|
|
239
|
+
const selectedItems = options.filter(opt => checkedItems[opt.value]);
|
|
240
|
+
// Enviar para o componente pai
|
|
241
|
+
if (onSelect)
|
|
242
|
+
onSelect(selectedItems);
|
|
243
|
+
if (onConfirm)
|
|
244
|
+
onConfirm(selectedItems);
|
|
245
|
+
setIsOpen(false);
|
|
246
|
+
}} size="large" variant="filled" expand/>
|
|
223
247
|
</View>)}
|
|
224
248
|
</View>
|
|
225
249
|
</View>
|