Skip to content

Commit

Permalink
fix(image): doesn't accept attributes, set border-radius not working, c…
Browse files Browse the repository at this point in the history
…loses #427
  • Loading branch information
07akioni committed Jul 7, 2021
1 parent 74ad691 commit cfff4e8
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 112 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- Fix `n-select` bug in using custom label, closes [#352](https://github.com/TuSimple/naive-ui/issues/352).
- Fix `n-carousel` when `autoplay` dot active status isn't displayed correctly, closes [#434](https://github.com/TuSimple/naive-ui/issues/434).
- Fix `n-input` fixed clearable position, closes [#428](https://github.com/TuSimple/naive-ui/issues/428).
- Fix `n-image` doesn't accept attributes.
- Fix `n-image` set border-radius not working, closes [#427](https://github.com/TuSimple/naive-ui/issues/427).

### Feats

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- 修复 `n-select` 自定义 label 的显示问题,关闭 [#352](https://github.com/TuSimple/naive-ui/issues/352)
- 修复 `n-carousel` 设定 `autoplay` 点击后 dot active 状态不正常,关闭 [#434](https://github.com/TuSimple/naive-ui/issues/434)
- 修复 `n-input` 清空按钮位置引起的样式问题,关闭 [#428](https://github.com/TuSimple/naive-ui/issues/428)
- 修复 `n-image` 不接受 attributes
- 修复 `n-image` 设定 border-radius 无效,关闭 [#427](https://github.com/TuSimple/naive-ui/issues/427)

### Feats

Expand Down
30 changes: 18 additions & 12 deletions src/image/src/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { defineComponent, h, inject, ref, PropType, toRef } from 'vue'
import {
defineComponent,
h,
inject,
ref,
PropType,
toRef,
mergeProps
} from 'vue'
import NImagePreview from './ImagePreview'
import type { ImagePreviewInst } from './ImagePreview'
import { imageGroupInjectionKey } from './ImageGroup'
Expand Down Expand Up @@ -31,6 +39,7 @@ export type ImageProps = ExtractPublicPropTypes<typeof imageProps>
export default defineComponent({
name: 'Image',
props: imageProps,
inheritAttrs: false,
setup (props) {
const imageRef = ref<HTMLImageElement | null>(null)
const imgPropsRef = toRef(props, 'imgProps')
Expand Down Expand Up @@ -61,7 +70,12 @@ export default defineComponent({
render () {
const { mergedClsPrefix, imgProps = {} } = this

const imgNode = (
const imgWrapperNode = h(
'div',
mergeProps(this.$attrs, {
role: 'none',
class: `${mergedClsPrefix}-image`
}),
<img
{...imgProps}
class={this.groupId}
Expand All @@ -76,23 +90,15 @@ export default defineComponent({
)

return this.groupId ? (
<div class={`${mergedClsPrefix}-image`} role="none">
{imgNode}
</div>
imgWrapperNode
) : (
<NImagePreview
clsPrefix={mergedClsPrefix}
ref="previewInstRef"
showToolbar={this.showToolbar}
>
{{
default: () => {
return (
<div class={`${mergedClsPrefix}-image`} role="none">
{imgNode}
</div>
)
}
default: () => imgWrapperNode
}}
</NImagePreview>
)
Expand Down
198 changes: 99 additions & 99 deletions src/image/src/ImagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ImagePreviewInst {
}

export default defineComponent({
name: 'Image',
name: 'ImagePreview',
props: {
showToolbar: Boolean,
onNext: Function as PropType<() => void>,
Expand Down Expand Up @@ -253,25 +253,10 @@ export default defineComponent({
default: () =>
this.show || this.displayed
? withDirectives(
<div
class={`${clsPrefix}-image-preview-container`}
style={this.cssVars as CSSProperties}
>
<Transition
name="fade-in-transition"
appear={this.appear}
<div
class={`${clsPrefix}-image-preview-container`}
style={this.cssVars as CSSProperties}
>
{{
default: () =>
this.show ? (
<div
class={`${clsPrefix}-image-preview-overlay`}
onClick={this.toggleShow}
/>
) : null
}}
</Transition>
{this.showToolbar ? (
<Transition
name="fade-in-transition"
appear={this.appear}
Expand All @@ -280,89 +265,104 @@ export default defineComponent({
default: () =>
this.show ? (
<div
class={`${clsPrefix}-image-preview-toolbar`}
>
{this.onPrev ? (
<>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.onPrev}
>
{{ default: () => prevIcon }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.onNext}
>
{{ default: () => nextIcon }}
</NBaseIcon>
</>
) : null}
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.rotateCounterclockwise}
>
{{
default: () => (
<RotateCounterclockwiseIcon />
)
}}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.rotateClockwise}
>
{{ default: () => <RotateClockwiseIcon /> }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.zoomOut}
>
{{ default: () => <ZoomOutIcon /> }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.zoomIn}
>
{{ default: () => <ZoomInIcon /> }}
</NBaseIcon>
</div>
class={`${clsPrefix}-image-preview-overlay`}
onClick={this.toggleShow}
/>
) : null
}}
</Transition>
) : null}
<Transition
name="fade-in-scale-up-transition"
onAfterLeave={this.handleAfterLeave}
appear={this.appear}
// BUG:
// onEnter will be called twice, I don't know why
// Maybe it is a bug of vue
onEnter={this.syncTransformOrigin}
onBeforeLeave={this.syncTransformOrigin}
>
{{
default: () =>
withDirectives(
<div
class={`${clsPrefix}-image-preview-wrapper`}
ref="previewWrapperRef"
>
<img
draggable={false}
onMousedown={this.handlePreviewMousedown}
class={`${clsPrefix}-image-preview`}
key={this.previewSrc}
src={this.previewSrc}
ref="previewRef"
/>
</div>,
[[vShow, this.show]]
)
}}
</Transition>
</div>,
[[zindexable, { enabled: this.show }]]
{this.showToolbar ? (
<Transition
name="fade-in-transition"
appear={this.appear}
>
{{
default: () =>
this.show ? (
<div
class={`${clsPrefix}-image-preview-toolbar`}
>
{this.onPrev ? (
<>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.onPrev}
>
{{ default: () => prevIcon }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.onNext}
>
{{ default: () => nextIcon }}
</NBaseIcon>
</>
) : null}
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.rotateCounterclockwise}
>
{{
default: () => (
<RotateCounterclockwiseIcon />
)
}}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.rotateClockwise}
>
{{ default: () => <RotateClockwiseIcon /> }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.zoomOut}
>
{{ default: () => <ZoomOutIcon /> }}
</NBaseIcon>
<NBaseIcon
clsPrefix={clsPrefix}
onClick={this.zoomIn}
>
{{ default: () => <ZoomInIcon /> }}
</NBaseIcon>
</div>
) : null
}}
</Transition>
) : null}
<Transition
name="fade-in-scale-up-transition"
onAfterLeave={this.handleAfterLeave}
appear={this.appear}
// BUG:
// onEnter will be called twice, I don't know why
// Maybe it is a bug of vue
onEnter={this.syncTransformOrigin}
onBeforeLeave={this.syncTransformOrigin}
>
{{
default: () =>
withDirectives(
<div
class={`${clsPrefix}-image-preview-wrapper`}
ref="previewWrapperRef"
>
<img
draggable={false}
onMousedown={this.handlePreviewMousedown}
class={`${clsPrefix}-image-preview`}
key={this.previewSrc}
src={this.previewSrc}
ref="previewRef"
/>
</div>,
[[vShow, this.show]]
)
}}
</Transition>
</div>,
[[zindexable, { enabled: this.show }]]
)
: null
}}
Expand Down
4 changes: 3 additions & 1 deletion src/image/src/styles/index.cssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ export default c([
cB('image', `
display: inline-flex;
cursor: pointer;
`)
`, [
c('img', 'border-radius: inherit;')
])
])

0 comments on commit cfff4e8

Please sign in to comment.