@retray-dev/ui-kit 2.5.2 → 2.7.0
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.
- package/COMPONENTS.md +245 -5
- package/README.md +18 -0
- package/dist/index.d.mts +173 -8
- package/dist/index.d.ts +173 -8
- package/dist/index.js +319 -179
- package/dist/index.mjs +259 -132
- package/package.json +1 -1
- package/src/components/AlertBanner/AlertBanner.tsx +14 -2
- package/src/components/Badge/Badge.tsx +16 -2
- package/src/components/Button/Button.tsx +20 -3
- package/src/components/EmptyState/EmptyState.tsx +15 -3
- package/src/components/Input/Input.tsx +29 -8
- package/src/components/ListItem/ListItem.tsx +26 -3
- package/src/components/Toast/Toast.tsx +11 -1
- package/src/components/Toggle/Toggle.tsx +27 -2
- package/src/index.ts +21 -0
- package/src/tokens.ts +69 -0
- package/src/utils/haptics.ts +18 -12
- package/src/utils/icons.ts +73 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import AntDesign from '@expo/vector-icons/AntDesign'
|
|
3
|
+
import Entypo from '@expo/vector-icons/Entypo'
|
|
4
|
+
import Feather from '@expo/vector-icons/Feather'
|
|
5
|
+
import FontAwesome5 from '@expo/vector-icons/FontAwesome5'
|
|
6
|
+
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
|
|
7
|
+
import Ionicons from '@expo/vector-icons/Ionicons'
|
|
8
|
+
|
|
9
|
+
export type IconFamily = 'Feather' | 'AntDesign' | 'Entypo' | 'FontAwesome5' | 'MaterialIcons' | 'Ionicons'
|
|
10
|
+
|
|
11
|
+
export interface IconProps {
|
|
12
|
+
/** Icon name from any supported @expo/vector-icons family. See https://icons.expo.fyi */
|
|
13
|
+
name: string
|
|
14
|
+
size: number
|
|
15
|
+
color: string
|
|
16
|
+
/** Override the resolved family when the same name exists in multiple families. */
|
|
17
|
+
family?: IconFamily
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ResolvedFamily = {
|
|
21
|
+
name: IconFamily
|
|
22
|
+
component: React.ComponentType<{ name: any; size: number; color: string }>
|
|
23
|
+
glyphMap: Record<string, number>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Priority order: highest-priority family listed last so it overwrites lower-priority entries in the cache
|
|
27
|
+
const ICON_FAMILIES: ResolvedFamily[] = [
|
|
28
|
+
{ name: 'Ionicons', component: Ionicons as any, glyphMap: (Ionicons as any).glyphMap },
|
|
29
|
+
{ name: 'MaterialIcons', component: MaterialIcons as any, glyphMap: (MaterialIcons as any).glyphMap },
|
|
30
|
+
{ name: 'FontAwesome5', component: FontAwesome5 as any, glyphMap: (FontAwesome5 as any).glyphMap },
|
|
31
|
+
{ name: 'Entypo', component: Entypo as any, glyphMap: (Entypo as any).glyphMap },
|
|
32
|
+
{ name: 'AntDesign', component: AntDesign as any, glyphMap: (AntDesign as any).glyphMap },
|
|
33
|
+
{ name: 'Feather', component: Feather as any, glyphMap: (Feather as any).glyphMap },
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
let resolvedCache: Map<string, ResolvedFamily> | null = null
|
|
37
|
+
|
|
38
|
+
function buildCache(): Map<string, ResolvedFamily> {
|
|
39
|
+
const cache = new Map<string, ResolvedFamily>()
|
|
40
|
+
for (const family of ICON_FAMILIES) {
|
|
41
|
+
if (!family.glyphMap) continue
|
|
42
|
+
for (const iconName of Object.keys(family.glyphMap)) {
|
|
43
|
+
cache.set(iconName, family)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return cache
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function resolveFamily(name: string): ResolvedFamily | null {
|
|
50
|
+
if (!resolvedCache) {
|
|
51
|
+
resolvedCache = buildCache()
|
|
52
|
+
}
|
|
53
|
+
return resolvedCache.get(name) ?? null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function Icon({ name, size, color, family }: IconProps): React.ReactElement | null {
|
|
57
|
+
let resolved: ResolvedFamily | null = null
|
|
58
|
+
|
|
59
|
+
if (family) {
|
|
60
|
+
resolved = ICON_FAMILIES.find((f) => f.name === family) ?? null
|
|
61
|
+
} else {
|
|
62
|
+
resolved = resolveFamily(name)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!resolved) return null
|
|
66
|
+
|
|
67
|
+
const Component = resolved.component
|
|
68
|
+
return React.createElement(Component, { name, size, color })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function renderIcon(name: string, size: number, color: string): React.ReactElement | null {
|
|
72
|
+
return React.createElement(Icon, { name, size, color })
|
|
73
|
+
}
|