Skip to content

Commit

Permalink
refactor(components): [switch] deprecate value prop (element-plus#8335)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored and LinZhanMing committed Jun 18, 2022
1 parent b9d7bd4 commit 9b7b4e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions packages/components/switch/src/switch.vue
Expand Up @@ -83,7 +83,15 @@
</template>

<script lang="ts">
import { computed, defineComponent, nextTick, onMounted, ref, watch } from 'vue'
import {
computed,
defineComponent,
getCurrentInstance,
nextTick,
onMounted,
ref,
watch,
} from 'vue'
import { isPromise } from '@vue/shared'
import { addUnit, debugWarn, isBoolean, throwError } from '@element-plus/utils'
import ElIcon from '@element-plus/components/icon'
Expand All @@ -94,6 +102,7 @@ import {
UPDATE_MODEL_EVENT,
} from '@element-plus/constants'
import {
useDeprecated,
useDisabled,
useFormItem,
useFormItemInputId,
Expand All @@ -114,15 +123,28 @@ export default defineComponent({
emits: switchEmits,
setup(props, { emit }) {
const vm = getCurrentInstance()!
const { formItem } = useFormItem()
const switchSize = useSize()
const switchDisabled = useDisabled(computed(() => props.loading))
const ns = useNamespace('switch')
useDeprecated(
{
from: '"value"',
replacement: '"model-value" or "v-model"',
scope: COMPONENT_NAME,
version: '2.3.0',
ref: 'https://element-plus.org/en-US/component/switch.html#attributes',
type: 'Attribute',
},
computed(() => !!vm.vnode.props?.value)
)
const { inputId } = useFormItemInputId(props, {
formItemContext: formItem,
})
const switchSize = useSize()
const isModelValue = ref(props.modelValue !== false)
const input = ref<HTMLInputElement>()
const core = ref<HTMLSpanElement>()
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/use-deprecated/index.ts
Expand Up @@ -9,7 +9,7 @@ type DeprecationParam = {
scope: string
version: string
ref: string
type?: 'API' | 'Slot' | 'Event'
type?: 'API' | 'Attribute' | 'Event' | 'Slot'
}

export const useDeprecated = (
Expand All @@ -22,7 +22,7 @@ export const useDeprecated = (
if (val) {
debugWarn(
scope,
`${type} ${from} is about to be deprecated in version ${version}, please use ${replacement} instead.
`[${type}] ${from} is about to be deprecated in version ${version}, please use ${replacement} instead.
For more detail, please visit: ${ref}
`
)
Expand Down

0 comments on commit 9b7b4e3

Please sign in to comment.