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

refactor(components): [switch] deprecate value prop #8335

Merged
merged 1 commit into from Jun 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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