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 img class #3080

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 packages/web-vue/components/image/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ description: Used to show and preview pictures.
|default-preview-visible|The default open state of the preview|`boolean`|`false`||
|preview-props|Preview configuration items (all options are optional) [ImagePreviewProps](#image-preview%20Props)|`ImagePreviewProps`|`-`||
|footer-class|The class name of the bottom display area|`string\|array\|object`|`-`|2.23.0|
|img-class|The class name of the image|`string \| any[]`|`-`||
### `<image>` Events

|Event Name|Description|Parameters|
Expand Down
1 change: 1 addition & 0 deletions packages/web-vue/components/image/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ description: 展示和预览图片。
|default-preview-visible|预览的默认打开状态|`boolean`|`false`||
|preview-props|预览的配置项(所有选项都是可选的) [ImagePreviewProps](#image-preview%20Props)|`ImagePreviewProps`|`-`||
|footer-class|底部显示区域的类名|`string\|array\|object`|`-`|2.23.0|
|img-class|图片的类名|`string \| any[]`|`-`||
### `<image>` Events

|事件名|描述|参数|
Expand Down
13 changes: 13 additions & 0 deletions packages/web-vue/components/image/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ describe('Image', () => {
expect(wrapper.find('.arco-image-error').exists()).toBe(true);
});

test('image Props img-class should work', async () => {
const wrapper = await mount(Image, {
props: {
src: imgSrc,
imgClass: 'img-class-test',
},
});
await wrapper.vm.onImgLoaded();
expect(wrapper.find('img').attributes('class').split(' ')).toContainEqual(
'img-class-test'
);
});

test('Footer should work', async () => {
const wrapper = await mount(Image, {
props: {
Expand Down
9 changes: 8 additions & 1 deletion packages/web-vue/components/image/image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div :class="wrapperClassNames" :style="wrapperStyles">
<img
ref="refImg"
:class="`${prefixCls}-img`"
:class="[`${prefixCls}-img`, imgClass]"
v-bind="imgProps"
:style="{ ...imgStyle, ...fitStyle }"
:title="title"
Expand Down Expand Up @@ -125,6 +125,13 @@ export default defineComponent({
height: {
type: [String, Number] as PropType<string | number>,
},
/**
* @zh 图片的类名
* @en The class name of the image
*/
imgClass: {
type: [String, Array] as PropType<string | any[]>,
},
/**
* @zh 标题
* @en Title
Expand Down