Skip to content
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(image): add preview prop #939

Merged
merged 77 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ea64917
feat:n-input Support hidden password
doom-9 Jun 17, 2021
149d8e6
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 17, 2021
8664169
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
0627777
feat(form): support require-mark-placement(#171)
doom-9 Jun 18, 2021
f9729c8
Revert "feat(form): support require-mark-placement(#171)"
doom-9 Jun 18, 2021
2566db7
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
aa41027
Revert "feat:n-input Support hidden password"
doom-9 Jun 18, 2021
3f01195
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 18, 2021
076c432
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
2307ef8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
d4f08f8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 21, 2021
56f6d75
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
658835d
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
3d90083
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 22, 2021
1e860cc
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 23, 2021
c1c7942
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 23, 2021
0cb198e
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 24, 2021
71ad4cd
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 24, 2021
cd8476a
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 25, 2021
ac74273
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 26, 2021
e685823
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 28, 2021
2a450f1
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 28, 2021
b02f5f8
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
4f151e7
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
b8cf341
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 29, 2021
c7fa132
Merge branch 'TuSimple:main' into main
doom-9-zz Jun 30, 2021
d7348e6
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
c504c72
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
c14f943
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 1, 2021
23da897
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
eb86273
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
ba7fdda
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 2, 2021
51430c2
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
f25cbf3
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
bfdf90f
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 3, 2021
36939e1
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 4, 2021
244ea96
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 4, 2021
a445262
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
43a5740
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
8c53a25
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 5, 2021
bdddc47
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 6, 2021
c4b7311
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 6, 2021
3ac6a8a
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 7, 2021
9c59190
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 8, 2021
988f21f
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 8, 2021
f6a3a9c
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 9, 2021
c1e42a7
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 10, 2021
4e65da9
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 11, 2021
bd7b76c
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 12, 2021
22576d3
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 13, 2021
a3e4ecb
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 15, 2021
89b4729
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 16, 2021
c603d61
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 17, 2021
4536c5a
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 22, 2021
b9b72a4
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 24, 2021
69ef0b6
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 26, 2021
2f3f242
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 27, 2021
cde10b4
Merge branch 'TuSimple:main' into main
doom-9-zz Jul 30, 2021
3d370f7
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 2, 2021
182f166
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 3, 2021
b9ac1d9
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 8, 2021
a77df05
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 9, 2021
59de411
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 10, 2021
1d21533
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 11, 2021
ae2e706
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 12, 2021
4a93636
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 13, 2021
f5f59c5
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 16, 2021
de2aa61
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 18, 2021
e9c17d4
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 20, 2021
4b88be4
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 21, 2021
ddb72e0
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 23, 2021
2fc986b
Merge branch 'TuSimple:main' into main
doom-9-zz Aug 25, 2021
fba0d76
feat(image): add preview-src prop
doom-9 Aug 22, 2021
7611d84
Update Image.spec.tsx
doom-9 Aug 22, 2021
c86bd07
feat: fix code
doom-9 Aug 23, 2021
59b758d
feat: fix code,remove test code
doom-9 Aug 25, 2021
1ba58dd
Merge branch 'main' into feat(image)-add-preview-prop
07akioni Aug 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Feats

- `n-timeline` add `horizontal` prop, closes [#887](https://github.com/TuSimple/naive-ui/issues/887).
- `n-image` add `preview-src` prop, closes [#922](https://github.com/TuSimple/naive-ui/issues/922)
- `n-dynamic-tags` add `input` and `add` slot, closes [#499](https://github.com/TuSimple/naive-ui/issues/499).

### Fixes
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Feats

- `n-timeline` 新增 `horizontal` 属性,关闭 [#887](https://github.com/TuSimple/naive-ui/issues/887)
- `n-image` 新增 `preview-src` 属性,关闭 [#922](https://github.com/TuSimple/naive-ui/issues/922)
- `n-dynamic-tags` 新增 `input` 和 `add` 插槽,关闭 [#499](https://github.com/TuSimple/naive-ui/issues/499)

### Fixes
Expand Down
1 change: 1 addition & 0 deletions src/image/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group
| height | `string \| number` | `undefined` | Image height. |
| img-props | `object` | `undefined` | The props of the img element inside the component. |
| object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `fill` | Object-fit type of the image in the container. |
| preview-src | `string` | `undefined` | Source of preview image. |
| show-toolbar | `boolean` | `true` | Whether to show the bottom toolbar when the image enlarge. |
| src | `string` | `undefined` | Image source. |
| width | `string \| number` | `undefined` | Image width. |
Expand Down
1 change: 1 addition & 0 deletions src/image/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ group
| height | `string \| number` | `undefined` | 图片高度 |
| img-props | `object` | `undefined` | 组件中 img 元素的属性 |
| object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `fill` | 图片在容器内的的适应类型 |
| preview-src | `string` | `undefined` | 预览图片的图片地址 |
| show-toolbar | `boolean` | `true` | 图片放大后是否展示底部工具栏 |
| src | `string` | `undefined` | 图片来源 |
| width | `string \| number` | `undefined` | 图片宽度 |
Expand Down
16 changes: 9 additions & 7 deletions src/image/src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const imageProps = {
>,
default: 'fill'
},
previewSrc: String,
width: [String, Number] as PropType<string | number>,
src: String,
showToolbar: { type: Boolean, default: true },
Expand All @@ -61,14 +62,14 @@ export default defineComponent({
imgProps: imgPropsRef,
handleClick: () => {
if (imageGroupHandle) {
imageGroupHandle.setPreviewSrc(props.src)
imageGroupHandle.setPreviewSrc(props.previewSrc || props.src)
imageGroupHandle.setThumbnailEl(imageRef.value)
imageGroupHandle.toggleShow()
return
}
const { value: previewInst } = previewInstRef
if (!previewInst) return
previewInst.setPreviewSrc(props.src)
previewInst.setPreviewSrc(props.previewSrc || props.src)
previewInst.setThumbnailEl(imageRef.value)
previewInst.toggleShow()
}
Expand All @@ -87,14 +88,15 @@ export default defineComponent({
{...imgProps}
class={this.groupId}
ref="imageRef"
width={this.width ? this.width : imgProps.width}
height={this.height ? this.height : imgProps.height}
src={this.src ? this.src : imgProps.src}
alt={this.alt ? this.alt : imgProps.alt}
aria-label={this.alt ? this.alt : imgProps.alt}
width={this.width || imgProps.width}
height={this.height || imgProps.height}
src={this.src || imgProps.src}
alt={this.alt || imgProps.alt}
aria-label={this.alt || imgProps.alt}
onClick={this.handleClick}
onError={this.onError}
style={{ objectFit: this.objectFit }}
data-preview-src={this.previewSrc || this.src}
/>
)

Expand Down
11 changes: 8 additions & 3 deletions src/image/src/ImageGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ export default defineComponent({
const imgs = container.getElementsByClassName(
groupId
) as HTMLCollectionOf<HTMLImageElement>

if (!imgs.length) return
const index = Array.from(imgs).findIndex((img) => img.src === currentSrc)
const index = Array.from(imgs).findIndex(
(img) => img.dataset.previewSrc === currentSrc
)
if (~index) {
setPreviewSrc(imgs[(index + step + imgs.length) % imgs.length].src)
setPreviewSrc(
imgs[(index + step + imgs.length) % imgs.length].dataset.previewSrc
)
} else {
setPreviewSrc(imgs[0].src)
setPreviewSrc(imgs[0].dataset.previewSrc)
}
}
provide(imageGroupInjectionKey, {
Expand Down