diff --git a/src/config.json b/src/config.json index 73b3d2d43a..0430193b47 100644 --- a/src/config.json +++ b/src/config.json @@ -129,6 +129,7 @@ "cName": "图片", "desc": "图片展示", "taro": false, + "setup": true, "author": "yangxiaolu" } ] @@ -928,4 +929,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/src/packages/__VUE/image/__tests__/__snapshots__/image.spec.tsx.snap b/src/packages/__VUE/image/__tests__/__snapshots__/image.spec.tsx.snap new file mode 100644 index 0000000000..25f004476c --- /dev/null +++ b/src/packages/__VUE/image/__tests__/__snapshots__/image.spec.tsx.snap @@ -0,0 +1,33 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Image: load error 1`] = ` +"
+ +
+ , +
+
" +`; + +exports[`Image: loading 1`] = ` +"
+
+ , +
+ +
" +`; + +exports[`Image: render 1`] = ` +"
+ + +
" +`; + +exports[`Image: render Round 1`] = ` +"
+ + +
" +`; diff --git a/src/packages/__VUE/image/__tests__/image.spec.ts b/src/packages/__VUE/image/__tests__/image.spec.tsx similarity index 52% rename from src/packages/__VUE/image/__tests__/image.spec.ts rename to src/packages/__VUE/image/__tests__/image.spec.tsx index 05e247c43f..fa35a63789 100644 --- a/src/packages/__VUE/image/__tests__/image.spec.ts +++ b/src/packages/__VUE/image/__tests__/image.spec.tsx @@ -1,23 +1,12 @@ -import { config, mount } from '@vue/test-utils' -import { Image as ImagePage } from '@nutui/nutui' -import { Loading, CircleClose, Image, ImageError } from '@nutui/icons-vue' -beforeAll(() => { - config.global.components = { - Loading, - CircleClose, - Image, - ImageError - } -}) +import { mount } from '@vue/test-utils' +import { Image } from '@nutui/nutui' -afterAll(() => { - config.global.components = {} -}) +const url = '//img10.360buyimg.com/ling/jfs/t1/181258/24/10385/53029/60d04978Ef21f2d42/92baeb21f907cd24.jpg' -test('ImagePage render', async () => { - const wrapper = mount(ImagePage, { +test('Image: render', async () => { + const wrapper = mount(Image, { props: { - src: '//img10.360buyimg.com/ling/jfs/t1/181258/24/10385/53029/60d04978Ef21f2d42/92baeb21f907cd24.jpg', + src: url, width: '100', height: '100', showLoading: false @@ -27,8 +16,8 @@ test('ImagePage render', async () => { expect(wrapper.html()).toMatchSnapshot() }) -test('ImagePage load error', async () => { - const wrapper = mount(ImagePage, { +test('Image: load error', async () => { + const wrapper = mount(Image, { props: { src: 'https://x', width: '100', @@ -41,8 +30,8 @@ test('ImagePage load error', async () => { expect(wrapper.html()).toMatchSnapshot() }) -test('ImagePage loading', async () => { - const wrapper = mount(ImagePage, { +test('Image: loading', async () => { + const wrapper = mount(Image, { props: { src: '', width: '100', @@ -55,10 +44,10 @@ test('ImagePage loading', async () => { expect(wrapper.html()).toMatchSnapshot() }) -test('ImagePage render Round', async () => { - const wrapper = mount(ImagePage, { +test('Image: render Round', async () => { + const wrapper = mount(Image, { props: { - src: '//img10.360buyimg.com/ling/jfs/t1/181258/24/10385/53029/60d04978Ef21f2d42/92baeb21f907cd24.jpg', + src: url, width: '100', height: '100', round: true diff --git a/src/packages/__VUE/image/doc.en-US.md b/src/packages/__VUE/image/doc.en-US.md index 84f996703e..dcc8633851 100644 --- a/src/packages/__VUE/image/doc.en-US.md +++ b/src/packages/__VUE/image/doc.en-US.md @@ -106,3 +106,16 @@ The Image component provides a default loading failure warning and supports cust | click | Emitted when image is clicked | event: Event | | load | Emitted when image loaded | - | | error | Emitted when image load failed | - | + +### Types version + +The component exports the following type definitions: + +```js +import type { + ImageFit, + ImagePosition, + ImageProps, + ImageInstance +} from '@nutui/nutui'; +``` diff --git a/src/packages/__VUE/image/doc.md b/src/packages/__VUE/image/doc.md index 246fd4aafe..623adde4d3 100644 --- a/src/packages/__VUE/image/doc.md +++ b/src/packages/__VUE/image/doc.md @@ -108,3 +108,16 @@ Image 组件提供了默认的加载失败提示,支持通过 `error` 插槽 | click | 点击图片时触发 | event: Event | | load | 图片加载完后触发 | -- | | error | 图片加载失败后触发 | -- | + +### 类型定义 version + +组件导出以下类型定义: + +```js +import type { + ImageFit, + ImagePosition, + ImageProps, + ImageInstance +} from '@nutui/nutui'; +``` diff --git a/src/packages/__VUE/image/image.taro.vue b/src/packages/__VUE/image/image.taro.vue new file mode 100644 index 0000000000..59e5053d05 --- /dev/null +++ b/src/packages/__VUE/image/image.taro.vue @@ -0,0 +1,3 @@ + diff --git a/src/packages/__VUE/image/image.vue b/src/packages/__VUE/image/image.vue new file mode 100644 index 0000000000..2b0a98d4b6 --- /dev/null +++ b/src/packages/__VUE/image/image.vue @@ -0,0 +1,152 @@ + + diff --git a/src/packages/__VUE/image/index.taro.ts b/src/packages/__VUE/image/index.taro.ts new file mode 100644 index 0000000000..c71d7a1f47 --- /dev/null +++ b/src/packages/__VUE/image/index.taro.ts @@ -0,0 +1,9 @@ +import Image from './image.taro.vue' +import type { ComponentPublicInstance } from 'vue' +import { withInstall } from '@/packages/utils' + +withInstall(Image) + +export type ImageInstance = ComponentPublicInstance & InstanceType + +export { Image, Image as default } diff --git a/src/packages/__VUE/image/index.taro.vue b/src/packages/__VUE/image/index.taro.vue deleted file mode 100644 index 91e5b1817d..0000000000 --- a/src/packages/__VUE/image/index.taro.vue +++ /dev/null @@ -1,38 +0,0 @@ - - diff --git a/src/packages/__VUE/image/index.ts b/src/packages/__VUE/image/index.ts new file mode 100644 index 0000000000..3ca8ffd13e --- /dev/null +++ b/src/packages/__VUE/image/index.ts @@ -0,0 +1,13 @@ +import Image from './image.vue' +import type { ComponentPublicInstance } from 'vue' +import { withInstall } from '@/packages/utils' + +withInstall(Image) + +export type { ImageProps } from './image.vue' + +export type { ImageFit, ImagePosition } from './types' + +export type ImageInstance = ComponentPublicInstance & InstanceType + +export { Image, Image as default } diff --git a/src/packages/__VUE/image/index.vue b/src/packages/__VUE/image/index.vue deleted file mode 100644 index 39196b4da2..0000000000 --- a/src/packages/__VUE/image/index.vue +++ /dev/null @@ -1,185 +0,0 @@ - - diff --git a/src/packages/__VUE/image/type.ts b/src/packages/__VUE/image/types.ts similarity index 100% rename from src/packages/__VUE/image/type.ts rename to src/packages/__VUE/image/types.ts