@ray-js/smart-ui 2.13.2-beta-0 → 2.13.2-beta-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.
Files changed (103) hide show
  1. package/es/@types/config-provider/index.d.ts +7 -2
  2. package/es/@types/config-provider/theme-vars.d.ts +1 -1
  3. package/es/action-sheet/README.md +613 -0
  4. package/es/battery/README.md +149 -0
  5. package/es/bottom-sheet/README.md +495 -0
  6. package/es/button/README.md +335 -0
  7. package/es/calendar/README.md +513 -0
  8. package/es/cascader/README.md +326 -0
  9. package/es/cell/README.md +317 -0
  10. package/es/checkbox/README.md +481 -0
  11. package/es/circle/README.md +132 -0
  12. package/es/col/README.md +162 -0
  13. package/es/collapse/README.md +127 -0
  14. package/es/config-provider/README.md +150 -0
  15. package/es/count-down/README.md +201 -0
  16. package/es/custom-keyboard/README.md +122 -0
  17. package/es/datetime-picker/README.md +438 -0
  18. package/es/dialog/README.md +451 -0
  19. package/es/divider/README.md +132 -0
  20. package/es/dropdown-menu/README.md +331 -0
  21. package/es/empty/README.md +119 -0
  22. package/es/field/README.md +455 -0
  23. package/es/grid/README.md +273 -0
  24. package/es/icon/README.md +178 -0
  25. package/es/image/README.md +225 -0
  26. package/es/index-bar/README.md +186 -0
  27. package/es/loading/README.md +120 -0
  28. package/es/nav-bar/README.md +410 -0
  29. package/es/notice-bar/README.md +274 -0
  30. package/es/notify/README.md +121 -0
  31. package/es/overlay/README.md +128 -0
  32. package/es/picker/README.md +412 -0
  33. package/es/popover/README.md +338 -0
  34. package/es/popup/README.md +272 -0
  35. package/es/progress/README.md +88 -0
  36. package/es/radio/README.md +423 -0
  37. package/es/rate/README.md +248 -0
  38. package/es/search/README.md +290 -0
  39. package/es/sidebar/README.md +176 -0
  40. package/es/skeleton/README.md +141 -0
  41. package/es/slider/README.md +444 -0
  42. package/es/stepper/README.md +231 -0
  43. package/es/sticky/README.md +91 -0
  44. package/es/swipe-cell/README.md +217 -0
  45. package/es/switch/README.md +316 -0
  46. package/es/tab/README.md +501 -0
  47. package/es/tabbar/README.md +397 -0
  48. package/es/tag/README.md +215 -0
  49. package/es/toast/README.md +293 -0
  50. package/es/transition/README.md +140 -0
  51. package/es/tree-select/README.md +348 -0
  52. package/lib/@types/config-provider/index.d.ts +7 -2
  53. package/lib/@types/config-provider/theme-vars.d.ts +1 -1
  54. package/lib/action-sheet/README.md +613 -0
  55. package/lib/battery/README.md +149 -0
  56. package/lib/bottom-sheet/README.md +495 -0
  57. package/lib/button/README.md +335 -0
  58. package/lib/calendar/README.md +513 -0
  59. package/lib/cascader/README.md +326 -0
  60. package/lib/cell/README.md +317 -0
  61. package/lib/checkbox/README.md +481 -0
  62. package/lib/circle/README.md +132 -0
  63. package/lib/col/README.md +162 -0
  64. package/lib/collapse/README.md +127 -0
  65. package/lib/config-provider/README.md +150 -0
  66. package/lib/count-down/README.md +201 -0
  67. package/lib/custom-keyboard/README.md +122 -0
  68. package/lib/datetime-picker/README.md +438 -0
  69. package/lib/dialog/README.md +451 -0
  70. package/lib/divider/README.md +132 -0
  71. package/lib/dropdown-menu/README.md +331 -0
  72. package/lib/empty/README.md +119 -0
  73. package/lib/field/README.md +455 -0
  74. package/lib/grid/README.md +273 -0
  75. package/lib/icon/README.md +178 -0
  76. package/lib/image/README.md +225 -0
  77. package/lib/index-bar/README.md +186 -0
  78. package/lib/loading/README.md +120 -0
  79. package/lib/nav-bar/README.md +410 -0
  80. package/lib/notice-bar/README.md +274 -0
  81. package/lib/notify/README.md +121 -0
  82. package/lib/overlay/README.md +128 -0
  83. package/lib/picker/README.md +412 -0
  84. package/lib/popover/README.md +338 -0
  85. package/lib/popup/README.md +272 -0
  86. package/lib/progress/README.md +88 -0
  87. package/lib/radio/README.md +423 -0
  88. package/lib/rate/README.md +248 -0
  89. package/lib/search/README.md +290 -0
  90. package/lib/sidebar/README.md +176 -0
  91. package/lib/skeleton/README.md +141 -0
  92. package/lib/slider/README.md +444 -0
  93. package/lib/stepper/README.md +231 -0
  94. package/lib/sticky/README.md +91 -0
  95. package/lib/swipe-cell/README.md +217 -0
  96. package/lib/switch/README.md +316 -0
  97. package/lib/tab/README.md +501 -0
  98. package/lib/tabbar/README.md +397 -0
  99. package/lib/tag/README.md +215 -0
  100. package/lib/toast/README.md +293 -0
  101. package/lib/transition/README.md +140 -0
  102. package/lib/tree-select/README.md +348 -0
  103. package/package.json +3 -3
