Skip to content

Commit

Permalink
feat(image): add can-preview & on-load prop and add loading & errorbo…
Browse files Browse the repository at this point in the history
…x slot (#1714)

* feat(n-input):add select methods, closes #1328

* Feat(image):add canPreview,onLoad,loading,errorbox

* del(image) show errorBox tests

* feat(switch):add activeColor`&inactiveColor&activeButtonColor&inactiveButtonColor

Co-authored-by: 勤劳上班的卑微小张 <jiazhan.zhang@ggimage.com>
  • Loading branch information
2277419213 and 勤劳上班的卑微小张 committed Dec 2, 2021
1 parent eff7472 commit 3884845
Show file tree
Hide file tree
Showing 24 changed files with 629 additions and 41 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

### Fixes

### Feats

- `n-switch` add `activeColor` & `inactiveColor` & `activeButtonColor` & `inactiveButtonColor` prop, closes [#1718](https://github.com/TuSimple/naive-ui/issues/1718)
- `n-image` add `can-preview` & `on-load` prop, closes [#1647](https://github.com/TuSimple/naive-ui/issues/1647).
- `n-image` add `loading` & `errorbox` slot.

## 2.21.2 (2021-11-29)

### Fixes
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

### Fixes

### Feats

- `n-switch` 新增 `activeColor` & `inactiveColor` & `activeButtonColor` & `inactiveButtonColor` 属性,关闭 [#1718](https://github.com/TuSimple/naive-ui/issues/1718)
- `n-image` 新增 `can-preview` & `on-load` 属性,关闭 [#1647](https://github.com/TuSimple/naive-ui/issues/1647)
- `n-image` 新增 `loading` & `errorbox` slot

## 2.21.2 (2021-11-29)

### Fixes
Expand Down
22 changes: 12 additions & 10 deletions demo/pages/docs/customize-theme/zhCN/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ Naive UI 通过使用 `n-config-provider` 调整主题。
如果你正在使用 ts 写代码,这块比较适合你。

```html

<script lang="ts">
import { NConfigProvider, GlobalThemeOverrides } from 'naive-ui'
import { NConfigProvider, GlobalThemeOverrides } from 'naive-ui'
const themeOverrides: GlobalThemeOverrides = {
common: {
Expand Down Expand Up @@ -124,7 +123,8 @@ Naive UI 通过使用 `n-config-provider` 调整主题。
type ButtonThemeOverrides = NonNullable<ButtonProps['themeOverrides']>
const selectThemeOverrides: SelectThemeOverrides = {
menuBoxShadow: '0 6px 16px -9px rgba(0, 0, 0, .08), 0 9px 28px 0 rgba(0, 0, 0, .05), 0 12px 48px 16px rgba(0, 0, 0, .03)',
menuBoxShadow:
'0 6px 16px -9px rgba(0, 0, 0, .08), 0 9px 28px 0 rgba(0, 0, 0, .05), 0 12px 48px 16px rgba(0, 0, 0, .03)',
peers: {
InternalSelection: {
textColor: '#FF0000',
Expand All @@ -141,7 +141,11 @@ Naive UI 通过使用 `n-config-provider` 调整主题。
</script>

<template>
<n-select v-model:value="value" :options="options" :theme-overrides="selectThemeOverrides" />
<n-select
v-model:value="value"
:options="options"
:theme-overrides="selectThemeOverrides"
/>
<n-button :theme-overrides="buttonThemeOverrides">theme</n-button>
</template>
```
Expand Down Expand Up @@ -204,9 +208,9 @@ peers 相关的主题变量还没有暴露,使用 `GlobalThemeOverrides` 可
textColor: '#FF0000'
},
InternalSelectMenu: {
borderRadius: '6px',
borderRadius: '6px'
}
},
}
},
DataTable: {
paginationMargin: '40px 0 0 0',
Expand All @@ -218,16 +222,14 @@ peers 相关的主题变量还没有暴露,使用 `GlobalThemeOverrides` 可
itemTextColor: '#ccc'
}
}
},
}
// ...
}
// ...
</script>

<template>
<n-config-provider
:theme-overrides="themeOverrides"
>
<n-config-provider :theme-overrides="themeOverrides">
<my-app />
</n-config-provider>
</template>
Expand Down
3 changes: 2 additions & 1 deletion src/_utils/naive/extract-public-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ type themePropKeys = keyof typeof useTheme.props

export type ExtractPublicPropTypes<T> = Omit<
Partial<ExtractPropTypes<T>>,
Exclude<themePropKeys, 'themeOverrides'> | Extract<keyof T, `internal${string}`>
| Exclude<themePropKeys, 'themeOverrides'>
| Extract<keyof T, `internal${string}`>
>

export type ExtractInternalPropTypes<T> = Partial<ExtractPropTypes<T>>
57 changes: 57 additions & 0 deletions src/image/demos/enUS/error.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Load failed

{{showError ? "Don't worry, the darkness will pass." : "In life, failure is inevitable."}}

```html
<n-button
type="primary"
@click="showError = !showError"
style="margin-bottom:10px"
>{{showError ? "To repair the image" : "Destroy the image"}}</n-button
>
<n-space>
<div style="margin-right: 10px">
<n-tag type="success"> Default style </n-tag>
<div>
<n-image
width="100"
:src="showError ? 'http://www.yi-schoo/logo.jpg' : 'http://www.yi-school.top/logo.jpg'"
:canPreview="false"
></n-image>
</div>
</div>
<div>
<n-tag type="success"> Error slot style </n-tag>
<div>
<n-image
width="200"
height="200"
:src="showError ? 'http://www.yi-schoo/logo.jpg' : 'http://www.yi-school.top/logo.jpg'"
:canPreview="false"
>
<template #errorbox>
<n-result
status="404"
size="small"
title="404 Resources do not exist"
>
</n-result>
</template>
</n-image>
</div>
</div>
</n-space>
```

```js
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup () {
const showError = ref(false)
return {
showError
}
}
})
```
11 changes: 11 additions & 0 deletions src/image/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Preview it.
```demo
basic
group
loading
error
```

## API
Expand All @@ -20,10 +22,19 @@ group
| 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. |
| can-preview | `boolean` | `true` | Whether clicking image preview is allowed. |
| 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. |
| on-error | `(e: Event) => void` | `undefined` | Callback executed when the image fails to load. |
| on-load | `(e: Event) => void` | `undefined` | Callback executed after the image is loaded. |

### Image Slots

| Name | Type | Description |
| -------- | ---- | ---------------------------------------------------- |
| loading | `()` | Excessive animation during image loading. |
| errorbox | `()` | A placeholder in the event of an image load failure. |

### ImageGroup Props

Expand Down
71 changes: 71 additions & 0 deletions src/image/demos/enUS/loading.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Loading Image

This is just a demo of the loading effect. The component will automatically display the loading effect when the image is loaded. It is `not recommended` to change the showLoadIng property unless you know exactly what you are doing!

```html
<n-button type="primary" @click="loadImg" style="margin-bottom:10px"
>{{showLoadIng ? "Finished loading" : "Show loading"}}</n-button
>
<n-space>
<div style="margin-right: 10px">
<n-tag type="success"> Default style </n-tag>
<div>
<n-image
width="100"
src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
:canPreview="false"
ref="nImageRef1"
></n-image>
</div>
</div>
<div>
<n-tag type="success"> Loading slot style </n-tag>
<div>
<n-image
width="200"
src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
:canPreview="false"
ref="nImageRef2"
>
<template #loading>
<n-progress type="circle" :percentage="percentage" />
</template>
</n-image>
</div>
</div>
</n-space>
```

```js
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup () {
const nImageRef1 = ref(null)
const nImageRef2 = ref(null)
const percentage = ref(0)
const TimeFun = ref(null)
const showLoadIng = ref(false)
return {
loadImg () {
nImageRef1.value.showLoadIng = !showLoadIng.value
nImageRef2.value.showLoadIng = !showLoadIng.value
showLoadIng.value = !showLoadIng.value
if (showLoadIng.value) {
TimeFun.value = setInterval(() => {
percentage.value =
percentage.value < 100 ? percentage.value + 1 : 100
}, 1000)
} else {
clearInterval(TimeFun.value)
percentage.value = 0
}
},
nImageRef1,
nImageRef2,
percentage,
showLoadIng
}
}
})
```
53 changes: 53 additions & 0 deletions src/image/demos/zhCN/error.demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 加载失败

{{showError ? "别担心,柳暗花明又一村。" : "人生嘛,失败总是难免的。"}}

```html
<n-button
type="primary"
@click="showError = !showError"
style="margin-bottom:10px"
>{{showError ? "修复一下" : "干掉图片"}}</n-button
>
<n-space>
<div style="margin-right: 10px">
<n-tag type="success"> 默认样式 </n-tag>
<div>
<n-image
width="100"
:src="showError ? 'http://www.yi-schoo/logo.jpg' : 'http://www.yi-school.top/logo.jpg'"
:canPreview="false"
></n-image>
</div>
</div>
<div>
<n-tag type="success"> error插槽样式 </n-tag>
<div>
<n-image
width="200"
height="200"
:src="showError ? 'http://www.yi-schoo/logo.jpg' : 'http://www.yi-school.top/logo.jpg'"
:canPreview="false"
>
<template #errorbox>
<n-result status="404" size="small" title="404 资源不存在">
</n-result>
</template>
</n-image>
</div>
</div>
</n-space>
```

```js
import { defineComponent, ref } from 'vue'

export default defineComponent({
setup () {
const showError = ref(false)
return {
showError
}
}
})
```
11 changes: 11 additions & 0 deletions src/image/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
```demo
basic
group
loading
error
```

## API
Expand All @@ -20,10 +22,19 @@ group
| img-props | `object` | `undefined` | 组件中 img 元素的属性 |
| object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `fill` | 图片在容器内的的适应类型 |
| preview-src | `string` | `undefined` | 预览图片的图片地址 |
| can-preview | `boolean` | `true` | 是否可以点击图片进行预览 |
| show-toolbar | `boolean` | `true` | 图片放大后是否展示底部工具栏 |
| src | `string` | `undefined` | 图片来源 |
| width | `string \| number` | `undefined` | 图片宽度 |
| on-error | `(e: Event) => void` | `undefined` | 图片加载失败执行的回调 |
| on-load | `(e: Event) => void` | `undefined` | 图片加载完成执行的回调 |

### Image Slots

| 名称 | 参数 | 说明 |
| -------- | ---- | -------------------- |
| loading | `()` | 图像加载中过度动画 |
| errorbox | `()` | 图像加载失败的占位图 |

### ImageGroup Props

Expand Down
Loading

0 comments on commit 3884845

Please sign in to comment.