Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AppSymbol.tsx

310 lines14.0 KB

1import type { Icon } from "@tabler/icons-react-native/types";
2/*
3 * Keep these as per-icon exports. Importing the package root eagerly registers
4 * the entire Tabler icon set in Metro.
5 */
6import IconAdjustmentsHorizontal from "@tabler/icons-react-native/IconAdjustmentsHorizontal";
7import IconAlignLeft from "@tabler/icons-react-native/IconAlignLeft";
8import IconAlertCircle from "@tabler/icons-react-native/IconAlertCircle";
9import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
10import IconApps from "@tabler/icons-react-native/IconApps";
11import IconArchive from "@tabler/icons-react-native/IconArchive";
12import IconArrowBackUp from "@tabler/icons-react-native/IconArrowBackUp";
13import IconArrowDown from "@tabler/icons-react-native/IconArrowDown";
14import IconArrowForwardUp from "@tabler/icons-react-native/IconArrowForwardUp";
15import IconArrowLeft from "@tabler/icons-react-native/IconArrowLeft";
16import IconArrowRight from "@tabler/icons-react-native/IconArrowRight";
17import IconArrowDownCircle from "@tabler/icons-react-native/IconArrowDownCircle";
18import IconArrowRightCircle from "@tabler/icons-react-native/IconArrowRightCircle";
19import IconArrowUp from "@tabler/icons-react-native/IconArrowUp";
20import IconArrowUpCircle from "@tabler/icons-react-native/IconArrowUpCircle";
21import IconArrowUpRight from "@tabler/icons-react-native/IconArrowUpRight";
22import IconArrowUpRightCircle from "@tabler/icons-react-native/IconArrowUpRightCircle";
23import IconArrowsLeftRight from "@tabler/icons-react-native/IconArrowsLeftRight";
24import IconArrowsDiagonal2 from "@tabler/icons-react-native/IconArrowsDiagonal2";
25import IconArrowsMinimize from "@tabler/icons-react-native/IconArrowsMinimize";
26import IconBellRinging from "@tabler/icons-react-native/IconBellRinging";
27import IconBolt from "@tabler/icons-react-native/IconBolt";
28import IconBox from "@tabler/icons-react-native/IconBox";
29import IconBrain from "@tabler/icons-react-native/IconBrain";
30import IconCamera from "@tabler/icons-react-native/IconCamera";
31import IconChartBar from "@tabler/icons-react-native/IconChartBar";
32import IconCheck from "@tabler/icons-react-native/IconCheck";
33import IconCloud from "@tabler/icons-react-native/IconCloud";
34import IconChevronDown from "@tabler/icons-react-native/IconChevronDown";
35import IconChevronLeft from "@tabler/icons-react-native/IconChevronLeft";
36import IconChevronRight from "@tabler/icons-react-native/IconChevronRight";
37import IconChevronUp from "@tabler/icons-react-native/IconChevronUp";
38import IconCircle from "@tabler/icons-react-native/IconCircle";
39import IconCircleCheck from "@tabler/icons-react-native/IconCircleCheck";
40import IconCircleXFilled from "@tabler/icons-react-native/IconCircleXFilled";
41import IconTicket from "@tabler/icons-react-native/IconTicket";
42import IconClock from "@tabler/icons-react-native/IconClock";
43import IconCode from "@tabler/icons-react-native/IconCode";
44import IconCopy from "@tabler/icons-react-native/IconCopy";
45import IconDatabase from "@tabler/icons-react-native/IconDatabase";
46import IconDeviceDesktop from "@tabler/icons-react-native/IconDeviceDesktop";
47import IconDeviceLaptop from "@tabler/icons-react-native/IconDeviceLaptop";
48import IconDeviceMobile from "@tabler/icons-react-native/IconDeviceMobile";
49import IconDots from "@tabler/icons-react-native/IconDots";
50import IconDotsVertical from "@tabler/icons-react-native/IconDotsVertical";
51import IconDotsCircleHorizontal from "@tabler/icons-react-native/IconDotsCircleHorizontal";
52import IconEdit from "@tabler/icons-react-native/IconEdit";
53import IconExternalLink from "@tabler/icons-react-native/IconExternalLink";
54import IconEye from "@tabler/icons-react-native/IconEye";
55import IconFileText from "@tabler/icons-react-native/IconFileText";
56import IconFilter from "@tabler/icons-react-native/IconFilter";
57import IconFilterFilled from "@tabler/icons-react-native/IconFilterFilled";
58import IconFolder from "@tabler/icons-react-native/IconFolder";
59import IconFolderOpen from "@tabler/icons-react-native/IconFolderOpen";
60import IconFolderPlus from "@tabler/icons-react-native/IconFolderPlus";
61import IconGitBranch from "@tabler/icons-react-native/IconGitBranch";
62import IconGitMerge from "@tabler/icons-react-native/IconGitMerge";
63import IconGitPullRequest from "@tabler/icons-react-native/IconGitPullRequest";
64import IconHammer from "@tabler/icons-react-native/IconHammer";
65import IconHome from "@tabler/icons-react-native/IconHome";
66import IconInfoCircle from "@tabler/icons-react-native/IconInfoCircle";
67import IconKeyboard from "@tabler/icons-react-native/IconKeyboard";
68import IconKeyboardHide from "@tabler/icons-react-native/IconKeyboardHide";
69import IconLock from "@tabler/icons-react-native/IconLock";
70import IconLayoutColumns from "@tabler/icons-react-native/IconLayoutColumns";
71import IconLayoutSidebar from "@tabler/icons-react-native/IconLayoutSidebar";
72import IconLayoutSidebarRight from "@tabler/icons-react-native/IconLayoutSidebarRight";
73import IconLetterSpacing from "@tabler/icons-react-native/IconLetterSpacing";
74import IconMicrophone from "@tabler/icons-react-native/IconMicrophone";
75import IconLink from "@tabler/icons-react-native/IconLink";
76import IconListNumbers from "@tabler/icons-react-native/IconListNumbers";
77import IconMenu2 from "@tabler/icons-react-native/IconMenu2";
78import IconMessage from "@tabler/icons-react-native/IconMessage";
79import IconMinus from "@tabler/icons-react-native/IconMinus";
80import IconMoon from "@tabler/icons-react-native/IconMoon";
81import IconNetwork from "@tabler/icons-react-native/IconNetwork";
82import IconPalette from "@tabler/icons-react-native/IconPalette";
83import IconPencil from "@tabler/icons-react-native/IconPencil";
84import IconPhoto from "@tabler/icons-react-native/IconPhoto";
85import IconPin from "@tabler/icons-react-native/IconPin";
86import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
87import IconPlayerPlay from "@tabler/icons-react-native/IconPlayerPlay";
88import IconPlayerStopFilled from "@tabler/icons-react-native/IconPlayerStopFilled";
89import IconPlus from "@tabler/icons-react-native/IconPlus";
90import IconQrcode from "@tabler/icons-react-native/IconQrcode";
91import IconRefresh from "@tabler/icons-react-native/IconRefresh";
92import IconSearch from "@tabler/icons-react-native/IconSearch";
93import IconServer from "@tabler/icons-react-native/IconServer";
94import IconSettings from "@tabler/icons-react-native/IconSettings";
95import IconSparkles from "@tabler/icons-react-native/IconSparkles";
96import IconStack2 from "@tabler/icons-react-native/IconStack2";
97import IconStar from "@tabler/icons-react-native/IconStar";
98import IconStarFilled from "@tabler/icons-react-native/IconStarFilled";
99import IconStethoscope from "@tabler/icons-react-native/IconStethoscope";
100import IconSun from "@tabler/icons-react-native/IconSun";
101import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
102import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
103import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
104import IconTool from "@tabler/icons-react-native/IconTool";
105import IconTrash from "@tabler/icons-react-native/IconTrash";
106import IconTypography from "@tabler/icons-react-native/IconTypography";
107import IconUpload from "@tabler/icons-react-native/IconUpload";
108import IconUserCircle from "@tabler/icons-react-native/IconUserCircle";
109import IconUsers from "@tabler/icons-react-native/IconUsers";
110import IconWifiOff from "@tabler/icons-react-native/IconWifiOff";
111import IconWorld from "@tabler/icons-react-native/IconWorld";
112import IconX from "@tabler/icons-react-native/IconX";
113import type { AndroidSymbol, SFSymbol, SymbolViewProps } from "expo-symbols";
114import { withUniwind } from "uniwind";
115​
116const ANDROID_ICON_BY_SF_SYMBOL = {
117 "arrow.branch": IconGitBranch,
118 "arrow.left": IconArrowLeft,
119 "arrow.right": IconArrowRight,
120 "arrow.left.arrow.right": IconArrowsLeftRight,
121 "arrow.clockwise": IconRefresh,
122 "arrow.down": IconArrowDown,
123 "arrow.down.circle": IconArrowDownCircle,
124 "arrow.right.circle": IconArrowRightCircle,
125 "arrow.triangle.branch": IconGitBranch,
126 "arrow.triangle.merge": IconGitMerge,
127 "arrow.triangle.pull": IconGitPullRequest,
128 "square.3.layers.3d": IconStack2,
129 "arrow.turn.left.up": IconArrowBackUp,
130 "arrow.up": IconArrowUp,
131 "arrow.up.circle": IconArrowUpCircle,
132 "arrow.up.left.and.arrow.down.right": IconArrowsDiagonal2,
133 "arrow.down.right.and.arrow.up.left": IconArrowsMinimize,
134 "arrow.up.right": IconArrowUpRight,
135 "arrow.up.right.circle": IconArrowUpRightCircle,
136 "arrow.uturn.backward": IconArrowBackUp,
137 "arrow.uturn.forward": IconArrowForwardUp,
138 archivebox: IconArchive,
139 "archivebox.fill": IconArchive,
140 "bell.badge": IconBellRinging,
141 "bolt.circle": IconBolt,
142 "bolt.horizontal.circle": IconBolt,
143 brain: IconBrain,
144 camera: IconCamera,
145 "chart.bar.xaxis": IconChartBar,
146 checkmark: IconCheck,
147 "checkmark.circle": IconCircleCheck,
148 circle: IconCircle,
149 clock: IconClock,
150 timer: IconClock,
151 ticket: IconTicket,
152 cloud: IconCloud,
153 cube: IconBox,
154 "chevron.down": IconChevronDown,
155 "chevron.left": IconChevronLeft,
156 "chevron.left.forwardslash.chevron.right": IconCode,
157 "chevron.right": IconChevronRight,
158 "chevron.up": IconChevronUp,
159 desktopcomputer: IconDeviceDesktop,
160 doc: IconFileText,
161 "doc.on.doc": IconCopy,
162 "doc.text": IconFileText,
163 ellipsis: IconDots,
164 moon: IconMoon,
165 "ellipsis.circle": IconDotsCircleHorizontal,
166 "exclamationmark.triangle": IconAlertTriangle,
167 "exclamationmark.circle": IconAlertCircle,
168 eye: IconEye,
169 folder: IconFolder,
170 "folder.badge.plus": IconFolderPlus,
171 "folder.fill": IconFolder,
172 gearshape: IconSettings,
173 globe: IconWorld,
174 hammer: IconHammer,
175 house: IconHome,
176 "info.circle": IconInfoCircle,
177 internaldrive: IconDatabase,
178 keyboard: IconKeyboard,
179 laptopcomputer: IconDeviceLaptop,
180 link: IconLink,
181 "list.number": IconListNumbers,
182 "line.3.horizontal": IconMenu2,
183 "line.3.horizontal.decrease": IconFilter,
184 "line.3.horizontal.decrease.circle": IconFilter,
185 "line.3.horizontal.decrease.circle.fill": IconFilterFilled,
186 // Tabler has no Apple desktops; the closest silhouettes stand in on Android.
187 macmini: IconServer,
188 macstudio: IconDeviceDesktop,
189 magnifyingglass: IconSearch,
190 mic: IconMicrophone,
191 paintbrush: IconPalette,
192 pencil: IconPencil,
193 "person.crop.circle": IconUserCircle,
194 "person.2": IconUsers,
195 photo: IconPhoto,
196 pin: IconPin,
197 "pin.slash": IconPinnedOff,
198 play: IconPlayerPlay,
199 plus: IconPlus,
200 minus: IconMinus,
201 "qrcode.viewfinder": IconQrcode,
202 "point.3.connected.trianglepath.dotted": IconNetwork,
203 "point.topleft.down.curvedto.point.bottomright.up": IconGitMerge,
204 safari: IconExternalLink,
205 "server.rack": IconServer,
206 stethoscope: IconStethoscope,
207 "sidebar.left": IconLayoutSidebar,
208 "sidebar.right": IconLayoutSidebarRight,
209 "slider.horizontal.3": IconAdjustmentsHorizontal,
210 "square.and.pencil": IconEdit,
211 "square.on.square": IconCopy,
212 "square.grid.2x2": IconApps,
213 "square.split.2x1": IconLayoutColumns,
214 star: IconStar,
215 "star.fill": IconStarFilled,
216 "sun.max": IconSun,
217 "stop.fill": IconPlayerStopFilled,
218 terminal: IconTerminal2,
219 "text.alignleft": IconAlignLeft,
220 "text.bubble": IconMessage,
221 "text.word.spacing": IconLetterSpacing,
222 "textformat.size": IconTypography,
223 "textformat.size.larger": IconTextIncrease,
224 "textformat.size.smaller": IconTextDecrease,
225 "tray.and.arrow.up": IconUpload,
226 trash: IconTrash,
227 "wifi.slash": IconWifiOff,
228 xmark: IconX,
229 "xmark.circle.fill": IconCircleXFilled,
230} satisfies Partial<Record<SFSymbol, Icon>>;
231const SF_ICON_LOOKUP: Partial<Record<SFSymbol, Icon>> = ANDROID_ICON_BY_SF_SYMBOL;
232​
233// Callers can pass `{ ios, android }` names where `android` is a Material
234// icon name (the raw expo-symbols contract). Resolve those here too so the
235// android key keeps working through this wrapper — it wins over the SF map
236// when both match (e.g. folder vs folder_open for expanded project groups).
237const ANDROID_ICON_BY_MATERIAL_NAME = {
238 auto_awesome: IconSparkles,
239 bolt: IconBolt,
240 build: IconTool,
241 chat: IconMessage,
242 chat_bubble: IconMessage,
243 check: IconCheck,
244 close: IconX,
245 construction: IconHammer,
246 content_copy: IconCopy,
247 desktop_windows: IconDeviceDesktop,
248 edit: IconEdit,
249 error: IconAlertCircle,
250 folder: IconFolder,
251 folder_open: IconFolderOpen,
252 keyboard: IconKeyboard,
253 keyboard_arrow_down: IconChevronDown,
254 keyboard_arrow_up: IconChevronUp,
255 keyboard_hide: IconKeyboardHide,
256 lock: IconLock,
257 more_vert: IconDotsVertical,
258 merge: IconGitMerge,
259 psychology: IconBrain,
260 public: IconWorld,
261 remove: IconMinus,
262 smartphone: IconDeviceMobile,
263 terminal: IconTerminal2,
264 visibility: IconEye,
265} satisfies Partial<Record<AndroidSymbol, Icon>>;
266​
267export type { SFSymbol } from "expo-symbols";
268export type AppSymbolName =
269 | keyof typeof ANDROID_ICON_BY_SF_SYMBOL
270 | {
271 ios: SFSymbol;
272 android: keyof typeof ANDROID_ICON_BY_MATERIAL_NAME;
273 };
274​
275export type AppSymbolViewProps = Omit<SymbolViewProps, "name"> & { name: AppSymbolName };
276​
277export function isAppSymbolName(name: string): name is Extract<AppSymbolName, string> {
278 return Object.prototype.hasOwnProperty.call(ANDROID_ICON_BY_SF_SYMBOL, name);
280​
281function AppSymbolView(props: AppSymbolViewProps) {
282 const materialName = typeof props.name === "string" ? undefined : props.name.android;
283 const sfSymbol = typeof props.name === "string" ? props.name : props.name.ios;
284 const AndroidIcon =
285 (materialName ? ANDROID_ICON_BY_MATERIAL_NAME[materialName] : undefined) ??
286 (sfSymbol ? SF_ICON_LOOKUP[sfSymbol] : undefined);
287​
288 if (!AndroidIcon) {
289 return props.fallback ?? null;
290 }
291​
292 return (
293 <AndroidIcon
294 accessibilityLabel={props.accessibilityLabel}
295 color={props.tintColor}
296 size={props.size}
297 strokeWidth={2}
298 style={props.style}
299 testID={props.testID}
300 />
301 );
303​
304/**
305 * expo-symbols and the Android Tabler fallback both expose tint as a native
306 * prop rather than a React Native style. Keep that third-party boundary here
307 * so callers can use Uniwind's `tintColorClassName` instead of subscribing to
308 * theme variables in every parent component.
309 */
310export const SymbolView = withUniwind(AppSymbolView);