mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-07 13:48:31 +08:00
feat(input): add count
slot, closes #1314
This commit is contained in:
parent
4ac6be229a
commit
23a7f24888
@ -10,6 +10,7 @@
|
|||||||
### Feats
|
### Feats
|
||||||
|
|
||||||
- `n-menu` add `dropdown-props` prop, closes [#1345](https://github.com/TuSimple/naive-ui/issues/1345).
|
- `n-menu` add `dropdown-props` prop, closes [#1345](https://github.com/TuSimple/naive-ui/issues/1345).
|
||||||
|
- `n-input` add `count` slot, closes [#1314](https://github.com/TuSimple/naive-ui/issues/1314).
|
||||||
|
|
||||||
## 2.19.8 (2021-10-14)
|
## 2.19.8 (2021-10-14)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
### Feats
|
### Feats
|
||||||
|
|
||||||
- `n-menu` 新增 `dropdown-props` 属性,关闭 [#1345](https://github.com/TuSimple/naive-ui/issues/1345)
|
- `n-menu` 新增 `dropdown-props` 属性,关闭 [#1345](https://github.com/TuSimple/naive-ui/issues/1345)
|
||||||
|
- `n-input` 新增 `count` slot,关闭 [#1314](https://github.com/TuSimple/naive-ui/issues/1314)
|
||||||
|
|
||||||
## 2.19.8 (2021-10-14)
|
## 2.19.8 (2021-10-14)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ show-options-by-value
|
|||||||
| clearable | `boolean` | `false` | Whether auto complete is clearable. |
|
| clearable | `boolean` | `false` | Whether auto complete is clearable. |
|
||||||
| default-value | `string` | `null` | Default value of auto complete. |
|
| default-value | `string` | `null` | Default value of auto complete. |
|
||||||
| disabled | `boolean` | `false` | Whether the auto complete is disabled. |
|
| disabled | `boolean` | `false` | Whether the auto complete is disabled. |
|
||||||
| get-show | `(value: string \| null) => boolean` | `undefined` | Based on value to determine whether to show menu when focusing. |
|
| get-show | `(value: string) => boolean` | `undefined` | Based on value to determine whether to show menu when focusing. |
|
||||||
| loading | `boolean` | `false` | Whether to show a loading status. |
|
| loading | `boolean` | `false` | Whether to show a loading status. |
|
||||||
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | Auto complete options. |
|
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | Auto complete options. |
|
||||||
| placeholder | `string` | `'Please Input'` | Auto complete's placeholder. |
|
| placeholder | `string` | `'Please Input'` | Auto complete's placeholder. |
|
||||||
|
@ -24,7 +24,7 @@ show-options-by-value
|
|||||||
| clearable | `boolean` | `false` | 自动填充是否支持可清除 |
|
| clearable | `boolean` | `false` | 自动填充是否支持可清除 |
|
||||||
| default-value | `string` | `null` | 自动填充的默认值 |
|
| default-value | `string` | `null` | 自动填充的默认值 |
|
||||||
| disabled | `boolean` | `false` | 自动填充是否禁用 |
|
| disabled | `boolean` | `false` | 自动填充是否禁用 |
|
||||||
| get-show | `(value: string \| null) => boolean` | `undefined` | 根据输入值在聚焦的状态中决定是否显示菜单 |
|
| get-show | `(value: string) => boolean` | `undefined` | 根据输入值在聚焦的状态中决定是否显示菜单 |
|
||||||
| loading | `boolean` | `false` | 是否展示加载状态 |
|
| loading | `boolean` | `false` | 是否展示加载状态 |
|
||||||
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | 自动填充的自定义选项 |
|
| options | `Array<string \| AutoCompleteOption \| AutoCompleteGroupOption>` | `[]` | 自动填充的自定义选项 |
|
||||||
| placeholder | `string` | `'请输入'` | 自动填充的提示信息 |
|
| placeholder | `string` | `'请输入'` | 自动填充的提示信息 |
|
||||||
|
@ -70,7 +70,7 @@ const autoCompleteProps = {
|
|||||||
value: String,
|
value: String,
|
||||||
blurAfterSelect: Boolean,
|
blurAfterSelect: Boolean,
|
||||||
clearAfterSelect: Boolean,
|
clearAfterSelect: Boolean,
|
||||||
getShow: Function as PropType<(inputValue: string | null) => boolean>,
|
getShow: Function as PropType<(inputValue: string) => boolean>,
|
||||||
size: String as PropType<'small' | 'medium' | 'large'>,
|
size: String as PropType<'small' | 'medium' | 'large'>,
|
||||||
options: {
|
options: {
|
||||||
type: Array as PropType<AutoCompleteOptions>,
|
type: Array as PropType<AutoCompleteOptions>,
|
||||||
@ -134,7 +134,7 @@ export default defineComponent({
|
|||||||
const mergedShowOptionsRef = computed(() => {
|
const mergedShowOptionsRef = computed(() => {
|
||||||
const { getShow } = props
|
const { getShow } = props
|
||||||
if (getShow) {
|
if (getShow) {
|
||||||
return getShow(mergedValueRef.value)
|
return getShow(mergedValueRef.value || '')
|
||||||
}
|
}
|
||||||
return !!mergedValueRef.value
|
return !!mergedValueRef.value
|
||||||
})
|
})
|
||||||
|
@ -6,5 +6,10 @@ Don't waste words.
|
|||||||
<n-space vertical>
|
<n-space vertical>
|
||||||
<n-input maxlength="30" show-count clearable />
|
<n-input maxlength="30" show-count clearable />
|
||||||
<n-input type="textarea" maxlength="30" show-count />
|
<n-input type="textarea" maxlength="30" show-count />
|
||||||
|
<n-input type="textarea" show-count #count="{ value }">
|
||||||
|
<n-input type="textarea" default-value="What" show-count #count="{ value }">
|
||||||
|
{{ value.includes('What') ? '99+' : value.length }}
|
||||||
|
</n-input>
|
||||||
|
</n-input>
|
||||||
</n-space>
|
</n-space>
|
||||||
```
|
```
|
||||||
|
@ -59,9 +59,10 @@ event
|
|||||||
|
|
||||||
| Name | Parameters | Description |
|
| Name | Parameters | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
|
| count | `(value: string)` | Word count. |
|
||||||
| prefix | `()` | Prefix content slot. |
|
| prefix | `()` | Prefix content slot. |
|
||||||
| suffix | `()` | Suffix content slot. |
|
|
||||||
| separator | `()` | The separator content of the input, only works when `pair` is true. This will take priority over the separator property. |
|
| separator | `()` | The separator content of the input, only works when `pair` is true. This will take priority over the separator property. |
|
||||||
|
| suffix | `()` | Suffix content slot. |
|
||||||
|
|
||||||
### InputGroup Slots
|
### InputGroup Slots
|
||||||
|
|
||||||
|
@ -6,5 +6,8 @@
|
|||||||
<n-space vertical>
|
<n-space vertical>
|
||||||
<n-input maxlength="30" show-count clearable />
|
<n-input maxlength="30" show-count clearable />
|
||||||
<n-input type="textarea" maxlength="30" show-count />
|
<n-input type="textarea" maxlength="30" show-count />
|
||||||
|
<n-input type="textarea" default-value="啥" show-count #count="{ value }">
|
||||||
|
{{ value.includes('啥') ? '99+' : value.length }}
|
||||||
|
</n-input>
|
||||||
</n-space>
|
</n-space>
|
||||||
```
|
```
|
||||||
|
@ -56,21 +56,22 @@ focus
|
|||||||
|
|
||||||
### Input Slots
|
### Input Slots
|
||||||
|
|
||||||
| 属性 | 类型 | 说明 |
|
| 属性 | 参数 | 说明 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
|
| count | `(value: string)` | 字数统计 |
|
||||||
| prefix | `()` | 输入框头部内容 |
|
| prefix | `()` | 输入框头部内容 |
|
||||||
| suffix | `()` | 输入框尾部内容 |
|
|
||||||
| separator | `()` | 成对输入框之间分隔符,仅 `pair` = true 生效且优先级高于 separator 属性 |
|
| separator | `()` | 成对输入框之间分隔符,仅 `pair` = true 生效且优先级高于 separator 属性 |
|
||||||
|
| suffix | `()` | 输入框尾部内容 |
|
||||||
|
|
||||||
### InputGroup Slots
|
### InputGroup Slots
|
||||||
|
|
||||||
| 属性 | 类型 | 说明 |
|
| 属性 | 参数 | 说明 |
|
||||||
| ------- | ---- | ------------ |
|
| ------- | ---- | ------------ |
|
||||||
| default | `()` | 输入组的内容 |
|
| default | `()` | 输入组的内容 |
|
||||||
|
|
||||||
### InputGroupLabel Slots
|
### InputGroupLabel Slots
|
||||||
|
|
||||||
| 属性 | 类型 | 说明 |
|
| 属性 | 参数 | 说明 |
|
||||||
| ------- | ---- | ---------------- |
|
| ------- | ---- | ---------------- |
|
||||||
| default | `()` | 输入组标签的内容 |
|
| default | `()` | 输入组标签的内容 |
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ import {
|
|||||||
InputWrappedRef,
|
InputWrappedRef,
|
||||||
inputInjectionKey
|
inputInjectionKey
|
||||||
} from './interface'
|
} from './interface'
|
||||||
import { len, isEmptyValue } from './utils'
|
import { isEmptyValue } from './utils'
|
||||||
import WordCount from './WordCount'
|
import WordCount from './WordCount'
|
||||||
import style from './styles/input.cssr'
|
import style from './styles/input.cssr'
|
||||||
import { off, on } from 'evtd'
|
import { off, on } from 'evtd'
|
||||||
@ -658,11 +658,7 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
provide(inputInjectionKey, {
|
provide(inputInjectionKey, {
|
||||||
wordCountRef: computed(() => {
|
mergedValueRef,
|
||||||
const { value: mergedValue } = mergedValueRef
|
|
||||||
if (mergedValue === null || Array.isArray(mergedValue)) return 0
|
|
||||||
return len(mergedValue)
|
|
||||||
}),
|
|
||||||
maxlengthRef,
|
maxlengthRef,
|
||||||
mergedClsPrefixRef
|
mergedClsPrefixRef
|
||||||
})
|
})
|
||||||
@ -1082,7 +1078,9 @@ export default defineComponent({
|
|||||||
{this.mergedBordered ? (
|
{this.mergedBordered ? (
|
||||||
<div class={`${mergedClsPrefix}-input__state-border`} />
|
<div class={`${mergedClsPrefix}-input__state-border`} />
|
||||||
) : null}
|
) : null}
|
||||||
{this.showCount && this.type === 'textarea' ? <WordCount /> : null}
|
{this.showCount && this.type === 'textarea' ? (
|
||||||
|
<WordCount>{{ default: this.$slots.count }}</WordCount>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
import { defineComponent, inject, h, computed } from 'vue'
|
||||||
import { defineComponent, inject, h } from 'vue'
|
|
||||||
import { inputInjectionKey } from './interface'
|
import { inputInjectionKey } from './interface'
|
||||||
|
import { len } from './utils'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'InputWordCount',
|
name: 'InputWordCount',
|
||||||
setup () {
|
setup (_, { slots }) {
|
||||||
const { wordCountRef, maxlengthRef, mergedClsPrefixRef } =
|
const { mergedValueRef, maxlengthRef, mergedClsPrefixRef } =
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
inject(inputInjectionKey)!
|
inject(inputInjectionKey)!
|
||||||
|
const wordCountRef = computed(() => {
|
||||||
|
const { value: mergedValue } = mergedValueRef
|
||||||
|
if (mergedValue === null || Array.isArray(mergedValue)) return 0
|
||||||
|
return len(mergedValue)
|
||||||
|
})
|
||||||
return () => {
|
return () => {
|
||||||
const { value: maxlength } = maxlengthRef
|
const { value: maxlength } = maxlengthRef
|
||||||
|
const { value: mergedValue } = mergedValueRef
|
||||||
return (
|
return (
|
||||||
<span class={`${mergedClsPrefixRef.value}-input-word-count`}>
|
<span class={`${mergedClsPrefixRef.value}-input-word-count`}>
|
||||||
{maxlength === undefined
|
{slots.default
|
||||||
? wordCountRef.value
|
? slots.default({
|
||||||
: `${wordCountRef.value} / ${maxlength}`}
|
value:
|
||||||
|
mergedValue === null || Array.isArray(mergedValue)
|
||||||
|
? ''
|
||||||
|
: mergedValue
|
||||||
|
})
|
||||||
|
: maxlength === undefined
|
||||||
|
? wordCountRef.value
|
||||||
|
: `${wordCountRef.value} / ${maxlength}`}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ export interface InputWrappedRef {
|
|||||||
export type InputInst = UnwrapRef<InputWrappedRef>
|
export type InputInst = UnwrapRef<InputWrappedRef>
|
||||||
|
|
||||||
export const inputInjectionKey: InjectionKey<{
|
export const inputInjectionKey: InjectionKey<{
|
||||||
wordCountRef: Ref<number>
|
mergedValueRef: Ref<string | [string, string] | null>
|
||||||
maxlengthRef: Ref<number | undefined>
|
maxlengthRef: Ref<number | undefined>
|
||||||
mergedClsPrefixRef: Ref<string>
|
mergedClsPrefixRef: Ref<string>
|
||||||
}> = Symbol('input')
|
}> = Symbol('input')
|
||||||
|
Loading…
Reference in New Issue
Block a user