@unif/react-native-design 0.1.0 → 0.1.2
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/README.md +80 -17
- package/lib/module/components/ui/Logo/Logo.js +9 -12
- package/lib/module/components/ui/Logo/Logo.js.map +1 -1
- package/lib/typescript/src/components/ui/Logo/Logo.d.ts +7 -4
- package/lib/typescript/src/components/ui/Logo/Logo.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/Logo/types.d.ts +6 -4
- package/lib/typescript/src/components/ui/Logo/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/ui/Logo/Logo.tsx +9 -11
- package/src/components/ui/Logo/types.ts +6 -4
package/README.md
CHANGED
|
@@ -1,37 +1,100 @@
|
|
|
1
|
-
# react-native-
|
|
1
|
+
# @unif/react-native-design
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unif 设计系统 —— theme + icons + utils + components,面向 React Native 0.85 新架构(Fabric + concurrent React)。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
6
|
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @unif/react-native-design
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
需要在宿主工程提前安装的 peer dependencies:
|
|
7
12
|
|
|
8
13
|
```sh
|
|
9
|
-
|
|
14
|
+
yarn add react-native-svg react-native-gesture-handler react-native-reanimated \
|
|
15
|
+
react-native-worklets react-native-safe-area-context \
|
|
16
|
+
react-native-reanimated-carousel @gorhom/bottom-sheet @sbaiahmed1/react-native-blur
|
|
10
17
|
```
|
|
11
18
|
|
|
19
|
+
## 用法
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
在 app 根附近挂一次 `ThemeProvider`,并按需挂载命令式 host:
|
|
14
22
|
|
|
23
|
+
```tsx
|
|
24
|
+
import { ThemeProvider, ToastHost, ConfirmHost } from '@unif/react-native-design';
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
export function App() {
|
|
27
|
+
return (
|
|
28
|
+
<ThemeProvider>
|
|
29
|
+
{/* ...你的导航 / 屏幕... */}
|
|
30
|
+
<ToastHost />
|
|
31
|
+
<ConfirmHost />
|
|
32
|
+
</ThemeProvider>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
组件内通过 `useThemedStyles` 拿当前主题的 `StyleSheet`:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Button, useThemedStyles, type ColorTokens } from '@unif/react-native-design';
|
|
41
|
+
import { View } from 'react-native';
|
|
42
|
+
|
|
43
|
+
// makeStyles 必须定义在模块顶层,不要写在组件里 inline
|
|
44
|
+
const makeStyles = (c: ColorTokens) => ({
|
|
45
|
+
wrap: { padding: 16, backgroundColor: c.surface },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export function Demo() {
|
|
49
|
+
const styles = useThemedStyles(makeStyles);
|
|
50
|
+
return (
|
|
51
|
+
<View style={styles.wrap}>
|
|
52
|
+
<Button label="保存" onPress={() => {}} />
|
|
53
|
+
</View>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
20
57
|
|
|
21
|
-
|
|
58
|
+
命令式 API:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { toast, confirm } from '@unif/react-native-design';
|
|
62
|
+
|
|
63
|
+
toast.success('已保存');
|
|
64
|
+
|
|
65
|
+
const ok = await confirm({
|
|
66
|
+
title: '确认注销账号?',
|
|
67
|
+
message: '注销后数据无法恢复',
|
|
68
|
+
destructive: true,
|
|
69
|
+
});
|
|
22
70
|
```
|
|
23
71
|
|
|
72
|
+
## 包结构
|
|
24
73
|
|
|
25
|
-
|
|
74
|
+
- **theme** —— `ThemeProvider` / `useTheme` / `useColors` / `useShadow` / `useThemedStyles`,以及 color / shadow / type / space / radius / icon / control / motion 等 token,`r` / `rf` 尺寸 & 字号缩放
|
|
75
|
+
- **icons** —— `IconName` 联合类型 + `ICONS` 数据(用 `<Icon name="..." />` 渲染)
|
|
76
|
+
- **components/ui** —— 原子组件:Button、Card、Cell、NavBar、BottomSheet、Toast、Confirm、Input、Search、Tabs、Switch 等约 37 个
|
|
77
|
+
- **components/business** —— 通用业务复合组件:AvatarWithRing、Decorations、GlassStats、VersionPill(耦合 navigation / store 的组件留在消费者仓库)
|
|
78
|
+
- **utils** —— `createLogger(scope)` 日志器、`childTestID` 列表型组件 testID 拼接助手
|
|
26
79
|
|
|
27
|
-
|
|
28
|
-
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
-
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
80
|
+
## Example
|
|
30
81
|
|
|
31
|
-
|
|
82
|
+
`example/` 是接通本库的 RN 宿主应用:
|
|
32
83
|
|
|
33
|
-
|
|
84
|
+
```sh
|
|
85
|
+
yarn
|
|
86
|
+
yarn example start # metro
|
|
87
|
+
yarn example ios # 或 yarn example android
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
源码改动会通过 Metro monorepo 配置直接热更新,不需要重新构建原生。
|
|
34
91
|
|
|
35
|
-
|
|
92
|
+
## 贡献
|
|
36
93
|
|
|
37
|
-
|
|
94
|
+
- [开发流程](CONTRIBUTING.md#development-workflow)
|
|
95
|
+
- [提交 PR](CONTRIBUTING.md#sending-a-pull-request)
|
|
96
|
+
- [行为准则](CODE_OF_CONDUCT.md)
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
|
@@ -3,28 +3,25 @@
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Image } from 'react-native';
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
// Native/Metro:require() 返回 asset 数字 ID;Web/webpack:返回 URL 字符串,
|
|
7
|
-
// 但 RN-Web Image 不解析 webpack URL,所以走 docusaurus 镜像的 `/img/logo.png` 公开路径。
|
|
8
|
-
const RAW_SOURCE = require('../../../assets/logo.png');
|
|
9
|
-
const SOURCE = typeof RAW_SOURCE === 'string' ? {
|
|
10
|
-
uri: '/img/logo.png'
|
|
11
|
-
} : RAW_SOURCE;
|
|
12
|
-
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
7
|
+
* 品牌 logo 容器组件 —— 提供尺寸 / 圆角 / a11y 标准化包装。
|
|
8
|
+
*
|
|
9
|
+
* 不持有任何品牌资产。consumer 通过 `source` prop 传入自己品牌的图片
|
|
10
|
+
* (推荐 1024×1024 RGBA PNG / SVG 转 png)。
|
|
15
11
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
12
|
+
* @example
|
|
13
|
+
* <Logo source={require('@/assets/logo.png')} size={64} label="Unif" />
|
|
18
14
|
*/
|
|
19
15
|
export function Logo({
|
|
16
|
+
source,
|
|
20
17
|
size = 64,
|
|
21
18
|
borderRadius,
|
|
22
|
-
label = '
|
|
19
|
+
label = 'Logo',
|
|
23
20
|
style,
|
|
24
21
|
testID
|
|
25
22
|
}) {
|
|
26
23
|
return /*#__PURE__*/_jsx(Image, {
|
|
27
|
-
source:
|
|
24
|
+
source: source,
|
|
28
25
|
accessibilityLabel: label,
|
|
29
26
|
style: [{
|
|
30
27
|
width: size,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Image","jsx","_jsx","
|
|
1
|
+
{"version":3,"names":["React","Image","jsx","_jsx","Logo","source","size","borderRadius","label","style","testID","accessibilityLabel","width","height","resizeMode"],"sourceRoot":"../../../../../src","sources":["components/ui/Logo/Logo.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,KAAK,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,IAAIA,CAAC;EACnBC,MAAM;EACNC,IAAI,GAAG,EAAE;EACTC,YAAY;EACZC,KAAK,GAAG,MAAM;EACdC,KAAK;EACLC;AACS,CAAC,EAAqB;EAC/B,oBACEP,IAAA,CAACF,KAAK;IACJI,MAAM,EAAEA,MAAO;IACfM,kBAAkB,EAAEH,KAAM;IAC1BC,KAAK,EAAE,CACL;MACEG,KAAK,EAAEN,IAAI;MACXO,MAAM,EAAEP,IAAI;MACZC,YAAY,EAAEA,YAAY,IAAID,IAAI,GAAG;IACvC,CAAC,EACDG,KAAK,CACL;IACFK,UAAU,EAAC,OAAO;IAClBJ,MAAM,EAAEA;EAAO,CAChB,CAAC;AAEN","ignoreList":[]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { LogoProps } from './types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 品牌 logo 容器组件 —— 提供尺寸 / 圆角 / a11y 标准化包装。
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* 不持有任何品牌资产。consumer 通过 `source` prop 传入自己品牌的图片
|
|
7
|
+
* (推荐 1024×1024 RGBA PNG / SVG 转 png)。
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* <Logo source={require('@/assets/logo.png')} size={64} label="Unif" />
|
|
8
11
|
*/
|
|
9
|
-
export declare function Logo({ size, borderRadius, label, style, testID, }: LogoProps): React.JSX.Element;
|
|
12
|
+
export declare function Logo({ source, size, borderRadius, label, style, testID, }: LogoProps): React.JSX.Element;
|
|
10
13
|
//# sourceMappingURL=Logo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logo.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/Logo/Logo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Logo.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/Logo/Logo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,EACnB,MAAM,EACN,IAAS,EACT,YAAY,EACZ,KAAc,EACd,KAAK,EACL,MAAM,GACP,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAiB/B"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { ImageStyle, StyleProp } from 'react-native';
|
|
1
|
+
import type { ImageSourcePropType, ImageStyle, StyleProp } from 'react-native';
|
|
2
2
|
export type LogoProps = {
|
|
3
|
-
/**
|
|
3
|
+
/** 品牌 logo 图片源 —— consumer 必传(`require('./logo.png')` / `{ uri: '...' }`)。 */
|
|
4
|
+
source: ImageSourcePropType;
|
|
5
|
+
/** 渲染尺寸(正方形)。默认 64。 */
|
|
4
6
|
size?: number;
|
|
5
|
-
/** 覆盖圆角。默认 `size / 4
|
|
7
|
+
/** 覆盖圆角。默认 `size / 4`,呈柔和的 squircle。 */
|
|
6
8
|
borderRadius?: number;
|
|
7
|
-
/**
|
|
9
|
+
/** SR / 测试用文案,默认 'Logo'。 */
|
|
8
10
|
label?: string;
|
|
9
11
|
style?: StyleProp<ImageStyle>;
|
|
10
12
|
/** E2E / 测试定位 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/Logo/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/Logo/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE/E,MAAM,MAAM,SAAS,GAAG;IACtB,8EAA8E;IAC9E,MAAM,EAAE,mBAAmB,CAAC;IAC5B,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC9B,iBAAiB;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unif/react-native-design",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Unif 设计系统:theme + icons + utils + components",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -136,6 +136,7 @@
|
|
|
136
136
|
},
|
|
137
137
|
"jest": {
|
|
138
138
|
"preset": "@react-native/jest-preset",
|
|
139
|
+
"testEnvironment": "node",
|
|
139
140
|
"modulePathIgnorePatterns": [
|
|
140
141
|
"<rootDir>/example/node_modules",
|
|
141
142
|
"<rootDir>/lib/"
|
|
@@ -2,28 +2,26 @@ import React from 'react';
|
|
|
2
2
|
import { Image } from 'react-native';
|
|
3
3
|
import type { LogoProps } from './types';
|
|
4
4
|
|
|
5
|
-
// Native/Metro:require() 返回 asset 数字 ID;Web/webpack:返回 URL 字符串,
|
|
6
|
-
// 但 RN-Web Image 不解析 webpack URL,所以走 docusaurus 镜像的 `/img/logo.png` 公开路径。
|
|
7
|
-
const RAW_SOURCE = require('../../../assets/logo.png');
|
|
8
|
-
const SOURCE: number | { uri: string } =
|
|
9
|
-
typeof RAW_SOURCE === 'string' ? { uri: '/img/logo.png' } : RAW_SOURCE;
|
|
10
|
-
|
|
11
5
|
/**
|
|
12
|
-
*
|
|
6
|
+
* 品牌 logo 容器组件 —— 提供尺寸 / 圆角 / a11y 标准化包装。
|
|
7
|
+
*
|
|
8
|
+
* 不持有任何品牌资产。consumer 通过 `source` prop 传入自己品牌的图片
|
|
9
|
+
* (推荐 1024×1024 RGBA PNG / SVG 转 png)。
|
|
13
10
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* @example
|
|
12
|
+
* <Logo source={require('@/assets/logo.png')} size={64} label="Unif" />
|
|
16
13
|
*/
|
|
17
14
|
export function Logo({
|
|
15
|
+
source,
|
|
18
16
|
size = 64,
|
|
19
17
|
borderRadius,
|
|
20
|
-
label = '
|
|
18
|
+
label = 'Logo',
|
|
21
19
|
style,
|
|
22
20
|
testID,
|
|
23
21
|
}: LogoProps): React.JSX.Element {
|
|
24
22
|
return (
|
|
25
23
|
<Image
|
|
26
|
-
source={
|
|
24
|
+
source={source}
|
|
27
25
|
accessibilityLabel={label}
|
|
28
26
|
style={[
|
|
29
27
|
{
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { ImageStyle, StyleProp } from 'react-native';
|
|
1
|
+
import type { ImageSourcePropType, ImageStyle, StyleProp } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export type LogoProps = {
|
|
4
|
-
/**
|
|
4
|
+
/** 品牌 logo 图片源 —— consumer 必传(`require('./logo.png')` / `{ uri: '...' }`)。 */
|
|
5
|
+
source: ImageSourcePropType;
|
|
6
|
+
/** 渲染尺寸(正方形)。默认 64。 */
|
|
5
7
|
size?: number;
|
|
6
|
-
/** 覆盖圆角。默认 `size / 4
|
|
8
|
+
/** 覆盖圆角。默认 `size / 4`,呈柔和的 squircle。 */
|
|
7
9
|
borderRadius?: number;
|
|
8
|
-
/**
|
|
10
|
+
/** SR / 测试用文案,默认 'Logo'。 */
|
|
9
11
|
label?: string;
|
|
10
12
|
style?: StyleProp<ImageStyle>;
|
|
11
13
|
/** E2E / 测试定位 */
|