vpt-sebraeds 0.0.28 → 0.0.30
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.
|
@@ -157,6 +157,7 @@ export const DropdownCommitments = () => {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
const { height: screenHeight } = Dimensions.get('window');
|
|
160
|
+
const ITEM_HEIGHT = 50;
|
|
160
161
|
|
|
161
162
|
const Dropdown = ({
|
|
162
163
|
title,
|
|
@@ -168,10 +169,29 @@ const Dropdown = ({
|
|
|
168
169
|
setIsOpen = () => { },
|
|
169
170
|
confirmButtonLabel,
|
|
170
171
|
onConfirm,
|
|
172
|
+
displayMode = 'list',
|
|
173
|
+
selectedValue,
|
|
171
174
|
}) => {
|
|
175
|
+
// Estado centralizado para checkboxes
|
|
176
|
+
const [checkedItems, setCheckedItems] = useState({});
|
|
177
|
+
const scrollViewRef = useRef(null);
|
|
178
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
179
|
+
|
|
180
|
+
// Resetar estado quando o modal abre
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (isOpen) {
|
|
183
|
+
setCheckedItems({});
|
|
184
|
+
// Para modo picker, encontrar índice do item selecionado
|
|
185
|
+
if (displayMode === 'picker' && selectedValue) {
|
|
186
|
+
const idx = options.findIndex(opt => opt.value === selectedValue || opt === selectedValue);
|
|
187
|
+
setSelectedIndex(idx >= 0 ? idx : 0);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, [isOpen, displayMode, selectedValue, options]);
|
|
172
191
|
|
|
173
192
|
const handleSelect = (option) => {
|
|
174
193
|
if (onSelect) onSelect(option);
|
|
194
|
+
setIsOpen(false); // Fechar modal após seleção
|
|
175
195
|
};
|
|
176
196
|
|
|
177
197
|
const RippleItem = ({ item, index, onPress }) => {
|
|
@@ -244,13 +264,46 @@ const Dropdown = ({
|
|
|
244
264
|
);
|
|
245
265
|
};
|
|
246
266
|
|
|
267
|
+
// Picker Item com estilos dinâmicos baseados na distância do centro
|
|
268
|
+
const PickerItem = ({ item, index }) => {
|
|
269
|
+
const distance = Math.abs(index - selectedIndex);
|
|
270
|
+
const isSelected = index === selectedIndex;
|
|
271
|
+
|
|
272
|
+
const getTextStyle = () => {
|
|
273
|
+
if (isSelected) return styles.pickerSelectedText;
|
|
274
|
+
if (distance === 1) return styles.pickerAdjacentText;
|
|
275
|
+
return styles.pickerDistantText;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<TouchableOpacity
|
|
280
|
+
style={styles.pickerItem}
|
|
281
|
+
onPress={() => {
|
|
282
|
+
setSelectedIndex(index);
|
|
283
|
+
handleSelect(item);
|
|
284
|
+
}}
|
|
285
|
+
activeOpacity={0.7}
|
|
286
|
+
>
|
|
287
|
+
<Text style={[styles.pickerItemText, getTextStyle()]}>{item.label || item}</Text>
|
|
288
|
+
</TouchableOpacity>
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
|
|
247
292
|
const RenderItem = ({ item, index }) => {
|
|
248
|
-
|
|
293
|
+
// Usar estado centralizado em vez de estado local
|
|
294
|
+
const isChecked = checkedItems[item.value] || false;
|
|
295
|
+
|
|
296
|
+
const handleCheckboxChange = () => {
|
|
297
|
+
setCheckedItems(prev => ({
|
|
298
|
+
...prev,
|
|
299
|
+
[item.value]: !prev[item.value]
|
|
300
|
+
}));
|
|
301
|
+
};
|
|
249
302
|
|
|
250
303
|
return item.isCheckbox ? (
|
|
251
304
|
<Checkbox
|
|
252
305
|
checked={isChecked}
|
|
253
|
-
onChange={
|
|
306
|
+
onChange={handleCheckboxChange}
|
|
254
307
|
label={item.label || item}
|
|
255
308
|
variant="check-line"
|
|
256
309
|
/>
|
|
@@ -264,6 +317,47 @@ const Dropdown = ({
|
|
|
264
317
|
};
|
|
265
318
|
|
|
266
319
|
const hasCheckboxes = options.some(item => item.isCheckbox);
|
|
320
|
+
const isPicker = displayMode === 'picker';
|
|
321
|
+
|
|
322
|
+
// Renderizar conteúdo baseado no modo
|
|
323
|
+
const renderContent = () => {
|
|
324
|
+
if (isPicker) {
|
|
325
|
+
return (
|
|
326
|
+
<View style={styles.pickerContainer}>
|
|
327
|
+
<ScrollView
|
|
328
|
+
ref={scrollViewRef}
|
|
329
|
+
style={styles.pickerScrollView}
|
|
330
|
+
contentContainerStyle={{
|
|
331
|
+
paddingVertical: ITEM_HEIGHT * 2
|
|
332
|
+
}}
|
|
333
|
+
showsVerticalScrollIndicator={false}
|
|
334
|
+
snapToInterval={ITEM_HEIGHT}
|
|
335
|
+
decelerationRate="fast"
|
|
336
|
+
onMomentumScrollEnd={(e) => {
|
|
337
|
+
const idx = Math.round(e.nativeEvent.contentOffset.y / ITEM_HEIGHT);
|
|
338
|
+
const clampedIdx = Math.max(0, Math.min(idx, options.length - 1));
|
|
339
|
+
setSelectedIndex(clampedIdx);
|
|
340
|
+
}}
|
|
341
|
+
onLayout={() => {
|
|
342
|
+
if (scrollViewRef.current && selectedIndex >= 0) {
|
|
343
|
+
scrollViewRef.current.scrollTo({ y: selectedIndex * ITEM_HEIGHT, animated: false });
|
|
344
|
+
}
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
{options.map((item, index) => (
|
|
348
|
+
<PickerItem key={index.toString()} item={item} index={index} />
|
|
349
|
+
))}
|
|
350
|
+
</ScrollView>
|
|
351
|
+
</View>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return (
|
|
356
|
+
<ScrollView style={styles.optionsList} contentContainerStyle={{ paddingBottom: 8 }} showsVerticalScrollIndicator={false} bounces={false}>
|
|
357
|
+
{options.map((item, index) => (<RenderItem key={index.toString()} item={item} index={index} />))}
|
|
358
|
+
</ScrollView>
|
|
359
|
+
);
|
|
360
|
+
};
|
|
267
361
|
|
|
268
362
|
return (
|
|
269
363
|
<View style={styles.wrapper}>
|
|
@@ -284,32 +378,27 @@ const Dropdown = ({
|
|
|
284
378
|
{/* Conteúdo do modal - não propaga toque para o overlay */}
|
|
285
379
|
<View style={styles.modalContainer}>
|
|
286
380
|
<View style={styles.modalHeader}>
|
|
287
|
-
<TouchableOpacity
|
|
288
|
-
onPress={() => setIsOpen(false)}
|
|
289
|
-
style={styles.closeButton}
|
|
290
|
-
>
|
|
291
|
-
<Icon name="subtract-line" size={26} color="#687499" />
|
|
292
|
-
</TouchableOpacity>
|
|
293
381
|
<Text style={styles.modalTitle}>{title || "Título"}</Text>
|
|
294
382
|
</View>
|
|
295
383
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
showsVerticalScrollIndicator={false}
|
|
300
|
-
bounces={false}
|
|
301
|
-
>
|
|
302
|
-
{options.map((item, index) => (
|
|
303
|
-
<RenderItem key={index.toString()} item={item} index={index} />
|
|
304
|
-
))}
|
|
305
|
-
</ScrollView>
|
|
306
|
-
|
|
307
|
-
{hasCheckboxes && (
|
|
384
|
+
{renderContent()}
|
|
385
|
+
|
|
386
|
+
{(hasCheckboxes || isPicker) && (
|
|
308
387
|
<View style={styles.buttonContainer}>
|
|
309
388
|
<Button
|
|
310
389
|
label={confirmButtonLabel || "Confirmar"}
|
|
311
390
|
onPress={() => {
|
|
312
|
-
if (
|
|
391
|
+
if (isPicker) {
|
|
392
|
+
// Para picker, enviar o item selecionado pelo índice
|
|
393
|
+
const selectedItem = options[selectedIndex];
|
|
394
|
+
if (onSelect) onSelect(selectedItem);
|
|
395
|
+
if (onConfirm) onConfirm(selectedItem);
|
|
396
|
+
} else {
|
|
397
|
+
// Para checkboxes, coletar itens selecionados
|
|
398
|
+
const selectedItems = options.filter(opt => checkedItems[opt.value]);
|
|
399
|
+
if (onSelect) onSelect(selectedItems);
|
|
400
|
+
if (onConfirm) onConfirm(selectedItems);
|
|
401
|
+
}
|
|
313
402
|
setIsOpen(false);
|
|
314
403
|
}}
|
|
315
404
|
size="large"
|
|
@@ -395,6 +484,38 @@ const styles = StyleSheet.create({
|
|
|
395
484
|
paddingTop: 16,
|
|
396
485
|
paddingBottom: 8,
|
|
397
486
|
},
|
|
487
|
+
// Picker styles
|
|
488
|
+
pickerContainer: {
|
|
489
|
+
height: ITEM_HEIGHT * 5,
|
|
490
|
+
overflow: 'hidden',
|
|
491
|
+
},
|
|
492
|
+
pickerScrollView: {
|
|
493
|
+
flex: 1,
|
|
494
|
+
},
|
|
495
|
+
pickerItem: {
|
|
496
|
+
height: ITEM_HEIGHT,
|
|
497
|
+
justifyContent: 'center',
|
|
498
|
+
alignItems: 'center',
|
|
499
|
+
},
|
|
500
|
+
pickerItemText: {
|
|
501
|
+
fontFamily: 'Nunito Sans',
|
|
502
|
+
textAlign: 'center',
|
|
503
|
+
},
|
|
504
|
+
pickerSelectedText: {
|
|
505
|
+
fontSize: 24,
|
|
506
|
+
fontWeight: 'bold',
|
|
507
|
+
color: '#1B244B',
|
|
508
|
+
},
|
|
509
|
+
pickerAdjacentText: {
|
|
510
|
+
fontSize: 18,
|
|
511
|
+
fontWeight: '500',
|
|
512
|
+
color: '#687499',
|
|
513
|
+
},
|
|
514
|
+
pickerDistantText: {
|
|
515
|
+
fontSize: 14,
|
|
516
|
+
fontWeight: '400',
|
|
517
|
+
color: '#CED2DE',
|
|
518
|
+
},
|
|
398
519
|
});
|
|
399
520
|
|
|
400
521
|
export default Dropdown;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function DropdownCommitments(): React.JSX.Element;
|
|
2
2
|
export default Dropdown;
|
|
3
3
|
import React from 'react';
|
|
4
|
-
declare function Dropdown({ title, onSelect, options, withSeparator, isOpen, isCheckbox, setIsOpen, confirmButtonLabel, onConfirm, }: {
|
|
4
|
+
declare function Dropdown({ title, onSelect, options, withSeparator, isOpen, isCheckbox, setIsOpen, confirmButtonLabel, onConfirm, displayMode, selectedValue, }: {
|
|
5
5
|
title: any;
|
|
6
6
|
onSelect: any;
|
|
7
7
|
options?: never[] | undefined;
|
|
@@ -11,5 +11,7 @@ declare function Dropdown({ title, onSelect, options, withSeparator, isOpen, isC
|
|
|
11
11
|
setIsOpen?: (() => void) | undefined;
|
|
12
12
|
confirmButtonLabel: any;
|
|
13
13
|
onConfirm: any;
|
|
14
|
+
displayMode?: string | undefined;
|
|
15
|
+
selectedValue: any;
|
|
14
16
|
}): React.JSX.Element;
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Dropdown/index.jsx"],"names":[],"mappings":"AA+FO,yDA6DN;;kBA3JkD,OAAO;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/Dropdown/index.jsx"],"names":[],"mappings":"AA+FO,yDA6DN;;kBA3JkD,OAAO;AAgK1D;;;;;;;;;;;;sBA6PC"}
|
|
@@ -135,10 +135,27 @@ export const DropdownCommitments = () => {
|
|
|
135
135
|
</View>);
|
|
136
136
|
};
|
|
137
137
|
const { height: screenHeight } = Dimensions.get('window');
|
|
138
|
-
const
|
|
138
|
+
const ITEM_HEIGHT = 50;
|
|
139
|
+
const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen = false, isCheckbox = false, setIsOpen = () => { }, confirmButtonLabel, onConfirm, displayMode = 'list', selectedValue, }) => {
|
|
140
|
+
// Estado centralizado para checkboxes
|
|
141
|
+
const [checkedItems, setCheckedItems] = useState({});
|
|
142
|
+
const scrollViewRef = useRef(null);
|
|
143
|
+
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
144
|
+
// Resetar estado quando o modal abre
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (isOpen) {
|
|
147
|
+
setCheckedItems({});
|
|
148
|
+
// Para modo picker, encontrar índice do item selecionado
|
|
149
|
+
if (displayMode === 'picker' && selectedValue) {
|
|
150
|
+
const idx = options.findIndex(opt => opt.value === selectedValue || opt === selectedValue);
|
|
151
|
+
setSelectedIndex(idx >= 0 ? idx : 0);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}, [isOpen, displayMode, selectedValue, options]);
|
|
139
155
|
const handleSelect = (option) => {
|
|
140
156
|
if (onSelect)
|
|
141
157
|
onSelect(option);
|
|
158
|
+
setIsOpen(false); // Fechar modal após seleção
|
|
142
159
|
};
|
|
143
160
|
const RippleItem = ({ item, index, onPress }) => {
|
|
144
161
|
const [ripples, setRipples] = useState([]);
|
|
@@ -194,11 +211,60 @@ const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen
|
|
|
194
211
|
</View>
|
|
195
212
|
</TouchableWithoutFeedback>);
|
|
196
213
|
};
|
|
214
|
+
// Picker Item com estilos dinâmicos baseados na distância do centro
|
|
215
|
+
const PickerItem = ({ item, index }) => {
|
|
216
|
+
const distance = Math.abs(index - selectedIndex);
|
|
217
|
+
const isSelected = index === selectedIndex;
|
|
218
|
+
const getTextStyle = () => {
|
|
219
|
+
if (isSelected)
|
|
220
|
+
return styles.pickerSelectedText;
|
|
221
|
+
if (distance === 1)
|
|
222
|
+
return styles.pickerAdjacentText;
|
|
223
|
+
return styles.pickerDistantText;
|
|
224
|
+
};
|
|
225
|
+
return (<TouchableOpacity style={styles.pickerItem} onPress={() => {
|
|
226
|
+
setSelectedIndex(index);
|
|
227
|
+
handleSelect(item);
|
|
228
|
+
}} activeOpacity={0.7}>
|
|
229
|
+
<Text style={[styles.pickerItemText, getTextStyle()]}>{item.label || item}</Text>
|
|
230
|
+
</TouchableOpacity>);
|
|
231
|
+
};
|
|
197
232
|
const RenderItem = ({ item, index }) => {
|
|
198
|
-
|
|
199
|
-
|
|
233
|
+
// Usar estado centralizado em vez de estado local
|
|
234
|
+
const isChecked = checkedItems[item.value] || false;
|
|
235
|
+
const handleCheckboxChange = () => {
|
|
236
|
+
setCheckedItems(prev => ({
|
|
237
|
+
...prev,
|
|
238
|
+
[item.value]: !prev[item.value]
|
|
239
|
+
}));
|
|
240
|
+
};
|
|
241
|
+
return item.isCheckbox ? (<Checkbox checked={isChecked} onChange={handleCheckboxChange} label={item.label || item} variant="check-line"/>) : (<RippleItem item={item} index={index} onPress={handleSelect}/>);
|
|
200
242
|
};
|
|
201
243
|
const hasCheckboxes = options.some(item => item.isCheckbox);
|
|
244
|
+
const isPicker = displayMode === 'picker';
|
|
245
|
+
// Renderizar conteúdo baseado no modo
|
|
246
|
+
const renderContent = () => {
|
|
247
|
+
if (isPicker) {
|
|
248
|
+
return (<View style={styles.pickerContainer}>
|
|
249
|
+
<ScrollView ref={scrollViewRef} style={styles.pickerScrollView} contentContainerStyle={{
|
|
250
|
+
paddingVertical: ITEM_HEIGHT * 2
|
|
251
|
+
}} showsVerticalScrollIndicator={false} snapToInterval={ITEM_HEIGHT} decelerationRate="fast" onMomentumScrollEnd={(e) => {
|
|
252
|
+
const idx = Math.round(e.nativeEvent.contentOffset.y / ITEM_HEIGHT);
|
|
253
|
+
const clampedIdx = Math.max(0, Math.min(idx, options.length - 1));
|
|
254
|
+
setSelectedIndex(clampedIdx);
|
|
255
|
+
}} onLayout={() => {
|
|
256
|
+
if (scrollViewRef.current && selectedIndex >= 0) {
|
|
257
|
+
scrollViewRef.current.scrollTo({ y: selectedIndex * ITEM_HEIGHT, animated: false });
|
|
258
|
+
}
|
|
259
|
+
}}>
|
|
260
|
+
{options.map((item, index) => (<PickerItem key={index.toString()} item={item} index={index}/>))}
|
|
261
|
+
</ScrollView>
|
|
262
|
+
</View>);
|
|
263
|
+
}
|
|
264
|
+
return (<ScrollView style={styles.optionsList} contentContainerStyle={{ paddingBottom: 8 }} showsVerticalScrollIndicator={false} bounces={false}>
|
|
265
|
+
{options.map((item, index) => (<RenderItem key={index.toString()} item={item} index={index}/>))}
|
|
266
|
+
</ScrollView>);
|
|
267
|
+
};
|
|
202
268
|
return (<View style={styles.wrapper}>
|
|
203
269
|
<Modal visible={isOpen} transparent={true} animationType="fade" onRequestClose={() => setIsOpen(false)}>
|
|
204
270
|
<View style={styles.overlay}>
|
|
@@ -208,20 +274,29 @@ const Dropdown = ({ title, onSelect, options = [], withSeparator = false, isOpen
|
|
|
208
274
|
{/* Conteúdo do modal - não propaga toque para o overlay */}
|
|
209
275
|
<View style={styles.modalContainer}>
|
|
210
276
|
<View style={styles.modalHeader}>
|
|
211
|
-
<TouchableOpacity onPress={() => setIsOpen(false)} style={styles.closeButton}>
|
|
212
|
-
<Icon name="subtract-line" size={26} color="#687499"/>
|
|
213
|
-
</TouchableOpacity>
|
|
214
277
|
<Text style={styles.modalTitle}>{title || "Título"}</Text>
|
|
215
278
|
</View>
|
|
216
279
|
|
|
217
|
-
|
|
218
|
-
{options.map((item, index) => (<RenderItem key={index.toString()} item={item} index={index}/>))}
|
|
219
|
-
</ScrollView>
|
|
280
|
+
{renderContent()}
|
|
220
281
|
|
|
221
|
-
{hasCheckboxes && (<View style={styles.buttonContainer}>
|
|
282
|
+
{(hasCheckboxes || isPicker) && (<View style={styles.buttonContainer}>
|
|
222
283
|
<Button label={confirmButtonLabel || "Confirmar"} onPress={() => {
|
|
223
|
-
if (
|
|
224
|
-
|
|
284
|
+
if (isPicker) {
|
|
285
|
+
// Para picker, enviar o item selecionado pelo índice
|
|
286
|
+
const selectedItem = options[selectedIndex];
|
|
287
|
+
if (onSelect)
|
|
288
|
+
onSelect(selectedItem);
|
|
289
|
+
if (onConfirm)
|
|
290
|
+
onConfirm(selectedItem);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
// Para checkboxes, coletar itens selecionados
|
|
294
|
+
const selectedItems = options.filter(opt => checkedItems[opt.value]);
|
|
295
|
+
if (onSelect)
|
|
296
|
+
onSelect(selectedItems);
|
|
297
|
+
if (onConfirm)
|
|
298
|
+
onConfirm(selectedItems);
|
|
299
|
+
}
|
|
225
300
|
setIsOpen(false);
|
|
226
301
|
}} size="large" variant="filled" expand/>
|
|
227
302
|
</View>)}
|
|
@@ -300,5 +375,37 @@ const styles = StyleSheet.create({
|
|
|
300
375
|
paddingTop: 16,
|
|
301
376
|
paddingBottom: 8,
|
|
302
377
|
},
|
|
378
|
+
// Picker styles
|
|
379
|
+
pickerContainer: {
|
|
380
|
+
height: ITEM_HEIGHT * 5,
|
|
381
|
+
overflow: 'hidden',
|
|
382
|
+
},
|
|
383
|
+
pickerScrollView: {
|
|
384
|
+
flex: 1,
|
|
385
|
+
},
|
|
386
|
+
pickerItem: {
|
|
387
|
+
height: ITEM_HEIGHT,
|
|
388
|
+
justifyContent: 'center',
|
|
389
|
+
alignItems: 'center',
|
|
390
|
+
},
|
|
391
|
+
pickerItemText: {
|
|
392
|
+
fontFamily: 'Nunito Sans',
|
|
393
|
+
textAlign: 'center',
|
|
394
|
+
},
|
|
395
|
+
pickerSelectedText: {
|
|
396
|
+
fontSize: 24,
|
|
397
|
+
fontWeight: 'bold',
|
|
398
|
+
color: '#1B244B',
|
|
399
|
+
},
|
|
400
|
+
pickerAdjacentText: {
|
|
401
|
+
fontSize: 18,
|
|
402
|
+
fontWeight: '500',
|
|
403
|
+
color: '#687499',
|
|
404
|
+
},
|
|
405
|
+
pickerDistantText: {
|
|
406
|
+
fontSize: 14,
|
|
407
|
+
fontWeight: '400',
|
|
408
|
+
color: '#CED2DE',
|
|
409
|
+
},
|
|
303
410
|
});
|
|
304
411
|
export default Dropdown;
|