@jsb188/react 1.0.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/icons/Icon.tsx ADDED
@@ -0,0 +1,207 @@
1
+ import { memo } from 'react';
2
+ import type { ReactSpanElement } from '../types/dom';
3
+ import * as IconSVGs from './IconSVGs';
4
+
5
+ /**
6
+ * Convert cameCalsed string to dash-separated
7
+ */
8
+
9
+ function camelCaseToDash(str: string) {
10
+ if (/^[A-Z0-9]+$/.test(str)) {
11
+ return str.toLowerCase();
12
+ }
13
+ return str.replace(/[A-Z0-9]/g, (m, i) => {
14
+ return `${i ? '-' : ''}${m.toLowerCase()}`;
15
+ });
16
+ }
17
+
18
+ /**
19
+ * Combine list of class names
20
+ */
21
+
22
+ export function cn(...classNames: (string | boolean | undefined | null)[]) {
23
+ return classNames.filter(Boolean).join(' ');
24
+ }
25
+
26
+ /**
27
+ * Icon map
28
+ */
29
+
30
+ const ICON_MAP = Object.entries(IconSVGs).reduce((acc, [key, IconComponent]) => {
31
+ acc[camelCaseToDash(key)] = IconComponent;
32
+ return acc;
33
+ }, {} as Record<string, React.ReactNode>);
34
+
35
+ // Full icon map: https://tablericons.com/
36
+
37
+ /**
38
+ * Types
39
+ */
40
+
41
+ interface IconProps {
42
+ name: string;
43
+ }
44
+
45
+ interface SpecialIconProps extends IconProps {
46
+ name: string;
47
+ cornerIconName?: string;
48
+ }
49
+
50
+ interface AIFaceProps extends ReactSpanElement {
51
+ size: 'tiny' | 'small' | 'default' | 'medium' | 'large';
52
+ }
53
+
54
+ /**
55
+ * Commonly used icon names
56
+ */
57
+
58
+ export const COMMON_ICON_NAMES = {
59
+ ai_magic: 'sparkles',
60
+ broken_file: 'file-broken',
61
+ call: 'phone-call',
62
+ chat: 'messages',
63
+ click: 'click',
64
+ close: 'x',
65
+ close_small: 'x-filled',
66
+ co: 'crown',
67
+ colors: 'color-swatch',
68
+ copied: 'copy-check',
69
+ description: 'notes',
70
+ delete: 'trash-x',
71
+ delete_filled: 'trash-x-filled',
72
+ edit: 'edit-circle',
73
+ empty: 'square-forbid-2',
74
+ favorites: 'stars',
75
+ friends_list: 'address-book',
76
+ group: 'users-group',
77
+ image: 'photo',
78
+ images: 'library-photo',
79
+ live: 'broadcast',
80
+ mobile: 'device-mobile',
81
+ moderator: 'gavel',
82
+ not_pinned: 'pinned-off',
83
+ owner: 'crown',
84
+ personas: 'masks-theater',
85
+ pinned: 'pinned',
86
+ plus: 'plus',
87
+ plus_circle: 'circle-plus-filled',
88
+ read: 'checklist',
89
+ report: 'exclamation-circle',
90
+ smile: 'confetti',
91
+ settings: 'settings',
92
+ snooze: 'zzz',
93
+ sticker: 'sticker',
94
+ theme: 'photo-hexagon',
95
+ timeout: 'clock-cancel',
96
+ timeout_unban: 'clock-check',
97
+ unread: 'mailbox',
98
+ user: 'user',
99
+ user_scan: 'user-scan',
100
+ user_blocked: 'user-x',
101
+ user_deleted: 'user-off',
102
+ };
103
+
104
+ /**
105
+ * Simple icon with a very basic fix
106
+ */
107
+
108
+ export const Icon = memo((p: IconProps) => {
109
+ const { name: iconName } = p;
110
+ const IconComponent = ICON_MAP[iconName];
111
+
112
+ if (!IconComponent) {
113
+ console.warn('Icon: Unknown icon name:', iconName);
114
+ }
115
+
116
+ return IconComponent || null;
117
+ });
118
+
119
+ Icon.displayName = 'Icon';
120
+
121
+ /**
122
+ * Special icons that aren't included in FA
123
+ */
124
+
125
+ export const SpecialIcon = memo((p: SpecialIconProps) => {
126
+ const { name } = p;
127
+ const className = 'ic_special';
128
+
129
+ switch (name) {
130
+ case 'google':
131
+ return (
132
+ <img
133
+ alt='Google logo'
134
+ src='/img/google-icon.png'
135
+ className={className}
136
+ />
137
+ );
138
+ default:
139
+ console.warn('SpecialIcon: Unknown icon name:', name);
140
+ }
141
+
142
+ return null;
143
+ });
144
+
145
+ SpecialIcon.displayName = 'SpecialIcon';
146
+
147
+ /**
148
+ * Icon with plus at corner
149
+ */
150
+
151
+ export const IconWithPlus = memo((p: SpecialIconProps) => {
152
+ const { name, cornerIconName } = p;
153
+
154
+ return (
155
+ <>
156
+ <Icon name={name} />
157
+ <span className='abs_corner_1 ic_d ft_t'>
158
+ <Icon name={cornerIconName || 'circle-plus'} />
159
+ </span>
160
+ </>
161
+ );
162
+ });
163
+
164
+ IconWithPlus.displayName = 'IconWithPlus';
165
+
166
+ /**
167
+ * AI (brand) icon
168
+ */
169
+
170
+ export const AIFace = memo((p: AIFaceProps) => {
171
+ const { size, className } = p;
172
+
173
+ let sizeClassName;
174
+ switch (size) {
175
+ case 'tiny':
176
+ sizeClassName = 'av_t ic_d bd_s';
177
+ break;
178
+ case 'small':
179
+ sizeClassName = 'av_s ic_l bd_d';
180
+ break;
181
+ case 'default':
182
+ case 'medium':
183
+ case 'large':
184
+ default:
185
+ console.warn(`<AIFace /> size "${size}" is not implemented yet.`);
186
+ }
187
+
188
+
189
+ return (
190
+ <span
191
+ className={cn(
192
+ 'ai_face bg v_center r av',
193
+ sizeClassName,
194
+ // 'bg_primary',
195
+ className
196
+ )}
197
+ >
198
+ <svg className='icon' viewBox="0 0 100 100" fill='currentColor'>
199
+ <path d="M77.44,65.61c-4.07-7.98-12.79-12.11-20.74-9.83-1.01.29-4.51,1.77-5.39,2.76-1.13,1.27-1.44,3.22-.75,4.75.64,1.41,1.96,2.21,3.52,2.15,1.52.01,3.75.04,4.72.06,5.75.11,6.8.65,11.46,4.39.35.28.9.82,1.43,1.35,1.22,1.2,2.49,2.44,3.37,2.77.33.12.66.19.96.19.43,0,.82-.12,1.17-.36,1.1-.76,1.33-2.41,1.33-3.66,0-1.77-.67-3.75-1.09-4.58Z"/>
200
+ <path d="M31.22,39.18h0c-5.16.52-7.43,5.17-6.99,9.49.38,3.78,2.97,7.61,7.79,7.61.3,0,.62-.02.94-.05,2.79-.27,4.96-1.83,6.11-4.39,1.38-3.04,1.01-7.02-.89-9.66-1.6-2.23-4.07-3.29-6.96-3Z"/>
201
+ <path d="M67.2,46.47c.73,0,1.48-.1,2.26-.3,4.74-1.24,6.47-5.94,5.74-9.96-.69-3.78-3.61-7.36-8.57-6.83-3.03.32-5.29,2.03-6.36,4.82-1.27,3.3-.58,7.38,1.68,9.92,1.38,1.55,3.2,2.35,5.26,2.35Z"/>
202
+ </svg>
203
+ </span>
204
+ );
205
+ });
206
+
207
+ AIFace.displayName = 'AIFace';