soiz1's picture
Upload folder using huggingface_hub
4d70170 verified
raw
history blame contribute delete
868 Bytes
/**
* (Use with the DisabledChild mixin)
* Allow disabling an entire tree of components implementing the DisabledChild mixin.
*/
import { computed, inject, provide, reactive, watch } from 'vue'
export function useDisabledParent(props: { disabled?: boolean }) {
const injectedDisableData = reactive({
value: props.disabled || false,
})
provide('VueDisableMixin', {
data: injectedDisableData,
})
watch(
() => props.disabled,
(value, oldValue) => {
if (value !== oldValue) {
injectedDisableData.value = value
}
},
)
}
export function useDisabledChild(props: { disabled?: boolean }) {
const injectDisable = inject<{ data: { value: boolean } } | undefined>(
'VueDisableMixin',
null,
)
return {
finalDisabled: computed(() => props.disabled || (injectDisable && injectDisable.data.value)),
}
}