@shotik/react-native 0.0.0-stage → 0.1.1

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/src/theme.ts ADDED
@@ -0,0 +1,141 @@
1
+ // Brand theme and copy for the widget. Colors follow the system scheme; the founder's brand sets accent, radius and
2
+ // font. Copy is a small en/ru catalog picked from the device locale (or the locale prop), falling back to en.
3
+
4
+ export interface Colors {
5
+ bg: string
6
+ raised: string
7
+ line: string
8
+ text: string
9
+ sub: string
10
+ faint: string
11
+ danger: string
12
+ ok: string
13
+ warn: string
14
+ backdrop: string
15
+ }
16
+
17
+ export interface SupportTheme {
18
+ // Brand color for your bubbles, the send button, the launcher and links.
19
+ accent?: string
20
+ // Text and icons drawn on the accent (default white).
21
+ onAccent?: string
22
+ // Bubble corner radius (default 18); the sheet, chips and fields follow it.
23
+ radius?: number
24
+ // fontFamily for regular and semibold text (default: the system font).
25
+ font?: string
26
+ fontBold?: string
27
+ // Force a scheme instead of following the system.
28
+ scheme?: 'light' | 'dark'
29
+ light?: Partial<Colors>
30
+ dark?: Partial<Colors>
31
+ }
32
+
33
+ const base: Record<'light' | 'dark', Colors> = {
34
+ light: { bg: '#FFFFFF', raised: '#F2F2F4', line: 'rgba(0,0,0,0.08)', text: '#0B0B0C', sub: '#6B6B73', faint: '#A3A3AB', danger: '#E5484D', ok: '#30A46C', warn: '#E38A1B', backdrop: 'rgba(0,0,0,0.32)' },
35
+ dark: { bg: '#161617', raised: '#252527', line: 'rgba(255,255,255,0.09)', text: '#F4F4F5', sub: '#9B9BA3', faint: '#6B6B73', danger: '#FF6369', ok: '#3DD68C', warn: '#FFB224', backdrop: 'rgba(0,0,0,0.5)' }
36
+ }
37
+
38
+ export interface Resolved extends Colors {
39
+ dark: boolean
40
+ accent: string
41
+ onAccent: string
42
+ radius: number
43
+ font?: string
44
+ fontBold?: string
45
+ }
46
+
47
+ export function resolveTheme(t: SupportTheme | undefined, system: 'light' | 'dark'): Resolved {
48
+ const scheme = t?.scheme ?? system
49
+ const dark = scheme === 'dark'
50
+ return { ...base[scheme], ...t?.[scheme], dark, accent: t?.accent ?? (dark ? '#0A84FF' : '#007AFF'), onAccent: t?.onAccent ?? '#FFFFFF', radius: t?.radius ?? 18, font: t?.font, fontBold: t?.fontBold }
51
+ }
52
+
53
+ const en = {
54
+ title: 'Support',
55
+ greeting: 'How can we help?',
56
+ online: 'Online',
57
+ connecting: 'Connecting',
58
+ offline: 'Offline',
59
+ queuedN: '{n} queued',
60
+ error: "Couldn't connect",
61
+ retry: 'Retry',
62
+ newMessage: 'New message',
63
+ placeholder: 'Message',
64
+ send: 'Send',
65
+ close: 'Close',
66
+ back: 'Back',
67
+ attach: 'Attach',
68
+ photo: 'Photo',
69
+ screenshot: 'Screenshot',
70
+ cancel: 'Cancel',
71
+ remove: 'Remove',
72
+ sending: 'Sending',
73
+ queued: "Will send when you're back online",
74
+ sent: 'Sent',
75
+ delivered: 'Delivered',
76
+ seen: 'Seen',
77
+ failed: 'Not sent · Retry',
78
+ ai: 'AI',
79
+ team: 'Team',
80
+ you: 'You',
81
+ talk: 'Talk to a person',
82
+ handedOff: 'A person will reply',
83
+ resolved: 'Resolved',
84
+ person: 'Person',
85
+ typing: '{who} is typing',
86
+ open: 'Open support',
87
+ unreadN: '{n} unread'
88
+ }
89
+
90
+ export type Copy = typeof en
91
+
92
+ const ru: Copy = {
93
+ title: 'Поддержка',
94
+ greeting: 'Чем помочь?',
95
+ online: 'В сети',
96
+ connecting: 'Подключаемся',
97
+ offline: 'Нет сети',
98
+ queuedN: 'В очереди: {n}',
99
+ error: 'Не удалось подключиться',
100
+ retry: 'Повторить',
101
+ newMessage: 'Новое сообщение',
102
+ placeholder: 'Сообщение',
103
+ send: 'Отправить',
104
+ close: 'Закрыть',
105
+ back: 'Назад',
106
+ attach: 'Прикрепить',
107
+ photo: 'Фото',
108
+ screenshot: 'Снимок экрана',
109
+ cancel: 'Отмена',
110
+ remove: 'Убрать',
111
+ sending: 'Отправляется',
112
+ queued: 'Отправим, когда появится связь',
113
+ sent: 'Отправлено',
114
+ delivered: 'Доставлено',
115
+ seen: 'Прочитано',
116
+ failed: 'Не отправлено · Повторить',
117
+ ai: 'ИИ',
118
+ team: 'Команда',
119
+ you: 'Вы',
120
+ talk: 'Позвать человека',
121
+ handedOff: 'Ответит человек',
122
+ resolved: 'Решено',
123
+ person: 'Человек',
124
+ typing: '{who} печатает',
125
+ open: 'Открыть поддержку',
126
+ unreadN: 'Непрочитанных: {n}'
127
+ }
128
+
129
+ export const catalogs: Record<string, Copy> = { en, ru }
130
+
131
+ export function copyFor(locale?: string): Copy {
132
+ let tag = locale
133
+ if (!tag) {
134
+ try {
135
+ tag = Intl.DateTimeFormat().resolvedOptions().locale
136
+ } catch {}
137
+ }
138
+ return catalogs[(tag ?? 'en').slice(0, 2).toLowerCase()] ?? en
139
+ }
140
+
141
+ export const fill = (s: string, v: Record<string, string | number>) => s.replace(/\{(\w+)\}/g, (_, k: string) => String(v[k] ?? ''))