@@ -0,0 +1,273 @@
1
+ ---
2
+ category: 布局
3
+ ---
4
+
5
+ # Grid 宫格
6
+
7
+ ### 介绍
8
+
9
+ 宫格可以在水平方向上把页面分隔成等宽度的区块,用于展示内容或进行页面导航。
10
+
11
+ ### 引入
12
+
13
+ ```jsx
14
+ import { Grid, GridItem } from '@ray-js/smart-ui';
15
+ ```
16
+
17
+ ## 代码演示
18
+
19
+ ### 基础用法
20
+
21
+ 通过`icon`属性设置格子内的图标,`text`属性设置文字内容。
22
+
23
+ ```jsx
24
+ import React from 'react';
25
+ import { Grid, GridItem } from '@ray-js/smart-ui';
26
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
27
+
28
+ export default function Demo() {
29
+ const array = [0, 1, 2, 3];
30
+ return (
31
+ <Grid>
32
+ {array.map((item, index) => (
33
+ <GridItem icon={IconBubble} text="文字" key={`${index + 1}`} />
34
+ ))}
35
+ </Grid>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### 自定义列数
41
+
42
+ 默认一行展示四个格子,可以通过`columnNum`自定义列数。
43
+
44
+ ```jsx
45
+ import { Grid, GridItem } from '@ray-js/smart-ui';
46
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
47
+ import React from 'react';
48
+
49
+ export default function Demo() {
50
+ const array = [0, 1, 2, 3, 4, 5];
51
+ return (
52
+ <Grid columnNum={2}>
53
+ {array.map((item, index) => (
54
+ <GridItem icon={IconBubble} text="文字" key={`${index + 1}`} />
55
+ ))}
56
+ </Grid>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### 自定义内容
62
+
63
+ 通过插槽可以自定义格子展示的内容。
64
+
65
+ ```jsx
66
+ import { Grid, GridItem, Image } from '@ray-js/smart-ui';
67
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
68
+ import React from 'react';
69
+
70
+ export default function Demo() {
71
+ const array = [0, 1, 2];
72
+ return (
73
+ <Grid columnNum={3} border={false}>
74
+ {array.map((item, index) => (
75
+ <GridItem useSlot icon={IconBubble} text="文字" key={`${index + 1}`}>
76
+ <Image
77
+ width="90px"
78
+ height="90px"
79
+ fit="contain"
80
+ src="https://static1.tuyacn.com/static/tuya-miniapp-doc/_next/static/images/logo-small.png"
81
+ />
82
+ </GridItem>
83
+ ))}
84
+ </Grid>
85
+ );
86
+ }
87
+ ```
88
+
89
+ ### 正方形格子
90
+
91
+ 设置`square`属性后,格子的高度会和宽度保持一致。
92
+
93
+ ```jsx
94
+ import { Grid, GridItem } from '@ray-js/smart-ui';
95
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
96
+ import React from 'react';
97
+
98
+ export default function Demo() {
99
+ const array = [0, 1, 2, 3, 4, 5, 6, 7];
100
+ return (
101
+ <Grid square>
102
+ {array.map((item, index) => (
103
+ <GridItem icon={IconBubble} text="文字" key={`${index + 1}`} />
104
+ ))}
105
+ </Grid>
106
+ );
107
+ }
108
+ ```
109
+
110
+ ### 格子间距
111
+
112
+ 通过`gutter`属性设置格子之间的距离。
113
+
114
+ ```jsx
115
+ import { Grid, GridItem } from '@ray-js/smart-ui';
116
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
117
+ import React from 'react';
118
+
119
+ export default function Demo() {
120
+ const array = [0, 1, 2, 3, 4, 5, 6, 7];
121
+ return (
122
+ <Grid gutter="10px">
123
+ {array.map((item, index) => (
124
+ <GridItem icon={IconBubble} text="文字" key={`${index + 1}`} />
125
+ ))}
126
+ </Grid>
127
+ );
128
+ }
129
+ ```
130
+
131
+ ### 内容横排
132
+
133
+ 将`direction`属性设置为`horizontal`,可以让宫格的内容呈横向排列。
134
+
135
+ ```jsx
136
+ import { Grid, GridItem } from '@ray-js/smart-ui';
137
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
138
+ import React from 'react';
139
+
140
+ export default function Demo() {
141
+ const array = [0, 1, 2];
142
+ return (
143
+ <Grid direction="horizontal" columnNum={3}>
144
+ {array.map((item, index) => (
145
+ <GridItem icon={IconBubble} text="文字" key={`${index + 1}`} />
146
+ ))}
147
+ </Grid>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### 页面跳转
153
+
154
+ 可以通过`url`属性进行页面跳转,通过`linkType`属性控制跳转类型。
155
+
156
+ ```jsx
157
+ import { Grid, GridItem } from '@ray-js/smart-ui';
158
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
159
+ import IconHandPoint from '@tuya-miniapp/icons/dist/svg/HandPoint';
160
+ import React from 'react';
161
+
162
+ export default function Demo() {
163
+ return (
164
+ <Grid direction="horizontal" columnNum="2">
165
+ <GridItem
166
+ icon={IconBubble}
167
+ text="Navigate 跳转"
168
+ linkType="navigateTo"
169
+ url="/pages/home/index"
170
+ />
171
+ <GridItem
172
+ icon={IconHandPoint}
173
+ linkType="reLaunch"
174
+ url="/pages/home/index"
175
+ text="ReLaunch 跳转"
176
+ />
177
+ </Grid>
178
+ );
179
+ }
180
+ ```
181
+
182
+ ### 徽标提示
183
+
184
+ 设置`dot`属性后,会在图标右上角展示一个小红点。设置`badge`属性后,会在图标右上角展示相应的徽标。
185
+
186
+ ```jsx
187
+ import { Grid, GridItem } from '@ray-js/smart-ui';
188
+ import IconBubble from '@tuya-miniapp/icons/dist/svg/Bubble';
189
+ import IconHandPoint from '@tuya-miniapp/icons/dist/svg/HandPoint';
190
+ import React from 'react';
191
+
192
+ export default function Demo() {
193
+ return (
194
+ <Grid columnNum="2">
195
+ <GridItem icon={IconBubble} text="文字" dot />
196
+ <GridItem icon={IconHandPoint} text="文字" badge="99+" />
197
+ </Grid>
198
+ );
199
+ }
200
+ ```
201
+
202
+ ## API
203
+
204
+ ### Grid Props
205
+
206
+ | 参数 | 说明 | 类型 | 默认值 |
207
+ | ------------------ | ----------------------------------------- | ------------------ | ---------- |
208
+ | border | 是否显示边框 | _boolean_ | `true` |
209
+ | center | 是否将格子内容居中显示 | _boolean_ | `true` |
210
+ | clickable | 是否开启格子点击反馈 | _boolean_ | `false` |
211
+ | columnNum | 列数 | _number_ | `4` |
212
+ | direction | 格子内容排列的方向,可选值为 `horizontal` | _string_ | `vertical` |
213
+ | gutter | 格子之间的间距,默认单位为`px` | _string \| number_ | `0` |
214
+ | iconSize `v1.3.2` | 图标大小,默认单位为`px` | _string_ | `28px` |
215
+ | reverse `v1.7.0` | 是否调换图标和文本的位置 | _boolean_ | `false` |
216
+ | square | 是否将格子固定为正方形 | _boolean_ | `false` |
217
+ | useSlot | 是否使用自定义内容的插槽 | _boolean_ | `false` |
218
+
219
+ ### Grid 外部样式类
220
+
221
+ | 类名 | 说明 |
222
+ | ------------ | ------------ |
223
+ | customClass | 根节点样式类 |
224
+
225
+ ### GridItem Props
226
+
227
+ | 参数 | 说明 | 类型 | 默认值 |
228
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ------------ |
229
+ | ariaLabel `v2.13.0` | 无障碍读屏文案,设置在根节点的 `aria-label` 上 | _string_ | - |
230
+ | badge | 图标右上角徽标的内容 | _string \| number_ | - |
231
+ | dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
232
+ | icon | 图标 svg 值或图片链接,可选值见 [Icon 组件](/material/smartui?comId=icon) | _string_ | - |
233
+ | iconColor | 图标颜色 | _string_ | - |
234
+ | iconPrefix `v1.7.0` | 第三方图标前缀 | _string_ | `smart-icon` |
235
+ | linkType | 链接跳转类型,可选值为 `redirectTo` [`switchTab`](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html) `reLaunch` | _string_ | `navigateTo` |
236
+ | text | 文字 | _string_ | - |
237
+ | url | 点击后跳转的链接地址 | _string_ | - |
238
+
239
+ ### GridItem Events
240
+
241
+ | 事件名 | 说明 | 回调参数 |
242
+ | ---------- | -------------- | -------- |
243
+ | onClick | 点击格子时触发 | - |
244
+
245
+ ### GridItem Slots
246
+
247
+ | 名称 | 说明 |
248
+ | ---- | ------------------------------------------------------ |
249
+ | - | 自定义宫格的所有内容,需要设置`use-slot`属性 |
250
+ | icon | 自定义图标,如果设置了`use-slot`或者`icon`属性则不生效 |
251
+ | text | 自定义文字,如果设置了`use-slot`或者`text`属性则不生效 |
252
+
253
+ ### GridItem 外部样式类
254
+
255
+ | 类名 | 说明 |
256
+ | ------------- | ------------ |
257
+ | contentClass | 内容样式类 |
258
+ | customClass | 根节点样式类 |
259
+ | iconClass | 图标样式类 |
260
+ | textClass | 文本样式类 |
261
+
262
+ ### 样式变量
263
+
264
+ 组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](/material/smartui?comId=config-provider)。
265
+
266
+ | 名称 | 默认值 | 描述 |
267
+ | ------------------------------------ | -------------------------------------- | ------------ |
268
+ | --grid-item-content-padding | _@padding-md @padding-xs_ | 内容内边距 |
269
+ | --grid-item-content-background-color | _var(--app-B3, #ffffff)_ | 背景颜色 |
270
+ | --grid-item-content-active-color | _#f2f3f5_ | 激活时颜色 |
271
+ | --grid-item-icon-size | _26px_ | 图标大小 |
272
+ | --grid-item-text-color | _var(--app-B6-N2, rgba(0, 0, 0, 0.7))_ | 文本颜色 |
273
+ | --grid-item-text-font-size | _12px_ | 文本字体大小 |
@@ -0,0 +1,178 @@
1
+ ---
2
+ category: 展示
3
+ assets: Svg
4
+ ---
5
+
6
+ # Icon 图标
7
+
8
+ ### 介绍
9
+
10
+ 基于字体的图标集,可以通过 Icon 组件使用,也可以在其他组件中通过 icon 属性引用。
11
+
12
+ ### 引入
13
+
14
+ ```jsx
15
+ import { Icon } from '@ray-js/smart-ui';
16
+ ```
17
+
18
+ ## 代码演示
19
+
20
+ ### 基础用法
21
+
22
+ `Icon`的`name`属性支持传入图标名称或图片链接。
23
+
24
+ ```jsx
25
+ import WarningIcon from '@tuya-miniapp/icons/dist/svg/Warning';
26
+ import { View } from '@ray-js/ray';
27
+ import { Icon } from '@ray-js/smart-ui';
28
+ import React from 'react';
29
+
30
+ export default function Demo() {
31
+ return (
32
+ <View>
33
+ <Icon name={WarningIcon} />
34
+ <Icon name="https://static1.tuyacn.com/static/tuya-miniapp-doc/_next/static/images/logo-small.png" />
35
+ </View>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### 提示信息
41
+
42
+ 设置`dot`属性后,会在图标右上角展示一个小红点。设置`info`属性后,会在图标右上角展示相应的徽标。
43
+
44
+ ```jsx
45
+ import WarningIcon from '@tuya-miniapp/icons/dist/svg/Warning';
46
+ import { View } from '@ray-js/ray';
47
+ import { Icon } from '@ray-js/smart-ui';
48
+ import React from 'react';
49
+
50
+ export default function Demo() {
51
+ return (
52
+ <View style={{padding: 48}}>
53
+ <Icon name={WarningIcon} dot />
54
+ <Icon name={WarningIcon} info="9" />
55
+ <Icon name={WarningIcon} info="99+" />
56
+ </View>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### 图标颜色
62
+
63
+ 设置`color`属性来控制图标颜色。
64
+
65
+ ```jsx
66
+ import AlarmIcon from '@tuya-miniapp/icons/dist/svg/Alarm';
67
+ import WarningIcon from '@tuya-miniapp/icons/dist/svg/Warning';
68
+ import { Icon } from '@ray-js/smart-ui';
69
+ import React from 'react';
70
+
71
+ export default function Demo() {
72
+ return (
73
+ <>
74
+ <Icon name={AlarmIcon} size="36px" color="#1989fa" />
75
+ <Icon name={WarningIcon} size="36px" color="#07c160" />
76
+ </>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ### 图标大小
82
+
83
+ 设置`size`属性来控制图标大小。
84
+
85
+ ```jsx
86
+ import WarningIcon from '@tuya-miniapp/icons/dist/svg/Warning';
87
+ import { Icon } from '@ray-js/smart-ui';
88
+ import React from 'react';
89
+
90
+ export default function Demo() {
91
+ return (
92
+ <>
93
+ <Icon name={WarningIcon} size="36"/>
94
+ <Icon name={WarningIcon} size="48"/>
95
+ </>
96
+ );
97
+ }
98
+ ```
99
+
100
+
101
+ ### Svg Path `v2.3.3`
102
+
103
+ 组件现在也支持传入path的方式渲染
104
+
105
+ ```jsx
106
+ import { Icon } from '@ray-js/smart-ui';
107
+ import React from 'react';
108
+
109
+ export default function Demo() {
110
+ const svgPath = 'M192 448C192 624.736 335.264 768 512 768s320-143.264 320-320a319.872 319.872 0 0 0-160-277.184V160a64 64 0 0 0-64-64h-192a64 64 0 0 0-64 64v10.816A319.872 319.872 0 0 0 192 448z m224-384h192a32 32 0 0 0 0-64h-192a32 32 0 0 0 0 64z';
111
+ return (
112
+ <Icon name={svgPath} size="42" color="#1989fa" />
113
+ );
114
+ }
115
+ ```
116
+
117
+ ### 自定义图标
118
+
119
+ 如果需要在现有 Icon 的基础上使用更多图标,可以引入第三方 iconfont 对应的字体文件和 CSS 文件,之后就可以在 Icon 组件中直接使用。例如,可以在 `app.wxss` 文件中引入。
120
+
121
+ ```css
122
+ /* 引入第三方或自定义的字体图标样式 */
123
+ @font-face {
124
+ font-family: 'my-icon';
125
+ src: url('./my-icon.ttf') format('truetype');
126
+ }
127
+
128
+ .my-icon {
129
+ font-family: 'my-icon';
130
+ }
131
+
132
+ .my-icon-extra::before {
133
+ content: '\e626';
134
+ }
135
+ ```
136
+
137
+ ```jsx
138
+ // 通过 class-prefix 指定类名为 my-icon
139
+ <Icon class-prefix="my-icon" name="extra" />
140
+ ```
141
+
142
+ ## API
143
+
144
+ ### Props
145
+
146
+ | 参数 | 说明 | 类型 | 默认值 |
147
+ | ------------ | ------------------------------------------ | ------------------ | ------------ |
148
+ | ariaLabel `v2.13.0` | 无障碍读屏文案;非空时根节点 `aria-role` 为 `button` | _string_ | - |
149
+ | ariaRole `v2.13.0` | 无障碍 `aria-role` | _string_ | - |
150
+ | classPrefix | 类名前缀 | _string_ | `smart-icon` |
151
+ | color | 图标颜色 | _string_ | `inherit` |
152
+ | customStyle | 自定义样式 | _React.CSSProperties_ | - |
153
+ | dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
154
+ | info | 图标右上角文字提示 | _string \| number_ | - |
155
+ | name | 图标名称或 Svg URL 或图片链接 | _string_ | - |
156
+ | size | 图标大小,如 `20px`,`2em`,默认单位为`px` | _string \| number_ | `inherit` |
157
+
158
+ ### Events
159
+
160
+ | 事件名 | 说明 | 参数 |
161
+ | ---------- | -------------- | ---- |
162
+ | onClick | 点击图标时触发 | - |
163
+
164
+ ### 外部样式类
165
+
166
+ | 类名 | 说明 |
167
+ | ------------ | -------------------- |
168
+ | customClass | 根节点样式类 |
169
+ | infoClass | 图标右上角文字样式类 |
170
+
171
+
172
+ ### 样式变量
173
+
174
+ 组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](/material/smartui?comId=config-provider)。
175
+
176
+ | 名称 | 默认值 | 描述 |
177
+ | ----------------------------- | -------------------------------------- | ---- |
178
+ | --icon-color | _var(--app-B4-N2, rgba(0, 0, 0, 0.7))_ | 图标颜色 |
@@ -0,0 +1,225 @@
1
+ ---
2
+ category: 展示
3
+ ---
4
+
5
+ # Image 图片
6
+
7
+ ### 介绍
8
+
9
+ 图片
10
+
11
+ ### 引入
12
+
13
+ ```jsx
14
+ import { Image } from '@ray-js/smart-ui';
15
+ ```
16
+
17
+ ## 代码演示
18
+
19
+ ### 基础用法
20
+ 基础用法与原生 [image](<(https://developers.weixin.qq.com/miniprogram/dev/component/image.html)>) 标签一致,可以设置`src`、`width`、`height`等原生属性。
21
+ ```jsx
22
+ import { Image } from '@ray-js/smart-ui';
23
+ import React from 'react';
24
+
25
+ export default function Demo() {
26
+ return (
27
+ <Image width="100px" height="100px" src="https://images.tuyacn.com/rms-static/f350c8a0-0eb2-11ef-8f06-49ae7b2fadcf-1715334722090.jpeg?tyName=cat.jpeg" />
28
+ );
29
+ }
30
+ ```
31
+
32
+ ### 填充模式
33
+
34
+ 通过`fit`属性可以设置图片填充模式,可选值见下方表格。
35
+
36
+ ```jsx
37
+ import { Image } from '@ray-js/smart-ui';
38
+ import React from 'react';
39
+
40
+ export default function Demo() {
41
+ return (
42
+ <Image
43
+ width="100px"
44
+ height="100px"
45
+ fit="contain"
46
+ src="https://images.tuyacn.com/rms-static/f350c8a0-0eb2-11ef-8f06-49ae7b2fadcf-1715334722090.jpeg?tyName=cat.jpeg" />
47
+ );
48
+ }
49
+ ```
50
+
51
+ ### 圆形图片
52
+
53
+ 通过`round`属性可以设置图片变圆,注意当图片宽高不相等且`fit`为`contain`或`scale-down`时,将无法填充一个完整的圆形。
54
+ ```jsx
55
+ import { Image } from '@ray-js/smart-ui';
56
+ import React from 'react';
57
+
58
+ export default function Demo() {
59
+ return (
60
+ <Image
61
+ width="100px"
62
+ height="100px"
63
+ round
64
+ src="https://images.tuyacn.com/rms-static/f350c8a0-0eb2-11ef-8f06-49ae7b2fadcf-1715334722090.jpeg?tyName=cat.jpeg" />
65
+ );
66
+ }
67
+ ```
68
+
69
+ ### 图片懒加载
70
+
71
+ 图片懒加载,在即将进入一定范围(上下三屏)时才开始加载。
72
+
73
+ ```jsx
74
+ import { Image } from '@ray-js/smart-ui';
75
+ import React from 'react';
76
+
77
+ export default function Demo() {
78
+ return (
79
+ <Image
80
+ width="100px"
81
+ height="100px"
82
+ lazyLoad
83
+ src="https://images.tuyacn.com/rms-static/f350c8a0-0eb2-11ef-8f06-49ae7b2fadcf-1715334722090.jpeg?tyName=cat.jpeg" />
84
+ );
85
+ }
86
+ ```
87
+
88
+
89
+ ### 加载中提示
90
+
91
+ `Image`组件提供了默认的加载中提示,支持通过`loading`插槽自定义内容。
92
+
93
+ ```jsx
94
+ import { Image, Loading } from '@ray-js/smart-ui';
95
+ import React from 'react';
96
+
97
+ export default function Demo() {
98
+ return (
99
+ <Image
100
+ width="100px"
101
+ height="100px"
102
+ showLoading
103
+ useLoadingSlot
104
+ slot={{
105
+ loading: <Loading type="spinner" size="20" vertical />
106
+ }}
107
+ />
108
+ );
109
+ }
110
+ ```
111
+
112
+ ### 加载失败提示
113
+
114
+ `Image`组件提供了默认的加载失败提示,支持通过`error`插槽自定义内容。
115
+
116
+ ```jsx
117
+ import { Image } from '@ray-js/smart-ui';
118
+ import { Text } from '@ray-js/ray'
119
+ import React from 'react';
120
+
121
+ export default function Demo() {
122
+ return (
123
+ <Image
124
+ width="100px"
125
+ height="100px"
126
+ useErrorSlot
127
+ src="error-test"
128
+ slot={{
129
+ error: <Text>加载失败</Text>
130
+ }}
131
+ />
132
+ );
133
+ }
134
+ ```
135
+
136
+
137
+ ### 修改图片颜色 `v2.3.3`
138
+
139
+ `tintColor`属性可以直接修改图片的颜色,类似RN的tintColor属性,原理是通过css mask实现的,所以使用之前要做好用户兼容性调查哦。
140
+
141
+ ```jsx
142
+ import { Image } from '@ray-js/smart-ui';
143
+ import React from 'react';
144
+
145
+ export default function Demo() {
146
+ return (
147
+ <Image
148
+ src="https://static1.tuyacn.com/static/tuya-miniapp-doc/_next/static/images/logo-small.png"
149
+ width="100px"
150
+ height="100px"
151
+ tintColor="rgba(255, 255, 25, 0.8)"
152
+ />
153
+ );
154
+ }
155
+ ```
156
+
157
+ ## API
158
+
159
+ ### Props
160
+
161
+ | 参数 | 说明 | 类型 | 默认值 |
162
+ | ---------------------- | ------------------------------------ | ------------------ | ------- |
163
+ | alt | 替代文本 | _string_ | - |
164
+ | fit | 图片填充模式 | _string_ | _fill_ |
165
+ | height | 高度,默认单位为`px` | _string \| number_ | - |
166
+ | lazyLoad | 是否懒加载 | _boolean_ | `false` |
167
+ | radius | 圆角大小,默认单位为`px` | _string \| number_ | `0` |
168
+ | round | 是否显示为圆形 | _boolean_ | `false` |
169
+ | showError | 是否展示图片加载失败提示 | _boolean_ | `true` |
170
+ | showLoading | 是否展示图片加载中提示 | _boolean_ | `true` `v2.0.0` `false` `v2.7.0` |
171
+ | showMenuByLongpress | 是否开启长按图片显示识别小程序码菜单 | _boolean_ | `false` |
172
+ | src | 图片链接 | _string_ | - |
173
+ | useErrorSlot | 是否使用 error 插槽 | _boolean_ | `false` |
174
+ | useLoadingSlot | 是否使用 loading 插槽 | _boolean_ | `false` |
175
+ | webp `v1.10.11` | 是否解析 webp 格式 | _boolean_ | `false` |
176
+ | width | 宽度,默认单位为`px` | _string \| number_ | - |
177
+ | tintColor `v2.3.3` | 修改图片颜色,类似RN的tintColor,采用css mask实现 | _string_ | - |
178
+
179
+ ### 图片填充模式
180
+
181
+ | 名称 | 含义 |
182
+ | --------- | ------------------------------------------------------ |
183
+ | contain | 保持宽高缩放图片,使图片的长边能完全显示出来 |
184
+ | cover | 保持宽高缩放图片,使图片的短边能完全显示出来,裁剪长边 |
185
+ | fill | 拉伸图片,使图片填满元素 |
186
+ | heightFix | 缩放模式,高度不变,宽度自动变化,保持原图宽高比不变 |
187
+ | none | 保持图片原有尺寸 |
188
+ | widthFix | 缩放模式,宽度不变,高度自动变化,保持原图宽高比不变 |
189
+
190
+ ### Events
191
+
192
+ | 事件名 | 说明 | 回调参数 |
193
+ | ---------- | ------------------ | ------------ |
194
+ | onClick | 点击图片时触发 | event: Event |
195
+ | onError | 图片加载失败时触发 | event: Event |
196
+ | onLoad | 图片加载完毕时触发 | event: Event |
197
+
198
+ ### Slots
199
+
200
+ | 名称 | 说明 |
201
+ | ------- | -------------------------- |
202
+ | error | 自定义加载失败时的提示内容 |
203
+ | loading | 自定义加载中的提示内容 |
204
+
205
+ ### 外部样式类
206
+
207
+ | 类名 | 说明 |
208
+ | ------------- | -------------- |
209
+ | customClass | 根节点样式类 |
210
+ | errorClass | error 样式类 |
211
+ | imageClass | 图片样式类 |
212
+ | loadingClass | loading 样式类 |
213
+
214
+ ### 样式变量
215
+
216
+ 组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](/material/smartui?comId=config-provider)。
217
+
218
+ | 名称 | 默认值 | 描述 |
219
+ | ----------------------------- | -------------------------------------- | ---- |
220
+ | --image-placeholder-text-color | _#969799_ | 加载描述文字 |
221
+ | --image-placeholder-font-size | _14px_ | 加载文字字体 |
222
+ | --image-placeholder-background-color | _#f7f8fa_ | 加载遮照背景色 |
223
+ | --image-loading-icon-size | _32px_ | 加载图标体积 |
224
+ | --image-loading-icon-color | _#dcdee0_ | 加载图标颜色 |
225
+ | --image-error-size `v2.0.0` | _32px_ | 图片加载错误时默认图片 |