@thanhphi/unistyles-ui 0.0.0-stage → 0.2.7

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +384 -2
  3. package/dist/choices.d.ts +52 -0
  4. package/dist/choices.js +143 -0
  5. package/dist/colors/index.d.ts +79 -0
  6. package/dist/colors/index.js +2 -0
  7. package/dist/date.d.ts +40 -0
  8. package/dist/date.js +153 -0
  9. package/dist/fields.d.ts +140 -0
  10. package/dist/fields.js +233 -0
  11. package/dist/form/index.d.ts +14 -0
  12. package/dist/form/index.js +68 -0
  13. package/dist/icons.d.ts +10 -0
  14. package/dist/icons.js +52 -0
  15. package/dist/image.d.ts +20 -0
  16. package/dist/image.js +34 -0
  17. package/dist/index.d.ts +15 -0
  18. package/dist/index.js +33 -0
  19. package/dist/list-picker.d.ts +45 -0
  20. package/dist/list-picker.js +76 -0
  21. package/dist/module/choices.js +135 -0
  22. package/dist/module/colors/index.js +1 -0
  23. package/dist/module/colors/package.json +1 -0
  24. package/dist/module/date.js +145 -0
  25. package/dist/module/fields.js +225 -0
  26. package/dist/module/form/index.js +62 -0
  27. package/dist/module/form/package.json +1 -0
  28. package/dist/module/icons.js +16 -0
  29. package/dist/module/image.js +31 -0
  30. package/dist/module/index.js +13 -0
  31. package/dist/module/list-picker.js +70 -0
  32. package/dist/module/overlays.js +138 -0
  33. package/dist/module/package.json +1 -0
  34. package/dist/module/primitives.js +432 -0
  35. package/dist/module/process-graph.js +125 -0
  36. package/dist/module/rich-html/html-styles.js +55 -0
  37. package/dist/module/rich-html/image-renderers.js +141 -0
  38. package/dist/module/rich-html/index.js +54 -0
  39. package/dist/module/rich-html/normalize-inline-colors.js +93 -0
  40. package/dist/module/rich-html/package.json +1 -0
  41. package/dist/module/rich-html/rich-html.js +118 -0
  42. package/dist/module/search.js +88 -0
  43. package/dist/module/theme.js +62 -0
  44. package/dist/module/toast.js +30 -0
  45. package/dist/module/ui-modal.js +145 -0
  46. package/dist/overlays.d.ts +72 -0
  47. package/dist/overlays.js +146 -0
  48. package/dist/primitives.d.ts +157 -0
  49. package/dist/primitives.js +480 -0
  50. package/dist/process-graph.d.ts +33 -0
  51. package/dist/process-graph.js +161 -0
  52. package/dist/rich-html/html-styles.d.ts +23 -0
  53. package/dist/rich-html/html-styles.js +63 -0
  54. package/dist/rich-html/image-renderers.d.ts +12 -0
  55. package/dist/rich-html/image-renderers.js +144 -0
  56. package/dist/rich-html/index.d.ts +18 -0
  57. package/dist/rich-html/index.js +92 -0
  58. package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
  59. package/dist/rich-html/normalize-inline-colors.js +99 -0
  60. package/dist/rich-html/rich-html.d.ts +7 -0
  61. package/dist/rich-html/rich-html.js +123 -0
  62. package/dist/search.d.ts +27 -0
  63. package/dist/search.js +91 -0
  64. package/dist/theme.d.ts +67 -0
  65. package/dist/theme.js +68 -0
  66. package/dist/toast.d.ts +3 -0
  67. package/dist/toast.js +69 -0
  68. package/dist/ui-modal.d.ts +17 -0
  69. package/dist/ui-modal.js +151 -0
  70. package/package.json +35 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thanhphi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,385 @@
