-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ImageUploader): add another layout mode by grid
#5728
feat(ImageUploader): add another layout mode by grid
#5728
Conversation
PR preview has been successfully built and deployed to https://antd-mobile-preview-pr-5728.surge.sh |
Codecov ReportBase: 89.52% // Head: 90.05% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## feature #5728 +/- ##
===========================================
+ Coverage 89.52% 90.05% +0.53%
===========================================
Files 297 297
Lines 6375 6408 +33
Branches 1566 1582 +16
===========================================
+ Hits 5707 5771 +64
+ Misses 614 584 -30
+ Partials 54 53 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
columns
and other css props
@@ -15,7 +15,9 @@ | |||
| accept | The file types, `image/gif` `image/jpeg` `image/jpg` `image/png` | `string` | `image/*` | | |||
| beforeUpload | Callback function before file reading, return `null` to terminate file reading, support return `Promise` | `(file: File, files: File[]) => Promise<File \| null> \| File \| null` | - | | |||
| capture | Picture selection mode, the optional value is `camera` (directly adjust the camera) | `boolean \| string` | - | | |||
| children | Custom upload button | `ReactNode` | - | | |||
| children | Custom upload button | | |||
| columns | 行展示数 | `number` | - | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该是英文描述吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,我改下哈~
@@ -2,6 +2,20 @@ | |||
|
|||
.@{class-prefix-image-uploader} { | |||
--cell-size: 80px; | |||
--gap: 12px; | |||
---gap: var(--gap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
第一眼看到 ---gap
的写法感觉有些奇怪,误以为语法错误😅~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是按照 selector 那边的写法,大佬能给点正确的写法的 demo 或者关键词吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我有一个想法:就是直接去掉该组件的根元素 <div className={classPrefix}>
,直接用 Grid
或 Space
作为该组件的根节点。这样就不需要 ---gap
这种额外的 CSS 变量了,这边的样式会简化很多。不知道去掉现在的根元素,会不会导致额外的问题。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我有两个想法哈,求大佬给指点一下 @zqran
- 一般组件的根节点的 className 一般都是组件名开头的,这算是个样式命名规范吧。
- 如果没有根节点限定范围,我担心会跟其他用
Grid
或Space
组件的地方产生样式冲突(污染)。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我懂您意思了,我这边试试看是否会有意外影响
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改好了哈,目前没有发现额外的问题,麻烦大佬再看看~
93f479c
to
d948bfd
Compare
return withNativeProps( | ||
props, | ||
props.columns ? ( | ||
<Grid className={`${classPrefix}-grid`} columns={props.columns}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边缺少 classPrefix
类名,导致单测失败了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前在run test
过程中发现两个问题:
- 删除了原来的根节点,造成
image-uploader
的测试快照不一致,已通过npm test -- -u
生成新的快照 image-viewer
有个测试用例没过,初步判断是偏移量有问题,这个我需要再看一下jest
相关的文档再尝试修复。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于问题1,我觉得应该保留 classPrefix
类名,这是 antd-mobile 组件库的规范,所有组件都自己的根类名
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那这样的话,还是要加上原来的根节点吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以保留类名,类似:${classPrefix} ${classPrefix}-grid
这种形式~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗷嗷嗷嗷,恍然大悟
&-grid { | ||
--gap: 12px; | ||
--cell-size: calc( | ||
(100vw - var(--gap) * (var(--columns) - 1)) / var(--columns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方应该用父级元素的宽度来计算吧,也就是 100%
替换 100vw
,但是我这样改组件高度直接没有了,大佬有什么想法吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
试下用 js 计算
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试试哈
@@ -58,8 +59,12 @@ | |||
|
|||
## FAQ | |||
|
|||
### The `capture` attribute is configured, but why some `Android` phones will still have the file option? | |||
### 1. The `capture` attribute is configured, but why some `Android` phones will still have the file option? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### 1. The `capture` attribute is configured, but why some `Android` phones will still have the file option? | |
### The `capture` attribute is configured, but why some `Android` phones will still have the file option? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
|
||
The `capture` provided by ImageUploader comes from the native HTML capability, and in some operating systems/browser environments, this attribute may not be supported, so this problem cannot be avoided. | ||
|
||
See the discussion in this [issue](https://github.com/ant-design/ant-design-mobile/issues/5254). | ||
|
||
### 2. Compatibility description of the `columns` attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### 2. Compatibility description of the `columns` attribute | |
### Compatibility description of the `columns` attribute |
不用加序号
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
本次 PR 难点在于无法得出栅格布局中的每个单元组件的属性,目前是通过 useSize 拿到父元素的宽度再计算得出。 @miracles1919 目前
|
columns
and other css propsgrid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cell-size 的大小除了跟 container 相关外,--gap-horizontal
和 --cell-size
应该是关联的:
- 改了
--cell-size
,--gap
就要变化 - 改了
--gap
,--cell-size
就要变化
const width = containerSize.width | ||
const columns = props.columns | ||
const gap = | ||
Number(props.style?.['--gap-horizontal']?.replace('px', '')) || 12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
css 的单位不只是 px,可能还有 rem vw,可以用 measureCSSLength
,参考:https://github.com/ant-design/ant-design-mobile/blob/master/src/components/picker-view/wheel.tsx#L53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里我改一下
{ ...props, ...extraStyle }, | ||
<div className={classPrefix} ref={containerRef}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ ...props, ...extraStyle }, | |
<div className={classPrefix} ref={containerRef}> | |
<div className={classPrefix} ref={containerRef} style={style}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实这里的 extraStyle
主要是一个 --cell-size
属性,放在 style 里会有类型错误哈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以 style 需要额外的 ts 定义,ref:https://github.com/ant-design/ant-design-mobile/blob/master/src/components/tag/tag.tsx#L42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好滴
我觉得在 |
done |
在你的基础上调整了一下
|
感谢大佬,get 很多新知识 |
@@ -59,6 +80,10 @@ export default () => { | |||
<CustomeSize /> | |||
</DemoBlock> | |||
|
|||
<DemoBlock title='自定义列数'> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边加一下描述,如果设置了 columns,cell size 会失效,而会根据空间自动变化。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props, | ||
<div className={classPrefix}> | ||
<Space className={`${classPrefix}-space`} wrap block> | ||
const renderChildren = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边看起来不需要做成 function,直接:
const contentNode = (
<>
{...}
</>
);
下面直接:
<Grid ...>
...
{contentNode}
</Grid>
|
||
### `columns` 属性说明 | ||
|
||
`columns` 属性依赖 [Grid](./grid) 布局,该属性存在时,不支持自定义 `--cell-size` 属性,因为图片和上传按钮的大小是自动计算的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面 Demo 也需要注明一下,不用看到的这么远的描述。
done @zombieJ |
| --cell-size | 图片和上传按钮的大小 | `80px` | | ||
| --gap | 间距大小 | `12px` | | ||
| --gap-horizontal | 水平方向的间距大小 | `var(--gap)` | | ||
| --gap-vertical | 垂直方向的间距大小 | `var(--gap)` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| --cell-size | 图片和上传按钮的大小 | `80px` | | |
| --gap | 间距大小 | `12px` | | |
| --gap-horizontal | 水平方向的间距大小 | `var(--gap)` | | |
| --gap-vertical | 垂直方向的间距大小 | `var(--gap)` | | |
| --cell-size | 图片和上传按钮的大小(仅在 columns 模式下有效) | `80px` | | |
| --gap | 间距大小(仅在非 columns 模式下有效) | `12px` | | |
| --gap-horizontal | 水平方向的间距大小(仅在非 columns 模式下有效) | `var(--gap)` | | |
| --gap-vertical | 垂直方向的间距大小(仅在非 columns 模式下有效) | `var(--gap)` | |
或许也可以这样注明
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: 卡晨 <awmleer@icloud.com>
done @awmleer 大佬辛苦啦 |
应该只需要改下 --cell-size 的说明哈,commit 已提交 @miracles1919 @awmleer |
conflict 了 |
好啦,麻烦大佬再看看 |
正好也给了我点思路 幸运 |
approved. Base 改一下到 feature 哈~ |
rebase 一下 feature 分支是吧 |
才反应过来,done 啦 |
Co-authored-by: zqran <215244947@qq.com>
合并了,辛苦了 ~ |
relate issue
本次 PR 内容: