Nessuna descrizione

icon-button.tsx 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Pressable, StyleSheet } from 'react-native';
  2. import { Colors } from '@/constants/theme';
  3. import { useColorScheme } from '@/hooks/use-color-scheme';
  4. import { IconSymbol } from '@/components/ui/icon-symbol';
  5. type Variant = 'default' | 'danger';
  6. type Props = {
  7. name: React.ComponentProps<typeof IconSymbol>['name'];
  8. onPress: () => void;
  9. accessibilityLabel: string;
  10. testID?: string;
  11. variant?: Variant;
  12. };
  13. export function IconButton({
  14. name,
  15. onPress,
  16. accessibilityLabel,
  17. testID,
  18. variant = 'default',
  19. }: Props) {
  20. const theme = useColorScheme() ?? 'light';
  21. const tint = Colors[theme].tint;
  22. const danger = theme === 'light' ? '#B42318' : '#F97066';
  23. const iconColor = variant === 'danger' ? danger : tint;
  24. return (
  25. <Pressable
  26. accessibilityRole="button"
  27. accessibilityLabel={accessibilityLabel}
  28. testID={testID}
  29. onPress={onPress}
  30. style={({ pressed }) => [
  31. styles.base,
  32. { opacity: pressed ? 0.7 : 1 },
  33. ]}>
  34. <IconSymbol size={20} name={name} color={iconColor} />
  35. </Pressable>
  36. );
  37. }
  38. const styles = StyleSheet.create({
  39. base: {
  40. padding: 6,
  41. borderRadius: 999,
  42. },
  43. });