1
- # Temporary Holding Version
1
+ # @thanhphi/unistyles-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Component React Native với theme do ứng dụng sở hữu. Dùng được độc lập hoặc kết hợp với Unistyles trong host app và mini app.
4
+
5
+ ## Cài đặt
6
+
7
+ Phiên bản này hỗ trợ React 19, React Native 0.83.x và Expo Image 55.x. Cài các peer dependency vào ứng dụng có binary native, ví dụ trong dự án Expo SDK 55:
8
+
9
+ ```sh
10
+ npm install @thanhphi/unistyles-ui@0.2.6
11
+ npx expo install expo-image react-native-calendars react-native-safe-area-context react-native-svg
12
+ ```
13
+
14
+ | Tính năng bổ sung | Peer dependency |
15
+ | --- | --- |
16
+ | `@thanhphi/unistyles-ui/form` | `react-native-keyboard-controller` và `KeyboardProvider` |
17
+ | `@thanhphi/unistyles-ui/rich-html` | `react-native-render-html@6.3.4` |
18
+ | `@thanhphi/unistyles-ui/toast` | `react-native-toast-message@2.3.3` |
19
+
20
+ Với dự án React Native dùng thư mục native, đồng bộ các module native và chạy `pod install` cho iOS sau khi cài. Khi chuyển sang package này, cập nhật tên dependency, các import root và subpath, cấu hình Module Federation và lockfile. Phiên bản `0.2.6` dùng cùng component, props và theme contract.
21
+
22
+ ## Khởi tạo theme
23
+
24
+ Tạo palette riêng cho app. Ví dụ dưới đây có thể lưu vào `themes/colors/light.ts`. Khi hỗ trợ dark mode, tạo một palette khác cũng thỏa kiểu `UIColors`.
25
+
26
+ ```ts
27
+ import type { UIColors } from '@thanhphi/unistyles-ui';
28
+
29
+ export const lightColors = {
30
+ backdrop: 'rgba(0,0,0,0.5)',
31
+ background: '#FFFFFF',
32
+ base2: '#EFF6FF',
33
+ base3: '#F7F7F7',
34
+ divider: '#F4F4F4',
35
+ focus: '#2563EB',
36
+
37
+ content1: '#232323',
38
+ content2: '#666666',
39
+ content3: '#AFB4B8',
40
+ content4: '#DBDFE2',
41
+
42
+ textPrimary: '#FFFFFF',
43
+
44
+ default: '#D4D4D8',
45
+ primary: '#2563EB',
46
+ secondary: '#F5A524',
47
+ success: '#17C964',
48
+ warning: '#F5A524',
49
+ danger: '#F5222D',
50
+
51
+ gray50: '#FAFAFA',
52
+ gray100: '#F4F4F5',
53
+ gray200: '#E4E4E7',
54
+ gray300: '#D4D4D8',
55
+ gray400: '#A1A1AA',
56
+ gray500: '#71717A',
57
+ gray600: '#52525B',
58
+ gray700: '#3F3F46',
59
+ gray800: '#27272A',
60
+ gray900: '#18181B',
61
+
62
+ primary50: '#EFF6FF',
63
+ primary100: '#DBEAFE',
64
+ primary200: '#BFDBFE',
65
+ primary300: '#93C5FD',
66
+ primary400: '#60A5FA',
67
+ primary500: '#2563EB',
68
+ primary600: '#1D4ED8',
69
+ primary700: '#1E40AF',
70
+ primary800: '#1E3A8A',
71
+ primary900: '#172554',
72
+
73
+ secondary50: '#FEF6E9',
74
+ secondary100: '#FDEDD3',
75
+ secondary200: '#FBDBA7',
76
+ secondary300: '#F9C97C',
77
+ secondary400: '#F7B750',
78
+ secondary500: '#F5A524',
79
+ secondary600: '#C4841D',
80
+ secondary700: '#936316',
81
+ secondary800: '#7B5312',
82
+ secondary900: '#62420E',
83
+
84
+ success50: '#E8FAF0',
85
+ success100: '#D1F4E0',
86
+ success200: '#A2E9C1',
87
+ success300: '#74DFA2',
88
+ success400: '#45D483',
89
+ success500: '#17C964',
90
+ success600: '#12A150',
91
+ success700: '#0E793C',
92
+ success800: '#095028',
93
+ success900: '#095028',
94
+
95
+ warning50: '#FEFCE8',
96
+ warning100: '#FDEDD3',
97
+ warning200: '#FBDBA7',
98
+ warning300: '#F9C97C',
99
+ warning400: '#F7B750',
100
+ warning500: '#F5A524',
101
+ warning600: '#C4841D',
102
+ warning700: '#936316',
103
+ warning800: '#62420E',
104
+ warning900: '#312107',
105
+
106
+ danger50: '#FEE9EA',
107
+ danger100: '#FDD3D5',
108
+ danger200: '#FBA7AB',
109
+ danger300: '#F97A81',
110
+ danger400: '#F74E57',
111
+ danger500: '#F5222D',
112
+ danger600: '#C41B24',
113
+ danger700: '#93141B',
114
+ danger800: '#620E12',
115
+ danger900: '#310709',
116
+ } as const satisfies UIColors;
117
+ ```
118
+
119
+ Sau đó bọc root của app bằng `UIThemeProvider`. Các component con đọc theme gần nhất. Card, header và sheet dùng `background`, còn `content1` là màu chữ nội dung. Dùng `textPrimary` cho chữ tương phản trên nền `primary500`.
120
+
121
+ ```tsx
122
+ import React from "react";
123
+ import {
124
+ Button,
125
+ createUITheme,
126
+ UIThemeProvider,
127
+ } from "@thanhphi/unistyles-ui";
128
+ import { lightColors } from "./themes/colors/light";
129
+
130
+ export function MiniApp() {
131
+ const [accent, setAccent] = React.useState("#006C67");
132
+ const theme = React.useMemo(
133
+ () =>
134
+ createUITheme({
135
+ colors: { ...lightColors, primary500: accent },
136
+ }),
137
+ [accent]
138
+ );
139
+ return (
140
+ <UIThemeProvider theme={theme}>
141
+ <Button label="Đổi màu" onPress={() => setAccent("#6D28D9")} />
142
+ </UIThemeProvider>
143
+ );
144
+ }
145
+ ```
146
+
147
+ `createUITheme({ colors, mode?, scale?, spacing?, radius?, typography? })` yêu cầu palette đầy đủ, tạo value mới và freeze. Chỉ spacing/radius/typography có default để merge. `UIThemeProvider` nhận theme hoàn chỉnh; `useUITheme()` báo lỗi nếu thiếu provider. `scale` áp dụng cho default geometry; override số đã là dp. Theme được cập nhật bằng value mới, không mutate object. Provider mini có thể ghi đè Context Unistyles UI trong subtree, nhưng không tạo ranh giới runtime Unistyles. Provider phải bao tất cả overlay; portal host cũng cần nằm trong subtree đó.
148
+
149
+ Tên token theo guideline, giá trị nằm trong lightColors/darkColors của app. Factory local có thể nhận UIThemeOptions để merge override từng màu trên palette đầy đủ trước khi gọi shared factory. Muốn đổi cả brand cần điều chỉnh đủ dải primary và màu chữ tương phản.
150
+
151
+ | Nhóm | Export chính |
152
+ | --------------- | --------------------------------------------------------------------------------------------------------------------------- |
153
+ | Nội dung/layout | `UIText`, `ScreenHeader`/`Header`, `HeaderAction`, `FormHeader`, `InfoRow`, `EmptyState`, `Card`, `CollapsibleSection`/`CollapsibleCard` |
154
+ | Form | `Field`, `TextField`, `PressableField`, `SelectField`, `DateField`, `TimeField`, `AttachmentField` |
155
+ | Action/status | `Button`, `Badge`, `ActionBar`, `Radio`, `Checkbox`, `ToggleSwitch`, `SegmentedTabs`, `RadioIndicator`, `CheckboxIndicator` |
156
+ | Feedback | `Skeleton`, `TextOrSkeleton`, `ImageWithSkeleton`, `LoadingOverlay`, `Sheet`, `ActionSheet`, `ConfirmDialog`, `ResultDialog` |
157
+
158
+ Màn hình import trực tiếp từ `@thanhphi/unistyles-ui`. Không cần giữ component trung gian chỉ để đổi tên props, dịch label hoặc lặp style mặc định. App dịch chuỗi và chuyển dữ liệu nghiệp vụ trước khi truyền props; các khối như hồ sơ nhân viên, adapter dữ liệu duyệt đơn vẫn là component của app.
159
+
160
+ `ProcessGraph` hiển thị quy trình dọc với nền chấm, các thẻ trạng thái và các dòng
161
+ người xử lý. App truyền `nodes` đã sắp thứ tự, mỗi node có `id`, `title`,
162
+ `statusLabel`, `tone` và `people`. Mỗi người có `id`, `label`, `statusLabel?`,
163
+ `tone?`. Các tone `success`, `warning`, `danger`, `accent`, `neutral` dùng palette
164
+ của provider; có thể ghi đè bằng `tones`. `startAdornment` và `connector` nhận icon
165
+ do app cung cấp. Component không gọi API hoặc suy diễn quyền, tên bước hay kết
166
+ quả xử lý. Node ID phải phân biệt các lần lặp của cùng một bước. Adapter và trạng
167
+ thái tải/lỗi/rỗng thuộc mini app.
168
+
169
+ ```tsx
170
+ import { Button, CollapsibleSection, DateField, InfoRow } from '@thanhphi/unistyles-ui';
171
+
172
+ <CollapsibleSection variant="bordered" title={t('thong_tin')}>
173
+ <InfoRow variant="summary" label={t('ho_ten')} value={employee.name} />
174
+ </CollapsibleSection>
175
+ <DateField
176
+ variant="form"
177
+ label={t('ngay_bat_dau')}
178
+ required
179
+ value={startDate}
180
+ onChange={setStartDate}
181
+ confirmText={t('xac_nhan')}
182
+ />
183
+ <Button label={t('luu')} onPress={handleSave} throttleMs={200} />
184
+ ```
185
+
186
+ | Component | Preset và contract |
187
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
188
+ | `ScreenHeader` | Nhận `onBack`, `backIcon`, `leading`/`trailing`; app tự xử lý navigation. `variant="surface"` dùng nền `background`, viền dưới `divider` và title `content1`. `default`/`onAccent` giữ nền trong suốt; `onAccent` dùng màu `textPrimary` cho title và icon back mặc định. Hai vùng action được đo và giữ cùng chiều rộng để title luôn ở giữa; title dài cắt cuối. Body cao tối thiểu 56 dp, padding ngang 24 dp, cộng top safe area một lần (`safeArea=false` bỏ inset); geometry đi theo theme. `titleWeight="platform"` giữ weight 600 trên iOS, bold trên Android; mặc định luôn 600. |
189
+ | `HeaderAction` | Nút icon/text cho `leading`, `trailing` hoặc search: bắt buộc `accessibilityLabel`, nhận `onPress`, `icon`, `label`, `active`, `indicator`, `disabled`, `testID` và props Pressable. Geometry mặc định 32×32 dp tối thiểu, icon 24 dp, radius 8 dp, hitSlop 6 dp và phản hồi opacity khi nhấn. `active` dùng `primary500`/`primary50`; `indicator` hiển thị chấm `danger`. `icon` nhận ReactNode hoặc hàm `({color, size}) => ReactNode`; dùng hàm để icon đi theo theme và trạng thái. Label text có thể làm nút rộng hơn. |
190
+ | `FormHeader` | Header hủy/xác nhận của form sheet: `title`, `cancelText`, `confirmText`, `onCancel`, `onConfirm`, `confirmDisabled`. Mặc định absolute top, cao 52 dp, padding ngang 20 dp; geometry đi theo theme. Override qua `style`, `titleStyle`, `actionTextStyle`, `disabledActionTextStyle`. |
191
+ | `CollapsibleSection` | `variant="bordered"` thêm viền màu `divider` và padding dọc `spacing.md`; default giữ kiểu Card. Có controlled `expanded/onExpandedChange` hoặc `defaultExpanded`. |
192
+ | `InfoRow` | `variant="detail"` mặc định label rộng 120 dp, cỡ chữ 13 dp, margin dưới 14 dp; `variant="summary"` value căn phải. Có `loading`, `divider`, style overrides. Geometry đi theo theme. |
193
+ | `PressableField` | Trigger hiển thị value/placeholder để mở modal do app quản lý. Có `onPress`, `required`, `error`, `disabled`, `loading`, `icon`/`trailing` và style overrides; không chứa modal state. Default/form cùng geometry SelectField. `variant="filter"` dùng gap 8 dp, label 14 dp/weight 500, field 48 dp/padding 14 dp/radius 12 dp, placeholder màu `content2`, không margin dưới. |
194
+ | `SelectField` | Controlled option object `value/onChange`, local hoặc remote search, `autoFocus` mặc định false. `variant="form"` dùng field cao 48 dp, padding ngang 16 dp, radius 12 dp, gap 8 dp và margin dưới 16 dp. |
195
+ | `DateField` | Controlled ISO `YYYY-MM-DD`; draft chỉ commit lúc xác nhận. Có min/max/clear/formatValue, `icon` hoặc `iconSource` để dùng asset của app. `variant="form"` cùng geometry với SelectField. |
196
+ | `TimeField` | Controlled `value/onChange` cho chuỗi giờ. Form UI 48 dp/padding 16 dp/radius 12 dp, label 14 dp/value 15 dp, error/required/disabled và `clearable`. App bắt buộc truyền `renderPicker({ visible, value, onClose, onConfirm })`; picker chỉ mount khi mở, confirm gọi onChange rồi đóng. Thư viện không import native time picker; nút clear chặn bubbling để tránh mở picker. |
197
+ | `EmptyState` | `variant="illustrated"` nhận `image`, tự đo chiều rộng container và chọn width `min(width * (width < 380 ? 0.6 : 0.4), 320)`. `illustrationSize` ghi đè width; `illustrationAspectRatio` là width/height (ví dụ `780 / 685`). Title màu `content1`, weight 600, padding trên `spacing.lg`; app có thể override style. |
198
+ | `Skeleton` | Mặc định `variant="shimmer"`, gradient SVG chạy ngang (`animationType="overlay"`), 800 ms, radius 0. Có thể chọn phủ màu fade (`animationType="fade"`); `variant="pulse"` vẫn giữ hiệu ứng opacity và radius cũ. `animated={false}` hiển thị placeholder tĩnh; `primaryColor`/`secondaryColor` mặc định từ theme. RN Animated chạy native driver, không thêm native dependency. |
199
+ | `TextOrSkeleton` | Nhận `skeletonProps` để chọn variant/duration/color cùng `skeletonStyle`; nhánh text vẫn nhận các props của `UIText`, gồm `numberOfLines`. |
200
+ | `ImageWithSkeleton` | Ảnh dùng `expo-image`, giữ ảnh mount dưới skeleton tới `onLoad`/`onError`. Nhận `source` (URI string, asset number hoặc ImageSource có headers), `fallbackSource`, `loading` khi app đang lấy source, `style` cho khung, `imageStyle`, `contentFit` (cover), `fallbackContentFit` (contain) và `skeletonProps`. App truyền width/height hoặc aspectRatio, borderRadius cho ảnh tròn/chữ nhật. Source/headers đổi sẽ reset trạng thái; ảnh lỗi dừng skeleton và dùng fallback. Không chứa API, Redux, token resolver hay ảnh mặc định của app. |
201
+ | `Button` | `throttleMs` tùy chọn, mặc định không throttle. Press/long press dùng chung cooldown; press-in/press-out cũng bỏ qua callback khi đang cooldown. Đặt `200` ở nơi cần giữ hành vi button cũ. |
202
+ | `ToggleSwitch` | Controlled `checked/onChange`, `size="small" / "medium" / "large"`, `disabled`, `hitSlop` và accessibility role switch. Track/thumb giữ geometry 40×20/15, 46×24/18, 70×40/30 dp; animation native 300 ms xử lý RTL và cleanup khi state đổi/unmount. Màu mặc định `primary500`/`gray200`/`textPrimary`, ghi đè qua `onColor`, `offColor`, `thumbColor`. Disabled không làm mờ. |
203
+
204
+ `AttachmentField` nhận danh sách file và callback pick/open/remove; app tự thực hiện picker/upload/preview. Dialog/sheet controlled visibility, không lưu ref/global callback trong package. Thư viện không chứa API, refresh token, upload, validation nghiệp vụ hoặc thư viện dịch.
205
+
206
+ `Sheet` nhận `heightRatio` để đặt chiều cao theo cửa sổ và `keyboardAvoiding` để dành chỗ cho bàn phím. Dùng `showHandle`, `description`, `headerStart`, `headerEnd`, `headerStyle` và `titleNumberOfLines` để tùy chỉnh header. `headerEnd` mặc định hiển thị nút đóng. Với danh sách tìm kiếm, đặt phần danh sách `flex: 1` để giữ vùng hiển thị kể cả khi kết quả rỗng. `SelectField` đã làm việc này khi bật `fixedSheetHeight` và nhận `sheetHeightRatio` để tùy chỉnh tỷ lệ mặc định 70%.
207
+
208
+ Dùng `onOpened` để dựng nội dung sau khi hiệu ứng mở kết thúc và `onClosed` để xử lý lựa chọn sau khi sheet đóng. `onClose` nhận yêu cầu đóng từ nút X, nền mờ hoặc nút Back trên Android.
209
+
210
+ `UIModal` dùng cùng vòng đời với `Sheet` và hỗ trợ `position="center"`, `"bottom"` hoặc `"fullScreen"`. Trong `Sheet`, nút X mặc định nằm ở góc trên bên phải. Các hành động truyền qua `headerStart` và `headerEnd` nằm trong hàng tiêu đề. Truyền `showHandle={false}` để ẩn thanh ngang.
211
+
212
+ `ListPicker` có thể đặt bên trong `Sheet` hoặc `UIModal`. Truyền `items`, `getKey`, `getLabel`, `value` và `onChange`. Với `multiple`, `onChange` nhận mảng sau khi người dùng xác nhận. Dùng `searchPlaceholder` cho tìm kiếm local. Khi có `onSearch`, picker chuyển từ khóa sang hook của ứng dụng. Với React Query hoặc API phân trang, hook truyền kết quả, trạng thái tải, `onRetry` và `onLoadMore` vào picker.
213
+
214
+ `SearchBar` nhận `value`, `onChangeText`, `onSubmit` và `onClear` để app quản lý tìm kiếm. Truyền `onPress` để mở màn tìm kiếm khi chạm vào ô. Dùng `fieldStyle` và `textStyle` để tùy chỉnh bố cục và chữ theo màn. Thêm `filter={{ onPress, count, accessibilityLabel }}` để hiện nút lọc. Khi có bộ lọc đang bật, badge số lượng nằm trên mép trên bên phải của nút và được đọc qua trợ năng.
215
+
216
+ Props và type được export từ package root. Khi chia sẻ package qua Module Federation, cấu hình singleton cho `@thanhphi/unistyles-ui` và đặt provider ở root host app. Khi đóng gói UI riêng trong mini app, đặt provider của bản UI đó tại root mini app và đưa các overlay, portal vào cùng subtree. Host app cung cấp native dependencies và các token Unistyles mà mini app sử dụng.
217
+
218
+ ## Form
219
+
220
+ Import `FormScrollView`, `FormErrorAnchor` và `useScrollToFormError` từ `@thanhphi/unistyles-ui/form`.
221
+ App cần `react-native-keyboard-controller` và `KeyboardProvider` ở ngoài vùng form.
222
+ `FormScrollView` cuộn để giữ ô đang nhập trong tầm nhìn và giữ `footer` phía trên bàn phím nếu có.
223
+
224
+ Truyền `validationAttempt` từ hook vào `FormScrollView`. Bọc từng ô bằng `FormErrorAnchor`
225
+ và truyền cùng `error` cho anchor và input. Gọi `onValidationError` khi gửi form thất bại
226
+ để cuộn tới ô lỗi đầu tiên. App quản lý schema và thông báo lỗi.
227
+
228
+ ## Toast
229
+
230
+ Cài `react-native-toast-message@2.3.3` trong từng app và mount `AppToast`
231
+ trong `SafeAreaProvider` ở root. Native modal có thể mount lại cùng
232
+ renderer khi cần toast hiển thị trên modal.
233
+
234
+ ```tsx
235
+ import { AppToast } from "@thanhphi/unistyles-ui/toast";
236
+ import Toast from "react-native-toast-message";
237
+
238
+ // Trong root của app
239
+ <AppToast />;
240
+
241
+ // Khi lưu thành công
242
+ Toast.show({ type: "multilineSuccess", text1: "Lưu hồ sơ thành công" });
243
+ ```
244
+
245
+ `multilineSuccess` và `multilineError` dùng cùng bố cục nhiều dòng.
246
+ Mỗi app gọi `Toast.show()` từ thư viện đã cài trong app đó. App có thể truyền
247
+ `config` để thêm kiểu riêng và `topOffset` để ghi đè safe area mặc định.
248
+
249
+ ## Rich HTML
250
+
251
+ Dùng renderer bài viết qua `@thanhphi/unistyles-ui/rich-html`.
252
+ Entry này cần `react-native-render-html@6.3.4` và nhận màu cùng chiều rộng nội dung từ app.
253
+
254
+ ```tsx
255
+ import { RichHtmlContent } from "@thanhphi/unistyles-ui/rich-html";
256
+
257
+ <RichHtmlContent
258
+ content={article.content}
259
+ contentWidth={contentWidth}
260
+ textColor={theme.color.content1}
261
+ linkColor={theme.color.secondary500}
262
+ />;
263
+ ```
264
+
265
+ Truyền `imageUrls` để thêm ảnh sau nội dung hoặc `renderers` để tùy chỉnh cách
266
+ render theo thẻ HTML. Với danh sách dài, bọc các mục trong `RichHtmlProvider`
267
+ cùng màu để tái sử dụng render engine.
268
+
269
+ Từ 0.2.5, `RichHtmlContent` và `RichHtmlProvider` nhận `baseStyle` cho chữ
270
+ mặc định, `tagsStyles` theo thẻ HTML và `classesStyles` theo class. Các prop
271
+ này ghi đè từng thuộc tính, nên tùy chỉnh một thẻ vẫn giữ những thẻ còn lại.
272
+ Style truyền trực tiếp vào `RichHtmlContent` ưu tiên hơn cấu hình provider.
273
+ CSS inline do tác giả khai báo vẫn đi theo thứ tự ưu tiên của renderer.
274
+ Nếu chỉ truyền `fontSize` dạng số, Unistyles UI tự tính `lineHeight` bằng 1,5 lần
275
+ cỡ chữ. Giãn dòng do Unistyles UI áp dụng được hiệu chỉnh cho iOS.
276
+
277
+ ```tsx
278
+ const articleStyles = {
279
+ baseStyle: { fontSize: 14, lineHeight: 21 },
280
+ tagsStyles: { h2: { fontSize: 18 } },
281
+ classesStyles: { "article-caption": { fontSize: 12 } },
282
+ };
283
+
284
+ <RichHtmlContent
285
+ {...articleStyles}
286
+ content={article.content}
287
+ contentWidth={contentWidth}
288
+ textColor={theme.color.content1}
289
+ linkColor={theme.color.secondary500}
290
+ />;
291
+ ```
292
+
293
+ Từ 0.2.4, `createRichHtmlImageRenderers` tạo bộ `renderers` có skeleton cho ảnh
294
+ và bố cục lưới cho bảng chỉ chứa ảnh. Tạo bộ renderer ngoài component hoặc
295
+ memoize theo các options. Dùng dưới `UIThemeProvider`.
296
+
297
+ ```tsx
298
+ import { createRichHtmlImageRenderers } from "@thanhphi/unistyles-ui/rich-html";
299
+
300
+ const renderers = useMemo(
301
+ () => createRichHtmlImageRenderers({
302
+ fallbackSource: placeholderImage,
303
+ onImagePress: openImage,
304
+ imageAccessibilityLabel: openImageLabel,
305
+ }),
306
+ [placeholderImage, openImage, openImageLabel]
307
+ );
308
+ ```
309
+
310
+ Với Unistyles, truyền palette và mode đang hoạt động vào `createUITheme` khi chúng thay đổi. Nếu app đã có spacing, radius và typography, truyền các giá trị đã tính để component và màn hình đọc cùng hệ token. Khởi tạo Unistyles ở entry của ứng dụng sở hữu runtime, còn `UIThemeProvider` cấp theme cho component của thư viện.
311
+
312
+ ### Ảnh có skeleton
313
+
314
+ `expo-image` phiên bản 55.x là peer dependency, host cung cấp native module. Mặc định skeleton tắt khi ảnh tải xong. Bật `waitForDisplay` để chờ ảnh hiển thị trên màn hình. Component chuyển tiếp `onLoad`, `onDisplay` và `onError` cho app. `testID` gắn vào ảnh, khung và skeleton lần lượt có hậu tố `-container`, `-skeleton`.
315
+
316
+ ```tsx
317
+ import { ImageWithSkeleton } from '@thanhphi/unistyles-ui';
318
+
319
+ <ImageWithSkeleton
320
+ source={avatarSource}
321
+ fallbackSource={defaultAvatar}
322
+ loading={isProfileLoading}
323
+ style={{ width: 48, height: 48, borderRadius: 24 }}
324
+ />
325
+ <ImageWithSkeleton
326
+ source={bannerSource}
327
+ style={{ width: '100%', aspectRatio: 16 / 9, borderRadius: 12 }}
328
+ />
329
+ ```
330
+
331
+ ### Screen header có search
332
+
333
+ `search` nhận `{ active, value, onChangeText, onSubmit?, onClear?, onCancel, placeholder?, cancelLabel?, cancelIcon?, leading?, autoFocus?, clearAccessibilityLabel?, cancelAccessibilityLabel?, accessibilityLabel? }`. App giữ state, dịch chuỗi và xử lý filter/API. Khi `active=true`, header thay title và action thường bằng `search.leading`, ô tìm kiếm và action hủy; chiều cao và safe area giữ nguyên. `autoFocus` mặc định true khi bật mode; `onChangeText` chỉ cập nhật draft, phím search gọi `onSubmit(value)`. Clear gọi `onChangeText('')` rồi `onClear`; hủy dismiss keyboard và chỉ gọi `onCancel`, không tự xóa hay submit. App quyết định reset draft/query đã áp dụng khi hủy.
334
+
335
+ `cancelLabel` mặc định `Cancel`; nếu có `cancelIcon`, header chỉ hiển thị icon và dùng `cancelAccessibilityLabel` cho người dùng trình đọc màn hình. Truyền label/accessibility đã dịch tại app. Search leading độc lập với `leading`/`onBack` của mode thường, ví dụ giữ nút filter bên trái ô search.
336
+
337
+ ```tsx
338
+ import { HeaderAction, ScreenHeader } from '@thanhphi/unistyles-ui';
339
+
340
+ // FilterIcon và SearchIcon là SVG của app; callback/state cũng thuộc app.
341
+ <ScreenHeader
342
+ title={t('don_cua_toi')}
343
+ variant="surface"
344
+ titleWeight="platform"
345
+ trailing={
346
+ <>
347
+ <HeaderAction
348
+ accessibilityLabel={t('bo_loc')}
349
+ active={isFiltering}
350
+ onPress={openFilter}
351
+ icon={({ color, size }) => <FilterIcon color={color} width={size} height={size} />}
352
+ />
353
+ <HeaderAction
354
+ accessibilityLabel={t('tim_kiem')}
355
+ onPress={() => setSearchActive(true)}
356
+ icon={({ color, size }) => <SearchIcon color={color} width={size} height={size} />}
357
+ />
358
+ </>
359
+ }
360
+ search={{
361
+ active: searchActive,
362
+ value: draft,
363
+ onChangeText: setDraft,
364
+ onSubmit: applySearch,
365
+ onClear: clearSearch,
366
+ onCancel: closeSearch,
367
+ placeholder: t('tim_kiem'),
368
+ cancelLabel: t('huy'),
369
+ clearAccessibilityLabel: t('xoa_tim_kiem'),
370
+ }}
371
+ />
372
+ ```
373
+
374
+ ```tsx
375
+ <ToggleSwitch
376
+ checked={isRepeat}
377
+ onChange={setIsRepeat}
378
+ size="small"
379
+ accessibilityLabel={t("lap_lai")}
380
+ />
381
+ ```
382
+
383
+ ## License
384
+
385
+ [MIT](./LICENSE), copyright (c) 2026 thanhphi.
@@ -0,0 +1,52 @@
1
+ import React from "react";
2
+ import { PressableProps, StyleProp, TextStyle, ViewStyle } from "react-native";
3
+ export interface ToggleSwitchProps {
4
+ checked: boolean;
5
+ onChange: (checked: boolean) => void;
6
+ size?: "small" | "medium" | "large";
7
+ disabled?: boolean;
8
+ style?: StyleProp<ViewStyle>;
9
+ onColor?: string;
10
+ offColor?: string;
11
+ thumbColor?: string;
12
+ hitSlop?: PressableProps["hitSlop"];
13
+ testID?: string;
14
+ accessibilityLabel?: string;
15
+ }
16
+ /** Controlled switch. Animation belongs to the component; state belongs to the app. */
17
+ export declare function ToggleSwitch({ checked, onChange, size, disabled, style, onColor, offColor, thumbColor, hitSlop, testID, accessibilityLabel, }: ToggleSwitchProps): React.JSX.Element;
18
+ export interface CheckboxProps {
19
+ checked: boolean;
20
+ onChange: (checked: boolean) => void;
21
+ label?: React.ReactNode;
22
+ disabled?: boolean;
23
+ style?: StyleProp<ViewStyle>;
24
+ labelStyle?: StyleProp<TextStyle>;
25
+ }
26
+ export interface ChoiceIndicatorProps {
27
+ selected: boolean;
28
+ disabled?: boolean;
29
+ size?: number;
30
+ style?: StyleProp<ViewStyle>;
31
+ }
32
+ /** Use an indicator inside an app-owned Pressable to avoid nested touch targets. */
33
+ export declare function RadioIndicator({ selected, disabled, size, style, }: ChoiceIndicatorProps): React.JSX.Element;
34
+ export declare function CheckboxIndicator({ selected, disabled, size, style, }: ChoiceIndicatorProps): React.JSX.Element;
35
+ export declare function Checkbox({ checked, onChange, label, disabled, style, labelStyle, }: CheckboxProps): React.JSX.Element;
36
+ export interface RadioProps extends Omit<CheckboxProps, "checked" | "onChange"> {
37
+ selected: boolean;
38
+ onPress: () => void;
39
+ }
40
+ export declare function Radio({ selected, onPress, label, disabled, style, labelStyle, }: RadioProps): React.JSX.Element;
41
+ export interface SegmentedTab<T> {
42
+ value: T;
43
+ label: string;
44
+ disabled?: boolean;
45
+ }
46
+ export interface SegmentedTabsProps<T> {
47
+ tabs: readonly SegmentedTab<T>[];
48
+ value: T;
49
+ onChange: (value: T) => void;
50
+ style?: StyleProp<ViewStyle>;
51
+ }
52
+ export declare function SegmentedTabs<T>({ tabs, value, onChange, style, }: SegmentedTabsProps<T>): React.JSX.Element;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToggleSwitch = ToggleSwitch;
4
+ exports.RadioIndicator = RadioIndicator;
5
+ exports.CheckboxIndicator = CheckboxIndicator;
6
+ exports.Checkbox = Checkbox;
7
+ exports.Radio = Radio;
8
+ exports.SegmentedTabs = SegmentedTabs;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const react_1 = require("react");
11
+ const react_native_1 = require("react-native");
12
+ const theme_1 = require("./theme");
13
+ const primitives_1 = require("./primitives");
14
+ const icons_1 = require("./icons");
15
+ const switchDimensions = {
16
+ small: { width: 40, padding: 10, thumb: 15, onOffset: 18 },
17
+ medium: { width: 46, padding: 12, thumb: 18, onOffset: 20 },
18
+ large: { width: 70, padding: 20, thumb: 30, onOffset: 32 },
19
+ };
20
+ /** Controlled switch. Animation belongs to the component; state belongs to the app. */
21
+ function ToggleSwitch({ checked, onChange, size = "medium", disabled = false, style, onColor, offColor, thumbColor, hitSlop, testID, accessibilityLabel, }) {
22
+ const { colors: c } = (0, theme_1.useUITheme)();
23
+ const dimensions = switchDimensions[size];
24
+ const offset = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
25
+ const isRTL = react_native_1.I18nManager.isRTL;
26
+ const desktop = ["windows", "macos"].includes(react_native_1.Platform.OS);
27
+ (0, react_1.useEffect)(() => {
28
+ const animation = react_native_1.Animated.timing(offset, {
29
+ toValue: checked
30
+ ? isRTL
31
+ ? -dimensions.onOffset
32
+ : dimensions.onOffset
33
+ : -1,
34
+ duration: 300,
35
+ useNativeDriver: true,
36
+ });
37
+ animation.start();
38
+ return () => animation.stop();
39
+ }, [checked, isRTL, dimensions.onOffset, offset]);
40
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.row, style], children: (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: testID, hitSlop: hitSlop, disabled: disabled, onPress: () => onChange(!checked), accessibilityRole: "switch", accessibilityLabel: accessibilityLabel, accessibilityState: { checked, disabled }, style: ({ pressed }) => ({
41
+ justifyContent: "center",
42
+ width: dimensions.width,
43
+ borderRadius: desktop ? 10 : 20,
44
+ padding: dimensions.padding,
45
+ paddingBottom: dimensions.padding + (desktop ? 2 : 0),
46
+ backgroundColor: checked ? onColor ?? c.primary500 : offColor ?? c.gray200,
47
+ opacity: pressed ? 0.8 : 1,
48
+ }), children: (0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { pointerEvents: "none", style: {
49
+ position: "absolute",
50
+ alignItems: "center",
51
+ justifyContent: "center",
52
+ margin: react_native_1.Platform.OS === "web" ? 0 : 4,
53
+ left: react_native_1.Platform.OS === "web" ? 4 : 0,
54
+ width: dimensions.thumb,
55
+ height: dimensions.thumb,
56
+ borderRadius: dimensions.thumb / 2,
57
+ backgroundColor: thumbColor ?? c.textPrimary,
58
+ transform: [{ translateX: offset }],
59
+ shadowColor: "#000",
60
+ shadowOffset: { width: 0, height: 2 },
61
+ shadowOpacity: 0.2,
62
+ shadowRadius: 2.5,
63
+ elevation: 1.5,
64
+ } }) }) }));
65
+ }
66
+ /** Use an indicator inside an app-owned Pressable to avoid nested touch targets. */
67
+ function RadioIndicator({ selected, disabled, size = 20, style, }) {
68
+ const { colors: c } = (0, theme_1.useUITheme)();
69
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
70
+ styles.choice,
71
+ {
72
+ width: size,
73
+ height: size,
74
+ borderRadius: 99,
75
+ borderColor: selected ? c.primary500 : c.gray200,
76
+ backgroundColor: c.background,
77
+ opacity: disabled ? 0.5 : 1,
78
+ },
79
+ style,
80
+ ], children: selected && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
81
+ width: size / 2,
82
+ height: size / 2,
83
+ borderRadius: 99,
84
+ backgroundColor: c.primary500,
85
+ } })) }));
86
+ }
87
+ function CheckboxIndicator({ selected, disabled, size = 20, style, }) {
88
+ const { colors: c, radius: r } = (0, theme_1.useUITheme)();
89
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
90
+ styles.choice,
91
+ {
92
+ width: size,
93
+ height: size,
94
+ borderColor: selected ? c.primary500 : c.gray200,
95
+ backgroundColor: selected ? c.primary500 : c.background,
96
+ borderRadius: r.sm,
97
+ opacity: disabled ? 0.5 : 1,
98
+ },
99
+ style,
100
+ ], children: selected && (0, jsx_runtime_1.jsx)(icons_1.UIIcon, { name: "check", color: c.textPrimary, size: size * 0.8 }) }));
101
+ }
102
+ function Checkbox({ checked, onChange, label, disabled, style, labelStyle, }) {
103
+ const { spacing: s } = (0, theme_1.useUITheme)();
104
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => onChange(!checked), disabled: disabled, accessibilityRole: "checkbox", accessibilityState: { checked, disabled: !!disabled }, style: [styles.row, { gap: s.sm, opacity: disabled ? 0.5 : 1 }, style], children: [(0, jsx_runtime_1.jsx)(CheckboxIndicator, { selected: checked }), typeof label === "string" ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { style: labelStyle, children: label })) : (label)] }));
105
+ }
106
+ function Radio({ selected, onPress, label, disabled, style, labelStyle, }) {
107
+ const { spacing: s } = (0, theme_1.useUITheme)();
108
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: onPress, disabled: disabled, accessibilityRole: "radio", accessibilityState: { selected, disabled: !!disabled }, style: [styles.row, { gap: s.sm, opacity: disabled ? 0.5 : 1 }, style], children: [(0, jsx_runtime_1.jsx)(RadioIndicator, { selected: selected }), typeof label === "string" ? ((0, jsx_runtime_1.jsx)(primitives_1.UIText, { style: labelStyle, children: label })) : (label)] }));
109
+ }
110
+ function SegmentedTabs({ tabs, value, onChange, style, }) {
111
+ const { colors: c, spacing: s, radius: r } = (0, theme_1.useUITheme)();
112
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { accessibilityRole: "tablist", style: [
113
+ styles.row,
114
+ {
115
+ backgroundColor: c.gray50,
116
+ padding: s.xs,
117
+ borderRadius: r.md,
118
+ gap: s.xs,
119
+ },
120
+ style,
121
+ ], children: tabs.map((tab, index) => {
122
+ const selected = Object.is(tab.value, value);
123
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "tab", accessibilityState: { selected, disabled: !!tab.disabled }, disabled: tab.disabled, onPress: () => onChange(tab.value), style: {
124
+ flex: 1,
125
+ paddingVertical: s.sm,
126
+ paddingHorizontal: s.sm,
127
+ alignItems: "center",
128
+ borderRadius: r.sm,
129
+ backgroundColor: selected ? c.background : "transparent",
130
+ opacity: tab.disabled ? 0.5 : 1,
131
+ }, children: (0, jsx_runtime_1.jsx)(primitives_1.UIText, { weight: selected ? "600" : "400", color: selected ? "primary500" : "content2", children: tab.label }) }, index));
132
+ }) }));
133
+ }
134
+ const styles = react_native_1.StyleSheet.create({
135
+ row: { flexDirection: "row", alignItems: "center" },
136
+ choice: {
137
+ width: 20,
138
+ height: 20,
139
+ borderWidth: 1.5,
140
+ alignItems: "center",
141
+ justifyContent: "center",
142
+ },
143
+ });