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

perf(ui/rate): add call function #379

Merged
merged 4 commits into from
Apr 4, 2022
Merged
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
26 changes: 14 additions & 12 deletions packages/varlet-ui/src/rate/Rate.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="var-rate__warp">
<div class="var-rate">
<div :class="n('warp')">
<div :class="n()">
<div
:key="val"
v-for="val in toNumber(count)"
Expand All @@ -27,12 +27,14 @@ import VarFormDetails from '../form-details'
import Ripple from '../ripple'
import { defineComponent, nextTick } from 'vue'
import { useForm } from '../form/provide'
import { useValidation } from '../utils/components'
import { useValidation, call, createNamespace} from '../utils/components'
import { toSizeUnit } from '../utils/elements'
import { toNumber } from '../utils/shared'
import { props } from './props'
import type { RateProvider } from './provide'

const { n } = createNamespace('rate')

export default defineComponent({
name: 'VarRate',
components: {
Expand Down Expand Up @@ -61,10 +63,10 @@ export default defineComponent({
const { type, color } = transformValue(val)

return {
'var-rate__content': true,
'var-rate--disabled': form?.disabled.value,
'var-rate--error': errorMessage.value,
'var-rate--primary': type !== 'empty' && !color,
[n('content')]: true,
[n('--disabled')]: form?.disabled.value,
[n('--error')]: errorMessage.value,
[n('--primary')]: type !== 'empty' && !color,
}
}

Expand Down Expand Up @@ -100,7 +102,7 @@ export default defineComponent({
if (event.offsetX <= Math.floor(offsetWidth / 2)) score -= 0.5
}

props['onUpdate:modelValue']?.(score)
call(props['onUpdate:modelValue'],score)
}

const validate = () => v(props.rules, toNumber(props.modelValue))
Expand All @@ -115,12 +117,12 @@ export default defineComponent({
}

changeValue(score, event)
onChange?.(score)
call(onChange, score)
validateWithTrigger()
}

const reset = () => {
props['onUpdate:modelValue']?.(0)
call(props['onUpdate:modelValue'], 0)
resetValidation()
}

Expand All @@ -130,8 +132,7 @@ export default defineComponent({
resetValidation,
}

bindForm?.(rateProvider)

call(bindForm, rateProvider)
return {
errorMessage,
formDisabled: form?.disabled,
Expand All @@ -145,6 +146,7 @@ export default defineComponent({
resetValidation,
toSizeUnit,
toNumber,
n,
}
},
})
Expand Down