eletrotupi / tcc/ frontend/components/ui/icon-symbol.tsxc901c35af9c84b6a29e5185545ced1129f33b8f4
1.2 KB | 41 lines Raw
1
// Fallback for using MaterialIcons on Android and web.
2

3
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
4
import { ComponentProps } from 'react';
5
import { OpaqueColorValue, type StyleProp, type TextStyle } from 'react-native';
6

7
type MaterialIconName = ComponentProps<typeof MaterialIcons>['name'];
8

9
const MAPPING = {
10
  'house.fill': 'home',
11
  'notifications': 'notifications',
12
  'add-circle': 'add-circle',
13
  'history': 'history',
14
  'lightbulb-outline': 'lightbulb-outline',
15
  'paperplane.fill': 'send',
16
  'chevron.left.forwardslash.chevron.right': 'code',
17
  'chevron.right': 'chevron-right',
18
  'bolt': 'bolt',
19
  'settings.fill': 'settings',
20
  'book': 'book'
21
} as const satisfies Record<string, MaterialIconName>;
22

23
type IconSymbolName = keyof typeof MAPPING;
24

25
/**
26
 * An icon component that uses Material Icons on all platforms.
27
 * Icon `name`s are based on SF Symbols and require manual mapping to Material Icons.
28
 */
29
export function IconSymbol({
30
  name,
31
  size = 24,
32
  color,
33
  style,
34
}: {
35
  name: IconSymbolName;
36
  size?: number;
37
  color: string | OpaqueColorValue;
38
  style?: StyleProp<TextStyle>;
39
}) {
40
  return <MaterialIcons color={color} size={size} name={MAPPING[name]} style={style} />;
41
}