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

types(ui): optimize form component validate trigger type name #1745

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import Ripple from '../ripple'
import Hover from '../hover'
import VarHoverOverlay, { useHoverOverlay } from '../hover-overlay'
import { defineComponent, ref, computed, nextTick } from 'vue'
import { props, type ValidateTriggers } from './props'
import { props, type CheckboxValidateTrigger } from './props'
import { useValidation, createNamespace } from '../utils/components'
import { useCheckboxGroup, type CheckboxProvider } from './provide'
import { useForm } from '../form/provide'
Expand Down Expand Up @@ -127,7 +127,7 @@ export default defineComponent({
useEventListener(() => window, 'keydown', handleKeydown)
useEventListener(() => window, 'keyup', handleKeyup)

function validateWithTrigger(trigger: ValidateTriggers) {
function validateWithTrigger(trigger: CheckboxValidateTrigger) {
nextTick(() => {
const { validateTrigger, rules, modelValue } = props
vt(validateTrigger, trigger, rules, modelValue)
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/checkbox/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PropType } from 'vue'
import { defineListenerProp } from '../utils/components'

export type ValidateTriggers = 'onChange'
export type CheckboxValidateTrigger = 'onChange'

export const props = {
modelValue: {
Expand All @@ -27,7 +27,7 @@ export const props = {
default: true,
},
validateTrigger: {
type: Array as PropType<Array<ValidateTriggers>>,
type: Array as PropType<Array<CheckboxValidateTrigger>>,
default: () => ['onChange'],
},
rules: Array as PropType<Array<(value: any) => any>>,
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/counter/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import VarFormDetails from '../form-details'
import Ripple from '../ripple'
import { defineComponent, ref, watch, computed, nextTick, type ComputedRef } from 'vue'
import { Decimal } from 'decimal.js'
import { props, type ValidateTrigger } from './props'
import { props, type CounterValidateTrigger } from './props'
import { toNumber, call } from '@varlet/shared'
import { toSizeUnit } from '../utils/elements'
import { useForm } from '../form/provide'
Expand Down Expand Up @@ -170,7 +170,7 @@ export default defineComponent({
return v(props.rules, props.modelValue)
}

function validateWithTrigger(trigger: ValidateTrigger) {
function validateWithTrigger(trigger: CounterValidateTrigger) {
nextTick(() => {
const { validateTrigger, rules, modelValue } = props
vt(validateTrigger, trigger, rules, modelValue)
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/counter/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const value = ref(0)
| `press` | Long press the open button | _boolean_ | `true` |
| `ripple` | Whether to open ripple | _boolean_ | `true` |
| `lazy-change` | Whether to prevent the component itself from updating the bound value | _boolean_ | `false` |
| `validate-trigger` | Timing to trigger validation,Optional value is `onInputChange` `onLazyChange` `onIncrement` `onDecrement` | _ValidateTriggers[]_ | `['onIncrement', 'onDecrement', 'onInputChange', 'onLazyChange']` |
| `validate-trigger` | Timing to trigger validation,Optional value is `onInputChange` `onLazyChange` `onIncrement` `onDecrement` | _CounterValidateTrigger[]_ | `['onIncrement', 'onDecrement', 'onInputChange', 'onLazyChange']` |
| `rules` | The validation rules, return `true` to indicate that the validation passed. The remaining values are converted to text as user prompts | _Array<(value: number) => any>_ | `-` |

### Methods
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/counter/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const value = ref(0)
| `press` | 是否开启按钮长按 | _boolean_ | `true` |
| `ripple` | 是否开启水波纹 | _boolean_ | `true` |
| `lazy-change` | 是否阻止组件本身的绑定值更新操作 | _boolean_ | `false` |
| `validate-trigger` | 触发验证的时机,可选值为 `onInputChange` `onLazyChange` `onIncrement` `onDecrement` | _ValidateTriggers[]_ | `['onIncrement', 'onDecrement', 'onInputChange', 'onLazyChange']` |
| `validate-trigger` | 触发验证的时机,可选值为 `onInputChange` `onLazyChange` `onIncrement` `onDecrement` | _CounterValidateTrigger[]_ | `['onIncrement', 'onDecrement', 'onInputChange', 'onLazyChange']` |
| `rules` | 验证规则,返回 `true` 表示验证通过,其余的值则转换为文本作为用户提示 | _Array<(value: number) => any>_ | `-` |

### 方法
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/counter/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type PropType } from 'vue'
import { defineListenerProp } from '../utils/components'

export type ValidateTrigger = 'onIncrement' | 'onDecrement' | 'onInputChange' | 'onLazyChange'
export type CounterValidateTrigger = 'onIncrement' | 'onDecrement' | 'onInputChange' | 'onLazyChange'

export const props = {
modelValue: {
Expand Down Expand Up @@ -46,7 +46,7 @@ export const props = {
default: true,
},
validateTrigger: {
type: Array as PropType<Array<ValidateTrigger>>,
type: Array as PropType<Array<CounterValidateTrigger>>,
default: () => ['onInputChange', 'onLazyChange', 'onIncrement', 'onDecrement'],
},
rules: Array as PropType<Array<(v: number) => any>>,
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/input/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const value13 = ref('')
| `clearable` | Whether the clearable | _boolean_ | `false` |
| `resize` | Whether textarea can be dragged to resize | _boolean_ | `false` |
| `autofocus` | Whether the autofocus | _boolean_ | `false` |
| `validate-trigger` | Timing to trigger validation, The optional value is `onFocus` `onBlur` `onChange` `onClick` `onClear` `onInput` | _ValidateTriggers[]_ | `['onInput', 'onClear']` |
| `validate-trigger` | Timing to trigger validation, The optional value is `onFocus` `onBlur` `onChange` `onClick` `onClear` `onInput` | _InputValidateTrigger[]_ | `['onInput', 'onClear']` |
| `rules` | The validation rules, return `true` to indicate that the validation passed,The remaining values are converted to text as user prompts | _Array<(v: string) => any>_ | `-` |
| `enterkeyhint` | Customize the enter key style, See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint) | _string_ | `-` |

Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/input/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const value13 = ref('')
| `clearable` | 是否可清除 | _boolean_ | `false` |
| `resize` | 文本域是否可以拖动调整尺寸 | _boolean_ | `false` |
| `autofocus` | 是否自动聚焦 | _boolean_ | `false` |
| `validate-trigger` | 触发验证的时机,可选值为 `onFocus` `onBlur` `onChange` `onClick` `onClear` `onInput` | _ValidateTriggers[]_ | `['onInput', 'onClear']` |
| `validate-trigger` | 触发验证的时机,可选值为 `onFocus` `onBlur` `onChange` `onClick` `onClear` `onInput` | _InputValidateTrigger[]_ | `['onInput', 'onClear']` |
| `rules` | 验证规则,返回 `true` 表示验证通过,其余的值则转换为文本作为用户提示 | _Array<(v: string) => any>_ | `-` |
| `enterkeyhint` | 定制回车键样式,参见 [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint) | _string_ | `-` |

Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/radio-group/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import VarFormDetails from '../form-details'
import VarRadio from '../radio'
import { computed, defineComponent, nextTick, watch } from 'vue'
import { props, type ValidateTriggers } from './props'
import { props, type RadioGroupValidateTrigger } from './props'
import { useValidation, createNamespace, MaybeVNode } from '../utils/components'
import { useRadios, type RadioGroupProvider } from './provide'
import { useForm } from '../form/provide'
Expand Down Expand Up @@ -115,7 +115,7 @@ export default defineComponent({
}
}

function validateWithTrigger(trigger: ValidateTriggers) {
function validateWithTrigger(trigger: RadioGroupValidateTrigger) {
nextTick(() => {
const { validateTrigger, rules, modelValue } = props
vt(validateTrigger, trigger, rules, modelValue)
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/radio-group/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { VNode, VNodeChild, type PropType } from 'vue'
import { defineListenerProp } from '../utils/components'

export type ValidateTriggers = 'onChange'
export type RadioGroupValidateTrigger = 'onChange'

export type RadioGroupOptionLabelRender = (option: RadioGroupOption, checked: boolean) => VNodeChild

Expand Down Expand Up @@ -34,7 +34,7 @@ export const props = {
default: 'value',
},
validateTrigger: {
type: Array as PropType<Array<ValidateTriggers>>,
type: Array as PropType<Array<RadioGroupValidateTrigger>>,
default: () => ['onChange'],
},
rules: Array as PropType<Array<(value: any) => any>>,
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/radio/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import Ripple from '../ripple'
import Hover from '../hover'
import VarHoverOverlay, { useHoverOverlay } from '../hover-overlay'
import { computed, defineComponent, nextTick, ref } from 'vue'
import { props, type ValidateTrigger } from './props'
import { props, type RadioValidateTrigger } from './props'
import { useValidation, createNamespace } from '../utils/components'
import { useRadioGroup, type RadioProvider } from './provide'
import { useForm } from '../form/provide'
Expand Down Expand Up @@ -150,7 +150,7 @@ export default defineComponent({
}
}

function validateWithTrigger(trigger: ValidateTrigger) {
function validateWithTrigger(trigger: RadioValidateTrigger) {
nextTick(() => {
const { validateTrigger, rules, modelValue } = props
vt(validateTrigger, trigger, rules, modelValue)
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/radio/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type PropType } from 'vue'
import { defineListenerProp } from '../utils/components'

export type ValidateTrigger = 'onChange'
export type RadioValidateTrigger = 'onChange'

export const props = {
modelValue: {
Expand All @@ -26,7 +26,7 @@ export const props = {
default: true,
},
validateTrigger: {
type: Array as PropType<Array<ValidateTrigger>>,
type: Array as PropType<Array<RadioValidateTrigger>>,
default: () => ['onChange'],
},
rules: Array as PropType<Array<(value: any) => any>>,
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/select/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ const keyOptions = ref([
| `options` ***3.3.4*** | Specifies options | _SelectOption[]_ | `-` |
| `label-key` ***3.3.4*** | As the key that uniquely identifies label | _string_ | `label` |
| `value-key` ***3.3.4*** | As the key that uniquely identifies value | _string_ | `value` |
| `validate-trigger` | Timing to trigger validation, optional value is `onFocus` `onBlur` `onChange` `onClick` `onClear` `onClose` | _ValidateTriggers[]_ | `['onChange', 'onClear', 'onClose']` |
| `validate-trigger` | Timing to trigger validation, optional value is `onFocus` `onBlur` `onChange` `onClick` `onClear` `onClose` | _SelectValidateTrigger[]_ | `['onChange', 'onClear', 'onClose']` |
| `rules` | The validation rules, return `true` to indicate that the validation passed, The remaining values are converted to text as user prompts | _Array<(v: any \| any[]) => any>_ | `-` |

#### SelectOption
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/select/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ const keyOptions = ref([
| `options` ***3.3.4*** | 指定可选项 | _SelectOption[]_ | `-` |
| `label-key` ***3.3.4*** | 作为 label 唯一标识的键名 | _string_ | `label` |
| `value-key` ***3.3.4*** | 作为 value 唯一标识的键名 | _string_ | `value` |
| `validate-trigger` | 触发验证的时机,可选值为 `onFocus` `onBlur` `onChange` `onClick` `onClear` `onClose` | _ValidateTriggers[]_ | `['onChange', 'onClear', 'onClose']` |
| `validate-trigger` | 触发验证的时机,可选值为 `onFocus` `onBlur` `onChange` `onClick` `onClear` `onClose` | _SelectValidateTrigger[]_ | `['onChange', 'onClear', 'onClose']` |
| `rules` | 验证规则,返回 `true` 表示验证通过,其余的值则转换为文本作为用户提示 | _Array<(v: any \| any[]) => any>_ | `-` |

#### SelectOption
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/switch/Switch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { defineComponent, computed, nextTick, ref } from 'vue'
import { useValidation, createNamespace, formatElevation } from '../utils/components'
import { multiplySizeUnit } from '../utils/elements'
import { useForm } from '../form/provide'
import { props, type ValidateTrigger } from './props'
import { props, type SwitchValidateTrigger } from './props'
import { call, preventDefault } from '@varlet/shared'
import { useEventListener } from '@varlet/use'
import { type SwitchProvider } from './provide'
Expand Down Expand Up @@ -174,7 +174,7 @@ export default defineComponent({
return v(props.rules, props.modelValue)
}

function validateWithTrigger(trigger: ValidateTrigger) {
function validateWithTrigger(trigger: SwitchValidateTrigger) {
nextTick(() => {
const { validateTrigger, rules, modelValue } = props
vt(validateTrigger, trigger, rules, modelValue)
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/switch/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const value = ref(true)
| `size` | Size of switch | _string \| number_ | `-` |
| `rules` | Validation rules | _Array<(value: any) => any>_ | `-` |
| `lazy-change` | Whether to allow the `before-change` event to be triggered | _boolean_ | `false` |
| `validate-trigger` | Timing to trigger verification, optional values are `onChange` `onLazyChange` | _ValidateTriggers[]_ | `['onChange', 'onLazyChange']` |
| `validate-trigger` | Timing to trigger verification, optional values are `onChange` `onLazyChange` | _SwitchValidateTrigger[]_ | `['onChange', 'onLazyChange']` |
| `variant` ***3.2.3*** | Variant mode | _boolean_ | `false` |

### Events
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/switch/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const value = ref(true)
| `size` | switch 的大小 | _string \| number_ | `-` |
| `rules` | 校验规则 | _Array<(value: any) => any>_ | `-` |
| `lazy-change` | 是否允许触发 `before-change` 事件 | _boolean_ | `false` |
| `validate-trigger` | 触发验证的时机,可选值为 `onChange` `onLazyChange` | _ValidateTriggers[]_ | `['onChange', 'onLazyChange']` |
| `validate-trigger` | 触发验证的时机,可选值为 `onChange` `onLazyChange` | _SwitchValidateTrigger[]_ | `['onChange', 'onLazyChange']` |
| `variant` ***3.2.3*** | 变体模式 | _boolean_ | `false` |

### 事件
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/switch/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type PropType } from 'vue'
import { defineListenerProp } from '../utils/components'

export type ValidateTrigger = 'onChange' | 'onLazyChange'
export type SwitchValidateTrigger = 'onChange' | 'onLazyChange'

export const props = {
modelValue: {
Expand Down Expand Up @@ -32,7 +32,7 @@ export const props = {
default: true,
},
validateTrigger: {
type: Array as PropType<Array<ValidateTrigger>>,
type: Array as PropType<Array<SwitchValidateTrigger>>,
default: () => ['onChange', 'onLazyChange'],
},
onClick: defineListenerProp<(event: Event) => void>(),
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/uploader/docs/en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ const files = ref([
| `ripple` | Whether to open ripple | _boolean_ | `true` |
| `hide-list` | Whether to hide the file list | _boolean_ | `false` |
| `resolve-type` | The file preprocessing type, can be set to `default` `file` `data-url` (`default`, the image type contains dataURL and File object, other types contain only File object. `file`, which contains only File object. `data-url`, all file types contain dataURL and File object) | _string_ | `default` |
| `validate-trigger` | Timing to trigger validation. The optional value is `onChange` `onRemove` | _ValidateTriggers[]_ | `['onChange', 'onRemove']` |
| `validate-trigger` | Timing to trigger validation. The optional value is `onChange` `onRemove` | _UploaderValidateTrigger[]_ | `['onChange', 'onRemove']` |
| `rules` | The validation rules, return `true` to indicate that the validation passed. The remaining values are converted to text as user prompts | _Array<(v: VarFile, u: VarFileUtils) => any>_ | `-` |


Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/uploader/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const files = ref([
| `ripple` | 是否开启水波纹 | _boolean_ | `true` |
| `hide-list` | 是否隐藏文件列表 | _boolean_ | `false` |
| `resolve-type` | 文件预处理类型,可选值为 `default` `file` `data-url`(`default`,图片文件包含 dataURL 编码和 File 对象,其他类型仅包含 File 对象。`file`,仅包含 File 对象。`data-url`,所有文件类型都包含 dataURL 编码和 File 对象) | _string_ | `default` |
| `validate-trigger` | 触发验证的时机, 可选值为 `onChange` `onRemove` | _ValidateTriggers[]_ | `['onChange', 'onRemove']` |
| `validate-trigger` | 触发验证的时机, 可选值为 `onChange` `onRemove` | _UploaderValidateTrigger[]_ | `['onChange', 'onRemove']` |
| `rules` | 验证规则,返回 `true` 表示验证通过,其余的值则转换为文本作为用户提示 | _Array<(v: VarFile, u: VarFileUtils) => any>_ | `-` |


Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/types/checkbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VNode } from 'vue'

export declare const checkboxProps: Record<keyof CheckboxProps, any>

export type CheckboxValidateTriggers = 'onChange'
export type CheckboxValidateTrigger = 'onChange'

export interface CheckboxProps extends BasicAttributes {
modelValue?: any
Expand All @@ -16,7 +16,7 @@ export interface CheckboxProps extends BasicAttributes {
indeterminate?: boolean
iconSize?: string | number
ripple?: boolean
validateTrigger?: Array<CheckboxValidateTriggers>
validateTrigger?: Array<CheckboxValidateTrigger>
rules?: Array<(value: any) => any>
onClick?: ListenerProp<(e: Event) => void>
onChange?: ListenerProp<(value: any) => void>
Expand Down
Loading